Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmMainWindow.cs @ 85:bfb29a60b802
Re #308: Make GTK# UI translatable
* Translate the bits of FrmNewArmy that can't be translated via cascade
* Set up label names and translations for translating (need to get Stetic to use TranslatableLabel)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 29 Dec 2010 16:56:55 +0000 |
parents | 678e9a0392fc |
children | ea4069bbe6e9 |
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.Collections.Generic; | |
7 using System.Configuration; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
8 using System.IO; |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
9 using GLib; |
13 | 10 using Gtk; |
11 using IBBoard; | |
0 | 12 using IBBoard.Commands; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
13 using IBBoard.CustomMath; |
12
685532d43a96
Re #88: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
10
diff
changeset
|
14 using IBBoard.GtkSharp; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
15 using IBBoard.GtkSharp.Translatable; |
0 | 16 using IBBoard.IO; |
13 | 17 using IBBoard.Lang; |
18 using IBBoard.Logging; | |
0 | 19 using IBBoard.WarFoundry.API; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
20 using IBBoard.WarFoundry.API.Commands; |
28 | 21 using IBBoard.WarFoundry.API.Exporters; |
0 | 22 using IBBoard.WarFoundry.API.Factories; |
13 | 23 using IBBoard.WarFoundry.API.Factories.Xml; |
24 using IBBoard.WarFoundry.API.Objects; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
25 using IBBoard.WarFoundry.API.Requirements; |
0 | 26 using IBBoard.WarFoundry.API.Savers; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
27 using IBBoard.WarFoundry.GUI.GTK.Widgets; |
13 | 28 using IBBoard.WarFoundry.Plugin.Rollcall; |
0 | 29 using IBBoard.Xml; |
30 using log4net; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
31 using WFObjects = IBBoard.WarFoundry.API.Objects; |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
32 using System.Collections; |
0 | 33 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
34 namespace IBBoard.WarFoundry.GUI.GTK |
21 | 35 { |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
36 public partial class FrmMainWindow: TranslatableWindowWithActions |
0 | 37 { |
38 private static readonly string AppTitle = "WarFoundry"; | |
13 | 39 private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6; |
40 private Preferences preferences; | |
41 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); | |
0 | 42 private CommandStack commandStack; |
43 private Dictionary<ToolButton, Category> categoryMap = new Dictionary<ToolButton, Category>(); | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
44 private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>(); |
13 | 45 private ObjectAddDelegate UnitAddedMethod; |
46 private ObjectRemoveDelegate UnitRemovedMethod; | |
47 private DoubleValChangedDelegate PointsValueChangedMethod; | |
0 | 48 private FailedUnitRequirementDelegate FailedUnitRequirementMethod; |
49 private StringValChangedDelegate UnitNameChangedMethod; | |
50 private GameSystem system; | |
51 private string loadedArmyPath; | |
52 private MenuToolButton undoMenuButton, redoMenuButton; | |
21 | 53 |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
54 public static void Main(string[] args) |
21 | 55 { |
13 | 56 try |
0 | 57 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
58 ExceptionManager.UnhandledException += HandleUnhandledException; |
0 | 59 Application.Init(); |
60 FrmMainWindow win = new FrmMainWindow(args); | |
61 win.Show(); | |
62 Application.Run(); | |
13 | 63 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); |
64 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
65 catch (Exception ex) |
13 | 66 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
67 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
68 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
69 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
70 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
71 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
|
72 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
73 object obj = args.ExceptionObject; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
74 Exception ex = null; |
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 if (obj is Exception) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
77 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
78 ex = (Exception)obj; |
0 | 79 } |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
80 else |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
81 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
82 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
|
83 } |
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 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
86 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
87 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
88 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
|
89 { |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 dialog.Run(); |
64
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
94 dialog.Hide(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
95 dialog.Dispose(); |
0 | 96 } |
21 | 97 |
0 | 98 public FrmMainWindow() : this(new string[0]) |
99 { | |
100 //Do nothing extra | |
101 } | |
21 | 102 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
103 public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel) |
0 | 104 { |
105 logger.Info("Opening FrmMainWindow"); | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
106 Build(); |
0 | 107 //Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support |
108 redoMenuButton = new MenuToolButton("gtk-redo"); | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
109 redoMenuButton.Name = "bttnRedo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
110 redoMenuButton.Clicked += redoTBButtonActivated; |
78
e63209ab2cfa
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
111 redoMenuButton.Sensitive = false; |
0 | 112 toolbar.Insert(redoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
113 undoMenuButton = new MenuToolButton("gtk-undo"); | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
114 undoMenuButton.Name = "bttnUndo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
115 undoMenuButton.Clicked += undoTBButtonActivated; |
78
e63209ab2cfa
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
116 undoMenuButton.Sensitive = false; |
0 | 117 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
|
118 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
|
119 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 2]); |
0 | 120 toolbar.ShowAll(); |
21 | 121 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
122 TreeViewColumn mainColumn = new TreeViewColumn(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
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"); | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
129 Preferences = new Preferences("WarFoundry-GTK"); |
0 | 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); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
151 TranslateWindow(); |
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 |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
222 private void TranslateWindow() |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
223 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
224 ControlTranslator.TranslateWidget(this); |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
225 SetAppTitle(); |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
226 treeUnits.GetColumn(0).Title = Translation.GetTranslation("armyCategoryColumnTitle", "categories"); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
227 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
228 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
229 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
|
230 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
231 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
|
232 { |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
233 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
|
234 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
235 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
236 |
0 | 237 private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
238 { | |
239 object o = model.GetValue(iter, 0); | |
21 | 240 |
0 | 241 if (o is ArmyCategory) |
242 { | |
243 ArmyCategory c = (ArmyCategory)o; | |
244 string name = ""; | |
21 | 245 |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
246 if (!Preferences.GetBooleanProperty("ShowCatPercentage")) |
0 | 247 { |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
248 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}pts", c.Name, c.Points); |
0 | 249 } |
250 else | |
251 { | |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
252 name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}pts ({2}%)", c.Name, c.Points, (c.ParentArmy.Points > 0 ? Math.Round((c.Points / c.ParentArmy.Points) * 100) : 0)); |
0 | 253 } |
21 | 254 |
0 | 255 (cell as CellRendererText).Text = name; |
256 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
257 else |
0 | 258 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
259 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
|
260 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
261 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
|
262 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
|
263 (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
|
264 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
265 |
0 | 266 } |
267 } | |
21 | 268 |
0 | 269 private void OnWindowDestroyed(object source, EventArgs args) |
270 { | |
271 logger.Info("Exiting"); | |
272 Application.Quit(); | |
273 } | |
21 | 274 |
0 | 275 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue) |
276 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
277 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
278 logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name); |
0 | 279 UnitDisplayWidget widget; |
280 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
|
281 |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
282 if (widget != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
283 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
284 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
|
285 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
286 |
41
a32b6bb7f1eb
Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
287 treeUnits.QueueDraw(); |
0 | 288 } |
21 | 289 |
0 | 290 private void OnUnitAdded(WarFoundryObject val) |
291 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
292 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
|
293 unit.NameChanged += UnitNameChangedMethod; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
294 unit.PointsValueChanged += HandleUnitPointsValueChanged; |
0 | 295 AddUnitToTree(unit); |
296 } | |
21 | 297 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
298 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
|
299 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
300 treeUnits.QueueDraw(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
301 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
302 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
303 private void AddUnitToTree(WFObjects.Unit unit) |
0 | 304 { |
305 TreeStore model = (TreeStore)treeUnits.Model; | |
306 TreeIter iter; | |
307 model.GetIterFirst(out iter); | |
21 | 308 |
0 | 309 do |
310 { | |
311 object obj = model.GetValue(iter, 0); | |
21 | 312 |
0 | 313 if (obj is ArmyCategory) |
314 { | |
315 ArmyCategory cat = (ArmyCategory)obj; | |
21 | 316 |
0 | 317 if (cat.Equals(unit.Category)) |
318 { | |
319 model.AppendValues(iter, unit); | |
320 TreePath path = model.GetPath(iter); | |
321 treeUnits.ExpandToPath(path); | |
322 } | |
323 } | |
324 } | |
325 while (model.IterNext(ref iter)); | |
326 } | |
21 | 327 |
0 | 328 private void OnUnitRemoved(WarFoundryObject obj) |
329 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
330 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
|
331 unit.NameChanged -= UnitNameChangedMethod; |
0 | 332 RemoveUnitFromTree(unit); |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
333 RemoveUnitTab(unit); |
0 | 334 } |
21 | 335 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
336 private void RemoveUnitFromTree(WFObjects.Unit unit) |
0 | 337 { |
338 TreeStore model = (TreeStore)treeUnits.Model; | |
339 TreeIter iter; | |
340 model.GetIterFirst(out iter); | |
341 bool removed = false; | |
21 | 342 |
0 | 343 do |
344 { | |
345 object obj = model.GetValue(iter, 0); | |
21 | 346 |
0 | 347 if (obj is ArmyCategory) |
348 { | |
349 ArmyCategory cat = (ArmyCategory)obj; | |
21 | 350 |
0 | 351 if (unit.Category == null || cat.Equals(unit.Category)) |
352 { | |
353 TreeIter innerIter; | |
354 model.IterChildren(out innerIter, iter); | |
21 | 355 |
0 | 356 do |
357 { | |
358 object innerObj = model.GetValue(innerIter, 0); | |
21 | 359 |
0 | 360 if (unit.Equals(innerObj)) |
361 { | |
362 model.Remove(ref innerIter); | |
363 removed = true; | |
364 break; | |
365 } | |
366 } | |
367 while (model.IterNext(ref innerIter)); | |
21 | 368 |
0 | 369 if (removed) |
370 { | |
371 break; | |
372 } | |
373 } | |
374 } | |
375 } | |
376 while (model.IterNext(ref iter)); | |
377 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
378 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
379 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
|
380 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
381 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
|
382 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
383 if (widget != null) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
384 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
385 unitsNotebook.Remove(widget); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
386 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
387 } |
21 | 388 |
0 | 389 private void OnPointsValueChanged(WarFoundryObject obj, double before, double after) |
390 { | |
391 //Set points in panel | |
392 } | |
21 | 393 |
0 | 394 private void OnFailedUnitRequirement(List<FailedUnitRequirement> failedRequirement) |
395 { | |
396 //Show error message in panel | |
397 } | |
21 | 398 |
0 | 399 public Preferences Preferences |
400 { | |
401 get { return preferences; } | |
21 | 402 set { preferences = value; } |
0 | 403 } |
21 | 404 |
0 | 405 /*public AbstractNativeWarFoundryFactory Factory |
406 { | |
407 get { return WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(Constants.ExecutablePath, factoryType); } | |
408 }*/ | |
21 | 409 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
410 protected void OnDeleteEvent(object sender, DeleteEventArgs a) |
0 | 411 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
412 Application.Quit(); |
0 | 413 a.RetVal = true; |
414 } | |
415 | |
416 protected virtual void OnExitActivated(object sender, System.EventArgs e) | |
417 { | |
418 Application.Quit(); | |
419 } | |
420 | |
421 protected virtual void OnCreateArmyActivated(object sender, System.EventArgs e) | |
422 { | |
423 CreateNewArmy(); | |
424 } | |
425 | |
426 protected virtual void OnReloadFilesActivated(object sender, System.EventArgs e) | |
427 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
428 WarFoundryLoader.GetDefault().LoadFiles(); |
0 | 429 } |
430 | |
431 protected virtual void OnSaveArmyAsActivated(object sender, System.EventArgs e) | |
432 { | |
433 SaveCurrentArmyAs(); | |
434 } | |
435 | |
436 protected virtual void OnCloseArmyActivated(object sender, System.EventArgs e) | |
437 { | |
438 CloseCurrentArmy(); | |
439 } | |
440 | |
441 protected virtual void OnOpenArmyActivated(object sender, System.EventArgs e) | |
442 { | |
443 OpenArmy(); | |
444 } | |
445 | |
446 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e) | |
447 { | |
33 | 448 SaveCurrentArmyOrSaveAs(); |
0 | 449 } |
21 | 450 |
0 | 451 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e) |
452 { | |
453 if (sender is ToolButton) | |
454 { | |
455 Category cat = null; | |
456 categoryMap.TryGetValue((ToolButton)sender, out cat); | |
21 | 457 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
458 if (cat != null) |
0 | 459 { |
460 logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name); | |
461 FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy); | |
462 ResponseType response = (ResponseType)newUnit.Run(); | |
463 newUnit.Hide(); | |
21 | 464 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
465 if (response == ResponseType.Ok) |
0 | 466 { |
14
abbf8a3ac431
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
467 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat)); |
0 | 468 commandStack.Execute(cmd); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
469 ShowUnitWidget(cmd.Unit); |
0 | 470 } |
21 | 471 |
0 | 472 newUnit.Dispose(); |
473 } | |
474 } | |
475 } | |
21 | 476 |
13 | 477 public CommandStack CommandStack |
478 { | |
479 get { return commandStack; } | |
0 | 480 } |
21 | 481 |
0 | 482 private void SetAppTitle() |
483 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
484 if (WarFoundryCore.CurrentArmy != null) |
0 | 485 { |
486 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name; | |
487 } | |
488 else | |
489 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
490 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
|
491 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
492 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
|
493 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
494 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
495 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
496 Title = AppTitle; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
497 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
498 |
0 | 499 } |
500 } | |
21 | 501 |
0 | 502 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys) |
503 { | |
504 system = newSys; | |
505 SetAppTitle(); | |
506 RemoveCategoryButtons(); | |
21 | 507 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
508 if (system != null) |
0 | 509 { |
510 AddCategoryButtons(system.Categories); | |
511 } | |
512 } | |
21 | 513 |
0 | 514 private void OnArmyChanged(Army oldArmy, Army newArmy) |
515 { | |
516 loadedArmyPath = null; | |
517 SetAppTitle(); | |
518 SetArmyTree(newArmy); | |
21 | 519 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
520 if (oldArmy != null) |
13 | 521 { |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
522 oldArmy.UnitAdded -= UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
523 oldArmy.UnitRemoved -= UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
524 oldArmy.PointsValueChanged -= PointsValueChangedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
525 oldArmy.FailedRequirement -= FailedUnitRequirementMethod; |
0 | 526 } |
21 | 527 |
0 | 528 unitToWidgetMap.Clear(); |
21 | 529 |
0 | 530 while (unitsNotebook.NPages > 0) |
531 { | |
532 unitsNotebook.RemovePage(0); | |
533 } | |
21 | 534 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
535 if (newArmy == null) |
13 | 536 { |
537 DisableCategoryButtons(); | |
538 } | |
539 else | |
540 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
541 newArmy.UnitAdded += UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
542 newArmy.UnitRemoved += UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
543 newArmy.PointsValueChanged += PointsValueChangedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
544 newArmy.FailedRequirement += FailedUnitRequirementMethod; |
13 | 545 //TODO: Clear all buttons |
546 EnableCategoryButtons(); | |
547 | |
548 if (newArmy.Race.HasCategoryOverrides()) | |
549 { | |
550 RemoveCategoryButtons(); | |
551 AddCategoryButtons(newArmy.Race.Categories); | |
552 } | |
0 | 553 } |
21 | 554 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
555 bool nonNullNewArmy = (newArmy != null); |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
556 miCloseArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
557 miSaveArmyAs.Sensitive = nonNullNewArmy; |
81
3ff8e10de45a
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
79
diff
changeset
|
558 miExportArmyAs.Sensitive = nonNullNewArmy; |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
559 hpaned2.Visible = nonNullNewArmy; |
33 | 560 loadedArmyPath = null; |
0 | 561 //New army has no changes, so we can't save it |
562 miSaveArmy.Sensitive = false; | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
563 bttnSaveArmy.Sensitive = false; |
13 | 564 |
565 CommandStack.Reset(); | |
0 | 566 SetPointsPanelText(); |
567 } | |
21 | 568 |
0 | 569 private void SetArmyTree(Army army) |
570 { | |
571 logger.Debug("Resetting tree"); | |
572 TreeStore store = (TreeStore)treeUnits.Model; | |
573 store.Clear(); | |
574 TreeIter iter; | |
21 | 575 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
576 if (army != null) |
0 | 577 { |
578 logger.Debug("Loading in categories to tree"); | |
21 | 579 |
0 | 580 foreach (ArmyCategory cat in army.Categories) |
581 { | |
582 logger.DebugFormat("Append category {0}", cat.Name); | |
583 iter = store.AppendValues(cat); | |
21 | 584 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
585 foreach (WFObjects.Unit unit in cat.GetUnits()) |
0 | 586 { |
587 store.AppendValues(iter, unit); | |
21 | 588 } |
0 | 589 } |
21 | 590 |
0 | 591 logger.Debug("Finished loading tree categories"); |
592 } | |
593 } | |
21 | 594 |
0 | 595 private void DisableCategoryButtons() |
596 { | |
597 SetCategoryButtonsSensitive(false); | |
598 } | |
21 | 599 |
0 | 600 private void EnableCategoryButtons() |
601 { | |
602 SetCategoryButtonsSensitive(true); | |
603 } | |
21 | 604 |
0 | 605 private void SetCategoryButtonsSensitive(bool state) |
606 { | |
607 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
|
608 logger.Debug("Last button index: " + toolbarButtonCount); |
21 | 609 |
0 | 610 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
611 { | |
612 logger.DebugFormat("Setting button {0} state to {1}", i, state); | |
613 toolbar.Children[i].Sensitive = state; | |
614 } | |
615 } | |
21 | 616 |
0 | 617 private void RemoveCategoryButtons() |
618 { | |
619 int toolbarButtonCount = toolbar.Children.Length - 1; | |
21 | 620 |
0 | 621 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
622 { | |
623 toolbar.Remove(toolbar.Children[i]); | |
624 } | |
21 | 625 |
0 | 626 categoryMap.Clear(); |
627 } | |
21 | 628 |
0 | 629 private void AddCategoryButtons(Category[] cats) |
630 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
631 if (cats != null && cats.Length > 0) |
0 | 632 { |
633 logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length); | |
21 | 634 |
0 | 635 foreach (Category cat in cats) |
636 { | |
637 ToolButton button = new ToolButton("gtk-add"); | |
638 button.Label = cat.Name; | |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
639 button.TooltipText = Translation.GetTranslation("bttnCreateFromCat", "{0}", cat.Name); |
0 | 640 //TODO: See if we can associate data in some way, the same as we can with SWF. For now we just use the map. |
641 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
|
642 button.Clicked += new System.EventHandler(OnAddUnitActivated); |
0 | 643 toolbar.Insert(button, -1); |
644 } | |
645 } | |
21 | 646 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
647 toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats != null && cats.Length > 0; |
21 | 648 |
0 | 649 toolbar.ShowAll(); |
650 } | |
21 | 651 |
0 | 652 private void SetPointsPanelText() |
653 { | |
654 //TODO: Set the points value in the status bar | |
655 } | |
21 | 656 |
13 | 657 private void commandStack_CommandStackUpdated() |
658 { | |
659 undoMenuButton.Sensitive = commandStack.CanUndo(); | |
660 miUndo.Sensitive = undoMenuButton.Sensitive; | |
661 redoMenuButton.Sensitive = commandStack.CanRedo(); | |
662 miRedo.Sensitive = redoMenuButton.Sensitive; | |
0 | 663 int redoLength = commandStack.RedoLength; |
21 | 664 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
665 int maxRedo = Math.Min(10, redoLength); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
666 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
667 //TODO: Add tooltips |
13 | 668 if (redoLength > 0) |
669 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
670 Menu menu = new Menu(); |
13 | 671 Command com; |
672 MenuItem mi; | |
673 | |
674 for (int i = 0; i < maxRedo; i++) | |
675 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
676 com = commandStack.PeekRedoCommand(i + 1); |
13 | 677 |
678 if (com == null) | |
679 { | |
21 | 680 break; |
13 | 681 } |
682 | |
683 mi = new MenuItem(com.Description); | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
684 mi.Activated += new EventHandler(RedoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
685 menu.Append(mi); |
13 | 686 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
687 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
688 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
689 redoMenuButton.Menu = menu; |
13 | 690 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
691 else |
13 | 692 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
693 redoMenuButton.Menu = null; |
13 | 694 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
695 |
13 | 696 int undoLength = commandStack.UndoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
697 int maxUndo = Math.Min(10, undoLength); |
21 | 698 |
13 | 699 if (undoLength > 0) |
700 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
701 Menu menu = new Menu(); |
13 | 702 Command com; |
703 MenuItem mi; | |
704 | |
705 for (int i = 0; i < maxUndo; i++) | |
706 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
707 com = commandStack.PeekUndoCommand(i + 1); |
13 | 708 |
709 if (com == null) | |
710 { | |
21 | 711 break; |
13 | 712 } |
713 | |
714 mi = new MenuItem(com.UndoDescription); | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
715 mi.Activated += new EventHandler(UndoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
716 menu.Add(mi); |
13 | 717 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
718 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
719 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
720 undoMenuButton.Menu = menu; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
721 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
722 else |
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 undoMenuButton.Menu = null; |
13 | 725 } |
726 | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
727 bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
728 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
|
729 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
730 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
731 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
|
732 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
733 if (sender is MenuItem) |
13 | 734 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
735 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
736 //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
|
737 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
738 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
|
739 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
740 if (max >= 0) |
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 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
|
743 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
744 commandStack.Redo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
745 } |
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 } |
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 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
750 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
|
751 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
752 if (sender is MenuItem) |
0 | 753 { |
46
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 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
756 //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
|
757 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
758 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
|
759 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
760 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
761 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
762 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
|
763 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
764 commandStack.Undo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
765 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
766 } |
0 | 767 } |
13 | 768 } |
769 | |
770 private bool SaveCurrentArmyOrSaveAs() | |
771 { | |
33 | 772 if (loadedArmyPath != null) |
13 | 773 { |
774 return SaveCurrentArmy(); | |
775 } | |
21 | 776 else |
13 | 777 { |
778 return SaveCurrentArmyAs(); | |
779 } | |
0 | 780 } |
21 | 781 |
0 | 782 private bool OpenArmy() |
783 { | |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
784 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
|
785 FileFilter filter = new FileFilter(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
786 filter.AddPattern("*.army"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
787 filter.Name = "WarFoundry Army files (*.army)"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
788 fileDialog.AddFilter(filter); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
789 int response = fileDialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
790 string filePath = null; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
791 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
792 if (response == (int)ResponseType.Accept) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
793 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
794 filePath = fileDialog.Filename; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
795 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
796 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
797 fileDialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
798 fileDialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
799 |
0 | 800 bool success = false; |
25
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 if (filePath != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
803 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
804 FileInfo file = new FileInfo(filePath); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
805 Army army = WarFoundryLoader.GetDefault().LoadArmy(file); |
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 (army != 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 logger.Debug("Loaded army " + army.ID); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
810 success = true; |
33 | 811 WarFoundryCore.CurrentArmy = army; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
812 loadedArmyPath = filePath; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
813 logger.Debug("Army loading complete"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
814 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
815 else |
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 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
|
818 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
|
819 dialog.Title = "Failed to open army"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
820 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
821 dialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
822 dialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
823 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
824 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
825 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
826 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
827 logger.Debug("Army open requested but cancelled"); |
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 |
0 | 830 return success; |
13 | 831 } |
832 | |
833 private bool SaveCurrentArmy() | |
0 | 834 { |
835 bool success = false; | |
21 | 836 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
837 if (loadedArmyPath != null) |
0 | 838 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
839 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); |
0 | 840 } |
21 | 841 |
13 | 842 return success; |
843 } | |
844 | |
845 private bool SaveCurrentArmyAs() | |
846 { | |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
847 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
|
848 FileFilter filter = new FileFilter(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
849 filter.AddPattern("*.army"); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
850 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
|
851 fileDialog.AddFilter(filter); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
852 int response = fileDialog.Run(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
853 string filePath = null; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
854 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
855 if (response == (int)ResponseType.Accept) |
13 | 856 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
857 filePath = fileDialog.Filename; |
13 | 858 } |
23
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 fileDialog.Hide(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
861 fileDialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
862 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
863 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
864 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
865 |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
866 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
|
867 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
868 bool success = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
869 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
870 if (filePath != null) |
13 | 871 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
872 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
|
873 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
874 miSaveArmy.Sensitive = false; |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
875 bttnSaveArmy.Sensitive = false; |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
876 CommandStack.setCleanMark(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
877 loadedArmyPath = filePath; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
878 success = true; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
879 } |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
880 else |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
881 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
882 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
|
883 dialog.Title = "Army save failed"; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
884 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
885 dialog.Hide(); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
886 dialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
887 } |
21 | 888 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
889 //else user cancelled |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
890 |
21 | 891 return success; |
0 | 892 } |
21 | 893 |
13 | 894 private bool CloseCurrentArmy() |
895 { | |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
896 if (WarFoundryCore.CurrentArmy != null) |
13 | 897 { |
898 bool canClose = false; | |
899 | |
900 if (CommandStack.IsDirty()) | |
0 | 901 { |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
902 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
|
903 dia.AddButton("Cancel", ResponseType.Cancel); |
0 | 904 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
|
905 dia.Hide(); |
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
906 dia.Dispose(); |
0 | 907 |
13 | 908 if (dr == ResponseType.Yes) |
0 | 909 { |
910 //They want to save so try to save it or prompt for save as | |
13 | 911 //If they cancel the save as then assume they don't want to close |
912 canClose = SaveCurrentArmyOrSaveAs(); | |
913 } | |
0 | 914 else |
915 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
916 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
|
917 { |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
918 //They don't care about their changes |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
919 canClose = true; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
920 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
921 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
922 { |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
923 //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
|
924 canClose = false; |
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 |
0 | 927 } |
13 | 928 } |
929 else | |
930 { | |
931 //Nothing has changed so we can safely close | |
932 canClose = true; | |
933 } | |
934 | |
935 if (canClose) | |
0 | 936 { |
13 | 937 //do close |
938 WarFoundryCore.CurrentArmy = null; | |
939 return true; | |
940 } | |
941 else | |
942 { | |
943 return false; | |
944 } | |
945 } | |
946 else | |
947 { | |
948 //pretend we succeeded | |
949 return true; | |
950 } | |
951 } | |
952 | |
953 private void CreateNewArmy() | |
0 | 954 { |
955 logger.Debug("Create new army"); | |
956 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem); | |
957 ResponseType type = (ResponseType)newArmy.Run(); | |
958 newArmy.Hide(); | |
21 | 959 |
0 | 960 if (type == ResponseType.Ok) |
13 | 961 { |
962 if (CloseCurrentArmy()) | |
0 | 963 { |
964 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); | |
965 } | |
966 } | |
967 else | |
968 { | |
969 logger.Debug("Create new army cancelled"); | |
970 } | |
21 | 971 |
13 | 972 newArmy.Destroy(); |
0 | 973 } |
21 | 974 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
975 protected virtual void undoTBButtonActivated(object sender, System.EventArgs e) |
0 | 976 { |
977 CommandStack.Undo(); | |
978 } | |
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 redoTBButtonActivated(object sender, System.EventArgs e) |
0 | 981 { |
982 CommandStack.Redo(); | |
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 saveTBButtonActivated(object sender, System.EventArgs e) |
0 | 986 { |
33 | 987 SaveCurrentArmyOrSaveAs(); |
0 | 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 openTBButtonActivated(object sender, System.EventArgs e) |
0 | 991 { |
992 OpenArmy(); | |
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 newTBButtonActivated(object sender, System.EventArgs e) |
0 | 996 { |
997 CreateNewArmy(); | |
998 } | |
999 | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1000 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 1001 { |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1002 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); |
21 | 1003 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1004 if (obj is WFObjects.Unit) |
0 | 1005 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1006 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
|
1007 ShowUnitWidget(unit); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1008 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1009 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1010 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1011 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
|
1012 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1013 UnitDisplayWidget widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1014 unitToWidgetMap.TryGetValue(unit, out widget); |
21 | 1015 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1016 if (widget != null) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1017 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1018 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
|
1019 unitsNotebook.Page = unitsNotebook.PageNum(widget); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1020 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1021 else |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1022 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1023 widget = new UnitDisplayWidget(unit, CommandStack); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1024 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
|
1025 unitToWidgetMap[unit] = widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1026 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
|
1027 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
|
1028 unitsNotebook.ShowAll(); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1029 unitsNotebook.CurrentPage = pageNum; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1030 unitsNotebook.SetTabReorderable(widget, true); |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1031 } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1032 } |
28 | 1033 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1034 protected virtual void OnMiExportAsBasicHtmlActivated(object sender, System.EventArgs e) |
28 | 1035 { |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1036 string exportArmyTitle = Translation.GetTranslation("exportBasicHtmlDialogTitle", "export army"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1037 string cancelText = Translation.GetTranslation("exportBasicHtmlCancel", "cancel"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1038 string exportText = Translation.GetTranslation("exportBasicHtmlExport", "export"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1039 FileChooserDialog fileDialog = new FileChooserDialog(exportArmyTitle, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, exportText, ResponseType.Accept); |
28 | 1040 FileFilter filter = new FileFilter(); |
1041 filter.AddPattern("*.html"); | |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1042 filter.Name = Translation.GetTranslation("exportBasicHtmlHtmlFilter", "HTML pages (*.html)"); |
28 | 1043 fileDialog.AddFilter(filter); |
1044 int response = fileDialog.Run(); | |
1045 string filePath = null; | |
1046 | |
1047 if (response == (int)ResponseType.Accept) | |
1048 { | |
1049 filePath = fileDialog.Filename; | |
1050 } | |
1051 | |
1052 fileDialog.Hide(); | |
1053 fileDialog.Dispose(); | |
1054 | |
1055 if (filePath != null) | |
1056 { | |
1057 Army army = WarFoundryCore.CurrentArmy; | |
1058 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); | |
1059 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); | |
1060 } | |
1061 } | |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1062 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1063 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
|
1064 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1065 object selectedItem = TreeUtils.GetSelectedItem(treeUnits); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1066 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1067 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
|
1068 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1069 Menu menu = new Menu(); |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1070 ImageMenuItem delete = new ImageMenuItem(Translation.GetTranslation("menuRemoveUnit", "remove unit")); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1071 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
|
1072 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
|
1073 delete.Data["unit"] = selectedItem; |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1074 menu.Append(delete); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1075 menu.ShowAll(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1076 menu.Popup(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1077 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1078 } |
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 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
|
1081 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1082 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
|
1083 commandStack.Execute(command); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1084 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1085 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1086 [GLib.ConnectBefore] |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1087 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1088 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
|
1089 { |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1090 TreePath path; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1091 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
|
1092 |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1093 if (!treeUnits.Selection.PathIsSelected(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 treeUnits.Selection.SelectPath(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 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1098 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
|
1099 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1100 OnTreeUnitsPopupMenu(o, null); |
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 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1103 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1104 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
|
1105 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1106 Widget widget = args.Widget; |
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 if (widget is UnitDisplayWidget) |
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 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit); |
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 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1113 |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1114 protected virtual void HelpAboutActivated(object sender, System.EventArgs e) |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1115 { |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1116 FrmAbout form = FrmAbout.GetForm(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1117 form.Run(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1118 form.Hide(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1119 } |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1120 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1121 public override ICollection<Action> Actions |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1122 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1123 get |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1124 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1125 List<Action> actions = new List<Action>(); |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1126 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1127 foreach (ActionGroup actionGroup in this.UIManager.ActionGroups) |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1128 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1129 actions.AddRange(actionGroup.ListActions()); |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1130 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1131 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1132 return actions; |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1133 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1134 } |
0 | 1135 } |
1136 } |