Added basic framework for providing game configuration interfaces that can

be used by a matchmaking interface when setting up a game.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1617 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-07-25 23:20:22 +00:00
parent d06aeb2cc7
commit b7b44f5f14
4 changed files with 191 additions and 56 deletions
@@ -0,0 +1,56 @@
//
// $Id: TableGameConfigurator.java,v 1.1 2002/07/25 23:20:22 mdb Exp $
package com.threerings.micasa.lobby.table;
import javax.swing.JPanel;
import javax.swing.JSlider;
import com.samskivert.swing.HGroupLayout;
import com.samskivert.swing.VGroupLayout;
import com.samskivert.swing.SimpleSlider;
import com.threerings.parlor.client.GameConfigurator;
import com.threerings.parlor.data.TableConfig;
import com.threerings.parlor.util.ParlorContext;
/**
* Extends the basic game configurator with elements to support the
* configuration of standard table game configurations.
*/
public class TableGameConfigurator extends GameConfigurator
{
// documentation inherited
protected void createConfigInterface ()
{
// create a slider and associated label for configuring the number
// of people at the table
add(_pslide = new SimpleSlider("Seats:", 0, 10, 0), VGroupLayout.FIXED);
// TODO: get a message bundle and translate "Seats"
}
// documentation inherited
protected void gotGameConfig ()
{
TableConfig tconfig = (TableConfig)_config;
// configure our slider
_pslide.setMinimum(tconfig.getMinimumPlayers());
_pslide.setMaximum(tconfig.getMaximumPlayers());
_pslide.setValue(tconfig.getDesiredPlayers());
// if the min == the max, hide the slider because it's pointless
_pslide.setVisible(tconfig.getMinimumPlayers() !=
tconfig.getMaximumPlayers());
}
// documentation inherited
protected void flushGameConfig ()
{
TableConfig tconfig = (TableConfig)_config;
tconfig.setDesiredPlayers(_pslide.getValue());
}
/** Our number of players slider. */
protected SimpleSlider _pslide;
}
@@ -1,5 +1,5 @@
//
// $Id: TableListView.java,v 1.4 2002/03/18 23:21:26 mdb Exp $
// $Id: TableListView.java,v 1.5 2002/07/25 23:20:22 mdb Exp $
package com.threerings.micasa.lobby.table;
@@ -25,9 +25,10 @@ import com.samskivert.swing.VGroupLayout;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.parlor.client.GameConfigurator;
import com.threerings.parlor.client.SeatednessObserver;
import com.threerings.parlor.client.TableDirector;
import com.threerings.parlor.client.TableObserver;
import com.threerings.parlor.client.SeatednessObserver;
import com.threerings.parlor.data.Table;
import com.threerings.parlor.data.TableConfig;
import com.threerings.parlor.game.GameConfig;
@@ -43,10 +44,8 @@ import com.threerings.micasa.util.MiCasaContext;
* the matchmaking process. UI mechanisms for creating and joining tables
* are also provided.
*/
public class TableListView
extends JPanel
implements PlaceView, TableObserver, ActionListener, SeatednessObserver,
ChangeListener
public class TableListView extends JPanel
implements PlaceView, TableObserver, ActionListener, SeatednessObserver
{
/**
* Creates a new table list view, suitable for providing the user
@@ -82,32 +81,33 @@ public class TableListView
_matchList.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.add(new JScrollPane(_matchList));
// create a prototype game config to configure our slider
// create our configurator interface
GameConfig gconfig = null;
try {
TableConfig tconfig = (TableConfig)config.getGameConfig();
JPanel cpanel =
new JPanel(new HGroupLayout(HGroupLayout.STRETCH));
cpanel.add(new JLabel("Seats:"), HGroupLayout.FIXED);
int min = tconfig.getMinimumPlayers();
_pslide = new JSlider(JSlider.HORIZONTAL, min,
tconfig.getMaximumPlayers(), min);
_pslide.addChangeListener(this);
cpanel.add(_pslide);
_pcount = new JLabel(Integer.toString(min));
cpanel.add(_pcount, HGroupLayout.FIXED);
gconfig = config.getGameConfig();
Class cclass = gconfig.getConfiguratorClass();
if (cclass != null) {
// create and initialize the configurator interface
_figger = (GameConfigurator)cclass.newInstance();
_figger.init(_ctx);
// give it the game config
_figger.setGameConfig(gconfig);
// and add the whole business to the main UI
panel.add(_figger, VGroupLayout.FIXED);
}
_create = new JButton("Create table");
_create.addActionListener(this);
cpanel.add(_create, HGroupLayout.FIXED);
panel.add(cpanel, VGroupLayout.FIXED);
panel.add(_create, VGroupLayout.FIXED);
} catch (Exception e) {
Log.warning("Unable to obtain prototype game config to " +
"configure matchmaking interface.");
Log.warning("Unable to create configurator interface " +
"[config=" + gconfig + "].");
Log.logStackTrace(e);
// stick something in the UI to let them know we're hosed
panel.add(new JLabel("Aiya! Can't create tables. " +
"Configuration borked."), VGroupLayout.FIXED);
}
add(panel);
@@ -216,24 +216,9 @@ public class TableListView
// documentation inherited
public void actionPerformed (ActionEvent event)
{
// the create table button was clicked. pass the word on to the
// table director
GameConfig config = null;
try {
config = _config.getGameConfig();
} catch (Exception e) {
Log.warning("Unable to resolve game config class " +
"[lconfig=" + _config + ", error=" + e + "].");
return;
}
if (config instanceof TableConfig) {
// set the desired number of players
((TableConfig)config).setDesiredPlayers(_pslide.getValue());
}
// and create a table with these values
_tdtr.createTable(config);
// the create table button was clicked. use the game config as
// configured by the configurator to create a table
_tdtr.createTable(_figger.getGameConfig());
}
// documentation inherited
@@ -243,15 +228,6 @@ public class TableListView
_create.setEnabled(!isSeated);
}
// documentation inherited
public void stateChanged (ChangeEvent e)
{
JSlider source = (JSlider)e.getSource();
if (!source.getValueIsAdjusting()) {
_pcount.setText(Integer.toString(source.getValue()));
}
}
/**
* Fetches the table item component associated with the specified
* table id.
@@ -296,12 +272,12 @@ public class TableListView
/** The list of tables that are in play. */
protected JPanel _playList;
/** The interface used to configure a table before creating it. */
protected GameConfigurator _figger;
/** Our create table button. */
protected JButton _create;
/** Our number of players slider. */
protected JSlider _pslide;
/** Our number of players indicator. */
protected JLabel _pcount;
}
@@ -0,0 +1,94 @@
//
// $Id: GameConfigurator.java,v 1.1 2002/07/25 23:20:22 mdb Exp $
package com.threerings.parlor.client;
import javax.swing.JPanel;
import com.samskivert.swing.VGroupLayout;
import com.threerings.parlor.game.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.
*
* <p> 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 class GameConfigurator extends JPanel
{
/**
* 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;
// set up our layout manager
VGroupLayout layout = new VGroupLayout(VGroupLayout.NONE);
layout.setOffAxisPolicy(VGroupLayout.STRETCH);
setLayout(layout);
// create our interface elements
createConfigInterface();
}
/**
* The default implementation creates a label indicating that no game
* specific configurations are available.
*/
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;
}
@@ -1,9 +1,10 @@
//
// $Id: GameConfig.java,v 1.10 2002/07/23 05:54:52 mdb Exp $
// $Id: GameConfig.java,v 1.11 2002/07/25 23:20:22 mdb Exp $
package com.threerings.parlor.game;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.parlor.client.GameConfigurator;
/**
* The game config class encapsulates the configuration information for a
@@ -27,6 +28,14 @@ public abstract class GameConfig extends PlaceConfig
/** Indicates whether or not this game is rated. */
public boolean rated = true;
/**
* Returns the class that should be used to create a user interface
* that can be used to configure this instance prior to starting the
* game. The configurator class must derive from {@link
* GameConfigurator}.
*/
public abstract Class getConfiguratorClass ();
/**
* Returns true if this game config object is equal to the supplied
* object (meaning it is also a game config object and its