|
From: Erik V. <ev...@us...> - 2012-01-27 20:42:22
|
rails/common/GuiDef.java | 3
rails/game/GameManager.java | 32 +++++--
rails/game/GameManagerI.java | 2
rails/game/specific/_1880/GameManager_1880.java | 99 ++++++++++++------------
rails/game/state/ArrayListState.java | 5 -
rails/ui/swing/GameStatus.java | 73 +++++++++--------
rails/ui/swing/GridPanel.java | 78 +++++++++---------
rails/ui/swing/ORPanel.java | 14 +--
rails/ui/swing/StartRoundWindow.java | 43 ++++++----
rails/ui/swing/elements/Caption.java | 31 +------
rails/ui/swing/elements/Cell.java | 46 +++++++++++
rails/ui/swing/elements/Field.java | 29 +------
12 files changed, 249 insertions(+), 206 deletions(-)
New commits:
commit b95fd7fd0bf822a8f275166402ca7c3a9f701ef9
Author: Erik Vos <eri...@xs...>
Date: Fri Jan 27 21:39:51 2012 +0100
Player captions made variable to reflect player reordering.
Capability is game-dependent. Setting it is currently hardcoded in GameManager[_1880].setGuiParameters().
The list of players in GameManager is now an ArrayListState.
As ArrayListState does not inherit from ModelObject, a separate
StringState[] array had to be created to hold the player names for use in the GUI.
A new Cell superclass for Caption and Field allows Field to get a caption background and also centralises highlighting.
diff --git a/rails/common/GuiDef.java b/rails/common/GuiDef.java
index 5d75906..5f746de 100644
--- a/rails/common/GuiDef.java
+++ b/rails/common/GuiDef.java
@@ -41,7 +41,8 @@ public class GuiDef {
HAS_ANY_RIGHTS,
NO_MAP_MODE,
REVENUE_SUGGEST,
- ROUTE_HIGHLIGHT
+ ROUTE_HIGHLIGHT,
+ PLAYER_ORDER_VARIES
}
/**
diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java
index d18cba0..886aa80 100644
--- a/rails/game/GameManager.java
+++ b/rails/game/GameManager.java
@@ -65,11 +65,12 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
protected String gameName;
protected Map<String, String> gameOptions;
- protected List<Player> players;
+ protected ArrayListState<Player> players;
protected List<String> originalPlayerNamesList;
protected int numberOfPlayers;
protected State currentPlayer = new State("CurrentPlayer", Player.class);
protected State priorityPlayer = new State("PriorityPlayer", Player.class);
+ protected StringState[] playerNameModels;
/** Map relating portfolio names and objects, to enable deserialization.
* OBSOLETE since Rails 1.3.1, but still required to enable reading old saved files */
@@ -549,11 +550,15 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
this.revenueManager = revenueManager;
this.bank = bank;
- players = playerManager.getPlayers();
+ players = new ArrayListState<Player> ("Players", playerManager.getPlayers());
originalPlayerNamesList = playerManager.getPlayerNames();
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());
+ }
showCompositeORNumber = !"simple".equalsIgnoreCase(Config.get("or.number_format"));
}
@@ -578,7 +583,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
moveStack.enable();
}
- private void setGuiParameters () {
+ protected void setGuiParameters () {
for (PublicCompanyI company : companyManager.getAllPublicCompanies()) {
if (company.hasParPrice()) guiParameters.put(GuiDef.Parm.HAS_ANY_PAR_PRICE, true);
@@ -595,7 +600,6 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
break loop;
}
}
-
}
// define guiParameters from gameOptions
@@ -1392,7 +1396,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
/* Sort players by total worth */
List<Player> rankedPlayers = new ArrayList<Player>();
- for (Player player : players) {
+ for (Player player : getPlayers()) {
rankedPlayers.add(player);
}
Collections.sort(rankedPlayers);
@@ -1488,7 +1492,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
* @see rails.game.GameManagerI#getPlayers()
*/
public List<Player> getPlayers() {
- return players;
+ return players.viewList();
}
/* (non-Javadoc)
@@ -1888,23 +1892,31 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
public Player reorderPlayersByCash (boolean ascending) {
final boolean _ascending = ascending;
- Collections.sort (this.players, new Comparator<Player>() {
+ List<Player> reorderedPlayers = new ArrayList<Player>(players.viewList());
+ Collections.sort(reorderedPlayers, new Comparator<Player>() {
public int compare (Player p1, Player p2) {
return _ascending ? p1.getCash() - p2.getCash() : p2.getCash() - p1.getCash();
}
});
+ players.clear();
+
Player player;
- for (int i=0; i<this.players.size(); i++) {
- player = this.players.get(i);
+ for (int i=0; i<reorderedPlayers.size(); i++) {
+ player = reorderedPlayers.get(i);
+ players.add(player);
player.setIndex (i);
- //this.originalPlayerNamesList.set (i, player.getName());
+ playerNameModels[i].set(player.getName());
log.debug("New player "+i+" is "+player.getName() +" (cash="+Bank.format(player.getCash())+")");
}
return this.players.get(0);
}
+ public StringState getPlayerNameModel(int index) {
+ return playerNameModels[index];
+ }
+
public void resetStorage() {
objectStorage = new HashMap<String, Object>();
storageIds = new HashMap<String, Integer>();
diff --git a/rails/game/GameManagerI.java b/rails/game/GameManagerI.java
index 2703019..a321507 100644
--- a/rails/game/GameManagerI.java
+++ b/rails/game/GameManagerI.java
@@ -13,6 +13,7 @@ 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 {
@@ -213,6 +214,7 @@ public interface GameManagerI extends MoveableHolder, ConfigurableComponentI {
public void setSkipDone (GameDef.OrStep step);
public Player reorderPlayersByCash(boolean high);
+ public StringState getPlayerNameModel(int index) ;
/**
* reset the storage for other elements like tokens, special property
diff --git a/rails/game/specific/_1880/GameManager_1880.java b/rails/game/specific/_1880/GameManager_1880.java
index 6fded62..8facac2 100644
--- a/rails/game/specific/_1880/GameManager_1880.java
+++ b/rails/game/specific/_1880/GameManager_1880.java
@@ -3,11 +3,8 @@
*/
package rails.game.specific._1880;
-import rails.game.GameManager;
-import rails.game.PhaseI;
-import rails.game.RoundI;
-import rails.game.StartRound;
-import rails.game.StockRound;
+import rails.common.GuiDef;
+import rails.game.*;
import rails.game.state.IntegerState;
/**
@@ -16,18 +13,24 @@ import rails.game.state.IntegerState;
*
*/
public class GameManager_1880 extends GameManager {
-
+
private RoundI previousRound = null;
public IntegerState numOfORs = new IntegerState("numOfORs");
- //Keeps track of the company that purchased the last train
+ //Keeps track of the company that purchased the last train
private PublicCompany_1880 lastTrainBuyingCompany;
- /**
+ /**
*
*/
public GameManager_1880() {
super();
}
+ @Override
+ protected void setGuiParameters () {
+ super.setGuiParameters();
+ guiParameters.put(GuiDef.Parm.PLAYER_ORDER_VARIES, true);
+ }
+
/* (non-Javadoc)
* @see rails.game.GameManager#nextRound(rails.game.RoundI)
*/
@@ -36,41 +39,41 @@ public class GameManager_1880 extends GameManager {
if (round instanceof StartRound) { // BCR Operates only if all privates are sold out
if (startPacket != null && !startPacket.areAllSold()) {
startOperatingRound(runIfStartPacketIsNotCompletelySold());
- } else {
- startStockRound();
- }
+ } else {
+ startStockRound();
+ }
numOfORs.set(10);
- } else if (round instanceof StockRound) {
- if (interruptedRound != null) {
- setRound(interruptedRound);
- interruptedRound.resume();
- interruptedRound = null;
- } else { // First StockRound after StartRound...
- PhaseI currentPhase = getCurrentPhase();
- if (currentPhase == null) log.error ("Current Phase is null??", new Exception (""));
- // Create a new OperatingRound (never more than one Stock Round)
- // OperatingRound.resetRelativeORNumber();
-
- relativeORNumber.set(1);
-
- startOperatingRound(true);
- }
- } else if ( round instanceof OperatingRound_1880) {
- if (gameOverPending.booleanValue() && !gameEndsAfterSetOfORs) {
+ } else if (round instanceof StockRound) {
+ if (interruptedRound != null) {
+ setRound(interruptedRound);
+ interruptedRound.resume();
+ interruptedRound = null;
+ } else { // First StockRound after StartRound...
+ PhaseI currentPhase = getCurrentPhase();
+ if (currentPhase == null) log.error ("Current Phase is null??", new Exception (""));
+ // Create a new OperatingRound (never more than one Stock Round)
+ // OperatingRound.resetRelativeORNumber();
- finishGame();
+ relativeORNumber.set(1);
- } else if (relativeORNumber.add(1) <= numOfORs.intValue()) {
- // There will be another OR
- startOperatingRound(true);
- } else if (startPacket != null && !startPacket.areAllSold()) {
- startStartRound();
- } else {
- if (gameOverPending.booleanValue() && gameEndsAfterSetOfORs) {
- finishGame();
- }
+ startOperatingRound(true);
+ }
+ } else if ( round instanceof OperatingRound_1880) {
+ if (gameOverPending.booleanValue() && !gameEndsAfterSetOfORs) {
+
+ finishGame();
+
+ } else if (relativeORNumber.add(1) <= numOfORs.intValue()) {
+ // There will be another OR
+ startOperatingRound(true);
+ } else if (startPacket != null && !startPacket.areAllSold()) {
+ startStartRound();
+ } else {
+ if (gameOverPending.booleanValue() && gameEndsAfterSetOfORs) {
+ finishGame();
}
}
+ }
}// End of nextRound
/**
@@ -87,16 +90,16 @@ public class GameManager_1880 extends GameManager {
this.lastTrainBuyingCompany = lastTrainBuyingCompany;
}
- /* (non-Javadoc)
- * @see rails.game.GameManager#startStockRound()
- */
-
- protected void startStockRound_1880(OperatingRound_1880 or) {
- // TODO Auto-generated method stub
- interruptedRound = or;
- super.startStockRound();
- }
+ /* (non-Javadoc)
+ * @see rails.game.GameManager#startStockRound()
+ */
+
+ protected void startStockRound_1880(OperatingRound_1880 or) {
+ // TODO Auto-generated method stub
+ interruptedRound = or;
+ super.startStockRound();
+ }
+
-
}
diff --git a/rails/game/state/ArrayListState.java b/rails/game/state/ArrayListState.java
index 320ed4f..011dd6f 100644
--- a/rails/game/state/ArrayListState.java
+++ b/rails/game/state/ArrayListState.java
@@ -58,13 +58,14 @@ public class ArrayListState<E> {
public void move (E element, int toIndex) {
if (remove (element)) add (toIndex, element);
}
-
+
public boolean contains (E element) {
return list.contains(element);
}
public void clear() {
- for (E element:list) {
+ List<E> copy = new ArrayList<E> (list);
+ for (E element:copy) {
remove(element);
}
}
diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java
index c2e51b3..3e30944 100644
--- a/rails/ui/swing/GameStatus.java
+++ b/rails/ui/swing/GameStatus.java
@@ -1,9 +1,7 @@
package rails.ui.swing;
import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseListener;
+import java.awt.event.*;
import java.util.*;
import java.util.List;
@@ -89,8 +87,8 @@ public class GameStatus extends GridPanel implements ActionListener {
protected int futureTrainsXOffset, futureTrainsYOffset, futureTrainsWidth;
protected int rightCompCaptionXOffset;
- protected Caption[] upperPlayerCaption;
- protected Caption[] lowerPlayerCaption;
+ protected Cell[] upperPlayerCaption;
+ protected Cell[] lowerPlayerCaption;
protected Caption treasurySharesCaption;
protected Portfolio ipo, pool;
@@ -117,7 +115,6 @@ public class GameStatus extends GridPanel implements ActionListener {
protected Map<PublicCompanyI, Integer> companyIndex =
new HashMap<PublicCompanyI, Integer>();
- protected Map<Player, Integer> playerIndex = new HashMap<Player, Integer>();
protected static Logger log =
Logger.getLogger(GameStatus.class.getPackage().getName());
@@ -145,7 +142,7 @@ public class GameStatus extends GridPanel implements ActionListener {
setBorder(BorderFactory.createEtchedBorder());
setOpaque(false);
- players = gameUIManager.getPlayers().toArray(new Player[0]);
+ players = gameUIManager.getPlayers();
np = gameUIManager.getNumberOfPlayers();
companies = gameUIManager.getAllPublicCompanies().toArray(new PublicCompanyI[0]);
nc = companies.length;
@@ -186,8 +183,8 @@ public class GameStatus extends GridPanel implements ActionListener {
playerWorth = new Field[np];
playerORWorthIncrease = new Field[np];
playerCertCount = new Field[np];
- upperPlayerCaption = new Caption[np];
- lowerPlayerCaption = new Caption[np];
+ upperPlayerCaption = new Cell[np];
+ lowerPlayerCaption = new Cell[np];
MouseListener companyCaptionMouseClickListener = gameUIManager.getORUIManager().getORPanel().getCompanyCaptionMouseClickListener();
@@ -258,15 +255,21 @@ public class GameStatus extends GridPanel implements ActionListener {
fields = new JComponent[1+lastX][2+lastY];
rowVisibilityObservers = new RowVisibility[nc];
+ // 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++) {
- playerIndex.put(players[i], new Integer(i));
- f = upperPlayerCaption[i] = new Caption(players[i].getNameAndPriority());
- int wideGapPosition = WIDE_BOTTOM +
- ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
+ 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());
+ }
+ int wideGapPosition = WIDE_BOTTOM +
+ ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
addField(f, certPerPlayerXOffset + i, 1, 1, 1, wideGapPosition, true);
}
addField(new Caption(LocalText.getText("BANK_SHARES")),
@@ -341,7 +344,7 @@ public class GameStatus extends GridPanel implements ActionListener {
f =
certPerPlayer[i][j] =
new Field(
- players[j].getPortfolio().getShareModel(
+ players.get(j).getPortfolio().getShareModel(
c));
int wideGapPosition = ((j==0)? WIDE_LEFT : 0) + ((j==np-1)? WIDE_RIGHT : 0);
addField(f, certPerPlayerXOffset + j, certPerPlayerYOffset + i,
@@ -364,7 +367,7 @@ public class GameStatus extends GridPanel implements ActionListener {
LocalText.getText("ClickToSelectForBuying"),
this, buySellGroup);
addField(f, certInIPOXOffset, certInIPOYOffset + i, 1, 1, 0, false);
-
+
//no size alignment as button size could also be smaller than the field's one
//certInIPO[i].setPreferredSize(certInIPOButton[i].getPreferredSize());
@@ -471,9 +474,9 @@ public class GameStatus extends GridPanel implements ActionListener {
addField(new Caption(LocalText.getText("CASH")), 0, playerCashYOffset,
1, 1, WIDE_TOP , true);
for (int i = 0; i < np; i++) {
- f = playerCash[i] = new Field(players[i].getCashModel());
- int wideGapPosition = WIDE_TOP +
- ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
+ f = playerCash[i] = new Field(players.get(i).getCashModel());
+ int wideGapPosition = WIDE_TOP +
+ ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
addField(f, playerCashXOffset + i, playerCashYOffset, 1, 1,
wideGapPosition, true);
f =
@@ -493,10 +496,10 @@ public class GameStatus extends GridPanel implements ActionListener {
f =
playerPrivates[i] =
new Field(
- players[i].getPortfolio().getPrivatesOwnedModel());
+ players.get(i).getPortfolio().getPrivatesOwnedModel());
HexHighlightMouseListener.addMouseListener(f,
gameUIManager.getORUIManager(),
- players[i].getPortfolio());
+ players.get(i).getPortfolio());
int wideGapPosition = ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
addField(f, playerPrivatesXOffset + i, playerPrivatesYOffset, 1, 1,
wideGapPosition, true);
@@ -505,7 +508,7 @@ public class GameStatus extends GridPanel implements ActionListener {
addField(new Caption(LocalText.getText("WORTH")), 0,
playerWorthYOffset, 1, 1, 0, true);
for (int i = 0; i < np; i++) {
- f = playerWorth[i] = new Field(players[i].getWorthModel());
+ f = playerWorth[i] = new Field(players.get(i).getWorthModel());
int wideGapPosition = ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
addField(f, playerWorthXOffset + i, playerWorthYOffset, 1, 1, wideGapPosition, true);
}
@@ -513,7 +516,7 @@ public class GameStatus extends GridPanel implements ActionListener {
addField(new Caption(LocalText.getText("ORWORTHINCR")), 0,
playerORWorthIncreaseYOffset, 1, 1, 0, true);
for (int i = 0; i < np; i++) {
- f = playerORWorthIncrease[i] = new Field(players[i].getLastORWorthIncrease());
+ f = playerORWorthIncrease[i] = new Field(players.get(i).getLastORWorthIncrease());
int wideGapPosition = ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
addField(f, playerORWorthIncreaseXOffset + i, playerORWorthIncreaseYOffset, 1, 1, wideGapPosition, true);
}
@@ -523,17 +526,23 @@ public class GameStatus extends GridPanel implements ActionListener {
for (int i = 0; i < np; i++) {
f =
playerCertCount[i] =
- new Field(players[i].getCertCountModel(), false, true);
- int wideGapPosition = WIDE_TOP +
- ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
+ new Field(players.get(i).getCertCountModel(), false, true);
+ int wideGapPosition = WIDE_TOP +
+ ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
addField(f, playerCertCountXOffset + i, playerCertCountYOffset, 1,
1, wideGapPosition, true);
}
-
+
+ // Bottom player captions
for (int i = 0; i < np; i++) {
- f = lowerPlayerCaption[i] = new Caption(players[i].getName());
- int wideGapPosition = WIDE_TOP +
- ((i==0)? WIDE_LEFT : 0) + ((i==np-1)? WIDE_RIGHT : 0);
+ 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);
}
@@ -948,7 +957,7 @@ public class GameStatus extends GridPanel implements ActionListener {
}
if (ch instanceof Player) {
Player p = (Player)ch;
- int i = playerIndex.get(p);
+ int i = players.indexOf(p);
setPlayerCashButton(i, true, a);
}
}
@@ -961,7 +970,7 @@ public class GameStatus extends GridPanel implements ActionListener {
public void setPriorityPlayer(int index) {
for (int j = 0; j < np; j++) {
- upperPlayerCaption[j].setText(players[j].getName()
+ upperPlayerCaption[j].setText(players.get(j).getName()
+ (j == index ? " PD" : ""));
}
}
@@ -982,7 +991,7 @@ public class GameStatus extends GridPanel implements ActionListener {
public String getSRPlayer() {
if (actorIndex >= 0)
- return players[actorIndex].getName();
+ return players.get(actorIndex).getName();
else
return "";
}
diff --git a/rails/ui/swing/GridPanel.java b/rails/ui/swing/GridPanel.java
index 6644dd1..9f11f42 100644
--- a/rails/ui/swing/GridPanel.java
+++ b/rails/ui/swing/GridPanel.java
@@ -7,9 +7,7 @@ import java.util.*;
import java.util.List;
import javax.swing.*;
-import javax.swing.border.AbstractBorder;
-import javax.swing.border.Border;
-import javax.swing.border.CompoundBorder;
+import javax.swing.border.*;
import org.apache.log4j.Logger;
@@ -17,10 +15,7 @@ import rails.common.parser.Config;
import rails.game.*;
import rails.game.model.ModelObject;
import rails.game.state.BooleanState;
-import rails.ui.swing.elements.Caption;
-import rails.ui.swing.elements.ClickField;
-import rails.ui.swing.elements.Field;
-import rails.ui.swing.elements.ViewObject;
+import rails.ui.swing.elements.*;
public abstract class GridPanel extends JPanel
implements ActionListener, KeyListener {
@@ -43,7 +38,7 @@ implements ActionListener, KeyListener {
protected static Color buttonHighlight = new Color(255, 160, 80);
protected int np;
- protected Player[] players;
+ protected List<Player> players;
protected int nc;
protected PublicCompanyI[] companies;
protected RoundI round;
@@ -66,7 +61,7 @@ implements ActionListener, KeyListener {
protected Color tableBorderColor;
protected Color cellOutlineColor;
protected Color highlightedBorderColor;
-
+
public GridPanel() {
//initialize border colors according to the configuration
if ("enabled".equals(Config.get("gridPanel.tableBorders"))) {
@@ -117,29 +112,29 @@ implements ActionListener, KeyListener {
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;
-
- //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)));
-
- gridPanel.add(comp, gbc);
-
- if (comp instanceof ViewObject
- && ((ViewObject) comp).getModel() != null) {
- observers.add((ViewObject) comp);
- }
+ (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)
+
+ comp.setBorder(new FieldBorder(comp.getBorder(),
+ new DynamicBorder(cellOutlineColor,NARROW_GAP),
+ new DynamicBorder(tableBorderColor,padTop,padLeft,padBottom,padRight)));
+
+ gridPanel.add(comp, gbc);
+
+ 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);
}
-
+
/**
* highlights given component by altering its border's attributes
*/
@@ -147,7 +142,7 @@ implements ActionListener, KeyListener {
//quit if nothing is to be done
if (isToBeHighlighted && highlightedComps.contains(comp)) return;
if (!isToBeHighlighted && !highlightedComps.contains(comp)) return;
-
+
if (comp.getBorder() instanceof FieldBorder) {
FieldBorder fb = (FieldBorder)comp.getBorder();
fb.setHighlight(isToBeHighlighted);
@@ -159,7 +154,7 @@ implements ActionListener, KeyListener {
}
}
}
-
+
protected void removeAllHighlights() {
for (JComponent c : highlightedComps) {
if (c.getBorder() instanceof FieldBorder) {
@@ -170,7 +165,7 @@ implements ActionListener, KeyListener {
}
highlightedComps.clear();
}
-
+
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_F1) {
HelpWindow.displayHelp(GameManager.getInstance().getHelp());
@@ -242,7 +237,7 @@ implements ActionListener, KeyListener {
}
/**
- * Wrapper for three level compound borders and directly accessing border constituents
+ * Wrapper for three level compound borders and directly accessing border constituents
* @author Frederick Weld
*
*/
@@ -266,13 +261,13 @@ implements ActionListener, KeyListener {
}
public void setHighlight(boolean isToBeHighlighted) {
outlineBorder.setHighlight(isToBeHighlighted);
- this.insideBorder = isToBeHighlighted ?
+ this.insideBorder = isToBeHighlighted ?
highlightedInnerBorder : nativeInnerBorder;
}
}
/**
- * A potentially asymmetric line border providing methods for changing the look
+ * A potentially asymmetric line border providing methods for changing the look
* @author Frederick Weld
*
*/
@@ -289,7 +284,7 @@ implements ActionListener, KeyListener {
this.padRight = symmetricPad;
this.borderColor = borderColor;
}
-
+
public DynamicBorder (Color borderColor,int padTop, int padLeft, int padBottom, int padRight) {
this.padTop = padTop;
this.padLeft = padLeft;
@@ -297,13 +292,14 @@ implements ActionListener, KeyListener {
this.padRight = padRight;
this.borderColor = borderColor;
}
-
+
public void setHighlight(boolean isToBeHighlighted) {
if (isHighlighted != isToBeHighlighted) {
isHighlighted = isToBeHighlighted;
}
}
+ @Override
public void paintBorder(Component c,Graphics g, int x, int y, int width,int height) {
Graphics2D g2d = (Graphics2D)g;
if (isHighlighted) {
@@ -331,12 +327,14 @@ implements ActionListener, KeyListener {
g2d.setStroke(oldStroke);
}
+ @Override
public Insets getBorderInsets (Component c) {
return new Insets(padTop,padLeft,padBottom,padRight);
}
- public boolean isBorderOpaque() {
- return true;
+ @Override
+ public boolean isBorderOpaque() {
+ return true;
}
}
}
diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java
index c8193ac..566b06b 100644
--- a/rails/ui/swing/ORPanel.java
+++ b/rails/ui/swing/ORPanel.java
@@ -149,7 +149,7 @@ implements ActionListener, KeyListener, RevenueListener {
initButtonPanel();
gbc = new GridBagConstraints();
- players = gameUIManager.getPlayers().toArray(new Player[0]);
+ players = gameUIManager.getPlayers();
if (round instanceof OperatingRound) {
companies = ((OperatingRound) round).getOperatingCompanies().toArray(new PublicCompanyI[0]);
@@ -790,7 +790,7 @@ implements ActionListener, KeyListener, RevenueListener {
redoButton.setEnabled(false);
disableRoutesDisplay();
-
+
//clear all highlighting (president column and beyond)
resetActions();
@@ -1005,9 +1005,9 @@ implements ActionListener, KeyListener, RevenueListener {
this.orComp = orComp;
this.orCompIndex = orCompIndex;
president[orCompIndex].setHighlight(true);
-
+
removeAllHighlights();
-
+
buttonOC.clearPossibleActions();
button1.clearPossibleActions();
button2.clearPossibleActions();
@@ -1021,7 +1021,7 @@ implements ActionListener, KeyListener, RevenueListener {
updateCurrentRoutes(false);
}
-
+
public void initTileLayingStep() {
tileCaption.setHighlight(true);
@@ -1244,7 +1244,7 @@ implements ActionListener, KeyListener, RevenueListener {
button1.setEnabled(false);
orCompIndex = -1;
-
+
orUIManager.getMap().setTrainPaths(null);
}
@@ -1255,7 +1255,7 @@ implements ActionListener, KeyListener, RevenueListener {
public String getORPlayer() {
if (playerIndex >= 0)
- return players[playerIndex].getName();
+ return players.get(playerIndex).getName();
else
return "";
}
diff --git a/rails/ui/swing/StartRoundWindow.java b/rails/ui/swing/StartRoundWindow.java
index 8f33970..4cf1b88 100644
--- a/rails/ui/swing/StartRoundWindow.java
+++ b/rails/ui/swing/StartRoundWindow.java
@@ -10,6 +10,7 @@ import javax.swing.*;
import org.apache.log4j.Logger;
+import rails.common.GuiDef;
import rails.common.LocalText;
import rails.game.*;
import rails.game.action.*;
@@ -62,8 +63,8 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
private int infoXOffset, infoYOffset;
private Field itemStatus[]; // Remains invisible, only used for status tooltip
- private Caption[] upperPlayerCaption;
- private Caption[] lowerPlayerCaption;
+ private Cell[] upperPlayerCaption;
+ private Cell[] lowerPlayerCaption;
private ActionButton bidButton;
private ActionButton buyButton;
@@ -110,13 +111,10 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
private boolean includeBidding;
private boolean showBasePrices;
- // private boolean repacked = false;
-
protected static Logger log =
Logger.getLogger(StartRoundWindow.class.getPackage().getName());
public void init(StartRound round, GameUIManager parent) {
- //super();
this.round = round;
includeBidding = round.hasBidding();
showBasePrices = round.hasBasePrices();
@@ -238,8 +236,8 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
bidPerPlayer = new Field[ni][np];
info = new Field[ni];
itemStatus = new Field[ni];
- upperPlayerCaption = new Caption[np];
- lowerPlayerCaption = new Caption[np];
+ upperPlayerCaption = new Cell[np];
+ lowerPlayerCaption = new Cell[np];
playerBids = new Field[np];
playerFree = new Field[np];
@@ -279,27 +277,35 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
addField(new Caption(LocalText.getText("MINIMUM_BID")),
minBidXOffset, 0, 1, 2, WIDE_BOTTOM + WIDE_RIGHT);
}
+
+ // Top player captions
addField(new Caption(LocalText.getText("PLAYERS")),
bidPerPlayerXOffset, 0, np, 1, 0);
+ boolean playerOrderCanVary = getGameUIManager().getGameParameterAsBoolean(GuiDef.Parm.PLAYER_ORDER_VARIES);
for (int i = 0; i < np; i++) {
- f = upperPlayerCaption[i] = new Caption(players[i].getName());
+ 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[i].getName());
+ }
addField(f, bidPerPlayerXOffset + i, 1, 1, 1, WIDE_BOTTOM);
}
for (int i = 0; i < ni; i++) {
si = items[i];
f = itemName[i] = new Caption(si.getName());
- HexHighlightMouseListener.addMouseListener(f,
+ HexHighlightMouseListener.addMouseListener(f,
gameUIManager.getORUIManager(),
- si);
+ si);
addField(f, itemNameXOffset, itemNameYOffset + i, 1, 1, WIDE_RIGHT);
f =
itemNameButton[i] =
new ClickField(si.getName(), "", "", this,
itemGroup);
- HexHighlightMouseListener.addMouseListener(f,
+ HexHighlightMouseListener.addMouseListener(f,
gameUIManager.getORUIManager(),
- si);
+ si);
addField(f, itemNameXOffset, itemNameYOffset + i, 1, 1, WIDE_RIGHT);
// Prevent row height resizing after every buy action
itemName[i].setPreferredSize(itemNameButton[i].getPreferredSize());
@@ -322,9 +328,9 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
f = info[i] = new Field (infoIcon);
f.setToolTipText(getStartItemDescription(si));
- HexHighlightMouseListener.addMouseListener(f,
+ HexHighlightMouseListener.addMouseListener(f,
gameUIManager.getORUIManager(),
- si);
+ si);
addField (f, infoXOffset, infoYOffset + i, 1, 1, WIDE_LEFT);
// Invisible field, only used to hold current item status.
@@ -360,7 +366,12 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
}
for (int i = 0; i < np; i++) {
- f = lowerPlayerCaption[i] = new Caption(players[i].getName());
+ 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[i].getName());
+ }
addField(f, playerFreeCashXOffset + i, playerFreeCashYOffset + 1,
1, 1, WIDE_TOP);
}
@@ -702,7 +713,7 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner {
}
public void setSRPlayerTurn(int selectedPlayerIndex) {
-
+
highlightCurrentPlayer(selectedPlayerIndex);
}
diff --git a/rails/ui/swing/elements/Caption.java b/rails/ui/swing/elements/Caption.java
index aacaa96..78c6610 100644
--- a/rails/ui/swing/elements/Caption.java
+++ b/rails/ui/swing/elements/Caption.java
@@ -1,38 +1,17 @@
/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/Caption.java,v 1.4 2008/06/04 19:00:38 evos Exp $*/
package rails.ui.swing.elements;
-import java.awt.Color;
+import javax.swing.ImageIcon;
-import javax.swing.*;
-import javax.swing.border.Border;
-
-public class Caption extends JLabel {
+public class Caption extends Cell {
private static final long serialVersionUID = 1L;
- private Border labelBorder = BorderFactory.createEmptyBorder(1, 2, 1, 2);
-
- private static final Color NORMAL_BG_COLOUR = new Color(240, 240, 240);
-
- private static final Color HIGHLIGHT_BG_COLOUR = new Color(255, 255, 80);
-
- private static final Color NORMAL_FG_COLOUR = new Color (0, 0, 0);
-
- private static final Color LOCAL_PLAYER_COLOUR = new Color (255, 0, 0);
-
public Caption(String text) {
- super(text);
- this.setForeground(NORMAL_FG_COLOUR);
- this.setBackground(NORMAL_BG_COLOUR);
- this.setHorizontalAlignment(SwingConstants.CENTER);
- this.setBorder(labelBorder);
- this.setOpaque(true);
+ super(text, true);
}
- public void setHighlight(boolean highlight) {
- this.setBackground(highlight ? HIGHLIGHT_BG_COLOUR : NORMAL_BG_COLOUR);
+ public Caption (ImageIcon icon) {
+ super (icon, true);
}
- public void setLocalPlayer (boolean highlight) {
- this.setForeground(highlight ? LOCAL_PLAYER_COLOUR : NORMAL_FG_COLOUR);
- }
}
diff --git a/rails/ui/swing/elements/Cell.java b/rails/ui/swing/elements/Cell.java
new file mode 100644
index 0000000..54d5c87
--- /dev/null
+++ b/rails/ui/swing/elements/Cell.java
@@ -0,0 +1,46 @@
+/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/Cell.java,v 1.4 2008/06/04 19:00:38 evos Exp $*/
+package rails.ui.swing.elements;
+
+import java.awt.Color;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+
+public abstract class Cell extends JLabel {
+ private static final long serialVersionUID = 1L;
+
+ protected Border labelBorder = BorderFactory.createEmptyBorder(1, 2, 1, 2);
+
+ public static final Color NORMAL_CAPTION_BG_COLOUR = new Color(240, 240, 240);
+ public static final Color NORMAL_FIELD_BG_COLOUR = Color.WHITE;
+ public static final Color HIGHLIGHT_BG_COLOUR = new Color(255, 255, 80);
+ public static final Color NORMAL_FG_COLOUR = new Color (0, 0, 0);
+ public static final Color LOCAL_PLAYER_COLOUR = new Color (255, 0, 0);
+
+ protected Color normalBgColour = NORMAL_FIELD_BG_COLOUR;
+
+ public Cell(String text, boolean asCaption) {
+ super(text);
+ setForeground(NORMAL_FG_COLOUR);
+ setNormalBgColour (asCaption ? NORMAL_CAPTION_BG_COLOUR : NORMAL_FIELD_BG_COLOUR);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ setBorder(labelBorder);
+ setOpaque(true);
+ }
+
+ public Cell (ImageIcon icon, boolean asCaption) {
+ super (icon);
+ }
+
+ public void setHighlight(boolean highlight) {
+ this.setBackground(highlight ? HIGHLIGHT_BG_COLOUR : normalBgColour);
+ }
+
+ public void setNormalBgColour (Color colour) {
+ setBackground (normalBgColour = colour);
+ }
+
+ public void setLocalPlayer (boolean highlight) {
+ this.setForeground(highlight ? LOCAL_PLAYER_COLOUR : NORMAL_FG_COLOUR);
+ }
+}
diff --git a/rails/ui/swing/elements/Field.java b/rails/ui/swing/elements/Field.java
index eee384b..ede39b7 100644
--- a/rails/ui/swing/elements/Field.java
+++ b/rails/ui/swing/elements/Field.java
@@ -5,25 +5,18 @@ import java.awt.Color;
import java.awt.Graphics;
import java.util.*;
-import javax.swing.*;
-import javax.swing.border.Border;
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
import rails.game.model.ModelObject;
import rails.game.model.ViewUpdate;
import rails.util.Util;
-public class Field extends JLabel implements ViewObject {
+public class Field extends Cell implements ViewObject {
private static final long serialVersionUID = 1L;
- private Border labelBorder = BorderFactory.createEmptyBorder(1, 2, 1, 2);
-
- private static final Color NORMAL_BG_COLOUR = Color.WHITE;
-
- private static final Color HIGHLIGHT_BG_COLOUR = new Color(255, 255, 80);
-
private ModelObject modelObject;
- private Color normalBgColour = NORMAL_BG_COLOUR;
private List<JComponent> dependents = null;
@@ -35,19 +28,11 @@ public class Field extends JLabel implements ViewObject {
private String baseToolTipInfo = null;
public Field(String text) {
- super(text.equals("0%") ? "" : text);
- this.setBackground(NORMAL_BG_COLOUR);
- this.setHorizontalAlignment(SwingConstants.CENTER);
- this.setBorder(labelBorder);
- this.setOpaque(true);
+ super(text.equals("0%") ? "" : text, false);
}
public Field(ImageIcon info) {
- super(info);
- this.setBackground(NORMAL_BG_COLOUR);
- this.setHorizontalAlignment(SwingConstants.CENTER);
- this.setBorder(labelBorder);
- this.setOpaque(true);
+ super(info, false);
}
public Field(ModelObject modelObject) {
@@ -81,10 +66,6 @@ public class Field extends JLabel implements ViewObject {
update(null, null);
}
- public void setHighlight(boolean highlight) {
- setBackground(highlight ? HIGHLIGHT_BG_COLOUR : normalBgColour);
- }
-
/** This method is mainly needed when NOT using the Observer pattern. */
@Override
|