diff --git a/src/java/com/threerings/micasa/lobby/table/TableListView.java b/src/java/com/threerings/micasa/lobby/table/TableListView.java index 5664aaf19..4c5be67ee 100644 --- a/src/java/com/threerings/micasa/lobby/table/TableListView.java +++ b/src/java/com/threerings/micasa/lobby/table/TableListView.java @@ -40,14 +40,14 @@ import com.threerings.micasa.Log; import com.threerings.micasa.lobby.LobbyConfig; import com.threerings.micasa.util.MiCasaContext; -import com.threerings.parlor.client.GameConfigurator; import com.threerings.parlor.client.SeatednessObserver; +import com.threerings.parlor.client.TableConfigurator; import com.threerings.parlor.client.TableDirector; import com.threerings.parlor.client.TableObserver; import com.threerings.parlor.data.Table; -import com.threerings.parlor.data.TableConfigurator; +import com.threerings.parlor.game.client.GameConfigurator; +import com.threerings.parlor.game.client.SwingGameConfigurator; import com.threerings.parlor.game.data.GameConfig; -import com.threerings.parlor.game.data.TableableGameConfig; import com.threerings.crowd.client.PlaceView; import com.threerings.crowd.data.PlaceObject; @@ -100,15 +100,22 @@ public class TableListView extends JPanel GameConfig gconfig = null; try { gconfig = config.getGameConfig(); - _tableFigger = - ((TableableGameConfig) gconfig).createTableConfigurator(_ctx); - panel.add((Component) _tableFigger, VGroupLayout.FIXED); + + _tableFigger = gconfig.createTableConfigurator(); + if (_tableFigger == null) { + Log.warning("Game config has not been set up to work with " + + "tables: it needs to return non-null from " + + "createTableConfigurator()."); + // let's just wait until we throw an NPE below + } _figger = gconfig.createConfigurator(); + _tableFigger.init(_ctx, _figger); if (_figger != null) { _figger.init(_ctx); _figger.setGameConfig(gconfig); - panel.add(_figger, VGroupLayout.FIXED); + panel.add(((SwingGameConfigurator) _figger).getPanel(), + VGroupLayout.FIXED); } _create = new JButton("Create table"); diff --git a/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java b/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java index f6c0570c1..352a67449 100644 --- a/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java +++ b/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java @@ -22,80 +22,100 @@ package com.threerings.parlor.client; import javax.swing.JCheckBox; +import javax.swing.JLabel; import javax.swing.JPanel; import com.samskivert.swing.SimpleSlider; import com.samskivert.swing.VGroupLayout; -import com.threerings.parlor.data.TableConfigurator; import com.threerings.parlor.data.TableConfig; import com.threerings.parlor.util.ParlorContext; +import com.threerings.parlor.game.client.SwingGameConfigurator; +import com.threerings.parlor.game.data.GameConfig; /** * Provides a default implementation of a TableConfigurator for * a Swing interface. */ -public class DefaultSwingTableConfigurator extends JPanel - implements TableConfigurator +public class DefaultSwingTableConfigurator extends TableConfigurator { /** * Create a TableConfigurator that allows only the specified number * of players and lets the configuring user enable private games * only if the number of players is greater than 2. */ - public DefaultSwingTableConfigurator (ParlorContext ctx, int players) + public DefaultSwingTableConfigurator (int players) { - this(ctx, players, (players > 2)); + this(players, (players > 2)); } /** * Create a TableConfigurator that allows only the specified number * of players and lets the user configure a private table, or not. */ - public DefaultSwingTableConfigurator (ParlorContext ctx, int players, - boolean allowPrivate) + public DefaultSwingTableConfigurator (int players, boolean allowPrivate) { - this(ctx, players, players, players, allowPrivate); + this(players, players, players, allowPrivate); } /** * Create a TableConfigurator that allows for the specified configuration * parameters. */ - public DefaultSwingTableConfigurator (ParlorContext ctx, int minPlayers, + public DefaultSwingTableConfigurator (int minPlayers, int desiredPlayers, int maxPlayers, boolean allowPrivate) { - super(new VGroupLayout()); // TODO: layout improvement? - - // TODO: translations - _playerSlider = new SimpleSlider( - "Seats:", minPlayers, maxPlayers, desiredPlayers); - _privateCheck = new JCheckBox("Private?:"); - - // figure out what to actually show + // create a slider for players, if applicable if (minPlayers != maxPlayers) { - add(_playerSlider); + _playerSlider = new SimpleSlider( + "", minPlayers, maxPlayers, desiredPlayers); + + } else { + _config.desiredPlayerCount = desiredPlayers; } + + // create up the checkbox for private games, if applicable if (allowPrivate) { - add(_privateCheck); + _privateCheck = new JCheckBox(); } } - // documentation inherited from interface TableConfigurator + // documentation inherited + protected void createConfigInterface () + { + super.createConfigInterface(); + + SwingGameConfigurator gconf = (SwingGameConfigurator) _gameConfigurator; + + if (_playerSlider != null) { + // TODO: proper translation + gconf.addControl(new JLabel("Players:"), _playerSlider); + } + + if (_privateCheck != null) { + // TODO: proper translation + gconf.addControl(new JLabel("Private:"), _privateCheck); + } + } + + // documentation inherited public boolean isEmpty () { - return (getComponentCount() == 0); + return (_playerSlider == null) && (_privateCheck == null); } - // documentation inherited from interface TableConfigurator - public TableConfig getTableConfig () + // documentation inherited + protected void flushTableConfig() { - TableConfig tconfig = new TableConfig(); - tconfig.desiredPlayerCount = _playerSlider.getValue(); - tconfig.privateTable = _privateCheck.isSelected(); + super.flushTableConfig(); - return tconfig; + if (_playerSlider != null) { + _config.desiredPlayerCount = _playerSlider.getValue(); + } + if (_privateCheck != null) { + _config.privateTable = _privateCheck.isSelected(); + } } /** A slider for configuring the number of players at the table. */ diff --git a/src/java/com/threerings/parlor/client/TableConfigurator.java b/src/java/com/threerings/parlor/client/TableConfigurator.java new file mode 100644 index 000000000..6ba904fb2 --- /dev/null +++ b/src/java/com/threerings/parlor/client/TableConfigurator.java @@ -0,0 +1,108 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.parlor.client; + +import com.threerings.parlor.util.ParlorContext; + +import com.threerings.parlor.data.TableConfig; + +import com.threerings.parlor.game.client.GameConfigurator; + +/** + * This should be implemented some user-interface element that allows + * the user to configure whichever TableConfig options are relevant. + */ +public abstract class TableConfigurator +{ + /** + * Create a TableConfigurator. + */ + public TableConfigurator () + { + _config = createTableConfig(); + } + + /** + * Initialize the TableConfigurator. + * + * At the time this is called, the GameConfigurator should have + * already been initialized. + */ + public void init (ParlorContext ctx, GameConfigurator gameConfigurator) + { + _ctx = ctx; + _gameConfigurator = gameConfigurator; + createConfigInterface(); + } + + /** + * Create the table config object that will be used. + */ + protected TableConfig createTableConfig () + { + return new TableConfig(); + } + + /** + * Create the config interface. + */ + protected void createConfigInterface () + { + // nothing by default + } + + /** + * If true, the TableConfigurator is empty, which doesn't mean that + * it will not return a TableConfig object (for it must), but rather + * that there are no user-editable options being presented in the + * config interface. + */ + public abstract boolean isEmpty (); + + /** + * Return the fully configured table config according to the currently + * configured user interface elements. + */ + public TableConfig getTableConfig () + { + flushTableConfig(); + return _config; + } + + /** + * Derived classes will want to override this method, flushing + * values from the user interface to the table config object. + */ + protected void flushTableConfig () + { + // nothing by default + } + + /** Provides access to client services. */ + protected ParlorContext _ctx; + + /** The config we're configurating. */ + protected TableConfig _config; + + /** The game configurator, which we may wish to reference. */ + protected GameConfigurator _gameConfigurator; +} diff --git a/src/java/com/threerings/parlor/data/TableConfigurator.java b/src/java/com/threerings/parlor/data/TableConfigurator.java deleted file mode 100644 index f5af5cd6b..000000000 --- a/src/java/com/threerings/parlor/data/TableConfigurator.java +++ /dev/null @@ -1,42 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.parlor.data; - -/** - * This should be implemented some user-interface element that allows - * the user to configure whichever TableConfig options are relevant. - */ -public interface TableConfigurator -{ - /** - * If true, the tableConfigurator is empty, useful if the lobby code - * can skip the step of letting the table creator configure things - * if the game configurator is also empty. - */ - public boolean isEmpty (); - - /** - * Return the fully configured table config when the user is ready - * to create their table. - */ - public TableConfig getTableConfig (); -} diff --git a/src/java/com/threerings/parlor/game/client/GameConfigurator.java b/src/java/com/threerings/parlor/game/client/GameConfigurator.java new file mode 100644 index 000000000..4936b9f64 --- /dev/null +++ b/src/java/com/threerings/parlor/game/client/GameConfigurator.java @@ -0,0 +1,103 @@ +// +// $Id: GameConfigurator.java 3590 2005-06-08 23:20:18Z ray $ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.parlor.game.client; + +import com.threerings.parlor.game.data.GameConfig; +import com.threerings.parlor.util.ParlorContext; + +/** + * Provides the base from which interfaces can be built to configure games + * prior to starting them. Derived classes would extend the base + * configurator adding interface elements and wiring them up properly to + * allow the user to configure an instance of their game. + * + *

Clients that use the game configurator will want to instantiate one + * based on the class returned from the {@link GameConfig} and then + * initialize it with a call to {@link #init}. + */ +public abstract class GameConfigurator +{ + /** + * Initializes this game configurator, creates its user interface + * elements and prepares it for display. + */ + public void init (ParlorContext ctx) + { + // save this for later + _ctx = ctx; + + // create our interface elements + createConfigInterface(); + } + + /** + * The default implementation creates nothing. + */ + protected void createConfigInterface () + { + } + + /** + * Provides this configurator with its configuration. It should set up + * all of its user interface elements to reflect the configuration. + */ + public void setGameConfig (GameConfig config) + { + _config = config; + // set up the user interface + gotGameConfig(); + } + + /** + * Derived classes will likely want to override this method and + * configure their user interface elements accordingly. + */ + protected void gotGameConfig () + { + } + + /** + * Obtains a configured game configuration. + */ + public GameConfig getGameConfig () + { + // flush our changes to the config object + flushGameConfig(); + return _config; + } + + /** + * Derived classes will want to override this method, flushing values + * from the user interface to the game config object so that it is + * properly configured prior to being returned to the {@link + * #getGameConfig} caller. + */ + protected void flushGameConfig () + { + } + + /** Provides access to client services. */ + protected ParlorContext _ctx; + + /** Our game configuration. */ + protected GameConfig _config; +} diff --git a/src/java/com/threerings/parlor/client/GameConfigurator.java b/src/java/com/threerings/parlor/game/client/SwingGameConfigurator.java similarity index 64% rename from src/java/com/threerings/parlor/client/GameConfigurator.java rename to src/java/com/threerings/parlor/game/client/SwingGameConfigurator.java index f700caa20..92478142b 100644 --- a/src/java/com/threerings/parlor/client/GameConfigurator.java +++ b/src/java/com/threerings/parlor/game/client/SwingGameConfigurator.java @@ -1,5 +1,5 @@ // -// $Id$ +// $Id: GameConfigurator.java 3590 2005-06-08 23:20:18Z ray $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -19,7 +19,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -package com.threerings.parlor.client; +package com.threerings.parlor.game.client; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -43,64 +43,14 @@ import com.threerings.parlor.util.ParlorContext; * based on the class returned from the {@link GameConfig} and then * initialize it with a call to {@link #init}. */ -public class GameConfigurator extends JPanel +public abstract class SwingGameConfigurator extends GameConfigurator { - // initializer - { - // BACKcompatible, older code (and toybox) expects the layout - // to be a vgroup, so we default to that - VGroupLayout layout = new VGroupLayout(VGroupLayout.NONE); - layout.setOffAxisPolicy(VGroupLayout.STRETCH); - setLayout(layout); - } - /** - * Initializes this game configurator, creates its user interface - * elements and prepares it for display. + * Get the Swing JPanel that contains the UI elements for this configurator. */ - public void init (ParlorContext ctx) + public JPanel getPanel () { - // save this for later - _ctx = ctx; - - // create our interface elements - createConfigInterface(); - } - - /** - * The default implementation creates nothing. - */ - protected void createConfigInterface () - { - } - - /** - * Provides this configurator with its configuration. It should set up - * all of its user interface elements to reflect the configuration. - */ - public void setGameConfig (GameConfig config) - { - _config = config; - // set up the user interface - gotGameConfig(); - } - - /** - * Derived classes will likely want to override this method and - * configure their user interface elements accordingly. - */ - protected void gotGameConfig () - { - } - - /** - * Obtains a configured game configuration. - */ - public GameConfig getGameConfig () - { - // flush our changes to the config object - flushGameConfig(); - return _config; + return _panel; } /** @@ -114,8 +64,8 @@ public class GameConfigurator extends JPanel { // BACKcompatible, newer code will call this method, and so // we need to switch the layout to gridbag instead of vgroup - if (!(getLayout() instanceof GridBagLayout)) { - setLayout(new GridBagLayout()); + if (!(_panel.getLayout() instanceof GridBagLayout)) { + _panel.setLayout(new GridBagLayout()); } // Set up the constraints. There's really no point in saving @@ -133,26 +83,21 @@ public class GameConfigurator extends JPanel cc.gridwidth = GridBagConstraints.REMAINDER; // add the components - add(label, lc); - add(control, cc); + _panel.add(label, lc); + _panel.add(control, cc); } - /** - * Derived classes will want to override this method, flushing values - * from the user interface to the game config object so that it is - * properly configured prior to being returned to the {@link - * #getGameConfig} caller. - */ - protected void flushGameConfig () - { + /** The panel on which the config options are placed. */ + protected JPanel _panel = new JPanel(); + + { // initializer + // BACKcompatible, older code (and toybox) expects the layout + // to be a vgroup, so we default to that + VGroupLayout layout = new VGroupLayout(VGroupLayout.NONE); + layout.setOffAxisPolicy(VGroupLayout.STRETCH); + _panel.setLayout(layout); } - /** Provides access to client services. */ - protected ParlorContext _ctx; - - /** Our game configuration. */ - protected GameConfig _config; - /** Insets for configuration labels. */ protected Insets _labelInsets = new Insets(1, 0, 1, 4); diff --git a/src/java/com/threerings/parlor/game/data/GameConfig.java b/src/java/com/threerings/parlor/game/data/GameConfig.java index 89708e54e..3b0f2a515 100644 --- a/src/java/com/threerings/parlor/game/data/GameConfig.java +++ b/src/java/com/threerings/parlor/game/data/GameConfig.java @@ -27,7 +27,8 @@ import java.util.List; import com.threerings.crowd.data.PlaceConfig; import com.threerings.util.Name; -import com.threerings.parlor.client.GameConfigurator; +import com.threerings.parlor.client.TableConfigurator; +import com.threerings.parlor.game.client.GameConfigurator; /** * The game config class encapsulates the configuration information for a @@ -75,6 +76,15 @@ public abstract class GameConfig extends PlaceConfig implements Cloneable */ public abstract GameConfigurator createConfigurator (); + /** + * Creates a table configurator for initializing 'table' properties + * of the game. The default implementation returns null. + */ + public TableConfigurator createTableConfigurator () + { + return null; + } + /** * Returns a translatable label describing this game. */ diff --git a/src/java/com/threerings/parlor/game/data/TableableGameConfig.java b/src/java/com/threerings/parlor/game/data/TableableGameConfig.java deleted file mode 100644 index 1aff014a1..000000000 --- a/src/java/com/threerings/parlor/game/data/TableableGameConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.parlor.game.data; - -import com.threerings.parlor.data.TableConfigurator; -import com.threerings.parlor.util.ParlorContext; - -/** - * An interface to be implemented by GameConfigs if they want to be - * able to use Table matchmaking services. - */ -public interface TableableGameConfig -{ - /** - * Called when this GameConfig is to be used for Table matchmaking, - * returns the TableConfigurator to be used to configure the Table. - */ - public TableConfigurator createTableConfigurator (ParlorContext ctx); -}