手札からの判定、プロットの追加と削除、プロットからの判定を実装
@@ -21,10 +21,11 @@ | ||
21 | 21 | /** |
22 | 22 | * @see jp.sf.chaplet.core.server.ServerAction#execute(java.lang.String[], jp.sf.chaplet.core.server.ClientProxy) |
23 | 23 | */ |
24 | - public ActionResult execute(String[] request, ClientProxy invoker) | |
24 | + public ActionResult execute(String[] request, ClientProxy proxy) | |
25 | 25 | throws IOException { |
26 | 26 | String card = ((NovaServerPlugin)getPlugin()).getCardManager().next(); |
27 | - String[] log = {request[0], invoker.getSessionId(), card}; | |
27 | + String name = getUserManager().getName(proxy.getSessionId()); | |
28 | + String[] log = {request[0], name, card}; | |
28 | 29 | sendLog(log); |
29 | 30 | return ActionResult.OK_NEXT; |
30 | 31 | } |
@@ -36,7 +36,8 @@ | ||
36 | 36 | } |
37 | 37 | proxy.sendMessage(resp); |
38 | 38 | if(request.length == 2 || !request[2].equals("hidden")){ |
39 | - String[] log = {request[0], proxy.getSessionId(), request[1]}; | |
39 | + String name = getUserManager().getName(proxy.getSessionId()); | |
40 | + String[] log = {request[0], name, request[1]}; | |
40 | 41 | sendLog(log); |
41 | 42 | } |
42 | 43 | return ActionResult.OK_NEXT; |
@@ -27,10 +27,11 @@ | ||
27 | 27 | Hand hand = ((NovaServerPlugin)getPlugin()).getHandManager().getHandOf(proxy.getSessionId()); |
28 | 28 | int protNo = Integer.parseInt(request[1]); |
29 | 29 | if( hand.removeCard(protNo, request[2]) ){ |
30 | - String[] resp = {"ok/" + request[0], request[1], request[2]}; | |
30 | + String name = getUserManager().getName(proxy.getSessionId()); | |
31 | + String[] resp = {"ok/" + request[0], request[1], request[2]}; | |
31 | 32 | proxy.sendMessage(resp); |
32 | 33 | if(request.length == 3 || !request[3].equals("hidden")){ |
33 | - String[] log = {request[0], proxy.getSessionId(), request[2], String.valueOf(hand.getProtOrder(protNo))}; | |
34 | + String[] log = {request[0], name, request[2], String.valueOf(hand.getProtOrder(protNo))}; | |
34 | 35 | sendLog(log); |
35 | 36 | } |
36 | 37 | sendStatus(); |
@@ -48,6 +48,9 @@ | ||
48 | 48 | case 'A': |
49 | 49 | rank = 1; |
50 | 50 | break; |
51 | + case 'T': | |
52 | + rank = 10; | |
53 | + break; | |
51 | 54 | default: |
52 | 55 | rank = s.charAt(1) - '0'; |
53 | 56 | break; |
@@ -137,7 +140,28 @@ | ||
137 | 140 | default: |
138 | 141 | break; |
139 | 142 | } |
140 | - sb.append(getRankString()); | |
143 | + switch(rank){ | |
144 | + case 1: | |
145 | + sb.append('A'); | |
146 | + break; | |
147 | + case 11: | |
148 | + sb.append('J'); | |
149 | + break; | |
150 | + case 12: | |
151 | + sb.append('Q'); | |
152 | + break; | |
153 | + case 13: | |
154 | + sb.append('K'); | |
155 | + break; | |
156 | + case 10: | |
157 | + sb.append('T'); | |
158 | + break; | |
159 | + case 0: // ジョーカー | |
160 | + sb.append("JK"); | |
161 | + break; | |
162 | + default: | |
163 | + sb.append(String.valueOf(rank)); | |
164 | + } | |
141 | 165 | return sb.toString(); |
142 | 166 | } |
143 | 167 |
@@ -21,8 +21,13 @@ | ||
21 | 21 | return plotList.remove(index); |
22 | 22 | } |
23 | 23 | |
24 | - public boolean remove(Object o) { | |
25 | - return plotList.remove(o); | |
24 | + public boolean remove(Card card) { | |
25 | + for (Plot plot : plotList) { | |
26 | + if(plot.getCard().equals(card)){ | |
27 | + return plotList.remove(plot); | |
28 | + } | |
29 | + } | |
30 | + return false; | |
26 | 31 | } |
27 | 32 | |
28 | 33 | public int size() { |
@@ -123,9 +123,12 @@ | ||
123 | 123 | index = i; |
124 | 124 | } |
125 | 125 | } |
126 | - if(max >= columnCount){ | |
126 | + if(max >= DEFAULT_COLUMN_COUNT){ | |
127 | 127 | columnCount = max + 1; |
128 | 128 | longestRow = index; |
129 | + } else { | |
130 | + columnCount = DEFAULT_COLUMN_COUNT; | |
131 | + longestRow = -1; | |
129 | 132 | } |
130 | 133 | fireTableStructureChanged(); |
131 | 134 | } else { |
@@ -148,7 +151,11 @@ | ||
148 | 151 | public Plot getPlot(int charaNo, int index){ |
149 | 152 | for (PlotChara chara : plotList) { |
150 | 153 | if(chara.getCharaNo() == charaNo){ |
151 | - return chara.get(index); | |
154 | + if(chara.size() > index){ | |
155 | + return chara.get(index); | |
156 | + } else { | |
157 | + return null; | |
158 | + } | |
152 | 159 | } |
153 | 160 | } |
154 | 161 | return null; |
@@ -164,6 +171,10 @@ | ||
164 | 171 | } |
165 | 172 | |
166 | 173 | public PlotChara indexOf(int index){ |
167 | - return plotList.get(index); | |
174 | + if(plotList.size() <= index){ | |
175 | + return null; | |
176 | + } else { | |
177 | + return plotList.get(index); | |
178 | + } | |
168 | 179 | } |
169 | 180 | } |
@@ -53,7 +53,11 @@ | ||
53 | 53 | } else { |
54 | 54 | setBorder(border); |
55 | 55 | } |
56 | - setIcon(icons[card.getSuite()]); | |
56 | + if(card.isJoker()){ | |
57 | + setIcon(null); | |
58 | + } else { | |
59 | + setIcon(icons[card.getSuite()]); | |
60 | + } | |
57 | 61 | setText("<html><font color=\"#" + (card.isRed() ? "ff0000" : "000000") + "\">" + card.getRankString() + "</font></html>"); |
58 | 62 | } |
59 | 63 | return comp; |
@@ -5,6 +5,8 @@ | ||
5 | 5 | import java.awt.GridBagConstraints; |
6 | 6 | import java.awt.GridBagLayout; |
7 | 7 | import java.awt.Insets; |
8 | +import java.awt.event.ActionEvent; | |
9 | +import java.awt.event.ActionListener; | |
8 | 10 | |
9 | 11 | import javax.swing.ActionMap; |
10 | 12 | import javax.swing.BorderFactory; |
@@ -16,6 +18,7 @@ | ||
16 | 18 | import javax.swing.JPanel; |
17 | 19 | import javax.swing.JScrollPane; |
18 | 20 | import javax.swing.JTable; |
21 | +import javax.swing.SwingUtilities; | |
19 | 22 | import javax.swing.border.BevelBorder; |
20 | 23 | import javax.swing.event.TableModelEvent; |
21 | 24 | import javax.swing.event.TableModelListener; |
@@ -153,6 +156,13 @@ | ||
153 | 156 | handList.setVisibleRowCount(0); |
154 | 157 | handList.setCellRenderer(getCardListRenderer()); |
155 | 158 | handList.setModel(getCardListModel()); |
159 | + handList.addMouseListener(new java.awt.event.MouseAdapter() { | |
160 | + public void mouseClicked(java.awt.event.MouseEvent e) { | |
161 | + if(e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)){ | |
162 | + actionMap.get("handToPile").actionPerformed(new ActionEvent(getHandList(),ActionEvent.ACTION_PERFORMED , "handToPile")); | |
163 | + } | |
164 | + } | |
165 | + }); | |
156 | 166 | handList.setLayoutOrientation(JList.HORIZONTAL_WRAP); |
157 | 167 | |
158 | 168 | } |
@@ -179,10 +189,10 @@ | ||
179 | 189 | private DefaultListModel getCardListModel() { |
180 | 190 | if (cardListModel == null) { |
181 | 191 | cardListModel = new DefaultListModel(); |
182 | - cardListModel.addElement(new Card(0, 10)); | |
183 | - cardListModel.addElement(new Card(1, 1)); | |
184 | - cardListModel.addElement(new Card(2, 3)); | |
185 | - cardListModel.addElement(new Card(3, 13)); | |
192 | +// cardListModel.addElement(new Card(0, 10)); | |
193 | +// cardListModel.addElement(new Card(1, 1)); | |
194 | +// cardListModel.addElement(new Card(2, 3)); | |
195 | +// cardListModel.addElement(new Card(3, 13)); | |
186 | 196 | } |
187 | 197 | return cardListModel; |
188 | 198 | } |
@@ -260,27 +270,26 @@ | ||
260 | 270 | plotTable.setShowVerticalLines(false); |
261 | 271 | plotTable.setRowHeight(48); |
262 | 272 | plotTable.setColumnSelectionAllowed(true); |
263 | - TableColumnModel tcm = plotTable.getColumnModel(); | |
264 | - TableColumn c0 = tcm.getColumn(0); | |
265 | - c0.setPreferredWidth(30); | |
266 | -// c0.setCellRenderer(getProtTableCellRenderer()); | |
267 | - TableColumn c1 = tcm.getColumn(1); | |
268 | - c1.setPreferredWidth(60); | |
269 | - c1.setCellRenderer(getPlotTableCellRenderer()); | |
270 | - TableColumn c2 = tcm.getColumn(2); | |
271 | - c2.setPreferredWidth(60); | |
272 | - c2.setCellRenderer(getPlotTableCellRenderer()); | |
273 | - TableColumn c3 = tcm.getColumn(3); | |
274 | - c3.setPreferredWidth(60); | |
275 | - c3.setCellRenderer(getPlotTableCellRenderer()); | |
276 | - TableColumn c4 = tcm.getColumn(4); | |
277 | - c4.setPreferredWidth(60); | |
278 | - c4.setCellRenderer(getPlotTableCellRenderer()); | |
273 | + setTableRenderer(); | |
279 | 274 | } |
280 | 275 | return plotTable; |
281 | 276 | } |
282 | 277 | |
283 | 278 | /** |
279 | + * | |
280 | + */ | |
281 | + private void setTableRenderer() { | |
282 | + TableColumnModel tcm = plotTable.getColumnModel(); | |
283 | + TableColumn c0 = tcm.getColumn(0); | |
284 | + c0.setPreferredWidth(25); | |
285 | + for(int i = 1; i < tcm.getColumnCount(); i++){ | |
286 | + TableColumn column = tcm.getColumn(i); | |
287 | + column.setPreferredWidth(60); | |
288 | + column.setCellRenderer(getPlotTableCellRenderer()); | |
289 | + } | |
290 | + } | |
291 | + | |
292 | + /** | |
284 | 293 | * This method initializes plotTableModel |
285 | 294 | * |
286 | 295 | * @return etude.swing.ProtTableModel |
@@ -288,29 +297,21 @@ | ||
288 | 297 | public PlotTableModel getPlotTableModel() { |
289 | 298 | if (plotTableModel == null) { |
290 | 299 | plotTableModel = new PlotTableModel(); |
291 | - PlotChara c1 = new PlotChara(); | |
292 | - c1.setCharaNo(1); | |
293 | - c1.add(new Plot(new Card(1, 4), 1, false)); | |
294 | - c1.add(new Plot(new Card(2, 9), 1, false)); | |
295 | - PlotChara c2 = new PlotChara(); | |
296 | - c2.setCharaNo(2); | |
297 | - c2.add(new Plot(new Card(1, 1), 2, false)); | |
298 | - c2.add(new Plot(new Card(3, 12), 2, true)); | |
299 | - c2.add(new Plot(new Card(2, 11), 2, false)); | |
300 | - plotTableModel.add(c1); | |
301 | - plotTableModel.add(c2); | |
300 | +// PlotChara c1 = new PlotChara(); | |
301 | +// c1.setCharaNo(1); | |
302 | +// c1.add(new Plot(new Card(1, 4), 1, false)); | |
303 | +// c1.add(new Plot(new Card(2, 9), 1, false)); | |
304 | +// PlotChara c2 = new PlotChara(); | |
305 | +// c2.setCharaNo(2); | |
306 | +// c2.add(new Plot(new Card(1, 1), 2, false)); | |
307 | +// c2.add(new Plot(new Card(3, 12), 2, true)); | |
308 | +// c2.add(new Plot(new Card(2, 11), 2, false)); | |
309 | +// plotTableModel.add(c1); | |
310 | +// plotTableModel.add(c2); | |
302 | 311 | plotTableModel.addTableModelListener(new TableModelListener(){ |
303 | 312 | public void tableChanged(TableModelEvent e) { |
304 | 313 | if(e.getFirstRow() == TableModelEvent.HEADER_ROW){ |
305 | - int column = e.getColumn(); | |
306 | - if(column != TableModelEvent.ALL_COLUMNS){ | |
307 | - TableColumnModel tcm = getPlotTable().getColumnModel(); | |
308 | - if(tcm.getColumnCount() < column){ | |
309 | - TableColumn cm = tcm.getColumn(column); | |
310 | - cm.setPreferredWidth(60); | |
311 | - cm.setCellRenderer(getPlotTableCellRenderer()); | |
312 | - } | |
313 | - } | |
314 | + setTableRenderer(); | |
314 | 315 | } |
315 | 316 | } |
316 | 317 | }); |
@@ -602,6 +603,11 @@ | ||
602 | 603 | if (removeCharacterButton == null) { |
603 | 604 | removeCharacterButton = new JButton(); |
604 | 605 | removeCharacterButton.setText("プロットを削除"); |
606 | + removeCharacterButton.addActionListener(new ActionListener(){ | |
607 | + public void actionPerformed(ActionEvent e) { | |
608 | + actionMap.get("removeCharacter").actionPerformed(e); | |
609 | + } | |
610 | + }); | |
605 | 611 | } |
606 | 612 | return removeCharacterButton; |
607 | 613 | } |
@@ -648,6 +654,7 @@ | ||
648 | 654 | */ |
649 | 655 | public void setGM(boolean gm) { |
650 | 656 | getSceneButton().setEnabled(gm); |
657 | + getInitButton().setEnabled(gm); | |
651 | 658 | } |
652 | 659 | |
653 | 660 | /** |
@@ -654,7 +661,7 @@ | ||
654 | 661 | * @see jp.sf.chaplet.core.ui.IPluginView#setLoginOK(boolean) |
655 | 662 | */ |
656 | 663 | public void setLoginOK(boolean ok) { |
657 | - getSceneButton().setEnabled(ok); | |
664 | +// getSceneButton().setEnabled(ok); | |
658 | 665 | getToHandButton().setEnabled(ok); |
659 | 666 | getFeedButton().setEnabled(ok); |
660 | 667 | getYamabikiButton().setEnabled(ok); |
@@ -668,13 +675,21 @@ | ||
668 | 675 | * @see jp.sf.chaplet.nova.ui.INovaView#addPlot(int, java.lang.String[]) |
669 | 676 | */ |
670 | 677 | public void addPlot(int plotNo, String[] plots) { |
671 | - PlotChara chara = new PlotChara(); | |
678 | + final PlotChara chara = new PlotChara(); | |
672 | 679 | chara.setCharaNo(plotNo); |
673 | - for (String s : plots) { | |
674 | - Plot plot = new Plot(new Card(s), plotNo, false); | |
675 | - chara.add(plot); | |
680 | + if(plots != null){ | |
681 | + for (String s : plots) { | |
682 | + Plot plot = new Plot(new Card(s), plotNo, false); | |
683 | + chara.add(plot); | |
684 | + } | |
676 | 685 | } |
677 | - getPlotTableModel().add(chara); | |
686 | + SwingUtilities.invokeLater(new Runnable() { | |
687 | + public void run() { | |
688 | + int row = getPlotTable().getSelectedRow(); | |
689 | + getPlotTableModel().add(chara); | |
690 | + getPlotTable().getSelectionModel().addSelectionInterval(row, row); | |
691 | + } | |
692 | + }); | |
678 | 693 | } |
679 | 694 | |
680 | 695 | /** |
@@ -696,38 +711,65 @@ | ||
696 | 711 | /** |
697 | 712 | * @see jp.sf.chaplet.nova.ui.INovaView#moveToPlot(int, java.lang.String) |
698 | 713 | */ |
699 | - public void moveToPlot(int charaNo, String card) { | |
700 | - getPlotTableModel().add(charaNo, new Card(card)); | |
714 | + public void moveToPlot(final int charaNo, String cardStr) { | |
715 | + final Card card = new Card(cardStr); | |
716 | + SwingUtilities.invokeLater(new Runnable() { | |
717 | + public void run() { | |
718 | + int row = getPlotTable().getSelectedRow(); | |
719 | + getPlotTableModel().add(charaNo, card); | |
720 | + getCardListModel().removeElement(card); | |
721 | + getPlotTable().getSelectionModel().addSelectionInterval(row, row); | |
722 | + getPlotTable().getColumnModel().getSelectionModel().addSelectionInterval(0, 0); | |
723 | + } | |
724 | + }); | |
701 | 725 | } |
702 | 726 | |
703 | 727 | /** |
704 | 728 | * @see jp.sf.chaplet.nova.ui.INovaView#removeFromPlot(int, java.lang.String) |
705 | 729 | */ |
706 | - public void removeFromPlot(int charaNo, String card) { | |
707 | - getPlotTableModel().remove(charaNo, new Card(card)); | |
730 | + public void removeFromPlot(final int charaNo, final String card) { | |
731 | + SwingUtilities.invokeLater(new Runnable() { | |
732 | + public void run() { | |
733 | + getPlotTableModel().remove(charaNo, new Card(card)); | |
734 | + } | |
735 | + }); | |
708 | 736 | } |
709 | 737 | |
710 | 738 | /** |
711 | 739 | * @see jp.sf.chaplet.nova.ui.INovaView#removePlot(int) |
712 | 740 | */ |
713 | - public void removePlot(int charaNo) { | |
714 | - getPlotTableModel().remove(charaNo); | |
741 | + public void removePlot(final int charaNo) { | |
742 | + SwingUtilities.invokeLater(new Runnable() { | |
743 | + public void run() { | |
744 | + getPlotTableModel().remove(charaNo); | |
745 | + } | |
746 | + }); | |
715 | 747 | } |
716 | 748 | |
717 | 749 | /** |
718 | 750 | * @see jp.sf.chaplet.nova.ui.INovaView#setHand(java.lang.String[]) |
719 | 751 | */ |
720 | - public void setHand(String[] hands) { | |
721 | - getCardListModel().removeAllElements(); | |
722 | - for (String s : hands) { | |
723 | - getCardListModel().addElement(new Card(s)); | |
724 | - } | |
752 | + public void setHand(final String[] hands) { | |
753 | + SwingUtilities.invokeLater(new Runnable() { | |
754 | + public void run() { | |
755 | + getCardListModel().removeAllElements(); | |
756 | + if (hands != null) { | |
757 | + for (String s : hands) { | |
758 | + getCardListModel().addElement(new Card(s)); | |
759 | + } | |
760 | + } | |
761 | + } | |
762 | + }); | |
725 | 763 | } |
726 | 764 | |
727 | 765 | /** |
728 | 766 | * @see jp.sf.chaplet.nova.ui.INovaView#setSceneCard(java.lang.String) |
729 | 767 | */ |
730 | - public void setSceneCard(String scene) { | |
731 | - sceneLabel.setText(scene); | |
768 | + public void setSceneCard(final String scene) { | |
769 | + SwingUtilities.invokeLater(new Runnable() { | |
770 | + public void run() { | |
771 | + sceneLabel.setText(scene); | |
772 | + } | |
773 | + }); | |
732 | 774 | } |
733 | 775 | } // @jve:decl-index=0:visual-constraint="10,10" |
@@ -117,8 +117,15 @@ | ||
117 | 117 | * @param index プロットの順番 |
118 | 118 | */ |
119 | 119 | @Action |
120 | - public void removeCharacter(int index) { | |
121 | - getConnection().sendMessage(new String[]{"nova:delchara", String.valueOf(index)}); | |
120 | + public void removeCharacter() { | |
121 | + int rowIndex = view.getPlotTable().getSelectedRow(); | |
122 | + if(rowIndex < 0){ | |
123 | + return; | |
124 | + } | |
125 | + PlotChara chara = view.getPlotTableModel().indexOf(rowIndex); | |
126 | + if(chara != null){ | |
127 | + getConnection().sendMessage(new String[]{"nova:delchara", String.valueOf(chara.getCharaNo())}); | |
128 | + } | |
122 | 129 | } |
123 | 130 | |
124 | 131 | /** |
@@ -146,7 +153,9 @@ | ||
146 | 153 | return; |
147 | 154 | } |
148 | 155 | PlotChara chara = view.getPlotTableModel().indexOf(rowIndex); |
149 | - getConnection().sendMessage(new String[]{"nova:toplot", String.valueOf(chara.getCharaNo()), card.toString()}); | |
156 | + if(chara != null){ | |
157 | + getConnection().sendMessage(new String[]{"nova:toplot", String.valueOf(chara.getCharaNo()), card.toString()}); | |
158 | + } | |
150 | 159 | } |
151 | 160 | |
152 | 161 | /** |
@@ -164,14 +173,16 @@ | ||
164 | 173 | return; |
165 | 174 | } |
166 | 175 | PlotChara chara = view.getPlotTableModel().indexOf(rowIndex); |
176 | + | |
167 | 177 | int columnIndex = view.getPlotTable().getSelectedColumn(); |
168 | 178 | if(columnIndex <= 0){ |
169 | 179 | return; |
170 | 180 | } |
171 | 181 | Plot plot = view.getPlotTableModel().getPlot(chara.getCharaNo(), columnIndex - 1); |
172 | - | |
173 | - String[] message= new String[]{"nova:plottopile", String.valueOf(chara.getCharaNo()), plot.getCard().toString()}; | |
174 | - getConnection().sendMessage(message); | |
182 | + if(plot != null){ | |
183 | + String[] message= new String[]{"nova:plottopile", String.valueOf(chara.getCharaNo()), plot.getCard().toString()}; | |
184 | + getConnection().sendMessage(message); | |
185 | + } | |
175 | 186 | } |
176 | 187 | |
177 | 188 | /** |
@@ -18,7 +18,7 @@ | ||
18 | 18 | * @see jp.sf.chaplet.core.client.ClientAction#messageRecieved(java.lang.String[]) |
19 | 19 | */ |
20 | 20 | public ActionResult messageRecieved(String[] message) { |
21 | - appendFunctionLog("カード機能", message[1], "手札から " + NovaUtil.toVisibleStyle(message[2])); | |
21 | + appendFunctionLog("カード機能", message[1], NovaUtil.toVisibleStyle(message[2]) + " (手札から)"); | |
22 | 22 | return ActionResult.OK_NEXT; |
23 | 23 | } |
24 | 24 |
@@ -19,7 +19,7 @@ | ||
19 | 19 | */ |
20 | 20 | public ActionResult messageRecieved(String[] message) { |
21 | 21 | appendFunctionLog("カード機能", message[1], |
22 | - "プロット("+ message[3] +")から " + NovaUtil.toVisibleStyle(message[2])); | |
22 | + NovaUtil.toVisibleStyle(message[2]) + "(プロット["+ message[3] +"]から)"); | |
23 | 23 | return ActionResult.OK_NEXT; |
24 | 24 | } |
25 | 25 |
@@ -57,9 +57,9 @@ | ||
57 | 57 | return null; |
58 | 58 | } |
59 | 59 | |
60 | - public User getUser(String account){ | |
60 | + public User getUser(String sessionId){ | |
61 | 61 | for (User user : userList){ |
62 | - if(user.getName().equals(account)){ | |
62 | + if(user.getSessionId().equals(sessionId)){ | |
63 | 63 | return user; |
64 | 64 | } |
65 | 65 | } |
@@ -87,4 +87,9 @@ | ||
87 | 87 | userList.add(user); |
88 | 88 | } |
89 | 89 | } |
90 | + | |
91 | + public String getName(String sessionId){ | |
92 | + User user = getUser(sessionId); | |
93 | + return user != null ? user.getName() : ""; | |
94 | + } | |
90 | 95 | } |