Enhanced configuration configuration.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@512 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-11-27 21:00:56 +00:00
parent 55926ab3ea
commit 7be5c32548
2 changed files with 73 additions and 50 deletions
@@ -48,11 +48,23 @@ import com.threerings.ezgame.data.ToggleParameter;
*/ */
public class EZGameConfigurator extends FlexGameConfigurator public class EZGameConfigurator extends FlexGameConfigurator
{ {
public function EZGameConfigurator (ratedParam :ToggleParameter = null)
{
_ratedParam = ratedParam;
}
// from GameConfigurator // from GameConfigurator
override protected function gotGameConfig () :void override protected function gotGameConfig () :void
{ {
super.gotGameConfig(); super.gotGameConfig();
// add an interface for checking ratedness
if (_ratedParam != null) {
_ratedCheck = new CheckBox();
_ratedCheck.selected = _ratedParam.start;
addLabeledControl(_ratedParam, _ratedCheck);
}
var params :Array = (_config as EZGameConfig).getGameDefinition().params; var params :Array = (_config as EZGameConfig).getGameDefinition().params;
if (params == null) { if (params == null) {
return; return;
@@ -113,6 +125,11 @@ public class EZGameConfigurator extends FlexGameConfigurator
{ {
super.flushGameConfig(); super.flushGameConfig();
// flush ratedness
if (_ratedCheck != null) {
_config.rated = _ratedCheck.selected;
}
// if there were any custom XML configs, flush those as well. // if there were any custom XML configs, flush those as well.
if (_customConfigs.length > 0) { if (_customConfigs.length > 0) {
var params :StreamableHashMap = new StreamableHashMap(); var params :StreamableHashMap = new StreamableHashMap();
@@ -151,7 +168,7 @@ public class EZGameConfigurator extends FlexGameConfigurator
} }
var lbl :Label = new Label(); var lbl :Label = new Label();
lbl.text = param.name + ":"; lbl.text = param.name;
lbl.styleName = "lobbyLabel"; lbl.styleName = "lobbyLabel";
lbl.toolTip = param.tip; lbl.toolTip = param.tip;
control.toolTip = param.tip; control.toolTip = param.tip;
@@ -160,6 +177,12 @@ public class EZGameConfigurator extends FlexGameConfigurator
_customConfigs.push(param.ident, control); _customConfigs.push(param.ident, control);
} }
/** The parameter to use for whether the game is rated, or null. */
protected var _ratedParam :ToggleParameter;
/** A toggle indicating whether the game should be rated. */
protected var _ratedCheck :CheckBox;
/** Contains pairs of identString, control, identString, control.. */ /** Contains pairs of identString, control, identString, control.. */
protected var _customConfigs :Array = []; protected var _customConfigs :Array = [];
} }
@@ -27,6 +27,10 @@ import mx.controls.CheckBox;
import mx.controls.ComboBox; import mx.controls.ComboBox;
import mx.controls.Label; import mx.controls.Label;
// TODO: we shouldn't use these here but I don't feel like a major refactor
import com.threerings.ezgame.data.ToggleParameter;
import com.threerings.ezgame.data.RangeParameter;
import com.threerings.flex.GridUtil; import com.threerings.flex.GridUtil;
import com.threerings.parlor.data.TableConfig; import com.threerings.parlor.data.TableConfig;
@@ -42,54 +46,44 @@ import com.threerings.parlor.game.data.GameConfig;
public class DefaultFlexTableConfigurator extends TableConfigurator public class DefaultFlexTableConfigurator extends TableConfigurator
{ {
/** /**
* Create a TableConfigurator that allows for the specified configuration * Create a TableConfigurator that allows for the specified configuration parameters.
* parameters.
*/ */
public function DefaultFlexTableConfigurator ( public function DefaultFlexTableConfigurator (
desiredPlayers :int, minPlayers :int = -1, maxPlayers :int = -1, players :RangeParameter, watchable :ToggleParameter = null, prvate :ToggleParameter = null)
allowWatchable :Boolean = true, playersXlate :String = "Players: ",
watchableXlate :String = "Watchable: ", privateXlate :String = "Private: ")
{ {
var partyGame :Boolean = (minPlayers < 0) && (maxPlayers < 0); _playersParam = players;
if (minPlayers < 0) { _watchableParam = watchable;
minPlayers = desiredPlayers; _privateParam = prvate;
}
if (maxPlayers < 0) { _config.minimumPlayerCount = players.minimum;
maxPlayers = desiredPlayers;
}
_config.minimumPlayerCount = minPlayers;
// create a slider for players, if applicable // create a slider for players, if applicable
if (minPlayers != maxPlayers) { if (players.minimum != players.maximum) {
_players = new ComboBox(); _playersBox = new ComboBox();
var values :Array = []; var values :Array = [];
var startDex :int = 0; var startDex :int = 0;
for (var ii :int = minPlayers; ii <= maxPlayers; ii++) { for (var ii :int = players.minimum; ii <= players.maximum; ii++) {
if (ii == desiredPlayers) { if (ii == players.start) {
startDex = ii; startDex = ii;
} }
values.push(ii); values.push(ii);
} }
_players.dataProvider = values; _playersBox.dataProvider = values;
_players.selectedIndex = startDex; _playersBox.selectedIndex = startDex;
} else { } else {
_config.desiredPlayerCount = desiredPlayers; _config.desiredPlayerCount = players.start;
} }
// create up the checkbox for private games, if applicable if (watchable != null) {
if (partyGame) {
_privateCheck = new CheckBox();
_privateCheck.selected = false;
} else if (allowWatchable) {
_watchableCheck = new CheckBox(); _watchableCheck = new CheckBox();
// default to watchable, if the game allows it. _watchableCheck.selected = watchable.start;
_watchableCheck.selected = true;
} }
_playersXlate = playersXlate; if (prvate != null) {
_watchableXlate = watchableXlate; _privateCheck = new CheckBox();
_privateXlate = privateXlate; _privateCheck.selected = prvate.start;
}
} }
// documentation inherited // documentation inherited
@@ -97,24 +91,28 @@ public class DefaultFlexTableConfigurator extends TableConfigurator
{ {
super.createConfigInterface(); super.createConfigInterface();
var gconf :FlexGameConfigurator = var gconf :FlexGameConfigurator = (_gameConfigurator as FlexGameConfigurator);
(_gameConfigurator as FlexGameConfigurator);
if (_players != null) { if (_playersBox != null) {
var playerLabel :Label = new Label(); var playerLabel :Label = new Label();
playerLabel.text = _playersXlate; playerLabel.text = _playersParam.name;
playerLabel.toolTip = _playersParam.tip;
playerLabel.styleName = "lobbyLabel"; playerLabel.styleName = "lobbyLabel";
gconf.addControl(playerLabel, _players); gconf.addControl(playerLabel, _playersBox);
} }
if (_watchableCheck != null) { if (_watchableCheck != null) {
var watchableLabel :Label = new Label(); var watchableLabel :Label = new Label();
watchableLabel.text = _watchableXlate; watchableLabel.text = _watchableParam.name;
watchableLabel.toolTip = _watchableParam.tip;
watchableLabel.styleName = "lobbyLabel"; watchableLabel.styleName = "lobbyLabel";
gconf.addControl(watchableLabel, _watchableCheck); gconf.addControl(watchableLabel, _watchableCheck);
} else if (_privateCheck != null) { }
if (_privateCheck != null) {
var privateLabel :Label = new Label(); var privateLabel :Label = new Label();
privateLabel.text = _privateXlate; privateLabel.text = _privateParam.name;
privateLabel.toolTip = _privateParam.tip;
privateLabel.styleName = "lobbyLabel"; privateLabel.styleName = "lobbyLabel";
gconf.addControl(privateLabel, _privateCheck); gconf.addControl(privateLabel, _privateCheck);
} }
@@ -123,7 +121,7 @@ public class DefaultFlexTableConfigurator extends TableConfigurator
// documentation inherited // documentation inherited
override public function isEmpty () :Boolean override public function isEmpty () :Boolean
{ {
return (_players == null) && (_watchableCheck == null); return (_playersBox == null) && (_watchableCheck == null) && (_privateCheck == null);
} }
// documentation inherited // documentation inherited
@@ -131,20 +129,22 @@ public class DefaultFlexTableConfigurator extends TableConfigurator
{ {
super.flushTableConfig(); super.flushTableConfig();
if (_players != null) { if (_playersBox != null) {
_config.desiredPlayerCount = int(_players.value); _config.desiredPlayerCount = int(_playersBox.value);
} }
// TODO - it is wacky for the TableConfig.privateTable to mean two different things.
// It should be extended to have separate privateTable and watchableTable options. // TODO: it is wacky for the TableConfig.privateTable to mean two different things; it
// should be extended to have separate privateTable and watchableTable options.
if (_watchableCheck != null) { if (_watchableCheck != null) {
_config.privateTable = !_watchableCheck.selected; _config.privateTable = !_watchableCheck.selected;
} else if (_privateCheck != null) { }
if (_privateCheck != null) {
_config.privateTable = _privateCheck.selected; _config.privateTable = _privateCheck.selected;
} }
} }
/** A component for configuring the number of players at the table. */ /** A component for configuring the number of players at the table. */
protected var _players :ComboBox; protected var _playersBox :ComboBox;
/** A checkbox to allow the table creator to specify if the table is watchable */ /** A checkbox to allow the table creator to specify if the table is watchable */
protected var _watchableCheck :CheckBox; protected var _watchableCheck :CheckBox;
@@ -152,9 +152,9 @@ public class DefaultFlexTableConfigurator extends TableConfigurator
/** A checkbox to allow the table creator to specifiy if the table is private */ /** A checkbox to allow the table creator to specifiy if the table is private */
protected var _privateCheck :CheckBox; protected var _privateCheck :CheckBox;
/** Translation strings passed in by the caller */ /** Configuration passed in by the caller */
protected var _playersXlate :String; protected var _playersParam :RangeParameter;
protected var _watchableXlate :String; protected var _watchableParam :ToggleParameter;
protected var _privateXlate :String; protected var _privateParam :ToggleParameter;
} }
} }