• R/O
  • SSH
  • HTTPS

chaplet: 提交


Commit MetaInfo

修訂27 (tree)
時間2007-06-19 23:21:35
作者koe

Log Message

手札からの判定、プロットの追加と削除、プロットからの判定を実装

Change Summary

差異

--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/server/YamabikiAction.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/server/YamabikiAction.java (revision 27)
@@ -21,10 +21,11 @@
2121 /**
2222 * @see jp.sf.chaplet.core.server.ServerAction#execute(java.lang.String[], jp.sf.chaplet.core.server.ClientProxy)
2323 */
24- public ActionResult execute(String[] request, ClientProxy invoker)
24+ public ActionResult execute(String[] request, ClientProxy proxy)
2525 throws IOException {
2626 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};
2829 sendLog(log);
2930 return ActionResult.OK_NEXT;
3031 }
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/server/HandToPileAction.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/server/HandToPileAction.java (revision 27)
@@ -36,7 +36,8 @@
3636 }
3737 proxy.sendMessage(resp);
3838 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]};
4041 sendLog(log);
4142 }
4243 return ActionResult.OK_NEXT;
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/server/PlotToPileAction.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/server/PlotToPileAction.java (revision 27)
@@ -27,10 +27,11 @@
2727 Hand hand = ((NovaServerPlugin)getPlugin()).getHandManager().getHandOf(proxy.getSessionId());
2828 int protNo = Integer.parseInt(request[1]);
2929 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]};
3132 proxy.sendMessage(resp);
3233 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))};
3435 sendLog(log);
3536 }
3637 sendStatus();
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/Card.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/Card.java (revision 27)
@@ -48,6 +48,9 @@
4848 case 'A':
4949 rank = 1;
5050 break;
51+ case 'T':
52+ rank = 10;
53+ break;
5154 default:
5255 rank = s.charAt(1) - '0';
5356 break;
@@ -137,7 +140,28 @@
137140 default:
138141 break;
139142 }
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+ }
141165 return sb.toString();
142166 }
143167
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/PlotChara.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/PlotChara.java (revision 27)
@@ -21,8 +21,13 @@
2121 return plotList.remove(index);
2222 }
2323
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;
2631 }
2732
2833 public int size() {
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/ui/PlotTableModel.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/ui/PlotTableModel.java (revision 27)
@@ -123,9 +123,12 @@
123123 index = i;
124124 }
125125 }
126- if(max >= columnCount){
126+ if(max >= DEFAULT_COLUMN_COUNT){
127127 columnCount = max + 1;
128128 longestRow = index;
129+ } else {
130+ columnCount = DEFAULT_COLUMN_COUNT;
131+ longestRow = -1;
129132 }
130133 fireTableStructureChanged();
131134 } else {
@@ -148,7 +151,11 @@
148151 public Plot getPlot(int charaNo, int index){
149152 for (PlotChara chara : plotList) {
150153 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+ }
152159 }
153160 }
154161 return null;
@@ -164,6 +171,10 @@
164171 }
165172
166173 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+ }
168179 }
169180 }
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/ui/CardListRenderer.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/ui/CardListRenderer.java (revision 27)
@@ -53,7 +53,11 @@
5353 } else {
5454 setBorder(border);
5555 }
56- setIcon(icons[card.getSuite()]);
56+ if(card.isJoker()){
57+ setIcon(null);
58+ } else {
59+ setIcon(icons[card.getSuite()]);
60+ }
5761 setText("<html><font color=\"#" + (card.isRed() ? "ff0000" : "000000") + "\">" + card.getRankString() + "</font></html>");
5862 }
5963 return comp;
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/ui/NovaView.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/ui/NovaView.java (revision 27)
@@ -5,6 +5,8 @@
55 import java.awt.GridBagConstraints;
66 import java.awt.GridBagLayout;
77 import java.awt.Insets;
8+import java.awt.event.ActionEvent;
9+import java.awt.event.ActionListener;
810
911 import javax.swing.ActionMap;
1012 import javax.swing.BorderFactory;
@@ -16,6 +18,7 @@
1618 import javax.swing.JPanel;
1719 import javax.swing.JScrollPane;
1820 import javax.swing.JTable;
21+import javax.swing.SwingUtilities;
1922 import javax.swing.border.BevelBorder;
2023 import javax.swing.event.TableModelEvent;
2124 import javax.swing.event.TableModelListener;
@@ -153,6 +156,13 @@
153156 handList.setVisibleRowCount(0);
154157 handList.setCellRenderer(getCardListRenderer());
155158 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+ });
156166 handList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
157167
158168 }
@@ -179,10 +189,10 @@
179189 private DefaultListModel getCardListModel() {
180190 if (cardListModel == null) {
181191 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));
186196 }
187197 return cardListModel;
188198 }
@@ -260,27 +270,26 @@
260270 plotTable.setShowVerticalLines(false);
261271 plotTable.setRowHeight(48);
262272 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();
279274 }
280275 return plotTable;
281276 }
282277
283278 /**
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+ /**
284293 * This method initializes plotTableModel
285294 *
286295 * @return etude.swing.ProtTableModel
@@ -288,29 +297,21 @@
288297 public PlotTableModel getPlotTableModel() {
289298 if (plotTableModel == null) {
290299 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);
302311 plotTableModel.addTableModelListener(new TableModelListener(){
303312 public void tableChanged(TableModelEvent e) {
304313 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();
314315 }
315316 }
316317 });
@@ -602,6 +603,11 @@
602603 if (removeCharacterButton == null) {
603604 removeCharacterButton = new JButton();
604605 removeCharacterButton.setText("プロットを削除");
606+ removeCharacterButton.addActionListener(new ActionListener(){
607+ public void actionPerformed(ActionEvent e) {
608+ actionMap.get("removeCharacter").actionPerformed(e);
609+ }
610+ });
605611 }
606612 return removeCharacterButton;
607613 }
@@ -648,6 +654,7 @@
648654 */
649655 public void setGM(boolean gm) {
650656 getSceneButton().setEnabled(gm);
657+ getInitButton().setEnabled(gm);
651658 }
652659
653660 /**
@@ -654,7 +661,7 @@
654661 * @see jp.sf.chaplet.core.ui.IPluginView#setLoginOK(boolean)
655662 */
656663 public void setLoginOK(boolean ok) {
657- getSceneButton().setEnabled(ok);
664+// getSceneButton().setEnabled(ok);
658665 getToHandButton().setEnabled(ok);
659666 getFeedButton().setEnabled(ok);
660667 getYamabikiButton().setEnabled(ok);
@@ -668,13 +675,21 @@
668675 * @see jp.sf.chaplet.nova.ui.INovaView#addPlot(int, java.lang.String[])
669676 */
670677 public void addPlot(int plotNo, String[] plots) {
671- PlotChara chara = new PlotChara();
678+ final PlotChara chara = new PlotChara();
672679 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+ }
676685 }
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+ });
678693 }
679694
680695 /**
@@ -696,38 +711,65 @@
696711 /**
697712 * @see jp.sf.chaplet.nova.ui.INovaView#moveToPlot(int, java.lang.String)
698713 */
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+ });
701725 }
702726
703727 /**
704728 * @see jp.sf.chaplet.nova.ui.INovaView#removeFromPlot(int, java.lang.String)
705729 */
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+ });
708736 }
709737
710738 /**
711739 * @see jp.sf.chaplet.nova.ui.INovaView#removePlot(int)
712740 */
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+ });
715747 }
716748
717749 /**
718750 * @see jp.sf.chaplet.nova.ui.INovaView#setHand(java.lang.String[])
719751 */
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+ });
725763 }
726764
727765 /**
728766 * @see jp.sf.chaplet.nova.ui.INovaView#setSceneCard(java.lang.String)
729767 */
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+ });
732774 }
733775 } // @jve:decl-index=0:visual-constraint="10,10"
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/client/NovaClientPlugin.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/client/NovaClientPlugin.java (revision 27)
@@ -117,8 +117,15 @@
117117 * @param index プロットの順番
118118 */
119119 @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+ }
122129 }
123130
124131 /**
@@ -146,7 +153,9 @@
146153 return;
147154 }
148155 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+ }
150159 }
151160
152161 /**
@@ -164,14 +173,16 @@
164173 return;
165174 }
166175 PlotChara chara = view.getPlotTableModel().indexOf(rowIndex);
176+
167177 int columnIndex = view.getPlotTable().getSelectedColumn();
168178 if(columnIndex <= 0){
169179 return;
170180 }
171181 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+ }
175186 }
176187
177188 /**
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/client/HandToPileAction.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/client/HandToPileAction.java (revision 27)
@@ -18,7 +18,7 @@
1818 * @see jp.sf.chaplet.core.client.ClientAction#messageRecieved(java.lang.String[])
1919 */
2020 public ActionResult messageRecieved(String[] message) {
21- appendFunctionLog("カード機能", message[1], "手札から " + NovaUtil.toVisibleStyle(message[2]));
21+ appendFunctionLog("カード機能", message[1], NovaUtil.toVisibleStyle(message[2]) + " (手札から)");
2222 return ActionResult.OK_NEXT;
2323 }
2424
--- chaplet/trunk/src/nova/jp/sf/chaplet/nova/client/PlotToPileAction.java (revision 26)
+++ chaplet/trunk/src/nova/jp/sf/chaplet/nova/client/PlotToPileAction.java (revision 27)
@@ -19,7 +19,7 @@
1919 */
2020 public ActionResult messageRecieved(String[] message) {
2121 appendFunctionLog("カード機能", message[1],
22- "プロット("+ message[3] +")から " + NovaUtil.toVisibleStyle(message[2]));
22+ NovaUtil.toVisibleStyle(message[2]) + "(プロット["+ message[3] +"]から)");
2323 return ActionResult.OK_NEXT;
2424 }
2525
--- chaplet/trunk/src/core/jp/sf/chaplet/core/server/UserManager.java (revision 26)
+++ chaplet/trunk/src/core/jp/sf/chaplet/core/server/UserManager.java (revision 27)
@@ -57,9 +57,9 @@
5757 return null;
5858 }
5959
60- public User getUser(String account){
60+ public User getUser(String sessionId){
6161 for (User user : userList){
62- if(user.getName().equals(account)){
62+ if(user.getSessionId().equals(sessionId)){
6363 return user;
6464 }
6565 }
@@ -87,4 +87,9 @@
8787 userList.add(user);
8888 }
8989 }
90+
91+ public String getName(String sessionId){
92+ User user = getUser(sessionId);
93+ return user != null ? user.getName() : "";
94+ }
9095 }
Show on old repository browser