|
From: <ste...@us...> - 2010-08-07 14:26:17
|
Revision: 1372
http://rails.svn.sourceforge.net/rails/?rev=1372&view=rev
Author: stefanfrey
Date: 2010-08-07 14:26:10 +0000 (Sat, 07 Aug 2010)
Log Message:
-----------
Fixed bug of wrong cgr train limit
Improved undo behavior of cgr formation
Added PresidentModel for UI reasons
Modified Paths:
--------------
trunk/18xx/LocalisedText.properties
trunk/18xx/rails/game/OperatingRound.java
trunk/18xx/rails/game/PublicCompany.java
trunk/18xx/rails/game/PublicCompanyI.java
trunk/18xx/rails/game/Round.java
trunk/18xx/rails/game/model/ShareModel.java
trunk/18xx/rails/game/move/MoveStack.java
trunk/18xx/rails/game/specific/_1856/CGRFormationRound.java
trunk/18xx/rails/ui/swing/GameUIManager.java
trunk/18xx/rails/ui/swing/ORPanel.java
trunk/18xx/rails/ui/swing/ORUIManager.java
trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java
Added Paths:
-----------
trunk/18xx/rails/game/model/PresidentModel.java
Modified: trunk/18xx/LocalisedText.properties
===================================================================
--- trunk/18xx/LocalisedText.properties 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/LocalisedText.properties 2010-08-07 14:26:10 UTC (rev 1372)
@@ -1,4 +1,5 @@
# Texts with lowercase keys are intended to be inserted into other messages
+1856MergerDialog=Repay loan decision of {0} for CGR merger
1856THBHomeBlocked=THB home hex is blocked for token lays (unless gray tile)
1889PrivateBactive=Player {0} (owner of Private B) may lay port tile
1889PrivateCactive=Player {0} (previous owner of Private C) may lay tile on C4 immediately
@@ -247,7 +248,7 @@
ExchangeTokensPrompt1=Select {0} cities where {1} will exchange a base token
ExchangeTokensPrompt2=Select {0} through {1} cities where {2} will exchange a base token
ExchangesTrain={0} exchanges a {1}-train for a {2}-train from {3} for {4}
-ExceedCertificateLimit=<em>{0} exceeds certificate limit!</em><br>{1}<br>Only share selling allowed until certificate limit holds.
+ExceedCertificateLimit=<em>{0} exceeds certificate limit!</em><br>{1}<br>Only share selling allowed until certificate limit holds again.
ExceedCertificateLimitTotal=-> Player has {0} certificates, exceeds total certificate limit of {1}.
ExceedCertificateLimitCompany=-> Player has a {1}% holding of {0}, exceeds company holding limit of {2}%.
extra=extra
Modified: trunk/18xx/rails/game/OperatingRound.java
===================================================================
--- trunk/18xx/rails/game/OperatingRound.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/OperatingRound.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -233,7 +233,7 @@
} else if (selectedAction instanceof ExchangeTokens) {
- result = exchangeTokens ((ExchangeTokens)selectedAction);
+ result = exchangeTokens ((ExchangeTokens)selectedAction, false); // 2nd parameter: unlinked moveset
} else if (selectedAction instanceof ClosePrivate) {
Modified: trunk/18xx/rails/game/PublicCompany.java
===================================================================
--- trunk/18xx/rails/game/PublicCompany.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/PublicCompany.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -93,6 +93,9 @@
/** Company treasury, holding cash */
protected CashModel treasury = null;
+
+ /** PresidentModel */
+ protected PresidentModel presidentModel = null;
/** Has the company started? */
protected BooleanState hasStarted = null;
@@ -620,6 +623,7 @@
lastRevenue.setOption(MoneyModel.SUPPRESS_INITIAL_ZERO);
lastRevenueAllocation = new StringState(name + "_lastAllocation");
baseTokensModel = new BaseTokensModel(this);
+ presidentModel = new PresidentModel(this);
hasStarted = new BooleanState(name + "_hasStarted", false);
hasFloated = new BooleanState(name + "_hasFloated", false);
@@ -1241,6 +1245,10 @@
return null;
}
+ public PresidentModel getPresidentModel() {
+ return presidentModel;
+ }
+
public PublicCertificateI getPresidentsShare () {
return certificates.get(0);
}
@@ -1982,4 +1990,5 @@
public String getExtraShareMarks () {
return "";
}
+
}
Modified: trunk/18xx/rails/game/PublicCompanyI.java
===================================================================
--- trunk/18xx/rails/game/PublicCompanyI.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/PublicCompanyI.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -209,6 +209,8 @@
public Player getPresident();
+ public PresidentModel getPresidentModel();
+
public PublicCertificateI getPresidentsShare();
public int getFloatPercentage();
@@ -355,6 +357,7 @@
public ModelObject getInGameModel ();
public ModelObject getIsClosedModel ();
+
}
Modified: trunk/18xx/rails/game/Round.java
===================================================================
--- trunk/18xx/rails/game/Round.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/Round.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -167,7 +167,7 @@
return true;
}
- protected boolean exchangeTokens (ExchangeTokens action) {
+ protected boolean exchangeTokens(ExchangeTokens action, boolean linkedMoveSet) {
String errMsg = null;
@@ -199,6 +199,7 @@
}
moveStack.start(true);
+ if (linkedMoveSet) moveStack.linkToPreviousMoveSet();
if (exchanged > 0) {
MapHex hex;
Added: trunk/18xx/rails/game/model/PresidentModel.java
===================================================================
--- trunk/18xx/rails/game/model/PresidentModel.java (rev 0)
+++ trunk/18xx/rails/game/model/PresidentModel.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -0,0 +1,34 @@
+package rails.game.model;
+
+import java.util.Observable;
+import java.util.Observer;
+
+import rails.game.Player;
+import rails.game.PublicCompanyI;
+
+/**
+ * model object for the current company president
+ * gets registered by the ShareModels
+ */
+
+public class PresidentModel extends ModelObject implements Observer {
+
+ PublicCompanyI company;
+
+ public PresidentModel(PublicCompanyI company) {
+ this.company = company;
+ }
+
+ public void update(Observable o, Object arg) {
+ // if notified by ShareModels, calls update itself
+ update();
+ }
+
+ @Override
+ public String getText() {
+ Player president = company.getPresident();
+ if (president == null ) return "";
+ else return company.getPresident().getNameAndPriority();
+ }
+
+}
Property changes on: trunk/18xx/rails/game/model/PresidentModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/18xx/rails/game/model/ShareModel.java
===================================================================
--- trunk/18xx/rails/game/model/ShareModel.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/model/ShareModel.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -13,6 +13,8 @@
this.portfolio = portfolio;
this.company = company;
this.share = 0;
+ // add companies president model as observer
+ this.addObserver(company.getPresidentModel());
}
public void setShare() {
Modified: trunk/18xx/rails/game/move/MoveStack.java
===================================================================
--- trunk/18xx/rails/game/move/MoveStack.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/move/MoveStack.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -128,8 +128,14 @@
public boolean redoMoveSet () {
if (currentMoveSet == null && lastIndex < moveStack.size() - 1) {
- ReportBuffer.add(LocalText.getText("REDO"));
- (moveStack.get(++lastIndex)).reexecute();
+ MoveSet redoAction;
+ redoAction= moveStack.get(++lastIndex);
+ do {
+ ReportBuffer.add(LocalText.getText("REDO"));
+ redoAction.reexecute();
+ if (lastIndex == moveStack.size() - 1) break;
+ redoAction= moveStack.get(++lastIndex);
+ } while (redoAction.isLinkedToPreviousMove());
// log.debug ("MoveStack redo index is "+lastIndex);
return true;
} else {
Modified: trunk/18xx/rails/game/specific/_1856/CGRFormationRound.java
===================================================================
--- trunk/18xx/rails/game/specific/_1856/CGRFormationRound.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/game/specific/_1856/CGRFormationRound.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -15,13 +15,23 @@
public class CGRFormationRound extends SwitchableUIRound {
private Player startingPlayer;
+ private int maxLoansToRepayByPresident = 0;
private Map<Player, List<PublicCompanyI>> companiesToRepayLoans = null;
+
private PublicCompanyI currentCompany = null;
- private int maxLoansToRepayByPresident = 0;
private List<PublicCompanyI> mergingCompanies = new ArrayList<PublicCompanyI>();
+
+ /*
+ * pointers to cgr company
+ */
private String cgrName = PublicCompany_CGR.NAME;
private PublicCompany_CGR cgr
= (PublicCompany_CGR)gameManager.getCompanyManager().getPublicCompany(cgrName);
+
+ /*
+ * effects from the merger, processed at the end
+ * thus no need for state variables
+ */
private List<TrainI> trainsToDiscardFrom = null;
private boolean forcedTrainDiscard = true;
private List<ExchangeableToken> tokensToExchangeFrom = null;
@@ -187,14 +197,14 @@
numberOfLoans,
currentCompany.getName()),
false);
- currentCompany.getLoanValueModel().setText(LocalText.getText("MERGE"));
+// currentCompany.getLoanValueModel().setText(LocalText.getText("MERGE"));
}
maxLoansToRepayByPresident = maxNumber;
break;
} else {
// President cannot help, this company will merge into CGR anyway
mergingCompanies.add(currentCompany);
- currentCompany.getLoanValueModel().setText(LocalText.getText("MERGE"));
+// currentCompany.getLoanValueModel().setText(LocalText.getText("MERGE"));
message = LocalText.getText("WillMergeInto",
currentCompany.getName(),
PublicCompany_CGR.NAME);
@@ -237,7 +247,7 @@
// TODO Validation skipped for now...
- moveStack.start(true);
+ moveStack.start(true).linkToPreviousMoveSet();
PublicCompanyI company = action.getCompany();
int numberRepaid = action.getNumberRepaid();
@@ -273,7 +283,7 @@
if (action.getCompany().getCurrentNumberOfLoans() > 0) {
mergingCompanies.add(currentCompany);
- currentCompany.getLoanValueModel().setText(LocalText.getText("MERGE"));
+// currentCompany.getLoanValueModel().setText(LocalText.getText("MERGE"));
String message = LocalText.getText("WillMergeInto",
currentCompany.getName(),
PublicCompany_CGR.NAME);
@@ -633,7 +643,7 @@
key, oldTokens.get(key)));
}
} else {
- executeExchangeTokens (nonHomeTokens);
+ executeExchangeTokens(nonHomeTokens);
}
// Close the merged companies
@@ -692,7 +702,7 @@
} else if (action instanceof DiscardTrain) {
result = discardTrain((DiscardTrain)action);
} else if (action instanceof ExchangeTokens) {
- result = exchangeTokens ((ExchangeTokens)action);
+ result = exchangeTokens((ExchangeTokens)action, true); // 2nd parameter: linked moveset
}
if (!result) return false;
@@ -812,7 +822,8 @@
}
/* End of validation, start of execution */
- moveStack.start(true);
+ // new: link always, see below commented
+ moveStack.start(true).linkToPreviousMoveSet();
if (train != null) {
@@ -825,8 +836,6 @@
} else {
cgrHasDiscardedTrains.set(true);
}
- // new: link always, see above uncommented
- moveStack.linkToPreviousMoveSet();
return true;
}
Modified: trunk/18xx/rails/ui/swing/GameUIManager.java
===================================================================
--- trunk/18xx/rails/ui/swing/GameUIManager.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/ui/swing/GameUIManager.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -305,6 +305,9 @@
/* Finish previous round UI processing */
if (previousRoundType != null) {
+ /* close current dialog */
+ setCurrentDialog(null, null);
+
if (StockRound.class.isAssignableFrom(previousRoundType)) {
log.debug("UI leaving Stock Round "+previousRoundName);
statusWindow.finishRound();
Modified: trunk/18xx/rails/ui/swing/ORPanel.java
===================================================================
--- trunk/18xx/rails/ui/swing/ORPanel.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/ui/swing/ORPanel.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -407,8 +407,9 @@
f =
president[i] =
- new Field(c.hasStarted() && !c.isClosed()
- ? c.getPresident().getNameAndPriority() : "");
+// new Field(c.hasStarted() && !c.isClosed()
+// ? c.getPresident().getNameAndPriority() : "");
+ new Field(c.getPresidentModel());
addField(f, presidentXOffset, presidentYOffset + i, 1, 1, 0, visible);
f = sharePrice[i] = new Field(c.getCurrentPriceModel());
@@ -468,7 +469,8 @@
addField(f, revXOffset, revYOffset + i, 1, 1, 0, visible);
f = revenueSelect[i] = new Spinner(0, 0, 0, 10);
addField(f, revXOffset, revYOffset + i, 1, 1, 0, false);
- revenue[i].addDependent(revenueSelect[i]);
+ // deactived below, as this caused problems by gridpanel rowvisibility function -- sfy
+ // revenue[i].addDependent(revenueSelect[i]);
f = decision[i] = new Field(c.getLastRevenueAllocationModel());
addField(f, revXOffset + 1, revYOffset + i, 1, 1, WIDE_RIGHT, visible);
@@ -749,6 +751,10 @@
president[i].setHighlight(false);
}
+ if (hasCompanyLoans) {
+ loansCaption.setHighlight(false);
+ }
+
for (JMenuItem item : menuItemsToReset) {
item.setEnabled(false);
if (item instanceof ActionMenuItem) {
@@ -764,6 +770,11 @@
}
}
+ public void resetCurrentRevenueDisplay() {
+ setSelect(revenue[orCompIndex], revenueSelect[orCompIndex], false);
+ }
+
+
public void initORCompanyTurn(PublicCompanyI orComp, int orCompIndex) {
this.orComp = orComp;
Modified: trunk/18xx/rails/ui/swing/ORUIManager.java
===================================================================
--- trunk/18xx/rails/ui/swing/ORUIManager.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/ui/swing/ORUIManager.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -619,6 +619,12 @@
orWindow.process(mapCorrectionAction);
}
} else if (tokenLayingEnabled) {
+ // if clickedHex == null, then go back to select hex step
+ if (clickedHex == null) {
+ upgradePanel.setPossibleTokenLays(null);
+ setLocalStep(SELECT_HEX_FOR_TOKEN);
+ return;
+ }
List<LayToken> allowances =
map.getTokenAllowanceForHex(clickedHex.getHexModel());
if (allowances.size() > 0) {
@@ -640,16 +646,18 @@
&& clickedHex == selectedHex) {
selectedHex.rotateTile();
map.repaint(selectedHex.getBounds());
-
return;
} else {
-
if (selectedHex != null && clickedHex != selectedHex) {
selectedHex.removeTile();
map.selectHex(null);
}
- if (clickedHex != null) {
+ // if clickedHex == null, then go back to select hex step
+ if (clickedHex == null) {
+ upgradePanel.setTileUpgrades(null);
+ setLocalStep(SELECT_HEX_FOR_TILE);
+ } else {
if (clickedHex.getHexModel().isUpgradeableNow())
/*
* Direct call to Model to be replaced later by use of
@@ -1443,6 +1451,7 @@
// initial deactivation of revenue calculation
if (!possibleActions.contains(SetDividend.class)) {
orPanel.stopRevenueUpdate();
+ orPanel.resetCurrentRevenueDisplay();
}
if (possibleActions.contains(MapCorrectionAction.class)) {
Modified: trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java
===================================================================
--- trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java 2010-08-07 14:24:24 UTC (rev 1371)
+++ trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java 2010-08-07 14:26:10 UTC (rev 1372)
@@ -1,5 +1,8 @@
package rails.ui.swing.gamespecific._1856;
+import javax.swing.JDialog;
+import javax.swing.WindowConstants;
+
import rails.game.*;
import rails.game.action.*;
import rails.game.specific._1856.CGRFormationRound;
@@ -19,7 +22,6 @@
@Override
public void updateStatus() {
RoundI currentRound = gameUIManager.getCurrentRound();
- //if (!(currentRound instanceof OperatingRound)) {
if (!(currentRound instanceof CGRFormationRound)) {
super.updateStatus();
} else if (possibleActions.contains(RepayLoans.class)) {
@@ -97,10 +99,11 @@
}
RadioButtonDialog currentDialog = new RadioButtonDialog (gameUIManager,
- LocalText.getText("Select"),
+ LocalText.getText("1856MergerDialog", action.getCompanyName()),
message,
options,
0);
+ currentDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
gameUIManager.setCurrentDialog (currentDialog, action);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|