From: Erik V. <ev...@us...> - 2011-11-16 22:07:23
|
rails/game/model/ShareModel.java | 33 +++++++++++++++++++++++++++++++-- rails/ui/swing/GameStatus.java | 25 +++++++++++++++++++++++-- rails/ui/swing/elements/Field.java | 29 +++++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 6 deletions(-) New commits: commit 902cac06c959dc53ef89aec36cdedb9db2cce2ac Author: Erik Vos <eri...@xs...> Date: Wed Nov 16 23:05:48 2011 +0100 Added tooltips to Game Status share fields to display portfolio composition. diff --git a/rails/game/model/ShareModel.java b/rails/game/model/ShareModel.java index d38691b..2dd9993 100644 --- a/rails/game/model/ShareModel.java +++ b/rails/game/model/ShareModel.java @@ -1,6 +1,8 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/model/ShareModel.java,v 1.8 2009/10/06 18:34:04 evos Exp $*/ package rails.game.model; +import java.util.*; + import rails.game.*; public class ShareModel extends ModelObject { @@ -9,6 +11,8 @@ public class ShareModel extends ModelObject { private Portfolio portfolio; private PublicCompanyI company; + public static final String SHARES = "SHARES"; + public ShareModel(Portfolio portfolio, PublicCompanyI company) { this.portfolio = portfolio; this.company = company; @@ -32,12 +36,37 @@ public class ShareModel extends ModelObject { } @Override + public Object getUpdate() { + ViewUpdate u = new ViewUpdate (getText()); + List<PublicCertificateI> certs = portfolio.getCertificatesPerCompany(company.getName()); + if (certs != null) { + Map<String, Integer> numberPerCertType = new HashMap<String, Integer>(); + String certType; + for (PublicCertificateI cert : certs) { + certType = cert.getTypeId(); + if (!numberPerCertType.containsKey(certType)) { + numberPerCertType.put(certType, 1); + } else { + numberPerCertType.put(certType, numberPerCertType.get(certType)+1); + } + } + StringBuilder b = new StringBuilder(); + for (String type : numberPerCertType.keySet()) { + if (b.length() > 0) b.append(","); + b.append(type).append(":").append(numberPerCertType.get(type)); + } + u.addObject(SHARES, b.toString()); + } + return u; + } + + @Override public String getText() { if (share == 0) return ""; - StringBuffer b = new StringBuffer(); + StringBuilder b = new StringBuilder(); b.append(share).append("%"); if (portfolio.getOwner() instanceof Player - && company.getPresident() == portfolio.getOwner()) { + && company.getPresident() == portfolio.getOwner()) { b.append("P"); if (!company.hasFloated()) b.append("U"); b.append(company.getExtraShareMarks()); diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index da0f965..29f55ea 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -16,6 +16,7 @@ import rails.game.*; import rails.game.action.*; import rails.game.correct.CashCorrectionAction; import rails.ui.swing.elements.*; +import rails.util.Util; /** * This class is incorporated into StatusWindow and displays the bulk of @@ -942,13 +943,14 @@ public class GameStatus extends GridPanel implements ActionListener { if (j < 0) return; setPlayerCertButton(i, j, clickable); + if (clickable) syncToolTipText (certPerPlayer[i][j], certPerPlayerButton[i][j]); if (clickable && o != null) { if (o instanceof PossibleAction) { certPerPlayerButton[i][j].addPossibleAction((PossibleAction) o); if (o instanceof SellShares) { - certPerPlayerButton[i][j].setToolTipText(LocalText.getText("ClickForSell")); + addToolTipText (certPerPlayerButton[i][j], LocalText.getText("ClickForSell")); } else if (o instanceof BuyCertificate) { - certPerPlayerButton[i][j].setToolTipText(LocalText.getText("ClickToSelectForBuying")); + addToolTipText (certPerPlayerButton[i][j], LocalText.getText("ClickToSelectForBuying")); } } } @@ -960,6 +962,7 @@ public class GameStatus extends GridPanel implements ActionListener { if (clickable) { certPerPlayerButton[i][j].setText(certPerPlayer[i][j].getText()); + syncToolTipText (certPerPlayer[i][j], certPerPlayerButton[i][j]); } else { certPerPlayerButton[i][j].clearPossibleActions(); } @@ -970,6 +973,7 @@ public class GameStatus extends GridPanel implements ActionListener { protected void setIPOCertButton(int i, boolean clickable, Object o) { setIPOCertButton(i, clickable); + if (clickable) syncToolTipText (certInIPO[i], certInIPOButton[i]); if (clickable && o != null) { if (o instanceof PossibleAction) certInIPOButton[i].addPossibleAction((PossibleAction) o); @@ -980,6 +984,7 @@ public class GameStatus extends GridPanel implements ActionListener { boolean visible = rowVisibilityObservers[i].lastValue(); if (clickable) { certInIPOButton[i].setText(certInIPO[i].getText()); + syncToolTipText (certInIPO[i], certInIPOButton[i]); } else { certInIPOButton[i].clearPossibleActions(); } @@ -990,6 +995,7 @@ public class GameStatus extends GridPanel implements ActionListener { protected void setPoolCertButton(int i, boolean clickable, Object o) { setPoolCertButton(i, clickable); + if (clickable) syncToolTipText (certInPool[i], certInPoolButton[i]); if (clickable && o != null) { if (o instanceof PossibleAction) certInPoolButton[i].addPossibleAction((PossibleAction) o); @@ -1000,6 +1006,7 @@ public class GameStatus extends GridPanel implements ActionListener { boolean visible = rowVisibilityObservers[i].lastValue(); if (clickable) { certInPoolButton[i].setText(certInPool[i].getText()); + syncToolTipText (certInIPO[i], certInIPOButton[i]); } else { certInPoolButton[i].clearPossibleActions(); } @@ -1011,6 +1018,7 @@ public class GameStatus extends GridPanel implements ActionListener { setTreasuryCertButton(i, clickable); if (clickable && o != null) { + if (clickable) syncToolTipText (certInTreasury[i], certInTreasuryButton[i]); if (o instanceof PossibleAction) certInTreasuryButton[i].addPossibleAction((PossibleAction) o); } @@ -1020,6 +1028,7 @@ public class GameStatus extends GridPanel implements ActionListener { boolean visible = rowVisibilityObservers[i].lastValue(); if (clickable) { certInTreasuryButton[i].setText(certInTreasury[i].getText()); + syncToolTipText (certInTreasury[i], certInTreasuryButton[i]); } else { certInTreasuryButton[i].clearPossibleActions(); } @@ -1054,4 +1063,16 @@ public class GameStatus extends GridPanel implements ActionListener { if (action != null) playerCashButton[i].addPossibleAction(action); } + + protected void syncToolTipText (Field field, ClickField clickField) { + String baseText = field.getToolTipText(); + clickField.setToolTipText(Util.hasValue(baseText) ? baseText : ""); + } + + protected void addToolTipText (ClickField clickField, String addText) { + if (!Util.hasValue(addText)) return; + String baseText = clickField.getToolTipText(); + clickField.setToolTipText(Util.hasValue(baseText) ? baseText+"<br>"+addText : addText); + } + } diff --git a/rails/ui/swing/elements/Field.java b/rails/ui/swing/elements/Field.java index 76b674f..1c7816f 100644 --- a/rails/ui/swing/elements/Field.java +++ b/rails/ui/swing/elements/Field.java @@ -8,8 +8,7 @@ import java.util.*; import javax.swing.*; import javax.swing.border.Border; -import rails.game.model.ModelObject; -import rails.game.model.ViewUpdate; +import rails.game.model.*; import rails.util.Util; public class Field extends JLabel implements ViewObject { @@ -31,6 +30,9 @@ public class Field extends JLabel implements ViewObject { private boolean html = false; + /** Intended for (possibly varying) tooltip text that must be held across player actions */ + private String baseToolTipInfo = null; + public Field(String text) { super(text.equals("0%") ? "" : text); this.setBackground(NORMAL_BG_COLOUR); @@ -120,6 +122,23 @@ public class Field extends JLabel implements ViewObject { setBackground((Color)vu.getValue(key)); normalBgColour = getBackground(); setForeground (Util.isDark(normalBgColour) ? Color.WHITE : Color.BLACK); + } else if (ShareModel.SHARES.equalsIgnoreCase(key)) { + int count; + String type; + String[] items; + StringBuilder b = new StringBuilder(); + for (String typeAndCount : ((String)vu.getValue(key)).split(",")) { + Util.getLogger().debug(">>> "+typeAndCount+" <<<"); + if (!Util.hasValue(typeAndCount)) continue; + items = typeAndCount.split(":"); + count = Integer.parseInt(items[1]); + items = items[0].split("_"); + type = items[1] + (items.length > 2 && items[2].contains("P") ? "P" : ""); + if (b.length() > 0) b.append("<br>"); + b.append(count).append(" x ").append(type); + } + baseToolTipInfo = b.toString(); + setToolTipText ("<html>" + baseToolTipInfo); } } } @@ -142,4 +161,10 @@ public class Field extends JLabel implements ViewObject { public void setHtml() { html = true; } + + public String getBaseToolTipInfo() { + return baseToolTipInfo; + } + + } |
From: Erik V. <ev...@us...> - 2011-11-19 09:35:56
|
rails/game/model/ShareModel.java | 4 - rails/game/model/ViewUpdate.java | 2 rails/game/specific/_1835/StockRound_1835.java | 92 +++++++++++++++---------- rails/ui/swing/GameStatus.java | 2 rails/ui/swing/elements/Field.java | 9 +- 5 files changed, 65 insertions(+), 44 deletions(-) New commits: commit 605008e5a969b1f3fe46a584a5ab86a32176e639 Author: Erik Vos <eri...@xs...> Date: Sat Nov 19 10:35:35 2011 +0100 Fixes for 1835: Nationalisation rewritten to handle mixed shares. Rewrote nationalisation to make it able to handle both 10% and 20% shares. The nationalisation code has also been refactored into setBuyableCerts(). Suppressed empty share field tooltips. Moved the SHARES update key from ShareModel to ViewUpdate, where the other keys are. diff --git a/rails/game/model/ShareModel.java b/rails/game/model/ShareModel.java index 2dd9993..2c7f913 100644 --- a/rails/game/model/ShareModel.java +++ b/rails/game/model/ShareModel.java @@ -11,8 +11,6 @@ public class ShareModel extends ModelObject { private Portfolio portfolio; private PublicCompanyI company; - public static final String SHARES = "SHARES"; - public ShareModel(Portfolio portfolio, PublicCompanyI company) { this.portfolio = portfolio; this.company = company; @@ -55,7 +53,7 @@ public class ShareModel extends ModelObject { if (b.length() > 0) b.append(","); b.append(type).append(":").append(numberPerCertType.get(type)); } - u.addObject(SHARES, b.toString()); + u.addObject(ViewUpdate.SHARES, b.toString()); } return u; } diff --git a/rails/game/model/ViewUpdate.java b/rails/game/model/ViewUpdate.java index 3a99661..bc1b57d 100644 --- a/rails/game/model/ViewUpdate.java +++ b/rails/game/model/ViewUpdate.java @@ -9,7 +9,6 @@ import java.util.*; * <p> The current version has text, background colour and foreground colour. * Receiving view objects must be prepared to handle extensions. * @author VosE - * */ public class ViewUpdate implements Serializable { @@ -18,6 +17,7 @@ public class ViewUpdate implements Serializable { public static final String TEXT = "TEXT"; public static final String BGCOLOUR = "BGCOLOUR"; + public static final String SHARES = "SHARES"; public static final long serialVersionUID = 1L; diff --git a/rails/game/specific/_1835/StockRound_1835.java b/rails/game/specific/_1835/StockRound_1835.java index 8d27f76..ff8eea3 100644 --- a/rails/game/specific/_1835/StockRound_1835.java +++ b/rails/game/specific/_1835/StockRound_1835.java @@ -4,7 +4,6 @@ */ package rails.game.specific._1835; -import java.util.ArrayList; import java.util.List; import rails.common.LocalText; @@ -25,45 +24,68 @@ public class StockRound_1835 extends StockRound { /** Add nationalisations */ @Override - protected void setGameSpecificActions() { - if (!mayCurrentPlayerBuyAnything()) return; + public void setBuyableCerts() { + + super.setBuyableCerts(); if (companyBoughtThisTurnWrapper.get() != null) return; - List<Player> otherPlayers = new ArrayList<Player>(); - Portfolio holder; - CashHolder owner; - Player otherPlayer; int price; int cash = currentPlayer.getCash(); + List<PublicCertificateI> certs; + StockSpaceI stockSpace; + Portfolio from; + int unitsForPrice; - // Nationalization + // Nationalisation for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { if (!company.getTypeName().equalsIgnoreCase("Major")) continue; if (!company.hasFloated()) continue; if (company.getPresident() != currentPlayer) continue; - if (currentPlayer.getPortfolio().getShare(company) >= 55) { - otherPlayers.clear(); - for (PublicCertificateI cert : company.getCertificates()) { - holder = (Portfolio)cert.getHolder(); - owner = holder.getOwner(); + if (currentPlayer.getPortfolio().getShare(company) < 55) continue; + if (isSaleRecorded(currentPlayer, company)) continue; + + for (Player otherPlayer : this.getPlayers()) { + if (otherPlayer == currentPlayer) continue; + + /* Get the unique player certificates and check which ones can be bought */ + from = otherPlayer.getPortfolio(); + certs = from.getCertificatesPerCompany(company.getName()); + if (certs == null || certs.isEmpty()) continue; + + /* Allow for multiple share unit certificates (e.g. 1835) */ + PublicCertificateI[] uniqueCerts; + int shares; + + stockSpace = company.getCurrentSpace(); + unitsForPrice = company.getShareUnitsForSharePrice(); + price = (int)(1.5 * stockSpace.getPrice() / unitsForPrice); + + /* Check what share multiples are available + * Normally only 1, but 1 and 2 in 1835. Allow up to 4. + */ + uniqueCerts = new PublicCertificateI[5]; + for (PublicCertificateI cert2 : certs) { + shares = cert2.getShares(); + if (uniqueCerts[shares] != null) continue; + uniqueCerts[shares] = cert2; + } + + /* Create a BuyCertificate action per share size */ + for (shares = 1; shares < 5; shares++) { + if (uniqueCerts[shares] == null) continue; + /* Would the player exceed the total certificate limit? */ - StockSpaceI stockSpace = company.getCurrentSpace(); - if ((stockSpace == null || !stockSpace.isNoCertLimit()) && !mayPlayerBuyCertificate( - currentPlayer, company, cert.getCertificateCount())) continue; - // only nationalize other players - if (owner instanceof Player && owner != currentPlayer) { - otherPlayer = (Player) owner; - if (!otherPlayers.contains(otherPlayer)) { - price = (int)(1.5 * company.getCurrentPriceModel().getPrice().getPrice()); - if (price <= cash) { - possibleActions.add(new BuyCertificate (company, cert.getShare(), - holder, - (int)(1.5 * company.getCurrentPriceModel().getPrice().getPrice()), - 1)); - } - otherPlayers.add(otherPlayer); - } - } + if (!stockSpace.isNoCertLimit() + && !mayPlayerBuyCertificate(currentPlayer, company, + uniqueCerts[shares].getCertificateCount())) + continue; + + // Does the player have enough cash? + if (cash < price * shares) continue; + + possibleActions.add(new BuyCertificate(company, + uniqueCerts[shares].getShare(), + from, price, 1)); } } } @@ -97,7 +119,7 @@ public class StockRound_1835 extends StockRound { } // stored price is the previous unadjusted price price = price / company.getShareUnitsForSharePrice(); - return price; + return price; } @@ -133,9 +155,9 @@ public class StockRound_1835 extends StockRound { // Check for group releases if (sharesInIPO == 0) { if (name.equals(GameManager_1835.SX_ID) && - ipo.getShare(companyManager.getPublicCompany(GameManager_1835.BY_ID)) == 0 - || name.equals(GameManager_1835.BY_ID) && - ipo.getShare(companyManager.getPublicCompany(GameManager_1835.SX_ID)) == 0) { + ipo.getShare(companyManager.getPublicCompany(GameManager_1835.BY_ID)) == 0 + || name.equals(GameManager_1835.BY_ID) && + ipo.getShare(companyManager.getPublicCompany(GameManager_1835.SX_ID)) == 0) { // Group 1 sold out: release Badische releaseCompanyShares (companyManager.getPublicCompany(GameManager_1835.BA_ID)); ReportBuffer.add (LocalText.getText("SharesReleased", @@ -163,7 +185,7 @@ public class StockRound_1835 extends StockRound { "All", GameManager_1835.WT_ID)); } else if (sharesInIPO == 80) { // President sold: release four 10% Prussian shares - gameManager.getCompanyManager().getPublicCompany(GameManager_1835.PR_ID).setBuyable(true); + gameManager.getCompanyManager().getPublicCompany(GameManager_1835.PR_ID).setBuyable(true); for (int i=0; i<4; i++) { unavailable.getCertOfType(GameManager_1835.PR_ID+"_10%").moveTo(ipo); } diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index 29f55ea..a41d730 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -1066,7 +1066,7 @@ public class GameStatus extends GridPanel implements ActionListener { protected void syncToolTipText (Field field, ClickField clickField) { String baseText = field.getToolTipText(); - clickField.setToolTipText(Util.hasValue(baseText) ? baseText : ""); + clickField.setToolTipText(Util.hasValue(baseText) ? baseText : null); } protected void addToolTipText (ClickField clickField, String addText) { diff --git a/rails/ui/swing/elements/Field.java b/rails/ui/swing/elements/Field.java index 1c7816f..eee384b 100644 --- a/rails/ui/swing/elements/Field.java +++ b/rails/ui/swing/elements/Field.java @@ -8,7 +8,8 @@ import java.util.*; import javax.swing.*; import javax.swing.border.Border; -import rails.game.model.*; +import rails.game.model.ModelObject; +import rails.game.model.ViewUpdate; import rails.util.Util; public class Field extends JLabel implements ViewObject { @@ -122,13 +123,13 @@ public class Field extends JLabel implements ViewObject { setBackground((Color)vu.getValue(key)); normalBgColour = getBackground(); setForeground (Util.isDark(normalBgColour) ? Color.WHITE : Color.BLACK); - } else if (ShareModel.SHARES.equalsIgnoreCase(key)) { + } else if (ViewUpdate.SHARES.equalsIgnoreCase(key)) { int count; String type; String[] items; StringBuilder b = new StringBuilder(); for (String typeAndCount : ((String)vu.getValue(key)).split(",")) { - Util.getLogger().debug(">>> "+typeAndCount+" <<<"); + //Util.getLogger().debug(">>> "+typeAndCount+" <<<"); if (!Util.hasValue(typeAndCount)) continue; items = typeAndCount.split(":"); count = Integer.parseInt(items[1]); @@ -138,7 +139,7 @@ public class Field extends JLabel implements ViewObject { b.append(count).append(" x ").append(type); } baseToolTipInfo = b.toString(); - setToolTipText ("<html>" + baseToolTipInfo); + setToolTipText (b.length()>0 ? "<html>" + baseToolTipInfo : null); } } } |
From: Stefan F. <ste...@us...> - 2011-11-25 14:12:58
|
rails/game/MapManager.java | 2 +- rails/ui/swing/hexmap/HexMapImage.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) New commits: commit 572d4fa812f40923634d460a94236d4d94b5a453 Author: Stefan Frey <ste...@we...> Date: Fri Nov 25 15:15:47 2011 +0100 Fixed bug that prevented loading MapImage from jar diff --git a/rails/game/MapManager.java b/rails/game/MapManager.java index dd85c46..f45dd10 100644 --- a/rails/game/MapManager.java +++ b/rails/game/MapManager.java @@ -245,7 +245,7 @@ public class MapManager implements ConfigurableComponentI { if (!rails.util.Util.hasValue(rootDirectory)) { rootDirectory = "data"; } - mapImageFilepath = rootDirectory + "/" + mapImageFilename; + mapImageFilepath = "/" + rootDirectory + "/" + mapImageFilename; } for (String hexName : mHexes.keySet()) { diff --git a/rails/ui/swing/hexmap/HexMapImage.java b/rails/ui/swing/hexmap/HexMapImage.java index e360245..a1435e6 100644 --- a/rails/ui/swing/hexmap/HexMapImage.java +++ b/rails/ui/swing/hexmap/HexMapImage.java @@ -67,9 +67,10 @@ public final class HexMapImage extends JSVGCanvas { private void loadMap() { try { - File imageFile = new File (mapManager.getMapImageFilepath()); - setURI(imageFile.toURI().toString()); - log.debug("ImageFile="+ imageFile.getName()); +// File imageFile = new File (mapManager.getMapImageFilepath()); +// setURI(imageFile.toURI().toString()); +// log.debug("ImageFile="+ imageFile.getName()); + setURI(getClass().getResource(mapManager.getMapImageFilepath()).toString()); } catch (Exception e) { log.error ("Cannot load map image file " + mapManager.getMapImageFilepath(), e); } |
From: Erik V. <ev...@us...> - 2012-01-26 21:09:28
|
rails/game/GameManager.java | 15 +++++++-------- rails/game/GameManagerI.java | 26 ++++++++++++-------------- rails/ui/swing/GameUIManager.java | 8 ++++---- 3 files changed, 23 insertions(+), 26 deletions(-) New commits: commit fb01a78aa7fc7de3b7c66bcc2e4a074cb14b72ce Author: Erik Vos <eri...@xs...> Date: Thu Jan 26 22:08:29 2012 +0100 Fixed 1880 reloading. The original player names sequence is now saved, rather than the reordered list. Method getPlayerNames() has been removed from teh GameManagerI interface; it was hardly used. diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java index 8058d91..d18cba0 100644 --- a/rails/game/GameManager.java +++ b/rails/game/GameManager.java @@ -17,7 +17,6 @@ import rails.game.move.*; import rails.game.special.SpecialPropertyI; import rails.game.special.SpecialTokenLay; import rails.game.state.*; -import rails.sound.BackgroundMusicManager; import rails.util.GameFileIO; import rails.util.Util; @@ -67,7 +66,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { protected Map<String, String> gameOptions; protected List<Player> players; - protected List<String> playerNames; + protected List<String> originalPlayerNamesList; protected int numberOfPlayers; protected State currentPlayer = new State("CurrentPlayer", Player.class); protected State priorityPlayer = new State("PriorityPlayer", Player.class); @@ -551,7 +550,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { this.bank = bank; players = playerManager.getPlayers(); - playerNames = playerManager.getPlayerNames(); + originalPlayerNamesList = playerManager.getPlayerNames(); numberOfPlayers = players.size(); priorityPlayer.setState(players.get(0)); setPlayerCertificateLimit (playerManager.getInitialPlayerCertificateLimit()); @@ -1152,7 +1151,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { protected boolean save(File file, boolean displayErrorMessage, String errorMessageKey) { GameFileIO gameSaver = new GameFileIO(); - gameSaver.initSave(saveFileVersionID, gameName, gameOptions, playerNames); + gameSaver.initSave(saveFileVersionID, gameName, gameOptions, originalPlayerNamesList); gameSaver.setActions(executedActions); gameSaver.setComments(ReportBuffer.getCommentItems()); return gameSaver.saveGame(file, displayErrorMessage, errorMessageKey); @@ -1502,9 +1501,9 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { /* (non-Javadoc) * @see rails.game.GameManagerI#getPlayerNames() */ - public List<String> getPlayerNames() { - return playerNames; - } + //public List<String> getPlayerNames() { + // return originalPlayerNamesList; + //} public int getPlayerCertificateLimit(Player player) { return playerCertificateLimit.intValue(); @@ -1899,7 +1898,7 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { for (int i=0; i<this.players.size(); i++) { player = this.players.get(i); player.setIndex (i); - this.playerNames.set (i, player.getName()); + //this.originalPlayerNamesList.set (i, player.getName()); log.debug("New player "+i+" is "+player.getName() +" (cash="+Bank.format(player.getCash())+")"); } diff --git a/rails/game/GameManagerI.java b/rails/game/GameManagerI.java index 01253a0..2703019 100644 --- a/rails/game/GameManagerI.java +++ b/rails/game/GameManagerI.java @@ -4,9 +4,7 @@ import java.util.List; import java.util.Map; import rails.algorithms.RevenueManager; -import rails.common.DisplayBuffer; -import rails.common.GuiDef; -import rails.common.GuiHints; +import rails.common.*; import rails.common.parser.ConfigurableComponentI; import rails.game.action.PossibleAction; import rails.game.correct.CorrectionManagerI; @@ -71,7 +69,7 @@ public interface GameManagerI extends MoveableHolder, ConfigurableComponentI { public abstract void registerBrokenBank(); public void registerMaxedSharePrice(PublicCompanyI company, StockSpaceI space); - + public boolean isDynamicOperatingOrder(); /** @@ -136,7 +134,7 @@ public interface GameManagerI extends MoveableHolder, ConfigurableComponentI { public abstract int getNumberOfPlayers(); - public abstract List<String> getPlayerNames(); + //public abstract List<String> getPlayerNames(); public abstract List<PublicCompanyI> getAllPublicCompanies(); @@ -210,28 +208,28 @@ public interface GameManagerI extends MoveableHolder, ConfigurableComponentI { public CorrectionManagerI getCorrectionManager(CorrectionType ct); public List<PublicCompanyI> getCompaniesInRunningOrder (); - public boolean isReloading(); - public void setReloading(boolean reloading); - public void setSkipDone (GameDef.OrStep step); - - public Player reorderPlayersByCash(boolean high); + public boolean isReloading(); + public void setReloading(boolean reloading); + public void setSkipDone (GameDef.OrStep step); + + public Player reorderPlayersByCash(boolean high); /** * reset the storage for other elements like tokens, special property * that a referred by unique ids * TODO */ - public void resetStorage(); - + public void resetStorage(); + /** * store element in storage * @param name to identify the type of the object to retrieve * @param object to store - * @return unique id of the object in the storage + * @return unique id of the object in the storage * TODO move to a better place */ public int storeObject(String typeName, Object object); - + /** * ask storage for object * @param name to identify the type of the object to retrieve diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index 07b5726..e50d32e 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -149,7 +149,7 @@ public class GameUIManager implements DialogOwner { if (Util.hasValue(saveSuffixSpec) && !saveSuffixSpec.equals(NEXT_PLAYER_SUFFIX)) { saveSuffix = saveSuffixSpec; } else { - saveSuffix = getPlayerNames().get(0); + saveSuffix = getPlayers().get(0).getName(); } log.debug("Initial save suffix: "+saveSuffix); } @@ -1030,9 +1030,9 @@ public class GameUIManager implements DialogOwner { return gameManager.getPlayers(); } - public List<String> getPlayerNames() { - return gameManager.getPlayerNames(); - } + //public List<String> getPlayerNames() { + // return gameManager.getPlayerNames(); + //} public Player getCurrentPlayer() { return gameManager.getCurrentPlayer(); |
From: Erik V. <ev...@us...> - 2012-02-03 20:12:36
|
rails/game/specific/_18EU/StartCompany_18EU.java | 20 - rails/ui/swing/GameStatus.java | 2 rails/ui/swing/GameUIManager.java | 77 +++--- rails/ui/swing/ORUIManager.java | 32 +- rails/ui/swing/StartRoundWindow.java | 5 rails/ui/swing/elements/CheckBoxDialog.java | 11 rails/ui/swing/elements/ConfirmationDialog.java | 111 +-------- rails/ui/swing/elements/MessageDialog.java | 6 rails/ui/swing/elements/NonModalDialog.java | 73 +++--- rails/ui/swing/elements/RadioButtonDialog.java | 6 rails/ui/swing/gamespecific/_1835/GameUIManager_1835.java | 46 ++-- rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java | 12 - rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java | 13 - rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java | 3 rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java | 161 +++++++------- 15 files changed, 256 insertions(+), 322 deletions(-) New commits: commit c734b75e2823f0be6ede03d5d58b57e66e300b3f Author: Erik Vos <eri...@xs...> Date: Fri Feb 3 21:06:37 2012 +0100 Refactored nonmodal dialog classes II Added MessageDialog. Refactored most non-modal dialog processing to take advantage of the new dialog-key concept. The Type and Usage enums (introduced in the previous commit) have been dropped. diff --git a/rails/game/specific/_18EU/StartCompany_18EU.java b/rails/game/specific/_18EU/StartCompany_18EU.java index f8333f1..0c44e69 100644 --- a/rails/game/specific/_18EU/StartCompany_18EU.java +++ b/rails/game/specific/_18EU/StartCompany_18EU.java @@ -86,7 +86,7 @@ public class StartCompany_18EU extends StartCompany { MapHex hex = mapManager.getHex(parts[0]); selectedHomeStation = hex.getStop(Integer.parseInt(parts[1])); } - + return selectedHomeStation; } @@ -97,25 +97,23 @@ public class StartCompany_18EU extends StartCompany { @Override public String toString() { - StringBuffer text = new StringBuffer(super.toString()); - if (minorsToMergeNames != null) { - text.append(" minors=").append(minorsToMergeNames); - } + StringBuilder text = new StringBuilder(super.toString()); if (chosenMinorName != null) { - text.append(" merged minor=" + chosenMinorName); - } - if (availableHomeStationNames != null) { - text.append(" stations=" + availableHomeStationNames); + text.append(" minor=" + chosenMinorName); + } else if (minorsToMergeNames != null) { + text.append(" minors=").append(minorsToMergeNames); } if (selectedHomeStationName != null) { - text.append(" home station=" + selectedHomeStationName); + text.append(" home=" + selectedHomeStationName); + } else if (availableHomeStationNames != null) { + text.append(" homes=" + availableHomeStationNames); } return text.toString(); } /** Deserialize */ private void readObject(ObjectInputStream in) throws IOException, - ClassNotFoundException { + ClassNotFoundException { in.defaultReadObject(); diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index dd8e00e..a10dd80 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -768,7 +768,7 @@ public class GameStatus extends GridPanel implements ActionListener { if (options.size() > 1) { if (startCompany) { RadioButtonDialog dialog = new RadioButtonDialog ( - NonModalDialog.Usage.COMPANY_START_PRICE, + GameUIManager.COMPANY_START_PRICE_DIALOG, gameUIManager, parent, LocalText.getText("PleaseSelect"), diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index b081250..72a3aa7 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -89,6 +89,12 @@ public class GameUIManager implements DialogOwner { protected boolean previousResult; + /* Keys of dialogs owned by this class */ + public static final String COMPANY_START_PRICE_DIALOG = "CompanyStartPrice"; + public static final String SELECT_COMPANY_DIALOG = "SelectCompany"; + public static final String REPAY_LOANS_DIALOG = "RepayLoans"; + public static final String EXCHANGE_TOKENS_DIALOG = "ExchangeTokens"; + protected static Logger log = Logger.getLogger(GameUIManager.class.getPackage().getName()); @@ -221,7 +227,7 @@ public class GameUIManager implements DialogOwner { // define configWindow configWindow = new ConfigWindow(true); configWindow.init(); - + // notify sound manager of game initialization SoundManager.notifyOfGameInit(gameManager); } @@ -256,7 +262,7 @@ public class GameUIManager implements DialogOwner { // resulting sfx are played in the correct order (first the action // related sfx and then model-change related sfx) SoundManager.notifyOfActionProcessing(gameManager, action); - + // Process the action on the server result = previousResult = processOnServer (action); @@ -272,7 +278,7 @@ public class GameUIManager implements DialogOwner { log.info ("Relinquishing turn to "+newPlayer.getName()); } else if (!wasMyTurn && isMyTurn) { autoLoadPoller.setActive(false); - setCurrentDialog(new MessageDialog(this, + setCurrentDialog(new MessageDialog(null, this, (JFrame) activeWindow, LocalText.getText("Message"), LocalText.getText("YourTurn", localPlayerName)), @@ -341,7 +347,7 @@ public class GameUIManager implements DialogOwner { public boolean displayServerMessage() { String[] message = DisplayBuffer.get(); if (message != null) { - setCurrentDialog(new MessageDialog(this, + setCurrentDialog(new MessageDialog(null, this, (JFrame) activeWindow, LocalText.getText("Message"), "<html>" + Util.joinWithDelimiter(message, "<br>")), @@ -631,7 +637,7 @@ public class GameUIManager implements DialogOwner { orWindow.setVisible(true); orWindow.toFront(); - CheckBoxDialog dialog = new CheckBoxDialog(NonModalDialog.Usage.EXCHANGE_TOKENS, + CheckBoxDialog dialog = new CheckBoxDialog(EXCHANGE_TOKENS_DIALOG, this, orWindow, LocalText.getText("ExchangeTokens"), @@ -650,10 +656,27 @@ public class GameUIManager implements DialogOwner { if (!ready) { - if (checkGameSpecificDialogAction()) { - ; - } else if (currentDialog instanceof RadioButtonDialog - && currentDialogAction instanceof StartCompany) { + String key = ""; + if (currentDialog instanceof NonModalDialog) key = ((NonModalDialog)currentDialog).getKey(); + + if (currentDialog instanceof AutoSaveLoadDialog) { + // Not yet a NonModalDialog subclass + autoSaveLoadGame2 ((AutoSaveLoadDialog)currentDialog); + + } else if (!(currentDialog instanceof NonModalDialog)) { + + log.warn("Unknown dialog action: dialog=["+currentDialog+"] action=["+currentDialogAction+"]"); + currentDialogAction = null; + + } else if (currentDialog instanceof MessageDialog) { + // Nothing to do. + currentDialogAction = null; + // This cancels the currently incomplete user action. + // WARNING: always do this if dialog processing terminates in a context + // where an action is aborted and the UI must return to its previous state. + // This will normally be the case after a CANCEL (but not after a NO). + + } else if (COMPANY_START_PRICE_DIALOG.equals(key)) { RadioButtonDialog dialog = (RadioButtonDialog) currentDialog; StartCompany action = (StartCompany) currentDialogAction; @@ -665,12 +688,10 @@ public class GameUIManager implements DialogOwner { action.setNumberBought(action.getSharesPerCertificate()); } else { // No selection done - no action - return; + currentDialogAction = null; } - - } else if (currentDialog instanceof CheckBoxDialog - && currentDialogAction instanceof ExchangeTokens) { + } else if (EXCHANGE_TOKENS_DIALOG.equals(key)) { CheckBoxDialog dialog = (CheckBoxDialog) currentDialog; ExchangeTokens action = (ExchangeTokens) currentDialogAction; @@ -704,28 +725,20 @@ public class GameUIManager implements DialogOwner { action.getTokensToExchange().get(index).setSelected(true); } } - } else if (currentDialog instanceof RadioButtonDialog - && currentDialogAction instanceof RepayLoans) { + } else if (REPAY_LOANS_DIALOG.equals(key)) { 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 { - return; + log.warn("Unknown NonModal dialog action: dialog=["+currentDialog+"] action=["+currentDialogAction+"]"); + currentDialogAction = null; } } - /*if (currentDialogAction != null)*/ processAction(currentDialogAction); + processAction(currentDialogAction); } @@ -988,16 +1001,6 @@ public class GameUIManager implements DialogOwner { } - /* - public boolean isMyTurn() { - return myTurn; - } - - public void setMyTurn(boolean myTurn) { - this.myTurn = myTurn; - } - */ - public void setSaveDirectory(String saveDirectory) { this.saveDirectory = saveDirectory; } @@ -1042,10 +1045,6 @@ public class GameUIManager implements DialogOwner { return gameManager.getPlayers(); } - //public List<String> getPlayerNames() { - // return gameManager.getPlayerNames(); - //} - public Player getCurrentPlayer() { return gameManager.getCurrentPlayer(); } diff --git a/rails/ui/swing/ORUIManager.java b/rails/ui/swing/ORUIManager.java index 226a8b5..ea2d561 100644 --- a/rails/ui/swing/ORUIManager.java +++ b/rails/ui/swing/ORUIManager.java @@ -90,6 +90,10 @@ public class ORUIManager implements DialogOwner { "ConfirmToken", "SetRevenue", "SelectPayout", "CorrectMap" }; + /* Keys of dialogs owned by this class */ + public static final String SELECT_DESTINATION_COMPANIES_DIALOG = "SelectDestinationCompanies"; + public static final String REPAY_LOANS_DIALOG = "RepayLoans"; + protected static Logger log = Logger.getLogger(ORUIManager.class.getPackage().getName()); @@ -494,7 +498,7 @@ public class ORUIManager implements DialogOwner { orPanel.stopRevenueUpdate(); log.debug("Set revenue amount is " + amount); action.setActualRevenue(amount); - + // notify sound manager of set revenue amount as soon as // set revenue is pressed (not waiting for the completion // of the set dividend action) @@ -554,7 +558,7 @@ public class ORUIManager implements DialogOwner { orWindow.setVisible(true); orWindow.toFront(); - CheckBoxDialog dialog = new CheckBoxDialog(NonModalDialog.Usage.SELECT_DESTINATION_COMPANIES, + CheckBoxDialog dialog = new CheckBoxDialog(SELECT_DESTINATION_COMPANIES_DIALOG, this, orWindow, LocalText.getText("DestinationsReached"), @@ -614,7 +618,7 @@ public class ORUIManager implements DialogOwner { public boolean hexClicked(GUIHex clickedHex, GUIHex selectedHex) { boolean triggerORPanelRepaint = false; - + if (mapCorrectionEnabled) { triggerORPanelRepaint = true; boolean checkClickedHex = false; @@ -696,7 +700,7 @@ public class ORUIManager implements DialogOwner { } if (triggerORPanelRepaint) orWindow.repaintORPanel(); - + return triggerORPanelRepaint; } @@ -730,7 +734,7 @@ public class ORUIManager implements DialogOwner { upgradePanel.showUpgrades(); } } - + /** * @return True if the indicated tile must be connected to some other track if * placed on indicated hex. @@ -738,26 +742,26 @@ public class ORUIManager implements DialogOwner { public boolean getMustConnectRequirement (GUIHex hex,TileI tile) { if (tile == null || hex == null) return false; return tile.getColourName().equalsIgnoreCase(Tile.YELLOW_COLOUR_NAME) - // Does not apply to the current company's home hex(es) - && !hex.getHexModel().isHomeFor(orComp) - // Does not apply to special tile lays - && !isUnconnectedTileLayTarget(hex.getHexModel()); + // Does not apply to the current company's home hex(es) + && !hex.getHexModel().isHomeFor(orComp) + // Does not apply to special tile lays + && !isUnconnectedTileLayTarget(hex.getHexModel()); } - + public void addTileUpgradeIfValid(GUIHex hex, int tileId) { addTileUpgradeIfValid (hex, gameUIManager.getGameManager().getTileManager().getTile(tileId)); } - + public void addTileUpgradeIfValid(GUIHex hex, TileI tile) { if (!tileUpgrades.contains(tile) && isTileUpgradeValid(hex,tile)) { tileUpgrades.add(tile); } } - + public boolean isTileUpgradeValid(GUIHex hex, TileI tile) { // Check if the new tile must be connected to some other track - return hex.isTileUpgradeValid(tile.getId(), + return hex.isTileUpgradeValid(tile.getId(), getMustConnectRequirement(hex,tile)); } @@ -1477,7 +1481,7 @@ public class ORUIManager implements DialogOwner { Bank.format(i * loanAmount)); } } - RadioButtonDialog currentDialog = new RadioButtonDialog (NonModalDialog.Usage.REPAY_LOANS, + RadioButtonDialog currentDialog = new RadioButtonDialog (REPAY_LOANS_DIALOG, gameUIManager, orWindow, LocalText.getText("Select"), diff --git a/rails/ui/swing/StartRoundWindow.java b/rails/ui/swing/StartRoundWindow.java index 47f0a9a..1ff36cd 100644 --- a/rails/ui/swing/StartRoundWindow.java +++ b/rails/ui/swing/StartRoundWindow.java @@ -112,6 +112,9 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { private boolean includeBidding; private boolean showBasePrices; + /* Keys of dialogs owned by this class */ + public static final String COMPANY_START_PRICE_DIALOG = "CompanyStartPrice"; + protected static Logger log = Logger.getLogger(StartRoundWindow.class.getPackage().getName()); @@ -653,7 +656,7 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { } RadioButtonDialog dialog = new RadioButtonDialog( - NonModalDialog.Usage.COMPANY_START_PRICE, + COMPANY_START_PRICE_DIALOG, this, this, LocalText.getText("PleaseSelect"), diff --git a/rails/ui/swing/elements/CheckBoxDialog.java b/rails/ui/swing/elements/CheckBoxDialog.java index 0a56e91..d2fd91a 100644 --- a/rails/ui/swing/elements/CheckBoxDialog.java +++ b/rails/ui/swing/elements/CheckBoxDialog.java @@ -24,15 +24,16 @@ public class CheckBoxDialog extends NonModalDialog { int chosenOption = -1; boolean hasCancelButton = false; - public CheckBoxDialog(Usage usage, DialogOwner owner, JFrame window, String title, String message, + public CheckBoxDialog(String key, DialogOwner owner, JFrame window, String title, String message, String[] options) { - this (usage, owner, window, title, message, options, null, false); + this (key, owner, window, title, message, options, null, false); } - public CheckBoxDialog(Usage usage, DialogOwner owner, JFrame window, String title, String message, + public CheckBoxDialog(String key, DialogOwner owner, JFrame window, String title, String message, String[] options, boolean[] selectedOptions, boolean addCancelButton) { - super (Type.CHECKBOX, usage, owner, window, title, message, addCancelButton); + super (key, owner, window, title, message); + this.hasCancelButton = addCancelButton; this.options = options; this.numOptions = options.length; @@ -42,7 +43,7 @@ public class CheckBoxDialog extends NonModalDialog { this.selectedOptions = new boolean[numOptions]; } - initialize(); + initialize(hasCancelButton); } @Override diff --git a/rails/ui/swing/elements/ConfirmationDialog.java b/rails/ui/swing/elements/ConfirmationDialog.java index c3269b9..cbcdf6b 100644 --- a/rails/ui/swing/elements/ConfirmationDialog.java +++ b/rails/ui/swing/elements/ConfirmationDialog.java @@ -1,118 +1,35 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/ConfirmationDialog.java,v 1.1 2010/02/28 21:38:06 evos Exp $*/ package rails.ui.swing.elements; -import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; -import javax.swing.*; - -import org.apache.log4j.Logger; - -import rails.common.LocalText; +import javax.swing.JFrame; /** - * A generic YES/NO dialog + * A generic YES/NO dialog */ -public class ConfirmationDialog extends JDialog implements ActionListener { +public class ConfirmationDialog extends NonModalDialog { private static final long serialVersionUID = 1L; - GridBagConstraints gc; - JPanel messagePane, buttonPane; - JButton okButton, cancelButton; - Dimension size, optSize; - DialogOwner owner; - String message; boolean answer = false; - protected static Logger log = - Logger.getLogger(ConfirmationDialog.class.getPackage().getName()); - - public ConfirmationDialog(DialogOwner owner, String title, String message, - String okText, String cancelText) { - super((Frame) null, title, false); // Non-modal - this.owner = owner; - this.message = message; - - initialize(okText, cancelText); - pack(); + public ConfirmationDialog(String key, DialogOwner owner, JFrame window, String title, String message, + String okTextKey, String cancelTextKey) { - // Center on owner - /* - int x = - (int) owner.getLocationOnScreen().getX() - + (owner.getWidth() - getWidth()) / 2; - int y = - (int) owner.getLocationOnScreen().getY() - + (owner.getHeight() - getHeight()) / 2; - */ - int x = 400; - int y = 400; - setLocation(x, y); + super (key, owner, window, title, message); - setVisible(true); - setAlwaysOnTop(true); + initialize(okTextKey, cancelTextKey); } - private void initialize(String okText, String cancelText) { - - gc = new GridBagConstraints(); - - getContentPane().setLayout(new GridBagLayout()); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - messagePane = new JPanel(); - - messagePane.add(new JLabel(message)); - - buttonPane = new JPanel(); - - okButton = new JButton(LocalText.getText(okText)); - // We only expect Yes/No or OK/Cancel - if (okText.startsWith("O")) - okButton.setMnemonic(KeyEvent.VK_O); - else if (okText.startsWith("Y")) - okButton.setMnemonic(KeyEvent.VK_Y); - okButton.addActionListener(this); - buttonPane.add(okButton); - - cancelButton = new JButton(LocalText.getText(cancelText)); - // We only expect Yes/No or OK/Cancel - if (cancelText.startsWith("C")) - cancelButton.setMnemonic(KeyEvent.VK_C); - else if (cancelText.startsWith("N")) - cancelButton.setMnemonic(KeyEvent.VK_N); - cancelButton.addActionListener(this); - buttonPane.add(cancelButton); - - getContentPane().add(messagePane, constraints(0, 0, 0, 0, 0, 0)); - getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); - } - - private GridBagConstraints constraints(int gridx, int gridy, int leftinset, - int topinset, int rightinset, int bottominset) { - if (gridx >= 0) gc.gridx = gridx; - if (gridy >= 0) gc.gridy = gridy; - gc.fill = GridBagConstraints.BOTH; - gc.weightx = 0.5; - gc.weighty = 0.5; - if (leftinset >= 0) gc.insets.left = leftinset; - if (topinset >= 0) gc.insets.top = topinset; - if (rightinset >= 0) gc.insets.right = rightinset; - if (bottominset >= 0) gc.insets.bottom = bottominset; - - return gc; + @Override + protected void processOK (ActionEvent actionEvent) { + answer = true; } - public void actionPerformed(ActionEvent arg0) { - if (arg0.getSource().equals(okButton)) { - answer = true; - } else if (arg0.getSource().equals(cancelButton)) { - answer = false; - } - this.setVisible(false); - this.dispose(); - owner.dialogActionPerformed(); + @Override + protected void processCancel (ActionEvent actionEvent) { + answer = false; } public synchronized boolean getAnswer() { diff --git a/rails/ui/swing/elements/MessageDialog.java b/rails/ui/swing/elements/MessageDialog.java index e4bfe66..9a6dad3 100644 --- a/rails/ui/swing/elements/MessageDialog.java +++ b/rails/ui/swing/elements/MessageDialog.java @@ -10,11 +10,11 @@ public class MessageDialog extends NonModalDialog { private static final long serialVersionUID = 1L; - public MessageDialog(DialogOwner owner, JFrame window, String title, String message) { + public MessageDialog(String key, DialogOwner owner, JFrame window, String title, String message) { - super (Type.MESSAGE, null, owner, window, title, message, false); + super (key, owner, window, title, message); - initialize(); + initialize(false); } diff --git a/rails/ui/swing/elements/NonModalDialog.java b/rails/ui/swing/elements/NonModalDialog.java index 0fe730c..72718d2 100644 --- a/rails/ui/swing/elements/NonModalDialog.java +++ b/rails/ui/swing/elements/NonModalDialog.java @@ -8,55 +8,47 @@ import javax.swing.*; import org.apache.log4j.Logger; import rails.common.LocalText; +import rails.util.Util; public abstract class NonModalDialog extends JDialog implements ActionListener { private static final long serialVersionUID = 1L; - protected Type type; - protected Usage usage; + protected String key; protected DialogOwner owner = null; protected JFrame window = null; protected String message; - protected boolean hasCancelButton = false; + protected boolean hasCancelButton = true; GridBagConstraints gc; JPanel optionsPane, buttonPane; JButton okButton, cancelButton; - - public static enum Usage { - REPAY_LOANS, - DESTINATION_REACHED, - BUY_WHICH_TRAIN, - COMPANY_START_PRICE, - EXCHANGE_TOKENS, - SELECT_FOLDING_COMPANIES, - SELECT_DESTINATION_COMPANIES, - SELECT_COMPANY, - SELECT_HOME_STATION - } - - public static enum Type { - CHECKBOX, - RADIO, - MESSAGE, - MIXED - } + String okTextKey = "OK"; + String cancelTextKey = "Cancel"; protected static Logger log = Logger.getLogger(NonModalDialog.class.getPackage().getName()); - public NonModalDialog(Type type, Usage usage, - DialogOwner owner, JFrame window, String title, String message, - boolean addCancelButton) { + public NonModalDialog(String key, + DialogOwner owner, JFrame window, String title, String message) { super((Frame) null, title, false); // Non-modal - this.type = type; - this.usage = usage; + this.key = key; this.owner = owner; this.window = window; this.message = message; - hasCancelButton = addCancelButton; + } + + protected final void initialize (String okTextKey, String cancelTextKey) { + this.okTextKey = okTextKey; + this.cancelTextKey = cancelTextKey; + this.hasCancelButton = Util.hasValue(cancelTextKey); + initialize(); + } + + protected final void initialize (boolean hasCancelButton) { + this.hasCancelButton = hasCancelButton; + initialize(); } protected final void initialize() { @@ -66,14 +58,14 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { optionsPane = new JPanel(); buttonPane = new JPanel(); - okButton = new JButton(LocalText.getText("OK")); - okButton.setMnemonic(KeyEvent.VK_O); + okButton = new JButton(LocalText.getText(okTextKey)); + okButton.setMnemonic(okTextKey.startsWith("Y") ? KeyEvent.VK_Y : KeyEvent.VK_O); okButton.addActionListener(this); buttonPane.add(okButton); if (hasCancelButton) { - cancelButton = new JButton(LocalText.getText("Cancel")); - cancelButton.setMnemonic(KeyEvent.VK_C); + cancelButton = new JButton(LocalText.getText(cancelTextKey)); + cancelButton.setMnemonic(cancelTextKey.startsWith("N") ? KeyEvent.VK_N : KeyEvent.VK_C); cancelButton.addActionListener(this); buttonPane.add(cancelButton); } @@ -102,8 +94,7 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { setAlwaysOnTop(true); } - protected void initializeInput() { - } + protected void initializeInput() {} protected GridBagConstraints constraints(int gridx, int gridy, int leftinset, int topinset, int rightinset, int bottominset) { @@ -126,12 +117,22 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { } else if (actionEvent.getSource().equals(cancelButton)) { processCancel (actionEvent); } + log.debug("Processed: dialog="+getClass().getSimpleName()+" key="+key); setVisible(false); dispose(); owner.dialogActionPerformed (); } - protected void processOK (ActionEvent actionEvent) {}; + protected void processOK (ActionEvent actionEvent) {} + + protected void processCancel (ActionEvent actionEvent) {} - protected void processCancel (ActionEvent actionEvent) {}; + public String getKey() { + return key; + } + + @Override + public String toString() { + return "Dialog type="+getClass().getSimpleName()+" key="+key; + } } diff --git a/rails/ui/swing/elements/RadioButtonDialog.java b/rails/ui/swing/elements/RadioButtonDialog.java index 1d7cc59..cbd4306 100644 --- a/rails/ui/swing/elements/RadioButtonDialog.java +++ b/rails/ui/swing/elements/RadioButtonDialog.java @@ -22,16 +22,16 @@ public class RadioButtonDialog extends NonModalDialog { int selectedOption; int chosenOption = -1; - public RadioButtonDialog(Usage usage, DialogOwner owner, JFrame window, String title, String message, + public RadioButtonDialog(String key, DialogOwner owner, JFrame window, String title, String message, String[] options, int selectedOption) { - super (Type.RADIO, usage, owner, window, title, message, selectedOption < 0); + super (key, owner, window, title, message); this.options = options; this.numOptions = options.length; this.selectedOption = selectedOption; - initialize(); + initialize(selectedOption < 0); } @Override diff --git a/rails/ui/swing/gamespecific/_1835/GameUIManager_1835.java b/rails/ui/swing/gamespecific/_1835/GameUIManager_1835.java index 22654a6..192bd50 100644 --- a/rails/ui/swing/gamespecific/_1835/GameUIManager_1835.java +++ b/rails/ui/swing/gamespecific/_1835/GameUIManager_1835.java @@ -6,45 +6,51 @@ import java.util.List; import rails.game.CompanyI; import rails.game.specific._1835.FoldIntoPrussian; import rails.ui.swing.GameUIManager; -import rails.ui.swing.elements.CheckBoxDialog; -import rails.ui.swing.elements.ConfirmationDialog; +import rails.ui.swing.elements.*; public class GameUIManager_1835 extends GameUIManager { - protected boolean checkGameSpecificDialogAction() { - - if (currentDialog instanceof ConfirmationDialog - && currentDialogAction instanceof FoldIntoPrussian) { - + // Keys of dialogs owned by this class. + public static final String START_PRUSSIAN_DIALOG = "StartPrussian"; + public static final String MERGE_INTO_PRUSSIAN_DIALOG = "MergeIntoPrussian"; + + @Override + public void dialogActionPerformed() { + + String key = ""; + if (currentDialog instanceof NonModalDialog) key = ((NonModalDialog)currentDialog).getKey(); + + // Check for the dialogs that are postprocessed in this class. + if (START_PRUSSIAN_DIALOG.equals(key)) { + ConfirmationDialog dialog = (ConfirmationDialog) currentDialog; FoldIntoPrussian action = (FoldIntoPrussian) currentDialogAction; if (dialog.getAnswer()) { action.setFoldedCompanies(action.getFoldableCompanies()); } - - return true; - - } else if (currentDialog instanceof CheckBoxDialog - && currentDialogAction instanceof FoldIntoPrussian) { - + + } else if (MERGE_INTO_PRUSSIAN_DIALOG.equals(key)) { + CheckBoxDialog dialog = (CheckBoxDialog) currentDialog; FoldIntoPrussian action = (FoldIntoPrussian) currentDialogAction; boolean[] exchanged = dialog.getSelectedOptions(); String[] options = dialog.getOptions(); - + List<CompanyI> foldedCompanies = new ArrayList<CompanyI>(); for (int index=0; index < options.length; index++) { if (exchanged[index]) { foldedCompanies.add(action.getFoldableCompanies().get(index)); - } + } } action.setFoldedCompanies(foldedCompanies); - - return true; - + } else { - return false; + // Current dialog not found yet, try the superclass. + super.dialogActionPerformed(false); + return; } - } + // Dialog action found and processed, let the superclass initiate processing. + super.dialogActionPerformed(true); + } } diff --git a/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java b/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java index aed46cc..75924af 100644 --- a/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java +++ b/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java @@ -2,8 +2,6 @@ package rails.ui.swing.gamespecific._1835; import java.util.List; -import javax.swing.JDialog; - import rails.common.LocalText; import rails.game.*; import rails.game.action.DiscardTrain; @@ -63,17 +61,19 @@ public class StatusWindow_1835 extends StatusWindow { protected void fold (FoldIntoPrussian action) { List<CompanyI> foldables = action.getFoldableCompanies(); - JDialog currentDialog; + NonModalDialog currentDialog; if (foldables.get(0).getName().equals("M2")) { // Ask if the Prussian should be started - currentDialog = new ConfirmationDialog (gameUIManager, + currentDialog = new ConfirmationDialog (GameUIManager_1835.START_PRUSSIAN_DIALOG, + gameUIManager, this, LocalText.getText("Select"), LocalText.getText("MergeMinorConfirm", getCurrentPlayer().getName(), GameManager_1835.M2_ID, GameManager_1835.PR_ID), "Yes", - "No"); + "No" + ); } else { // Ask if any other prePrussians should be folded String[] options = new String[foldables.size()]; @@ -87,7 +87,7 @@ public class StatusWindow_1835 extends StatusWindow { ((ExchangeForShare)(company.getSpecialProperties().get(0))).getShare() ); } - currentDialog = new CheckBoxDialog (NonModalDialog.Usage.SELECT_FOLDING_COMPANIES, + currentDialog = new CheckBoxDialog (GameUIManager_1835.MERGE_INTO_PRUSSIAN_DIALOG, gameUIManager, this, LocalText.getText("Select"), diff --git a/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java b/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java index b48d117..4a4b7e7 100644 --- a/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java +++ b/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java @@ -8,8 +8,8 @@ import rails.game.Bank; import rails.game.RoundI; import rails.game.action.*; import rails.game.specific._1856.CGRFormationRound; +import rails.ui.swing.GameUIManager; import rails.ui.swing.StatusWindow; -import rails.ui.swing.elements.NonModalDialog; import rails.ui.swing.elements.RadioButtonDialog; import rails.util.Util; @@ -52,15 +52,6 @@ public class StatusWindow_1856 extends StatusWindow { repayLoans (nextAction); return true; - /* Moved up - } else if (immediateAction instanceof DiscardTrain) { - // Make a local copy and discard the original, - // so that it's not going to loop. - DiscardTrain nextAction = (DiscardTrain) immediateAction; - immediateAction = null; - gameUIManager.discardTrains (nextAction); - return true; - */ } else if (immediateAction instanceof ExchangeTokens) { // Make a local copy and discard the original, // so that it's not going to loop. @@ -100,7 +91,7 @@ public class StatusWindow_1856 extends StatusWindow { + "<br>" + message; } - RadioButtonDialog currentDialog = new RadioButtonDialog (NonModalDialog.Usage.REPAY_LOANS, + RadioButtonDialog currentDialog = new RadioButtonDialog (GameUIManager.REPAY_LOANS_DIALOG, gameUIManager, this, LocalText.getText("1856MergerDialog", action.getCompanyName()), diff --git a/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java b/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java index 81e816d..f3378b3 100644 --- a/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java +++ b/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java @@ -8,7 +8,6 @@ import rails.game.PublicCompanyI; import rails.game.action.MergeCompanies; import rails.game.action.PossibleAction; import rails.ui.swing.GameStatus; -import rails.ui.swing.elements.NonModalDialog; import rails.ui.swing.elements.RadioButtonDialog; /** @@ -71,7 +70,7 @@ public class GameStatus_18EU extends GameStatus { } RadioButtonDialog dialog = new RadioButtonDialog ( - NonModalDialog.Usage.SELECT_COMPANY, + GameUIManager_18EU.SELECT_MERGING_MAJOR, gameUIManager, parent, LocalText.getText("PleaseSelect"), diff --git a/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java b/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java index 5c17748..0c6cc86 100644 --- a/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java +++ b/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java @@ -15,123 +15,138 @@ import rails.ui.swing.elements.RadioButtonDialog; public class GameUIManager_18EU extends GameUIManager { + // Keys of dialogs owned by this class. + public static final String SELECT_CONVERTING_MINOR = "SelectConvertingMinor"; + public static final String SELECT_MERGING_MAJOR = "SelectMergingMajor"; + public static final String SELECT_HOME_STATION_DIALOG = "SelectHomeStation"; + @Override public void dialogActionPerformed () { - if (currentDialog instanceof RadioButtonDialog - && currentDialogAction instanceof MergeCompanies) { + String key = ""; + if (currentDialog instanceof NonModalDialog) key = ((NonModalDialog)currentDialog).getKey(); + + // Check for the dialogs that are postprocessed in this class. + if (SELECT_MERGING_MAJOR.equals(key)) { + // A major company has been selected (or not) to merge a minor into. RadioButtonDialog dialog = (RadioButtonDialog) currentDialog; MergeCompanies action = (MergeCompanies) currentDialogAction; PublicCompanyI minor = action.getMergingCompany(); - if (action.getSelectedTargetCompany() == null) { - // Step 1: selection of the major company to merge into - int choice = dialog.getSelectedOption(); - if (choice < 0) return; + int choice = dialog.getSelectedOption(); + if (choice < 0) return; - PublicCompanyI major = action.getTargetCompanies().get(choice); - action.setSelectedTargetCompany(major); + PublicCompanyI major = action.getTargetCompanies().get(choice); + action.setSelectedTargetCompany(major); - if (major != null && action.canReplaceToken(choice)) { + if (major != null && action.canReplaceToken(choice)) { - boolean replaceToken = - JOptionPane.showConfirmDialog(statusWindow, LocalText.getText( - "WantToReplaceToken", - minor.getName(), - major.getName() ), - LocalText.getText("PleaseSelect"), - JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; - action.setReplaceToken(replaceToken); - } + boolean replaceToken = + JOptionPane.showConfirmDialog(statusWindow, LocalText.getText( + "WantToReplaceToken", + minor.getName(), + major.getName() ), + LocalText.getText("PleaseSelect"), + JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; + action.setReplaceToken(replaceToken); + } + + } else if (SELECT_CONVERTING_MINOR.equals(key)) { + + // A minor has been selected (or not) to merge into a starting company before phase 6. + RadioButtonDialog dialog = (RadioButtonDialog) currentDialog; + StartCompany_18EU action = (StartCompany_18EU) currentDialogAction; + int choice = dialog.getSelectedOption(); + if (choice < 0) { + currentDialogAction = null; } else { - // To be added later when ReplaceToken dialog is modeless + PublicCompanyI minor = action.getMinorsToMerge().get(choice); + action.setChosenMinor(minor); } - } else if (currentDialog instanceof RadioButtonDialog + } else if (COMPANY_START_PRICE_DIALOG.equals(key) && currentDialogAction instanceof StartCompany_18EU) { + // A start price has been selected (or not) for a stating major company. RadioButtonDialog dialog = (RadioButtonDialog) currentDialog; StartCompany_18EU action = (StartCompany_18EU) currentDialogAction; - if (action.getPrice() == 0) { + int index = dialog.getSelectedOption(); + if (index < 0) { + currentDialogAction = null; + return; + } + action.setStartPrice(action.getStartPrices()[index]); + + // Set up another dialog for the next step + List<PublicCompanyI> minors = action.getMinorsToMerge(); + + if (minors != null && !minors.isEmpty()) { + // Up to phase 6, a minor must be exchanged + String[] options = new String[minors.size()]; + int i = 0; + for (PublicCompanyI minor : minors) { + options[i++] = + "Minor " + minor.getName() + " " + + minor.getLongName(); + } + dialog = new RadioButtonDialog (SELECT_CONVERTING_MINOR, + this, + statusWindow, + LocalText.getText("PleaseSelect"), + LocalText.getText( + "SelectMinorToMerge", + action.getCompanyName()), + options, -1); + setCurrentDialog(dialog, action); + statusWindow.disableButtons(); + return; + } else { - // The price will be set first - int index = dialog.getSelectedOption(); - if (index < 0) return; - action.setStartPrice(action.getStartPrices()[index]); - - // Set up another dialog for the next step - List<PublicCompanyI> minors = action.getMinorsToMerge(); - - if (minors != null && !minors.isEmpty()) { - // Up to phase 6, a minor must be exchanged - String[] options = new String[minors.size()]; - int i = 0; - for (PublicCompanyI minor : minors) { - options[i++] = - "Minor " + minor.getName() + " " - + minor.getLongName(); + // From phase 6, no minors are involved, but a home station must be chosen + List<Stop> cities = action.getAvailableHomeStations(); + if (cities != null && !cities.isEmpty()) { + String[] options = new String[cities.size()]; + for (int i = 0; i < options.length; i++) { + options[i] = cities.get(i).toString(); } - dialog = new RadioButtonDialog (NonModalDialog.Usage.SELECT_FOLDING_COMPANIES, + dialog = new RadioButtonDialog (SELECT_HOME_STATION_DIALOG, this, statusWindow, LocalText.getText("PleaseSelect"), LocalText.getText( - "SelectMinorToMerge", + "SelectHomeStation", action.getCompanyName()), options, -1); setCurrentDialog(dialog, action); statusWindow.disableButtons(); return; - } else { - - // From phase 6, no minors are involved, but a home station must be chosen - List<Stop> cities = action.getAvailableHomeStations(); - if (cities != null && !cities.isEmpty()) { - String[] options = new String[cities.size()]; - for (int i = 0; i < options.length; i++) { - options[i] = cities.get(i).toString(); - } - dialog = new RadioButtonDialog (NonModalDialog.Usage.SELECT_HOME_STATION, - this, - statusWindow, - LocalText.getText("PleaseSelect"), - LocalText.getText( - "SelectHomeStation", - action.getCompanyName()), - options, -1); - setCurrentDialog(dialog, action); - statusWindow.disableButtons(); - return; - - } - } - } else if (action.getMinorsToMerge() != null) { - // Up to phase 5: a minor to merge has been selected (or not) - int choice = dialog.getSelectedOption(); - if (choice < 0) { - // Also reset price - action.setStartPrice(0); - return; } - action.setChosenMinor(action.getMinorsToMerge().get(choice)); + } + + } else if (SELECT_HOME_STATION_DIALOG.equals(key)) { + + RadioButtonDialog dialog = (RadioButtonDialog) currentDialog; + StartCompany_18EU action = (StartCompany_18EU) currentDialogAction; - } else if (action.getAvailableHomeStations() != null) { + if (action.getAvailableHomeStations() != null) { // From phase 6: a home station has been selected (or not) int index = dialog.getSelectedOption(); if (index < 0) { - // Also reset price - action.setStartPrice(0); + currentDialogAction = null; return; } action.setHomeStation(action.getAvailableHomeStations().get(index)); } } else { + // Current dialog not found yet, try the superclass. super.dialogActionPerformed(false); + return; } + // Dialog action found and processed, let the superclass initiate processing. super.dialogActionPerformed(true); } |
From: Erik V. <ev...@us...> - 2012-03-18 15:25:49
|
rails/game/specific/_1880/OffBoardRevenueModifier_1880.java | 2 rails/game/specific/_1880/StartRound_1880.java | 21 +++++- rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java | 36 +++++------ 3 files changed, 37 insertions(+), 22 deletions(-) New commits: commit d351b1a60f95c4dd78ea0ddedc60e311b6b1f87b Author: Martin Brumm <Dr....@t-...> Date: Sun Mar 18 16:03:21 2012 +0100 1880: fixed the reported bugs by Phil Davies. diff --git a/rails/game/specific/_1880/OffBoardRevenueModifier_1880.java b/rails/game/specific/_1880/OffBoardRevenueModifier_1880.java index 7580a5c..d8cbf97 100644 --- a/rails/game/specific/_1880/OffBoardRevenueModifier_1880.java +++ b/rails/game/specific/_1880/OffBoardRevenueModifier_1880.java @@ -29,7 +29,7 @@ public class OffBoardRevenueModifier_1880 implements RevenueStaticModifier { // 1. get the two off-board type stations (Russia and Wladiwostok) Set<NetworkVertex> offBoard = new HashSet<NetworkVertex>(); for (NetworkVertex vertex:revenueAdapter.getVertices()) { // We just need the two offboard Cities - if (vertex.isStation() && ((vertex.getStation().getName().equals("Russia") ||(vertex.getStation().getName().equals("Wladiwostok"))))) { + if (vertex.isStation() && ((vertex.getStation().getName().equals("Russia") ||(vertex.getStation().getName().equals("Vladivostok"))))) { offBoard.add(vertex); } } diff --git a/rails/game/specific/_1880/StartRound_1880.java b/rails/game/specific/_1880/StartRound_1880.java index d906796..9c2ecde 100644 --- a/rails/game/specific/_1880/StartRound_1880.java +++ b/rails/game/specific/_1880/StartRound_1880.java @@ -240,8 +240,25 @@ public class StartRound_1880 extends StartRound { Bank.format(bidAmount), item.getName(), Bank.format(player.getCash()) )); + if ((item.getBidders() >0) && (numPasses.intValue()== getNumberOfPlayers()-1)) { + // All but the highest bidder have passed. + int price = item.getBid(); + + log.debug("Highest bidder is " + + item.getBidder().getName()); + if (item.needsPriceSetting() != null) { + item.setStatus(StartItem.NEEDS_SHARE_PRICE); + } else { + assignItem(item.getBidder(), item, price, 0); + } + auctionItemState.set(null); + numPasses.set(0); + setNextStartingPlayer(); + return true; + } else { setNextBiddingPlayer(item); return true; + } } @@ -294,17 +311,15 @@ public class StartRound_1880 extends StartRound { assignItem((Player)startingPlayer.get(), auctionItem, 0, 0); setNextStartingPlayer(); - // startPacket.getFirstItem().getName()); return true; } } else { numPasses.set(0); - //gameManager.nextRound(this); finishRound(); } } - // if ((numPasses.intValue() >= auctionItem.getBidders() - 1) && + if ((auctionItem.getBidders() >0) && (numPasses.intValue()== getNumberOfPlayers()-1)) { // All but the highest bidder have passed. int price = auctionItem.getBid(); diff --git a/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java b/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java index dc264d2..7683295 100644 --- a/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java +++ b/rails/ui/swing/gamespecific/_1880/StartRoundWindow_1880.java @@ -77,22 +77,22 @@ public class StartRoundWindow_1880 extends StartRoundWindow { // Get a sorted prices List // TODO: should be included in BuyStartItem - List<StockSpaceI> startSpaces = stockMarket.getStartSpaces(); - Map<Integer, StockSpaceI> spacePerPrice = - new HashMap<Integer, StockSpaceI>(); - startPrices = new int[startSpaces.size()]; - String[] options = new String[startSpaces.size()]; - for (int i = 0; i < startSpaces.size(); i++) { - if (((StockMarket_1880) stockMarket).getParSlot(startSpaces.get(i).getPrice())) { //Make sure we got a Parslot left over - startPrices[i] = startSpaces.get(i).getPrice(); - spacePerPrice.put(startPrices[i], startSpaces.get(i)); - } - } - Arrays.sort(startPrices); - for (int i = 0; i < startSpaces.size(); i++) { - options[i] = Bank.format(spacePerPrice.get(startPrices[i]).getPrice()); - } - +// List<StockSpaceI> startSpaces = stockMarket.getStartSpaces(); +// Map<Integer, StockSpaceI> spacePerPrice = +// new HashMap<Integer, StockSpaceI>(); +// startPrices = new int[startSpaces.size()]; + String[] options = {""}; +// for (int i = 0; i < startSpaces.size(); i++) { +// if (((StockMarket_1880) stockMarket).getParSlot(startSpaces.get(i).getPrice())) { //Make sure we got a Parslot left over +// startPrices[i] = startSpaces.get(i).getPrice(); +// spacePerPrice.put(startPrices[i], startSpaces.get(i)); +// } +// } +// Arrays.sort(startPrices); +// for (int i = 0; i < startSpaces.size(); i++) { +// options[i] = Bank.format(spacePerPrice.get(startPrices[i]).getPrice()); +// } + options[0] = "100"; RadioButtonDialog dialog = new RadioButtonDialog( COMPANY_START_PRICE_DIALOG, this, @@ -102,7 +102,7 @@ public class StartRoundWindow_1880 extends StartRoundWindow { activeItem.getPlayerName(), compName), options, - -1); + 0); setCurrentDialog (dialog, activeItem); } return true; @@ -143,7 +143,7 @@ public class StartRoundWindow_1880 extends StartRoundWindow { int index = dialog.getSelectedOption(); if (index >= 0) { - int price = startPrices[index]; + int price = 100; action.setAssociatedSharePrice(price); ((StockMarket_1880) stockMarket).setParSlot(price); |
From: Erik V. <ev...@us...> - 2012-03-19 09:55:24
|
rails/game/MapHex.java | 1 + rails/ui/swing/hexmap/GUITile.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) New commits: commit e64779a1880d43bd4c810cf981b80654ddaab3bb Author: Martin Brumm <Dr....@t-...> Date: Mon Mar 19 10:54:15 2012 +0100 Fixed picture ID determination, which did not work for upgrades. diff --git a/rails/game/MapHex.java b/rails/game/MapHex.java index f6225cf..f02a37a 100644 --- a/rails/game/MapHex.java +++ b/rails/game/MapHex.java @@ -470,6 +470,7 @@ StationHolder, TokenHolder { /** Return the current picture ID (i.e. the tile ID to be displayed, rather than used for route determination). * <p> Usually, the picture ID is equal to the tile ID. Different values may be defined per hex or per tile. + * Restriction: definitions per hex can apply to preprinted tiles only. * @return The current picture ID */ public int getPictureId () { diff --git a/rails/ui/swing/hexmap/GUITile.java b/rails/ui/swing/hexmap/GUITile.java index f7162f9..9f34078 100644 --- a/rails/ui/swing/hexmap/GUITile.java +++ b/rails/ui/swing/hexmap/GUITile.java @@ -53,7 +53,14 @@ public class GUITile { this.hex = (MapHex)guiHex.getModel(); TileManager tileManager = guiHex.getHexMap().orUIManager.getTileManager(); tile = tileManager.getTile(tileId); - picId = hex.getPictureId(); + + if (tile.getId() > 0) { + // Layable tiles can have a different picture ID, defined per tile only. + picId = tile.getPictureId(); + } else { + // Preprinted tiles can have a different picture ID, defined per hex or per tile. + picId = hex.getPictureId(); + } if (hex.getTileOrientation() == TileOrientation.EW) { baseRotation = 0.5 * DEG60; |