annotate FrmMainWindow.cs @ 113:4a33b3012100 WarFoundry_v0.1RC1

* Tag v0.1RC1 release no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Jan 2011 19:43:47 +0000
parents d68992a831df
children 5e8de1507cfb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
a191d0655f55 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
1 // This file (FrmMainWindow.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard.
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
19
a191d0655f55 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Configuration;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
8 using System.IO;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
9 using GLib;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
10 using Gtk;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
11 using IBBoard;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using IBBoard.Commands;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
13 using IBBoard.CustomMath;
12
685532d43a96 Re #88: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
14 using IBBoard.GtkSharp;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
15 using IBBoard.GtkSharp.Translatable;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 using IBBoard.IO;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
17 using IBBoard.Lang;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
18 using IBBoard.Logging;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 using IBBoard.WarFoundry.API;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
20 using IBBoard.WarFoundry.API.Commands;
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
21 using IBBoard.WarFoundry.API.Exporters;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 using IBBoard.WarFoundry.API.Factories;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
23 using IBBoard.WarFoundry.API.Factories.Xml;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
24 using IBBoard.WarFoundry.API.Objects;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
25 using IBBoard.WarFoundry.API.Requirements;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 using IBBoard.WarFoundry.API.Savers;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
27 using IBBoard.WarFoundry.GUI.GTK.Widgets;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
28 using IBBoard.WarFoundry.Plugin.Rollcall;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 using IBBoard.Xml;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 using log4net;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
31 using WFObjects = IBBoard.WarFoundry.API.Objects;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
32 using System.Collections;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
34 namespace IBBoard.WarFoundry.GUI.GTK
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
35 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
36 public partial class FrmMainWindow: TranslatableWindowWithActions
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 private static readonly string AppTitle = "WarFoundry";
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
39 private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
40 private Preferences preferences;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
41 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 private CommandStack commandStack;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
43 private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
44 private ObjectAddDelegate UnitAddedMethod;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
45 private ObjectRemoveDelegate UnitRemovedMethod;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
46 private DoubleValChangedDelegate PointsValueChangedMethod;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 private FailedUnitRequirementDelegate FailedUnitRequirementMethod;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 private StringValChangedDelegate UnitNameChangedMethod;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 private GameSystem system;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 private string loadedArmyPath;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 private MenuToolButton undoMenuButton, redoMenuButton;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
52
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
53 public static void Main(string[] args)
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
54 {
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
55 try
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
57 ExceptionManager.UnhandledException += HandleUnhandledException;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 Application.Init();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 FrmMainWindow win = new FrmMainWindow(args);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 win.Show();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 Application.Run();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
62 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended");
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
63 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
64 catch (Exception ex)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
65 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
66 HandleUnhandledException(ex);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
67 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
68 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
69
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
70 private static void HandleUnhandledException(UnhandledExceptionArgs args)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
71 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
72 object obj = args.ExceptionObject;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
73 Exception ex = null;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
74
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
75 if (obj is Exception)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
76 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
77 ex = (Exception)obj;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
78 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
79 else
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
80 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
81 ex = new Exception("GLib returned unexpected exception object type " + obj.GetType());
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
83
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
84 HandleUnhandledException(ex);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
85 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
86
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
87 private static void HandleUnhandledException(Exception ex)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
88 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
89 string msg = String.Format("({0}) {1}", ex.GetType().FullName, ex.Message);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
90 LogManager.GetLogger(typeof(FrmMainWindow)).Fatal(msg, ex);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
91 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details.");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
92 dialog.Run();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
93 dialog.Hide();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
94 dialog.Dispose();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
96
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 public FrmMainWindow() : this(new string[0])
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 //Do nothing extra
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
101
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
102 public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 logger.Info("Opening FrmMainWindow");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
105 Build();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 //Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 redoMenuButton = new MenuToolButton("gtk-redo");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
108 redoMenuButton.Name = "bttnRedo";
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
109 redoMenuButton.Clicked += redoTBButtonActivated;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
110 redoMenuButton.Sensitive = false;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 toolbar.Insert(redoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 undoMenuButton = new MenuToolButton("gtk-undo");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
113 undoMenuButton.Name = "bttnUndo";
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
114 undoMenuButton.Clicked += undoTBButtonActivated;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
115 undoMenuButton.Sensitive = false;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 toolbar.Insert(undoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
117 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 1]);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
118 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 2]);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 toolbar.ShowAll();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
120
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
121 TreeViewColumn mainColumn = new TreeViewColumn();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
122 CellRendererText mainCell = new CellRendererText();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
123 mainColumn.PackStart(mainCell, true);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 treeUnits.AppendColumn(mainColumn);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderCategoryTreeObjectName));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 treeUnits.Model = new TreeStore(typeof(WarFoundryObject));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 logger.Debug("Loading preferences");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
128 Preferences = new Preferences("WarFoundry-GTK");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 logger.Debug("Loading translations");
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
130
8
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
131 try
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
132 {
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
133 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
134 }
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
135 catch (TranslationLoadException ex)
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
136 {
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
137 logger.Error(ex);
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
138 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, ex.Message);
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
139 dialog.Title = "Translation loading failed";
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
140 dialog.Run();
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
141 dialog.Destroy();
20c5fd0bb79d Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
142 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
143
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
144 logger.Debug("Initialising");
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
145 commandStack = new CommandStack();
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
146 commandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
147 WarFoundryCore.GameSystemChanged += new GameSystemChangedDelegate(OnGameSystemChanged);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
148 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(OnArmyChanged);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
149 Destroyed += new EventHandler(OnWindowDestroyed);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
150 Translation.TranslationChanged += Retranslate;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
151 Translate();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
152 UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded);
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
153 UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved);
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
154 PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
157
18
c4d9b1ec75ed Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents: 17
diff changeset
158 //FIXME: Temporary hack to add paths and factories before we get preferences and plugins
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + "data"));
18
c4d9b1ec75ed Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents: 17
diff changeset
160 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
c4d9b1ec75ed Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents: 17
diff changeset
161 WarFoundryLoader.GetDefault().RegisterNonNativeFactory(RollcallFactory.GetFactory());
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
162 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
163 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
164
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
165 logger.Debug("Initialising complete - seeing if we can load default army or system");
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
166
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 if (args.Length == 1)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 {
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
169 logger.Debug("Attempting to load from file");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 FileInfo file = new FileInfo(args[0]);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
171
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 try
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 {
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
174 ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file);
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
175
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
176 if (objects.Count == 1)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 {
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
178 List<IWarFoundryObject> objectList = new List<IWarFoundryObject>();
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
179 objectList.AddRange(objects);
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
180 IWarFoundryObject loadedObject = objectList[0];
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
181
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
182 if (loadedObject is Army)
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
183 {
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
184 WarFoundryCore.CurrentArmy = (Army)loadedObject;
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
185 logger.InfoFormat("Loaded army from {0}", file.FullName);
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
186 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
187 else
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
188 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
189 if (loadedObject is GameSystem)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
190 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
191 WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
192 logger.InfoFormat("Loaded game system from {0}", file.FullName);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
193 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
194
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
195 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 catch (InvalidFileException ex)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 //TODO: show error dialog
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 logger.Error(ex);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 string gameSystemID = Preferences.GetStringProperty("currSystem");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
208 if (gameSystemID != null && !"".Equals(gameSystemID))
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210 logger.Debug("Attempting to load current game system from properties");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
212
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
213 if (sys != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215 WarFoundryCore.CurrentGameSystem = sys;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
221
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
222 protected override void Translate()
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
223 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
224 base.Translate();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
225 SetAppTitle();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
226 treeUnits.GetColumn(0).Title = Translation.GetTranslation("armyCategoryColumnTitle", "categories");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
227 RebuildUndoRedoMenus();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
228 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
229
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
230 private void Retranslate()
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
231 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
232 Translate();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
233 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
234
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
235 public override void Dispose()
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
236 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
237 Translation.TranslationChanged -= Retranslate;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
238 base.Dispose();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
239 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
240
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
241 private void FileLoadingFinished(List<FileLoadFailure> failures)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
242 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
243 foreach (FileLoadFailure failure in failures)
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
244 {
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
245 logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
246 }
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
247 }
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
248
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 object o = model.GetValue(iter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
252
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 if (o is ArmyCategory)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 ArmyCategory c = (ArmyCategory)o;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 string name = "";
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
257
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
258 if (!Preferences.GetBooleanProperty("ShowCatPercentage"))
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 {
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
260 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}pts", c.Name, c.Points);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 {
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
264 name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}pts ({2}%)", c.Name, c.Points, (c.ParentArmy.Points > 0 ? Math.Round((c.Points / c.ParentArmy.Points) * 100) : 0));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
266
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267 (cell as CellRendererText).Text = name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
269 else
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
271 if (o is WFObjects.Unit)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
272 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
273 WFObjects.Unit u = (WFObjects.Unit)o;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
274 string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}pts", u.Name, u.Points);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
275 (cell as CellRendererText).Text = name;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
276 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
277
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
278 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
279 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
280
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281 private void OnWindowDestroyed(object source, EventArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283 logger.Info("Exiting");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
284 Application.Quit();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
286
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
287 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
289 WFObjects.Unit unit = (WFObjects.Unit)val;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
290 logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
291 UnitDisplayWidget widget;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
292 unitToWidgetMap.TryGetValue(unit, out widget);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
293
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
294 if (widget != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
295 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
296 unitsNotebook.SetTabLabel(widget, NotebookUtil.CreateNotebookTabLabelWithClose(unitsNotebook, widget, unit.Name));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
297 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
298
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
299 treeUnits.QueueDraw();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
300 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
301
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
302 private void OnUnitAdded(WarFoundryObject val)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
304 WFObjects.Unit unit = (WFObjects.Unit)val;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
305 unit.NameChanged += UnitNameChangedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
306 unit.PointsValueChanged += HandleUnitPointsValueChanged;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 AddUnitToTree(unit);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
308 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
309
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
310 private void HandleUnitPointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
311 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
312 treeUnits.QueueDraw();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
313 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
314
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
315 private void AddUnitToTree(WFObjects.Unit unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317 TreeStore model = (TreeStore)treeUnits.Model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
318 TreeIter iter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 model.GetIterFirst(out iter);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
320
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
321 do
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
322 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
323 object obj = model.GetValue(iter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
324
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
325 if (obj is ArmyCategory)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
326 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
327 ArmyCategory cat = (ArmyCategory)obj;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
328
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 if (cat.Equals(unit.Category))
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
331 model.AppendValues(iter, unit);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332 TreePath path = model.GetPath(iter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 treeUnits.ExpandToPath(path);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
334 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
335 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
336 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337 while (model.IterNext(ref iter));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
339
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
340 private void OnUnitRemoved(WarFoundryObject obj)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
341 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
342 WFObjects.Unit unit = (WFObjects.Unit)obj;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
343 unit.NameChanged -= UnitNameChangedMethod;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344 RemoveUnitFromTree(unit);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
345 RemoveUnitTab(unit);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
347
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
348 private void RemoveUnitFromTree(WFObjects.Unit unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350 TreeStore model = (TreeStore)treeUnits.Model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351 TreeIter iter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 model.GetIterFirst(out iter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353 bool removed = false;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
354
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
355 do
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 object obj = model.GetValue(iter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
358
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
359 if (obj is ArmyCategory)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
361 ArmyCategory cat = (ArmyCategory)obj;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
362
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363 if (unit.Category == null || cat.Equals(unit.Category))
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 TreeIter innerIter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
366 model.IterChildren(out innerIter, iter);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
367
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368 do
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
369 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 object innerObj = model.GetValue(innerIter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
371
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
372 if (unit.Equals(innerObj))
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
373 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374 model.Remove(ref innerIter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
375 removed = true;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
376 break;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
379 while (model.IterNext(ref innerIter));
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
380
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381 if (removed)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
383 break;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
384 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
385 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
386 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
387 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
388 while (model.IterNext(ref iter));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
389 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
390
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
391 private void RemoveUnitTab(WFObjects.Unit unit)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
392 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
393 UnitDisplayWidget widget = DictionaryUtils.GetValue(unitToWidgetMap, unit);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
394
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
395 if (widget != null)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
396 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
397 unitsNotebook.Remove(widget);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
398 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
399 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
400
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
401 private void OnPointsValueChanged(WarFoundryObject obj, double before, double after)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
402 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
403 SetPointsPanelText();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
404 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
405
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
406 private void OnFailedUnitRequirement(List<FailedUnitRequirement> failedRequirement)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
407 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408 //Show error message in panel
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
409 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
410
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
411 public Preferences Preferences
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
412 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
413 get { return preferences; }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
414 set { preferences = value; }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
415 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
416
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
417 protected void OnDeleteEvent(object sender, DeleteEventArgs a)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
418 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
419 Application.Quit();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
420 a.RetVal = true;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
421 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
422
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
423 protected virtual void OnExitActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
424 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
425 Application.Quit();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
426 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
427
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
428 protected virtual void OnCreateArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
429 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
430 CreateNewArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
431 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
432
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
433 protected virtual void OnReloadFilesActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
434 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
435 WarFoundryLoader.GetDefault().LoadFiles();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
436 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
437
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
438 protected virtual void OnSaveArmyAsActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
439 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
440 SaveCurrentArmyAs();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
441 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
442
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
443 protected virtual void OnCloseArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
444 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
445 CloseCurrentArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
447
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
448 protected virtual void OnOpenArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
449 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450 OpenArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
451 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
452
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
453 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
454 {
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
455 SaveCurrentArmyOrSaveAs();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
456 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
457
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
458 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460 if (sender is ToolButton)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
462 ToolButton toolButton = (ToolButton)sender;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
463 Category cat = (Category)toolButton.Data["Category"];
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
464
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
465 if (cat != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
466 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
467 logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
468 FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
469 ResponseType response = (ResponseType)newUnit.Run();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
470 newUnit.Hide();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
471
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
472 if (response == ResponseType.Ok)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
473 {
14
abbf8a3ac431 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
474 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
475 commandStack.Execute(cmd);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
476 ShowUnitWidget(cmd.Unit);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
477 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
478
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
479 newUnit.Dispose();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
480 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
481 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
483
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
484 public CommandStack CommandStack
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
485 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
486 get { return commandStack; }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
487 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
488
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
489 private void SetAppTitle()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
490 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
491 if (WarFoundryCore.CurrentArmy != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
493 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
494 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
495 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
497 if (WarFoundryCore.CurrentGameSystem != null)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
498 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
499 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
500 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
501 else
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
502 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
503 Title = AppTitle;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
504 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
505
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
506 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
507 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
508
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
509 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
510 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511 system = newSys;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
512 SetAppTitle();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513 RemoveCategoryButtons();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
514
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
515 if (system != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
517 AddCategoryButtons(system.Categories);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
518 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
520
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
521 private void OnArmyChanged(Army oldArmy, Army newArmy)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
522 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
523 loadedArmyPath = null;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
524 SetAppTitle();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
525 SetArmyTree(newArmy);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
526
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
527 if (oldArmy != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
528 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
529 oldArmy.UnitAdded -= UnitAddedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
530 oldArmy.UnitRemoved -= UnitRemovedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
531 oldArmy.PointsValueChanged -= PointsValueChangedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
532 oldArmy.FailedRequirement -= FailedUnitRequirementMethod;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
533 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
534
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 unitToWidgetMap.Clear();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
536
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
537 while (unitsNotebook.NPages > 0)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
538 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
539 unitsNotebook.RemovePage(0);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
540 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
541
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
542 if (newArmy == null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
543 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
544 DisableCategoryButtons();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
545 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
546 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
547 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
548 newArmy.UnitAdded += UnitAddedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
549 newArmy.UnitRemoved += UnitRemovedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
550 newArmy.PointsValueChanged += PointsValueChangedMethod;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
551 newArmy.FailedRequirement += FailedUnitRequirementMethod;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
552 //TODO: Clear all buttons
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
553 EnableCategoryButtons();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
554
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
555 if (newArmy.Race.HasCategoryOverrides())
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
556 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
557 RemoveCategoryButtons();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
558 AddCategoryButtons(newArmy.Race.Categories);
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
559 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
560 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
561
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
562 bool nonNullNewArmy = (newArmy != null);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
563 miCloseArmy.Sensitive = nonNullNewArmy;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
564 miSaveArmyAs.Sensitive = nonNullNewArmy;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
565 miExportArmyAs.Sensitive = nonNullNewArmy;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
566 hpaned2.Visible = nonNullNewArmy;
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
567 loadedArmyPath = null;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
568 //New army has no changes, so we can't save it
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 miSaveArmy.Sensitive = false;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
570 bttnSaveArmy.Sensitive = false;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
571
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
572 CommandStack.Reset();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573 SetPointsPanelText();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
575
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576 private void SetArmyTree(Army army)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
577 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578 logger.Debug("Resetting tree");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579 TreeStore store = (TreeStore)treeUnits.Model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580 store.Clear();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 TreeIter iter;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
582
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
583 if (army != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
585 logger.Debug("Loading in categories to tree");
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
586
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 foreach (ArmyCategory cat in army.Categories)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
589 logger.DebugFormat("Append category {0}", cat.Name);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590 iter = store.AppendValues(cat);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
591
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
592 foreach (WFObjects.Unit unit in cat.GetUnits())
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594 store.AppendValues(iter, unit);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
595 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
597
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598 logger.Debug("Finished loading tree categories");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
600 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
601
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 private void DisableCategoryButtons()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604 SetCategoryButtonsSensitive(false);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
606
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607 private void EnableCategoryButtons()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
609 SetCategoryButtonsSensitive(true);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
611
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
612 private void SetCategoryButtonsSensitive(bool state)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 int toolbarButtonCount = toolbar.Children.Length - 1;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
615 logger.Debug("Last button index: " + toolbarButtonCount);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
616
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
618 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619 logger.DebugFormat("Setting button {0} state to {1}", i, state);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620 toolbar.Children[i].Sensitive = state;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
623
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624 private void RemoveCategoryButtons()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626 int toolbarButtonCount = toolbar.Children.Length - 1;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
627
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
628 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630 toolbar.Remove(toolbar.Children[i]);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
631 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
633
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634 private void AddCategoryButtons(Category[] cats)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
636 if (cats != null && cats.Length > 0)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
638 logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
639
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 foreach (Category cat in cats)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
642 ToolButton button = new ToolButton("gtk-add");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 button.Label = cat.Name;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
644 button.TooltipText = Translation.GetTranslation("bttnCreateFromCat", "{0}", cat.Name);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
645 button.Data["Category"] = cat;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
646 button.Clicked += new System.EventHandler(OnAddUnitActivated);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647 toolbar.Insert(button, -1);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
648 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
650
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
651 toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats != null && cats.Length > 0;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
652
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653 toolbar.ShowAll();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
654 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
655
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 private void SetPointsPanelText()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
657 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
658 if (WarFoundryCore.CurrentArmy != null)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
659 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
660 lblTotalPoints.Text = Translation.GetTranslation("statusPanelPoints", "{0}pts of {1} pts", WarFoundryCore.CurrentArmy.Points, WarFoundryCore.CurrentArmy.MaxPoints);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
661 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
662 else
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
663 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
664 lblTotalPoints.Text = "";
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
665 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
666 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
667
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
668 private void commandStack_CommandStackUpdated()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
669 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
670 undoMenuButton.Sensitive = commandStack.CanUndo();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
671 miUndo.Sensitive = undoMenuButton.Sensitive;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
672 redoMenuButton.Sensitive = commandStack.CanRedo();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
673 miRedo.Sensitive = redoMenuButton.Sensitive;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
674
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
675 RebuildUndoRedoMenus();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
676
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
677 bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
678 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
679 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
680
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
681 private void RebuildUndoRedoMenus()
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
682 {
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
683 int redoLength = commandStack.RedoLength;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
684 int maxRedo = Math.Min(10, redoLength);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
685
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
686 if (redoLength > 0)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
687 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
688 Menu menu = new Menu();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
689 Command com;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
690 MenuItem mi;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
691
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
692 for (int i = 0; i < maxRedo; i++)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
693 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
694 com = commandStack.PeekRedoCommand(i + 1);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
695
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
696 if (com == null)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
697 {
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
698 break;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
699 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
700
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
701 mi = new MenuItem(com.Description);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
702 mi.Activated += new EventHandler(RedoMenuActivated);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
703 menu.Append(mi);
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
704 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
705
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
706 menu.ShowAll();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
707 redoMenuButton.Menu = menu;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
708 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
709 else
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
710 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
711 redoMenuButton.Menu = null;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
712 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
713
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
714 int undoLength = commandStack.UndoLength;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
715 int maxUndo = Math.Min(10, undoLength);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
716
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
717 if (undoLength > 0)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
718 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
719 Menu menu = new Menu();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
720 Command com;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
721 MenuItem mi;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
722
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
723 for (int i = 0; i < maxUndo; i++)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
724 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
725 com = commandStack.PeekUndoCommand(i + 1);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
726
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
727 if (com == null)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
728 {
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
729 break;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
730 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
731
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
732 mi = new MenuItem(com.UndoDescription);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
733 mi.Activated += new EventHandler(UndoMenuActivated);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
734 menu.Add(mi);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
735 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
736
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
737 menu.ShowAll();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
738 undoMenuButton.Menu = menu;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
739 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
740 else
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
741 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
742 undoMenuButton.Menu = null;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
743 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
744 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
745
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
746 private void RedoMenuActivated(object sender, EventArgs e)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
747 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
748 if (sender is MenuItem)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
749 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
750 MenuItem item = (MenuItem)sender;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
751 //we know it's an redo menu item so find it's index and redo everything
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
752
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
753 int max = Arrays.IndexOf(((Menu)redoMenuButton.Menu).Children, item);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
754
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
755 if (max >= 0)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
756 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
757 for (int i = 0; i <= max; i++)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
758 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
759 commandStack.Redo();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
760 }
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
761 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
762 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
763 }
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
764
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
765 private void UndoMenuActivated(object sender, EventArgs e)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
766 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
767 if (sender is MenuItem)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
768 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
769
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
770 MenuItem item = (MenuItem)sender;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
771 //we know it's an undo menu item so find it's index and undo everything
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
772
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
773 int max = Arrays.IndexOf(((Menu)undoMenuButton.Menu).Children, item);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
774
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
775 if (max >= 0)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
776 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
777 for (int i = 0; i <= max; i++)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
778 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
779 commandStack.Undo();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
780 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
781 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
782 }
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
783 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
784
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
785 private bool SaveCurrentArmyOrSaveAs()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
786 {
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
787 if (loadedArmyPath != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
788 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
789 return SaveCurrentArmy();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
790 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
791 else
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
792 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
793 return SaveCurrentArmyAs();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
794 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
795 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
796
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
797 private bool OpenArmy()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
798 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
799 string title = Translation.GetTranslation("openArmyDialog", "open army");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
800 string cancelText = Translation.GetTranslation("bttnCancel", "cancel");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
801 string openText = Translation.GetTranslation("bttnOpen", "open");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
802 FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Open, cancelText, ResponseType.Cancel, openText, ResponseType.Accept);
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
803 FileFilter filter = new FileFilter();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
804 filter.AddPattern("*.army");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
805 filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files");
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
806 fileDialog.AddFilter(filter);
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
807 int response = fileDialog.Run();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
808 string filePath = null;
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
809
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
810 if (response == (int)ResponseType.Accept)
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
811 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
812 filePath = fileDialog.Filename;
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
813 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
814
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
815 fileDialog.Hide();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
816 fileDialog.Dispose();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
817
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
818 bool success = false;
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
819
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
820 if (filePath != null)
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
821 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
822 FileInfo file = new FileInfo(filePath);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
823 Army army = null;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
824
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
825 try
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
826 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
827 army = WarFoundryLoader.GetDefault().LoadArmy(file);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
828 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
829 catch (Exception ex)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
830 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
831 logger.Error("Error while loading army file " + filePath, ex);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
832 }
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
833
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
834 if (army != null)
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
835 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
836 logger.Debug("Loaded army " + army.ID);
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
837 success = true;
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
838 WarFoundryCore.CurrentArmy = army;
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
839 loadedArmyPath = filePath;
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
840 logger.Debug("Army loading complete");
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
841 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
842 else
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
843 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
844 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("OpenFailed", "File open failed. Please check log file"));
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
845 dialog.Title = Translation.GetTranslation("OpenFailedTitle", "File open failed");
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
846 dialog.Run();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
847 dialog.Hide();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
848 dialog.Dispose();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
849 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
850 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
851 else
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
852 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
853 logger.Debug("Army open requested but cancelled");
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
854 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
855
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
856 return success;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
857 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
858
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
859 private bool SaveCurrentArmy()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
860 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
861 bool success = false;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
862
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
863 if (loadedArmyPath != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
864 {
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
865 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
866 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
867
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
868 return success;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
869 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
870
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
871 private bool SaveCurrentArmyAs()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
872 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
873 string title = Translation.GetTranslation("saveArmyDialog", "save army");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
874 string cancelText = Translation.GetTranslation("bttnCancel", "cancel");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
875 string saveText = Translation.GetTranslation("bttnSave", "save");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
876 FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, saveText, ResponseType.Accept);
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
877 FileFilter filter = new FileFilter();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
878 filter.AddPattern("*.army");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
879 filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files");
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
880 fileDialog.AddFilter(filter);
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
881 int response = fileDialog.Run();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
882 string filePath = null;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
883
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
884 if (response == (int)ResponseType.Accept)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
885 {
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
886 filePath = fileDialog.Filename;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
887 }
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
888
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
889 fileDialog.Hide();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
890 fileDialog.Dispose();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
891
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
892 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath);
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
893 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
894
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
895 private bool SaveArmyToPath(Army army, string filePath)
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
896 {
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
897 bool success = false;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
898
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
899 if (filePath != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
900 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
901 bool saveSuccess = false;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
902
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
903 try
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
904 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
905 saveSuccess = WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, filePath);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
906 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
907 catch (Exception ex)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
908 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
909 logger.Error("Error while saving army file to " + filePath, ex);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
910 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
911
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
912 if (saveSuccess)
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
913 {
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
914 miSaveArmy.Sensitive = false;
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
915 bttnSaveArmy.Sensitive = false;
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
916 CommandStack.setCleanMark();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
917 loadedArmyPath = filePath;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
918 success = true;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
919 }
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
920 else
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
921 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
922 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("SaveFailed", "File save failed. Please check log file"));
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
923 dialog.Title = Translation.GetTranslation("SaveFailedTitle", "File save failed");
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
924 dialog.Run();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
925 dialog.Hide();
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
926 dialog.Dispose();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
927 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
928 }
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
929 //else user cancelled
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
930
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
931 return success;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
932 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
933
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
934 private bool CloseCurrentArmy()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
935 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
936 if (WarFoundryCore.CurrentArmy != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
937 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
938 bool canClose = false;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
939
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
940 if (CommandStack.IsDirty())
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
941 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
942 string message = Translation.GetTranslation("SaveChangesQuestion", "Save changes to army before closing?", WarFoundryCore.CurrentArmy.Name);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
943 MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.None, message);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
944 dia.AddButton(Translation.GetTranslation("bttnDiscard", "lose changes"), ResponseType.No);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
945 Button button = (Button)dia.AddButton(Translation.GetTranslation("bttnCancel", "cancel"), ResponseType.Cancel);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
946 button.Image = new Image("gtk-cancel", IconSize.Button);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
947 button = (Button)dia.AddButton(Translation.GetTranslation("bttnSave", "save"), ResponseType.Yes);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
948 button.Image = new Image("gtk-save", IconSize.Button);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
949 dia.Title = Translation.GetTranslation("SaveChangesTitle", "Save changes?");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
950 ResponseType dr = (ResponseType)dia.Run();
27
83c8945edac2 Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents: 26
diff changeset
951 dia.Hide();
83c8945edac2 Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents: 26
diff changeset
952 dia.Dispose();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
953
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
954 if (dr == ResponseType.Yes)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
955 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
956 //They want to save so try to save it or prompt for save as
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
957 //If they cancel the save as then assume they don't want to close
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
958 canClose = SaveCurrentArmyOrSaveAs();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
959 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
960 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
961 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
962 if (dr == ResponseType.No)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
963 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
964 //They don't care about their changes
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
965 canClose = true;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
966 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
967 else
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
968 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
969 //Assume cancel or close with the X button
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
970 canClose = false;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
971 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
972
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
973 }
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
974 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
975 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
976 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
977 //Nothing has changed so we can safely close
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
978 canClose = true;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
979 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
980
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
981 if (canClose)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
982 {
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
983 //do close
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
984 WarFoundryCore.CurrentArmy = null;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
985 return true;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
986 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
987 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
988 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
989 return false;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
990 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
991 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
992 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
993 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
994 //pretend we succeeded
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
995 return true;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
996 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
997 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
998
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
999 private void CreateNewArmy()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1000 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1001 logger.Debug("Create new army");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1002 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1003 ResponseType type = (ResponseType)newArmy.Run();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1004 newArmy.Hide();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1005
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1006 if (type == ResponseType.Ok)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1007 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1008 if (CloseCurrentArmy())
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1009 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1010 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1011 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1012 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1013 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1014 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1015 logger.Debug("Create new army cancelled");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1016 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1017
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1018 newArmy.Destroy();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1019 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1020
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1021 protected virtual void undoTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1022 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1023 CommandStack.Undo();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1024 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1025
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1026 protected virtual void redoTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1027 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1028 CommandStack.Redo();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1029 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1030
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1031 protected virtual void saveTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1032 {
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
1033 SaveCurrentArmyOrSaveAs();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1034 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1035
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1036 protected virtual void openTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1037 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1038 OpenArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1039 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1040
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1041 protected virtual void newTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1042 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1043 CreateNewArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1044 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1045
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1046 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1047 {
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1048 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1049
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1050 if (obj is WFObjects.Unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1051 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1052 WFObjects.Unit unit = (WFObjects.Unit)obj;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1053 ShowUnitWidget(unit);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1054 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1055 }
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1056
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1057 private void ShowUnitWidget(WFObjects.Unit unit)
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1058 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1059 UnitDisplayWidget widget;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1060 unitToWidgetMap.TryGetValue(unit, out widget);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1061
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1062 if (widget != null)
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1063 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1064 logger.DebugFormat("Selecting existing page for " + unit.Name);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1065 unitsNotebook.Page = unitsNotebook.PageNum(widget);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1066 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1067 else
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1068 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1069 widget = new UnitDisplayWidget(unit, CommandStack);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1070 logger.Debug("Adding page for " + unit.Name);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1071 unitToWidgetMap[unit] = widget;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1072 int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1073 logger.Debug("Page added at index " + pageNum);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1074 unitsNotebook.ShowAll();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1075 unitsNotebook.CurrentPage = pageNum;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1076 unitsNotebook.SetTabReorderable(widget, true);
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1077 }
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1078 }
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1079
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1080 protected virtual void OnMiExportAsBasicHtmlActivated(object sender, System.EventArgs e)
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1081 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1082 string exportArmyTitle = Translation.GetTranslation("exportBasicHtmlDialogTitle", "export army");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1083 string cancelText = Translation.GetTranslation("exportBasicHtmlCancel", "cancel");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1084 string exportText = Translation.GetTranslation("exportBasicHtmlExport", "export");
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1085 FileChooserDialog fileDialog = new FileChooserDialog(exportArmyTitle, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, exportText, ResponseType.Accept);
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1086 FileFilter filter = new FileFilter();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1087 filter.AddPattern("*.html");
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1088 filter.Name = Translation.GetTranslation("exportBasicHtmlHtmlFilter", "HTML pages (*.html)");
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1089 fileDialog.AddFilter(filter);
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1090 int response = fileDialog.Run();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1091 string filePath = null;
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1092
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1093 if (response == (int)ResponseType.Accept)
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1094 {
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1095 filePath = fileDialog.Filename;
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1096 }
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1097
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1098 fileDialog.Hide();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1099 fileDialog.Dispose();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1100
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1101 if (filePath != null)
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1102 {
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1103 Army army = WarFoundryCore.CurrentArmy;
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1104 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1105 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1106 }
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1107 }
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1108
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1109 protected virtual void OnTreeUnitsPopupMenu(object o, Gtk.PopupMenuArgs args)
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1110 {
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1111 object selectedItem = TreeUtils.GetSelectedItem(treeUnits);
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1112
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1113 if (selectedItem is WFObjects.Unit)
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1114 {
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1115 Menu menu = new Menu();
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1116 ImageMenuItem delete = new ImageMenuItem(Translation.GetTranslation("menuRemoveUnit", "remove unit"));
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1117 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu);
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1118 delete.Activated += new EventHandler(OnUnitDelete);
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1119 delete.Data["unit"] = selectedItem;
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1120 menu.Append(delete);
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1121 menu.ShowAll();
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1122 menu.Popup();
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1123 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1124 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1125
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1126 private void OnUnitDelete(object o, EventArgs args)
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1127 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1128 RemoveUnitCommand command = new RemoveUnitCommand((WFObjects.Unit)((ImageMenuItem)o).Data["unit"]);
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1129 commandStack.Execute(command);
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1130 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1131
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1132 [GLib.ConnectBefore]
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1133
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1134 protected virtual void UnitTreeButtonPressed(object o, Gtk.ButtonPressEventArgs args)
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1135 {
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1136 TreePath path;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1137 treeUnits.GetPathAtPos((int)args.Event.X, (int)args.Event.Y, out path);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1138
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1139 if (!treeUnits.Selection.PathIsSelected(path))
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1140 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1141 treeUnits.Selection.SelectPath(path);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1142 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1143
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1144 if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3)
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1145 {
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1146 OnTreeUnitsPopupMenu(o, null);
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1147 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1148 }
113
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1149
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1150 protected virtual void NotebookPageRemoved(object o, Gtk.RemovedArgs args)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1151 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1152 Widget widget = args.Widget;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1153
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1154 if (widget is UnitDisplayWidget)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1155 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1156 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1157 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1158 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1159
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1160 protected virtual void HelpAboutActivated(object sender, System.EventArgs e)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1161 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1162 FrmAbout form = FrmAbout.GetForm();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1163 form.Run();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1164 form.Hide();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1165 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1166
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1167 protected virtual void miPreferencesClicked(object sender, System.EventArgs e)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1168 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1169 FrmPreferences form = new FrmPreferences(Preferences);
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1170 form.Run();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1171 form.Hide();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1172 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1173
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1174 public override ICollection<Action> Actions
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1175 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1176 get
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1177 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1178 List<Action> actions = new List<Action>();
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1179
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1180 foreach (ActionGroup actionGroup in this.UIManager.ActionGroups)
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1181 {
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1182 actions.AddRange(actionGroup.ListActions());
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1183 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1184
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1185 return actions;
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1186 }
4a33b3012100 * Tag v0.1RC1 release
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
1187 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1188 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1189 }