Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmMainWindow.cs @ 75:2ceae5d685d8
Re #86: Complete initial GTK# UI
* Fix default game system selecting
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 23 Nov 2010 20:17:18 +0000 |
parents | 52b731576845 |
children | 68804784bf6f |
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 private Preferences preferences; | |
39 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); | |
0 | 40 private CommandStack commandStack; |
41 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
|
42 private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>(); |
13 | 43 private ObjectAddDelegate UnitAddedMethod; |
44 private ObjectRemoveDelegate UnitRemovedMethod; | |
45 private DoubleValChangedDelegate PointsValueChangedMethod; | |
0 | 46 private FailedUnitRequirementDelegate FailedUnitRequirementMethod; |
47 private StringValChangedDelegate UnitNameChangedMethod; | |
48 private GameSystem system; | |
49 private string loadedArmyPath; | |
50 private MenuToolButton undoMenuButton, redoMenuButton; | |
21 | 51 |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
52 public static void Main(string[] args) |
21 | 53 { |
13 | 54 try |
0 | 55 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
56 ExceptionManager.UnhandledException += HandleUnhandledException; |
0 | 57 Application.Init(); |
58 FrmMainWindow win = new FrmMainWindow(args); | |
59 win.Show(); | |
60 Application.Run(); | |
13 | 61 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); |
62 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
63 catch (Exception ex) |
13 | 64 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
65 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
66 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
67 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
68 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
69 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
|
70 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
71 object obj = args.ExceptionObject; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
72 Exception ex = null; |
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 if (obj is Exception) |
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 ex = (Exception)obj; |
0 | 77 } |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
78 else |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
79 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
80 ex = new Exception("GLib returned unexpected exception object type " + obj.GetType()); |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
81 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
82 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
83 HandleUnhandledException(ex); |
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 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
86 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
|
87 { |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 dialog.Run(); |
64
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
92 dialog.Hide(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
93 dialog.Dispose(); |
0 | 94 } |
21 | 95 |
0 | 96 public FrmMainWindow() : this(new string[0]) |
97 { | |
98 //Do nothing extra | |
99 } | |
21 | 100 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
101 public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel) |
0 | 102 { |
103 logger.Info("Opening FrmMainWindow"); | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
104 Build(); |
0 | 105 //Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support |
106 redoMenuButton = new MenuToolButton("gtk-redo"); | |
107 redoMenuButton.Label = "Redo"; | |
10
c687bbe901f8
Re #37 - Resolve deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
108 redoMenuButton.TooltipText = "Redo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
109 redoMenuButton.Clicked += redoTBButtonActivated; |
0 | 110 toolbar.Insert(redoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
111 undoMenuButton = new MenuToolButton("gtk-undo"); | |
112 undoMenuButton.Label = "Undo"; | |
10
c687bbe901f8
Re #37 - Resolve deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
113 undoMenuButton.TooltipText = "Undo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
114 undoMenuButton.Clicked += undoTBButtonActivated; |
0 | 115 toolbar.Insert(undoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
116 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 1]); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
117 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 2]); |
0 | 118 toolbar.ShowAll(); |
21 | 119 |
0 | 120 Title = AppTitle; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
121 TreeViewColumn mainColumn = new TreeViewColumn(); |
0 | 122 mainColumn.Title = "Army Categories"; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
123 CellRendererText mainCell = new CellRendererText(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
124 mainColumn.PackStart(mainCell, true); |
0 | 125 treeUnits.AppendColumn(mainColumn); |
126 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderCategoryTreeObjectName)); | |
127 treeUnits.Model = new TreeStore(typeof(WarFoundryObject)); | |
128 logger.Debug("Loading preferences"); | |
129 Preferences = new Preferences("WarFoundryGTK"); | |
130 logger.Debug("Loading translations"); | |
21 | 131 |
8
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
132 try |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
133 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
134 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
135 } |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
136 catch (TranslationLoadException ex) |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
137 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
138 logger.Error(ex); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
139 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
|
140 dialog.Title = "Translation loading failed"; |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
141 dialog.Run(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
142 dialog.Destroy(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
143 } |
21 | 144 |
13 | 145 logger.Debug("Initialising"); |
146 commandStack = new CommandStack(); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
147 commandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
148 WarFoundryCore.GameSystemChanged += new GameSystemChangedDelegate(OnGameSystemChanged); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
149 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(OnArmyChanged); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
150 Destroyed += new EventHandler(OnWindowDestroyed); |
0 | 151 //TODO: Translate and subscribe to other events |
13 | 152 UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded); |
153 UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved); | |
154 PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged); | |
0 | 155 FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement); |
156 UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged); | |
21 | 157 |
18
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
158 //FIXME: Temporary hack to add paths and factories before we get preferences and plugins |
0 | 159 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
|
160 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); |
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
161 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
|
162 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; |
21 | 163 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); |
164 | |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
165 logger.Debug("Initialising complete - seeing if we can load default army or system"); |
21 | 166 |
0 | 167 if (args.Length == 1) |
168 { | |
21 | 169 logger.Debug("Attempting to load from file"); |
0 | 170 FileInfo file = new FileInfo(args[0]); |
21 | 171 |
0 | 172 try |
173 { | |
5 | 174 ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file); |
175 | |
176 if (objects.Count == 1) | |
0 | 177 { |
5 | 178 List<IWarFoundryObject> objectList = new List<IWarFoundryObject>(); |
179 objectList.AddRange(objects); | |
180 IWarFoundryObject loadedObject = objectList[0]; | |
21 | 181 |
5 | 182 if (loadedObject is Army) |
183 { | |
184 WarFoundryCore.CurrentArmy = (Army)loadedObject; | |
185 logger.InfoFormat("Loaded army from {0}", file.FullName); | |
186 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
187 else |
5 | 188 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
189 if (loadedObject is GameSystem) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
190 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
191 WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
192 logger.InfoFormat("Loaded game system from {0}", file.FullName); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
193 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
194 |
5 | 195 } |
0 | 196 } |
197 } | |
198 catch (InvalidFileException ex) | |
199 { | |
200 //TODO: show error dialog | |
201 logger.Error(ex); | |
202 } | |
203 } | |
204 else | |
205 { | |
206 string gameSystemID = Preferences.GetStringProperty("currSystem"); | |
207 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
208 if (gameSystemID != null && !"".Equals(gameSystemID)) |
0 | 209 { |
210 logger.Debug("Attempting to load current game system from properties"); | |
211 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); | |
21 | 212 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
213 if (sys != null) |
0 | 214 { |
215 WarFoundryCore.CurrentGameSystem = sys; | |
216 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); | |
217 } | |
218 } | |
219 } | |
220 } | |
21 | 221 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
222 private void FileLoadingFinished(List<FileLoadFailure> failures) |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
223 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
224 foreach (FileLoadFailure failure in failures) |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
225 { |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
226 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
|
227 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
228 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
229 |
0 | 230 private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
231 { | |
232 object o = model.GetValue(iter, 0); | |
21 | 233 |
0 | 234 if (o is ArmyCategory) |
235 { | |
236 ArmyCategory c = (ArmyCategory)o; | |
237 string name = ""; | |
21 | 238 |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
239 if (!Preferences.GetBooleanProperty("ShowCatPercentage")) |
0 | 240 { |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
241 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}pts", c.Name, c.Points); |
0 | 242 } |
243 else | |
244 { | |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
245 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 | 246 } |
21 | 247 |
0 | 248 (cell as CellRendererText).Text = name; |
249 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
250 else |
0 | 251 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
252 if (o is WFObjects.Unit) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
253 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
254 WFObjects.Unit u = (WFObjects.Unit)o; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
255 string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}pts", u.Name, u.Points); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
256 (cell as CellRendererText).Text = name; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
257 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
258 |
0 | 259 } |
260 } | |
21 | 261 |
0 | 262 private void OnWindowDestroyed(object source, EventArgs args) |
263 { | |
264 logger.Info("Exiting"); | |
265 Application.Quit(); | |
266 } | |
21 | 267 |
0 | 268 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue) |
269 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
270 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
271 logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name); |
0 | 272 UnitDisplayWidget widget; |
273 unitToWidgetMap.TryGetValue(unit, out widget); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
274 |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
275 if (widget != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
276 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
277 unitsNotebook.SetTabLabel(widget, NotebookUtil.CreateNotebookTabLabelWithClose(unitsNotebook, widget, unit.Name)); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
278 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
279 |
41
a32b6bb7f1eb
Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
280 treeUnits.QueueDraw(); |
0 | 281 } |
21 | 282 |
0 | 283 private void OnUnitAdded(WarFoundryObject val) |
284 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
285 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
286 unit.NameChanged += UnitNameChangedMethod; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
287 unit.PointsValueChanged += HandleUnitPointsValueChanged; |
0 | 288 AddUnitToTree(unit); |
289 } | |
21 | 290 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
291 private void HandleUnitPointsValueChanged(WarFoundryObject obj, double oldValue, double newValue) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
292 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
293 treeUnits.QueueDraw(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
294 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
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; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
324 unit.NameChanged -= UnitNameChangedMethod; |
0 | 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 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
403 protected void OnDeleteEvent(object sender, DeleteEventArgs a) |
0 | 404 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
405 Application.Quit(); |
0 | 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 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
477 if (WarFoundryCore.CurrentArmy != null) |
0 | 478 { |
479 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name; | |
480 } | |
481 else | |
482 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
483 if (WarFoundryCore.CurrentGameSystem != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
484 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
485 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
486 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
487 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
488 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
489 Title = AppTitle; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
490 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
491 |
0 | 492 } |
493 } | |
21 | 494 |
0 | 495 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys) |
496 { | |
497 system = newSys; | |
498 SetAppTitle(); | |
499 RemoveCategoryButtons(); | |
21 | 500 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
501 if (system != null) |
0 | 502 { |
503 AddCategoryButtons(system.Categories); | |
504 } | |
505 } | |
21 | 506 |
0 | 507 private void OnArmyChanged(Army oldArmy, Army newArmy) |
508 { | |
509 loadedArmyPath = null; | |
510 SetAppTitle(); | |
511 SetArmyTree(newArmy); | |
21 | 512 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
513 if (oldArmy != null) |
13 | 514 { |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
515 oldArmy.UnitAdded -= UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
516 oldArmy.UnitRemoved -= UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
517 oldArmy.PointsValueChanged -= PointsValueChangedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
518 oldArmy.FailedRequirement -= FailedUnitRequirementMethod; |
0 | 519 } |
21 | 520 |
0 | 521 unitToWidgetMap.Clear(); |
21 | 522 |
0 | 523 while (unitsNotebook.NPages > 0) |
524 { | |
525 unitsNotebook.RemovePage(0); | |
526 } | |
21 | 527 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
528 if (newArmy == null) |
13 | 529 { |
530 DisableCategoryButtons(); | |
531 } | |
532 else | |
533 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
534 newArmy.UnitAdded += UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
535 newArmy.UnitRemoved += UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
536 newArmy.PointsValueChanged += PointsValueChangedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
537 newArmy.FailedRequirement += FailedUnitRequirementMethod; |
13 | 538 //TODO: Clear all buttons |
539 EnableCategoryButtons(); | |
540 | |
541 if (newArmy.Race.HasCategoryOverrides()) | |
542 { | |
543 RemoveCategoryButtons(); | |
544 AddCategoryButtons(newArmy.Race.Categories); | |
545 } | |
0 | 546 } |
21 | 547 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
548 bool nonNullNewArmy = (newArmy != null); |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
549 miCloseArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
550 miSaveArmyAs.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
551 miExportArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
552 hpaned2.Visible = nonNullNewArmy; |
33 | 553 loadedArmyPath = null; |
0 | 554 //New army has no changes, so we can't save it |
555 miSaveArmy.Sensitive = false; | |
13 | 556 saveArmyButton.Sensitive = false; |
557 | |
558 CommandStack.Reset(); | |
0 | 559 SetPointsPanelText(); |
560 } | |
21 | 561 |
0 | 562 private void SetArmyTree(Army army) |
563 { | |
564 logger.Debug("Resetting tree"); | |
565 TreeStore store = (TreeStore)treeUnits.Model; | |
566 store.Clear(); | |
567 TreeIter iter; | |
21 | 568 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
569 if (army != null) |
0 | 570 { |
571 logger.Debug("Loading in categories to tree"); | |
21 | 572 |
0 | 573 foreach (ArmyCategory cat in army.Categories) |
574 { | |
575 logger.DebugFormat("Append category {0}", cat.Name); | |
576 iter = store.AppendValues(cat); | |
21 | 577 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
578 foreach (WFObjects.Unit unit in cat.GetUnits()) |
0 | 579 { |
580 store.AppendValues(iter, unit); | |
21 | 581 } |
0 | 582 } |
21 | 583 |
0 | 584 logger.Debug("Finished loading tree categories"); |
585 } | |
586 } | |
21 | 587 |
0 | 588 private void DisableCategoryButtons() |
589 { | |
590 SetCategoryButtonsSensitive(false); | |
591 } | |
21 | 592 |
0 | 593 private void EnableCategoryButtons() |
594 { | |
595 SetCategoryButtonsSensitive(true); | |
596 } | |
21 | 597 |
0 | 598 private void SetCategoryButtonsSensitive(bool state) |
599 { | |
600 int toolbarButtonCount = toolbar.Children.Length - 1; | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
601 logger.Debug("Last button index: " + toolbarButtonCount); |
21 | 602 |
0 | 603 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
604 { | |
605 logger.DebugFormat("Setting button {0} state to {1}", i, state); | |
606 toolbar.Children[i].Sensitive = state; | |
607 } | |
608 } | |
21 | 609 |
0 | 610 private void RemoveCategoryButtons() |
611 { | |
612 int toolbarButtonCount = toolbar.Children.Length - 1; | |
21 | 613 |
0 | 614 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
615 { | |
616 toolbar.Remove(toolbar.Children[i]); | |
617 } | |
21 | 618 |
0 | 619 categoryMap.Clear(); |
620 } | |
21 | 621 |
0 | 622 private void AddCategoryButtons(Category[] cats) |
623 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
624 if (cats != null && cats.Length > 0) |
0 | 625 { |
626 logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length); | |
21 | 627 |
0 | 628 foreach (Category cat in cats) |
629 { | |
630 ToolButton button = new ToolButton("gtk-add"); | |
631 button.Label = cat.Name; | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
632 button.TooltipText = "Add unit from " + cat.Name; |
0 | 633 //TODO: See if we can associate data in some way, the same as we can with SWF. For now we just use the map. |
634 categoryMap.Add(button, cat); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
635 button.Clicked += new System.EventHandler(OnAddUnitActivated); |
0 | 636 toolbar.Insert(button, -1); |
637 } | |
638 } | |
21 | 639 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
640 toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats != null && cats.Length > 0; |
21 | 641 |
0 | 642 toolbar.ShowAll(); |
643 } | |
21 | 644 |
0 | 645 private void SetPointsPanelText() |
646 { | |
647 //TODO: Set the points value in the status bar | |
648 } | |
21 | 649 |
13 | 650 private void commandStack_CommandStackUpdated() |
651 { | |
652 undoMenuButton.Sensitive = commandStack.CanUndo(); | |
653 miUndo.Sensitive = undoMenuButton.Sensitive; | |
654 redoMenuButton.Sensitive = commandStack.CanRedo(); | |
655 miRedo.Sensitive = redoMenuButton.Sensitive; | |
0 | 656 int redoLength = commandStack.RedoLength; |
21 | 657 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
658 int maxRedo = Math.Min(10, redoLength); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
659 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
660 //TODO: Add tooltips |
13 | 661 if (redoLength > 0) |
662 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
663 Menu menu = new Menu(); |
13 | 664 Command com; |
665 MenuItem mi; | |
666 | |
667 for (int i = 0; i < maxRedo; i++) | |
668 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
669 com = commandStack.PeekRedoCommand(i + 1); |
13 | 670 |
671 if (com == null) | |
672 { | |
21 | 673 break; |
13 | 674 } |
675 | |
676 mi = new MenuItem(com.Description); | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
677 mi.Activated += new EventHandler(RedoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
678 menu.Append(mi); |
13 | 679 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
680 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
681 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
682 redoMenuButton.Menu = menu; |
13 | 683 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
684 else |
13 | 685 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
686 redoMenuButton.Menu = null; |
13 | 687 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
688 |
13 | 689 int undoLength = commandStack.UndoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
690 int maxUndo = Math.Min(10, undoLength); |
21 | 691 |
13 | 692 if (undoLength > 0) |
693 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
694 Menu menu = new Menu(); |
13 | 695 Command com; |
696 MenuItem mi; | |
697 | |
698 for (int i = 0; i < maxUndo; i++) | |
699 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
700 com = commandStack.PeekUndoCommand(i + 1); |
13 | 701 |
702 if (com == null) | |
703 { | |
21 | 704 break; |
13 | 705 } |
706 | |
707 mi = new MenuItem(com.UndoDescription); | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
708 mi.Activated += new EventHandler(UndoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
709 menu.Add(mi); |
13 | 710 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
711 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
712 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
713 undoMenuButton.Menu = menu; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
714 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
715 else |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
716 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
717 undoMenuButton.Menu = null; |
13 | 718 } |
719 | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
720 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
|
721 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
|
722 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
723 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
724 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
|
725 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
726 if (sender is MenuItem) |
13 | 727 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
728 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
729 //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
|
730 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
731 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
|
732 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
733 if (max >= 0) |
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 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
|
736 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
737 commandStack.Redo(); |
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 } |
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 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
742 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
743 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
|
744 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
745 if (sender is MenuItem) |
0 | 746 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
747 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
748 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
749 //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
|
750 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
751 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
|
752 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
753 if (max >= 0) |
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 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
|
756 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
757 commandStack.Undo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
758 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
759 } |
0 | 760 } |
13 | 761 } |
762 | |
763 private bool SaveCurrentArmyOrSaveAs() | |
764 { | |
33 | 765 if (loadedArmyPath != null) |
13 | 766 { |
767 return SaveCurrentArmy(); | |
768 } | |
21 | 769 else |
13 | 770 { |
771 return SaveCurrentArmyAs(); | |
772 } | |
0 | 773 } |
21 | 774 |
0 | 775 private bool OpenArmy() |
776 { | |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
777 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
|
778 FileFilter filter = new FileFilter(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
779 filter.AddPattern("*.army"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
780 filter.Name = "WarFoundry Army files (*.army)"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
781 fileDialog.AddFilter(filter); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
782 int response = fileDialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
783 string filePath = null; |
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 if (response == (int)ResponseType.Accept) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
786 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
787 filePath = fileDialog.Filename; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
788 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
789 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
790 fileDialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
791 fileDialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
792 |
0 | 793 bool success = false; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
794 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
795 if (filePath != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
796 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
797 FileInfo file = new FileInfo(filePath); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
798 Army army = WarFoundryLoader.GetDefault().LoadArmy(file); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
799 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
800 if (army != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
801 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
802 logger.Debug("Loaded army " + army.ID); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
803 success = true; |
33 | 804 WarFoundryCore.CurrentArmy = army; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
805 loadedArmyPath = filePath; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
806 logger.Debug("Army loading complete"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
807 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
808 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
809 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
810 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
|
811 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
|
812 dialog.Title = "Failed to open army"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
813 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
814 dialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
815 dialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
816 } |
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 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
819 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
820 logger.Debug("Army open requested but cancelled"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
821 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
822 |
0 | 823 return success; |
13 | 824 } |
825 | |
826 private bool SaveCurrentArmy() | |
0 | 827 { |
828 bool success = false; | |
21 | 829 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
830 if (loadedArmyPath != null) |
0 | 831 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
832 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); |
0 | 833 } |
21 | 834 |
13 | 835 return success; |
836 } | |
837 | |
838 private bool SaveCurrentArmyAs() | |
839 { | |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
840 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
|
841 FileFilter filter = new FileFilter(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
842 filter.AddPattern("*.army"); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
843 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
|
844 fileDialog.AddFilter(filter); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
845 int response = fileDialog.Run(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
846 string filePath = null; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
847 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
848 if (response == (int)ResponseType.Accept) |
13 | 849 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
850 filePath = fileDialog.Filename; |
13 | 851 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
852 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
853 fileDialog.Hide(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
854 fileDialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
855 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
856 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
857 } |
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 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
|
860 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
861 bool success = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
862 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
863 if (filePath != null) |
13 | 864 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
865 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
|
866 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
867 miSaveArmy.Sensitive = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
868 saveArmyButton.Sensitive = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
869 CommandStack.setCleanMark(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
870 loadedArmyPath = filePath; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
871 success = true; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
872 } |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
873 else |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
874 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
875 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
|
876 dialog.Title = "Army save failed"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
877 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
878 dialog.Hide(); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
879 dialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
880 } |
21 | 881 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
882 //else user cancelled |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
883 |
21 | 884 return success; |
0 | 885 } |
21 | 886 |
13 | 887 private bool CloseCurrentArmy() |
888 { | |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
889 if (WarFoundryCore.CurrentArmy != null) |
13 | 890 { |
891 bool canClose = false; | |
892 | |
893 if (CommandStack.IsDirty()) | |
0 | 894 { |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
895 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
|
896 dia.AddButton("Cancel", ResponseType.Cancel); |
0 | 897 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
|
898 dia.Hide(); |
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
899 dia.Dispose(); |
0 | 900 |
13 | 901 if (dr == ResponseType.Yes) |
0 | 902 { |
903 //They want to save so try to save it or prompt for save as | |
13 | 904 //If they cancel the save as then assume they don't want to close |
905 canClose = SaveCurrentArmyOrSaveAs(); | |
906 } | |
0 | 907 else |
908 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
909 if (dr == ResponseType.No) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
910 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
911 //They don't care about their changes |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
912 canClose = true; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
913 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
914 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
915 { |
0 | 916 //Assume cancel or close with the X button |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
917 canClose = false; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
918 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
919 |
0 | 920 } |
13 | 921 } |
922 else | |
923 { | |
924 //Nothing has changed so we can safely close | |
925 canClose = true; | |
926 } | |
927 | |
928 if (canClose) | |
0 | 929 { |
13 | 930 //do close |
931 WarFoundryCore.CurrentArmy = null; | |
932 return true; | |
933 } | |
934 else | |
935 { | |
936 return false; | |
937 } | |
938 } | |
939 else | |
940 { | |
941 //pretend we succeeded | |
942 return true; | |
943 } | |
944 } | |
945 | |
946 private void CreateNewArmy() | |
0 | 947 { |
948 logger.Debug("Create new army"); | |
949 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem); | |
950 ResponseType type = (ResponseType)newArmy.Run(); | |
951 newArmy.Hide(); | |
21 | 952 |
0 | 953 if (type == ResponseType.Ok) |
13 | 954 { |
955 if (CloseCurrentArmy()) | |
0 | 956 { |
957 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); | |
958 } | |
959 } | |
960 else | |
961 { | |
962 logger.Debug("Create new army cancelled"); | |
963 } | |
21 | 964 |
13 | 965 newArmy.Destroy(); |
0 | 966 } |
21 | 967 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
968 protected virtual void undoTBButtonActivated(object sender, System.EventArgs e) |
0 | 969 { |
970 CommandStack.Undo(); | |
971 } | |
972 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
973 protected virtual void redoTBButtonActivated(object sender, System.EventArgs e) |
0 | 974 { |
975 CommandStack.Redo(); | |
976 } | |
977 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
978 protected virtual void saveTBButtonActivated(object sender, System.EventArgs e) |
0 | 979 { |
33 | 980 SaveCurrentArmyOrSaveAs(); |
0 | 981 } |
982 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
983 protected virtual void openTBButtonActivated(object sender, System.EventArgs e) |
0 | 984 { |
985 OpenArmy(); | |
986 } | |
987 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
988 protected virtual void newTBButtonActivated(object sender, System.EventArgs e) |
0 | 989 { |
990 CreateNewArmy(); | |
991 } | |
992 | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
993 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 994 { |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
995 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); |
21 | 996 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
997 if (obj is WFObjects.Unit) |
0 | 998 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
999 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
|
1000 ShowUnitWidget(unit); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1001 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1002 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1003 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1004 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
|
1005 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1006 UnitDisplayWidget widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1007 unitToWidgetMap.TryGetValue(unit, out widget); |
21 | 1008 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1009 if (widget != null) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1010 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1011 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
|
1012 unitsNotebook.Page = unitsNotebook.PageNum(widget); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1013 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1014 else |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1015 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1016 widget = new UnitDisplayWidget(unit, CommandStack); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1017 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
|
1018 unitToWidgetMap[unit] = widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1019 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
|
1020 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
|
1021 unitsNotebook.ShowAll(); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1022 unitsNotebook.CurrentPage = pageNum; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1023 unitsNotebook.SetTabReorderable(widget, true); |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1024 } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1025 } |
28 | 1026 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1027 protected virtual void OnMiExportAsBasicHtmlActivated(object sender, System.EventArgs e) |
28 | 1028 { |
1029 FileChooserDialog fileDialog = new FileChooserDialog("Export army", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Export", ResponseType.Accept); | |
1030 FileFilter filter = new FileFilter(); | |
1031 filter.AddPattern("*.html"); | |
1032 filter.Name = "HTML pages (*.html)"; | |
1033 fileDialog.AddFilter(filter); | |
1034 int response = fileDialog.Run(); | |
1035 string filePath = null; | |
1036 | |
1037 if (response == (int)ResponseType.Accept) | |
1038 { | |
1039 filePath = fileDialog.Filename; | |
1040 } | |
1041 | |
1042 fileDialog.Hide(); | |
1043 fileDialog.Dispose(); | |
1044 | |
1045 if (filePath != null) | |
1046 { | |
1047 Army army = WarFoundryCore.CurrentArmy; | |
1048 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); | |
1049 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); | |
1050 } | |
1051 } | |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1052 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1053 protected virtual void OnTreeUnitsPopupMenu(object o, Gtk.PopupMenuArgs args) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1054 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1055 object selectedItem = TreeUtils.GetSelectedItem(treeUnits); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1056 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1057 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
|
1058 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1059 Menu menu = new Menu(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1060 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
|
1061 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1062 delete.Activated += new EventHandler(OnUnitDelete); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1063 delete.Data["unit"] = selectedItem; |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1064 menu.Append(delete); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1065 menu.ShowAll(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1066 menu.Popup(); |
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 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1069 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1070 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
|
1071 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1072 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
|
1073 commandStack.Execute(command); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1074 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1075 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1076 [GLib.ConnectBefore] |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1077 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1078 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
|
1079 { |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1080 TreePath path; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1081 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
|
1082 |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1083 if (!treeUnits.Selection.PathIsSelected(path)) |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1084 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1085 treeUnits.Selection.SelectPath(path); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1086 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1087 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1088 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
|
1089 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1090 OnTreeUnitsPopupMenu(o, null); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1091 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1092 } |
45
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 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
|
1095 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1096 Widget widget = args.Widget; |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1097 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1098 if (widget is UnitDisplayWidget) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1099 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1100 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1101 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1102 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1103 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1104 |
0 | 1105 } |
1106 } |