Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmMainWindow.cs @ 167:9808adf2d566 default tip
Re #419: Remove assumptions of a file-based install
* Update GTK# GUI to use Streams version of XSLT export
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 28 Nov 2012 20:25:53 +0000 |
parents | dc13cef2bc2b |
children |
rev | line source |
---|---|
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
1 // This file (FrmMainWindow.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard. |
0 | 2 // |
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
0 | 4 using System; |
103
1bd748721040
* Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
5 using System.Collections; |
0 | 6 using System.Collections.Generic; |
7 using System.Configuration; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
8 using System.IO; |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
9 using GLib; |
13 | 10 using Gtk; |
11 using IBBoard; | |
0 | 12 using IBBoard.Commands; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
13 using IBBoard.CustomMath; |
12
685532d43a96
Re #88: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
10
diff
changeset
|
14 using IBBoard.GtkSharp; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
15 using IBBoard.GtkSharp.Translatable; |
0 | 16 using IBBoard.IO; |
13 | 17 using IBBoard.Lang; |
18 using IBBoard.Logging; | |
0 | 19 using IBBoard.WarFoundry.API; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
20 using IBBoard.WarFoundry.API.Commands; |
28 | 21 using IBBoard.WarFoundry.API.Exporters; |
0 | 22 using IBBoard.WarFoundry.API.Factories; |
13 | 23 using IBBoard.WarFoundry.API.Factories.Xml; |
24 using IBBoard.WarFoundry.API.Objects; | |
0 | 25 using IBBoard.WarFoundry.API.Savers; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
26 using IBBoard.WarFoundry.GUI.GTK.Widgets; |
0 | 27 using IBBoard.Xml; |
28 using log4net; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
29 using WFObjects = IBBoard.WarFoundry.API.Objects; |
108 | 30 using IBBoard.WarFoundry.API.Savers.Xml; |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
31 using IBBoard.WarFoundry.API.Objects.Requirement; |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
32 using System.Text; |
0 | 33 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
34 namespace IBBoard.WarFoundry.GUI.GTK |
21 | 35 { |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
36 public partial class FrmMainWindow: TranslatableWindowWithActions |
0 | 37 { |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
38 private static readonly string VALIDATION_RESULTS_KEY = "WarFoundryValidationFailureMessages"; |
0 | 39 private static readonly string AppTitle = "WarFoundry"; |
13 | 40 private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6; |
41 private Preferences preferences; | |
42 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); | |
0 | 43 private CommandStack commandStack; |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
44 private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>(); |
13 | 45 private ObjectAddDelegate UnitAddedMethod; |
46 private ObjectRemoveDelegate UnitRemovedMethod; | |
47 private DoubleValChangedDelegate PointsValueChangedMethod; | |
0 | 48 private StringValChangedDelegate UnitNameChangedMethod; |
49 private GameSystem system; | |
50 private string loadedArmyPath; | |
51 private MenuToolButton undoMenuButton, redoMenuButton; | |
21 | 52 |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
53 public static void Main(string[] args) |
21 | 54 { |
13 | 55 try |
0 | 56 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
57 ExceptionManager.UnhandledException += HandleUnhandledException; |
0 | 58 Application.Init(); |
59 FrmMainWindow win = new FrmMainWindow(args); | |
60 win.Show(); | |
61 Application.Run(); | |
13 | 62 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); |
63 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
64 catch (Exception ex) |
13 | 65 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
66 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
67 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
68 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
69 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
70 private static void HandleUnhandledException(UnhandledExceptionArgs args) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
71 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
72 object obj = args.ExceptionObject; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
73 Exception ex = null; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
74 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
75 if (obj is Exception) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
76 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
77 ex = (Exception)obj; |
0 | 78 } |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
79 else |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
80 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
81 ex = new Exception("GLib returned unexpected exception object type " + obj.GetType()); |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
82 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
83 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
84 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
85 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
86 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
87 private static void HandleUnhandledException(Exception ex) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
88 { |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
89 string msg = String.Format("({0}) {1}", ex.GetType().FullName, ex.Message); |
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
90 LogManager.GetLogger(typeof(FrmMainWindow)).Fatal(msg, ex); |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
91 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details."); |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
92 dialog.Run(); |
64
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
93 dialog.Hide(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
94 dialog.Dispose(); |
0 | 95 } |
21 | 96 |
0 | 97 public FrmMainWindow() : this(new string[0]) |
98 { | |
99 //Do nothing extra | |
100 } | |
21 | 101 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
102 public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel) |
0 | 103 { |
104 logger.Info("Opening FrmMainWindow"); | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
105 Build(); |
0 | 106 //Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support |
107 redoMenuButton = new MenuToolButton("gtk-redo"); | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
108 redoMenuButton.Name = "bttnRedo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
109 redoMenuButton.Clicked += redoTBButtonActivated; |
78
e63209ab2cfa
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
110 redoMenuButton.Sensitive = false; |
0 | 111 toolbar.Insert(redoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
112 undoMenuButton = new MenuToolButton("gtk-undo"); | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
113 undoMenuButton.Name = "bttnUndo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
114 undoMenuButton.Clicked += undoTBButtonActivated; |
78
e63209ab2cfa
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
115 undoMenuButton.Sensitive = false; |
0 | 116 toolbar.Insert(undoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
117 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 1]); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
118 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 2]); |
0 | 119 toolbar.ShowAll(); |
21 | 120 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
121 TreeViewColumn mainColumn = new TreeViewColumn(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
122 CellRendererText mainCell = new CellRendererText(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
123 mainColumn.PackStart(mainCell, true); |
0 | 124 treeUnits.AppendColumn(mainColumn); |
125 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderCategoryTreeObjectName)); | |
126 treeUnits.Model = new TreeStore(typeof(WarFoundryObject)); | |
127 logger.Debug("Loading preferences"); | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
128 Preferences = new Preferences("WarFoundry-GTK"); |
0 | 129 logger.Debug("Loading translations"); |
21 | 130 |
8
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
131 try |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
132 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
133 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
134 } |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
135 catch (TranslationLoadException ex) |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
136 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
137 logger.Error(ex); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
138 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, ex.Message); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
139 dialog.Title = "Translation loading failed"; |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
140 dialog.Run(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
141 dialog.Destroy(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
142 } |
21 | 143 |
13 | 144 logger.Debug("Initialising"); |
145 commandStack = new CommandStack(); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
146 commandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
147 WarFoundryCore.GameSystemChanged += new GameSystemChangedDelegate(OnGameSystemChanged); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
148 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(OnArmyChanged); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
149 Destroyed += new EventHandler(OnWindowDestroyed); |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
150 Translation.TranslationChanged += Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
151 Translate(); |
13 | 152 UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded); |
153 UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved); | |
154 PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged); | |
0 | 155 UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged); |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
156 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
157 SetStatusBarText(); |
21 | 158 |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
159 LoadFilesFromArgs(args); |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
160 } |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
161 |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
162 private void LoadFilesFromArgs(string[] args) |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
163 { |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
164 logger.Debug("Initialising complete - seeing if we can load default army or system"); |
0 | 165 if (args.Length == 1) |
166 { | |
21 | 167 logger.Debug("Attempting to load from file"); |
0 | 168 FileInfo file = new FileInfo(args[0]); |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
169 |
0 | 170 try |
171 { | |
5 | 172 ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file); |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
173 |
5 | 174 if (objects.Count == 1) |
0 | 175 { |
5 | 176 List<IWarFoundryObject> objectList = new List<IWarFoundryObject>(); |
177 objectList.AddRange(objects); | |
178 IWarFoundryObject loadedObject = objectList[0]; | |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
179 |
5 | 180 if (loadedObject is Army) |
181 { | |
182 WarFoundryCore.CurrentArmy = (Army)loadedObject; | |
183 logger.InfoFormat("Loaded army from {0}", file.FullName); | |
184 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
185 else |
5 | 186 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
187 if (loadedObject is GameSystem) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
188 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
189 WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
190 logger.InfoFormat("Loaded game system from {0}", file.FullName); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
191 } |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
192 |
5 | 193 } |
0 | 194 } |
195 } | |
196 catch (InvalidFileException ex) | |
197 { | |
198 //TODO: show error dialog | |
199 logger.Error(ex); | |
200 } | |
201 } | |
202 else | |
203 { | |
204 string gameSystemID = Preferences.GetStringProperty("currSystem"); | |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
205 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
206 if (gameSystemID != null && !"".Equals(gameSystemID)) |
0 | 207 { |
208 logger.Debug("Attempting to load current game system from properties"); | |
209 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); | |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
210 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
211 if (sys != null) |
0 | 212 { |
213 WarFoundryCore.CurrentGameSystem = sys; | |
214 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); | |
215 } | |
216 } | |
217 } | |
218 } | |
21 | 219 |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
220 protected override void Translate() |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
221 { |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
222 base.Translate(); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
223 SetAppTitle(); |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
224 treeUnits.GetColumn(0).Title = Translation.GetTranslation("armyCategoryColumnTitle", "categories"); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
225 RebuildUndoRedoMenus(); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
226 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
227 |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
228 private void Retranslate() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
229 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
230 Translate(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
231 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
232 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
233 public override void Dispose() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
234 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
235 Translation.TranslationChanged -= Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
236 base.Dispose(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
237 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
238 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
239 private void FileLoadingFinished(List<FileLoadFailure> failures) |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
240 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
241 foreach (FileLoadFailure failure in failures) |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
242 { |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
243 logger.Warn("Failed to load " + failure.FailedFile.Name + ": " + failure.Message); |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
244 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
245 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
246 |
0 | 247 private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
248 { | |
249 object o = model.GetValue(iter, 0); | |
21 | 250 |
0 | 251 if (o is ArmyCategory) |
252 { | |
253 ArmyCategory c = (ArmyCategory)o; | |
254 string name = ""; | |
21 | 255 |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
256 if (!Preferences.GetBooleanProperty("ShowCatPercentage")) |
0 | 257 { |
135
fda46380dd68
Re #329: "Points" system should be used in UI
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
258 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}{2}", c.Name, c.Points, WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(c.Points)); |
0 | 259 } |
260 else | |
261 { | |
135
fda46380dd68
Re #329: "Points" system should be used in UI
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
262 name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}{3} ({2}%)", c.Name, c.Points, (c.ParentArmy.Points > 0 ? Math.Round((c.Points / c.ParentArmy.Points) * 100) : 0), WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(c.Points)); |
0 | 263 } |
21 | 264 |
0 | 265 (cell as CellRendererText).Text = name; |
266 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
267 else |
0 | 268 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
269 if (o is WFObjects.Unit) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
270 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
271 WFObjects.Unit u = (WFObjects.Unit)o; |
135
fda46380dd68
Re #329: "Points" system should be used in UI
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
272 string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}{2}", u.Name, u.Points, WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(u.Points)); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
273 (cell as CellRendererText).Text = name; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
274 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
275 |
0 | 276 } |
277 } | |
21 | 278 |
0 | 279 private void OnWindowDestroyed(object source, EventArgs args) |
280 { | |
281 logger.Info("Exiting"); | |
282 Application.Quit(); | |
283 } | |
21 | 284 |
0 | 285 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue) |
286 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
287 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
288 logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name); |
0 | 289 UnitDisplayWidget widget; |
290 unitToWidgetMap.TryGetValue(unit, out widget); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
291 |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
292 if (widget != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
293 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
294 unitsNotebook.SetTabLabel(widget, NotebookUtil.CreateNotebookTabLabelWithClose(unitsNotebook, widget, unit.Name)); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
295 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
296 |
41
a32b6bb7f1eb
Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
297 treeUnits.QueueDraw(); |
0 | 298 } |
21 | 299 |
0 | 300 private void OnUnitAdded(WarFoundryObject val) |
301 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
302 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
303 unit.NameChanged += UnitNameChangedMethod; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
304 unit.PointsValueChanged += HandleUnitPointsValueChanged; |
0 | 305 AddUnitToTree(unit); |
306 } | |
21 | 307 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
308 private void HandleUnitPointsValueChanged(WarFoundryObject obj, double oldValue, double newValue) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
309 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
310 treeUnits.QueueDraw(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
311 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
312 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
313 private void AddUnitToTree(WFObjects.Unit unit) |
0 | 314 { |
315 TreeStore model = (TreeStore)treeUnits.Model; | |
316 TreeIter iter; | |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
317 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
318 if (unit.ParentUnit == null) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
319 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
320 iter = GetUnitTreeIterForCategory(model, unit.Category); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
321 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
322 else |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
323 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
324 iter = GetUnitTreeIterForUnit(model, unit.ParentUnit); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
325 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
326 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
327 if (!iter.Equals(TreeIter.Zero)) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
328 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
329 model.AppendValues(iter, unit); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
330 TreePath path = model.GetPath(iter); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
331 treeUnits.ExpandToPath(path); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
332 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
333 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
334 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
335 private TreeIter GetUnitTreeIterForCategory(TreeStore model, ArmyCategory category) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
336 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
337 TreeIter targetIter = TreeIter.Zero; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
338 TreeIter iter; |
0 | 339 model.GetIterFirst(out iter); |
21 | 340 |
0 | 341 do |
342 { | |
343 object obj = model.GetValue(iter, 0); | |
21 | 344 |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
345 if (obj.Equals(category)) |
0 | 346 { |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
347 targetIter = iter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
348 break; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
349 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
350 } while (model.IterNext(ref iter)); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
351 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
352 return targetIter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
353 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
354 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
355 private TreeIter GetUnitTreeIterForUnit(TreeStore model, WFObjects.Unit unit) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
356 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
357 TreeIter targetIter = TreeIter.Zero; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
358 TreeIter iter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
359 model.GetIterFirst(out iter); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
360 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
361 do |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
362 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
363 TreeIter unitIter = GetUnitTreeIterForUnit(model, iter, unit); |
21 | 364 |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
365 if (!unitIter.Equals(TreeIter.Zero)) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
366 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
367 targetIter = unitIter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
368 break; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
369 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
370 } while (model.IterNext(ref iter)); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
371 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
372 return targetIter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
373 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
374 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
375 private TreeIter GetUnitTreeIterForUnit(TreeStore model, TreeIter parentIter, WFObjects.Unit unit) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
376 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
377 TreeIter iter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
378 model.IterChildren(out iter, parentIter); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
379 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
380 if (iter.Equals(TreeIter.Zero)) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
381 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
382 return TreeIter.Zero; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
383 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
384 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
385 TreeIter targetIter = TreeIter.Zero; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
386 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
387 do |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
388 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
389 object obj = model.GetValue(iter, 0); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
390 if (obj.Equals(unit)) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
391 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
392 targetIter = iter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
393 break; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
394 } |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
395 else |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
396 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
397 TreeIter unitIter = GetUnitTreeIterForUnit(model, iter, unit); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
398 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
399 if (!unitIter.Equals(TreeIter.Zero)) |
0 | 400 { |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
401 targetIter = unitIter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
402 break; |
0 | 403 } |
404 } | |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
405 } while (model.IterNext(ref iter)); |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
406 |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
407 return targetIter; |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
408 |
0 | 409 } |
21 | 410 |
0 | 411 private void OnUnitRemoved(WarFoundryObject obj) |
412 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
413 WFObjects.Unit unit = (WFObjects.Unit)obj; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
414 unit.NameChanged -= UnitNameChangedMethod; |
0 | 415 RemoveUnitFromTree(unit); |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
416 RemoveUnitTab(unit); |
0 | 417 } |
21 | 418 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
419 private void RemoveUnitFromTree(WFObjects.Unit unit) |
0 | 420 { |
421 TreeStore model = (TreeStore)treeUnits.Model; | |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
422 TreeIter iter = GetUnitTreeIterForUnit(model, unit); |
21 | 423 |
164
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
424 if (!iter.Equals(TreeIter.Zero)) |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
425 { |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
426 model.Remove(ref iter); |
219340630150
Fixes #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
162
diff
changeset
|
427 } |
0 | 428 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
429 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
430 private void RemoveUnitTab(WFObjects.Unit unit) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
431 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
432 UnitDisplayWidget widget = DictionaryUtils.GetValue(unitToWidgetMap, unit); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
433 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
434 if (widget != null) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
435 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
436 unitsNotebook.Remove(widget); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
437 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
438 } |
21 | 439 |
0 | 440 private void OnPointsValueChanged(WarFoundryObject obj, double before, double after) |
441 { | |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
442 SetStatusBarText(); |
0 | 443 } |
21 | 444 |
0 | 445 public Preferences Preferences |
446 { | |
447 get { return preferences; } | |
21 | 448 set { preferences = value; } |
0 | 449 } |
21 | 450 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
451 protected void OnDeleteEvent(object sender, DeleteEventArgs a) |
0 | 452 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
453 Application.Quit(); |
0 | 454 a.RetVal = true; |
455 } | |
456 | |
457 protected virtual void OnExitActivated(object sender, System.EventArgs e) | |
458 { | |
459 Application.Quit(); | |
460 } | |
461 | |
462 protected virtual void OnCreateArmyActivated(object sender, System.EventArgs e) | |
463 { | |
464 CreateNewArmy(); | |
465 } | |
466 | |
467 protected virtual void OnReloadFilesActivated(object sender, System.EventArgs e) | |
468 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
469 WarFoundryLoader.GetDefault().LoadFiles(); |
0 | 470 } |
471 | |
472 protected virtual void OnSaveArmyAsActivated(object sender, System.EventArgs e) | |
473 { | |
474 SaveCurrentArmyAs(); | |
475 } | |
476 | |
477 protected virtual void OnCloseArmyActivated(object sender, System.EventArgs e) | |
478 { | |
479 CloseCurrentArmy(); | |
480 } | |
481 | |
482 protected virtual void OnOpenArmyActivated(object sender, System.EventArgs e) | |
483 { | |
484 OpenArmy(); | |
485 } | |
486 | |
487 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e) | |
488 { | |
33 | 489 SaveCurrentArmyOrSaveAs(); |
0 | 490 } |
21 | 491 |
0 | 492 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e) |
493 { | |
494 if (sender is ToolButton) | |
495 { | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
496 ToolButton toolButton = (ToolButton)sender; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
497 Category cat = (Category)toolButton.Data["Category"]; |
21 | 498 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
499 if (cat != null) |
0 | 500 { |
501 logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name); | |
502 FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy); | |
503 ResponseType response = (ResponseType)newUnit.Run(); | |
504 newUnit.Hide(); | |
21 | 505 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
506 if (response == ResponseType.Ok) |
0 | 507 { |
14
abbf8a3ac431
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
508 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat)); |
0 | 509 commandStack.Execute(cmd); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
510 ShowUnitWidget(cmd.Unit); |
0 | 511 } |
21 | 512 |
0 | 513 newUnit.Dispose(); |
514 } | |
515 } | |
516 } | |
21 | 517 |
13 | 518 public CommandStack CommandStack |
519 { | |
520 get { return commandStack; } | |
0 | 521 } |
21 | 522 |
0 | 523 private void SetAppTitle() |
524 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
525 if (WarFoundryCore.CurrentArmy != null) |
0 | 526 { |
527 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name; | |
528 } | |
529 else | |
530 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
531 if (WarFoundryCore.CurrentGameSystem != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
532 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
533 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
534 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
535 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
536 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
537 Title = AppTitle; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
538 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
539 |
0 | 540 } |
541 } | |
21 | 542 |
0 | 543 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys) |
544 { | |
545 system = newSys; | |
546 SetAppTitle(); | |
547 RemoveCategoryButtons(); | |
21 | 548 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
549 if (system != null) |
0 | 550 { |
551 AddCategoryButtons(system.Categories); | |
151
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
552 logger.DebugFormat("Game system set to {0} with ID {1}", system.Name, system.ID); |
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
553 } |
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
554 else |
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
555 { |
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
556 logger.Debug("Game system set to null"); |
0 | 557 } |
558 } | |
21 | 559 |
0 | 560 private void OnArmyChanged(Army oldArmy, Army newArmy) |
561 { | |
562 loadedArmyPath = null; | |
563 SetAppTitle(); | |
564 SetArmyTree(newArmy); | |
21 | 565 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
566 if (oldArmy != null) |
13 | 567 { |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
568 oldArmy.UnitAdded -= UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
569 oldArmy.UnitRemoved -= UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
570 oldArmy.PointsValueChanged -= PointsValueChangedMethod; |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
571 oldArmy.NameChanged -= OnArmyNameChanged; |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
572 oldArmy.MaxPointsValueChanged -= OnMaxPointsValueChanged; |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
573 oldArmy.ArmyCompositionChanged -= HandleArmyCompositionChanged; |
0 | 574 } |
21 | 575 |
0 | 576 unitToWidgetMap.Clear(); |
21 | 577 |
0 | 578 while (unitsNotebook.NPages > 0) |
579 { | |
580 unitsNotebook.RemovePage(0); | |
581 } | |
21 | 582 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
583 if (newArmy == null) |
13 | 584 { |
585 DisableCategoryButtons(); | |
586 } | |
587 else | |
588 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
589 newArmy.UnitAdded += UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
590 newArmy.UnitRemoved += UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
591 newArmy.PointsValueChanged += PointsValueChangedMethod; |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
592 newArmy.NameChanged += OnArmyNameChanged; |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
593 newArmy.MaxPointsValueChanged += OnMaxPointsValueChanged; |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
594 newArmy.ArmyCompositionChanged += HandleArmyCompositionChanged; |
13 | 595 //TODO: Clear all buttons |
596 EnableCategoryButtons(); | |
597 | |
598 if (newArmy.Race.HasCategoryOverrides()) | |
599 { | |
600 RemoveCategoryButtons(); | |
601 AddCategoryButtons(newArmy.Race.Categories); | |
602 } | |
0 | 603 } |
21 | 604 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
605 bool nonNullNewArmy = (newArmy != null); |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
606 miCloseArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
607 miSaveArmyAs.Sensitive = nonNullNewArmy; |
81
3ff8e10de45a
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
79
diff
changeset
|
608 miExportArmyAs.Sensitive = nonNullNewArmy; |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
609 miEditArmy.Sensitive = nonNullNewArmy; |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
610 treeUnits.Visible = nonNullNewArmy; |
33 | 611 loadedArmyPath = null; |
0 | 612 //New army has no changes, so we can't save it |
613 miSaveArmy.Sensitive = false; | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
614 bttnSaveArmy.Sensitive = false; |
13 | 615 |
616 CommandStack.Reset(); | |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
617 SetStatusBarText(); |
0 | 618 } |
21 | 619 |
151
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
620 private void OnArmyNameChanged(WarFoundryObject obj, string oldValue, string newValue) |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
621 { |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
622 SetAppTitle(); |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
623 } |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
624 |
151
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
625 private void OnMaxPointsValueChanged(WarFoundryObject obj, int oldValue, int newValue) |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
626 { |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
627 SetStatusBarText(); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
628 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
629 |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
630 private void HandleArmyCompositionChanged() |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
631 { |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
632 SetStatusBarText(); |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
633 } |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
634 |
0 | 635 private void SetArmyTree(Army army) |
636 { | |
637 logger.Debug("Resetting tree"); | |
638 TreeStore store = (TreeStore)treeUnits.Model; | |
639 store.Clear(); | |
640 TreeIter iter; | |
21 | 641 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
642 if (army != null) |
0 | 643 { |
644 logger.Debug("Loading in categories to tree"); | |
21 | 645 |
0 | 646 foreach (ArmyCategory cat in army.Categories) |
647 { | |
648 logger.DebugFormat("Append category {0}", cat.Name); | |
649 iter = store.AppendValues(cat); | |
21 | 650 |
165
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
651 foreach (WFObjects.Unit unit in cat.GetMainUnits()) |
0 | 652 { |
165
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
653 AddUnitToTree(store, iter, unit); |
21 | 654 } |
0 | 655 } |
21 | 656 |
0 | 657 logger.Debug("Finished loading tree categories"); |
658 } | |
165
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
659 |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
660 treeUnits.ExpandAll(); |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
661 } |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
662 |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
663 private void AddUnitToTree(TreeStore store, TreeIter parentIter, WFObjects.Unit unit) |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
664 { |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
665 TreeIter unitIter = store.AppendValues(parentIter, unit); |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
666 |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
667 foreach (WFObjects.Unit childUnit in unit.ContainedUnits) |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
668 { |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
669 AddUnitToTree(store, unitIter, childUnit); |
dc13cef2bc2b
Re #420: Saved army does not save "contained" structure
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
670 } |
0 | 671 } |
21 | 672 |
0 | 673 private void DisableCategoryButtons() |
674 { | |
675 SetCategoryButtonsSensitive(false); | |
676 } | |
21 | 677 |
0 | 678 private void EnableCategoryButtons() |
679 { | |
680 SetCategoryButtonsSensitive(true); | |
681 } | |
21 | 682 |
0 | 683 private void SetCategoryButtonsSensitive(bool state) |
684 { | |
685 int toolbarButtonCount = toolbar.Children.Length - 1; | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
686 logger.Debug("Last button index: " + toolbarButtonCount); |
21 | 687 |
0 | 688 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
689 { | |
690 logger.DebugFormat("Setting button {0} state to {1}", i, state); | |
691 toolbar.Children[i].Sensitive = state; | |
692 } | |
693 } | |
21 | 694 |
0 | 695 private void RemoveCategoryButtons() |
696 { | |
697 int toolbarButtonCount = toolbar.Children.Length - 1; | |
21 | 698 |
0 | 699 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
700 { | |
701 toolbar.Remove(toolbar.Children[i]); | |
702 } | |
703 } | |
21 | 704 |
0 | 705 private void AddCategoryButtons(Category[] cats) |
706 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
707 if (cats != null && cats.Length > 0) |
0 | 708 { |
709 logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length); | |
21 | 710 |
0 | 711 foreach (Category cat in cats) |
712 { | |
713 ToolButton button = new ToolButton("gtk-add"); | |
714 button.Label = cat.Name; | |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
715 button.TooltipText = Translation.GetTranslation("bttnCreateFromCat", "{0}", cat.Name); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
716 button.Data["Category"] = cat; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
717 button.Clicked += new System.EventHandler(OnAddUnitActivated); |
0 | 718 toolbar.Insert(button, -1); |
719 } | |
720 } | |
21 | 721 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
722 toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats != null && cats.Length > 0; |
21 | 723 |
0 | 724 toolbar.ShowAll(); |
725 } | |
21 | 726 |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
727 private void SetStatusBarText() |
0 | 728 { |
99
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
729 if (WarFoundryCore.CurrentArmy != null) |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
730 { |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
731 statusbar.Push(1, GetPointsText()); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
732 SetValidationText(); |
99
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
733 } |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
734 else |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
735 { |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
736 statusbar.Push(1, ""); |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
737 SetBlankValidationText(); |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
738 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
739 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
740 |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
741 private string GetPointsText() |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
742 { |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
743 int maxPts = WarFoundryCore.CurrentArmy.MaxPoints; |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
744 string maxPtsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.MaxPoints); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
745 double points = WarFoundryCore.CurrentArmy.Points; |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
746 string ptsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.Points); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
747 return Translation.GetTranslation("statusPanelPoints", "{0}{2} of {1}{3}", points, maxPts, ptsAbbrev, maxPtsAbbrev); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
748 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
749 |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
750 private void SetValidationText() |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
751 { |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
752 if (WarFoundryCore.CurrentGameSystem != null && WarFoundryCore.CurrentGameSystem.WarnOnError) |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
753 { |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
754 SetValidationTextAndColour(); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
755 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
756 else |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
757 { |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
758 SetBlankValidationText(); |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
759 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
760 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
761 |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
762 private void SetValidationTextAndColour() |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
763 { |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
764 ICollection<string> failureMessages; |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
765 Validation result = RequirementHandler.ValidateArmy(WarFoundryCore.CurrentArmy, out failureMessages); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
766 string pluralHack = (failureMessages.Count == 1 ? "" : "s"); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
767 lblValidationWarning.Text = String.Format("{0} validation warning{1}", failureMessages.Count, pluralHack); |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
768 lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = failureMessages; |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
769 |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
770 if (Validates.AsOkay(result)) |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
771 { |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
772 lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
773 } |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
774 else |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
775 { |
149
45c2485f37c0
* Initialise variable - xbuild is more picky than MonoDevelop
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
776 Gdk.Color red = Gdk.Color.Zero; |
140
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
777 Gdk.Color.Parse("#cc0000", ref red); |
2b9fabd65309
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
778 lblValidationWarning.ModifyFg(StateType.Normal, red); |
99
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
779 } |
0 | 780 } |
21 | 781 |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
782 private void SetBlankValidationText() |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
783 { |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
784 lblValidationWarning.Text = ""; |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
785 lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = new string[0]; |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
786 lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero); |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
787 } |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
788 |
13 | 789 private void commandStack_CommandStackUpdated() |
790 { | |
791 undoMenuButton.Sensitive = commandStack.CanUndo(); | |
792 miUndo.Sensitive = undoMenuButton.Sensitive; | |
793 redoMenuButton.Sensitive = commandStack.CanRedo(); | |
794 miRedo.Sensitive = redoMenuButton.Sensitive; | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
795 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
796 RebuildUndoRedoMenus(); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
797 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
798 bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
799 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
800 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
801 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
802 private void RebuildUndoRedoMenus() |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
803 { |
0 | 804 int redoLength = commandStack.RedoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
805 int maxRedo = Math.Min(10, redoLength); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
806 |
13 | 807 if (redoLength > 0) |
808 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
809 Menu menu = new Menu(); |
13 | 810 Command com; |
811 MenuItem mi; | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
812 |
13 | 813 for (int i = 0; i < maxRedo; i++) |
814 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
815 com = commandStack.PeekRedoCommand(i + 1); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
816 |
13 | 817 if (com == null) |
818 { | |
21 | 819 break; |
13 | 820 } |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
821 |
13 | 822 mi = new MenuItem(com.Description); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
823 mi.Activated += new EventHandler(RedoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
824 menu.Append(mi); |
13 | 825 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
826 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
827 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
828 redoMenuButton.Menu = menu; |
13 | 829 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
830 else |
13 | 831 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
832 redoMenuButton.Menu = null; |
13 | 833 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
834 |
13 | 835 int undoLength = commandStack.UndoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
836 int maxUndo = Math.Min(10, undoLength); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
837 |
13 | 838 if (undoLength > 0) |
839 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
840 Menu menu = new Menu(); |
13 | 841 Command com; |
842 MenuItem mi; | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
843 |
13 | 844 for (int i = 0; i < maxUndo; i++) |
845 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
846 com = commandStack.PeekUndoCommand(i + 1); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
847 |
13 | 848 if (com == null) |
849 { | |
21 | 850 break; |
13 | 851 } |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
852 |
13 | 853 mi = new MenuItem(com.UndoDescription); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
854 mi.Activated += new EventHandler(UndoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
855 menu.Add(mi); |
13 | 856 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
857 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
858 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
859 undoMenuButton.Menu = menu; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
860 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
861 else |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
862 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
863 undoMenuButton.Menu = null; |
13 | 864 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
865 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
866 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
867 private void RedoMenuActivated(object sender, EventArgs e) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
868 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
869 if (sender is MenuItem) |
13 | 870 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
871 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
872 //we know it's an redo menu item so find it's index and redo everything |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
873 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
874 int max = Arrays.IndexOf(((Menu)redoMenuButton.Menu).Children, item); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
875 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
876 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
877 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
878 for (int i = 0; i <= max; i++) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
879 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
880 commandStack.Redo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
881 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
882 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
883 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
884 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
885 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
886 private void UndoMenuActivated(object sender, EventArgs e) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
887 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
888 if (sender is MenuItem) |
0 | 889 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
890 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
891 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
892 //we know it's an undo menu item so find it's index and undo everything |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
893 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
894 int max = Arrays.IndexOf(((Menu)undoMenuButton.Menu).Children, item); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
895 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
896 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
897 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
898 for (int i = 0; i <= max; i++) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
899 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
900 commandStack.Undo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
901 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
902 } |
0 | 903 } |
13 | 904 } |
905 | |
906 private bool SaveCurrentArmyOrSaveAs() | |
907 { | |
33 | 908 if (loadedArmyPath != null) |
13 | 909 { |
910 return SaveCurrentArmy(); | |
911 } | |
21 | 912 else |
13 | 913 { |
914 return SaveCurrentArmyAs(); | |
915 } | |
0 | 916 } |
21 | 917 |
0 | 918 private bool OpenArmy() |
919 { | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
920 string title = Translation.GetTranslation("openArmyDialog", "open army"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
921 string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
922 string openText = Translation.GetTranslation("bttnOpen", "open"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
923 FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Open, cancelText, ResponseType.Cancel, openText, ResponseType.Accept); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
924 FileFilter filter = new FileFilter(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
925 filter.AddPattern("*.army"); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
926 filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files"); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
927 fileDialog.AddFilter(filter); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
928 int response = fileDialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
929 string filePath = null; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
930 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
931 if (response == (int)ResponseType.Accept) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
932 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
933 filePath = fileDialog.Filename; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
934 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
935 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
936 fileDialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
937 fileDialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
938 |
0 | 939 bool success = false; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
940 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
941 if (filePath != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
942 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
943 FileInfo file = new FileInfo(filePath); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
944 Army army = null; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
945 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
946 try |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
947 { |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
948 army = WarFoundryLoader.GetDefault().LoadArmy(file); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
949 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
950 catch (Exception ex) |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
951 { |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
952 logger.Error("Error while loading army file " + filePath, ex); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
953 } |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
954 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
955 if (army != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
956 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
957 logger.Debug("Loaded army " + army.ID); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
958 success = true; |
33 | 959 WarFoundryCore.CurrentArmy = army; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
960 loadedArmyPath = filePath; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
961 logger.Debug("Army loading complete"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
962 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
963 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
964 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
965 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("OpenFailed", "File open failed. Please check log file")); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
966 dialog.Title = Translation.GetTranslation("OpenFailedTitle", "File open failed"); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
967 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
968 dialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
969 dialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
970 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
971 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
972 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
973 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
974 logger.Debug("Army open requested but cancelled"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
975 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
976 |
0 | 977 return success; |
13 | 978 } |
979 | |
980 private bool SaveCurrentArmy() | |
0 | 981 { |
982 bool success = false; | |
21 | 983 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
984 if (loadedArmyPath != null) |
0 | 985 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
986 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); |
0 | 987 } |
21 | 988 |
13 | 989 return success; |
990 } | |
991 | |
992 private bool SaveCurrentArmyAs() | |
993 { | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
994 string title = Translation.GetTranslation("saveArmyDialog", "save army"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
995 string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
996 string saveText = Translation.GetTranslation("bttnSave", "save"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
997 FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, saveText, ResponseType.Accept); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
998 FileFilter filter = new FileFilter(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
999 filter.AddPattern("*.army"); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1000 filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files"); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1001 fileDialog.AddFilter(filter); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1002 int response = fileDialog.Run(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1003 string filePath = null; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1004 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1005 if (response == (int)ResponseType.Accept) |
13 | 1006 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1007 filePath = fileDialog.Filename; |
13 | 1008 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1009 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1010 fileDialog.Hide(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1011 fileDialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1012 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1013 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1014 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1015 |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1016 private bool SaveArmyToPath(Army army, string filePath) |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1017 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1018 bool success = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1019 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1020 if (filePath != null) |
13 | 1021 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1022 bool saveSuccess = false; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1023 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1024 try |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1025 { |
106
41e82ba675dc
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
1026 saveSuccess = WarFoundrySaver.GetSaver().Save(filePath, WarFoundryCore.CurrentArmy); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1027 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1028 catch (Exception ex) |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1029 { |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1030 logger.Error("Error while saving army file to " + filePath, ex); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1031 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1032 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1033 if (saveSuccess) |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1034 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1035 miSaveArmy.Sensitive = false; |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
1036 bttnSaveArmy.Sensitive = false; |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1037 CommandStack.setCleanMark(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1038 loadedArmyPath = filePath; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1039 success = true; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1040 } |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1041 else |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1042 { |
151
83b19b57cba1
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
150
diff
changeset
|
1043 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("SaveFailed", "File save failed. Please check log file")); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1044 dialog.Title = Translation.GetTranslation("SaveFailedTitle", "File save failed"); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
1045 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
1046 dialog.Hide(); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1047 dialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1048 } |
21 | 1049 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1050 //else user cancelled |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
1051 |
21 | 1052 return success; |
0 | 1053 } |
21 | 1054 |
13 | 1055 private bool CloseCurrentArmy() |
1056 { | |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
1057 if (WarFoundryCore.CurrentArmy != null) |
13 | 1058 { |
1059 bool canClose = false; | |
1060 | |
1061 if (CommandStack.IsDirty()) | |
0 | 1062 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1063 string message = Translation.GetTranslation("SaveChangesQuestion", "Save changes to army before closing?", WarFoundryCore.CurrentArmy.Name); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1064 MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.None, message); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1065 dia.AddButton(Translation.GetTranslation("bttnDiscard", "lose changes"), ResponseType.No); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1066 Button button = (Button)dia.AddButton(Translation.GetTranslation("bttnCancel", "cancel"), ResponseType.Cancel); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1067 button.Image = new Image("gtk-cancel", IconSize.Button); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1068 button = (Button)dia.AddButton(Translation.GetTranslation("bttnSave", "save"), ResponseType.Yes); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1069 button.Image = new Image("gtk-save", IconSize.Button); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
1070 dia.Title = Translation.GetTranslation("SaveChangesTitle", "Save changes?"); |
0 | 1071 ResponseType dr = (ResponseType)dia.Run(); |
27
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
1072 dia.Hide(); |
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
1073 dia.Dispose(); |
0 | 1074 |
13 | 1075 if (dr == ResponseType.Yes) |
0 | 1076 { |
1077 //They want to save so try to save it or prompt for save as | |
13 | 1078 //If they cancel the save as then assume they don't want to close |
1079 canClose = SaveCurrentArmyOrSaveAs(); | |
1080 } | |
0 | 1081 else |
1082 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1083 if (dr == ResponseType.No) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1084 { |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1085 //They don't care about their changes |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1086 canClose = true; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1087 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1088 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1089 { |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1090 //Assume cancel or close with the X button |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1091 canClose = false; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1092 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1093 |
0 | 1094 } |
13 | 1095 } |
1096 else | |
1097 { | |
1098 //Nothing has changed so we can safely close | |
1099 canClose = true; | |
1100 } | |
1101 | |
1102 if (canClose) | |
0 | 1103 { |
13 | 1104 //do close |
1105 WarFoundryCore.CurrentArmy = null; | |
1106 return true; | |
1107 } | |
1108 else | |
1109 { | |
1110 return false; | |
1111 } | |
1112 } | |
1113 else | |
1114 { | |
1115 //pretend we succeeded | |
1116 return true; | |
1117 } | |
1118 } | |
1119 | |
1120 private void CreateNewArmy() | |
0 | 1121 { |
1122 logger.Debug("Create new army"); | |
1123 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem); | |
1124 ResponseType type = (ResponseType)newArmy.Run(); | |
1125 newArmy.Hide(); | |
21 | 1126 |
0 | 1127 if (type == ResponseType.Ok) |
13 | 1128 { |
1129 if (CloseCurrentArmy()) | |
0 | 1130 { |
1131 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); | |
1132 } | |
1133 } | |
1134 else | |
1135 { | |
1136 logger.Debug("Create new army cancelled"); | |
1137 } | |
21 | 1138 |
13 | 1139 newArmy.Destroy(); |
0 | 1140 } |
21 | 1141 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1142 protected virtual void undoTBButtonActivated(object sender, System.EventArgs e) |
0 | 1143 { |
1144 CommandStack.Undo(); | |
1145 } | |
1146 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1147 protected virtual void redoTBButtonActivated(object sender, System.EventArgs e) |
0 | 1148 { |
1149 CommandStack.Redo(); | |
1150 } | |
1151 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1152 protected virtual void saveTBButtonActivated(object sender, System.EventArgs e) |
0 | 1153 { |
33 | 1154 SaveCurrentArmyOrSaveAs(); |
0 | 1155 } |
1156 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1157 protected virtual void openTBButtonActivated(object sender, System.EventArgs e) |
0 | 1158 { |
1159 OpenArmy(); | |
1160 } | |
1161 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1162 protected virtual void newTBButtonActivated(object sender, System.EventArgs e) |
0 | 1163 { |
1164 CreateNewArmy(); | |
1165 } | |
1166 | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1167 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 1168 { |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1169 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); |
21 | 1170 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1171 if (obj is WFObjects.Unit) |
0 | 1172 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1173 WFObjects.Unit unit = (WFObjects.Unit)obj; |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1174 ShowUnitWidget(unit); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1175 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1176 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1177 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1178 private void ShowUnitWidget(WFObjects.Unit unit) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1179 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1180 UnitDisplayWidget widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1181 unitToWidgetMap.TryGetValue(unit, out widget); |
21 | 1182 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1183 if (widget != null) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1184 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1185 logger.DebugFormat("Selecting existing page for " + unit.Name); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1186 unitsNotebook.Page = unitsNotebook.PageNum(widget); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1187 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1188 else |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1189 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1190 widget = new UnitDisplayWidget(unit, CommandStack); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1191 logger.Debug("Adding page for " + unit.Name); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1192 unitToWidgetMap[unit] = widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1193 int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1194 logger.Debug("Page added at index " + pageNum); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1195 unitsNotebook.ShowAll(); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1196 unitsNotebook.CurrentPage = pageNum; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1197 unitsNotebook.SetTabReorderable(widget, true); |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1198 } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1199 } |
28 | 1200 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1201 protected virtual void OnMiExportAsBasicHtmlActivated(object sender, System.EventArgs e) |
28 | 1202 { |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1203 string exportArmyTitle = Translation.GetTranslation("exportBasicHtmlDialogTitle", "export army"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1204 string cancelText = Translation.GetTranslation("exportBasicHtmlCancel", "cancel"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1205 string exportText = Translation.GetTranslation("exportBasicHtmlExport", "export"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1206 FileChooserDialog fileDialog = new FileChooserDialog(exportArmyTitle, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, exportText, ResponseType.Accept); |
28 | 1207 FileFilter filter = new FileFilter(); |
1208 filter.AddPattern("*.html"); | |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1209 filter.Name = Translation.GetTranslation("exportBasicHtmlHtmlFilter", "HTML pages (*.html)"); |
28 | 1210 fileDialog.AddFilter(filter); |
1211 int response = fileDialog.Run(); | |
1212 string filePath = null; | |
1213 | |
1214 if (response == (int)ResponseType.Accept) | |
1215 { | |
1216 filePath = fileDialog.Filename; | |
1217 } | |
1218 | |
1219 fileDialog.Hide(); | |
1220 fileDialog.Dispose(); | |
1221 | |
1222 if (filePath != null) | |
1223 { | |
1224 Army army = WarFoundryCore.CurrentArmy; | |
1225 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); | |
1226 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); | |
1227 } | |
1228 } | |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1229 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1230 protected virtual void OnTreeUnitsPopupMenu(object o, Gtk.PopupMenuArgs args) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1231 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1232 object selectedItem = TreeUtils.GetSelectedItem(treeUnits); |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1233 WFObjects.Unit theUnit = selectedItem as WFObjects.Unit; |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1234 |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1235 if (theUnit != null) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1236 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1237 Menu menu = new Menu(); |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1238 ImageMenuItem delete = new ImageMenuItem(Translation.GetTranslation("menuRemoveUnit", "remove unit")); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1239 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1240 delete.Activated += new EventHandler(OnUnitDelete); |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1241 delete.Data["unit"] = theUnit; |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1242 menu.Append(delete); |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1243 |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1244 if (theUnit.UnitType.ContainedUnitTypes.Length > 0) |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1245 { |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1246 ImageMenuItem addContained = new ImageMenuItem(Translation.GetTranslation("menuAddUnit", "add unit")); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1247 addContained.Image = new Gtk.Image(Stock.Add, IconSize.Menu); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1248 addContained.Activated += new EventHandler(OnSubUnitAdd); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1249 addContained.Data["unit"] = theUnit; |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1250 menu.Append(addContained); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1251 } |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1252 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1253 menu.ShowAll(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1254 menu.Popup(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1255 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1256 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1257 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1258 private void OnUnitDelete(object o, EventArgs args) |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1259 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1260 RemoveUnitCommand command = new RemoveUnitCommand((WFObjects.Unit)((ImageMenuItem)o).Data["unit"]); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1261 commandStack.Execute(command); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1262 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1263 |
162
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1264 void OnSubUnitAdd(object sender, EventArgs e) |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1265 { |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1266 WFObjects.Unit unit = (WFObjects.Unit)((ImageMenuItem)sender).Data["unit"]; |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1267 logger.DebugFormat("Show FrmNewUnit for contained units of {0}", unit.Name); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1268 FrmNewUnit newUnit = new FrmNewUnit(unit, WarFoundryCore.CurrentArmy); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1269 ResponseType response = (ResponseType)newUnit.Run(); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1270 newUnit.Hide(); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1271 |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1272 if (response == ResponseType.Ok) |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1273 { |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1274 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(newUnit.SelectedUnit.MainCategory), unit); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1275 commandStack.Execute(cmd); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1276 ShowUnitWidget(cmd.Unit); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1277 } |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1278 |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1279 newUnit.Dispose(); |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1280 } |
354c1d2ad086
Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents:
159
diff
changeset
|
1281 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1282 [GLib.ConnectBefore] |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1283 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1284 protected virtual void UnitTreeButtonPressed(object o, Gtk.ButtonPressEventArgs args) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1285 { |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1286 TreePath path; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1287 treeUnits.GetPathAtPos((int)args.Event.X, (int)args.Event.Y, out path); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1288 |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1289 if (!treeUnits.Selection.PathIsSelected(path)) |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1290 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1291 treeUnits.Selection.SelectPath(path); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1292 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1293 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1294 if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3) |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1295 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1296 OnTreeUnitsPopupMenu(o, null); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1297 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1298 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1299 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1300 protected virtual void NotebookPageRemoved(object o, Gtk.RemovedArgs args) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1301 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1302 Widget widget = args.Widget; |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1303 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1304 if (widget is UnitDisplayWidget) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1305 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1306 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1307 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1308 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1309 |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1310 protected virtual void HelpAboutActivated(object sender, System.EventArgs e) |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1311 { |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1312 FrmAbout form = FrmAbout.GetForm(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1313 form.Run(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1314 form.Hide(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1315 } |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1316 |
95
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1317 protected virtual void miPreferencesClicked(object sender, System.EventArgs e) |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1318 { |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1319 FrmPreferences form = new FrmPreferences(Preferences); |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1320 form.Run(); |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1321 form.Hide(); |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1322 } |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1323 |
103
1bd748721040
* Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
1324 public override ICollection<Gtk.Action> Actions |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1325 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1326 get |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1327 { |
103
1bd748721040
* Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
1328 List<Gtk.Action> actions = new List<Gtk.Action>(); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1329 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1330 foreach (ActionGroup actionGroup in this.UIManager.ActionGroups) |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1331 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1332 actions.AddRange(actionGroup.ListActions()); |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1333 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1334 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1335 return actions; |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1336 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1337 } |
123
f58f69ea2435
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
110
diff
changeset
|
1338 |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1339 protected void OnTransformedXmlActionActivated(object sender, System.EventArgs e) |
123
f58f69ea2435
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
110
diff
changeset
|
1340 { |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
123
diff
changeset
|
1341 FrmExportXml form = new FrmExportXml(WarFoundryCore.CurrentArmy); |
142
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
1342 form.ParentWindow = this.GdkWindow; |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
123
diff
changeset
|
1343 form.Run(); |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
123
diff
changeset
|
1344 form.Hide(); |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
123
diff
changeset
|
1345 form.Dispose(); |
123
f58f69ea2435
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
110
diff
changeset
|
1346 } |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1347 |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1348 protected void OnMiEditArmyActivated(object sender, System.EventArgs e) |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1349 { |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1350 FrmEditArmy form = new FrmEditArmy(commandStack, WarFoundryCore.CurrentArmy); |
142
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
1351 form.TransientFor = this; |
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
1352 form.WindowPosition = WindowPosition.CenterOnParent; |
138
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1353 form.Run(); |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1354 form.Hide(); |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1355 form.Dispose(); |
33962c2ef550
Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
1356 } |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1357 |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1358 protected void OnLblValidationWarningButtonReleaseEvent(object o, Gtk.ButtonReleaseEventArgs args) |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1359 { |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1360 if (args.Event.Button != (uint)MouseButton.Left) |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1361 { |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1362 return; |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1363 } |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1364 |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1365 ICollection<string> failureMessages = lblValidationWarning.Data[VALIDATION_RESULTS_KEY] as ICollection<string>; |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1366 |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1367 if (failureMessages != null && failureMessages.Count > 0) |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1368 { |
142
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
1369 ValidationFailureWidget failureWidget = new ValidationFailureWidget(failureMessages); |
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
1370 Dialog dialog = new SimpleDialog("Validation errors", this, DialogFlags.Modal, failureWidget); |
141
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1371 dialog.Run(); |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1372 dialog.Hide(); |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1373 dialog.Dispose(); |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1374 } |
1ce4fe9ae3c1
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
1375 } |
157
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1376 |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1377 protected void OnAddNewFileActionActivated(object sender, EventArgs e) |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1378 { |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1379 string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1380 string openText = Translation.GetTranslation("bttnOpen", "open"); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1381 FileChooserDialog fileDialog = new FileChooserDialog("Add data file", this, FileChooserAction.Open, cancelText, ResponseType.Cancel, openText, ResponseType.Accept); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1382 fileDialog.SelectMultiple = true; |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1383 FileFilter filter = new FileFilter(); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1384 filter.AddPattern("*.race"); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1385 filter.AddPattern("*.system"); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1386 filter.Name = "WarFoundry data files"; |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1387 fileDialog.AddFilter(filter); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1388 int response = fileDialog.Run(); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1389 string[] filePaths = fileDialog.Filenames; |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1390 fileDialog.Hide(); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1391 fileDialog.Dispose(); |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1392 |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1393 if (response == (int)ResponseType.Accept) |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1394 { |
159
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1395 List<Exception> exceptions = new List<Exception>(); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1396 |
157
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1397 foreach (string filePath in filePaths) |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1398 { |
159
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1399 try |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1400 { |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1401 WarFoundryLoader.AddNewDataFile(filePath); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1402 } |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1403 catch (Exception ex) |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1404 { |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1405 exceptions.Add(ex); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1406 } |
157
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1407 } |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1408 |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1409 WarFoundryLoader.GetDefault().LoadFiles(); |
159
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1410 |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1411 if (exceptions.Count > 0) |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1412 { |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1413 string errorMsg = MakeAddDataFileFailedMessage(exceptions); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1414 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, errorMsg); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1415 dialog.Run(); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1416 dialog.Hide(); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1417 dialog.Dispose(); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1418 } |
157
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1419 } |
2d1dd73a3289
Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
1420 } |
159
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1421 |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1422 private string MakeAddDataFileFailedMessage(List<Exception> exceptions) |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1423 { |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1424 StringBuilder sb = new StringBuilder(); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1425 sb.Append("errors occurred while adding the new data files: "); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1426 |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1427 foreach (Exception ex in exceptions) |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1428 { |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1429 sb.Append("\n\t• "); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1430 sb.Append(ex.Message); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1431 } |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1432 |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1433 return sb.ToString(); |
89e2442bbb60
Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
1434 } |
0 | 1435 } |
1436 } |