Table creation refactor: Rather than have the game config specify

table configuration parameters that are unneeded once the actual game starts,
and requiring each GameConfigurator to duplicate the functionality
of standard table setup, I separated TableConfig from GameConfig.
If a game wants to be usable in a table matchmaking service, it
implements TableableGameConfig, and returns the TableConfigurator to use.
There is a default TableConfigurator implementation that just does
everything needed. TableConfigurator returns a happily customized
TableConfig, which is sent to the server with the GameConfig in order to
create the Table.
More refactoring needs to happen to get the Party stuff in line, but
right now that's all a mess since we're still supporting the old-style
party interface for the old drinking puzzle in yohoho.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3525 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2005-04-26 02:38:42 +00:00
parent 2351316259
commit 052cf8e0e2
16 changed files with 265 additions and 190 deletions
@@ -1,69 +0,0 @@
//
// $Id: TableGameConfigurator.java,v 1.3 2004/08/27 02:12:51 mdb Exp $
//
// 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.micasa.lobby.table;
import com.samskivert.swing.SimpleSlider;
import com.samskivert.swing.VGroupLayout;
import com.threerings.parlor.client.GameConfigurator;
import com.threerings.parlor.data.TableConfig;
/**
* 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: TableItem.java,v 1.5 2004/08/27 02:12:51 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -41,7 +41,6 @@ import com.threerings.crowd.data.BodyObject;
import com.threerings.parlor.client.TableDirector;
import com.threerings.parlor.client.SeatednessObserver;
import com.threerings.parlor.data.Table;
import com.threerings.parlor.data.TableConfig;
import com.threerings.micasa.Log;
import com.threerings.micasa.util.MiCasaContext;
@@ -73,9 +72,6 @@ public class TableItem
// figure out who we are
_self = ((BodyObject)ctx.getClient().getClientObject()).username;
// grab the table config reference
_tconfig = (TableConfig)table.config;
// now create our user interface
setBorder(BorderFactory.createLineBorder(Color.black));
setLayout(new GridBagLayout());
@@ -88,10 +84,7 @@ public class TableItem
add(tlabel, gbc);
// we have one button for every "seat" at the table
int bcount = _tconfig.getDesiredPlayers();
if (bcount == -1) {
bcount = _tconfig.getMaximumPlayers();
}
int bcount = table.occupants.length;
// create blank buttons for now and then we'll update everything
// with the current state when we're done
@@ -243,9 +236,6 @@ public class TableItem
/** A reference to our table director. */
protected TableDirector _tdtr;
/** A casted reference to our table config object. */
protected TableConfig _tconfig;
/** We have a button for each "seat" at the table. */
protected JButton[] _seats;
@@ -21,6 +21,7 @@
package com.threerings.micasa.lobby.table;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
@@ -44,7 +45,9 @@ import com.threerings.parlor.client.SeatednessObserver;
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.data.GameConfig;
import com.threerings.parlor.game.data.TableableGameConfig;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.PlaceObject;
@@ -97,6 +100,10 @@ public class TableListView extends JPanel
GameConfig gconfig = null;
try {
gconfig = config.getGameConfig();
_tableFigger =
((TableableGameConfig) gconfig).createTableConfigurator(_ctx);
panel.add((Component) _tableFigger, VGroupLayout.FIXED);
_figger = gconfig.createConfigurator();
if (_figger != null) {
_figger.init(_ctx);
@@ -222,7 +229,8 @@ public class TableListView extends JPanel
{
// the create table button was clicked. use the game config as
// configured by the configurator to create a table
_tdtr.createTable(_figger.getGameConfig());
_tdtr.createTable(_tableFigger.getTableConfig(),
_figger.getGameConfig());
}
// documentation inherited
@@ -276,7 +284,10 @@ public class TableListView extends JPanel
/** The list of tables that are in play. */
protected JPanel _playList;
/** The interface used to configure a table before creating it. */
/** The interface used to configure the table for a game. */
protected TableConfigurator _tableFigger;
/** The interface used to configure a game before creating it. */
protected GameConfigurator _figger;
/** Our create table button. */