|
From: Stefan F. <ste...@us...> - 2012-01-02 18:42:02
|
LocalisedText.properties | 2 ++
rails/ui/swing/ORPanel.java | 39 ++++++++++++++++++++++++++++++++++++---
2 files changed, 38 insertions(+), 3 deletions(-)
New commits:
commit 39ac84492244350708aa503a7c23c81997e2955f
Author: Frederick Weld <fre...@gm...>
Date: Fri Dec 30 21:19:13 2011 +0100
Added user-friendly network info including keyboard shortcut
Provided for a non-developer version of the network info menu.
Differences to the developer-only version (available before):
- omitting the menu item for the complete network graph
- providing a localized dialog text for the dialog
- omitting train run information and train simulation
Applied further extensions to network info menu (also valid for
the developer-only version):
- Keyboard shortcut (Ctrl+N) dynamically assigned to the network info
menu item of the currently operating company
- Network info run visualization takes care of potential conflicts
with the visualization of the set revenue step
- Network info run visualization is turned off after the dialog
Provided functionality covers the use case described in feature
request 3064835.
Signed-off-by: Stefan Frey <ste...@we...>
diff --git a/LocalisedText.properties b/LocalisedText.properties
index 26b182e..a3fdd12 100644
--- a/LocalisedText.properties
+++ b/LocalisedText.properties
@@ -400,6 +400,8 @@ MustWithholdUntilPermanent={0} must withhold revenue until it owns a permanent t
NamesTrain={0} names {1}-train as {2}
NegativeAmountNotAllowed=Negative amount {0} not allowed
NetworkInfo=Network Info
+NetworkInfoDialogTitle=Network Info for Company {0}
+NetworkInfoDialogMessage={0} could run for a revenue of {1}
NEW=New
NewGame=New Game
NextPlayerMessage=Message(s) from previous player''s ({0}) turn:
diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java
index ffcb997..e88b788 100644
--- a/rails/ui/swing/ORPanel.java
+++ b/rails/ui/swing/ORPanel.java
@@ -611,7 +611,7 @@ implements ActionListener, KeyListener, RevenueListener {
if (networkInfoMenu != null) infoMenu.remove(networkInfoMenu);
networkInfoMenu = createNetworkInfo();
if (networkInfoMenu == null) return;
- networkInfoMenu.setEnabled(Game.getDevelop());
+ networkInfoMenu.setEnabled(true);
infoMenu.add(networkInfoMenu);
}
@@ -624,7 +624,8 @@ implements ActionListener, KeyListener, RevenueListener {
JMenu networkMenu = new JMenu(LocalText.getText("NetworkInfo"));
- if (route_highlight) {
+ //network graphs only for developers
+ if (route_highlight && Game.getDevelop()) {
JMenuItem item = new JMenuItem("Network");
item.addActionListener(this);
item.setActionCommand(NETWORK_INFO_CMD);
@@ -683,6 +684,17 @@ implements ActionListener, KeyListener, RevenueListener {
log.debug("Revenue Run:" + ra.getOptimalRunPrettyPrint(true));
ra.drawOptimalRunAsPath(orUIManager.getMap());
orUIManager.getMap().repaint();
+
+ if (!Game.getDevelop()) {
+ //parent component is ORPanel so that dialog won't hide the routes painted on the map
+ JOptionPane.showMessageDialog(this,
+ LocalText.getText("NetworkInfoDialogMessage",company.getName(),Bank.format(revenueValue)) ,
+ LocalText.getText("NetworkInfoDialogTitle",company.getName()),
+ JOptionPane.INFORMATION_MESSAGE);
+ //train simulation only for developers
+ break;
+ }
+
JOptionPane.showMessageDialog(orWindow, "RevenueValue = " + revenueValue +
"\nRevenueRun = \n" + ra.getOptimalRunPrettyPrint(true));
@@ -697,7 +709,11 @@ implements ActionListener, KeyListener, RevenueListener {
}
}
- revenueAdapter = ra;
+ //clean up the paths on the map
+ orUIManager.getMap().setTrainPaths(null);
+ //but retain paths already existing before
+ if (revenueAdapter != null) revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap());
+ orUIManager.getMap().repaint();
}
}
@@ -842,6 +858,21 @@ implements ActionListener, KeyListener, RevenueListener {
setSelect(revenue[orCompIndex], revenueSelect[orCompIndex], false);
}
+ /**
+ * Sets the keyboard shortcut (CTRL+N) for displaying routes of the given company
+ */
+ private void setKeyboardShortcutForNetwork(PublicCompanyI orComp) {
+ if (networkInfoMenu == null) return;
+ for (int i=0 ; i<networkInfoMenu.getItemCount(); i++) {
+ JMenuItem item = networkInfoMenu.getItem(i);
+ if (item.getAccelerator() != null) item.setAccelerator(null);
+ if (item.getText().equals(orComp.getName())) {
+ item.setAccelerator(KeyStroke.getKeyStroke(
+ KeyEvent.VK_N , ActionEvent.CTRL_MASK ));
+ }
+ }
+
+ }
public void initORCompanyTurn(PublicCompanyI orComp, int orCompIndex) {
@@ -858,6 +889,8 @@ implements ActionListener, KeyListener, RevenueListener {
button1.setEnabled(false);
button2.setEnabled(false);
button3.setEnabled(false);
+
+ setKeyboardShortcutForNetwork(orComp);
}
public void initTileLayingStep() {
|
|
From: Erik V. <ev...@us...> - 2012-02-23 14:37:48
|
LocalisedText.properties | 1
rails/ui/swing/GameUIManager.java | 48 ++++++++++++++++++++++++++++++--------
rails/ui/swing/GridPanel.java | 32 +++++++++++++++++++++++++
rails/ui/swing/StatusWindow.java | 18 ++++++++++++--
4 files changed, 87 insertions(+), 12 deletions(-)
New commits:
commit 2f42c466d42059702851c5fc5130a732ccfd73c3
Author: Erik Vos <eri...@xs...>
Date: Thu Feb 23 15:37:14 2012 +0100
Added StatusWindow File menu action to dump the (transposed) contents
of the GameStatus panel
into a semicolon-separated text file with ".status" extension.
Any tooltips (with additional info) are included between braces.
diff --git a/LocalisedText.properties b/LocalisedText.properties
index ac4899b..ce07410 100644
--- a/LocalisedText.properties
+++ b/LocalisedText.properties
@@ -616,6 +616,7 @@ SAVE_AND_APPLY=Save/Apply
SAVEAS=Save As ...
SaveDialogTitle=Save Game. Info: Report of current players action copied to Clipboard.
SaveFailed=Save failed, reason: {0}
+SaveGameStatus=Save game status
Select=Select
SelectCompanyToMergeMinorInto=Select major company to merge minor {0} into
SelectLoansToRepay=Select number of loans of {0} to repay
diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java
index 7e59194..1c25557 100644
--- a/rails/ui/swing/GameUIManager.java
+++ b/rails/ui/swing/GameUIManager.java
@@ -1,13 +1,12 @@
package rails.ui.swing;
-import java.awt.Font;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
+import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.List;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
@@ -100,7 +99,7 @@ public class GameUIManager implements DialogOwner {
Logger.getLogger(GameUIManager.class.getPackage().getName());
private SplashWindow splashWindow = null;
-
+
public GameUIManager() {
}
@@ -109,7 +108,7 @@ public class GameUIManager implements DialogOwner {
this.splashWindow = splashWindow;
splashWindow.notifyOfStep(SplashWindow.STEP_INIT_UI);
-
+
instance = this;
this.gameManager = gameManager;
uiHints = gameManager.getUIHints();
@@ -207,7 +206,7 @@ public class GameUIManager implements DialogOwner {
} else {
reportWindow = new ReportWindowDynamic(this);
}
-
+
orWindow = new ORWindow(this, splashWindow);
orUIManager = orWindow.getORUIManager();
@@ -250,7 +249,7 @@ public class GameUIManager implements DialogOwner {
public void startLoadedGame() {
gameUIInit(false); // false indicates reload
-
+
splashWindow.notifyOfStep(SplashWindow.STEP_INIT_LOADED_GAME);
processAction(new NullAction(NullAction.START_GAME));
statusWindow.setGameActions();
@@ -1019,6 +1018,34 @@ public class GameUIManager implements DialogOwner {
}
+ public void saveGameStatus() {
+
+ List<String> status = statusWindow.getGameStatus().getTextContents();
+
+ JFileChooser jfc = new JFileChooser();
+ String filename = saveDirectory + "/" + savePrefix + "_"
+ + saveDateTimeFormat.format(new Date())+ ".status";
+
+ File proposedFile = new File(filename);
+ jfc.setSelectedFile(proposedFile);
+
+ if (jfc.showSaveDialog(statusWindow) == JFileChooser.APPROVE_OPTION) {
+ File selectedFile = jfc.getSelectedFile();
+ }
+
+ try {
+ PrintWriter pw = new PrintWriter(filename);
+
+ for (String line : status) pw.println(line) ;
+
+ pw.close();
+
+ } catch (IOException e) {
+ log.error("Save failed", e);
+ DisplayBuffer.add(LocalText.getText("SaveFailed", e.getMessage()));
+ }
+ }
+
public void setSaveDirectory(String saveDirectory) {
this.saveDirectory = saveDirectory;
}
@@ -1131,7 +1158,7 @@ public class GameUIManager implements DialogOwner {
instance.initFontSettings();
instance.updateWindowsLookAndFeel();
}
-
+
/**
* Only set frame directly to visible if the splash phase is already over.
* Otherwise, the splash framework remembers this visibility request and
@@ -1159,7 +1186,7 @@ public class GameUIManager implements DialogOwner {
}
/**
- * called when the splash process is completed
+ * called when the splash process is completed
* (and visibility changes are not to be deferred any more)
*/
public void notifyOfSplashFinalization() {
@@ -1174,9 +1201,10 @@ public class GameUIManager implements DialogOwner {
public void packAndApplySizing(JFrame frame) {
final JFrame finalFrame = frame;
SwingUtilities.invokeLater(new Thread() {
+ @Override
public void run() {
finalFrame.pack();
-
+
WindowSettings ws = getWindowSettings();
Rectangle bounds = ws.getBounds(finalFrame);
if (bounds.x != -1 && bounds.y != -1) finalFrame.setLocation(bounds.getLocation());
diff --git a/rails/ui/swing/GridPanel.java b/rails/ui/swing/GridPanel.java
index ddc4582..a835007 100644
--- a/rails/ui/swing/GridPanel.java
+++ b/rails/ui/swing/GridPanel.java
@@ -16,6 +16,7 @@ import rails.game.*;
import rails.game.model.ModelObject;
import rails.game.state.BooleanState;
import rails.ui.swing.elements.*;
+import rails.util.Util;
public abstract class GridPanel extends JPanel
implements ActionListener, KeyListener {
@@ -166,6 +167,37 @@ implements ActionListener, KeyListener {
highlightedComps.clear();
}
+ /** Returns a string array, each element of which contains the text contents
+ * of one row, separated by semicolons.
+ */
+ public List<String> getTextContents () {
+
+ List<String> result = new ArrayList<String>(32);
+ StringBuilder b;
+ String text, tip;
+ if (fields == null || fields.length == 0) return result;
+
+ for (int i=0; i<fields.length; i++) {
+ b = new StringBuilder();
+ for (int j=0; j<fields[i].length; j++) {
+ if (j > 0) b.append(";");
+ if (fields[i][j] instanceof JLabel) {
+ text = ((JLabel)fields[i][j]).getText();
+ b.append (text == null ? "" : text);
+ if (fields[i][j] instanceof Field) {
+ tip = fields[i][j].getToolTipText();
+ if (Util.hasValue(tip)) {
+ b.append("{").append(tip).append("}");
+ }
+ }
+ }
+ }
+ result.add(b.toString().replaceAll("</?html>", "").replaceAll("<br>",",").replaceAll(" x ", "x"));
+ }
+
+ return result;
+ }
+
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_F1) {
HelpWindow.displayHelp(GameManager.getInstance().getHelp());
diff --git a/rails/ui/swing/StatusWindow.java b/rails/ui/swing/StatusWindow.java
index 48ee3bd..c0b6640 100644
--- a/rails/ui/swing/StatusWindow.java
+++ b/rails/ui/swing/StatusWindow.java
@@ -1,10 +1,10 @@
/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/StatusWindow.java,v 1.46 2010/06/15 20:16:54 evos Exp $*/
package rails.ui.swing;
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Color;
import java.awt.event.*;
import java.util.*;
-import java.util.List;
import javax.swing.*;
@@ -34,6 +34,8 @@ KeyListener, ActionPerformer {
protected static final String AUTOSAVELOAD_CMD = "AutoSaveLoad";
+ protected static final String SAVESTATUS_CMD = "SaveGameStatus";
+
protected static final String EXPORT_CMD = "Export";
protected static final String UNDO_CMD = "Undo";
@@ -139,6 +141,15 @@ KeyListener, ActionPerformer {
menuItem.setEnabled(true);
fileMenu.add(menuItem);
+ menuItem = new JMenuItem(LocalText.getText("SaveGameStatus"));
+ menuItem.setActionCommand(SAVESTATUS_CMD);
+ menuItem.setMnemonic(KeyEvent.VK_G);
+ menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
+ ActionEvent.ALT_MASK));
+ menuItem.addActionListener(this);
+ menuItem.setEnabled(true);
+ fileMenu.add(menuItem);
+
// export menu item
// exportItem = new ActionMenuItem(LocalText.getText("EXPORT"));
// exportItem.setActionCommand(EXPORT_CMD);
@@ -148,6 +159,7 @@ KeyListener, ActionPerformer {
// fileMenu.add(exportItem);
// fileMenu.addSeparator();
+
menuItem = new JMenuItem(LocalText.getText("QUIT"));
menuItem.setActionCommand(QUIT_CMD);
menuItem.setMnemonic(KeyEvent.VK_Q);
@@ -643,6 +655,8 @@ KeyListener, ActionPerformer {
gameUIManager.configWindow.setVisible(((JMenuItem) actor.getSource()).isSelected());
} else if (command.equals(AUTOSAVELOAD_CMD)) {
gameUIManager.autoSaveLoadGame();
+ } else if (command.equals(SAVESTATUS_CMD)) {
+ gameUIManager.saveGameStatus();
} else if (executedAction == null) {
;
} else if (executedAction instanceof GameAction) {
|