view FrmMain.cs @ 197:10ba2c5340b2

Re #343: Show unit requirement failures * Rework existing dialog box to use new messages
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 15:21:13 +0000
parents 15148d255e50
children ac5f87626abd 53d79e1be712
line source
1 // This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard.
2 //
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.
5 using System;
6 using System.Collections.Generic;
7 using System.Drawing;
8 using System.Drawing.Drawing2D;
9 using System.ComponentModel;
10 using System.Windows.Forms;
11 using System.Data;
12 using System.IO;
13 using System.Threading;
14 using log4net;
15 using IBBoard;
16 using IBBoard.CustomMath;
17 using IBBoard.Commands;
18 using IBBoard.IO;
19 using IBBoard.Lang;
20 using IBBoard.Windows.Forms;
21 using IBBoard.Windows.Forms.I18N;
22 using IBBoard.Xml;
23 using IBBoard.WarFoundry.API;
24 using IBBoard.WarFoundry.API.Commands;
25 using IBBoard.WarFoundry.API.Exporters;
26 using IBBoard.WarFoundry.API.Objects;
27 using IBBoard.WarFoundry.API.Objects.Requirement;
28 using IBBoard.WarFoundry.API.Util;
29 using IBBoard.WarFoundry.API.Savers;
30 using IBBoard.WarFoundry.API.Savers.Xml;
31 using IBBoard.WarFoundry.API.Factories;
32 using IBBoard.WarFoundry.API.Factories.Xml;
34 namespace IBBoard.WarFoundry.GUI.WinForms
35 {
36 /// <summary>
37 /// Summary description for Form1.
38 /// </summary>
39 public class FrmMain : System.Windows.Forms.Form
40 {
41 private static readonly string AppTitle = "WarFoundry";
42 internal static readonly string VERSION = "0.1";
43 const string DefaultDataDir = "data";
44 /* public static string pointsAbbrevSingle;
45 public static string pointsAbbrevPlural;
46 public static string pointsAbbreviation;
47 public static string pointsNameSingle;
48 public static string pointsNamePlural;
49 public static string pointsName;*/
51 private Preferences preferences;
52 private readonly ILog log = LogManager.GetLogger(typeof(FrmMain));
54 private CommandStack commandStack;
56 public ObjectAddDelegate UnitAddedMethod;
57 public ObjectRemoveDelegate UnitRemovedMethod;
58 public DoubleValChangedDelegate PointsValueChangedMethod;
59 //public FailedUnitRequirementDelegate FailedUnitRequirementMethod;
61 private FrmArmyTree armyTree;
62 private string loadedFilePath;
63 private Dictionary<string, FrmUnit> unitWindows;
65 private System.ComponentModel.IContainer components;
66 private System.Windows.Forms.OpenFileDialog openArmyDialog;
67 private System.Windows.Forms.SaveFileDialog saveArmyDialog;
68 private System.Windows.Forms.MainMenu mainMenu;
69 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbMainPanel;
70 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbErrorPanel;
71 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel;
72 private System.Windows.Forms.ContextMenu undoMenu;
73 private System.Windows.Forms.ContextMenu redoMenu;
74 private IBBoard.Windows.Forms.ColorableStatusBar statusBar;
75 private MenuStrip menuStrip;
76 private IBBToolStripMenuItem menuFile;
77 private IBBToolStripMenuItem miNewArmy;
78 private IBBToolStripMenuItem miOpenArmy;
79 private IBBToolStripMenuItem miSaveArmy;
80 private IBBToolStripMenuItem miSaveArmyAs;
81 private IBBToolStripMenuItem miExportArmyAs;
82 private IBBToolStripMenuItem miExportArmyAsBasicHTML;
83 private IBBToolStripMenuItem miCloseArmy;
84 private ToolStripSeparator toolStripSeparator1;
85 private IBBToolStripMenuItem miReloadFiles;
86 private ToolStripSeparator toolStripSeparator2;
87 private IBBToolStripMenuItem miExit;
88 private IBBToolStripMenuItem menuEdit;
89 private IBBToolStripMenuItem miUndo;
90 private IBBToolStripMenuItem miRedo;
91 private IBBToolStripMenuItem menuHelp;
92 private ToolStrip mainToolStrip;
93 private IBBToolStripButton bttnNewArmy;
94 private IBBToolStripButton bttnOpenArmy;
95 private IBBToolStripButton bttnSaveArmy;
96 private ToolStripSeparator toolStripSeparator3;
97 private IBBToolStripSplitButton bttnUndo;
98 private IBBToolStripSplitButton bttnRedo;
99 private ToolStrip catToolStrip;
100 private ToolStripPanel toolStripPanel;
101 private ToolStripSeparator toolStripSeparator4;
102 private IBBToolStripMenuItem miPreferences;
103 private IBBToolStripMenuItem miAbout;
106 /// <summary>
107 /// The main entry point for the application.
108 /// </summary>
109 [STAThread]
110 static void Main(string[] args)
111 {
112 try
113 {
114 LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms");
115 Application.EnableVisualStyles();
116 Application.Run(new FrmMain(args));
117 LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms");
118 }
119 catch (Exception ex)
120 {
121 LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
122 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);
123 }
124 }
126 public FrmMain(string[] args)
127 {
128 this.Closing+=new CancelEventHandler(FrmMain_Closing);
129 CommandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated);
131 InitializeComponent();
132 toolStripPanel.Join(mainToolStrip, 0, 0);
133 toolStripPanel.Join(catToolStrip, mainToolStrip.Right, 0);
135 Preferences = new Preferences("WarFoundry");
136 try
137 {
138 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
139 }
140 catch (TranslationLoadException ex)
141 {
142 log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex);
143 MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
144 }
146 Translation.TranslationChanged += new MethodInvoker(TranslationChanged);
148 TranslateControls();
149 unitWindows = new Dictionary<string, FrmUnit>();
151 WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged);
152 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged);
153 UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod);
154 UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod);
155 PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod);
156 //FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(FrmMain_FailedUnitRequirement);
159 sbErrorPanel.Color = Color.Red;
160 SetPointsPanelToolTipText();
162 // hack to load default files
163 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
164 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
165 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
166 WarFoundrySaver.SetFileSaver(new WarFoundryXmlFileSaver());
167 }
169 private FrmArmyTree GetArmyTree()
170 {
171 if (armyTree == null || armyTree.IsDisposed)
172 {
173 CreateArmyTree();
174 }
176 return armyTree;
177 }
179 private void CreateArmyTree()
180 {
181 armyTree = new FrmArmyTree(CommandStack);
182 armyTree.MdiParent = this;
183 armyTree.StartPosition = FormStartPosition.Manual;
184 armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
185 }
187 private void TranslateControls()
188 {
189 ControlTranslator.TranslateControls(Controls);
190 ControlTranslator.TranslateComponents(components.Components);
191 ControlTranslator.TranslateComponent(openArmyDialog);
192 ControlTranslator.TranslateComponent(saveArmyDialog);
193 //translate pointspanel and tooltip
194 SetPointsPanelToolTipText();
195 SetPointsPanelText();
196 }
198 void TranslationChanged()
199 {
200 TranslateControls();
201 }
203 public static string DataPath
204 {
205 get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; }
206 }
208 public static String ArmiesPath
209 {
210 get { return Environment.GetFolderPath(Environment.SpecialFolder.Personal); }
211 }
213 public Preferences Preferences
214 {
215 get { return preferences; }
216 set { preferences = value; }
217 }
219 public CommandStack CommandStack
220 {
221 get
222 {
223 if (commandStack == null)
224 {
225 commandStack = new CommandStack();
226 }
228 return commandStack;
229 }
230 }
232 /// <summary>
233 /// Clean up any resources being used.
234 /// </summary>
235 protected override void Dispose( bool disposing )
236 {
237 if( disposing )
238 {
239 if (components != null)
240 {
241 components.Dispose();
242 }
243 }
244 base.Dispose( disposing );
245 }
247 #region Windows Form Designer generated code
248 /// <summary>
249 /// Required method for Designer support - do not modify
250 /// the contents of this method with the code editor.
251 /// </summary>
252 private void InitializeComponent()
253 {
254 this.components = new System.ComponentModel.Container();
255 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
256 this.undoMenu = new System.Windows.Forms.ContextMenu();
257 this.redoMenu = new System.Windows.Forms.ContextMenu();
258 this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
259 this.openArmyDialog = new System.Windows.Forms.OpenFileDialog();
260 this.saveArmyDialog = new System.Windows.Forms.SaveFileDialog();
261 this.menuStrip = new System.Windows.Forms.MenuStrip();
262 this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
263 this.miNewArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
264 this.miOpenArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
265 this.miSaveArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
266 this.miSaveArmyAs = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
267 this.miExportArmyAs = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
268 this.miExportArmyAsBasicHTML = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
269 this.miCloseArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
270 this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
271 this.miReloadFiles = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
272 this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
273 this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
274 this.menuEdit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
275 this.miUndo = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
276 this.miRedo = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
277 this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
278 this.miPreferences = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
279 this.menuHelp = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
280 this.miAbout = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
281 this.mainToolStrip = new System.Windows.Forms.ToolStrip();
282 this.bttnNewArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
283 this.bttnOpenArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
284 this.bttnSaveArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
285 this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
286 this.bttnUndo = new IBBoard.Windows.Forms.IBBToolStripSplitButton();
287 this.bttnRedo = new IBBoard.Windows.Forms.IBBToolStripSplitButton();
288 this.catToolStrip = new System.Windows.Forms.ToolStrip();
289 this.statusBar = new IBBoard.Windows.Forms.ColorableStatusBar();
290 this.sbMainPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
291 this.sbErrorPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
292 this.sbPointsPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
293 this.toolStripPanel = new System.Windows.Forms.ToolStripPanel();
294 this.menuStrip.SuspendLayout();
295 this.mainToolStrip.SuspendLayout();
296 ((System.ComponentModel.ISupportInitialize)(this.sbMainPanel)).BeginInit();
297 ((System.ComponentModel.ISupportInitialize)(this.sbErrorPanel)).BeginInit();
298 ((System.ComponentModel.ISupportInitialize)(this.sbPointsPanel)).BeginInit();
299 this.SuspendLayout();
300 //
301 // saveArmyDialog
302 //
303 this.saveArmyDialog.Title = "Translatable:saveArmyDialog";
304 //
305 // menuStrip
306 //
307 this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
308 this.menuFile,
309 this.menuEdit,
310 this.menuHelp});
311 this.menuStrip.Location = new System.Drawing.Point(0, 0);
312 this.menuStrip.Name = "menuStrip";
313 this.menuStrip.Size = new System.Drawing.Size(790, 24);
314 this.menuStrip.TabIndex = 6;
315 this.menuStrip.Text = "menuStrip1";
316 //
317 // menuFile
318 //
319 this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
320 this.miNewArmy,
321 this.miOpenArmy,
322 this.miSaveArmy,
323 this.miSaveArmyAs,
324 this.miExportArmyAs,
325 this.miCloseArmy,
326 this.toolStripSeparator1,
327 this.miReloadFiles,
328 this.toolStripSeparator2,
329 this.miExit});
330 this.menuFile.Name = "menuFile";
331 this.menuFile.Size = new System.Drawing.Size(33, 20);
332 this.menuFile.Text = "&file";
333 //
334 // miNewArmy
335 //
336 this.miNewArmy.Name = "miNewArmy";
337 this.miNewArmy.Size = new System.Drawing.Size(164, 22);
338 this.miNewArmy.Text = "&new army";
339 this.miNewArmy.Click += new System.EventHandler(this.miNewArmy_Click);
340 //
341 // miOpenArmy
342 //
343 this.miOpenArmy.Name = "miOpenArmy";
344 this.miOpenArmy.Size = new System.Drawing.Size(164, 22);
345 this.miOpenArmy.Text = "&open army";
346 this.miOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click);
347 //
348 // miSaveArmy
349 //
350 this.miSaveArmy.Enabled = false;
351 this.miSaveArmy.Name = "miSaveArmy";
352 this.miSaveArmy.Size = new System.Drawing.Size(164, 22);
353 this.miSaveArmy.Text = "&save army";
354 this.miSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click);
355 //
356 // miSaveArmyAs
357 //
358 this.miSaveArmyAs.Enabled = false;
359 this.miSaveArmyAs.Name = "miSaveArmyAs";
360 this.miSaveArmyAs.Size = new System.Drawing.Size(164, 22);
361 this.miSaveArmyAs.Text = "save army &as...";
362 this.miSaveArmyAs.Click += new System.EventHandler(this.miSaveArmyAs_Click);
363 //
364 // miExportArmyAs
365 //
366 this.miExportArmyAs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
367 this.miExportArmyAsBasicHTML});
368 this.miExportArmyAs.Enabled = false;
369 this.miExportArmyAs.Name = "miExportArmyAs";
370 this.miExportArmyAs.Size = new System.Drawing.Size(164, 22);
371 this.miExportArmyAs.Text = "export army as...";
372 //
373 // miExportArmyAsBasicHTML
374 //
375 this.miExportArmyAsBasicHTML.Name = "miExportArmyAsBasicHTML";
376 this.miExportArmyAsBasicHTML.Size = new System.Drawing.Size(130, 22);
377 this.miExportArmyAsBasicHTML.Text = "&basic html";
378 this.miExportArmyAsBasicHTML.Click += new System.EventHandler(this.miExportArmyAsBasicHTML_Click);
379 //
380 // miCloseArmy
381 //
382 this.miCloseArmy.Enabled = false;
383 this.miCloseArmy.Name = "miCloseArmy";
384 this.miCloseArmy.Size = new System.Drawing.Size(164, 22);
385 this.miCloseArmy.Text = "&close army";
386 this.miCloseArmy.Click += new System.EventHandler(this.miCloseArmy_Click);
387 //
388 // toolStripSeparator1
389 //
390 this.toolStripSeparator1.Name = "toolStripSeparator1";
391 this.toolStripSeparator1.Size = new System.Drawing.Size(161, 6);
392 //
393 // miReloadFiles
394 //
395 this.miReloadFiles.Name = "miReloadFiles";
396 this.miReloadFiles.Size = new System.Drawing.Size(164, 22);
397 this.miReloadFiles.Text = "&reload files";
398 this.miReloadFiles.Click += new System.EventHandler(this.miReloadFiles_Click);
399 //
400 // toolStripSeparator2
401 //
402 this.toolStripSeparator2.Name = "toolStripSeparator2";
403 this.toolStripSeparator2.Size = new System.Drawing.Size(161, 6);
404 //
405 // miExit
406 //
407 this.miExit.Name = "miExit";
408 this.miExit.Size = new System.Drawing.Size(164, 22);
409 this.miExit.Text = "e&xit";
410 this.miExit.Click += new System.EventHandler(this.miExit_Click);
411 //
412 // menuEdit
413 //
414 this.menuEdit.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
415 this.miUndo,
416 this.miRedo,
417 this.toolStripSeparator4,
418 this.miPreferences});
419 this.menuEdit.Name = "menuEdit";
420 this.menuEdit.Size = new System.Drawing.Size(36, 20);
421 this.menuEdit.Text = "&edit";
422 //
423 // miUndo
424 //
425 this.miUndo.Enabled = false;
426 this.miUndo.Name = "miUndo";
427 this.miUndo.Size = new System.Drawing.Size(142, 22);
428 this.miUndo.Text = "&undo";
429 this.miUndo.Click += new System.EventHandler(this.miUndo_Click);
430 //
431 // miRedo
432 //
433 this.miRedo.Enabled = false;
434 this.miRedo.Name = "miRedo";
435 this.miRedo.Size = new System.Drawing.Size(142, 22);
436 this.miRedo.Text = "&redo";
437 this.miRedo.Click += new System.EventHandler(this.miRedo_Click);
438 //
439 // toolStripSeparator4
440 //
441 this.toolStripSeparator4.Name = "toolStripSeparator4";
442 this.toolStripSeparator4.Size = new System.Drawing.Size(139, 6);
443 //
444 // miPreferences
445 //
446 this.miPreferences.Name = "miPreferences";
447 this.miPreferences.Size = new System.Drawing.Size(142, 22);
448 this.miPreferences.Text = "&preferences";
449 this.miPreferences.Click += new System.EventHandler(this.miPreferences_Click);
450 //
451 // menuHelp
452 //
453 this.menuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
454 this.miAbout});
455 this.menuHelp.Name = "menuHelp";
456 this.menuHelp.Size = new System.Drawing.Size(39, 20);
457 this.menuHelp.Text = "&help";
458 //
459 // miAbout
460 //
461 this.miAbout.Name = "miAbout";
462 this.miAbout.Size = new System.Drawing.Size(109, 22);
463 this.miAbout.Text = "&about";
464 this.miAbout.Click += new System.EventHandler(this.miAbout_Click);
465 //
466 // mainToolStrip
467 //
468 this.mainToolStrip.Dock = System.Windows.Forms.DockStyle.None;
469 this.mainToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
470 this.bttnNewArmy,
471 this.bttnOpenArmy,
472 this.bttnSaveArmy,
473 this.toolStripSeparator3,
474 this.bttnUndo,
475 this.bttnRedo});
476 this.mainToolStrip.Location = new System.Drawing.Point(0, 24);
477 this.mainToolStrip.Name = "mainToolStrip";
478 this.mainToolStrip.Size = new System.Drawing.Size(182, 25);
479 this.mainToolStrip.TabIndex = 8;
480 //
481 // bttnNewArmy
482 //
483 this.bttnNewArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
484 this.bttnNewArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_new;
485 this.bttnNewArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
486 this.bttnNewArmy.Name = "bttnNewArmy";
487 this.bttnNewArmy.Size = new System.Drawing.Size(23, 22);
488 this.bttnNewArmy.Text = "new army";
489 this.bttnNewArmy.Click += new System.EventHandler(this.miNewArmy_Click);
490 //
491 // bttnOpenArmy
492 //
493 this.bttnOpenArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
494 this.bttnOpenArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_open;
495 this.bttnOpenArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
496 this.bttnOpenArmy.Name = "bttnOpenArmy";
497 this.bttnOpenArmy.Size = new System.Drawing.Size(23, 22);
498 this.bttnOpenArmy.Text = "open army";
499 this.bttnOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click);
500 //
501 // bttnSaveArmy
502 //
503 this.bttnSaveArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
504 this.bttnSaveArmy.Enabled = false;
505 this.bttnSaveArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_save;
506 this.bttnSaveArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
507 this.bttnSaveArmy.Name = "bttnSaveArmy";
508 this.bttnSaveArmy.Size = new System.Drawing.Size(23, 22);
509 this.bttnSaveArmy.Text = "save army";
510 this.bttnSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click);
511 //
512 // toolStripSeparator3
513 //
514 this.toolStripSeparator3.Name = "toolStripSeparator3";
515 this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
516 //
517 // bttnUndo
518 //
519 this.bttnUndo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
520 this.bttnUndo.Enabled = false;
521 this.bttnUndo.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_undo;
522 this.bttnUndo.ImageTransparentColor = System.Drawing.Color.Magenta;
523 this.bttnUndo.Name = "bttnUndo";
524 this.bttnUndo.Size = new System.Drawing.Size(32, 22);
525 this.bttnUndo.Text = "undo";
526 this.bttnUndo.ButtonClick += new System.EventHandler(this.miUndo_Click);
527 //
528 // bttnRedo
529 //
530 this.bttnRedo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
531 this.bttnRedo.Enabled = false;
532 this.bttnRedo.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_redo;
533 this.bttnRedo.ImageTransparentColor = System.Drawing.Color.Magenta;
534 this.bttnRedo.Name = "bttnRedo";
535 this.bttnRedo.Size = new System.Drawing.Size(32, 22);
536 this.bttnRedo.Text = "redo";
537 this.bttnRedo.ButtonClick += new System.EventHandler(this.miRedo_Click);
538 //
539 // catToolStrip
540 //
541 this.catToolStrip.Dock = System.Windows.Forms.DockStyle.None;
542 this.catToolStrip.Location = new System.Drawing.Point(161, 24);
543 this.catToolStrip.Name = "catToolStrip";
544 this.catToolStrip.Size = new System.Drawing.Size(111, 25);
545 this.catToolStrip.TabIndex = 9;
546 this.catToolStrip.Visible = false;
547 //
548 // statusBar
549 //
550 this.statusBar.Location = new System.Drawing.Point(0, 586);
551 this.statusBar.Name = "statusBar";
552 this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
553 this.sbMainPanel,
554 this.sbErrorPanel,
555 this.sbPointsPanel});
556 this.statusBar.ShowPanels = true;
557 this.statusBar.Size = new System.Drawing.Size(790, 22);
558 this.statusBar.TabIndex = 1;
559 this.statusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar_PanelClick);
560 this.statusBar.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem);
561 //
562 // sbMainPanel
563 //
564 this.sbMainPanel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
565 this.sbMainPanel.Color = System.Drawing.SystemColors.WindowText;
566 this.sbMainPanel.Name = "sbMainPanel";
567 this.sbMainPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
568 this.sbMainPanel.Width = 473;
569 //
570 // sbErrorPanel
571 //
572 this.sbErrorPanel.Color = System.Drawing.SystemColors.WindowText;
573 this.sbErrorPanel.Name = "sbErrorPanel";
574 this.sbErrorPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
575 this.sbErrorPanel.Width = 150;
576 //
577 // sbPointsPanel
578 //
579 this.sbPointsPanel.Color = System.Drawing.SystemColors.WindowText;
580 this.sbPointsPanel.Name = "sbPointsPanel";
581 this.sbPointsPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
582 this.sbPointsPanel.ToolTipText = "current points total";
583 this.sbPointsPanel.Width = 150;
584 //
585 // toolStripPanel
586 //
587 this.toolStripPanel.Dock = System.Windows.Forms.DockStyle.Top;
588 this.toolStripPanel.Location = new System.Drawing.Point(0, 24);
589 this.toolStripPanel.Name = "toolStripPanel";
590 this.toolStripPanel.Orientation = System.Windows.Forms.Orientation.Horizontal;
591 this.toolStripPanel.RowMargin = new System.Windows.Forms.Padding(3, 0, 0, 0);
592 this.toolStripPanel.Size = new System.Drawing.Size(790, 0);
593 //
594 // FrmMain
595 //
596 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
597 this.ClientSize = new System.Drawing.Size(790, 608);
598 this.Controls.Add(this.mainToolStrip);
599 this.Controls.Add(this.toolStripPanel);
600 this.Controls.Add(this.statusBar);
601 this.Controls.Add(this.catToolStrip);
602 this.Controls.Add(this.menuStrip);
603 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
604 this.IsMdiContainer = true;
605 this.MainMenuStrip = this.menuStrip;
606 this.Menu = this.mainMenu;
607 this.Name = "FrmMain";
608 this.Text = "WarFoundry";
609 this.Load += new System.EventHandler(this.FrmMain_Load);
610 this.menuStrip.ResumeLayout(false);
611 this.menuStrip.PerformLayout();
612 this.mainToolStrip.ResumeLayout(false);
613 this.mainToolStrip.PerformLayout();
614 ((System.ComponentModel.ISupportInitialize)(this.sbMainPanel)).EndInit();
615 ((System.ComponentModel.ISupportInitialize)(this.sbErrorPanel)).EndInit();
616 ((System.ComponentModel.ISupportInitialize)(this.sbPointsPanel)).EndInit();
617 this.ResumeLayout(false);
618 this.PerformLayout();
620 }
621 #endregion
623 private void FileLoadingFinished(List<FileLoadFailure> failures)
624 {
625 foreach (FileLoadFailure failure in failures)
626 {
627 log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
628 }
629 }
631 private void miExit_Click(object sender, System.EventArgs e)
632 {
633 Application.Exit();
634 }
636 private void miNewArmy_Click(object sender, System.EventArgs e)
637 {
638 CreateNewArmy();
639 }
641 private void CreateNewArmy()
642 {
643 if (CloseCurrentArmy())
644 {
645 FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem);
646 DialogResult dr = newArmy.ShowDialog();
648 if (dr == DialogResult.OK)
649 {
650 try
651 {
652 CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize);
653 }
654 catch (RequiredDataMissingException ex)
655 {
656 log.Error("Required data missing from race file", ex);
657 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
658 }
659 catch (InvalidFileException ex)
660 {
661 log.Error("Race file was invalid", ex);
662 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
663 }
664 }
665 }
666 }
668 private bool OpenArmy()
669 {
670 if (openArmyDialog.Filter=="")
671 {
672 string savePath = ArmiesPath;
674 if (!Directory.Exists(savePath))
675 {
676 Directory.CreateDirectory(savePath);
677 }
679 openArmyDialog.InitialDirectory = savePath;
680 openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
681 openArmyDialog.Title = Translation.GetTranslation("openArmyDialog");
683 }
685 DialogResult dr = openArmyDialog.ShowDialog(this);
687 if (dr == DialogResult.OK)
688 {
689 if (CloseCurrentArmy())
690 {
691 try
692 {
693 string newFilePath = openArmyDialog.FileName;
694 CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath));
695 loadedFilePath = newFilePath;
696 return true;
697 }
698 catch (RequiredDataMissingException ex)
699 {
700 log.Error(ex);
701 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
702 return false;
703 }
704 catch (InvalidFileException ex)
705 {
706 log.Error(ex);
707 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
708 return false;
709 }
710 }
711 else
712 {
713 return false;
714 }
715 }
716 else
717 {
718 return false;
719 }
720 }
722 private bool CloseCurrentArmy()
723 {
724 if (CurrentArmy!=null)
725 {
726 bool canClose = false;
728 if (CommandStack.IsDirty())
729 {
730 string saveChanges = Translation.GetTranslation("SaveChangesQuestion", "the army \"{0}\" has been modified\r\nsave changes before closing army?", CurrentArmy.Name);
731 string saveChangesTitle = Translation.GetTranslation("SaveChangesTitle", "unsaved changes");
732 DialogResult dr = MessageBox.Show(this, saveChanges, saveChangesTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3);
734 if (dr == DialogResult.Yes)
735 {
736 canClose = SaveCurrentArmy();
737 }
738 else if (dr == DialogResult.No)
739 {
740 canClose = true;
741 }
742 //else they said cancel and we default to "canClose = false" so do nothing
743 }
744 else
745 {
746 canClose = true;
747 }
749 if (canClose)
750 {
751 //do close
752 DisableCategoryButtons();
753 CurrentArmy = null;
754 return true;
755 }
756 else
757 {
758 return false;
759 }
760 }
761 else
762 {
763 DisableCategoryButtons();
764 //pretend we succeeded
765 return true;
766 }
767 }
769 private void UndoLastAction()
770 {
771 if (commandStack.CanUndo())
772 {
773 commandStack.Undo();
774 }
775 }
777 private void RedoAction()
778 {
779 if (commandStack.CanRedo())
780 {
781 commandStack.Redo();
782 }
783 }
785 private bool SaveCurrentArmy()
786 {
787 bool saved = false;
789 string filePath = loadedFilePath;
791 if (filePath == null)
792 {
793 filePath = PromptForArmyFilePath();
794 }
796 if (filePath != null)
797 {
798 saved = SaveCurrentArmyToFile(filePath);
799 }
801 return saved;
802 }
804 private bool SaveCurrentArmyAs()
805 {
806 bool saved = false;
807 string filePath = PromptForArmyFilePath();
809 if (filePath != null)
810 {
811 saved = SaveCurrentArmyToFile(filePath);
812 }
814 return saved;
815 }
817 private bool SaveCurrentArmyToFile(string filePath)
818 {
819 if (WarFoundrySaver.GetSaver().Save(filePath, CurrentArmy))
820 {
821 loadedFilePath = filePath;
822 miSaveArmy.Enabled = false;
823 bttnSaveArmy.Enabled = false;
824 CommandStack.setCleanMark();
825 return true;
826 }
827 else
828 {
829 MessageBox.Show(this, Translation.GetTranslation("SaveFailed", "file save failed - check log for details"), Translation.GetTranslation("SaveFailedTitle", "file save failed"), MessageBoxButtons.OK, MessageBoxIcon.Error);
830 return false;
831 }
832 }
834 private string PromptForArmyFilePath()
835 {
836 if (saveArmyDialog.Filter == "")
837 {
838 string savePath = ArmiesPath;
840 if (!Directory.Exists(savePath))
841 {
842 Directory.CreateDirectory(savePath);
843 }
845 saveArmyDialog.InitialDirectory = savePath;
846 saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
847 saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog");
848 }
850 DialogResult dr = saveArmyDialog.ShowDialog(this);
852 if (dr == DialogResult.OK)
853 {
854 return saveArmyDialog.FileName;
855 }
856 else
857 {
858 return null;
859 }
860 }
862 public GameSystem CurrentGameSystem
863 {
864 get { return WarFoundryCore.CurrentGameSystem; }
865 set { WarFoundryCore.CurrentGameSystem = value; }
866 }
868 public Army CurrentArmy
869 {
870 get { return WarFoundryCore.CurrentArmy; }
871 set { SetArmy(value); }
872 }
874 private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem)
875 {
876 SetAppTitle();
878 if (newSystem == null)
879 {
880 Preferences["currSystem"] = "";
881 }
882 else
883 {
884 Preferences["currSystem"] = newSystem.ID;
885 }
887 Preferences.Save();
888 RemoveCategoryButtons();
889 }
891 private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy)
892 {
893 CommandStack.Reset();
894 loadedFilePath = null;
895 miSaveArmy.Enabled = false;
896 bttnSaveArmy.Enabled = false;
897 //TODO: Subscribe to an "army changed" event here
898 SetPointsPanelText();
899 SetAppTitle();
900 }
902 private void SetArmy(Army newArmy)
903 {
904 IgnoreArmy(CurrentArmy);
905 CloseAllUnitWindows();
907 if (newArmy == null)
908 {
909 SetNullArmyState();
910 }
911 else
912 {
913 WarFoundryCore.CurrentGameSystem = newArmy.GameSystem;
914 ListenToArmy(newArmy);
915 SetNonNullArmyState(newArmy);
916 }
918 WarFoundryCore.CurrentArmy = newArmy;
919 }
921 private void IgnoreArmy(Army oldArmy)
922 {
923 if (oldArmy != null)
924 {
925 oldArmy.UnitAdded -= UnitAddedMethod;
926 oldArmy.UnitRemoved -= UnitRemovedMethod;
927 oldArmy.PointsValueChanged -= PointsValueChangedMethod;
928 }
929 }
931 private void CloseAllUnitWindows()
932 {
933 FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows);
935 foreach (FrmUnit window in unitForms)
936 {
937 window.Close();
938 }
940 unitWindows.Clear();
941 }
943 private void ListenToArmy(Army newArmy)
944 {
945 if (newArmy != null)
946 {
947 newArmy.UnitAdded += UnitAddedMethod;
948 newArmy.UnitRemoved += UnitRemovedMethod;
949 newArmy.PointsValueChanged += PointsValueChangedMethod;
950 }
951 }
953 private void SetNullArmyState()
954 {
955 miSaveArmyAs.Enabled = false;
956 miCloseArmy.Enabled = false;
957 miExportArmyAs.Enabled = false;
958 DisableCategoryButtons();
959 GetArmyTree().Hide();
960 }
962 private void SetNonNullArmyState(Army newArmy)
963 {
964 SetCategoryButtons(newArmy.Race.Categories);
965 EnableCategoryButtons();
966 miSaveArmyAs.Enabled = true;
967 miCloseArmy.Enabled = true;
968 miExportArmyAs.Enabled = true;
969 GetArmyTree().Show();
970 }
972 private void SetCategoryButtons(Category[] cats)
973 {
974 if (CategoryButtonsHaveChanged(cats))
975 {
976 RemoveCategoryButtons();
977 AddCategoryButtons(cats);
978 }
979 }
981 private bool CategoryButtonsHaveChanged(Category[] cats)
982 {
983 int catCount = cats.Length;
984 ToolStripItemCollection items = catToolStrip.Items;
985 bool haveChanged = (!catToolStrip.Visible || catCount != items.Count);
987 if (!haveChanged)
988 {
989 for (int i = 0; i < catCount; i++)
990 {
991 if (cats[i].Equals(items[i+1].Tag))
992 {
993 haveChanged = true;
994 break;
995 }
996 }
997 }
999 return haveChanged;
1002 private void RemoveCategoryButtons()
1004 this.Invoke(new MethodInvoker(catToolStrip.Items.Clear));
1007 private void AddCategoryButtons(Category[] cats)
1009 int catCount = cats.Length;
1010 Category cat;
1011 IBBToolStripButton[] categoryButtons = new IBBToolStripButton[catCount];
1013 for (int i = 0; i < catCount; i++)
1015 cat = cats[i];
1016 IBBToolStripButton button = new IBBToolStripButton();
1017 button.Text = cat.Name;
1018 button.Tag = cat;
1019 button.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
1020 button.Enabled = false;
1021 button.Click += new EventHandler(CreateUnitForCategoryButtonClick);
1022 categoryButtons[i] = button;
1025 this.Invoke(new ArrayMethodInvoker<IBBToolStripButton>(AddCatToolStripButtons), new object[] { categoryButtons });
1028 private void AddCatToolStripButtons(IBBToolStripButton[] buttons)
1030 log.Debug("Toolstrip width: " + catToolStrip.Width);
1031 catToolStrip.Items.AddRange(buttons);
1032 catToolStrip.Refresh();
1033 int buttonWidths = 0;
1035 foreach (IBBToolStripButton button in buttons)
1037 buttonWidths += button.Width;
1039 catToolStrip.Width = buttonWidths;
1040 log.Debug("Button widths: " + buttonWidths);
1041 log.Debug("Toolstrip width: " + catToolStrip.Width);
1044 private void CreateUnitForCategoryButtonClick(object sender, EventArgs e)
1046 if (sender is IBBToolStripButton)
1048 IBBToolStripButton button = (IBBToolStripButton)sender;
1049 object tag = button.Tag;
1051 if (tag is Category)
1053 AddUnitFromCategory((Category)tag);
1058 private void EnableCategoryButtons()
1060 catToolStrip.Visible = true;
1061 SetCategoryButtonState(true);
1064 private void DisableCategoryButtons()
1066 catToolStrip.Visible = false;
1067 SetCategoryButtonState(false);
1070 private void SetCategoryButtonState(bool state)
1072 foreach (IBBToolStripButton button in catToolStrip.Items)
1074 button.Enabled = state;
1078 private void miSaveArmyAs_Click(object sender, System.EventArgs e)
1080 SaveCurrentArmyAs();
1083 private void commandStack_CommandStackUpdated()
1085 bttnUndo.Enabled = commandStack.CanUndo();
1086 miUndo.Enabled = bttnUndo.Enabled;
1087 bttnRedo.Enabled = commandStack.CanRedo();
1088 miRedo.Enabled = bttnRedo.Enabled;
1090 PopulateRedoMenu();
1091 PopulateUndoMenu();
1093 bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null;
1094 miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null;
1097 private void PopulateRedoMenu()
1099 int redoLength = commandStack.RedoLength;
1100 int maxRedo = Math.Min(10, redoLength);
1101 ToolStripItemCollection dropDownItems = bttnRedo.DropDownItems;
1102 dropDownItems.Clear();
1104 for (int i = 1; i <= maxRedo; i++)
1106 Command cmd = commandStack.PeekRedoCommand(i);
1108 if (cmd == null)
1110 break;
1113 dropDownItems.Add(cmd.Description, null, redoMenu_Click);
1116 if (redoLength > 0)
1118 bttnRedo.Text = commandStack.PeekRedoCommand(1).Description;
1120 else
1122 bttnRedo.Text = Translation.GetTranslation("bttnRedo");
1126 private void PopulateUndoMenu()
1128 int undoLength = commandStack.UndoLength;
1129 int maxUndo = Math.Min(10, undoLength);
1130 ToolStripItemCollection dropDownItems = bttnUndo.DropDownItems;
1131 dropDownItems.Clear();
1133 for (int i = 1; i <= maxUndo; i++)
1135 Command cmd = commandStack.PeekUndoCommand(i);
1137 if (cmd == null)
1139 break;
1142 dropDownItems.Add(cmd.UndoDescription, null, undoMenu_Click);
1145 if (undoLength > 0)
1147 bttnUndo.Text = commandStack.PeekUndoCommand(1).UndoDescription;
1149 else
1151 bttnUndo.Text = Translation.GetTranslation("bttnUndo");
1155 private void miSaveArmy_Click(object sender, System.EventArgs e)
1157 SaveCurrentArmy();
1160 private void SetAppTitle()
1162 string str = AppTitle;
1164 if (CurrentGameSystem!=null)
1166 str+= " - "+CurrentGameSystem.Name;
1169 if (CurrentArmy!=null)
1171 str+= " - "+CurrentArmy.Name;
1174 this.Text = str;
1177 private void AddUnitFromCategory(Category cat)
1179 FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy);
1180 DialogResult dr = newUnit.ShowDialog(this);
1182 if (dr == DialogResult.OK)
1184 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat));
1185 commandStack.Execute(cmd);
1186 OpenUnitDialog(cmd.Unit);
1190 internal void OpenUnitDialog(Unit unit)
1192 string unitID = unit.ID;
1194 if (unitWindows.ContainsKey(unitID))
1196 unitWindows[unitID].Focus();
1198 else
1200 FrmUnit unitForm = new FrmUnit(unit, commandStack);
1201 unitWindows.Add(unitID, unitForm);
1202 unitForm.MdiParent = this;
1203 unitForm.Closing += new CancelEventHandler(unitForm_Closing);
1204 unitForm.Show();
1208 private void unitForm_Closing(object sender, CancelEventArgs e)
1210 if (sender is FrmUnit)
1212 FrmUnit unitForm = (FrmUnit) sender;
1213 unitWindows.Remove(unitForm.Unit.ID);
1217 private void FrmMain_UnitAddedMethod(object unitObj)
1219 ValidateArmy();
1222 private void ValidateArmy()
1224 ICollection<string> failureMessages;
1225 if (Validates.AsOkay(RequirementHandler.ValidateArmy(CurrentArmy, out failureMessages)))
1227 sbErrorPanel.Text = "";
1228 sbErrorPanel.Tag = "";
1230 else
1232 sbErrorPanel.Text = failureMessages.Count + " validation errors";
1233 sbErrorPanel.Tag = String.Join("\n", new List<string>(failureMessages).ToArray());
1237 private void FrmMain_UnitRemovedMethod(object unitObj)
1239 ValidateArmy();
1241 if (unitObj is Unit)
1243 Unit unit = (Unit)unitObj;
1245 //check if window is open, and close it if it is
1246 foreach (Form frm in this.MdiChildren)
1248 if (frm is FrmUnit)
1250 if (((FrmUnit)frm).Unit == unit)
1252 frm.Close();
1253 break;
1260 private void miUndo_Click(object sender, System.EventArgs e)
1262 UndoLastAction();
1265 private void miRedo_Click(object sender, System.EventArgs e)
1267 RedoAction();
1270 private void miCloseArmy_Click(object sender, EventArgs e)
1272 CloseCurrentArmy();
1275 private void miOpenArmy_Click(object sender, EventArgs e)
1277 OpenArmy();
1280 private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal)
1282 if (obj is Army)
1284 SetPointsPanelText();
1288 private void SetPointsPanelText()
1290 if (CurrentArmy==null)
1292 sbPointsPanel.Text = "";
1293 sbPointsPanel.ResetColor();
1295 else
1297 string pointsPanelText = String.Format(Translation.GetTranslation("statusPanelPoints"), CurrentArmy.Points, CurrentGameSystem.GetPointsName(CurrentArmy.Points), CurrentArmy.MaxPoints, CurrentGameSystem.GetPointsName(CurrentArmy.MaxPoints));
1298 sbPointsPanel.Text = pointsPanelText;
1300 if (CurrentArmy.Points>CurrentArmy.MaxPoints)
1302 sbPointsPanel.Color = Color.Red;
1304 else
1306 sbPointsPanel.ResetColor();
1311 private void SetPointsPanelToolTipText()
1313 sbPointsPanel.ToolTipText = Translation.GetTranslation("statusPanelPointsToolTip", "total points value");
1316 private void redoMenu_Click(object sender, EventArgs e)
1318 if (sender is ToolStripDropDownItem)
1320 ToolStripDropDownItem item = (ToolStripDropDownItem)sender;
1321 //we know it's an redo menu item so find it's index and redo everything
1322 int max = bttnRedo.DropDownItems.IndexOf(item);
1324 if (max >= 0)
1326 for (int i = 0; i <= max; i++)
1328 commandStack.Redo();
1334 private void undoMenu_Click(object sender, EventArgs e)
1336 if (sender is ToolStripDropDownItem)
1338 ToolStripDropDownItem item = (ToolStripDropDownItem)sender;
1339 //we know it's an redo menu item so find it's index and redo everything
1340 int max = bttnUndo.DropDownItems.IndexOf(item);
1342 if (max >= 0)
1344 for (int i = 0; i <= max; i++)
1346 commandStack.Undo();
1352 private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
1354 statusBar.ColorableStatusBarDrawItem(sender, sbdevent);
1357 private void FrmMain_Closing(object sender, CancelEventArgs e)
1359 if (!CloseCurrentArmy())
1361 e.Cancel = true;
1365 private void miReloadFiles_Click(object sender, System.EventArgs e)
1367 WarFoundryLoader.GetDefault().LoadFiles();
1368 sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded");
1371 private void statusBar_PanelClick(object sender, StatusBarPanelClickEventArgs e)
1373 if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="")
1375 MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
1379 private void miExportArmyAsBasicHTML_Click(object sender, EventArgs e)
1381 SaveFileDialog dialog = new SaveFileDialog();
1382 dialog.Filter = Translation.GetTranslation("armyExportBasicHtmlFilter", "HTML pages") + "|*.html";
1383 dialog.Title = Translation.GetTranslation("exportArmyDialog", "Export army");
1385 DialogResult dr = dialog.ShowDialog(this);
1387 if (dr == DialogResult.OK)
1389 Army army = CurrentArmy;
1390 string filePath = dialog.FileName;
1391 log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
1392 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
1396 private void FrmMain_Load(object sender, EventArgs e)
1398 string gameSystemID = Preferences.GetStringProperty("currSystem");
1400 if (gameSystemID != null && !"".Equals(gameSystemID))
1402 log.Debug("Attempting to load current game system from properties");
1403 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
1405 if (sys != null)
1407 WarFoundryCore.CurrentGameSystem = sys;
1408 log.InfoFormat("Loaded game system {0} from properties", gameSystemID);
1413 private void miAbout_Click(object sender, EventArgs e)
1415 FrmAbout about = new FrmAbout();
1416 about.ShowDialog(this);
1419 private void miPreferences_Click(object sender, EventArgs e)
1421 FrmPreferences prefsForm = new FrmPreferences(Preferences);
1422 prefsForm.Show(this);