Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmMainWindow.cs @ 57:293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
* Make enabling/disabling fit the values passed (copied from existing WinForms checks)
* Add extra interface methods and properties to get necessary values from UI to use in command
* Implement new interface methods
* Implement command execution
* Make use of IDisposable interface instead of defining Dispose ourselves
Also:
* Use existing method of printing exception stack traces in main window
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 26 Aug 2010 19:30:22 +0000 |
parents | 4bad8cb3f889 |
children | e3fe48c4d794 |
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 |
5 using System; | |
6 using System.IO; | |
7 using System.Collections.Generic; | |
8 using System.Configuration; | |
13 | 9 using Gtk; |
10 using IBBoard; | |
0 | 11 using IBBoard.Commands; |
12
685532d43a96
Re #88: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
10
diff
changeset
|
12 using IBBoard.GtkSharp; |
0 | 13 using IBBoard.IO; |
13 | 14 using IBBoard.Lang; |
15 using IBBoard.Logging; | |
0 | 16 using IBBoard.CustomMath; |
17 using IBBoard.WarFoundry.API; | |
28 | 18 using IBBoard.WarFoundry.API.Exporters; |
0 | 19 using IBBoard.WarFoundry.API.Factories; |
13 | 20 using IBBoard.WarFoundry.API.Factories.Xml; |
21 using IBBoard.WarFoundry.API.Objects; | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
22 using WFObjects = IBBoard.WarFoundry.API.Objects; |
0 | 23 using IBBoard.WarFoundry.API.Commands; |
24 using IBBoard.WarFoundry.API.Savers; | |
25 using IBBoard.WarFoundry.API.Requirements; | |
6
cfc7683e73f9
Fix breakage from r33 by completing update of move to IBBoard.WarFoundry.GTK sub-packages
IBBoard <dev@ibboard.co.uk>
parents:
5
diff
changeset
|
26 using IBBoard.WarFoundry.GTK.Widgets; |
13 | 27 using IBBoard.WarFoundry.Plugin.Rollcall; |
0 | 28 using IBBoard.Xml; |
29 using log4net; | |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
30 using GLib; |
0 | 31 |
13 | 32 namespace IBBoard.WarFoundry.GTK |
21 | 33 { |
0 | 34 public partial class FrmMainWindow: Gtk.Window |
35 { | |
36 private static readonly string AppTitle = "WarFoundry"; | |
13 | 37 private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6; |
38 | |
39 private Preferences preferences; | |
40 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); | |
41 | |
0 | 42 private CommandStack commandStack; |
43 private Dictionary<ToolButton, Category> categoryMap = new Dictionary<ToolButton, Category>(); | |
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 |
46 private ObjectAddDelegate UnitAddedMethod; | |
47 private ObjectRemoveDelegate UnitRemovedMethod; | |
48 private DoubleValChangedDelegate PointsValueChangedMethod; | |
0 | 49 private FailedUnitRequirementDelegate FailedUnitRequirementMethod; |
50 private StringValChangedDelegate UnitNameChangedMethod; | |
21 | 51 |
0 | 52 private GameSystem system; |
53 private string loadedArmyPath; | |
21 | 54 |
0 | 55 private MenuToolButton undoMenuButton, redoMenuButton; |
21 | 56 |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
57 public static void Main(string[] args) |
21 | 58 { |
13 | 59 try |
0 | 60 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
61 ExceptionManager.UnhandledException += HandleUnhandledException; |
0 | 62 Application.Init(); |
63 FrmMainWindow win = new FrmMainWindow(args); | |
64 win.Show(); | |
65 Application.Run(); | |
13 | 66 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); |
67 } | |
68 catch(Exception ex) | |
69 { | |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
70 HandleUnhandledException(ex); |
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 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
73 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
74 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
|
75 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
76 object obj = args.ExceptionObject; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
77 Exception ex = null; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
78 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
79 if (obj is Exception) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
80 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
81 ex = (Exception)obj; |
0 | 82 } |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
83 else |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
84 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
85 ex = new Exception("GLib returned unexpected exception object type "+obj.GetType()); |
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 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
88 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
89 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
90 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
91 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
|
92 { |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 dialog.Run(); |
0 | 97 } |
52
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
98 |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
99 private static string GetStackTrace(Exception ex) |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
100 { |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
101 string message = ""; |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
102 |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
103 if (ex != null) |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
104 { |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
105 message = "Caused by: " + ex.GetType().FullName + Environment.NewLine + ex.StackTrace + Environment.NewLine ; |
52
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
106 } |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
107 |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
108 return message; |
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
109 } |
21 | 110 |
0 | 111 public FrmMainWindow() : this(new string[0]) |
112 { | |
113 //Do nothing extra | |
114 } | |
21 | 115 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
116 public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel) |
0 | 117 { |
118 logger.Info("Opening FrmMainWindow"); | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
119 Build(); |
0 | 120 //Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support |
121 redoMenuButton = new MenuToolButton("gtk-redo"); | |
122 redoMenuButton.Label = "Redo"; | |
10
c687bbe901f8
Re #37 - Resolve deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
123 redoMenuButton.TooltipText = "Redo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
124 redoMenuButton.Clicked += redoTBButtonActivated; |
0 | 125 toolbar.Insert(redoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
126 undoMenuButton = new MenuToolButton("gtk-undo"); | |
127 undoMenuButton.Label = "Undo"; | |
10
c687bbe901f8
Re #37 - Resolve deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
128 undoMenuButton.TooltipText = "Undo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
129 undoMenuButton.Clicked += undoTBButtonActivated; |
0 | 130 toolbar.Insert(undoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
131 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX-1]); | |
132 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX-2]); | |
133 toolbar.ShowAll(); | |
21 | 134 |
0 | 135 Title = AppTitle; |
136 TreeViewColumn mainColumn = new TreeViewColumn (); | |
137 mainColumn.Title = "Army Categories"; | |
138 CellRendererText mainCell = new CellRendererText (); | |
139 mainColumn.PackStart (mainCell, true); | |
140 treeUnits.AppendColumn(mainColumn); | |
141 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderCategoryTreeObjectName)); | |
142 treeUnits.Model = new TreeStore(typeof(WarFoundryObject)); | |
143 logger.Debug("Loading preferences"); | |
144 Preferences = new Preferences("WarFoundryGTK"); | |
145 logger.Debug("Loading translations"); | |
21 | 146 |
8
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
147 try |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
148 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
149 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
150 } |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
151 catch (TranslationLoadException ex) |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
152 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
153 logger.Error(ex); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
154 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
|
155 dialog.Title = "Translation loading failed"; |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
156 dialog.Run(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
157 dialog.Destroy(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
158 } |
21 | 159 |
13 | 160 logger.Debug("Initialising"); |
161 commandStack = new CommandStack(); | |
0 | 162 commandStack.CommandStackUpdated+=new MethodInvoker(commandStack_CommandStackUpdated); |
163 WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(OnGameSystemChanged); | |
164 WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(OnArmyChanged); | |
165 Destroyed+= new EventHandler(OnWindowDestroyed); | |
166 //TODO: Translate and subscribe to other events | |
13 | 167 UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded); |
168 UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved); | |
169 PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged); | |
0 | 170 FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement); |
171 UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged); | |
21 | 172 |
18
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
173 //FIXME: Temporary hack to add paths and factories before we get preferences and plugins |
0 | 174 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + "data")); |
18
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
175 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); |
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
176 WarFoundryLoader.GetDefault().RegisterNonNativeFactory(RollcallFactory.GetFactory()); |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
177 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; |
21 | 178 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); |
179 | |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
180 logger.Debug("Initialising complete - seeing if we can load default army or system"); |
21 | 181 |
0 | 182 if (args.Length == 1) |
183 { | |
21 | 184 logger.Debug("Attempting to load from file"); |
0 | 185 FileInfo file = new FileInfo(args[0]); |
21 | 186 |
0 | 187 try |
188 { | |
5 | 189 ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file); |
190 | |
191 if (objects.Count == 1) | |
0 | 192 { |
5 | 193 List<IWarFoundryObject> objectList = new List<IWarFoundryObject>(); |
194 objectList.AddRange(objects); | |
195 IWarFoundryObject loadedObject = objectList[0]; | |
21 | 196 |
5 | 197 if (loadedObject is Army) |
198 { | |
199 WarFoundryCore.CurrentArmy = (Army)loadedObject; | |
200 logger.InfoFormat("Loaded army from {0}", file.FullName); | |
201 } | |
202 else if (loadedObject is GameSystem) | |
203 { | |
204 WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject; | |
205 logger.InfoFormat("Loaded game system from {0}", file.FullName); | |
206 } | |
0 | 207 } |
208 } | |
209 catch (InvalidFileException ex) | |
210 { | |
211 //TODO: show error dialog | |
212 logger.Error(ex); | |
213 } | |
214 } | |
215 else | |
216 { | |
217 string gameSystemID = Preferences.GetStringProperty("currSystem"); | |
218 | |
219 if (gameSystemID!=null && !"".Equals(gameSystemID)) | |
220 { | |
221 logger.Debug("Attempting to load current game system from properties"); | |
222 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); | |
21 | 223 |
0 | 224 if (sys!=null) |
225 { | |
226 WarFoundryCore.CurrentGameSystem = sys; | |
227 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); | |
228 } | |
229 } | |
230 } | |
231 } | |
21 | 232 |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
233 private void FileLoadingFinished (List<FileLoadFailure> failures) |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
234 { |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
235 foreach(FileLoadFailure failure in failures) |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
236 { |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
237 logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
238 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
239 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
240 |
0 | 241 private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
242 { | |
243 object o = model.GetValue(iter, 0); | |
21 | 244 |
0 | 245 if (o is ArmyCategory) |
246 { | |
247 ArmyCategory c = (ArmyCategory)o; | |
248 string name = ""; | |
21 | 249 |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
250 if (!Preferences.GetBooleanProperty("ShowCatPercentage")) |
0 | 251 { |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
252 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}pts", c.Name, c.Points); |
0 | 253 } |
254 else | |
255 { | |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
256 name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}pts ({2}%)", c.Name, c.Points, (c.ParentArmy.Points > 0 ? Math.Round((c.Points / c.ParentArmy.Points) * 100) : 0)); |
0 | 257 } |
21 | 258 |
0 | 259 (cell as CellRendererText).Text = name; |
260 } | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
261 else if (o is WFObjects.Unit) |
0 | 262 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
263 WFObjects.Unit u = (WFObjects.Unit)o; |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
264 string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}pts", u.Name, u.Points); |
0 | 265 (cell as CellRendererText).Text = name; |
266 } | |
267 } | |
21 | 268 |
0 | 269 private void OnWindowDestroyed(object source, EventArgs args) |
270 { | |
271 logger.Info("Exiting"); | |
272 Application.Quit(); | |
273 } | |
21 | 274 |
0 | 275 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue) |
276 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
277 WFObjects.Unit unit = (WFObjects.Unit)val; |
0 | 278 UnitDisplayWidget widget; |
279 unitToWidgetMap.TryGetValue(unit, out widget); | |
41
a32b6bb7f1eb
Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
280 logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name); |
a32b6bb7f1eb
Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
281 treeUnits.QueueDraw(); |
21 | 282 |
0 | 283 if (widget!=null) |
284 { | |
26
3a396783bfed
Fixes #125: Tabs lose close buttons
IBBoard <dev@ibboard.co.uk>
parents:
25
diff
changeset
|
285 unitsNotebook.SetTabLabel(widget, NotebookUtil.CreateNotebookTabLabelWithClose(unitsNotebook, widget, newValue)); |
0 | 286 } |
287 } | |
21 | 288 |
0 | 289 private void OnUnitAdded(WarFoundryObject val) |
290 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
291 WFObjects.Unit unit = (WFObjects.Unit)val; |
0 | 292 unit.NameChanged+= UnitNameChangedMethod; |
293 AddUnitToTree(unit); | |
294 } | |
21 | 295 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
296 private void AddUnitToTree(WFObjects.Unit unit) |
0 | 297 { |
298 TreeStore model = (TreeStore)treeUnits.Model; | |
299 TreeIter iter; | |
300 model.GetIterFirst(out iter); | |
21 | 301 |
0 | 302 do |
303 { | |
304 object obj = model.GetValue(iter, 0); | |
21 | 305 |
0 | 306 if (obj is ArmyCategory) |
307 { | |
308 ArmyCategory cat = (ArmyCategory)obj; | |
21 | 309 |
0 | 310 if (cat.Equals(unit.Category)) |
311 { | |
312 model.AppendValues(iter, unit); | |
313 TreePath path = model.GetPath(iter); | |
314 treeUnits.ExpandToPath(path); | |
315 } | |
316 } | |
317 } | |
318 while (model.IterNext(ref iter)); | |
319 } | |
21 | 320 |
0 | 321 private void OnUnitRemoved(WarFoundryObject obj) |
322 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
323 WFObjects.Unit unit = (WFObjects.Unit)obj; |
0 | 324 unit.NameChanged-= UnitNameChangedMethod; |
325 RemoveUnitFromTree(unit); | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
326 RemoveUnitTab(unit); |
0 | 327 } |
21 | 328 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
329 private void RemoveUnitFromTree(WFObjects.Unit unit) |
0 | 330 { |
331 TreeStore model = (TreeStore)treeUnits.Model; | |
332 TreeIter iter; | |
333 model.GetIterFirst(out iter); | |
334 bool removed = false; | |
21 | 335 |
0 | 336 do |
337 { | |
338 object obj = model.GetValue(iter, 0); | |
21 | 339 |
0 | 340 if (obj is ArmyCategory) |
341 { | |
342 ArmyCategory cat = (ArmyCategory)obj; | |
21 | 343 |
0 | 344 if (unit.Category == null || cat.Equals(unit.Category)) |
345 { | |
346 TreeIter innerIter; | |
347 model.IterChildren(out innerIter, iter); | |
21 | 348 |
0 | 349 do |
350 { | |
351 object innerObj = model.GetValue(innerIter, 0); | |
21 | 352 |
0 | 353 if (unit.Equals(innerObj)) |
354 { | |
355 model.Remove(ref innerIter); | |
356 removed = true; | |
357 break; | |
358 } | |
359 } | |
360 while (model.IterNext(ref innerIter)); | |
21 | 361 |
0 | 362 if (removed) |
363 { | |
364 break; | |
365 } | |
366 } | |
367 } | |
368 } | |
369 while (model.IterNext(ref iter)); | |
370 } | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
371 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
372 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
|
373 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
374 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
|
375 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
376 if (widget != null) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
377 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
378 unitsNotebook.Remove(widget); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
379 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
380 } |
21 | 381 |
0 | 382 private void OnPointsValueChanged(WarFoundryObject obj, double before, double after) |
383 { | |
384 //Set points in panel | |
385 } | |
21 | 386 |
0 | 387 private void OnFailedUnitRequirement(List<FailedUnitRequirement> failedRequirement) |
388 { | |
389 //Show error message in panel | |
390 } | |
21 | 391 |
0 | 392 public Preferences Preferences |
393 { | |
394 get { return preferences; } | |
21 | 395 set { preferences = value; } |
0 | 396 } |
21 | 397 |
0 | 398 /*public AbstractNativeWarFoundryFactory Factory |
399 { | |
400 get { return WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(Constants.ExecutablePath, factoryType); } | |
401 }*/ | |
21 | 402 |
0 | 403 protected void OnDeleteEvent (object sender, DeleteEventArgs a) |
404 { | |
405 Application.Quit (); | |
406 a.RetVal = true; | |
407 } | |
408 | |
409 protected virtual void OnExitActivated(object sender, System.EventArgs e) | |
410 { | |
411 Application.Quit(); | |
412 } | |
413 | |
414 protected virtual void OnCreateArmyActivated(object sender, System.EventArgs e) | |
415 { | |
416 CreateNewArmy(); | |
417 } | |
418 | |
419 protected virtual void OnReloadFilesActivated(object sender, System.EventArgs e) | |
420 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
421 WarFoundryLoader.GetDefault().LoadFiles(); |
0 | 422 } |
423 | |
424 protected virtual void OnSaveArmyAsActivated(object sender, System.EventArgs e) | |
425 { | |
426 SaveCurrentArmyAs(); | |
427 } | |
428 | |
429 protected virtual void OnCloseArmyActivated(object sender, System.EventArgs e) | |
430 { | |
431 CloseCurrentArmy(); | |
432 } | |
433 | |
434 protected virtual void OnOpenArmyActivated(object sender, System.EventArgs e) | |
435 { | |
436 OpenArmy(); | |
437 } | |
438 | |
439 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e) | |
440 { | |
33 | 441 SaveCurrentArmyOrSaveAs(); |
0 | 442 } |
21 | 443 |
0 | 444 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e) |
445 { | |
446 if (sender is ToolButton) | |
447 { | |
448 Category cat = null; | |
449 categoryMap.TryGetValue((ToolButton)sender, out cat); | |
21 | 450 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
451 if (cat != null) |
0 | 452 { |
453 logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name); | |
454 FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy); | |
455 ResponseType response = (ResponseType)newUnit.Run(); | |
456 newUnit.Hide(); | |
21 | 457 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
458 if (response == ResponseType.Ok) |
0 | 459 { |
14
abbf8a3ac431
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
460 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat)); |
0 | 461 commandStack.Execute(cmd); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
462 ShowUnitWidget(cmd.Unit); |
0 | 463 } |
21 | 464 |
0 | 465 newUnit.Dispose(); |
466 } | |
467 } | |
468 } | |
21 | 469 |
13 | 470 public CommandStack CommandStack |
471 { | |
472 get { return commandStack; } | |
0 | 473 } |
21 | 474 |
0 | 475 private void SetAppTitle() |
476 { | |
477 if (WarFoundryCore.CurrentArmy!=null) | |
478 { | |
479 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name; | |
480 } | |
481 else if (WarFoundryCore.CurrentGameSystem!=null) | |
482 { | |
483 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name; | |
484 } | |
485 else | |
486 { | |
487 Title = AppTitle; | |
488 } | |
489 } | |
21 | 490 |
0 | 491 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys) |
492 { | |
493 system = newSys; | |
494 SetAppTitle(); | |
495 RemoveCategoryButtons(); | |
21 | 496 |
0 | 497 if (system!=null) |
498 { | |
499 AddCategoryButtons(system.Categories); | |
500 } | |
501 } | |
21 | 502 |
0 | 503 private void OnArmyChanged(Army oldArmy, Army newArmy) |
504 { | |
505 loadedArmyPath = null; | |
506 SetAppTitle(); | |
507 SetArmyTree(newArmy); | |
21 | 508 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
509 if (oldArmy != null) |
13 | 510 { |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
511 oldArmy.UnitAdded -= UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
512 oldArmy.UnitRemoved -= UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
513 oldArmy.PointsValueChanged -= PointsValueChangedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
514 oldArmy.FailedRequirement -= FailedUnitRequirementMethod; |
0 | 515 } |
21 | 516 |
0 | 517 unitToWidgetMap.Clear(); |
21 | 518 |
0 | 519 while (unitsNotebook.NPages > 0) |
520 { | |
521 unitsNotebook.RemovePage(0); | |
522 } | |
21 | 523 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
524 if (newArmy == null) |
13 | 525 { |
526 DisableCategoryButtons(); | |
527 } | |
528 else | |
529 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
530 newArmy.UnitAdded += UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
531 newArmy.UnitRemoved += UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
532 newArmy.PointsValueChanged += PointsValueChangedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
533 newArmy.FailedRequirement += FailedUnitRequirementMethod; |
13 | 534 //TODO: Clear all buttons |
535 EnableCategoryButtons(); | |
536 | |
537 if (newArmy.Race.HasCategoryOverrides()) | |
538 { | |
539 RemoveCategoryButtons(); | |
540 AddCategoryButtons(newArmy.Race.Categories); | |
541 } | |
0 | 542 } |
21 | 543 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
544 bool nonNullNewArmy = (newArmy != null); |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
545 miCloseArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
546 miSaveArmyAs.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
547 miExportArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
548 hpaned2.Visible = nonNullNewArmy; |
33 | 549 loadedArmyPath = null; |
0 | 550 //New army has no changes, so we can't save it |
551 miSaveArmy.Sensitive = false; | |
13 | 552 saveArmyButton.Sensitive = false; |
553 | |
554 CommandStack.Reset(); | |
0 | 555 SetPointsPanelText(); |
556 } | |
21 | 557 |
0 | 558 private void SetArmyTree(Army army) |
559 { | |
560 logger.Debug("Resetting tree"); | |
561 TreeStore store = (TreeStore)treeUnits.Model; | |
562 store.Clear(); | |
563 TreeIter iter; | |
21 | 564 |
0 | 565 if (army!=null) |
566 { | |
567 logger.Debug("Loading in categories to tree"); | |
21 | 568 |
0 | 569 foreach (ArmyCategory cat in army.Categories) |
570 { | |
571 logger.DebugFormat("Append category {0}", cat.Name); | |
572 iter = store.AppendValues(cat); | |
21 | 573 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
574 foreach (WFObjects.Unit unit in cat.GetUnits()) |
0 | 575 { |
576 store.AppendValues(iter, unit); | |
21 | 577 } |
0 | 578 } |
21 | 579 |
0 | 580 logger.Debug("Finished loading tree categories"); |
581 } | |
582 } | |
21 | 583 |
0 | 584 private void DisableCategoryButtons() |
585 { | |
586 SetCategoryButtonsSensitive(false); | |
587 } | |
21 | 588 |
0 | 589 private void EnableCategoryButtons() |
590 { | |
591 SetCategoryButtonsSensitive(true); | |
592 } | |
21 | 593 |
0 | 594 private void SetCategoryButtonsSensitive(bool state) |
595 { | |
596 int toolbarButtonCount = toolbar.Children.Length - 1; | |
597 logger.Debug("Last button index: "+toolbarButtonCount); | |
21 | 598 |
0 | 599 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
600 { | |
601 logger.DebugFormat("Setting button {0} state to {1}", i, state); | |
602 toolbar.Children[i].Sensitive = state; | |
603 } | |
604 } | |
21 | 605 |
0 | 606 private void RemoveCategoryButtons() |
607 { | |
608 int toolbarButtonCount = toolbar.Children.Length - 1; | |
21 | 609 |
0 | 610 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
611 { | |
612 toolbar.Remove(toolbar.Children[i]); | |
613 } | |
21 | 614 |
0 | 615 categoryMap.Clear(); |
616 } | |
21 | 617 |
0 | 618 private void AddCategoryButtons(Category[] cats) |
619 { | |
620 if (cats!=null && cats.Length > 0) | |
621 { | |
622 logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length); | |
21 | 623 |
0 | 624 foreach (Category cat in cats) |
625 { | |
626 ToolButton button = new ToolButton("gtk-add"); | |
627 button.Label = cat.Name; | |
10
c687bbe901f8
Re #37 - Resolve deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
628 button.TooltipText = "Add unit from "+cat.Name; |
0 | 629 //TODO: See if we can associate data in some way, the same as we can with SWF. For now we just use the map. |
630 categoryMap.Add(button, cat); | |
631 button.Clicked+= new System.EventHandler(OnAddUnitActivated); | |
632 toolbar.Insert(button, -1); | |
633 } | |
634 } | |
21 | 635 |
0 | 636 toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats!=null && cats.Length>0; |
21 | 637 |
0 | 638 toolbar.ShowAll(); |
639 } | |
21 | 640 |
0 | 641 private void SetPointsPanelText() |
642 { | |
643 //TODO: Set the points value in the status bar | |
644 } | |
21 | 645 |
13 | 646 private void commandStack_CommandStackUpdated() |
647 { | |
648 undoMenuButton.Sensitive = commandStack.CanUndo(); | |
649 miUndo.Sensitive = undoMenuButton.Sensitive; | |
650 redoMenuButton.Sensitive = commandStack.CanRedo(); | |
651 miRedo.Sensitive = redoMenuButton.Sensitive; | |
0 | 652 int redoLength = commandStack.RedoLength; |
21 | 653 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
654 int maxRedo = Math.Min(10, redoLength); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
655 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
656 //TODO: Add tooltips |
13 | 657 if (redoLength > 0) |
658 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
659 Menu menu = new Menu(); |
13 | 660 Command com; |
661 MenuItem mi; | |
662 | |
663 for (int i = 0; i < maxRedo; i++) | |
664 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
665 com = commandStack.PeekRedoCommand(i + 1); |
13 | 666 |
667 if (com == null) | |
668 { | |
21 | 669 break; |
13 | 670 } |
671 | |
672 mi = new MenuItem(com.Description); | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
673 mi.Activated += new EventHandler(RedoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
674 menu.Append(mi); |
13 | 675 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
676 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
677 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
678 redoMenuButton.Menu = menu; |
13 | 679 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
680 else |
13 | 681 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
682 redoMenuButton.Menu = null; |
13 | 683 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
684 |
13 | 685 int undoLength = commandStack.UndoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
686 int maxUndo = Math.Min(10, undoLength); |
21 | 687 |
13 | 688 if (undoLength > 0) |
689 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
690 Menu menu = new Menu(); |
13 | 691 Command com; |
692 MenuItem mi; | |
693 | |
694 for (int i = 0; i < maxUndo; i++) | |
695 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
696 com = commandStack.PeekUndoCommand(i + 1); |
13 | 697 |
698 if (com == null) | |
699 { | |
21 | 700 break; |
13 | 701 } |
702 | |
703 mi = new MenuItem(com.UndoDescription); | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
704 mi.Activated += new EventHandler(UndoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
705 menu.Add(mi); |
13 | 706 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
707 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
708 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
709 undoMenuButton.Menu = menu; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
710 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
711 else |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
712 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
713 undoMenuButton.Menu = null; |
13 | 714 } |
715 | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
716 saveArmyButton.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
717 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
718 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
719 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
720 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
|
721 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
722 if (sender is MenuItem) |
13 | 723 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
724 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
725 //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
|
726 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
727 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
|
728 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
729 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
730 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
731 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
|
732 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
733 commandStack.Redo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
734 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
735 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
736 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
737 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
738 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
739 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
|
740 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
741 if (sender is MenuItem) |
0 | 742 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
743 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
744 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
745 //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
|
746 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
747 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
|
748 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
749 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
750 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
751 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
|
752 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
753 commandStack.Undo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
754 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
755 } |
0 | 756 } |
13 | 757 } |
758 | |
759 private bool SaveCurrentArmyOrSaveAs() | |
760 { | |
33 | 761 if (loadedArmyPath != null) |
13 | 762 { |
763 return SaveCurrentArmy(); | |
764 } | |
21 | 765 else |
13 | 766 { |
767 return SaveCurrentArmyAs(); | |
768 } | |
0 | 769 } |
21 | 770 |
0 | 771 private bool OpenArmy() |
772 { | |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
773 FileChooserDialog fileDialog = new FileChooserDialog("Open army", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
774 FileFilter filter = new FileFilter(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
775 filter.AddPattern("*.army"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
776 filter.Name = "WarFoundry Army files (*.army)"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
777 fileDialog.AddFilter(filter); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
778 int response = fileDialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
779 string filePath = null; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
780 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
781 if (response == (int)ResponseType.Accept) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
782 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
783 filePath = fileDialog.Filename; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
784 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
785 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
786 fileDialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
787 fileDialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
788 |
0 | 789 bool success = false; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
790 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
791 if (filePath != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
792 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
793 FileInfo file = new FileInfo(filePath); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
794 Army army = WarFoundryLoader.GetDefault().LoadArmy(file); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
795 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
796 if (army != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
797 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
798 logger.Debug("Loaded army " + army.ID); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
799 success = true; |
33 | 800 WarFoundryCore.CurrentArmy = army; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
801 loadedArmyPath = filePath; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
802 logger.Debug("Army loading complete"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
803 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
804 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
805 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
806 logger.ErrorFormat("Failed to load {0} as an army file", filePath); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
807 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, file.Name + " could not be loaded.\n\nIf the file is an army file then please check your file loaders."); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
808 dialog.Title = "Failed to open army"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
809 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
810 dialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
811 dialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
812 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
813 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
814 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
815 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
816 logger.Debug("Army open requested but cancelled"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
817 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
818 |
0 | 819 return success; |
13 | 820 } |
821 | |
822 private bool SaveCurrentArmy() | |
0 | 823 { |
824 bool success = false; | |
21 | 825 |
33 | 826 if (loadedArmyPath!=null) |
0 | 827 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
828 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); |
0 | 829 } |
21 | 830 |
13 | 831 return success; |
832 } | |
833 | |
834 private bool SaveCurrentArmyAs() | |
835 { | |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
836 FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
837 FileFilter filter = new FileFilter(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
838 filter.AddPattern("*.army"); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
839 filter.Name = "WarFoundry Army files (*.army)"; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
840 fileDialog.AddFilter(filter); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
841 int response = fileDialog.Run(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
842 string filePath = null; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
843 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
844 if (response == (int)ResponseType.Accept) |
13 | 845 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
846 filePath = fileDialog.Filename; |
13 | 847 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
848 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
849 fileDialog.Hide(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
850 fileDialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
851 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
852 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
853 } |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
854 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
855 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
|
856 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
857 bool success = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
858 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
859 if (filePath!=null) |
13 | 860 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
861 if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, filePath)) |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
862 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
863 miSaveArmy.Sensitive = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
864 saveArmyButton.Sensitive = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
865 CommandStack.setCleanMark(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
866 loadedArmyPath = filePath; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
867 success = true; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
868 } |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
869 else |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
870 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
871 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to "+filePath); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
872 dialog.Title = "Army save failed"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
873 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
874 dialog.Hide(); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
875 dialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
876 } |
21 | 877 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
878 //else user cancelled |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
879 |
21 | 880 return success; |
0 | 881 } |
21 | 882 |
13 | 883 private bool CloseCurrentArmy() |
884 { | |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
885 if (WarFoundryCore.CurrentArmy != null) |
13 | 886 { |
887 bool canClose = false; | |
888 | |
889 if (CommandStack.IsDirty()) | |
0 | 890 { |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
891 MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo, "The army \"" + WarFoundryCore.CurrentArmy.Name + "\" has been modified.\r\nSave changes before closing army?"); |
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
892 dia.AddButton("Cancel", ResponseType.Cancel); |
0 | 893 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
|
894 dia.Hide(); |
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
895 dia.Dispose(); |
0 | 896 |
13 | 897 if (dr == ResponseType.Yes) |
0 | 898 { |
899 //They want to save so try to save it or prompt for save as | |
13 | 900 //If they cancel the save as then assume they don't want to close |
901 canClose = SaveCurrentArmyOrSaveAs(); | |
902 } | |
903 else if (dr == ResponseType.No) | |
0 | 904 { |
13 | 905 //They don't care about their changes |
906 canClose = true; | |
0 | 907 } |
908 else | |
909 { | |
910 //Assume cancel or close with the X button | |
911 canClose = false; | |
912 } | |
13 | 913 } |
914 else | |
915 { | |
916 //Nothing has changed so we can safely close | |
917 canClose = true; | |
918 } | |
919 | |
920 if (canClose) | |
0 | 921 { |
13 | 922 //do close |
923 WarFoundryCore.CurrentArmy = null; | |
924 return true; | |
925 } | |
926 else | |
927 { | |
928 return false; | |
929 } | |
930 } | |
931 else | |
932 { | |
933 //pretend we succeeded | |
934 return true; | |
935 } | |
936 } | |
937 | |
938 private void CreateNewArmy() | |
0 | 939 { |
940 logger.Debug("Create new army"); | |
941 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem); | |
942 ResponseType type = (ResponseType)newArmy.Run(); | |
943 newArmy.Hide(); | |
21 | 944 |
0 | 945 if (type == ResponseType.Ok) |
13 | 946 { |
947 if (CloseCurrentArmy()) | |
0 | 948 { |
949 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); | |
950 } | |
951 } | |
952 else | |
953 { | |
954 logger.Debug("Create new army cancelled"); | |
955 } | |
21 | 956 |
13 | 957 newArmy.Destroy(); |
0 | 958 } |
21 | 959 |
0 | 960 protected virtual void undoTBButtonActivated (object sender, System.EventArgs e) |
961 { | |
962 CommandStack.Undo(); | |
963 } | |
964 | |
965 protected virtual void redoTBButtonActivated (object sender, System.EventArgs e) | |
966 { | |
967 CommandStack.Redo(); | |
968 } | |
969 | |
970 protected virtual void saveTBButtonActivated (object sender, System.EventArgs e) | |
971 { | |
33 | 972 SaveCurrentArmyOrSaveAs(); |
0 | 973 } |
974 | |
975 protected virtual void openTBButtonActivated (object sender, System.EventArgs e) | |
976 { | |
977 OpenArmy(); | |
978 } | |
979 | |
980 protected virtual void newTBButtonActivated (object sender, System.EventArgs e) | |
981 { | |
982 CreateNewArmy(); | |
983 } | |
984 | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
985 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 986 { |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
987 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); |
21 | 988 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
989 if (obj is WFObjects.Unit) |
0 | 990 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
991 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
|
992 ShowUnitWidget(unit); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
993 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
994 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
995 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
996 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
|
997 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
998 UnitDisplayWidget widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
999 unitToWidgetMap.TryGetValue(unit, out widget); |
21 | 1000 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1001 if (widget != null) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1002 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1003 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
|
1004 unitsNotebook.Page = unitsNotebook.PageNum(widget); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1005 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1006 else |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1007 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1008 widget = new UnitDisplayWidget(unit, CommandStack); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1009 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
|
1010 unitToWidgetMap[unit] = widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1011 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
|
1012 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
|
1013 unitsNotebook.ShowAll(); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1014 unitsNotebook.CurrentPage = pageNum; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1015 unitsNotebook.SetTabReorderable(widget, true); |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1016 } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1017 } |
28 | 1018 |
1019 protected virtual void OnMiExportAsBasicHtmlActivated (object sender, System.EventArgs e) | |
1020 { | |
1021 FileChooserDialog fileDialog = new FileChooserDialog("Export army", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Export", ResponseType.Accept); | |
1022 FileFilter filter = new FileFilter(); | |
1023 filter.AddPattern("*.html"); | |
1024 filter.Name = "HTML pages (*.html)"; | |
1025 fileDialog.AddFilter(filter); | |
1026 int response = fileDialog.Run(); | |
1027 string filePath = null; | |
1028 | |
1029 if (response == (int)ResponseType.Accept) | |
1030 { | |
1031 filePath = fileDialog.Filename; | |
1032 } | |
1033 | |
1034 fileDialog.Hide(); | |
1035 fileDialog.Dispose(); | |
1036 | |
1037 if (filePath != null) | |
1038 { | |
1039 Army army = WarFoundryCore.CurrentArmy; | |
1040 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); | |
1041 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); | |
1042 } | |
1043 } | |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1044 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1045 protected virtual void OnTreeUnitsPopupMenu (object o, Gtk.PopupMenuArgs args) |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1046 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1047 object selectedItem = TreeUtils.GetSelectedItem(treeUnits); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1048 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1049 if (selectedItem is WFObjects.Unit) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1050 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1051 Menu menu = new Menu(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1052 ImageMenuItem delete = new ImageMenuItem("Remove unit"); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1053 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1054 delete.Activated+= new EventHandler(OnUnitDelete); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1055 delete.Data["unit"] = selectedItem; |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1056 menu.Append(delete); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1057 menu.ShowAll(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1058 menu.Popup(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1059 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1060 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1061 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1062 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
|
1063 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1064 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
|
1065 commandStack.Execute(command); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1066 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1067 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1068 [GLib.ConnectBefore] |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1069 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
|
1070 { |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1071 TreePath path; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1072 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
|
1073 |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1074 if (!treeUnits.Selection.PathIsSelected(path)) |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1075 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1076 treeUnits.Selection.SelectPath(path); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1077 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1078 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1079 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
|
1080 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1081 OnTreeUnitsPopupMenu(o, null); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1082 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1083 } |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1084 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1085 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
|
1086 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1087 Widget widget = args.Widget; |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1088 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1089 if (widget is UnitDisplayWidget) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1090 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1091 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1092 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1093 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1094 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1095 |
0 | 1096 } |
1097 } |