From: Erik V. <ev...@us...> - 2012-04-10 13:20:37
|
rails/game/GameManager.java | 40 +++++++-- rails/game/GameManagerI.java | 4 rails/ui/swing/GameStatus.java | 74 +++++++++++++----- rails/ui/swing/GameUIManager.java | 50 ++++++++++++ rails/ui/swing/GridPanel.java | 33 +++----- rails/ui/swing/StartRoundWindow.java | 97 +++++++++++++++++------- rails/ui/swing/StatusWindow.java | 8 + test/data/test/1835_PRHasTwoExcessTrains.report | 2 test/data/test/1835_PR_3rdTrain.report | 6 - 9 files changed, 232 insertions(+), 82 deletions(-) New commits: commit fc634eb4a9d56c061375477083d7f049a89cf2b7 Author: Erik Vos <eri...@xs...> Date: Tue Apr 10 15:18:36 2012 +0200 Replaced two 1835 test reports, which were affected by the PR worth calculation fix. diff --git a/test/data/test/1835_PRHasTwoExcessTrains.report b/test/data/test/1835_PRHasTwoExcessTrains.report index 2049760..4396818 100644 --- a/test/data/test/1835_PRHasTwoExcessTrains.report +++ b/test/data/test/1835_PRHasTwoExcessTrains.report @@ -1038,7 +1038,7 @@ CompanyWithholds,WT,280 PRICE_MOVES_LOG,WT,72,A5,64,A6 EndOfOperatingRound,7.1 -ORWorthIncrease,Alice,7.1,741 +ORWorthIncrease,Alice,7.1,587 ORWorthIncrease,Bob,7.1,442 ORWorthIncrease,Charlie,7.1,516 Has,M1,1 diff --git a/test/data/test/1835_PR_3rdTrain.report b/test/data/test/1835_PR_3rdTrain.report index aef617c..d80d659 100644 --- a/test/data/test/1835_PR_3rdTrain.report +++ b/test/data/test/1835_PR_3rdTrain.report @@ -1061,9 +1061,9 @@ PrivateCloses,PfB CompanyDiscardsTrain,SX,3 EndOfOperatingRound,7.1 -ORWorthIncrease,Alice,7.1,549 -ORWorthIncrease,Bob,7.1,824 -ORWorthIncrease,Charlie,7.1,946 +ORWorthIncrease,Alice,7.1,395 +ORWorthIncrease,Bob,7.1,439 +ORWorthIncrease,Charlie,7.1,561 Has,BY,250 Has,SX,175 Has,BA,24 commit e5581e31305d172a7ff5d68ede5e5fe0207165bc Author: Erik Vos <eri...@xs...> Date: Tue Apr 10 15:09:03 2012 +0200 Player columns in StartRoundWindow and GameStatus can now be reordered. Required for 1880 and other games. Remaining issue: Undo does not reverse the new player order in the GameStatus window. But at the next SR the player order should be OK. diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java index 15915f0..b379959 100644 --- a/rails/game/GameManager.java +++ b/rails/game/GameManager.java @@ -71,7 +71,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { protected int numberOfPlayers; protected State currentPlayer = new State("CurrentPlayer", Player.class); protected State priorityPlayer = new State("PriorityPlayer", Player.class); - protected StringState[] playerNameModels; + protected PlayerOrderState playerNamesModel; /** Map relating portfolio names and objects, to enable deserialization. * OBSOLETE since Rails 1.3.1, but still required to enable reading old saved files */ @@ -565,10 +565,8 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { numberOfPlayers = players.size(); priorityPlayer.setState(players.get(0)); setPlayerCertificateLimit (playerManager.getInitialPlayerCertificateLimit()); - playerNameModels = new StringState[numberOfPlayers]; - for (int i=0; i<numberOfPlayers; i++) { - playerNameModels[i] = new StringState ("Player_"+(i+1), players.get(i).getName()); - } + + playerNamesModel = new PlayerOrderState ("PlayerOrder", new ArrayList<String>(originalPlayerNamesList)); showCompositeORNumber = !"simple".equalsIgnoreCase(Config.get("or.number_format")); } @@ -639,7 +637,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { * @return instance of GameManager */ public static GameManagerI getInstance () { -// return gameManagerMap.get(NDC.peek()); + // return gameManagerMap.get(NDC.peek()); return gameManagerMap.get(GM_KEY); } @@ -1929,19 +1927,21 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { players.clear(); Player player; + List<String> reorderedPlayerNames = new ArrayList<String>(players.size()); for (int i=0; i<reorderedPlayers.size(); i++) { player = reorderedPlayers.get(i); players.add(player); player.setIndex (i); - playerNameModels[i].set(player.getName()); + reorderedPlayerNames.add(player.getName()); log.debug("New player "+i+" is "+player.getName() +" (cash="+Bank.format(player.getCash())+")"); } + playerNamesModel.set(reorderedPlayerNames); return this.players.get(0); } - public StringState getPlayerNameModel(int index) { - return playerNameModels[index]; + public PlayerOrderState getPlayerNamesModel() { + return playerNamesModel; } public void resetStorage() { @@ -1965,5 +1965,27 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { public void processPhaseAction (String name, String value) { getCurrentRound().processPhaseAction(name, value); } + + public class PlayerOrderState extends State { + + protected PlayerOrderState (String name, List<String> playerNames) { + super (name, playerNames); + } + + protected void set (List<String> playerNames) { + super.set (playerNames); + } + + @SuppressWarnings("unchecked") + @Override + public List<String> get() { + return (List<String>) super.get(); + } + + @Override + public String getText () { + return Util.joinWithDelimiter(get().toArray(new String[0]), ";"); + } + } } diff --git a/rails/game/GameManagerI.java b/rails/game/GameManagerI.java index 92f2a88..63ae0e5 100644 --- a/rails/game/GameManagerI.java +++ b/rails/game/GameManagerI.java @@ -6,6 +6,7 @@ import java.util.Map; import rails.algorithms.RevenueManager; import rails.common.*; import rails.common.parser.ConfigurableComponentI; +import rails.game.GameManager.PlayerOrderState; import rails.game.action.PossibleAction; import rails.game.correct.CorrectionManagerI; import rails.game.correct.CorrectionType; @@ -13,7 +14,6 @@ import rails.game.model.ModelObject; import rails.game.move.MoveStack; import rails.game.move.MoveableHolder; import rails.game.special.SpecialPropertyI; -import rails.game.state.StringState; public interface GameManagerI extends MoveableHolder, ConfigurableComponentI { @@ -222,7 +222,7 @@ public interface GameManagerI extends MoveableHolder, ConfigurableComponentI { public void setSkipDone (GameDef.OrStep step); public Player reorderPlayersByCash(boolean high); - public StringState getPlayerNameModel(int index) ; + public PlayerOrderState getPlayerNamesModel(); /** * reset the storage for other elements like tokens, special property diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index a10dd80..4022dc3 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -112,7 +112,8 @@ public class GameStatus extends GridPanel implements ActionListener { protected int actorIndex = -2; protected ButtonGroup buySellGroup = new ButtonGroup(); - protected ClickField dummyButton; // To be selected if none else is. + /** Invisible default radio button option */ + protected ClickField dummyButton = new ClickField("", "", "", this, buySellGroup); protected Map<PublicCompanyI, Integer> companyIndex = new HashMap<PublicCompanyI, Integer>(); @@ -187,8 +188,6 @@ public class GameStatus extends GridPanel implements ActionListener { upperPlayerCaption = new Cell[np]; lowerPlayerCaption = new Cell[np]; - MouseListener companyCaptionMouseClickListener = gameUIManager.getORUIManager().getORPanel().getCompanyCaptionMouseClickListener(); - int lastX = 0; int lastY = 1; certPerPlayerXOffset = ++lastX; @@ -256,19 +255,27 @@ public class GameStatus extends GridPanel implements ActionListener { fields = new JComponent[1+lastX][2+lastY]; rowVisibilityObservers = new RowVisibility[nc]; + initFields(); + + } + + protected void initFields () { + + MouseListener companyCaptionMouseClickListener = gameUIManager.getORUIManager().getORPanel().getCompanyCaptionMouseClickListener(); + // Top captions addField(new Caption(LocalText.getText("COMPANY")), 0, 0, 1, 2, WIDE_BOTTOM, true); addField(new Caption(LocalText.getText("PLAYERS")), certPerPlayerXOffset, 0, np, 1, WIDE_LEFT + WIDE_RIGHT, true); - boolean playerOrderCanVary = gameUIManager.getGameParameterAsBoolean(GuiDef.Parm.PLAYER_ORDER_VARIES); for (int i = 0; i < np; i++) { - if (playerOrderCanVary) { - f = upperPlayerCaption[i] = new Field(gameUIManager.getGameManager().getPlayerNameModel(i)); - upperPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); - } else { - f = upperPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); - } + //if (playerOrderCanVary) { + // f = upperPlayerCaption[i] = new Field(gameUIManager.getGameManager().getPlayerNameModel(i)); + // upperPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); + //} else { + f = upperPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); + log.debug(" GS: new player "+i+" is "+players.get(i).getName()); + //} int wideGapPosition = WIDE_BOTTOM + ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0); addField(f, certPerPlayerXOffset + i, 1, 1, 1, wideGapPosition, true); @@ -536,12 +543,12 @@ public class GameStatus extends GridPanel implements ActionListener { // Bottom player captions for (int i = 0; i < np; i++) { - if (playerOrderCanVary) { - f = lowerPlayerCaption[i] = new Field(gameUIManager.getGameManager().getPlayerNameModel(i)); - lowerPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); - } else { - f = lowerPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); - } + //if (playerOrderCanVary) { + // f = lowerPlayerCaption[i] = new Field(gameUIManager.getGameManager().getPlayerNameModel(i)); + // lowerPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); + //} else { + f = lowerPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); + //} int wideGapPosition = WIDE_TOP + ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0); addField(f, i + 1, playerCertCountYOffset + 1, 1, 1, wideGapPosition, true); @@ -583,8 +590,6 @@ public class GameStatus extends GridPanel implements ActionListener { newTrains = new Field(ipo.getTrainsModel()); addField(newTrains, newTrainsXOffset, newTrainsYOffset, 1, 1, 0, true); - dummyButton = new ClickField("", "", "", this, buySellGroup); - // Future trains addField(new Caption(LocalText.getText("Future")), futureTrainsXOffset, futureTrainsYOffset - 1, futureTrainsWidth, 1, WIDE_TOP, true); @@ -602,8 +607,39 @@ public class GameStatus extends GridPanel implements ActionListener { addField (f = new Caption("<html>" + text + "</html>"), poolTrainsXOffset, newTrainsYOffset + 1, futureTrainsWidth + 2, 2, 0, true); f.setPreferredSize(new Dimension (1,1));// To enable auto word wrap + } + + public void recreate() { + log.debug("GameStatus.recreate() called"); + + // Remove old fields. Don't forget to deregister the Observers + deRegisterObservers(); + removeAll(); + + // Create new fields + initFields(); + + //repaint(); + } - dummyButton = new ClickField("", "", "", this, buySellGroup); + public void updatePlayerOrder (List<String> newPlayerNames) { + + List<String> oldPlayerNames = gameUIManager.getCurrentGuiPlayerNames(); + log.debug("GS: old player list: "+Util.joinWithDelimiter(oldPlayerNames.toArray(new String[0]), ",")); + log.debug("GS: new player list: "+Util.joinWithDelimiter(newPlayerNames.toArray(new String[0]), ",")); + + /* Currently, the passed new player order is ignored. + * A call to this method only serves as a signal to rebuild the player columns in the proper order + * (in fact, the shortcut is taken to rebuild the whole GameStatus panel). + * For simplicity reasons, the existing reference to the (updated) + * players list in GameManager is used. + * + * In the future (e.g. when implementing a client/server split), + * newPlayerNames may actually become to be used to reorder the + * (then internal) UI player list. + */ + recreate(); + gameUIManager.packAndApplySizing(parent); } public void actionPerformed(ActionEvent actor) { diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index a43f683..15e0f2c 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -16,6 +16,7 @@ import org.apache.log4j.Logger; import rails.common.*; import rails.game.*; import rails.game.action.*; +import rails.game.model.ModelObject; import rails.sound.SoundManager; import rails.ui.swing.elements.*; import rails.util.Util; @@ -88,6 +89,14 @@ public class GameUIManager implements DialogOwner { protected boolean previousResult; + // Player order + protected PlayerOrderView playerOrderView; + /** Player names set at time of initialisation or after reordering. + *<p> To be used as a reference to the current player order as shown in the UI. + * Note, that getPlayers() currently calls the game engine directly, and + * therefore updates before the UI gets notice via the playerOrderView.*/ + protected List<String> currentGuiPlayerNames; + /* Keys of dialogs owned by this class */ public static final String COMPANY_START_PRICE_DIALOG = "CompanyStartPrice"; public static final String SELECT_COMPANY_DIALOG = "SelectCompany"; @@ -120,6 +129,11 @@ public class GameUIManager implements DialogOwner { configuredStockChartVisibility = "yes".equalsIgnoreCase(Config.get("stockchart.window.open")); + playerOrderView = new PlayerOrderView(); + currentGuiPlayerNames = new ArrayList<String>(); + for (Player player : getPlayers()) { + currentGuiPlayerNames.add (player.getName()); + } } private void initWindowSettings () { @@ -552,6 +566,12 @@ public class GameUIManager implements DialogOwner { } + protected void updatePlayerOrder (List<String> newPlayerOrder) { + if (startRoundWindow != null) startRoundWindow.updatePlayerOrder (newPlayerOrder); + if (statusWindow != null) statusWindow.updatePlayerOrder (newPlayerOrder); + currentGuiPlayerNames = newPlayerOrder; + } + /** Stub, to be overridden in subclasses for special round types */ protected void updateStatus(ActionPerformer activeWindow) { @@ -1212,4 +1232,34 @@ public class GameUIManager implements DialogOwner { } }); } + + public List<String> getCurrentGuiPlayerNames() { + return currentGuiPlayerNames; + } + + public class PlayerOrderView implements ViewObject { + + PlayerOrderView () { + gameManager.getPlayerNamesModel().addObserver(this); + } + + public void update(Observable o, Object arg) { + if (o instanceof GameManager.PlayerOrderState && arg instanceof String) { + List<String> newPlayerNames = Arrays.asList(((String)arg).split(";")); + updatePlayerOrder (newPlayerNames); + } + + } + + public ModelObject getModel() { + // TODO Auto-generated method stub + return null; + } + + public void deRegister() { + // TODO Auto-generated method stub + + } + + } } diff --git a/rails/ui/swing/GridPanel.java b/rails/ui/swing/GridPanel.java index 20d78d3..a4f2592 100644 --- a/rails/ui/swing/GridPanel.java +++ b/rails/ui/swing/GridPanel.java @@ -112,28 +112,27 @@ implements ActionListener, KeyListener { int padTop, padLeft, padBottom, padRight; padTop = (wideGapPositions & WIDE_TOP) > 0 ? WIDE_GAP - NARROW_GAP : 0; padLeft = (wideGapPositions & WIDE_LEFT) > 0 ? WIDE_GAP - NARROW_GAP : 0; - padBottom = - (wideGapPositions & WIDE_BOTTOM) > 0 ? WIDE_GAP - NARROW_GAP : 0; - padRight = (wideGapPositions & WIDE_RIGHT) > 0 ? WIDE_GAP - NARROW_GAP : 0; + padBottom = (wideGapPositions & WIDE_BOTTOM) > 0 ? WIDE_GAP - NARROW_GAP : 0; + padRight = (wideGapPositions & WIDE_RIGHT) > 0 ? WIDE_GAP - NARROW_GAP : 0; - //set field borders - //- inner border: the field's native border - //- outline border: the field's outline (in narrow_gap thickness) - //- outer border: grid table lines (in wide_gap - narrow_gap thickness) + //set field borders + //- inner border: the field's native border + //- outline border: the field's outline (in narrow_gap thickness) + //- outer border: grid table lines (in wide_gap - narrow_gap thickness) - comp.setBorder(new FieldBorder(comp.getBorder(), - new DynamicBorder(cellOutlineColor,NARROW_GAP), - new DynamicBorder(tableBorderColor,padTop,padLeft,padBottom,padRight))); + comp.setBorder(new FieldBorder(comp.getBorder(), + new DynamicBorder(cellOutlineColor,NARROW_GAP), + new DynamicBorder(tableBorderColor,padTop,padLeft,padBottom,padRight))); - gridPanel.add(comp, gbc); + gridPanel.add(comp, gbc); - if (comp instanceof ViewObject - && ((ViewObject) comp).getModel() != null) { - observers.add((ViewObject) comp); - } + if (comp instanceof ViewObject + && ((ViewObject) comp).getModel() != null) { + observers.add((ViewObject) comp); + } - if (fields != null && fields[x][y] == null) fields[x][y] = comp; - comp.setVisible(visible); + if (fields != null && fields[x][y] == null) fields[x][y] = comp; + comp.setVisible(visible); } /** diff --git a/rails/ui/swing/StartRoundWindow.java b/rails/ui/swing/StartRoundWindow.java index cb3445c..ed4c2ca 100644 --- a/rails/ui/swing/StartRoundWindow.java +++ b/rails/ui/swing/StartRoundWindow.java @@ -10,7 +10,6 @@ import javax.swing.*; import org.apache.log4j.Logger; -import rails.common.GuiDef; import rails.common.LocalText; import rails.game.*; import rails.game.action.*; @@ -18,6 +17,7 @@ import rails.game.special.SpecialPropertyI; import rails.sound.SoundManager; import rails.ui.swing.elements.*; import rails.ui.swing.hexmap.HexHighlightMouseListener; +import rails.util.Util; /** * This displays the Auction Window @@ -64,8 +64,10 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { private int infoXOffset, infoYOffset; private Field itemStatus[]; // Remains invisible, only used for status tooltip + private int playerCaptionXOffset, upperPlayerCaptionYOffset, lowerPlayerCaptionYOffset; private Cell[] upperPlayerCaption; private Cell[] lowerPlayerCaption; + private JComponent[][] fields; private ActionButton bidButton; private ActionButton buyButton; @@ -183,7 +185,7 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { infoIcon = createInfoIcon(); - init(); + initCells(); getContentPane().add(statusPanel, BorderLayout.NORTH); getContentPane().add(buttonPanel, BorderLayout.SOUTH); @@ -223,9 +225,9 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { gameUIManager.packAndApplySizing(this); } - private void init() { + private void initCells() { int lastX = -1; - int lastY = 1; + int lastY = 0; itemName = new Caption[ni]; itemNameButton = new ClickField[ni]; @@ -239,6 +241,8 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { playerBids = new Field[np]; playerFree = new Field[np]; + upperPlayerCaptionYOffset = ++lastY; + itemNameXOffset = ++lastX; itemNameYOffset = ++lastY; if (showBasePrices) { @@ -249,7 +253,7 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { minBidXOffset = ++lastX; minBidYOffset = lastY; } - bidPerPlayerXOffset = ++lastX; + bidPerPlayerXOffset = playerCaptionXOffset = ++lastX; bidPerPlayerYOffset = lastY; infoXOffset = bidPerPlayerXOffset + np; @@ -264,6 +268,10 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { playerFreeCashXOffset = bidPerPlayerXOffset; playerFreeCashYOffset = ++lastY; + lowerPlayerCaptionYOffset = ++lastY; + + fields = new JComponent[1+infoXOffset][2+lastY]; + addField(new Caption(LocalText.getText("ITEM")), 0, 0, 1, 2, WIDE_RIGHT + WIDE_BOTTOM); if (showBasePrices) { @@ -278,16 +286,16 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { // Top player captions addField(new Caption(LocalText.getText("PLAYERS")), - bidPerPlayerXOffset, 0, np, 1, 0); - boolean playerOrderCanVary = getGameUIManager().getGameParameterAsBoolean(GuiDef.Parm.PLAYER_ORDER_VARIES); + playerCaptionXOffset, 0, np, 1, 0); + //boolean playerOrderCanVary = getGameUIManager().getGameParameterAsBoolean(GuiDef.Parm.PLAYER_ORDER_VARIES); for (int i = 0; i < np; i++) { - if (playerOrderCanVary) { - f = upperPlayerCaption[i] = new Field(getGameUIManager().getGameManager().getPlayerNameModel(i)); - upperPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); - } else { - f = upperPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); - } - addField(f, bidPerPlayerXOffset + i, 1, 1, 1, WIDE_BOTTOM); + //if (playerOrderCanVary) { + // f = upperPlayerCaption[i] = new Field(getGameUIManager().getGameManager().getPlayerNameModel(i)); + // upperPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); + //} else { + f = upperPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); + //} + addField(f, playerCaptionXOffset + i, upperPlayerCaptionYOffset, 1, 1, WIDE_BOTTOM); } for (int i = 0; i < ni; i++) { @@ -364,13 +372,13 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { } for (int i = 0; i < np; i++) { - if (playerOrderCanVary) { - f = lowerPlayerCaption[i] = new Field(getGameUIManager().getGameManager().getPlayerNameModel(i)); - lowerPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); - } else { - f = lowerPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); - } - addField(f, playerFreeCashXOffset + i, playerFreeCashYOffset + 1, + //if (playerOrderCanVary) { + // f = lowerPlayerCaption[i] = new Field(getGameUIManager().getGameManager().getPlayerNameModel(i)); + // lowerPlayerCaption[i].setNormalBgColour(Cell.NORMAL_CAPTION_BG_COLOUR); + //} else { + f = lowerPlayerCaption[i] = new Caption(players.get(i).getNameAndPriority()); + //} + addField(f, playerCaptionXOffset + i, lowerPlayerCaptionYOffset, 1, 1, WIDE_TOP); } @@ -390,13 +398,12 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { gbc.fill = GridBagConstraints.BOTH; padTop = (wideGapPositions & WIDE_TOP) > 0 ? WIDE_GAP : NARROW_GAP; padLeft = (wideGapPositions & WIDE_LEFT) > 0 ? WIDE_GAP : NARROW_GAP; - padBottom = - (wideGapPositions & WIDE_BOTTOM) > 0 ? WIDE_GAP : NARROW_GAP; - padRight = (wideGapPositions & WIDE_RIGHT) > 0 ? WIDE_GAP : NARROW_GAP; - gbc.insets = new Insets(padTop, padLeft, padBottom, padRight); - - statusPanel.add(comp, gbc); + padBottom = (wideGapPositions & WIDE_BOTTOM) > 0 ? WIDE_GAP : NARROW_GAP; + padRight = (wideGapPositions & WIDE_RIGHT) > 0 ? WIDE_GAP : NARROW_GAP; + gbc.insets = new Insets(padTop, padLeft, padBottom, padRight); + statusPanel.add(comp, gbc); + fields[x][y] = comp; } public void updateStatus(boolean myTurn) { @@ -548,11 +555,45 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { return true; } + public void updatePlayerOrder (List<String> newPlayerNames) { + + int[] xref = new int[np]; + List<String> oldPlayerNames = gameUIManager.getCurrentGuiPlayerNames(); + for (int i=0; i<np; i++) { + xref[i] = oldPlayerNames.indexOf(newPlayerNames.get(i)); + } + log.debug("SRW: old player list: "+Util.joinWithDelimiter(oldPlayerNames.toArray(new String[0]), ",")); + log.debug("SRW: new player list: "+Util.joinWithDelimiter(newPlayerNames.toArray(new String[0]), ",")); + //log.debug("SRW: xref="+Util.joinWithDelimiter(xref, ",")); + + JComponent[] cells = new Cell[np]; + GridBagConstraints[] constraints = new GridBagConstraints[np]; + JComponent f; + for (int y=upperPlayerCaptionYOffset; y<=lowerPlayerCaptionYOffset; y++) { + for (int i=0, x=playerCaptionXOffset; i<np; i++, x++) { + cells[i] = fields[x][y]; + constraints[i] = gb.getConstraints(cells[i]); + statusPanel.remove(cells[i]); + } + for (int i=0, x=playerCaptionXOffset; i<np; i++, x++) { + f = fields[x][y] = cells[xref[i]]; + statusPanel.add (f, constraints[i]); + } + } + for (int i=0, x=playerCaptionXOffset; i<np; i++, x++) { + upperPlayerCaption[i] = (Cell) fields[x][upperPlayerCaptionYOffset]; + lowerPlayerCaption[i] = (Cell) fields[x][lowerPlayerCaptionYOffset]; + } + + gameUIManager.packAndApplySizing(this); + } + /* * (non-Javadoc) * * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ + public void actionPerformed(ActionEvent actor) { JComponent source = (JComponent) actor.getSource(); @@ -561,7 +602,7 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { StartItemAction currentActiveItem = (StartItemAction) ((ClickField) source).getPossibleActions().get( 0); - + //notify sound manager that click field has been selected SoundManager.notifyOfClickFieldSelection(currentActiveItem); diff --git a/rails/ui/swing/StatusWindow.java b/rails/ui/swing/StatusWindow.java index 554eef8..28d5c60 100644 --- a/rails/ui/swing/StatusWindow.java +++ b/rails/ui/swing/StatusWindow.java @@ -10,9 +10,7 @@ import javax.swing.*; import org.apache.log4j.Logger; -import rails.common.Config; -import rails.common.GuiDef; -import rails.common.LocalText; +import rails.common.*; import rails.game.*; import rails.game.action.*; import rails.game.correct.CorrectionModeAction; @@ -578,6 +576,10 @@ KeyListener, ActionPerformer { toFront(); } + public void updatePlayerOrder (List<String> newPlayerNames) { + gameStatus.updatePlayerOrder (newPlayerNames); + } + public void disableButtons () { passButton.setEnabled(false); autopassButton.setEnabled(false); |