From: Stefan F. <ste...@us...> - 2010-02-14 20:48:34
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv21890/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: Added NoMapMode as GameOption. This mode skips LayTile and LayTrack actions and replaces those by more generic OperatingCosts actions. Currently only a non-strict mode is supported, thus "illegal" actions are possible. Option only tested and active for 1889 and 1835. Others to follow. Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** ORUIManager.java 7 Feb 2010 18:28:22 -0000 1.53 --- ORUIManager.java 14 Feb 2010 20:48:20 -0000 1.54 *************** *** 10,13 **** --- 10,14 ---- import rails.game.*; import rails.game.action.*; + import rails.game.correct.*; import rails.game.special.*; import rails.ui.swing.elements.*; *************** *** 319,322 **** --- 320,327 ---- } + } else if (command.equals(ORPanel.OPERATING_COST_CMD)) { + + operatingCosts(); + } else if (command.equals(ORPanel.BUY_TRAIN_CMD)) { *************** *** 748,751 **** --- 753,813 ---- } + public void operatingCosts(){ + + List<String> textOC = new ArrayList<String>(); + List<OperatingCost> actionOC = possibleActions.getType(OperatingCost.class); + + for (OperatingCost ac:actionOC) { + + int suggestedCost = ac.getAmount(); + String suggestedCostText; + if (suggestedCost == 0) + suggestedCostText = LocalText.getText("OCAmountEntry"); + else + suggestedCostText = Bank.format(suggestedCost); + + OperatingCost.OCType t = ac.getOCType(); + if (t == OperatingCost.OCType.LAY_TILE) + textOC.add(LocalText.getText("OCLayTile", + suggestedCostText )); + + if (t == OperatingCost.OCType.LAY_BASE_TOKEN) + textOC.add(LocalText.getText("OCLayBaseToken", + suggestedCostText )); + } + + if (!textOC.isEmpty()) { + String chosenOption = (String) JOptionPane.showInputDialog(orWindow, + LocalText.getText("OCSelectMessage"), + LocalText.getText("OCSelectTitle"), + JOptionPane.QUESTION_MESSAGE, null, + textOC.toArray(), textOC.get(0)); + if (chosenOption != null) { + int index = textOC.indexOf(chosenOption); + OperatingCost chosenAction = actionOC.get(index); + if (chosenAction.getAmount() == 0) { + String costString = (String) JOptionPane.showInputDialog(orWindow, + LocalText.getText("OCDialogMessage", chosenOption), + LocalText.getText("OCDialogTitle"), + JOptionPane.QUESTION_MESSAGE, null, + null, chosenAction.getAmount()); + int cost; + try { + cost = Integer.parseInt(costString); + } catch (NumberFormatException e) { + cost = 0; + } + chosenAction.setAmount(cost); + } else { + chosenAction.setAmount(chosenAction.getAmount()); + } + + if (orWindow.process(chosenAction)) { + updateMessage(); + } + } + } + } + public void buyTrain() { *************** *** 1126,1129 **** --- 1188,1194 ---- orPanel.initPrivateBuying(privatesCanBeBoughtNow); + // sfy operating costs + orPanel.initOperatingCosts(possibleActions.contains(OperatingCost.class)); + //if (possibleActions.contains(LayTile.class)) { if (orStep == GameDef.OrStep.LAY_TRACK) { Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** ORPanel.java 4 Feb 2010 21:27:59 -0000 1.45 --- ORPanel.java 14 Feb 2010 20:48:21 -0000 1.46 *************** *** 23,26 **** --- 23,27 ---- private static final long serialVersionUID = 1L; + public static final String OPERATING_COST_CMD = "OperatingCost"; public static final String BUY_PRIVATE_CMD = "BuyPrivate"; public static final String BUY_TRAIN_CMD = "BuyTrain"; *************** *** 94,98 **** private Caption tileCaption, tokenCaption, revenueCaption, trainCaption, privatesCaption, loansCaption; ! private ActionButton button1; private ActionButton button2; --- 95,100 ---- private Caption tileCaption, tokenCaption, revenueCaption, trainCaption, privatesCaption, loansCaption; ! ! private ActionButton buttonOC; // sfy: button for operating costs private ActionButton button1; private ActionButton button2; *************** *** 127,130 **** --- 129,133 ---- round = gameUIManager.getCurrentRound(); + // noMapMode = gameUIManager.getGameParameterAsBoolean(GuiDef.Parm.NO_MAP_MODE); privatesCanBeBought = gameUIManager.getGameParameterAsBoolean(GuiDef.Parm.CAN_ANY_COMPANY_BUY_PRIVATES); bonusTokensExist = gameUIManager.getGameParameterAsBoolean(GuiDef.Parm.DO_BONUS_TOKENS_EXIST); *************** *** 224,227 **** --- 227,239 ---- buttonPanel = new JPanel(); + // sfy: operatingcosts button + buttonOC = new ActionButton(LocalText.getText("OCButtonLabel")); + buttonOC.setActionCommand(OPERATING_COST_CMD); + buttonOC.setMnemonic(KeyEvent.VK_O); + buttonOC.addActionListener(this); + buttonOC.setEnabled(false); + buttonOC.setVisible(false); + buttonPanel.add(buttonOC); + button1 = new ActionButton(LocalText.getText("LayTile")); button1.setActionCommand(LAY_TILE_CMD); *************** *** 563,566 **** --- 575,579 ---- public void finish() { + buttonOC.setEnabled(false); // operatingcosts sfy button1.setEnabled(false); button2.setEnabled(false); *************** *** 646,652 **** --- 659,668 ---- president[orCompIndex].setHighlight(true); + buttonOC.clearPossibleActions(); button1.clearPossibleActions(); button2.clearPossibleActions(); button3.clearPossibleActions(); + + buttonOC.setEnabled(false); button1.setEnabled(false); button2.setEnabled(false); *************** *** 681,685 **** button1.setVisible(true); } ! public void initPayoutStep(int orCompIndex, SetDividend action, boolean withhold, boolean split, boolean payout) { --- 697,701 ---- button1.setVisible(true); } ! public void initPayoutStep(int orCompIndex, SetDividend action, boolean withhold, boolean split, boolean payout) { *************** *** 739,742 **** --- 755,768 ---- } + // operating costs sfy + public void initOperatingCosts(boolean enabled) { + + buttonOC.setEnabled(enabled); + buttonOC.setVisible(enabled); + tileCaption.setHighlight(enabled); + tokenCaption.setHighlight(enabled); + } + + public void initPrivateBuying(boolean enabled) { |