|
From: Erik V. <ev...@us...> - 2011-10-04 17:34:57
|
rails/common/GuiDef.java | 7
rails/game/GameManager.java | 14
rails/game/StockRound.java | 67 ++--
rails/ui/swing/GameUIManager.java | 160 +++++----
rails/ui/swing/StartRoundWindow.java | 182 +++++------
rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java | 7
6 files changed, 234 insertions(+), 203 deletions(-)
New commits:
commit 49c5d96547d2904ccfc803dc9018b56233b39537
Author: Erik Vos <eri...@xs...>
Date: Tue Oct 4 19:34:19 2011 +0200
Allow game-specific StartRoundWindow classes.
Added empty StartRoundWindow_1880 class.
diff --git a/rails/common/GuiDef.java b/rails/common/GuiDef.java
index 570db32..5d75906 100644
--- a/rails/common/GuiDef.java
+++ b/rails/common/GuiDef.java
@@ -9,7 +9,8 @@ public class GuiDef {
OR_UI_MANAGER ("rails.ui.swing.ORUIManager"),
STATUS_WINDOW ("rails.ui.swing.StatusWindow"),
GAME_STATUS ("rails.ui.swing.GameStatus"),
- OR_WINDOW ("rails.ui.swing.ORWindow");
+ OR_WINDOW ("rails.ui.swing.ORWindow"),
+ START_ROUND_WINDOW ("rails.ui.swing.StartRoundWindow");
private String defaultClassName;
@@ -54,5 +55,5 @@ public class GuiDef {
MAP,
STOCK_MARKET
}
-
- }
+
+}
diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java
index eac056d..c691147 100644
--- a/rails/game/GameManager.java
+++ b/rails/game/GameManager.java
@@ -46,6 +46,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
protected String gameStatusClassName = GuiDef.getDefaultClassName(GuiDef.ClassName.GAME_STATUS);
protected String statusWindowClassName = GuiDef.getDefaultClassName(GuiDef.ClassName.STATUS_WINDOW);
protected String orWindowClassName = GuiDef.getDefaultClassName(GuiDef.ClassName.OR_WINDOW);
+ protected String startRoundWindowClassName = GuiDef.getDefaultClassName(GuiDef.ClassName.START_ROUND_WINDOW);
protected PlayerManager playerManager;
protected CompanyManagerI companyManager;
@@ -489,6 +490,16 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
// Check instantiatability (not sure if this belongs here)
canClassBeInstantiated (orWindowClassName);
}
+
+ // StartRoundWindow class
+ Tag startRoundWindowTag = guiClassesTag.getChild("StartRoundWindow");
+ if (startRoundWindowTag != null) {
+ startRoundWindowClassName =
+ startRoundWindowTag.getAttributeAsString("class",
+ startRoundWindowClassName);
+ // Check instantiatability (not sure if this belongs here)
+ canClassBeInstantiated (startRoundWindowClassName);
+ }
}
}
@@ -1640,6 +1651,9 @@ public class GameManager implements ConfigurableComponentI, GameManagerI {
case STATUS_WINDOW:
return statusWindowClassName;
+ case START_ROUND_WINDOW:
+ return startRoundWindowClassName;
+
case GAME_STATUS:
return gameStatusClassName;
diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java
index bee4214..07b5726 100644
--- a/rails/ui/swing/GameUIManager.java
+++ b/rails/ui/swing/GameUIManager.java
@@ -13,15 +13,12 @@ import javax.swing.plaf.FontUIResource;
import org.apache.log4j.Logger;
-import rails.common.DisplayBuffer;
-import rails.common.GuiDef;
-import rails.common.GuiHints;
-import rails.common.LocalText;
+import rails.common.*;
import rails.common.parser.Config;
import rails.game.*;
import rails.game.action.*;
import rails.ui.swing.elements.*;
-import rails.util.*;
+import rails.util.Util;
/**
* This class is called by main() and loads all of the UI components
@@ -69,7 +66,7 @@ public class GameUIManager implements DialogOwner {
protected String providedName = null;
protected SimpleDateFormat saveDateTimeFormat;
protected File lastFile, lastDirectory;
-
+
protected boolean autoSaveLoadInitialized = false;
protected int autoSaveLoadStatus = 0;
protected int autoSaveLoadPollingInterval = 30;
@@ -78,7 +75,7 @@ public class GameUIManager implements DialogOwner {
protected String lastSavedFilenameFilepath;
protected String lastSavedFilename = "";
protected String localPlayerName = "";
-
+
protected boolean gameWasLoaded = false;
protected WindowSettings windowSettings;
@@ -92,7 +89,7 @@ public class GameUIManager implements DialogOwner {
protected boolean previousResult;
protected static Logger log =
- Logger.getLogger(GameUIManager.class.getPackage().getName());
+ Logger.getLogger(GameUIManager.class.getPackage().getName());
public GameUIManager() {
@@ -201,11 +198,11 @@ public class GameUIManager implements DialogOwner {
Class.forName(statusWindowClassName).asSubclass(StatusWindow.class);
statusWindow = statusWindowClass.newInstance();
-// GraphicsEnvironment ge = GraphicsEnvironment.
-// getLocalGraphicsEnvironment();
-// GraphicsDevice[] gs = ge.getScreenDevices();
-// log.debug("ScreenDevices = " + Arrays.toString(gs));
-// statusWindow = statusWindowClass.getConstructor(GraphicsConfiguration.class).newInstance(gs[1].getDefaultConfiguration());
+ // GraphicsEnvironment ge = GraphicsEnvironment.
+ // getLocalGraphicsEnvironment();
+ // GraphicsDevice[] gs = ge.getScreenDevices();
+ // log.debug("ScreenDevices = " + Arrays.toString(gs));
+ // statusWindow = statusWindowClass.getConstructor(GraphicsConfiguration.class).newInstance(gs[1].getDefaultConfiguration());
statusWindow.init(this);
} catch (Exception e) {
@@ -245,7 +242,7 @@ public class GameUIManager implements DialogOwner {
result = previousResult;
} else {
-
+
Player oldPlayer = getCurrentPlayer();
boolean wasMyTurn = oldPlayer.getName().equals(localPlayerName);
@@ -268,7 +265,7 @@ public class GameUIManager implements DialogOwner {
(JFrame) activeWindow,
LocalText.getText("Message"),
LocalText.getText("YourTurn", localPlayerName)),
- null);
+ null);
log.info ("Resuming turn as "+localPlayerName);
} else {
log.info(newPlayer.getName()+" now has the turn");
@@ -303,13 +300,13 @@ public class GameUIManager implements DialogOwner {
if (!result) return false;
- return activeWindow.processImmediateAction();
+ return activeWindow.processImmediateAction();
}
protected boolean processOnServer (PossibleAction action) {
-
+
boolean result;
-
+
action.setActed();
action.setPlayerName(getCurrentPlayer().getName());
@@ -329,7 +326,7 @@ public class GameUIManager implements DialogOwner {
return result;
}
-
+
public boolean displayServerMessage() {
String[] message = DisplayBuffer.get();
if (message != null) {
@@ -337,7 +334,7 @@ public class GameUIManager implements DialogOwner {
(JFrame) activeWindow,
LocalText.getText("Message"),
"<html>" + Util.joinWithDelimiter(message, "<br>")),
- null);
+ null);
return true;
}
return false;
@@ -354,7 +351,7 @@ public class GameUIManager implements DialogOwner {
currentRoundName = currentRound.toString();
log.debug("Current round=" + currentRoundName + ", previous round="
- + previousRoundName);
+ + previousRoundName);
currentRoundType = uiHints.getCurrentRoundType();
@@ -394,7 +391,18 @@ public class GameUIManager implements DialogOwner {
log.debug("UI entering Start Round "+currentRoundName);
startRound = (StartRound) currentRound;
if (startRoundWindow == null) {
- startRoundWindow = new StartRoundWindow(startRound, this);
+ //startRoundWindow = new StartRoundWindow(startRound, this);
+ String startRoundWindowClassName = getClassName(GuiDef.ClassName.START_ROUND_WINDOW);
+ try {
+ Class<? extends StartRoundWindow> startRoundWindowClass =
+ Class.forName(startRoundWindowClassName).asSubclass(StartRoundWindow.class);
+ startRoundWindow = startRoundWindowClass.newInstance();
+ startRoundWindow.init(startRound, this);
+ } catch (Exception e) {
+ log.fatal("Cannot instantiate class " + startRoundWindowClassName, e);
+ System.exit(1);
+
+ }
}
} else if (StockRound.class.isAssignableFrom(currentRoundType)) {
@@ -427,13 +435,13 @@ public class GameUIManager implements DialogOwner {
switch (hint.getType()) {
case STOCK_MARKET:
boolean stockChartVisibilityHint = hint.getVisibility()
- || configuredStockChartVisibility;
+ || configuredStockChartVisibility;
if (stockChartVisibilityHint != previousStockChartVisibilityHint) {
stockChart.setVisible(stockChartVisibilityHint);
previousStockChartVisibilityHint = stockChartVisibilityHint;
}
if (hint.getVisibility()) stockChart.toFront();
- break;
+ break;
case STATUS:
boolean statusWindowVisibilityHint = hint.getVisibility();
if (statusWindowVisibilityHint != previousStatusWindowVisibilityHint) {
@@ -496,7 +504,7 @@ public class GameUIManager implements DialogOwner {
startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex());
} else if (StatusWindow.class.isAssignableFrom(activeWindow.getClass())) {
-// } else {
+ // } else {
log.debug("Updating Stock (status) round window");
statusWindow.updateStatus(myTurn);
@@ -523,7 +531,7 @@ public class GameUIManager implements DialogOwner {
List<TrainI> trains = dt.getOwnedTrains();
int size = trains.size() + (dt.isForced() ? 0 : 1);
List<String> trainOptions =
- new ArrayList<String>(size);
+ new ArrayList<String>(size);
String[] options = new String[size];
String prompt = null;
@@ -548,16 +556,16 @@ public class GameUIManager implements DialogOwner {
c.getName() );
String discardedTrainName =
- (String) JOptionPane.showInputDialog(orWindow,
- prompt,
- LocalText.getText("WhichTrainToDiscard"),
- JOptionPane.QUESTION_MESSAGE, null,
- options, options[0]);
+ (String) JOptionPane.showInputDialog(orWindow,
+ prompt,
+ LocalText.getText("WhichTrainToDiscard"),
+ JOptionPane.QUESTION_MESSAGE, null,
+ options, options[0]);
if (discardedTrainName != null) {
int index = trainOptions.indexOf(discardedTrainName);
if (index >= offset) {
TrainI discardedTrain =
- trains.get(trainOptions.indexOf(discardedTrainName)-offset);
+ trains.get(trainOptions.indexOf(discardedTrainName)-offset);
dt.setDiscardedTrain(discardedTrain);
}
@@ -613,7 +621,7 @@ public class GameUIManager implements DialogOwner {
orWindow.toFront();
CheckBoxDialog dialog = new CheckBoxDialog(this,
- orWindow,
+ orWindow,
LocalText.getText("ExchangeTokens"),
prompt,
options.toArray(new String[0]));
@@ -682,22 +690,22 @@ public class GameUIManager implements DialogOwner {
for (int index=0; index < options.length; index++) {
if (exchanged[index]) {
action.getTokensToExchange().get(index).setSelected(true);
- }
+ }
}
} else if (currentDialog instanceof RadioButtonDialog
- && currentDialogAction instanceof RepayLoans) {
+ && currentDialogAction instanceof RepayLoans) {
+
+ RadioButtonDialog dialog = (RadioButtonDialog) currentDialog;
+ RepayLoans action = (RepayLoans) currentDialogAction;
+ int selected = dialog.getSelectedOption();
+ action.setNumberTaken(action.getMinNumber() + selected);
- RadioButtonDialog dialog = (RadioButtonDialog) currentDialog;
- RepayLoans action = (RepayLoans) currentDialogAction;
- int selected = dialog.getSelectedOption();
- action.setNumberTaken(action.getMinNumber() + selected);
-
} else if (currentDialog instanceof MessageDialog) {
// Nothing to do
currentDialogAction = null; // Should already be null
-
+
} else if (currentDialog instanceof AutoSaveLoadDialog) {
-
+
autoSaveLoadGame2 ((AutoSaveLoadDialog)currentDialog);
} else {
@@ -708,22 +716,22 @@ public class GameUIManager implements DialogOwner {
/*if (currentDialogAction != null)*/ processAction(currentDialogAction);
}
-
+
protected void autoSave (String newPlayer) {
lastSavedFilename = savePrefix + "_"
- + saveDateTimeFormat.format(new Date()) + "_"
- + newPlayer + "."
- + saveExtension;
+ + saveDateTimeFormat.format(new Date()) + "_"
+ + newPlayer + "."
+ + saveExtension;
GameAction saveAction = new GameAction(GameAction.SAVE);
saveAction.setFilepath(saveDirectory + "/" + lastSavedFilename);
log.debug("Autosaving to "+lastSavedFilename);
processOnServer (saveAction);
-
+
saveAutoSavedFilename (lastSavedFilename);
}
-
+
protected void saveAutoSavedFilename (String lastSavedFilename) {
-
+
try {
File f = new File (lastSavedFilenameFilepath);
PrintWriter out = new PrintWriter (new FileWriter (f));
@@ -732,9 +740,9 @@ public class GameUIManager implements DialogOwner {
} catch (IOException e) {
log.error ("Exception whilst autosaving file '"+lastSavedFilenameFilepath+"'", e);
}
-
+
}
-
+
protected boolean pollingIsOn () {
return autoLoadPoller != null && autoLoadPoller.getStatus() == AutoLoadPoller.ON;
}
@@ -833,10 +841,10 @@ public class GameUIManager implements DialogOwner {
currentSuffix = saveSuffix;
}
filename =
- saveDirectory + "/" + savePrefix + "_"
- + saveDateTimeFormat.format(new Date()) + "_"
- + currentSuffix + "."
- + saveExtension;
+ saveDirectory + "/" + savePrefix + "_"
+ + saveDateTimeFormat.format(new Date()) + "_"
+ + currentSuffix + "."
+ + saveExtension;
}
File proposedFile = new File(filename);
@@ -858,7 +866,7 @@ public class GameUIManager implements DialogOwner {
&& proposedParts[1].equals(selectedParts[1])) {
savePrefix = selectedParts[0];
} else {
- // Otherwise, remember and keep using the whole filename.
+ // Otherwise, remember and keep using the whole filename.
providedName = filepath;
}
}
@@ -883,9 +891,9 @@ public class GameUIManager implements DialogOwner {
}
}
-
+
public void autoSaveLoadGame () {
-
+
localPlayerName = System.getProperty("local.player.name");
if (!Util.hasValue(localPlayerName)) {
localPlayerName = Config.get("local.player.name");
@@ -895,21 +903,21 @@ public class GameUIManager implements DialogOwner {
return;
}
log.debug("Polling local player name: "+localPlayerName);
-
+
AutoSaveLoadDialog dialog = new AutoSaveLoadDialog (this,
- autoSaveLoadStatus,
- autoSaveLoadPollingInterval);
+ autoSaveLoadStatus,
+ autoSaveLoadPollingInterval);
setCurrentDialog(dialog, null);
}
-
+
public void autoSaveLoadGame2 (AutoSaveLoadDialog dialog) {
-
+
autoSaveLoadStatus = dialog.getStatus();
autoSaveLoadPollingInterval = dialog.getInterval();
-
+
if (autoLoadPoller == null && autoSaveLoadStatus > 0) {
-
- autoLoadPoller = new AutoLoadPoller (this, saveDirectory, savePrefix,
+
+ autoLoadPoller = new AutoLoadPoller (this, saveDirectory, savePrefix,
localPlayerName, autoSaveLoadStatus, autoSaveLoadPollingInterval);
autoLoadPoller.start();
} else if (autoLoadPoller != null) {
@@ -918,26 +926,26 @@ public class GameUIManager implements DialogOwner {
}
log.debug("AutoSaveLoad parameters: status="+autoSaveLoadStatus
+" interval="+autoSaveLoadPollingInterval);
-
+
if (gameWasLoaded) {
autoSaveLoadInitialized = true;
lastSavedFilenameFilepath = saveDirectory + "/" + savePrefix + ".last_rails";
saveAutoSavedFilename (lastSavedFilename);
}
-
+
if (autoLoadPoller != null && autoSaveLoadStatus != AutoLoadPoller.OFF
&& !autoSaveLoadInitialized && !gameWasLoaded) {
-
+
/* The first time (only) we use the normal save process,
* so the player can select a directory, and change
- * the prefix if so desired.
+ * the prefix if so desired.
*/
GameAction saveAction = new GameAction(GameAction.SAVE);
saveSuffix = localPlayerName;
saveGame (saveAction);
File lastSavedFile = new File (saveAction.getFilepath());
saveDirectory = lastSavedFile.getParentFile().getPath();
-
+
/* Now also save the "last saved file" file */
String lastSavedFilename = lastSavedFile.getName();
lastSavedFilenameFilepath = saveDirectory + "/" + savePrefix + ".last_rails";
@@ -948,13 +956,13 @@ public class GameUIManager implements DialogOwner {
out.close();
autoSaveLoadInitialized = true;
} catch (IOException e) {
- log.error ("Exception whilst creating .last_rails file '"
+ log.error ("Exception whilst creating .last_rails file '"
+ lastSavedFilenameFilepath + "'", e);
}
}
-
+
myTurn = getCurrentPlayer().getName().equals(localPlayerName);
-
+
if (!myTurn) {
// Start autoload polling
autoLoadPoller.setActive(autoSaveLoadStatus == AutoLoadPoller.ON && !myTurn);
@@ -967,7 +975,7 @@ public class GameUIManager implements DialogOwner {
}
}
-
+
/*
public boolean isMyTurn() {
return myTurn;
@@ -976,7 +984,7 @@ public class GameUIManager implements DialogOwner {
public void setMyTurn(boolean myTurn) {
this.myTurn = myTurn;
}
- */
+ */
public void setSaveDirectory(String saveDirectory) {
this.saveDirectory = saveDirectory;
diff --git a/rails/ui/swing/StartRoundWindow.java b/rails/ui/swing/StartRoundWindow.java
index 28fd2c5..d27294b 100644
--- a/rails/ui/swing/StartRoundWindow.java
+++ b/rails/ui/swing/StartRoundWindow.java
@@ -20,7 +20,7 @@ import rails.ui.swing.elements.*;
* This displays the Auction Window
*/
public class StartRoundWindow extends JFrame implements ActionListener,
- KeyListener, ActionPerformer {
+KeyListener, ActionPerformer {
private static final long serialVersionUID = 1L;
// Gap sizes between screen cells, in pixels
@@ -36,10 +36,10 @@ public class StartRoundWindow extends JFrame implements ActionListener,
private static final Color soldColour = new Color (128, 128, 128);
private static final Color defaultColour = Color.BLACK;
- private final JPanel statusPanel;
- private final JPanel buttonPanel;
+ private JPanel statusPanel;
+ private JPanel buttonPanel;
- private final GridBagLayout gb;
+ private GridBagLayout gb;
private GridBagConstraints gbc;
// Grid elements per function
@@ -64,22 +64,22 @@ public class StartRoundWindow extends JFrame implements ActionListener,
private Caption[] lowerPlayerCaption;
private ActionButton bidButton;
- private final ActionButton buyButton;
+ private ActionButton buyButton;
private JSpinner bidAmount;
private SpinnerNumberModel spinnerModel;
- private final ActionButton passButton;
+ private ActionButton passButton;
private ImageIcon infoIcon = null;
- private final int np; // Number of players
- private final int ni; // Number of start items
- private final Player[] players;
- private final StartItem[] items;
- private final StartItemAction[] actionableItems;
- private final StartPacket packet;
- private final int[] crossIndex;
- private final StartRound round;
- private final GameUIManager gameUIManager;
+ private int np; // Number of players
+ private int ni; // Number of start items
+ private Player[] players;
+ private StartItem[] items;
+ private StartItemAction[] actionableItems;
+ private StartPacket packet;
+ private int[] crossIndex;
+ private StartRound round;
+ private GameUIManager gameUIManager;
private StartItem si;
private JComponent f;
@@ -87,29 +87,29 @@ public class StartRoundWindow extends JFrame implements ActionListener,
/** @see StartItem.statusName */
public static final String[] itemStatusTextKeys =
new String[] { "Status_Unavailable", "Status_Biddable", "Status_Buyable",
- "Status_Selectable", "Status_Auctioned",
- "Status_NeedingSharePrice", "Status_Sold" };
+ "Status_Selectable", "Status_Auctioned",
+ "Status_NeedingSharePrice", "Status_Sold" };
// Current state
private int playerIndex = -1;
private final PossibleActions possibleActions =
- PossibleActions.getInstance();
+ PossibleActions.getInstance();
private PossibleAction immediateAction = null;
private final ButtonGroup itemGroup = new ButtonGroup();
private ClickField dummyButton; // To be selected if none else is.
- private final boolean includeBidding;
- private final boolean showBasePrices;
+ private boolean includeBidding;
+ private boolean showBasePrices;
-// private boolean repacked = false;
+ // private boolean repacked = false;
protected static Logger log =
- Logger.getLogger(StartRoundWindow.class.getPackage().getName());
+ Logger.getLogger(StartRoundWindow.class.getPackage().getName());
- public StartRoundWindow(StartRound round, GameUIManager parent) {
- super();
+ public void init(StartRound round, GameUIManager parent) {
+ //super();
this.round = round;
includeBidding = round.hasBidding();
showBasePrices = round.hasBasePrices();
@@ -139,8 +139,8 @@ public class StartRoundWindow extends JFrame implements ActionListener,
buttonPanel.add(bidButton);
spinnerModel =
- new SpinnerNumberModel(new Integer(999), new Integer(0),
- null, new Integer(1));
+ new SpinnerNumberModel(new Integer(999), new Integer(0),
+ null, new Integer(1));
bidAmount = new JSpinner(spinnerModel);
bidAmount.setPreferredSize(new Dimension(50, 28));
bidAmount.setEnabled(false);
@@ -284,9 +284,9 @@ public class StartRoundWindow extends JFrame implements ActionListener,
f = itemName[i] = new Caption(si.getName());
addField(f, itemNameXOffset, itemNameYOffset + i, 1, 1, WIDE_RIGHT);
f =
- itemNameButton[i] =
- new ClickField(si.getName(), "", "", this,
- itemGroup);
+ itemNameButton[i] =
+ new ClickField(si.getName(), "", "", this,
+ itemGroup);
addField(f, itemNameXOffset, itemNameYOffset + i, 1, 1, WIDE_RIGHT);
// Prevent row height resizing after every buy action
itemName[i].setPreferredSize(itemNameButton[i].getPreferredSize());
@@ -335,9 +335,9 @@ public class StartRoundWindow extends JFrame implements ActionListener,
WIDE_RIGHT + (firstBelowTable ? WIDE_TOP : 0));
for (int i = 0; i < np; i++) {
f =
- playerFree[i] =
- new Field(includeBidding
- ? round.getFreeCashModel(i)
+ playerFree[i] =
+ new Field(includeBidding
+ ? round.getFreeCashModel(i)
: players[i].getCashModel());
addField(f, playerFreeCashXOffset + i, playerFreeCashYOffset, 1, 1,
firstBelowTable ? WIDE_TOP : 0);
@@ -366,11 +366,11 @@ public class StartRoundWindow extends JFrame implements ActionListener,
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);
+ (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);
+ statusPanel.add(comp, gbc);
}
@@ -384,7 +384,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
}
// Unselect the selected private
dummyButton.setSelected(true);
-
+
if (!myTurn) return;
// For debugging
@@ -393,7 +393,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
}
List<StartItemAction> actions =
- possibleActions.getType(StartItemAction.class);
+ possibleActions.getType(StartItemAction.class);
if (actions == null || actions.isEmpty()) {
close();
@@ -401,7 +401,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
}
int nextPlayerIndex =
- ((PossibleAction) actions.get(0)).getPlayerIndex();
+ ((PossibleAction) actions.get(0)).getPlayerIndex();
setSRPlayerTurn(nextPlayerIndex);
boolean passAllowed = false;
@@ -440,7 +440,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
} else {
PossibleAction lastAction = gameUIManager.getLastAction();
if (lastAction instanceof GameAction
- && (((GameAction) lastAction).getMode() == GameAction.UNDO || ((GameAction) lastAction).getMode() == GameAction.FORCED_UNDO)) {
+ && (((GameAction) lastAction).getMode() == GameAction.UNDO || ((GameAction) lastAction).getMode() == GameAction.FORCED_UNDO)) {
// If we come here via an Undo, we should not start
// with a modal dialog, as that would prevent further
// Undos.
@@ -482,7 +482,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
passAllowed = false;
List<NullAction> inactiveItems =
- possibleActions.getType(NullAction.class);
+ possibleActions.getType(NullAction.class);
if (inactiveItems != null && !inactiveItems.isEmpty()) {
// only one NullAction is allowed
NullAction na = inactiveItems.get(0);
@@ -534,8 +534,8 @@ public class StartRoundWindow extends JFrame implements ActionListener,
if (source instanceof ClickField) {
gbc = gb.getConstraints(source);
StartItemAction currentActiveItem =
- (StartItemAction) ((ClickField) source).getPossibleActions().get(
- 0);
+ (StartItemAction) ((ClickField) source).getPossibleActions().get(
+ 0);
if (currentActiveItem instanceof BuyStartItem) {
buyButton.setEnabled(true);
@@ -554,10 +554,10 @@ public class StartRoundWindow extends JFrame implements ActionListener,
passButton.setEnabled(true);
passButton.setText(LocalText.getText("SelectNoBid"));
passButton.setVisible(true);
-// if (!repacked) {
- pack();
-// repacked = true;
-// }
+ // if (!repacked) {
+ pack();
+ // repacked = true;
+ // }
}
if (includeBidding) {
@@ -572,11 +572,11 @@ public class StartRoundWindow extends JFrame implements ActionListener,
}
} else if (source instanceof ActionButton) {
PossibleAction activeItem =
- ((ActionButton) source).getPossibleActions().get(0);
+ ((ActionButton) source).getPossibleActions().get(0);
if (source == buyButton) {
if (activeItem instanceof BuyStartItem
- && ((BuyStartItem) activeItem).hasSharePriceToSet()) {
+ && ((BuyStartItem) activeItem).hasSharePriceToSet()) {
if (requestStartPrice((BuyStartItem) activeItem))
process(activeItem);
} else {
@@ -590,7 +590,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
} else if (source == passButton) {
if (activeItem != null && activeItem instanceof BidStartItem
- && ((BidStartItem) activeItem).isSelectForAuction()) {
+ && ((BidStartItem) activeItem).isSelectForAuction()) {
((BidStartItem) activeItem).setActualBid(-1);
}
process(activeItem);
@@ -610,7 +610,7 @@ public class StartRoundWindow extends JFrame implements ActionListener,
// TODO: should be included in BuyStartItem
List<StockSpaceI> startSpaces = stockMarket.getStartSpaces();
Map<Integer, StockSpaceI> spacePerPrice =
- new HashMap<Integer, StockSpaceI>();
+ new HashMap<Integer, StockSpaceI>();
int[] prices = new int[startSpaces.size()];
StockSpaceI[] options = new StockSpaceI[startSpaces.size()];
for (int i = 0; i < startSpaces.size(); i++) {
@@ -623,13 +623,13 @@ public class StartRoundWindow extends JFrame implements ActionListener,
}
StockSpace sp =
- (StockSpace) JOptionPane.showInputDialog(this,
- LocalText.getText("WHICH_START_PRICE",
- activeItem.getPlayerName(),
- compName),
- LocalText.getText("WHICH_PRICE"),
- JOptionPane.QUESTION_MESSAGE, null, options,
- options[0]);
+ (StockSpace) JOptionPane.showInputDialog(this,
+ LocalText.getText("WHICH_START_PRICE",
+ activeItem.getPlayerName(),
+ compName),
+ LocalText.getText("WHICH_PRICE"),
+ JOptionPane.QUESTION_MESSAGE, null, options,
+ options[0]);
if (sp == null) {
return false;
}
@@ -681,43 +681,43 @@ public class StartRoundWindow extends JFrame implements ActionListener,
status == StartItem.BUYABLE ? buyableColour : defaultColour);
}
- private String getStartItemDescription (StartItem item) {
- StringBuffer b = new StringBuffer("<html>");
- b.append (item.getPrimary().toString());
- if (item.getPrimary() instanceof PrivateCompany) {
- PrivateCompany priv = (PrivateCompany) item.getPrimary();
- b.append ("<br>Revenue: ").append(Bank.formatIntegerArray(priv.getRevenue()));
- List<MapHex> blockedHexes = priv.getBlockedHexes();
- if (blockedHexes == null) {
- } else if (blockedHexes.size() == 1) {
- b.append("<br>Blocked hex: ").append(blockedHexes.get(0).getName());
- } else if (blockedHexes.size() > 1) {
- b.append("<br>Blocked hexes:");
- for (MapHex hex : blockedHexes) {
- b.append(" ").append(hex.getName());
- }
- }
- if (priv.hasSpecialProperties()) {
- b.append("<br><b>Special properties:</b>");
- for (SpecialPropertyI sp : priv.getSpecialProperties()) {
- b.append("<br>").append(sp.toString());
- }
+ private String getStartItemDescription (StartItem item) {
+ StringBuffer b = new StringBuffer("<html>");
+ b.append (item.getPrimary().toString());
+ if (item.getPrimary() instanceof PrivateCompany) {
+ PrivateCompany priv = (PrivateCompany) item.getPrimary();
+ b.append ("<br>Revenue: ").append(Bank.formatIntegerArray(priv.getRevenue()));
+ List<MapHex> blockedHexes = priv.getBlockedHexes();
+ if (blockedHexes == null) {
+ } else if (blockedHexes.size() == 1) {
+ b.append("<br>Blocked hex: ").append(blockedHexes.get(0).getName());
+ } else if (blockedHexes.size() > 1) {
+ b.append("<br>Blocked hexes:");
+ for (MapHex hex : blockedHexes) {
+ b.append(" ").append(hex.getName());
}
- // sfy 1889
- List<String> preventClosingConditions = priv.getPreventClosingConditions();
- if (!preventClosingConditions.isEmpty()) {
- b.append("<br><b>Prevent closing conditions:</b>");
- for (String condition : preventClosingConditions) {
- b.append("<br>").append(condition);
- }
+ }
+ if (priv.hasSpecialProperties()) {
+ b.append("<br><b>Special properties:</b>");
+ for (SpecialPropertyI sp : priv.getSpecialProperties()) {
+ b.append("<br>").append(sp.toString());
}
-
}
- if (item.getSecondary() != null) {
- b.append("<br><b>Also contains:</b><br>");
- b.append(item.getSecondary().toString());
+ // sfy 1889
+ List<String> preventClosingConditions = priv.getPreventClosingConditions();
+ if (!preventClosingConditions.isEmpty()) {
+ b.append("<br><b>Prevent closing conditions:</b>");
+ for (String condition : preventClosingConditions) {
+ b.append("<br>").append(condition);
+ }
}
- return b.toString();
+
+ }
+ if (item.getSecondary() != null) {
+ b.append("<br><b>Also contains:</b><br>");
+ b.append(item.getSecondary().toString());
+ }
+ return b.toString();
}
private ImageIcon createInfoIcon() {
diff --git a/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java b/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java
new file mode 100644
index 0000000..0d28970
--- /dev/null
+++ b/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java
@@ -0,0 +1,7 @@
+package rails.ui.swing.gamespecific._1880;
+
+import rails.ui.swing.StartRoundWindow;
+
+public class StartRoundWindow_1880 extends StartRoundWindow {
+
+}
commit 8fce0f10a5c8ebcb6528a991efcfc74abe45a686
Author: Erik Vos <eri...@xs...>
Date: Tue Oct 4 19:07:55 2011 +0200
Fix bug that disallows selling a share after buying one in some cases.
Relates to the "don't sell a just bought certificate" rule.
The fix is to reverse the sequence of that and the pool size check.
diff --git a/rails/game/StockRound.java b/rails/game/StockRound.java
index 5284961..cafb86b 100644
--- a/rails/game/StockRound.java
+++ b/rails/game/StockRound.java
@@ -2,9 +2,7 @@ package rails.game;
import java.util.*;
-import rails.common.DisplayBuffer;
-import rails.common.GuiDef;
-import rails.common.LocalText;
+import rails.common.*;
import rails.common.parser.GameOption;
import rails.game.action.*;
import rails.game.move.*;
@@ -113,7 +111,7 @@ public class StockRound extends Round {
DisplayBuffer.add(LocalText.getText("ExceedCertificateLimit"
, currentPlayer.getName()
, isPlayerOverLimitsDetail(currentPlayer)
- )
+ )
);
return true;
}
@@ -262,7 +260,7 @@ public class StockRound extends Round {
price = stockSpace.getPrice() / unitsForPrice;
shareUnit = comp.getShareUnit();
maxNumberOfSharesToBuy
- = maxAllowedNumberOfSharesToBuy(currentPlayer, comp, shareUnit);
+ = maxAllowedNumberOfSharesToBuy(currentPlayer, comp, shareUnit);
/* Checks if the player can buy any shares of this company */
if (maxNumberOfSharesToBuy < 1) continue;
@@ -432,9 +430,6 @@ public class StockRound extends Round {
for (int i = 1; i <= 4; i++) {
number = shareCountPerUnit[i];
if (number == 0) continue;
- number =
- Math.min(number, maxShareToSell
- / (i * company.getShareUnit()));
/* In some games (1856), a just bought share may not be sold */
// This code ignores the possibility of different share units
@@ -444,6 +439,12 @@ public class StockRound extends Round {
}
if (number <= 0) continue;
+ // Check against the share% already in the pool
+ number =
+ Math.min(number, maxShareToSell
+ / (i * company.getShareUnit()));
+ if (number <= 0) continue;
+
possibleActions.add(new SellShares(compName, i, number, price));
}
@@ -964,8 +965,8 @@ public class StockRound extends Round {
// May player sell this company
if (!mayPlayerSellShareOfCompany(company)) {
- errMsg = LocalText.getText("SaleNotAllowed", companyName);
- break;
+ errMsg = LocalText.getText("SaleNotAllowed", companyName);
+ break;
}
// The player must have the share(s)
@@ -1083,8 +1084,8 @@ public class StockRound extends Round {
if (!company.isClosed()) {
- executeShareTransfer (company, certsToSell,
- dumpedPlayer, presSharesToSell);
+ executeShareTransfer (company, certsToSell,
+ dumpedPlayer, presSharesToSell);
}
// Remember that the player has sold this company this round.
@@ -1099,8 +1100,8 @@ public class StockRound extends Round {
}
protected void executeShareTransfer (PublicCompanyI company,
- List<PublicCertificateI> certsToSell,
- Player dumpedPlayer, int presSharesToSell) {
+ List<PublicCertificateI> certsToSell,
+ Player dumpedPlayer, int presSharesToSell) {
Portfolio portfolio = currentPlayer.getPortfolio();
@@ -1368,13 +1369,13 @@ public class StockRound extends Round {
setNextPlayer();
sellPrices.clear();
if (hasAutopassed(currentPlayer)) {
- if (isPlayerOverLimits(currentPlayer)) {
- // Being over a share/certificate limit undoes an Autopass setting
- setAutopass (currentPlayer, false);
- } else {
- // Process a pass for a player that has set Autopass
- done (currentPlayer.getName(), true);
- }
+ if (isPlayerOverLimits(currentPlayer)) {
+ // Being over a share/certificate limit undoes an Autopass setting
+ setAutopass (currentPlayer, false);
+ } else {
+ // Process a pass for a player that has set Autopass
+ done (currentPlayer.getName(), true);
+ }
}
}
@@ -1446,7 +1447,7 @@ public class StockRound extends Round {
if (noSaleIfNotOperated()
&& !company.hasOperated()) return false;
- return true;
+ return true;
}
@@ -1582,16 +1583,16 @@ public class StockRound extends Round {
return toString();
}
- public boolean isSellObligationLifted(PublicCompanyI company) {
- return sellObligationLifted != null
- && sellObligationLifted.contains(company);
- }
-
- public void setSellObligationLifted (PublicCompanyI company) {
- if (sellObligationLifted == null) {
- sellObligationLifted = new HashSetState<PublicCompanyI>("SellObligationLifted");
- }
- sellObligationLifted.add(company);
- }
+ public boolean isSellObligationLifted(PublicCompanyI company) {
+ return sellObligationLifted != null
+ && sellObligationLifted.contains(company);
+ }
+
+ public void setSellObligationLifted (PublicCompanyI company) {
+ if (sellObligationLifted == null) {
+ sellObligationLifted = new HashSetState<PublicCompanyI>("SellObligationLifted");
+ }
+ sellObligationLifted.add(company);
+ }
}
|