From: Erik V. <ev...@us...> - 2010-01-11 23:07:03
|
Update of /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_18EU In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv20271/rails/ui/swing/gamespecific/_18EU Modified Files: GameStatus_18EU.java Added Files: GameUIManager_18EU.java Log Message: More dialogs made modal Index: GameStatus_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GameStatus_18EU.java 11 Sep 2009 19:26:44 -0000 1.8 --- GameStatus_18EU.java 11 Jan 2010 23:06:18 -0000 1.9 *************** *** 4,9 **** import java.util.List; - import javax.swing.JOptionPane; - import rails.game.City; import rails.game.PublicCompanyI; --- 4,7 ---- *************** *** 73,103 **** } } - int choice = - new RadioButtonDialog(this, - LocalText.getText("PleaseSelect"), - LocalText.getText("SelectCompanyToMergeMinorInto", - minor.getName()), options, -1) // - .getSelectedOption(); - if (choice < 0) return null; - - PublicCompanyI major = targets.get(choice); - action.setSelectedTargetCompany(major); - - if (major != null - && action.canReplaceToken(choice)) { - boolean replaceToken = - JOptionPane.showConfirmDialog(this, LocalText.getText( - "WantToReplaceToken", - minor.getName(), - major.getName() ), - LocalText.getText("PleaseSelect"), - JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; - action.setReplaceToken(replaceToken); - } else { - return chosenAction; - } } ! return chosenAction; } --- 71,83 ---- } } + RadioButtonDialog dialog = new RadioButtonDialog (gameUIManager, + LocalText.getText("PleaseSelect"), + LocalText.getText("SelectCompanyToMergeMinorInto", + minor.getName()), + options, -1); + gameUIManager.setCurrentDialog(dialog, action); } ! return null; } *************** *** 113,137 **** ((StartCompany_18EU) chosenAction).getMinorsToMerge(); ! if (minors == null || minors.isEmpty()) { ! // Do nothing ! } else if (minors.size() == 1) { ! PublicCompanyI minor = minors.get(0); ! int answer = ! JOptionPane.showConfirmDialog( ! parent, ! LocalText.getText( ! "MergeMinorConfirm", ! minor.getName(), ! action.getCertificate().getCompany().getName() ), ! LocalText.getText("PleaseConfirm"), ! JOptionPane.OK_CANCEL_OPTION, ! JOptionPane.QUESTION_MESSAGE); ! if (answer == JOptionPane.OK_OPTION) { ! action.setChosenMinor(minor); ! chosenAction = action; ! } else { ! chosenAction = null; ! } ! } else { String[] options = new String[minors.size()]; int i = 0; --- 93,98 ---- ((StartCompany_18EU) chosenAction).getMinorsToMerge(); ! if (minors != null && !minors.isEmpty()) { ! // Up to phase 6, a minor must be exchanged String[] options = new String[minors.size()]; int i = 0; *************** *** 141,179 **** + minor.getLongName(); } ! int choice = ! new RadioButtonDialog( ! this, // ! LocalText.getText("PleaseSelect"), // ! LocalText.getText( ! "SelectMinorToMerge", ! action.getCertificate().getCompany().getName()), ! options, -1).getSelectedOption(); ! if (choice >= 0) { ! action.setChosenMinor(minors.get(choice)); ! chosenAction = action; ! } else { ! chosenAction = null; ! } ! } ! List<City> 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(); ! } ! int index = ! new RadioButtonDialog( ! this, // ! LocalText.getText("PleaseSelect"), // ! LocalText.getText( ! "SelectHomeStation", // ! action.getCertificate().getCompany().getName()), ! options, -1).getSelectedOption(); ! if (index >= 0) { ! action.setHomeStation(cities.get(index)); ! } else { ! return null; ! } } } --- 102,132 ---- + minor.getLongName(); } ! RadioButtonDialog dialog = new RadioButtonDialog (gameUIManager, ! LocalText.getText("PleaseSelect"), ! LocalText.getText( ! "SelectMinorToMerge", ! action.getCertificate().getCompany().getName()), ! options, -1); ! gameUIManager.setCurrentDialog(dialog, action); ! return null; ! } else { ! // From phase 6, no minors are involved, but a home station must be chosen ! List<City> 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(); ! } ! RadioButtonDialog dialog = new RadioButtonDialog (gameUIManager, ! LocalText.getText("PleaseSelect"), ! LocalText.getText( ! "SelectMinorToMerge", ! action.getCertificate().getCompany().getName()), ! options, -1); ! gameUIManager.setCurrentDialog(dialog, action); ! return null; ! ! } } } --- NEW FILE: GameUIManager_18EU.java --- package rails.ui.swing.gamespecific._18EU; import javax.swing.JOptionPane; import rails.game.PublicCompanyI; import rails.game.action.MergeCompanies; import rails.game.specific._18EU.StartCompany_18EU; import rails.ui.swing.GameUIManager; import rails.ui.swing.elements.RadioButtonDialog; import rails.util.LocalText; public class GameUIManager_18EU extends GameUIManager { @Override public void dialogActionPerformed () { if (currentDialog instanceof RadioButtonDialog && currentDialogAction instanceof MergeCompanies) { 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; PublicCompanyI major = action.getTargetCompanies().get(choice); action.setSelectedTargetCompany(major); 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); } } else { // To be added later when ReplaceToken dialog is modeless } } else if (currentDialog instanceof RadioButtonDialog && currentDialogAction instanceof StartCompany_18EU) { RadioButtonDialog dialog = (RadioButtonDialog) currentDialog; StartCompany_18EU action = (StartCompany_18EU) currentDialogAction; if (action.getMinorsToMerge() != null) { // Up to phase 5: a minor to merge has been selected (or not) int choice = dialog.getSelectedOption(); if (choice >= 0) { action.setChosenMinor(action.getMinorsToMerge().get(choice)); } else { return; } } else if (action.getAvailableHomeStations() != null) { // From phase 6: a home station has been selected (or not) int index = dialog.getSelectedOption(); if (index >= 0) { action.setHomeStation(action.getAvailableHomeStations().get(index)); } else { return; } } } else { super.dialogActionPerformed(false); } super.dialogActionPerformed(true); } } |