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