プロットから手札に戻すアクションを実装
@@ -9,7 +9,6 @@ | ||
9 | 9 | |
10 | 10 | import jp.sf.chaplet.StorageUtils; |
11 | 11 | import jp.sf.chaplet.core.server.ClientProxy; |
12 | -import jp.sf.chaplet.core.server.ServerAction; | |
13 | 12 | import jp.sf.chaplet.core.server.ServerPlugin; |
14 | 13 | import jp.sf.chaplet.core.server.User; |
15 | 14 | import jp.sf.chaplet.nova.NovaConfig; |
@@ -56,41 +55,22 @@ | ||
56 | 55 | * @see jp.sf.chaplet.core.server.ServerPlugin#init() |
57 | 56 | */ |
58 | 57 | public void init() throws Exception { |
59 | -// tarotManager.setFileName(ConfigLoader.getInstance().getWorkDir() + | |
60 | -// System.getProperty("file.separator") + tarotManager.getFileName()); | |
61 | - ServerAction[] actions = new ServerAction[14]; | |
62 | - actions[0] = new LoginServerAction(); | |
63 | - actions[1] = new LogoutServerAction(); | |
64 | - actions[2] = new FeedAction(); | |
65 | - actions[3] = new HandToPileAction(); | |
66 | - actions[4] = new AddCharacterAction(); | |
67 | - actions[5] = new PlotToPileAction(); | |
68 | - actions[6] = new ReactionAction(); | |
69 | - actions[7] = new RemoveCharacterAction(); | |
70 | - actions[8] = new SceneAction(); | |
71 | - actions[9] = new ToPlotAction(); | |
72 | - actions[10] = new YamabikiAction(); | |
73 | - actions[11] = new GiveCardAction(); | |
74 | - actions[12] = new ExchangePlotAction(); | |
75 | - actions[13] = new InitializeAction(); | |
76 | - for (int i = 0; i < actions.length; i++) { | |
77 | - actions[i].init(server, this); | |
78 | - } | |
79 | - addAction("login", actions[0]); | |
80 | - addAction("logout", actions[1]); | |
81 | - addAction("nova:feed", actions[2]); | |
82 | - addAction("nova:handtopile", actions[3]); | |
83 | - addAction("nova:addchara", actions[4]); | |
84 | - addAction("nova:plottopile", actions[5]); | |
85 | - addAction("nova:reaction", actions[6]); | |
86 | - addAction("nova:delchara", actions[7]); | |
87 | - addAction("nova:scene", actions[8]); | |
88 | - addAction("nova:toplot", actions[9]); | |
89 | - addAction("nova:yamabiki", actions[10]); | |
90 | - addAction("nova:givecard", actions[11]); | |
91 | - addAction("nova:exchange", actions[12]); | |
92 | - addAction("nova:init", actions[13]); | |
93 | - addAction("nova:status", actions[0]); | |
58 | + LoginServerAction loginAction = new LoginServerAction(); | |
59 | + addAction("login", loginAction); | |
60 | + addAction("nova:status", loginAction); | |
61 | + addAction("logout", new LogoutServerAction()); | |
62 | + addAction("nova:feed", new FeedAction()); | |
63 | + addAction("nova:handtopile", new HandToPileAction()); | |
64 | + addAction("nova:addchara", new AddCharacterAction()); | |
65 | + addAction("nova:plottopile", new PlotToPileAction()); | |
66 | + addAction("nova:reaction", new ReactionAction()); | |
67 | + addAction("nova:delchara", new RemoveCharacterAction()); | |
68 | + addAction("nova:scene", new SceneAction()); | |
69 | + addAction("nova:toplot", new ToPlotAction()); | |
70 | + addAction("nova:yamabiki", new YamabikiAction()); | |
71 | + addAction("nova:givecard", new GiveCardAction()); | |
72 | + addAction("nova:tohand", new PlotToHandAction()); | |
73 | + addAction("nova:init", new InitializeAction()); | |
94 | 74 | |
95 | 75 | NovaConfig config = (NovaConfig) StorageUtils.load(NovaConfig.NAME, NovaConfig.class); |
96 | 76 | tarotManager.setConfig(config); |
@@ -0,0 +1,43 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.sf.chaplet.nova.server; | |
5 | + | |
6 | +import java.io.IOException; | |
7 | + | |
8 | +import jp.sf.chaplet.ActionResult; | |
9 | +import jp.sf.chaplet.core.server.ClientProxy; | |
10 | +import jp.sf.chaplet.core.server.ServerAction; | |
11 | + | |
12 | +/** | |
13 | + * PlotToHandAction。<br> | |
14 | + * <ol> | |
15 | + * <li> nova:tohand | |
16 | + * <li> [プロット番号] | |
17 | + * <li> カード | |
18 | + * </ol> | |
19 | + * @version $Id$ | |
20 | + */ | |
21 | +public class PlotToHandAction extends ServerAction { | |
22 | + | |
23 | + /** | |
24 | + * @see jp.sf.chaplet.core.server.ServerAction#execute(java.lang.String[], jp.sf.chaplet.core.server.ClientProxy) | |
25 | + */ | |
26 | + @Override | |
27 | + public ActionResult execute(String[] request, ClientProxy proxy) throws IOException { | |
28 | + int plotNo = Integer.parseInt(request[1]); | |
29 | + String card = request[2]; | |
30 | + NovaServerPlugin plugin = (NovaServerPlugin) getPlugin(); | |
31 | + Hand hand = plugin.getHandManager().getHandOf(proxy.getSessionId()); | |
32 | + hand.removeCard(plotNo, card); | |
33 | + hand.addCard(0, card); | |
34 | + String[] resp = new String[3]; | |
35 | + resp[0] = "ok/" + request[0]; | |
36 | + resp[1] = request[1]; | |
37 | + resp[2] = request[2]; | |
38 | + proxy.sendMessage(resp); | |
39 | + sendStatus(); | |
40 | + return ActionResult.OK_NEXT; | |
41 | + } | |
42 | + | |
43 | +} |
@@ -25,7 +25,7 @@ | ||
25 | 25 | throws IOException { |
26 | 26 | Hand hand = ((NovaServerPlugin)getPlugin()).getHandManager().getHandOf(proxy.getSessionId()); |
27 | 27 | hand.removeCard(0, request[1]); |
28 | - if(request.length == 2 || !request[2].equals("hidden")){ | |
28 | + if((request.length == 2 || !request[2].equals("hidden")) && hand.getCardCount(0) < 4){ | |
29 | 29 | hand.addCard(0, ((NovaServerPlugin)getPlugin()).getCardManager().next()); |
30 | 30 | } |
31 | 31 | String[] cards = hand.getHand(0); |
@@ -19,8 +19,15 @@ | ||
19 | 19 | */ |
20 | 20 | public abstract void addPlot(final int plotNo, final String[] prot); |
21 | 21 | |
22 | - public abstract void moveToPlot(final int plotNo, final String card); | |
22 | + public abstract void moveToPlot(final int plotNo, final String card); | |
23 | 23 | |
24 | + /** | |
25 | + * プロットから手札にカードを移動する。 | |
26 | + * @param plotNo 異動元のプロット番号 | |
27 | + * @param card カード | |
28 | + */ | |
29 | + public abstract void moveToHand(final int plotNo, final String card); | |
30 | + | |
24 | 31 | /** |
25 | 32 | * プロットからカードを捨てる。 |
26 | 33 | * @param plotNo プロット番号 |
@@ -122,7 +122,7 @@ | ||
122 | 122 | gridBagConstraints.weightx = 5.0; |
123 | 123 | gridBagConstraints.weighty = 1.0; |
124 | 124 | gridBagConstraints.gridx = 0; |
125 | - this.setSize(355, 322); | |
125 | + this.setSize(355, 360); | |
126 | 126 | this.setLayout(new GridBagLayout()); |
127 | 127 | this.add(getJScrollPane(), gridBagConstraints); |
128 | 128 | this.add(getButtonPanel(), gridBagConstraints1); |
@@ -422,7 +422,7 @@ | ||
422 | 422 | toHandButton.setText("△手札へ"); |
423 | 423 | toHandButton.addActionListener(new java.awt.event.ActionListener() { |
424 | 424 | public void actionPerformed(java.awt.event.ActionEvent e) { |
425 | - System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() | |
425 | + actionMap.get("plotToHand").actionPerformed(e); | |
426 | 426 | } |
427 | 427 | }); |
428 | 428 | } |
@@ -826,4 +826,17 @@ | ||
826 | 826 | } |
827 | 827 | }); |
828 | 828 | } |
829 | + | |
830 | + /** | |
831 | + * @see jp.sf.chaplet.nova.ui.INovaView#moveToHand(int, java.lang.String) | |
832 | + */ | |
833 | + public void moveToHand(final int plotNo, final String cardS) { | |
834 | + SwingUtilities.invokeLater(new Runnable() { | |
835 | + public void run() { | |
836 | + Card card = new Card(cardS); | |
837 | + getPlotTableModel().remove(plotNo, card); | |
838 | + getCardListModel().addElement(card); | |
839 | + } | |
840 | + }); | |
841 | + } | |
829 | 842 | } // @jve:decl-index=0:visual-constraint="10,10" |
@@ -8,7 +8,6 @@ | ||
8 | 8 | |
9 | 9 | import javax.swing.JPanel; |
10 | 10 | |
11 | -import jp.sf.chaplet.core.client.ClientAction; | |
12 | 11 | import jp.sf.chaplet.core.client.ClientPlugin; |
13 | 12 | import jp.sf.chaplet.core.ui.IPluginView; |
14 | 13 | import jp.sf.chaplet.core.ui.IPrefView; |
@@ -35,34 +34,18 @@ | ||
35 | 34 | */ |
36 | 35 | @Override |
37 | 36 | protected void startup() { |
38 | - ClientAction[] actions = new ClientAction[12]; | |
39 | - actions[0] = new AddCharacterAction(); | |
40 | - actions[1] = new FeedAction(); | |
41 | - actions[2] = new HandToPileAction(); | |
42 | - actions[3] = new PlotToPileAction(); | |
43 | - actions[4] = new ReactionAction(); | |
44 | - actions[5] = new RemoveCharacterAction(); | |
45 | - actions[6] = new SceneAction(); | |
46 | - actions[7] = new ToPlotAction(); | |
47 | - actions[8] = new YamabikiAction(); | |
48 | - actions[9] = new SetStatusAction(); | |
49 | - actions[10] = new GiveCardAction(); | |
50 | - actions[11] = new ExchangePlotAction(); | |
51 | - for (int i = 0; i < actions.length; i++) { | |
52 | - actions[i].init(getController(), this); | |
53 | - } | |
54 | - addAction("nova:addchara", actions[0]); | |
55 | - addAction("nova:feed", actions[1]); | |
56 | - addAction("nova:handtopile", actions[2]); | |
57 | - addAction("nova:plottopile", actions[3]); | |
58 | - addAction("nova:reaction", actions[4]); | |
59 | - addAction("nova:delchara", actions[5]); | |
60 | - addAction("nova:scene", actions[6]); | |
61 | - addAction("nova:toplot", actions[7]); | |
62 | - addAction("nova:yamabiki", actions[8]); | |
63 | - addAction("nova:status", actions[9]); | |
64 | - addAction("nova:givecard", actions[10]); | |
65 | - addAction("nova:exchange", actions[10]); | |
37 | + addAction("nova:addchara", new AddCharacterAction()); | |
38 | + addAction("nova:feed", new FeedAction()); | |
39 | + addAction("nova:handtopile", new HandToPileAction()); | |
40 | + addAction("nova:plottopile", new PlotToPileAction()); | |
41 | + addAction("nova:reaction", new ReactionAction()); | |
42 | + addAction("nova:delchara", new RemoveCharacterAction()); | |
43 | + addAction("nova:scene", new SceneAction()); | |
44 | + addAction("nova:toplot", new ToPlotAction()); | |
45 | + addAction("nova:yamabiki", new YamabikiAction()); | |
46 | + addAction("nova:status", new SetStatusAction()); | |
47 | + addAction("nova:givecard", new GiveCardAction()); | |
48 | + addAction("nova:tohand", new PlotToHandAction()); | |
66 | 49 | |
67 | 50 | view = new NovaView(); |
68 | 51 | view.setController(this); |
@@ -184,6 +167,28 @@ | ||
184 | 167 | getConnection().sendMessage(message); |
185 | 168 | } |
186 | 169 | } |
170 | + | |
171 | + @Action | |
172 | + public void plotToHand(){ | |
173 | + int rowIndex = view.getPlotTable().getSelectedRow(); | |
174 | + if(rowIndex < 0){ | |
175 | + rowIndex = 0; | |
176 | + } | |
177 | + if(view.getPlotTable().getRowCount() < rowIndex){ | |
178 | + return; | |
179 | + } | |
180 | + PlotChara chara = view.getPlotTableModel().indexOf(rowIndex); | |
181 | + | |
182 | + int columnIndex = view.getPlotTable().getSelectedColumn(); | |
183 | + if(columnIndex <= 0){ | |
184 | + return; | |
185 | + } | |
186 | + Plot plot = view.getPlotTableModel().getPlot(chara.getCharaNo(), columnIndex - 1); | |
187 | + if(plot != null){ | |
188 | + String[] message= new String[]{"nova:tohand", String.valueOf(chara.getCharaNo()), plot.getCard().toString()}; | |
189 | + getConnection().sendMessage(message); | |
190 | + } | |
191 | + } | |
187 | 192 | |
188 | 193 | /** |
189 | 194 | * プロットのカードをリアクション宣言する、またはリアクション宣言したカードを元に戻す。 |
@@ -19,7 +19,7 @@ | ||
19 | 19 | */ |
20 | 20 | public ActionResult messageRecieved(String[] message) { |
21 | 21 | appendFunctionLog("カード機能", message[1], |
22 | - "山引き " + NovaUtil.toVisibleStyle(message[2])); | |
22 | + NovaUtil.toVisibleStyle(message[2]) + " (山引き)"); | |
23 | 23 | return ActionResult.OK_NEXT; |
24 | 24 | } |
25 | 25 | } |
@@ -0,0 +1,28 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.sf.chaplet.nova.client; | |
5 | + | |
6 | +import jp.sf.chaplet.ActionResult; | |
7 | +import jp.sf.chaplet.core.client.ClientAction; | |
8 | + | |
9 | +/** | |
10 | + * PlotToHandAction<br> | |
11 | + * <ol> | |
12 | + * <li> ok/nova:tohand | |
13 | + * <li> [プロット番号] | |
14 | + * <li> カード | |
15 | + * </ol> | |
16 | + * @version $Id$ | |
17 | + */ | |
18 | +public class PlotToHandAction extends ClientAction { | |
19 | + /** | |
20 | + * @see jp.sf.chaplet.core.client.ClientAction#responseRecieved(java.lang.String[]) | |
21 | + */ | |
22 | + @Override | |
23 | + public ActionResult responseRecieved(String[] response) { | |
24 | + NovaClientPlugin plugin = (NovaClientPlugin) getPlugin(); | |
25 | + plugin.getNovaView().moveToHand(Integer.parseInt(response[1]), response[2]); | |
26 | + return ActionResult.OK_NEXT; | |
27 | + } | |
28 | +} |
@@ -64,6 +64,7 @@ | ||
64 | 64 | public ChatServer(String masterName){ |
65 | 65 | owner = masterName; |
66 | 66 | userManager.setMasterId(masterName); |
67 | + server = this; | |
67 | 68 | } |
68 | 69 | |
69 | 70 | /** |
@@ -66,6 +66,7 @@ | ||
66 | 66 | * @param action アクション |
67 | 67 | */ |
68 | 68 | protected void addAction(String name, ServerAction action){ |
69 | + action.init(server, this); | |
69 | 70 | actionMap.put(name, action); |
70 | 71 | } |
71 | 72 |
@@ -183,7 +183,15 @@ | ||
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | + * @see jp.sf.chaplet.core.client.ClientPlugin#getController() | |
186 | 187 | */ |
188 | + @Override | |
189 | + public ChatClient getController() { | |
190 | + return this; | |
191 | + } | |
192 | + | |
193 | + /** | |
194 | + */ | |
187 | 195 | private void init() throws IOException { |
188 | 196 | ApplicationContext context = ApplicationContext.getInstance(); |
189 | 197 | for (Plugin plugin : ConfigLoader.getInstance().load().getPlugins()) { |
@@ -63,6 +63,7 @@ | ||
63 | 63 | * @param action アクション |
64 | 64 | */ |
65 | 65 | protected void addAction(String name, ClientAction action) { |
66 | + action.init(getController(), this); | |
66 | 67 | actionMap.put(name, action); |
67 | 68 | } |
68 | 69 |