Beginnings of a new unified way of configuring not only puzzles but
associated options depending on the context of the puzzle, for example the wager, or tournament options. Kept the default layout as a vgroup for backwards compatability (although I think the only thing that needs that is the ToyBoxConfigurator, and I've been wanting to make that bad boy line up nicely for a while now, so this backwards compatible stuff will only be needed for a short while). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3590 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,7 +21,13 @@
|
|||||||
|
|
||||||
package com.threerings.parlor.client;
|
package com.threerings.parlor.client;
|
||||||
|
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import com.samskivert.swing.VGroupLayout;
|
import com.samskivert.swing.VGroupLayout;
|
||||||
|
|
||||||
import com.threerings.parlor.game.data.GameConfig;
|
import com.threerings.parlor.game.data.GameConfig;
|
||||||
@@ -39,6 +45,15 @@ import com.threerings.parlor.util.ParlorContext;
|
|||||||
*/
|
*/
|
||||||
public class GameConfigurator extends JPanel
|
public class GameConfigurator extends 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);
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this game configurator, creates its user interface
|
* Initializes this game configurator, creates its user interface
|
||||||
* elements and prepares it for display.
|
* elements and prepares it for display.
|
||||||
@@ -48,18 +63,12 @@ public class GameConfigurator extends JPanel
|
|||||||
// save this for later
|
// save this for later
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
|
|
||||||
// set up our layout manager
|
|
||||||
VGroupLayout layout = new VGroupLayout(VGroupLayout.NONE);
|
|
||||||
layout.setOffAxisPolicy(VGroupLayout.STRETCH);
|
|
||||||
setLayout(layout);
|
|
||||||
|
|
||||||
// create our interface elements
|
// create our interface elements
|
||||||
createConfigInterface();
|
createConfigInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default implementation creates a label indicating that no game
|
* The default implementation creates nothing.
|
||||||
* specific configurations are available.
|
|
||||||
*/
|
*/
|
||||||
protected void createConfigInterface ()
|
protected void createConfigInterface ()
|
||||||
{
|
{
|
||||||
@@ -94,6 +103,40 @@ public class GameConfigurator extends JPanel
|
|||||||
return _config;
|
return _config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a control to the interface. This should be the standard way
|
||||||
|
* that configurator controls are added, but note also that external
|
||||||
|
* entities may add their own controls that are related to the game,
|
||||||
|
* but do not directly alter the game config, so that all the controls
|
||||||
|
* are added in a uniform manner and are well aligned.
|
||||||
|
*/
|
||||||
|
public void addControl (JComponent label, JComponent control)
|
||||||
|
{
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the constraints. There's really no point in saving
|
||||||
|
// this somewhere, as they're cloned anyway with every component
|
||||||
|
// insertion.
|
||||||
|
GridBagConstraints lc = new GridBagConstraints();
|
||||||
|
lc.gridx = 0;
|
||||||
|
lc.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
lc.insets = _labelInsets;
|
||||||
|
|
||||||
|
GridBagConstraints cc = new GridBagConstraints();
|
||||||
|
cc.gridx = 1;
|
||||||
|
cc.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
cc.insets = _controlInsets;
|
||||||
|
cc.gridwidth = GridBagConstraints.REMAINDER;
|
||||||
|
|
||||||
|
// add the components
|
||||||
|
add(label, lc);
|
||||||
|
add(control, cc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derived classes will want to override this method, flushing values
|
* Derived classes will want to override this method, flushing values
|
||||||
* from the user interface to the game config object so that it is
|
* from the user interface to the game config object so that it is
|
||||||
@@ -109,4 +152,10 @@ public class GameConfigurator extends JPanel
|
|||||||
|
|
||||||
/** Our game configuration. */
|
/** Our game configuration. */
|
||||||
protected GameConfig _config;
|
protected GameConfig _config;
|
||||||
|
|
||||||
|
/** Insets for configuration labels. */
|
||||||
|
protected Insets _labelInsets = new Insets(1, 0, 1, 4);
|
||||||
|
|
||||||
|
/** Insets for configuration controls. */
|
||||||
|
protected Insets _controlInsets = new Insets(1, 4, 1, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user