From: Stefan F. <ste...@us...> - 2010-03-03 00:46:00
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv3705/rails/ui/swing Modified Files: GameStatus.java StatusWindow.java GameUIManager.java Log Message: Added CorrectionMode - first part Cash Correction Index: StatusWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/StatusWindow.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** StatusWindow.java 31 Jan 2010 22:22:34 -0000 1.37 --- StatusWindow.java 3 Mar 2010 00:44:38 -0000 1.38 *************** *** 15,20 **** --- 15,22 ---- import rails.game.*; import rails.game.action.*; + import rails.game.correct.*; import rails.ui.swing.elements.ActionButton; import rails.ui.swing.elements.ActionMenuItem; + import rails.ui.swing.elements.ActionCheckBoxMenuItem; import rails.util.Config; import rails.util.LocalText; *************** *** 72,76 **** private static JMenu fileMenu, optMenu, moveMenu, moderatorMenu, ! specialMenu; private JMenuItem menuItem; --- 74,78 ---- private static JMenu fileMenu, optMenu, moveMenu, moderatorMenu, ! specialMenu, correctionMenu; private JMenuItem menuItem; *************** *** 193,196 **** --- 195,204 ---- moderatorMenu.add(redoItem2); + correctionMenu = new JMenu(LocalText.getText("CorrectionMainMenu")); + correctionMenu.setName(LocalText.getText("CorrectionMainMenu")); + correctionMenu.setMnemonic(KeyEvent.VK_C); + correctionMenu.setEnabled(false); + moderatorMenu.add(correctionMenu); + menuBar.add(moderatorMenu); *************** *** 313,317 **** --- 321,347 ---- } } + + public void setCorrectionMenu() { + // Update the menu + correctionMenu.removeAll(); + correctionMenu.setEnabled(false); + + List<CorrectionModeAction> corrections = + possibleActions.getType(CorrectionModeAction.class); + if (corrections != null) { + for (CorrectionModeAction a : corrections) { + ActionCheckBoxMenuItem item = new ActionCheckBoxMenuItem ( + LocalText.getText(a.getCorrectionName())); + item.addActionListener(this); + item.addPossibleAction(a); + item.setEnabled(true); + item.setSelected(a.isActive()); + correctionMenu.add(item); + } + correctionMenu.setEnabled(true); + } + } + public void setupFor(RoundI round) { *************** *** 331,334 **** --- 361,368 ---- public void updateStatus() { + + // correction actions always possible + gameStatus.initCashCorrectionActions(); + if (!(currentRound instanceof StockRound)) { return; Index: GameStatus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameStatus.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** GameStatus.java 9 Feb 2010 20:03:24 -0000 1.39 --- GameStatus.java 3 Mar 2010 00:44:33 -0000 1.40 *************** *** 14,17 **** --- 14,18 ---- import rails.game.*; import rails.game.action.*; + import rails.game.correct.CashCorrectionAction; import rails.ui.swing.elements.*; import rails.util.LocalText; *************** *** 27,30 **** --- 28,32 ---- private static final String BUY_FROM_POOL_CMD = "BuyFromPool"; private static final String SELL_CMD = "Sell"; + private static final String CASH_CORRECT_CMD = "CorrectCash"; protected StatusWindow parent; *************** *** 48,51 **** --- 50,54 ---- protected int currPriceXOffset, currPriceYOffset; protected Field compCash[]; + protected ClickField compCashButton[]; protected int compCashXOffset, compCashYOffset; protected Field compRevenue[]; *************** *** 60,63 **** --- 63,67 ---- protected int compLoansXOffset, compLoansYOffset; protected Field playerCash[]; + protected ClickField playerCashButton[]; protected int playerCashXOffset, playerCashYOffset; protected Field playerPrivates[]; *************** *** 159,162 **** --- 163,167 ---- currPrice = new Field[nc]; compCash = new Field[nc]; + compCashButton = new ClickField[nc]; compRevenue = new Field[nc]; compTrains = new Field[nc]; *************** *** 166,169 **** --- 171,175 ---- playerCash = new Field[np]; + playerCashButton = new ClickField[np]; playerPrivates = new Field[np]; playerWorth = new Field[np]; *************** *** 371,374 **** --- 377,389 ---- f = compCash[i] = new Field(c.getCashModel()); addField(f, compCashXOffset, compCashYOffset + i, 1, 1, 0, visible); + f = + compCashButton[i] = + new ClickField( + compCash[i].getText(), + CASH_CORRECT_CMD, + LocalText.getText("CorrectCashToolTip"), + this, buySellGroup); + addField(f, compCashXOffset, compCashYOffset + i, 1, 1, + WIDE_RIGHT, false); f = compRevenue[i] = new Field(c.getLastRevenueModel()); *************** *** 412,419 **** addField(f, playerCashXOffset + i, playerCashYOffset, 1, 1, WIDE_TOP, true); } addField(new Caption("Privates"), 0, playerPrivatesYOffset, 1, 1, ! WIDE_RIGHT, true); for (int i = 0; i < np; i++) { f = --- 427,443 ---- addField(f, playerCashXOffset + i, playerCashYOffset, 1, 1, WIDE_TOP, true); + f = + playerCashButton[i] = + new ClickField( + playerCash[i].getText(), + CASH_CORRECT_CMD, + LocalText.getText("CorrectCashToolTip"), + this, buySellGroup); + addField(f, playerCashXOffset + i, playerCashYOffset, 1, 1, + WIDE_TOP, false); } addField(new Caption("Privates"), 0, playerPrivatesYOffset, 1, 1, ! WIDE_RIGHT, false); for (int i = 0; i < np; i++) { f = *************** *** 648,652 **** index = options.indexOf(sp); } ! } else if (options.size() == 1) { int result = JOptionPane.showConfirmDialog(this, options.get(0), --- 672,676 ---- index = options.indexOf(sp); } ! } else if (options.size() == 1) { int result = JOptionPane.showConfirmDialog(this, options.get(0), *************** *** 666,671 **** ((BuyCertificate) chosenAction).setNumberBought(buyAmounts.get(index)); } ! } else { ! chosenAction = processGameSpecificActions(actor, actions.get(0)); --- 690,708 ---- ((BuyCertificate) chosenAction).setNumberBought(buyAmounts.get(index)); } ! } else if (actions.get(0) instanceof CashCorrectionAction) { ! CashCorrectionAction cca = (CashCorrectionAction)actions.get(0); ! String amountString = (String) JOptionPane.showInputDialog(this, ! LocalText.getText("CorrectCashDialogMessage", cca.getCashHolderName()), ! LocalText.getText("CorrectCashDialogTitle"), ! JOptionPane.QUESTION_MESSAGE, null, null, 0); ! int amount; ! try { ! amount = Integer.parseInt(amountString); ! } catch (NumberFormatException e) { ! amount = 0; ! } ! cca.setAmount(amount); ! chosenAction = cca; ! } else { chosenAction = processGameSpecificActions(actor, actions.get(0)); *************** *** 785,788 **** --- 822,859 ---- } + /** + * Initializes the CashCorrectionActions + */ + public void initCashCorrectionActions() { + + // Clear all buttons + for (int i = 0; i < nc; i++) { + setCompanyCashButton(i, false, null); + } + for (int j = 0; j < np; j++) { + setPlayerCashButton(j, false, null); + } + + List<CashCorrectionAction> actions = + possibleActions.getType(CashCorrectionAction.class); + + if (actions != null) { + for (CashCorrectionAction a : actions) { + CashHolder ch = a.getCashHolder(); + if (ch instanceof PublicCompanyI) { + PublicCompanyI pc = (PublicCompanyI)ch; + int i = pc.getPublicNumber(); + setCompanyCashButton(i, true, a); + } + if (ch instanceof Player) { + Player p = (Player)ch; + int i = playerIndex.get(p); + setPlayerCashButton(i, true, a); + } + } + } + + } + public void setPriorityPlayer(int index) { *************** *** 882,885 **** --- 953,984 ---- certInTreasuryButton[i].setVisible(clickable); } + + private void setCompanyCashButton(int i, boolean clickable, PossibleAction action){ + boolean visible = rowVisibilityObservers[i].lastValue(); + + if (clickable) { + compCashButton[i].setText(compCash[i].getText()); + } else { + compCashButton[i].clearPossibleActions(); + } + compCash[i].setVisible(visible && !clickable); + compCashButton[i].setVisible(visible && clickable); + + if (action != null) + compCashButton[i].addPossibleAction(action); + } + private void setPlayerCashButton(int i, boolean clickable, PossibleAction action){ + + if (clickable) { + playerCashButton[i].setText(playerCash[i].getText()); + } else { + playerCashButton[i].clearPossibleActions(); + } + playerCash[i].setVisible(!clickable); + playerCashButton[i].setVisible(clickable); + + if (action != null) + playerCashButton[i].addPossibleAction(action); + } } Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** GameUIManager.java 28 Feb 2010 21:38:04 -0000 1.40 --- GameUIManager.java 3 Mar 2010 00:44:50 -0000 1.41 *************** *** 196,199 **** --- 196,200 ---- statusWindow.setGameActions(); + statusWindow.setCorrectionMenu(); // Is this perhaps the right place to display messages...? |