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