Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmMain.cs @ 2:74df258710fe
Fixes #8 - Update SWF version of WarFoundry
* Add translations file and copy on build
* Add names to controls in FrmMain
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Dec 2008 19:20:26 +0000 |
parents | 42cf06b8f897 |
children | 8935971e307c |
rev | line source |
---|---|
0 | 1 using System; |
2 using System.Drawing; | |
3 using System.Drawing.Drawing2D; | |
4 using System.Collections; | |
5 using System.ComponentModel; | |
6 using System.Windows.Forms; | |
7 using System.Data; | |
8 using System.IO; | |
9 using System.Threading; | |
10 using IBBoard; | |
11 using IBBoard.CustomMath; | |
12 using IBBoard.Commands; | |
13 using IBBoard.IO; | |
14 using IBBoard.Lang; | |
15 using IBBoard.WarFoundry.API; | |
16 using IBBoard.WarFoundry.API.Commands; | |
17 using IBBoard.Windows.Forms; | |
18 using IBBoard.Xml; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
19 using log4net; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
20 using IBBoard.WarFoundry.API.Objects; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
21 using IBBoard.Windows.Forms.I18N; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
22 using IBBoard.WarFoundry.API.Savers; |
0 | 23 |
24 namespace IBBoard.WarFoundry | |
25 { | |
26 /// <summary> | |
27 /// Summary description for Form1. | |
28 /// </summary> | |
29 public class FrmMain : System.Windows.Forms.Form | |
30 { | |
31 private static readonly string AppTitle = "WarFoundry"; | |
32 | |
33 private Preferences preferences; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
34 protected readonly ILog logger = LogManager.GetLogger(typeof(FrmMain)); |
0 | 35 |
36 private CommandStack commandStack; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
37 private ToolBarButton[] categoryButtons; |
0 | 38 |
39 public ObjectAddDelegate UnitAddedMethod; | |
40 public ObjectRemoveDelegate UnitRemovedMethod; | |
41 public DoubleValChangedDelegate PointsValueChangedMethod; | |
42 //public FailedUnitRequirementDelegate FailedUnitRequirementMethod; | |
43 | |
44 private FrmArmyTree armyTree; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
45 private FrmDebugOutput debugWindow; |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
46 private string loadedFilePath; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
47 |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
48 private System.ComponentModel.IContainer components; |
0 | 49 private System.Windows.Forms.ToolBar toolBar; |
50 private IBBoard.Windows.Forms.IBBToolBarButton bttnNewArmy; | |
51 private System.Windows.Forms.ImageList buttonIcons; | |
52 private IBBoard.Windows.Forms.IBBToolBarButton bttnSaveArmy; | |
53 private System.Windows.Forms.OpenFileDialog openArmyDialog; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
54 private System.Windows.Forms.SaveFileDialog saveArmyDialog; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
55 private IBBoard.Windows.Forms.IBBToolBarButton bttnOpenArmy; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
56 private IBBoard.Windows.Forms.IBBToolBarButton bttnSep1; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
57 private IBBoard.Windows.Forms.IBBToolBarButton bttnUndo; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
58 private IBBoard.Windows.Forms.IBBToolBarButton bttnRedo; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
59 private System.Windows.Forms.MainMenu mainMenu; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
60 private IBBoard.Windows.Forms.IBBMenuItem menuFile; |
0 | 61 private IBBoard.Windows.Forms.IBBMenuItem miNewArmy; |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
62 private IBBoard.Windows.Forms.IBBMenuItem miOpenArmy; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
63 private IBBoard.Windows.Forms.IBBMenuItem miCloseArmy; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
64 private IBBoard.Windows.Forms.IBBMenuItem miSaveArmy; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
65 private IBBoard.Windows.Forms.IBBMenuItem miSaveArmyAs; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
66 private System.Windows.Forms.MenuItem miSep2; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
67 private IBBoard.Windows.Forms.IBBMenuItem miChangeSystem; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
68 private System.Windows.Forms.MenuItem miSep1; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
69 private IBBoard.Windows.Forms.IBBMenuItem miReloadFiles; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
70 private System.Windows.Forms.MenuItem miSep3; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
71 private IBBoard.Windows.Forms.IBBMenuItem miExit; |
0 | 72 private IBBoard.Windows.Forms.IBBMenuItem menuEdit; |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
73 private IBBoard.Windows.Forms.IBBMenuItem miUndo; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
74 private IBBoard.Windows.Forms.IBBMenuItem miRedo; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
75 private IBBoard.Windows.Forms.IBBMenuItem menuHelp; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
76 private IBBoard.Windows.Forms.IBBMenuItem miDebugWindow; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
77 private IBBoard.Windows.Forms.IBBMenuItem miAbout; |
0 | 78 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbMainPanel; |
79 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbErrorPanel; | |
80 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel; | |
81 private System.Windows.Forms.ContextMenu undoMenu; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
82 private System.Windows.Forms.ContextMenu redoMenu; |
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
83 private IBBoard.Windows.Forms.ColorableStatusBar statusBar; |
0 | 84 private System.Windows.Forms.Timer statusBarTimer; |
85 private System.Windows.Forms.Panel pnlRight; | |
86 | |
87 public FrmMain(string[] args) | |
88 { | |
89 this.Closing+=new CancelEventHandler(FrmMain_Closing); | |
90 CommandStack.CommandStackUpdated+=new MethodInvoker(commandStack_CommandStackUpdated); | |
91 | |
92 InitializeComponent(); | |
93 | |
94 Preferences = new Preferences("WarFoundry"); | |
95 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); | |
96 | |
97 //pnlRight.Left = ClientSize.Width - pnlRight.Width - 2; | |
98 //pnlRight.Top = toolBar.Height + 5; | |
99 //pnlRight.Height = ClientRectangle.Bottom - statusBar.Height - pnlRight.Top - 3; | |
100 | |
101 foreach (Control ctrl in Controls) | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
102 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
103 ControlTranslator.TranslateControl(ctrl); |
0 | 104 } |
105 | |
106 foreach(Component comp in components.Components) | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
107 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
108 ControlTranslator.TranslateComponent(comp); |
0 | 109 } |
110 | |
111 foreach (IBBMenuItem mi in Menu.MenuItems) | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
112 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
113 ControlTranslator.TranslateComponent(mi); |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
114 } |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
115 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
116 ControlTranslator.TranslateComponent(openArmyDialog); |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
117 ControlTranslator.TranslateComponent(saveArmyDialog); |
0 | 118 |
119 WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged); | |
120 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged); | |
121 UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod); | |
122 UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod); | |
123 PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod); | |
124 //FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(FrmMain_FailedUnitRequirement); | |
125 | |
126 sbErrorPanel.Color = Color.Red; | |
127 | |
128 armyTree = new FrmArmyTree(CommandStack); | |
129 armyTree.MdiParent = this; | |
130 armyTree.Show(); | |
131 armyTree.StartPosition = FormStartPosition.Manual; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
132 armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10); |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
133 ControlTranslator.TranslateControl(armyTree); |
0 | 134 |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
135 /* |
0 | 136 if (args.Length == 1) |
137 { | |
138 logger.Debug("Attempting to load from file"); | |
139 FileInfo file = new FileInfo(args[0]); | |
140 | |
141 try | |
142 { | |
143 if (file.Extension.Equals("."+Factory.GetArmyFileExtension())) | |
144 { | |
145 WarFoundryCore.CurrentArmy = Factory.CreateArmyFromFile(file); | |
146 logger.InfoFormat("Loaded army from {0}", file.FullName); | |
147 } | |
148 else if (file.Extension.Equals("."+Factory.GetSystemFileExtension())) | |
149 { | |
150 WarFoundryCore.CurrentGameSystem = Factory.CreateGameSystemFromFile(file); | |
151 logger.InfoFormat("Loaded game system from {0}", file.FullName); | |
152 } | |
153 } | |
154 catch (InvalidFileException ex) | |
155 { | |
156 MessageBox.Show(Translation.GetTranslation("InvalidFileLoadError", "The file loaded ({0}) was not a valid WarFoundry file", file.FullName), Translation.GetTranslation("InvalidFileLoadTitle", "Invalid data file", null), MessageBoxButtons.OK, MessageBoxIcon.Error); | |
157 logger.Error(ex); | |
158 } | |
159 } | |
160 else | |
161 { | |
162 string gameSystemID = Preferences.GetStringProperty("currSystem"); | |
163 | |
164 if (gameSystemID!=null && !"".Equals(gameSystemID)) | |
165 { | |
166 logger.Debug("Attempting to load current game system from properties"); | |
167 GameSystem sys = Factory.GetGameSystem(gameSystemID); | |
168 | |
169 if (sys!=null) | |
170 { | |
171 WarFoundryCore.CurrentGameSystem = sys; | |
172 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); | |
173 } | |
174 } | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
175 }*/ |
0 | 176 } |
177 | |
178 public static string DataPath | |
179 { | |
180 get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; } | |
181 } | |
182 | |
183 public static String ArmiesPath | |
184 { | |
185 get { return Constants.UserDataPath+Constants.DirectoryChar+"armies"; } | |
186 } | |
187 | |
188 public Preferences Preferences | |
189 { | |
190 get { return preferences; } | |
191 set { preferences = value; } | |
192 } | |
193 | |
194 public CommandStack CommandStack | |
195 { | |
196 get | |
197 { | |
198 if (commandStack == null) | |
199 { | |
200 commandStack = new CommandStack(); | |
201 } | |
202 | |
203 return commandStack; | |
204 } | |
205 } | |
206 | |
207 /// <summary> | |
208 /// Clean up any resources being used. | |
209 /// </summary> | |
210 protected override void Dispose( bool disposing ) | |
211 { | |
212 if( disposing ) | |
213 { | |
214 if (components != null) | |
215 { | |
216 components.Dispose(); | |
217 } | |
218 } | |
219 base.Dispose( disposing ); | |
220 } | |
221 | |
222 #region Windows Form Designer generated code | |
223 /// <summary> | |
224 /// Required method for Designer support - do not modify | |
225 /// the contents of this method with the code editor. | |
226 /// </summary> | |
227 private void InitializeComponent() | |
228 { | |
229 this.components = new System.ComponentModel.Container(); | |
230 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain)); | |
231 this.statusBar = new IBBoard.Windows.Forms.ColorableStatusBar(); | |
232 this.sbMainPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel(); | |
233 this.sbErrorPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel(); | |
234 this.sbPointsPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel(); | |
235 this.toolBar = new System.Windows.Forms.ToolBar(); | |
236 this.bttnNewArmy = new IBBoard.Windows.Forms.IBBToolBarButton(); | |
237 this.bttnOpenArmy = new IBBoard.Windows.Forms.IBBToolBarButton(); | |
238 this.bttnSaveArmy = new IBBoard.Windows.Forms.IBBToolBarButton(); | |
239 this.bttnSep1 = new IBBoard.Windows.Forms.IBBToolBarButton(); | |
240 this.bttnUndo = new IBBoard.Windows.Forms.IBBToolBarButton(); | |
241 this.undoMenu = new System.Windows.Forms.ContextMenu(); | |
242 this.bttnRedo = new IBBoard.Windows.Forms.IBBToolBarButton(); | |
243 this.redoMenu = new System.Windows.Forms.ContextMenu(); | |
244 this.buttonIcons = new System.Windows.Forms.ImageList(this.components); | |
245 this.mainMenu = new System.Windows.Forms.MainMenu(this.components); | |
246 this.menuFile = new IBBoard.Windows.Forms.IBBMenuItem(); | |
247 this.miNewArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | |
248 this.miOpenArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | |
249 this.miSaveArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | |
250 this.miSaveArmyAs = new IBBoard.Windows.Forms.IBBMenuItem(); | |
251 this.miCloseArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | |
252 this.miSep1 = new System.Windows.Forms.MenuItem(); | |
253 this.miChangeSystem = new IBBoard.Windows.Forms.IBBMenuItem(); | |
254 this.miSep2 = new System.Windows.Forms.MenuItem(); | |
255 this.miReloadFiles = new IBBoard.Windows.Forms.IBBMenuItem(); | |
256 this.miSep3 = new System.Windows.Forms.MenuItem(); | |
257 this.miExit = new IBBoard.Windows.Forms.IBBMenuItem(); | |
258 this.menuEdit = new IBBoard.Windows.Forms.IBBMenuItem(); | |
259 this.miUndo = new IBBoard.Windows.Forms.IBBMenuItem(); | |
260 this.miRedo = new IBBoard.Windows.Forms.IBBMenuItem(); | |
261 this.menuHelp = new IBBoard.Windows.Forms.IBBMenuItem(); | |
262 this.miAbout = new IBBoard.Windows.Forms.IBBMenuItem(); | |
263 this.miDebugWindow = new IBBoard.Windows.Forms.IBBMenuItem(); | |
264 this.openArmyDialog = new System.Windows.Forms.OpenFileDialog(); | |
265 this.saveArmyDialog = new System.Windows.Forms.SaveFileDialog(); | |
266 this.pnlRight = new System.Windows.Forms.Panel(); | |
267 this.statusBarTimer = new System.Windows.Forms.Timer(this.components); | |
268 ((System.ComponentModel.ISupportInitialize)(this.sbMainPanel)).BeginInit(); | |
269 ((System.ComponentModel.ISupportInitialize)(this.sbErrorPanel)).BeginInit(); | |
270 ((System.ComponentModel.ISupportInitialize)(this.sbPointsPanel)).BeginInit(); | |
271 this.SuspendLayout(); | |
272 // | |
273 // statusBar | |
274 // | |
275 this.statusBar.Location = new System.Drawing.Point(0, 548); | |
276 this.statusBar.Name = "statusBar"; | |
277 this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] { | |
278 this.sbMainPanel, | |
279 this.sbErrorPanel, | |
280 this.sbPointsPanel}); | |
281 this.statusBar.ShowPanels = true; | |
282 this.statusBar.Size = new System.Drawing.Size(792, 22); | |
283 this.statusBar.TabIndex = 1; | |
284 this.statusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar_PanelClick); | |
285 this.statusBar.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem); | |
286 // | |
287 // sbMainPanel | |
288 // | |
289 this.sbMainPanel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring; | |
290 this.sbMainPanel.Color = System.Drawing.SystemColors.WindowText; | |
291 this.sbMainPanel.Name = "sbMainPanel"; | |
292 this.sbMainPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw; | |
293 this.sbMainPanel.Width = 475; | |
294 // | |
295 // sbErrorPanel | |
296 // | |
297 this.sbErrorPanel.Color = System.Drawing.SystemColors.WindowText; | |
298 this.sbErrorPanel.Name = "sbErrorPanel"; | |
299 this.sbErrorPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw; | |
300 this.sbErrorPanel.Width = 150; | |
301 // | |
302 // sbPointsPanel | |
303 // | |
304 this.sbPointsPanel.Color = System.Drawing.SystemColors.WindowText; | |
305 this.sbPointsPanel.Name = "sbPointsPanel"; | |
306 this.sbPointsPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw; | |
307 this.sbPointsPanel.ToolTipText = "Current Points Total"; | |
308 this.sbPointsPanel.Width = 150; | |
309 // | |
310 // toolBar | |
311 // | |
312 this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat; | |
313 this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { | |
314 this.bttnNewArmy, | |
315 this.bttnOpenArmy, | |
316 this.bttnSaveArmy, | |
317 this.bttnSep1, | |
318 this.bttnUndo, | |
319 this.bttnRedo}); | |
320 this.toolBar.ButtonSize = new System.Drawing.Size(16, 16); | |
321 this.toolBar.DropDownArrows = true; | |
322 this.toolBar.ImageList = this.buttonIcons; | |
323 this.toolBar.Location = new System.Drawing.Point(0, 0); | |
324 this.toolBar.Name = "toolBar"; | |
325 this.toolBar.ShowToolTips = true; | |
326 this.toolBar.Size = new System.Drawing.Size(792, 28); | |
327 this.toolBar.TabIndex = 2; | |
328 this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); | |
329 // | |
330 // bttnNewArmy | |
331 // | |
332 this.bttnNewArmy.Enabled = false; | |
333 this.bttnNewArmy.ImageIndex = 0; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
334 this.bttnNewArmy.Name = "bttnNewArmy"; |
0 | 335 // |
336 // bttnOpenArmy | |
337 // | |
338 this.bttnOpenArmy.ImageIndex = 2; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
339 this.bttnOpenArmy.Name = "bttnOpenArmy"; |
0 | 340 // |
341 // bttnSaveArmy | |
342 // | |
343 this.bttnSaveArmy.Enabled = false; | |
344 this.bttnSaveArmy.ImageIndex = 1; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
345 this.bttnSaveArmy.Name = "bttnSaveArmy"; |
0 | 346 // |
347 // bttnSep1 | |
348 // | |
349 this.bttnSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator; | |
350 // | |
351 // bttnUndo | |
352 // | |
353 this.bttnUndo.DropDownMenu = this.undoMenu; | |
354 this.bttnUndo.Enabled = false; | |
355 this.bttnUndo.ImageIndex = 3; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
356 this.bttnUndo.Name = "bttnUndo"; |
0 | 357 this.bttnUndo.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton; |
358 // | |
359 // bttnRedo | |
360 // | |
361 this.bttnRedo.DropDownMenu = this.redoMenu; | |
362 this.bttnRedo.Enabled = false; | |
363 this.bttnRedo.ImageIndex = 4; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
364 this.bttnRedo.Name = "bttnRedo"; |
0 | 365 this.bttnRedo.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton; |
366 // | |
367 // buttonIcons | |
368 // | |
369 this.buttonIcons.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("buttonIcons.ImageStream"))); | |
370 this.buttonIcons.TransparentColor = System.Drawing.Color.Transparent; | |
371 this.buttonIcons.Images.SetKeyName(0, ""); | |
372 this.buttonIcons.Images.SetKeyName(1, ""); | |
373 this.buttonIcons.Images.SetKeyName(2, ""); | |
374 this.buttonIcons.Images.SetKeyName(3, ""); | |
375 this.buttonIcons.Images.SetKeyName(4, ""); | |
376 this.buttonIcons.Images.SetKeyName(5, ""); | |
377 this.buttonIcons.Images.SetKeyName(6, ""); | |
378 // | |
379 // mainMenu | |
380 // | |
381 this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
382 this.menuFile, | |
383 this.menuEdit, | |
384 this.menuHelp}); | |
385 // | |
386 // menuFile | |
387 // | |
388 this.menuFile.Index = 0; | |
389 this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
390 this.miNewArmy, | |
391 this.miOpenArmy, | |
392 this.miSaveArmy, | |
393 this.miSaveArmyAs, | |
394 this.miCloseArmy, | |
395 this.miSep1, | |
396 this.miChangeSystem, | |
397 this.miSep2, | |
398 this.miReloadFiles, | |
399 this.miSep3, | |
400 this.miExit}); | |
401 this.menuFile.Text = "&file"; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
402 this.menuFile.Name = "menuFile"; |
0 | 403 // |
404 // miNewArmy | |
405 // | |
406 this.miNewArmy.Index = 0; | |
407 this.miNewArmy.Text = "&new army"; | |
408 this.miNewArmy.Click += new System.EventHandler(this.miNewArmy_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
409 this.miNewArmy.Name = "miNewArmy"; |
0 | 410 // |
411 // miOpenArmy | |
412 // | |
413 this.miOpenArmy.Index = 1; | |
414 this.miOpenArmy.Text = "&open army"; | |
415 this.miOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
416 this.miOpenArmy.Name = "miOpenArmy"; |
0 | 417 // |
418 // miSaveArmy | |
419 // | |
420 this.miSaveArmy.Enabled = false; | |
421 this.miSaveArmy.Index = 2; | |
422 this.miSaveArmy.Text = "&save army"; | |
423 this.miSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
424 this.miSaveArmy.Name = "miSaveArmy"; |
0 | 425 // |
426 // miSaveArmyAs | |
427 // | |
428 this.miSaveArmyAs.Enabled = false; | |
429 this.miSaveArmyAs.Index = 3; | |
430 this.miSaveArmyAs.Text = "save army &as..."; | |
431 this.miSaveArmyAs.Click += new System.EventHandler(this.miSaveArmyAs_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
432 this.miSaveArmyAs.Name = "miSaveArmyAs"; |
0 | 433 // |
434 // miCloseArmy | |
435 // | |
436 this.miCloseArmy.Enabled = false; | |
437 this.miCloseArmy.Index = 4; | |
438 this.miCloseArmy.Text = "&close army"; | |
439 this.miCloseArmy.Click += new System.EventHandler(this.miCloseArmy_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
440 this.miCloseArmy.Name = "miCloseArmy"; |
0 | 441 // |
442 // miSep1 | |
443 // | |
444 this.miSep1.Index = 5; | |
445 this.miSep1.Text = "-"; | |
446 // | |
447 // miChangeSystem | |
448 // | |
449 this.miChangeSystem.Index = 6; | |
450 this.miChangeSystem.Text = "change &game system"; | |
451 this.miChangeSystem.Click += new System.EventHandler(this.miChangeSystem_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
452 this.miChangeSystem.Name = "miChangeSystem"; |
0 | 453 // |
454 // miSep2 | |
455 // | |
456 this.miSep2.Index = 7; | |
457 this.miSep2.Text = "-"; | |
458 // | |
459 // miReloadFiles | |
460 // | |
461 this.miReloadFiles.Index = 8; | |
462 this.miReloadFiles.Text = "&reload files"; | |
463 this.miReloadFiles.Click += new System.EventHandler(this.miReloadFiles_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
464 this.miReloadFiles.Name = "miReloadFiles"; |
0 | 465 // |
466 // miSep3 | |
467 // | |
468 this.miSep3.Index = 9; | |
469 this.miSep3.Text = "-"; | |
470 // | |
471 // miExit | |
472 // | |
473 this.miExit.Index = 10; | |
474 this.miExit.Text = "e&xit"; | |
475 this.miExit.Click += new System.EventHandler(this.miExit_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
476 this.miExit.Name = "miExit"; |
0 | 477 // |
478 // menuEdit | |
479 // | |
480 this.menuEdit.Index = 1; | |
481 this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
482 this.miUndo, | |
483 this.miRedo}); | |
484 this.menuEdit.Text = "&edit"; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
485 this.menuEdit.Name = "menuEdit"; |
0 | 486 // |
487 // miUndo | |
488 // | |
489 this.miUndo.Enabled = false; | |
490 this.miUndo.Index = 0; | |
491 this.miUndo.Text = "&undo"; | |
492 this.miUndo.Click += new System.EventHandler(this.miUndo_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
493 this.miUndo.Name = "miUndo"; |
0 | 494 // |
495 // miRedo | |
496 // | |
497 this.miRedo.Enabled = false; | |
498 this.miRedo.Index = 1; | |
499 this.miRedo.Text = "&redo"; | |
500 this.miRedo.Click += new System.EventHandler(this.miRedo_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
501 this.miRedo.Name = "miRedo"; |
0 | 502 // |
503 // menuHelp | |
504 // | |
505 this.menuHelp.Index = 2; | |
506 this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
507 this.miAbout, | |
508 this.miDebugWindow}); | |
509 this.menuHelp.Text = "&help"; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
510 this.menuHelp.Name = "menuHelp"; |
0 | 511 // |
512 // miAbout | |
513 // | |
514 this.miAbout.Enabled = false; | |
515 this.miAbout.Index = 0; | |
516 this.miAbout.Text = "&about"; | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
517 this.miAbout.Name = "miAbout"; |
0 | 518 // |
519 // miDebugWindow | |
520 // | |
521 this.miDebugWindow.Index = 1; | |
522 this.miDebugWindow.Text = "&debug"; | |
523 this.miDebugWindow.Click += new System.EventHandler(this.miDebugWindow_Click); | |
2
74df258710fe
Fixes #8 - Update SWF version of WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
524 this.miDebugWindow.Name = "miDebugWindow"; |
0 | 525 // |
526 // saveArmyDialog | |
527 // | |
528 this.saveArmyDialog.Title = "Translatable:saveArmyDialog"; | |
529 // | |
530 // pnlRight | |
531 // | |
532 this.pnlRight.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | |
533 | System.Windows.Forms.AnchorStyles.Right))); | |
534 this.pnlRight.BackColor = System.Drawing.SystemColors.AppWorkspace; | |
535 this.pnlRight.Location = new System.Drawing.Point(726, 30); | |
536 this.pnlRight.Name = "pnlRight"; | |
537 this.pnlRight.Size = new System.Drawing.Size(64, 516); | |
538 this.pnlRight.TabIndex = 4; | |
539 this.pnlRight.Visible = false; | |
540 this.pnlRight.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlRight_Paint); | |
541 // | |
542 // statusBarTimer | |
543 // | |
544 this.statusBarTimer.Interval = 5000; | |
545 this.statusBarTimer.Tick += new System.EventHandler(this.statusBarTimer_Tick); | |
546 // | |
547 // FrmMain | |
548 // | |
549 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
550 this.ClientSize = new System.Drawing.Size(792, 570); | |
551 this.Controls.Add(this.pnlRight); | |
552 this.Controls.Add(this.toolBar); | |
553 this.Controls.Add(this.statusBar); | |
554 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); | |
555 this.IsMdiContainer = true; | |
556 this.Menu = this.mainMenu; | |
557 this.Name = "FrmMain"; | |
558 this.Text = "WarFoundry"; | |
559 ((System.ComponentModel.ISupportInitialize)(this.sbMainPanel)).EndInit(); | |
560 ((System.ComponentModel.ISupportInitialize)(this.sbErrorPanel)).EndInit(); | |
561 ((System.ComponentModel.ISupportInitialize)(this.sbPointsPanel)).EndInit(); | |
562 this.ResumeLayout(false); | |
563 this.PerformLayout(); | |
564 | |
565 } | |
566 #endregion | |
567 | |
568 /// <summary> | |
569 /// The main entry point for the application. | |
570 /// </summary> | |
571 [STAThread] | |
572 static void Main(string[] args) | |
573 { | |
574 try | |
575 { | |
576 ///TODO: Work out how to auto-embed the Manifest file so that we can have visual styles without having a .manifest file floating around | |
577 //and without using the line below, which causes the toolbar buttons to lose their icons | |
578 //Application.EnableVisualStyles(); | |
579 Application.Run(new FrmMain(args)); | |
580 } | |
581 catch(Exception ex) | |
582 { | |
583 LogManager.GetLogger(typeof(FrmMain)).Fatal(ex); | |
584 MessageBox.Show(null, "A major, unexpected and fatal error ocurred while starting the application: \r\n\r\n"+ex.Message+"\r\n\r\n"+ex.StackTrace, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
585 } | |
586 } | |
587 | |
588 private void miExit_Click(object sender, System.EventArgs e) | |
589 { | |
590 Application.Exit(); | |
591 } | |
592 | |
593 private void miNewArmy_Click(object sender, System.EventArgs e) | |
594 { | |
595 createNewArmy(); | |
596 } | |
597 | |
598 private void createNewArmy() | |
599 { | |
600 if (closeCurrentArmy()) | |
601 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
602 FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem); |
0 | 603 DialogResult dr = newArmy.ShowDialog(); |
604 | |
605 if (dr == DialogResult.OK) | |
606 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
607 CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); |
0 | 608 } |
609 } | |
610 } | |
611 | |
612 private bool openArmy() | |
613 { | |
614 if (closeCurrentArmy()) | |
615 { | |
616 if (openArmyDialog.Filter=="") | |
617 { | |
618 string savePath = ArmiesPath; | |
619 | |
620 if (!Directory.Exists(savePath)) | |
621 { | |
622 Directory.CreateDirectory(savePath); | |
623 } | |
624 | |
625 openArmyDialog.InitialDirectory = savePath; | |
626 openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; | |
627 openArmyDialog.Title = Translation.GetTranslation("openArmyDialog"); | |
628 | |
629 } | |
630 | |
631 DialogResult dr = openArmyDialog.ShowDialog(this); | |
632 | |
633 if (dr == DialogResult.OK) | |
634 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
635 /* |
0 | 636 try |
637 { | |
638 CurrentArmy = Factory.LoadArmy(openArmyDialog.FileName); | |
639 return true; | |
640 } | |
641 catch (InvalidFileException ex) | |
642 { | |
643 logger.Error(ex); | |
644 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid data file"), MessageBoxButtons.OK, MessageBoxIcon.Error); | |
645 return false; | |
646 } | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
647 * */ |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
648 return false; |
0 | 649 } |
650 else | |
651 { | |
652 return false; | |
653 } | |
654 } | |
655 else | |
656 { | |
657 return false; | |
658 } | |
659 } | |
660 | |
661 private bool closeCurrentArmy() | |
662 { | |
663 if (CurrentArmy!=null) | |
664 { | |
665 bool canClose = false; | |
666 | |
667 if (CommandStack.IsDirty()) | |
668 { | |
669 DialogResult dr = MessageBox.Show(this, "The army \""+CurrentArmy.Name+"\" has been modified.\r\nSave changes before closing army?", "Unsaved changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3); | |
670 | |
671 if (dr == DialogResult.Yes) | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
672 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
673 canClose = SaveCurrentArmy(); |
0 | 674 } |
675 else if (dr == DialogResult.No) | |
676 { | |
677 canClose = true; | |
678 } | |
679 //else they said cancel and we default to "canClose = false" so do nothing | |
680 } | |
681 else | |
682 { | |
683 canClose = true; | |
684 } | |
685 | |
686 if (canClose) | |
687 { | |
688 //do close | |
689 disableCategoryButtons(); | |
690 CurrentArmy = null; | |
691 return true; | |
692 } | |
693 else | |
694 { | |
695 return false; | |
696 } | |
697 } | |
698 else | |
699 { | |
700 disableCategoryButtons(); | |
701 //pretend we succeeded | |
702 return true; | |
703 } | |
704 } | |
705 | |
706 private void undoLastAction() | |
707 { | |
708 if (commandStack.CanUndo()) | |
709 { | |
710 commandStack.Undo(); | |
711 } | |
712 } | |
713 | |
714 private void redoAction() | |
715 { | |
716 if (commandStack.CanRedo()) | |
717 { | |
718 commandStack.Redo(); | |
719 } | |
720 } | |
721 | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
722 private bool SaveCurrentArmy() |
0 | 723 { |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
724 bool saved = false; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
725 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
726 if (loadedFilePath != null || PromptForFilePath()) |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
727 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
728 saved = SaveCurrentArmyToFile(); |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
729 } |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
730 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
731 return saved; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
732 } |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
733 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
734 private bool SaveCurrentArmyAs() |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
735 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
736 bool saved = false; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
737 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
738 if (PromptForFilePath()) |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
739 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
740 saved = SaveCurrentArmyToFile(); |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
741 } |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
742 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
743 return saved; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
744 } |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
745 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
746 private bool SaveCurrentArmyToFile() |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
747 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
748 if (WarFoundrySaver.GetSaver().Save(CurrentArmy, loadedFilePath)) |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
749 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
750 miSaveArmy.Enabled = false; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
751 bttnSaveArmy.Enabled = false; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
752 CommandStack.setCleanMark(); |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
753 return true; |
0 | 754 } |
755 else | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
756 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
757 loadedFilePath = null; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
758 MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); |
0 | 759 return false; |
760 } | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
761 } |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
762 |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
763 private bool PromptForFilePath() |
0 | 764 { |
765 if (saveArmyDialog.Filter == "") | |
766 { | |
767 string savePath = ArmiesPath; | |
768 | |
769 if (!Directory.Exists(savePath)) | |
770 { | |
771 Directory.CreateDirectory(savePath); | |
772 } | |
773 | |
774 saveArmyDialog.InitialDirectory = savePath; | |
775 saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; | |
776 saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog"); | |
777 } | |
778 | |
779 DialogResult dr = saveArmyDialog.ShowDialog(this); | |
780 | |
781 if (dr == DialogResult.OK) | |
782 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
783 loadedFilePath = saveArmyDialog.FileName; |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
784 return true; |
0 | 785 } |
786 else | |
787 { | |
788 return false; | |
789 } | |
790 } | |
791 | |
792 private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) | |
793 { | |
794 if (e.Button == bttnUndo) | |
795 { | |
796 undoLastAction(); | |
797 } | |
798 else if (e.Button == bttnRedo) | |
799 { | |
800 redoAction(); | |
801 } | |
802 else if (e.Button == bttnNewArmy) | |
803 { | |
804 createNewArmy(); | |
805 } | |
806 else if (e.Button == bttnOpenArmy) | |
807 { | |
808 openArmy(); | |
809 } | |
810 else if (e.Button == bttnSaveArmy) | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
811 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
812 SaveCurrentArmy(); |
0 | 813 } |
814 else | |
815 { | |
816 //it must be one of our extra buttons for the categories | |
817 addUnitFromCategory((Category)e.Button.Tag); | |
818 } | |
819 } | |
820 | |
821 private GameSystem CurrentGameSystem | |
822 { | |
823 get { return WarFoundryCore.CurrentGameSystem; } | |
824 set { WarFoundryCore.CurrentGameSystem = value; } | |
825 } | |
826 | |
827 private static Army CurrentArmy | |
828 { | |
829 get { return WarFoundryCore.CurrentArmy; } | |
830 set { WarFoundryCore.CurrentArmy = value; } | |
831 } | |
832 | |
833 private void SelectGameSystem() | |
834 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
835 FrmSelectSystem selectSystem = new FrmSelectSystem(); |
0 | 836 DialogResult dr = selectSystem.ShowDialog(this); |
837 | |
838 if (dr==DialogResult.OK) | |
839 { | |
840 closeCurrentArmy(); | |
841 CurrentGameSystem = selectSystem.GameSystem; | |
842 } | |
843 } | |
844 | |
845 private void miChangeSystem_Click(object sender, System.EventArgs e) | |
846 { | |
847 SelectGameSystem(); | |
848 } | |
849 | |
850 private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) | |
851 { | |
852 miNewArmy.Enabled = newSystem != null; | |
853 bttnNewArmy.Enabled = newSystem != null; | |
854 setAppTitle(); | |
855 removeCategoryButtons(); | |
856 addCategoryButtons(); | |
857 } | |
858 | |
859 private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) | |
860 { | |
861 setAppTitle(); | |
862 | |
863 if (oldArmy != null) | |
864 { | |
865 oldArmy.UnitAdded += UnitAddedMethod; | |
866 oldArmy.UnitRemoved += UnitRemovedMethod; | |
867 oldArmy.PointsValueChanged += PointsValueChangedMethod; | |
868 } | |
869 | |
870 if (CurrentArmy==null) | |
871 { | |
872 miSaveArmyAs.Enabled = false; | |
873 miCloseArmy.Enabled = false; | |
874 disableCategoryButtons(); | |
875 } | |
876 else | |
877 { | |
878 newArmy.UnitAdded += UnitAddedMethod; | |
879 newArmy.UnitRemoved += UnitRemovedMethod; | |
880 newArmy.PointsValueChanged += PointsValueChangedMethod; | |
881 //TODO: Clear all buttons | |
882 miSaveArmyAs.Enabled = true; | |
883 miCloseArmy.Enabled = true; | |
884 enableCategoryButtons(); | |
885 | |
886 if (newArmy.Race.HasCategoryOverrides()) | |
887 { | |
888 removeCategoryButtons(); | |
889 addCategoryButtons(newArmy.Race.Categories); | |
890 } | |
891 } | |
892 | |
893 CommandStack.Reset(); | |
894 | |
895 miSaveArmy.Enabled = false; | |
896 bttnSaveArmy.Enabled = false; | |
897 | |
898 setPointsPanelText(); | |
899 } | |
900 | |
901 private void addCategoryButtons() | |
902 { | |
903 if (CurrentGameSystem!=null) | |
904 { | |
905 addCategoryButtons(CurrentGameSystem.Categories); | |
906 } | |
907 } | |
908 | |
909 private void addCategoryButtons(Category[] cats) | |
910 { | |
911 int catCount = cats.Length; | |
912 Category cat; | |
913 categoryButtons = new ToolBarButton[catCount+1]; | |
914 | |
915 ToolBarButton sep = new ToolBarButton(); | |
916 sep.Style = ToolBarButtonStyle.Separator; | |
917 categoryButtons[0] = sep; | |
918 | |
919 IBBToolBarButton button; | |
920 | |
921 for (int i = 0; i<catCount; i++) | |
922 { | |
923 cat = cats[i]; | |
924 button = new IBBToolBarButton(); | |
925 ///button.Name = "bttnAddCategory" + cat.Name[0].ToString(); | |
926 button.Text = cat.Name.ToString();//String.Format(Translation.GetTranslation("bttnAddCategory"), cat.Name); | |
927 button.Tag = cat; | |
928 button.ImageIndex = 6; | |
929 button.Enabled = false; | |
930 categoryButtons[i+1] = button; | |
931 } | |
932 | |
933 this.Invoke(new ToolBarButtonRangeDelegate(toolBar.Buttons.AddRange), new object[]{categoryButtons}); | |
934 } | |
935 | |
936 private void removeCategoryButtons() | |
937 { | |
938 if (categoryButtons!=null) | |
939 { | |
940 for (int i = 0; i<categoryButtons.Length; i++) | |
941 { | |
942 this.Invoke(new ToolBarButtonDelegate(toolBar.Buttons.Remove), new object[]{categoryButtons[i]}); | |
943 } | |
944 } | |
945 } | |
946 | |
947 private void enableCategoryButtons() | |
948 { | |
949 setCategoryButtonState(true); | |
950 } | |
951 | |
952 private void disableCategoryButtons() | |
953 { | |
954 setCategoryButtonState(false); | |
955 } | |
956 | |
957 private void setCategoryButtonState(bool state) | |
958 { | |
959 if (categoryButtons!=null) | |
960 { | |
961 for (int i = 0; i<categoryButtons.Length; i++) | |
962 { | |
963 categoryButtons[i].Enabled = state; | |
964 } | |
965 } | |
966 } | |
967 | |
968 private void miSaveArmyAs_Click(object sender, System.EventArgs e) | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
969 { |
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
970 SaveCurrentArmyAs(); |
0 | 971 } |
972 | |
973 private void commandStack_CommandStackUpdated() | |
974 { | |
975 bttnUndo.Enabled = commandStack.CanUndo(); | |
976 miUndo.Enabled = bttnUndo.Enabled; | |
977 bttnRedo.Enabled = commandStack.CanRedo(); | |
978 miRedo.Enabled = bttnRedo.Enabled; | |
979 MenuItem[] menuItems = null; | |
980 int redoLength = commandStack.RedoLength; | |
981 int maxRedo = Math.Min(10, redoLength); | |
982 | |
983 if (redoLength > 0) | |
984 { | |
985 menuItems = new MenuItem[maxRedo]; | |
986 Command com; | |
987 MenuItem mi; | |
988 | |
989 for (int i = 0; i < maxRedo; i++) | |
990 { | |
991 com = commandStack.PeekRedoCommand(i+1); | |
992 | |
993 if (com == null) | |
994 { | |
995 break; | |
996 } | |
997 | |
998 mi = new MenuItem(com.Description); | |
999 mi.Click+=new EventHandler(redoMenu_Click); | |
1000 menuItems[i] = mi; | |
1001 } | |
1002 } | |
1003 | |
1004 redoMenu.MenuItems.Clear(); | |
1005 | |
1006 if (menuItems!=null && menuItems[0]!=null) | |
1007 { | |
1008 bttnRedo.ToolTipText = menuItems[0].Text; | |
1009 redoMenu.MenuItems.AddRange(menuItems); | |
1010 } | |
1011 | |
1012 int undoLength = commandStack.UndoLength; | |
1013 int maxUndo = Math.Min(10, undoLength); | |
1014 MenuItem[] menuItemsUndo = null; | |
1015 | |
1016 if (undoLength > 0) | |
1017 { | |
1018 menuItemsUndo = new MenuItem[maxUndo]; | |
1019 Command com; | |
1020 MenuItem mi; | |
1021 | |
1022 for (int i = 0; i < maxUndo; i++) | |
1023 { | |
1024 com = commandStack.PeekUndoCommand(i+1); | |
1025 | |
1026 if (com == null) | |
1027 { | |
1028 break; | |
1029 } | |
1030 | |
1031 mi = new MenuItem(com.UndoDescription); | |
1032 mi.Click+=new EventHandler(undoMenu_Click); | |
1033 menuItemsUndo[i] = mi; | |
1034 } | |
1035 } | |
1036 | |
1037 undoMenu.MenuItems.Clear(); | |
1038 | |
1039 if (menuItemsUndo!=null && menuItemsUndo[0]!=null) | |
1040 { | |
1041 bttnUndo.ToolTipText = menuItemsUndo[0].Text; | |
1042 undoMenu.MenuItems.AddRange(menuItemsUndo); | |
1043 } | |
1044 | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
1045 bool canSave = loadedFilePath != null; |
0 | 1046 bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null && canSave; |
1047 miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null && canSave; | |
1048 } | |
1049 | |
1050 private void miSaveArmy_Click(object sender, System.EventArgs e) | |
1051 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
1052 SaveCurrentArmy(); |
0 | 1053 } |
1054 | |
1055 private void setAppTitle() | |
1056 { | |
1057 string str = AppTitle; | |
1058 | |
1059 if (CurrentGameSystem!=null) | |
1060 { | |
1061 str+= " - "+CurrentGameSystem.Name; | |
1062 } | |
1063 | |
1064 if (CurrentArmy!=null) | |
1065 { | |
1066 str+= " - "+CurrentArmy.Name; | |
1067 } | |
1068 | |
1069 this.Text = str; | |
1070 } | |
1071 | |
1072 private void addUnitFromCategory(Category cat) | |
1073 { | |
1074 FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy); | |
1075 DialogResult dr = newUnit.ShowDialog(this); | |
1076 | |
1077 if (dr == DialogResult.OK) | |
1078 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
1079 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, cat, CurrentArmy); |
0 | 1080 commandStack.Execute(cmd); |
1081 } | |
1082 } | |
1083 | |
1084 private void FrmMain_UnitAddedMethod(object unitObj) | |
1085 { | |
1086 if (unitObj is Unit) | |
1087 { | |
1088 Unit unit = (Unit)unitObj; | |
1089 sbErrorPanel.Text = ""; | |
1090 } | |
1091 } | |
1092 | |
1093 private void FrmMain_UnitRemovedMethod(object unitObj) | |
1094 { | |
1095 if (unitObj is Unit) | |
1096 { | |
1097 Unit unit = (Unit)unitObj; | |
1098 sbErrorPanel.Text = ""; | |
1099 | |
1100 //check if window is open, and close it if it is | |
1101 foreach (Form frm in this.MdiChildren) | |
1102 { | |
1103 if (frm is FrmUnit) | |
1104 { | |
1105 if (((FrmUnit)frm).Unit == unit) | |
1106 { | |
1107 frm.Close(); | |
1108 break; | |
1109 } | |
1110 } | |
1111 } | |
1112 } | |
1113 } | |
1114 | |
1115 /*private void FrmMain_FailedUnitRequirement(FailedUnitRequirement failedRequirement) | |
1116 { | |
1117 sbErrorPanel.Text = Translation.GetTranslation("UnitRequirementFailed", "Unit Requirement Failed"); | |
1118 sbErrorPanel.Tag = failedRequirement.Description; | |
1119 }*/ | |
1120 | |
1121 /*public void MdiChildMoved() | |
1122 { | |
1123 Point mouseAt = PointToClient(ActiveMdiChild.Location); | |
1124 | |
1125 if (Comparisons.ValueWithinAmount(pnlRight.Right, ActiveMdiChild.Right, 10)) | |
1126 { | |
1127 pnlRight.Visible = true; | |
1128 //pnlRight.Container.Add(ActiveMdiChild); | |
1129 } | |
1130 else | |
1131 { | |
1132 pnlRight.Visible = false; | |
1133 } | |
1134 }*/ | |
1135 | |
1136 public void pnlRight_Paint(object sender, System.Windows.Forms.PaintEventArgs e) | |
1137 { | |
1138 HatchBrush dockCueBrush = new HatchBrush(HatchStyle.LightDownwardDiagonal, Color.White, Color.Gray); | |
1139 Pen dockCuePen = new Pen(dockCueBrush, 10); | |
1140 e.Graphics.DrawRectangle(dockCuePen, new Rectangle(pnlRight.Left, pnlRight.Top, pnlRight.Width, pnlRight.Height)); | |
1141 } | |
1142 | |
1143 private void miUndo_Click(object sender, System.EventArgs e) | |
1144 { | |
1145 undoLastAction(); | |
1146 } | |
1147 | |
1148 private void miRedo_Click(object sender, System.EventArgs e) | |
1149 { | |
1150 redoAction(); | |
1151 } | |
1152 | |
1153 private void miCloseArmy_Click(object sender, EventArgs e) | |
1154 { | |
1155 closeCurrentArmy(); | |
1156 } | |
1157 | |
1158 private void miOpenArmy_Click(object sender, EventArgs e) | |
1159 { | |
1160 openArmy(); | |
1161 } | |
1162 | |
1163 private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal) | |
1164 { | |
1165 if (obj is Army) | |
1166 { | |
1167 setPointsPanelText(); | |
1168 } | |
1169 } | |
1170 | |
1171 private void setPointsPanelText() | |
1172 { | |
1173 if (CurrentArmy==null) | |
1174 { | |
1175 sbPointsPanel.Text = ""; | |
1176 sbPointsPanel.ResetColor(); | |
1177 } | |
1178 else | |
1179 { | |
1180 sbPointsPanel.Text = String.Format(Translation.GetTranslation("statusPanelPoints"), CurrentArmy.PointsTotal, CurrentArmy.MaxPoints); | |
1181 | |
1182 if (CurrentArmy.PointsTotal>CurrentArmy.MaxPoints) | |
1183 { | |
1184 sbPointsPanel.Color = Color.Red; | |
1185 } | |
1186 else | |
1187 { | |
1188 sbPointsPanel.ResetColor(); | |
1189 } | |
1190 } | |
1191 } | |
1192 | |
1193 private void redoMenu_Click(object sender, EventArgs e) | |
1194 { | |
1195 if (sender is MenuItem) | |
1196 { | |
1197 MenuItem mi = (MenuItem)sender; | |
1198 | |
1199 if (mi.Parent == redoMenu) | |
1200 { | |
1201 //we know it's an redo menu item so find it's index and redo everything | |
1202 int max = mi.Index; | |
1203 | |
1204 for (int i = 0; i <= max; i++) | |
1205 { | |
1206 commandStack.Redo(); | |
1207 } | |
1208 } | |
1209 } | |
1210 } | |
1211 | |
1212 private void undoMenu_Click(object sender, EventArgs e) | |
1213 { | |
1214 if (sender is MenuItem) | |
1215 { | |
1216 MenuItem mi = (MenuItem)sender; | |
1217 | |
1218 if (mi.Parent == undoMenu) | |
1219 { | |
1220 //we know it's an undo menu item so find it's index and undo everything | |
1221 int max = mi.Index; | |
1222 for (int i = 0; i <= max; i++) | |
1223 { | |
1224 commandStack.Undo(); | |
1225 } | |
1226 } | |
1227 } | |
1228 } | |
1229 | |
1230 private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent) | |
1231 { | |
1232 statusBar.ColorableStatusBarDrawItem(sender, sbdevent); | |
1233 } | |
1234 | |
1235 private void miDebugWindow_Click(object sender, EventArgs e) | |
1236 { | |
1237 if (debugWindow == null || debugWindow.IsDisposed) | |
1238 { | |
1239 debugWindow = new FrmDebugOutput(); | |
1240 } | |
1241 | |
1242 debugWindow.Show(); | |
1243 debugWindow.Focus(); | |
1244 } | |
1245 | |
1246 private void FrmMain_Closing(object sender, CancelEventArgs e) | |
1247 { | |
1248 if (!closeCurrentArmy()) | |
1249 { | |
1250 e.Cancel = true; | |
1251 } | |
1252 } | |
1253 | |
1254 private void miReloadFiles_Click(object sender, System.EventArgs e) | |
1255 { | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
1256 WarFoundryLoader.GetDefault().LoadFiles(); |
0 | 1257 sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded"); |
1258 statusBarTimer.Enabled = true; | |
1259 } | |
1260 | |
1261 private void statusBarTimer_Tick(object sender, System.EventArgs e) | |
1262 { | |
1263 sbMainPanel.Text = ""; | |
1264 statusBarTimer.Enabled = false; | |
1265 } | |
1266 | |
1267 private void statusBar_PanelClick(object sender, StatusBarPanelClickEventArgs e) | |
1268 { | |
1269 if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="") | |
1270 { | |
1271 MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
1272 } | |
1273 } | |
1274 } | |
1275 } |