annotate FrmMainWindow.cs @ 162:354c1d2ad086

Re #423: Support nested units in GTK UI * Add "add unit" context menu to tree * Add quick hacks to unit dialog to work with both nesting and direct category units
author IBBoard <dev@ibboard.co.uk>
date Sun, 05 Aug 2012 21:01:00 +0100
parents 89e2442bbb60
children 219340630150
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 using System;
103
1bd748721040 * Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
5 using System.Collections;
0
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;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
8 using System.IO;
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
9 using GLib;
13
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;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
13 using IBBoard.CustomMath;
12
685532d43a96 Re #88: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
14 using IBBoard.GtkSharp;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
15 using IBBoard.GtkSharp.Translatable;
0
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;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
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;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 using IBBoard.WarFoundry.API.Savers;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
26 using IBBoard.WarFoundry.GUI.GTK.Widgets;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 using IBBoard.Xml;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 using log4net;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
29 using WFObjects = IBBoard.WarFoundry.API.Objects;
108
b51935854587 * Use new saver
IBBoard <dev@ibboard.co.uk>
parents: 106
diff changeset
30 using IBBoard.WarFoundry.API.Savers.Xml;
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
31 using IBBoard.WarFoundry.API.Objects.Requirement;
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
32 using System.Text;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
34 namespace IBBoard.WarFoundry.GUI.GTK
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
35 {
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
36 public partial class FrmMainWindow: TranslatableWindowWithActions
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 {
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
38 private static readonly string VALIDATION_RESULTS_KEY = "WarFoundryValidationFailureMessages";
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 private static readonly string AppTitle = "WarFoundry";
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
40 private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
41 private Preferences preferences;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
42 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 private CommandStack commandStack;
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
44 private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
45 private ObjectAddDelegate UnitAddedMethod;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
46 private ObjectRemoveDelegate UnitRemovedMethod;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
47 private DoubleValChangedDelegate PointsValueChangedMethod;
0
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
47
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
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 {
47
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
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 }
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
64 catch (Exception ex)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
65 {
47
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
66 HandleUnhandledException(ex);
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
67 }
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
68 }
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
69
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
70 private static void HandleUnhandledException(UnhandledExceptionArgs args)
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
71 {
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
72 object obj = args.ExceptionObject;
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
73 Exception ex = null;
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
74
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
75 if (obj is Exception)
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
76 {
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
77 ex = (Exception)obj;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 }
47
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
79 else
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
80 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
81 ex = new Exception("GLib returned unexpected exception object type " + obj.GetType());
47
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
82 }
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
83
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
84 HandleUnhandledException(ex);
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
85 }
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
86
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
87 private static void HandleUnhandledException(Exception ex)
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
88 {
57
293d204e40db Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
89 string msg = String.Format("({0}) {1}", ex.GetType().FullName, ex.Message);
293d204e40db Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
90 LogManager.GetLogger(typeof(FrmMainWindow)).Fatal(msg, ex);
47
07fd9f7b0dd1 Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
91 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details.");
57
293d204e40db Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
92 dialog.Run();
64
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
93 dialog.Hide();
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 57
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
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
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");
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
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");
82
fb16ca1cb52b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
108 redoMenuButton.Name = "bttnRedo";
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
109 redoMenuButton.Clicked += redoTBButtonActivated;
78
e63209ab2cfa Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 77
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");
82
fb16ca1cb52b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
113 undoMenuButton.Name = "bttnUndo";
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
114 undoMenuButton.Clicked += undoTBButtonActivated;
78
e63209ab2cfa Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 77
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);
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
117 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 1]);
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
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
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
121 TreeViewColumn mainColumn = new TreeViewColumn();
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
122 CellRendererText mainCell = new CellRendererText();
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
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");
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
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();
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
146 commandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated);
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
147 WarFoundryCore.GameSystemChanged += new GameSystemChangedDelegate(OnGameSystemChanged);
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
148 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(OnArmyChanged);
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
149 Destroyed += new EventHandler(OnWindowDestroyed);
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
150 Translation.TranslationChanged += Retranslate;
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
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 UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged);
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
156 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
157 SetStatusBarText();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
158
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
159 LoadFilesFromArgs(args);
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
160 }
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
161
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
162 private void LoadFilesFromArgs(string[] args)
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
163 {
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
164 logger.Debug("Initialising complete - seeing if we can load default army or system");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165 if (args.Length == 1)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 {
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
167 logger.Debug("Attempting to load from file");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 FileInfo file = new FileInfo(args[0]);
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
169
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 try
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 {
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
172 ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file);
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
173
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
174 if (objects.Count == 1)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 {
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
176 List<IWarFoundryObject> objectList = new List<IWarFoundryObject>();
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
177 objectList.AddRange(objects);
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
178 IWarFoundryObject loadedObject = objectList[0];
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
179
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
180 if (loadedObject is Army)
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
181 {
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
182 WarFoundryCore.CurrentArmy = (Army)loadedObject;
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
183 logger.InfoFormat("Loaded army from {0}", file.FullName);
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
184 }
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
185 else
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
186 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
187 if (loadedObject is GameSystem)
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
188 {
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
189 WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
190 logger.InfoFormat("Loaded game system from {0}", file.FullName);
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
191 }
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
192
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
193 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 catch (InvalidFileException ex)
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 //TODO: show error dialog
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 logger.Error(ex);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 else
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 string gameSystemID = Preferences.GetStringProperty("currSystem");
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
205
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
206 if (gameSystemID != null && !"".Equals(gameSystemID))
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208 logger.Debug("Attempting to load current game system from properties");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
210
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
211 if (sys != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 WarFoundryCore.CurrentGameSystem = sys;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 }
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 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
219
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
220 protected override void Translate()
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
221 {
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
222 base.Translate();
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
223 SetAppTitle();
82
fb16ca1cb52b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
224 treeUnits.GetColumn(0).Title = Translation.GetTranslation("armyCategoryColumnTitle", "categories");
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
225 RebuildUndoRedoMenus();
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
226 }
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
227
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
228 private void Retranslate()
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
229 {
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
230 Translate();
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
231 }
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
232
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
233 public override void Dispose()
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
234 {
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
235 Translation.TranslationChanged -= Retranslate;
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
236 base.Dispose();
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
237 }
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
238
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
239 private void FileLoadingFinished(List<FileLoadFailure> failures)
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
240 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
241 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
242 {
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
243 logger.Warn("Failed to load " + failure.FailedFile.Name + ": " + failure.Message);
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 }
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
246
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 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
248 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 object o = model.GetValue(iter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
250
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 if (o is ArmyCategory)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 ArmyCategory c = (ArmyCategory)o;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 string name = "";
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
255
32
eab45344cd56 Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
256 if (!Preferences.GetBooleanProperty("ShowCatPercentage"))
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257 {
135
fda46380dd68 Re #329: "Points" system should be used in UI
IBBoard <dev@ibboard.co.uk>
parents: 125
diff changeset
258 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}{2}", c.Name, c.Points, WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(c.Points));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 {
135
fda46380dd68 Re #329: "Points" system should be used in UI
IBBoard <dev@ibboard.co.uk>
parents: 125
diff changeset
262 name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}{3} ({2}%)", c.Name, c.Points, (c.ParentArmy.Points > 0 ? Math.Round((c.Points / c.ParentArmy.Points) * 100) : 0), WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(c.Points));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
264
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 (cell as CellRendererText).Text = name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266 }
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
267 else
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
269 if (o is WFObjects.Unit)
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
270 {
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
271 WFObjects.Unit u = (WFObjects.Unit)o;
135
fda46380dd68 Re #329: "Points" system should be used in UI
IBBoard <dev@ibboard.co.uk>
parents: 125
diff changeset
272 string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}{2}", u.Name, u.Points, WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(u.Points));
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
273 (cell as CellRendererText).Text = name;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
274 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
275
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
276 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
278
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
279 private void OnWindowDestroyed(object source, EventArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
280 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281 logger.Info("Exiting");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282 Application.Quit();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
284
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
286 {
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
287 WFObjects.Unit unit = (WFObjects.Unit)val;
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
288 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
289 UnitDisplayWidget widget;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
290 unitToWidgetMap.TryGetValue(unit, out widget);
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
291
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
292 if (widget != null)
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
293 {
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
294 unitsNotebook.SetTabLabel(widget, NotebookUtil.CreateNotebookTabLabelWithClose(unitsNotebook, widget, unit.Name));
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
295 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
296
41
a32b6bb7f1eb Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
297 treeUnits.QueueDraw();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
298 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
299
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
300 private void OnUnitAdded(WarFoundryObject val)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
301 {
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
302 WFObjects.Unit unit = (WFObjects.Unit)val;
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
303 unit.NameChanged += UnitNameChangedMethod;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
304 unit.PointsValueChanged += HandleUnitPointsValueChanged;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
305 AddUnitToTree(unit);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
306 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
307
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
308 private void HandleUnitPointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
309 {
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
310 treeUnits.QueueDraw();
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
311 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
312
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
313 private void AddUnitToTree(WFObjects.Unit unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 TreeStore model = (TreeStore)treeUnits.Model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 TreeIter iter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317 model.GetIterFirst(out iter);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
318
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 do
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
320 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
321 object obj = model.GetValue(iter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
322
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
323 if (obj is ArmyCategory)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
324 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
325 ArmyCategory cat = (ArmyCategory)obj;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
326
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
327 if (cat.Equals(unit.Category))
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
328 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 model.AppendValues(iter, unit);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330 TreePath path = model.GetPath(iter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
331 treeUnits.ExpandToPath(path);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 }
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
334 } while (model.IterNext(ref iter));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
335 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
336
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337 private void OnUnitRemoved(WarFoundryObject obj)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338 {
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
339 WFObjects.Unit unit = (WFObjects.Unit)obj;
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
340 unit.NameChanged -= UnitNameChangedMethod;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
341 RemoveUnitFromTree(unit);
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
342 RemoveUnitTab(unit);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
344
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
345 private void RemoveUnitFromTree(WFObjects.Unit unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 TreeStore model = (TreeStore)treeUnits.Model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348 TreeIter iter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 model.GetIterFirst(out iter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350 bool removed = false;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
351
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 do
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
354 object obj = model.GetValue(iter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
355
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356 if (obj is ArmyCategory)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358 ArmyCategory cat = (ArmyCategory)obj;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
359
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 if (unit.Category == null || cat.Equals(unit.Category))
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
361 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
362 TreeIter innerIter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363 model.IterChildren(out innerIter, iter);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
364
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 do
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
366 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367 object innerObj = model.GetValue(innerIter, 0);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
368
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
369 if (unit.Equals(innerObj))
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371 model.Remove(ref innerIter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
372 removed = true;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
373 break;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374 }
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
375 } while (model.IterNext(ref innerIter));
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
376
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 if (removed)
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 break;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
380 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382 }
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
383 } while (model.IterNext(ref iter));
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
384 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
385
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
386 private void RemoveUnitTab(WFObjects.Unit unit)
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
387 {
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
388 UnitDisplayWidget widget = DictionaryUtils.GetValue(unitToWidgetMap, unit);
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
389
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
390 if (widget != null)
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
391 {
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
392 unitsNotebook.Remove(widget);
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
393 }
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
394 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
395
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
396 private void OnPointsValueChanged(WarFoundryObject obj, double before, double after)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
397 {
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
398 SetStatusBarText();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
399 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
400
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
401 public Preferences Preferences
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
402 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
403 get { return preferences; }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
404 set { preferences = value; }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
405 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
406
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
407 protected void OnDeleteEvent(object sender, DeleteEventArgs a)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
409 Application.Quit();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
410 a.RetVal = true;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
411 }
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 protected virtual void OnExitActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
414 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
415 Application.Quit();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
416 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
417
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
418 protected virtual void OnCreateArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
419 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
420 CreateNewArmy();
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 OnReloadFilesActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
424 {
43
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
425 WarFoundryLoader.GetDefault().LoadFiles();
0
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 OnSaveArmyAsActivated(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 SaveCurrentArmyAs();
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 OnCloseArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
434 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
435 CloseCurrentArmy();
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 OnOpenArmyActivated(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 OpenArmy();
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 OnSaveArmyActivated(object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
444 {
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
445 SaveCurrentArmyOrSaveAs();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
447
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
448 protected virtual void OnAddUnitActivated(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 if (sender is ToolButton)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
451 {
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
452 ToolButton toolButton = (ToolButton)sender;
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
453 Category cat = (Category)toolButton.Data["Category"];
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
454
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
455 if (cat != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
456 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
457 logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
458 FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 ResponseType response = (ResponseType)newUnit.Run();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460 newUnit.Hide();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
461
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
462 if (response == ResponseType.Ok)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
463 {
14
abbf8a3ac431 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
464 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
465 commandStack.Execute(cmd);
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
466 ShowUnitWidget(cmd.Unit);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
467 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
468
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
469 newUnit.Dispose();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
470 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
471 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
472 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
473
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
474 public CommandStack CommandStack
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
475 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
476 get { return commandStack; }
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 private void SetAppTitle()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
480 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
481 if (WarFoundryCore.CurrentArmy != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
483 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
484 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
485 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
486 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
487 if (WarFoundryCore.CurrentGameSystem != null)
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
488 {
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
489 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
490 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
491 else
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
492 {
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
493 Title = AppTitle;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
494 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
495
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
497 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
498
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
499 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501 system = newSys;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 SetAppTitle();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
503 RemoveCategoryButtons();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
504
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
505 if (system != null)
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 AddCategoryButtons(system.Categories);
151
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
508 logger.DebugFormat("Game system set to {0} with ID {1}", system.Name, system.ID);
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
509 }
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
510 else
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
511 {
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
512 logger.Debug("Game system set to null");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
515
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516 private void OnArmyChanged(Army oldArmy, Army newArmy)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
517 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
518 loadedArmyPath = null;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 SetAppTitle();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 SetArmyTree(newArmy);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
521
43
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
522 if (oldArmy != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
523 {
43
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
524 oldArmy.UnitAdded -= UnitAddedMethod;
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
525 oldArmy.UnitRemoved -= UnitRemovedMethod;
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
526 oldArmy.PointsValueChanged -= PointsValueChangedMethod;
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
527 oldArmy.NameChanged -= OnArmyNameChanged;
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
528 oldArmy.MaxPointsValueChanged -= OnMaxPointsValueChanged;
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
529 oldArmy.ArmyCompositionChanged -= HandleArmyCompositionChanged;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
530 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
531
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
532 unitToWidgetMap.Clear();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
533
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
534 while (unitsNotebook.NPages > 0)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
536 unitsNotebook.RemovePage(0);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
537 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
538
43
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
539 if (newArmy == null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
540 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
541 DisableCategoryButtons();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
542 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
543 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
544 {
43
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
545 newArmy.UnitAdded += UnitAddedMethod;
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
546 newArmy.UnitRemoved += UnitRemovedMethod;
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
547 newArmy.PointsValueChanged += PointsValueChangedMethod;
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
548 newArmy.NameChanged += OnArmyNameChanged;
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
549 newArmy.MaxPointsValueChanged += OnMaxPointsValueChanged;
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
550 newArmy.ArmyCompositionChanged += HandleArmyCompositionChanged;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
551 //TODO: Clear all buttons
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
552 EnableCategoryButtons();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
553
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
554 if (newArmy.Race.HasCategoryOverrides())
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
555 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
556 RemoveCategoryButtons();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
557 AddCategoryButtons(newArmy.Race.Categories);
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
558 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
560
43
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
561 bool nonNullNewArmy = (newArmy != null);
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
562 miCloseArmy.Sensitive = nonNullNewArmy;
4e127ce8682f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
563 miSaveArmyAs.Sensitive = nonNullNewArmy;
81
3ff8e10de45a Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 79
diff changeset
564 miExportArmyAs.Sensitive = nonNullNewArmy;
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
565 miEditArmy.Sensitive = nonNullNewArmy;
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
566 treeUnits.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;
82
fb16ca1cb52b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 81
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();
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
573 SetStatusBarText();
0
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
151
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
576 private void OnArmyNameChanged(WarFoundryObject obj, string oldValue, string newValue)
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
577 {
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
578 SetAppTitle();
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
579 }
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
580
151
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
581 private void OnMaxPointsValueChanged(WarFoundryObject obj, int oldValue, int newValue)
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
582 {
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
583 SetStatusBarText();
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
584 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
585
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
586 private void HandleArmyCompositionChanged()
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
587 {
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
588 SetStatusBarText();
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
589 }
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
590
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591 private void SetArmyTree(Army army)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
592 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 logger.Debug("Resetting tree");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594 TreeStore store = (TreeStore)treeUnits.Model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595 store.Clear();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 TreeIter iter;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
597
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
598 if (army != null)
0
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 logger.Debug("Loading in categories to tree");
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 foreach (ArmyCategory cat in army.Categories)
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 logger.DebugFormat("Append category {0}", cat.Name);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 iter = store.AppendValues(cat);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
606
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
607 foreach (WFObjects.Unit unit in cat.GetUnits())
0
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 store.AppendValues(iter, unit);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
610 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
612
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613 logger.Debug("Finished loading tree categories");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 }
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 private void DisableCategoryButtons()
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 SetCategoryButtonsSensitive(false);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
621
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 private void EnableCategoryButtons()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624 SetCategoryButtonsSensitive(true);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
626
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
627 private void SetCategoryButtonsSensitive(bool state)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
628 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 int toolbarButtonCount = toolbar.Children.Length - 1;
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
630 logger.Debug("Last button index: " + toolbarButtonCount);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
631
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634 logger.DebugFormat("Setting button {0} state to {1}", i, state);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 toolbar.Children[i].Sensitive = state;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
638
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
639 private void RemoveCategoryButtons()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 int toolbarButtonCount = toolbar.Children.Length - 1;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
642
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
645 toolbar.Remove(toolbar.Children[i]);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
648
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 private void AddCategoryButtons(Category[] cats)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
651 if (cats != null && cats.Length > 0)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
652 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653 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
654
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655 foreach (Category cat in cats)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
657 ToolButton button = new ToolButton("gtk-add");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
658 button.Label = cat.Name;
83
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
659 button.TooltipText = Translation.GetTranslation("bttnCreateFromCat", "{0}", cat.Name);
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
660 button.Data["Category"] = cat;
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
661 button.Clicked += new System.EventHandler(OnAddUnitActivated);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
662 toolbar.Insert(button, -1);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
663 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
664 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
665
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
666 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
667
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
668 toolbar.ShowAll();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
669 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
670
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
671 private void SetStatusBarText()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
672 {
99
8777e4f64d8e Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
673 if (WarFoundryCore.CurrentArmy != null)
8777e4f64d8e Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
674 {
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
675 statusbar.Push(1, GetPointsText());
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
676 SetValidationText();
99
8777e4f64d8e Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
677 }
8777e4f64d8e Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
678 else
8777e4f64d8e Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
679 {
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
680 statusbar.Push(1, "");
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
681 SetBlankValidationText();
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
682 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
683 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
684
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
685 private string GetPointsText()
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
686 {
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
687 int maxPts = WarFoundryCore.CurrentArmy.MaxPoints;
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
688 string maxPtsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.MaxPoints);
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
689 double points = WarFoundryCore.CurrentArmy.Points;
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
690 string ptsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.Points);
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
691 return Translation.GetTranslation("statusPanelPoints", "{0}{2} of {1}{3}", points, maxPts, ptsAbbrev, maxPtsAbbrev);
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
692 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
693
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
694 private void SetValidationText()
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
695 {
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
696 if (WarFoundryCore.CurrentGameSystem != null && WarFoundryCore.CurrentGameSystem.WarnOnError)
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
697 {
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
698 SetValidationTextAndColour();
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
699 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
700 else
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
701 {
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
702 SetBlankValidationText();
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
703 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
704 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
705
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
706 private void SetValidationTextAndColour()
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
707 {
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
708 ICollection<string> failureMessages;
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
709 Validation result = RequirementHandler.ValidateArmy(WarFoundryCore.CurrentArmy, out failureMessages);
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
710 string pluralHack = (failureMessages.Count == 1 ? "" : "s");
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
711 lblValidationWarning.Text = String.Format("{0} validation warning{1}", failureMessages.Count, pluralHack);
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
712 lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = failureMessages;
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
713
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
714 if (Validates.AsOkay(result))
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
715 {
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
716 lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero);
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
717 }
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
718 else
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
719 {
149
45c2485f37c0 * Initialise variable - xbuild is more picky than MonoDevelop
IBBoard <dev@ibboard.co.uk>
parents: 142
diff changeset
720 Gdk.Color red = Gdk.Color.Zero;
140
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
721 Gdk.Color.Parse("#cc0000", ref red);
2b9fabd65309 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
722 lblValidationWarning.ModifyFg(StateType.Normal, red);
99
8777e4f64d8e Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
723 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
724 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
725
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
726 private void SetBlankValidationText()
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
727 {
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
728 lblValidationWarning.Text = "";
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
729 lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = new string[0];
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
730 lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero);
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
731 }
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
732
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
733 private void commandStack_CommandStackUpdated()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
734 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
735 undoMenuButton.Sensitive = commandStack.CanUndo();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
736 miUndo.Sensitive = undoMenuButton.Sensitive;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
737 redoMenuButton.Sensitive = commandStack.CanRedo();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
738 miRedo.Sensitive = redoMenuButton.Sensitive;
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
739
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
740 RebuildUndoRedoMenus();
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
741
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
742 bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null;
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
743 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null;
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
744 }
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
745
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
746 private void RebuildUndoRedoMenus()
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
747 {
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
748 int redoLength = commandStack.RedoLength;
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
749 int maxRedo = Math.Min(10, redoLength);
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
750
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
751 if (redoLength > 0)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
752 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
753 Menu menu = new Menu();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
754 Command com;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
755 MenuItem mi;
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
756
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
757 for (int i = 0; i < maxRedo; i++)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
758 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
759 com = commandStack.PeekRedoCommand(i + 1);
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
760
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
761 if (com == null)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
762 {
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
763 break;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
764 }
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
765
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
766 mi = new MenuItem(com.Description);
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
767 mi.Activated += new EventHandler(RedoMenuActivated);
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
768 menu.Append(mi);
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
769 }
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
770
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
771 menu.ShowAll();
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
772 redoMenuButton.Menu = menu;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
773 }
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
774 else
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
775 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
776 redoMenuButton.Menu = null;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
777 }
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
778
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
779 int undoLength = commandStack.UndoLength;
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
780 int maxUndo = Math.Min(10, undoLength);
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
781
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
782 if (undoLength > 0)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
783 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
784 Menu menu = new Menu();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
785 Command com;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
786 MenuItem mi;
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
787
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
788 for (int i = 0; i < maxUndo; i++)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
789 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
790 com = commandStack.PeekUndoCommand(i + 1);
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
791
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
792 if (com == null)
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
793 {
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
794 break;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
795 }
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
796
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
797 mi = new MenuItem(com.UndoDescription);
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
798 mi.Activated += new EventHandler(UndoMenuActivated);
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
799 menu.Add(mi);
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
800 }
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
801
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
802 menu.ShowAll();
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
803 undoMenuButton.Menu = menu;
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
804 }
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
805 else
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
806 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
807 undoMenuButton.Menu = null;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
808 }
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
809 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
810
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
811 private void RedoMenuActivated(object sender, EventArgs e)
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
812 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
813 if (sender is MenuItem)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
814 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
815 MenuItem item = (MenuItem)sender;
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
816 //we know it's an redo menu item so find it's index and redo everything
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
817
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
818 int max = Arrays.IndexOf(((Menu)redoMenuButton.Menu).Children, item);
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
819
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
820 if (max >= 0)
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
821 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
822 for (int i = 0; i <= max; i++)
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
823 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
824 commandStack.Redo();
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
825 }
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
826 }
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
827 }
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
828 }
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
829
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
830 private void UndoMenuActivated(object sender, EventArgs e)
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
831 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
832 if (sender is MenuItem)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
833 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
834
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
835 MenuItem item = (MenuItem)sender;
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
836 //we know it's an undo menu item so find it's index and undo everything
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
837
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
838 int max = Arrays.IndexOf(((Menu)undoMenuButton.Menu).Children, item);
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
839
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
840 if (max >= 0)
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
841 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
842 for (int i = 0; i <= max; i++)
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
843 {
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
844 commandStack.Undo();
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
845 }
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
846 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
847 }
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
848 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
849
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
850 private bool SaveCurrentArmyOrSaveAs()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
851 {
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
852 if (loadedArmyPath != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
853 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
854 return SaveCurrentArmy();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
855 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
856 else
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 return SaveCurrentArmyAs();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
859 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
860 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
861
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
862 private bool OpenArmy()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
863 {
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
864 string title = Translation.GetTranslation("openArmyDialog", "open army");
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
865 string cancelText = Translation.GetTranslation("bttnCancel", "cancel");
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
866 string openText = Translation.GetTranslation("bttnOpen", "open");
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
867 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
868 FileFilter filter = new FileFilter();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
869 filter.AddPattern("*.army");
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
870 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
871 fileDialog.AddFilter(filter);
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
872 int response = fileDialog.Run();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
873 string filePath = null;
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
874
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
875 if (response == (int)ResponseType.Accept)
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
876 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
877 filePath = fileDialog.Filename;
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
878 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
879
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
880 fileDialog.Hide();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
881 fileDialog.Dispose();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
882
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
883 bool success = false;
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
884
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
885 if (filePath != null)
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
886 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
887 FileInfo file = new FileInfo(filePath);
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
888 Army army = null;
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
889
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
890 try
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
891 {
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
892 army = WarFoundryLoader.GetDefault().LoadArmy(file);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
893 }
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
894 catch (Exception ex)
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
895 {
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
896 logger.Error("Error while loading army file " + filePath, ex);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
897 }
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
898
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
899 if (army != null)
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
900 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
901 logger.Debug("Loaded army " + army.ID);
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
902 success = true;
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
903 WarFoundryCore.CurrentArmy = army;
25
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
904 loadedArmyPath = filePath;
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
905 logger.Debug("Army loading complete");
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
906 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
907 else
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
908 {
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
909 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("OpenFailed", "File open failed. Please check log file"));
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
910 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
911 dialog.Run();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
912 dialog.Hide();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
913 dialog.Dispose();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
914 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
915 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
916 else
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
917 {
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
918 logger.Debug("Army open requested but cancelled");
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
919 }
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
920
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
921 return success;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
922 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
923
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
924 private bool SaveCurrentArmy()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
925 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
926 bool success = false;
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
927
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
928 if (loadedArmyPath != null)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
929 {
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
930 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
931 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
932
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
933 return success;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
934 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
935
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
936 private bool SaveCurrentArmyAs()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
937 {
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
938 string title = Translation.GetTranslation("saveArmyDialog", "save army");
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
939 string cancelText = Translation.GetTranslation("bttnCancel", "cancel");
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
940 string saveText = Translation.GetTranslation("bttnSave", "save");
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
941 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
942 FileFilter filter = new FileFilter();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
943 filter.AddPattern("*.army");
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
944 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
945 fileDialog.AddFilter(filter);
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
946 int response = fileDialog.Run();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
947 string filePath = null;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
948
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
949 if (response == (int)ResponseType.Accept)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
950 {
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
951 filePath = fileDialog.Filename;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
952 }
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
953
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
954 fileDialog.Hide();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
955 fileDialog.Dispose();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
956
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
957 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath);
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
958 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
959
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
960 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
961 {
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
962 bool success = false;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
963
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
964 if (filePath != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
965 {
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
966 bool saveSuccess = false;
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
967
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
968 try
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
969 {
106
41e82ba675dc Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 105
diff changeset
970 saveSuccess = WarFoundrySaver.GetSaver().Save(filePath, WarFoundryCore.CurrentArmy);
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
971 }
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
972 catch (Exception ex)
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
973 {
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
974 logger.Error("Error while saving army file to " + filePath, ex);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
975 }
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
976
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
977 if (saveSuccess)
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
978 {
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
979 miSaveArmy.Sensitive = false;
82
fb16ca1cb52b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
980 bttnSaveArmy.Sensitive = false;
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
981 CommandStack.setCleanMark();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
982 loadedArmyPath = filePath;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
983 success = true;
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
984 }
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
985 else
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
986 {
151
83b19b57cba1 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
987 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("SaveFailed", "File save failed. Please check log file"));
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
988 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
989 dialog.Run();
01ddadfa9653 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
990 dialog.Hide();
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
991 dialog.Dispose();
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
992 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
993 }
23
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
994 //else user cancelled
d661cb257511 Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
995
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
996 return success;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
997 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
998
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
999 private bool CloseCurrentArmy()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1000 {
42
35ad26ac59c0 Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
1001 if (WarFoundryCore.CurrentArmy != null)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1002 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1003 bool canClose = false;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1004
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1005 if (CommandStack.IsDirty())
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1006 {
98
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1007 string message = Translation.GetTranslation("SaveChangesQuestion", "Save changes to army before closing?", WarFoundryCore.CurrentArmy.Name);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1008 MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.None, message);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1009 dia.AddButton(Translation.GetTranslation("bttnDiscard", "lose changes"), ResponseType.No);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1010 Button button = (Button)dia.AddButton(Translation.GetTranslation("bttnCancel", "cancel"), ResponseType.Cancel);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1011 button.Image = new Image("gtk-cancel", IconSize.Button);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1012 button = (Button)dia.AddButton(Translation.GetTranslation("bttnSave", "save"), ResponseType.Yes);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1013 button.Image = new Image("gtk-save", IconSize.Button);
fac0636ae13b Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
1014 dia.Title = Translation.GetTranslation("SaveChangesTitle", "Save changes?");
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1015 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
1016 dia.Hide();
83c8945edac2 Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents: 26
diff changeset
1017 dia.Dispose();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1018
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1019 if (dr == ResponseType.Yes)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1020 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1021 //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
1022 //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
1023 canClose = SaveCurrentArmyOrSaveAs();
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1024 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1025 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1026 {
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1027 if (dr == ResponseType.No)
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1028 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1029 //They don't care about their changes
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1030 canClose = true;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1031 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1032 else
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1033 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1034 //Assume cancel or close with the X button
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1035 canClose = false;
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1036 }
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1037
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1038 }
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1039 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1040 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1041 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1042 //Nothing has changed so we can safely close
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1043 canClose = true;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1044 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1045
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1046 if (canClose)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1047 {
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1048 //do close
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1049 WarFoundryCore.CurrentArmy = null;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1050 return true;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1051 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1052 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1053 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1054 return false;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1055 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1056 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1057 else
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1058 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1059 //pretend we succeeded
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1060 return true;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1061 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1062 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1063
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1064 private void CreateNewArmy()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1065 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1066 logger.Debug("Create new army");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1067 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1068 ResponseType type = (ResponseType)newArmy.Run();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1069 newArmy.Hide();
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1070
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1071 if (type == ResponseType.Ok)
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1072 {
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1073 if (CloseCurrentArmy())
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1074 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1075 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1076 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1077 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1078 else
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1079 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1080 logger.Debug("Create new army cancelled");
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1081 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1082
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1083 newArmy.Destroy();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1084 }
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1085
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1086 protected virtual void undoTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1087 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1088 CommandStack.Undo();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1089 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1090
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1091 protected virtual void redoTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1092 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1093 CommandStack.Redo();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1094 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1095
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1096 protected virtual void saveTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1097 {
33
441cfc410987 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 32
diff changeset
1098 SaveCurrentArmyOrSaveAs();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1099 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1100
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1101 protected virtual void openTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1102 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1103 OpenArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1104 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1105
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1106 protected virtual void newTBButtonActivated(object sender, System.EventArgs e)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1107 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1108 CreateNewArmy();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1109 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1110
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1111 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1112 {
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1113 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1114
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1115 if (obj is WFObjects.Unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1116 {
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1117 WFObjects.Unit unit = (WFObjects.Unit)obj;
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1118 ShowUnitWidget(unit);
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1119 }
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1120 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1121
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1122 private void ShowUnitWidget(WFObjects.Unit unit)
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1123 {
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1124 UnitDisplayWidget widget;
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1125 unitToWidgetMap.TryGetValue(unit, out widget);
21
2cf1af4c9baf Re #53: Add XML saver
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
1126
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
1127 if (widget != null)
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1128 {
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
1129 logger.DebugFormat("Selecting existing page for " + unit.Name);
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1130 unitsNotebook.Page = unitsNotebook.PageNum(widget);
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1131 }
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1132 else
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1133 {
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1134 widget = new UnitDisplayWidget(unit, CommandStack);
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
1135 logger.Debug("Adding page for " + unit.Name);
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1136 unitToWidgetMap[unit] = widget;
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1137 int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name);
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
1138 logger.Debug("Page added at index " + pageNum);
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1139 unitsNotebook.ShowAll();
46
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
1140 unitsNotebook.CurrentPage = pageNum;
3314f6a46661 Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
1141 unitsNotebook.SetTabReorderable(widget, true);
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1142 }
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1143 }
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1144
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1145 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
1146 {
83
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1147 string exportArmyTitle = Translation.GetTranslation("exportBasicHtmlDialogTitle", "export army");
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1148 string cancelText = Translation.GetTranslation("exportBasicHtmlCancel", "cancel");
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1149 string exportText = Translation.GetTranslation("exportBasicHtmlExport", "export");
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1150 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
1151 FileFilter filter = new FileFilter();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1152 filter.AddPattern("*.html");
83
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1153 filter.Name = Translation.GetTranslation("exportBasicHtmlHtmlFilter", "HTML pages (*.html)");
28
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1154 fileDialog.AddFilter(filter);
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1155 int response = fileDialog.Run();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1156 string filePath = null;
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1157
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1158 if (response == (int)ResponseType.Accept)
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1159 {
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1160 filePath = fileDialog.Filename;
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1161 }
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1162
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1163 fileDialog.Hide();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1164 fileDialog.Dispose();
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1165
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1166 if (filePath != null)
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1167 {
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1168 Army army = WarFoundryCore.CurrentArmy;
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1169 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
1170 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1171 }
9440eef124b0 Closes #69: Add "export" UI
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1172 }
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1173
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1174 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
1175 {
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1176 object selectedItem = TreeUtils.GetSelectedItem(treeUnits);
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1177 WFObjects.Unit theUnit = selectedItem as WFObjects.Unit;
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1178
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1179 if (theUnit != null)
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1180 {
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1181 Menu menu = new Menu();
83
678e9a0392fc Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1182 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
1183 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu);
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1184 delete.Activated += new EventHandler(OnUnitDelete);
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1185 delete.Data["unit"] = theUnit;
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1186 menu.Append(delete);
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1187
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1188 if (theUnit.UnitType.ContainedUnitTypes.Length > 0)
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1189 {
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1190 ImageMenuItem addContained = new ImageMenuItem(Translation.GetTranslation("menuAddUnit", "add unit"));
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1191 addContained.Image = new Gtk.Image(Stock.Add, IconSize.Menu);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1192 addContained.Activated += new EventHandler(OnSubUnitAdd);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1193 addContained.Data["unit"] = theUnit;
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1194 menu.Append(addContained);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1195 }
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1196
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1197 menu.ShowAll();
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1198 menu.Popup();
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1199 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1200 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1201
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1202 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
1203 {
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1204 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
1205 commandStack.Execute(command);
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1206 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1207
162
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1208 void OnSubUnitAdd(object sender, EventArgs e)
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1209 {
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1210 WFObjects.Unit unit = (WFObjects.Unit)((ImageMenuItem)sender).Data["unit"];
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1211 logger.DebugFormat("Show FrmNewUnit for contained units of {0}", unit.Name);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1212 FrmNewUnit newUnit = new FrmNewUnit(unit, WarFoundryCore.CurrentArmy);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1213 ResponseType response = (ResponseType)newUnit.Run();
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1214 newUnit.Hide();
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1215
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1216 if (response == ResponseType.Ok)
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1217 {
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1218 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(newUnit.SelectedUnit.MainCategory), unit);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1219 commandStack.Execute(cmd);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1220 ShowUnitWidget(cmd.Unit);
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1221 }
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1222
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1223 newUnit.Dispose();
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1224 }
354c1d2ad086 Re #423: Support nested units in GTK UI
IBBoard <dev@ibboard.co.uk>
parents: 159
diff changeset
1225
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1226 [GLib.ConnectBefore]
69
3b4a646b4054 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
1227
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1228 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
1229 {
44
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1230 TreePath path;
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1231 treeUnits.GetPathAtPos((int)args.Event.X, (int)args.Event.Y, out path);
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1232
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1233 if (!treeUnits.Selection.PathIsSelected(path))
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1234 {
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1235 treeUnits.Selection.SelectPath(path);
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1236 }
44e6833bb41a Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
1237
30
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1238 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
1239 {
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1240 OnTreeUnitsPopupMenu(o, null);
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1241 }
5fafbb1b4592 Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
1242 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1243
45
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1244 protected virtual void NotebookPageRemoved(object o, Gtk.RemovedArgs args)
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1245 {
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1246 Widget widget = args.Widget;
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1247
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1248 if (widget is UnitDisplayWidget)
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1249 {
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1250 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit);
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1251 }
5584860fb44b Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
1252 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1253
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1254 protected virtual void HelpAboutActivated(object sender, System.EventArgs e)
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1255 {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1256 FrmAbout form = FrmAbout.GetForm();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1257 form.Run();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1258 form.Hide();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 74
diff changeset
1259 }
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1260
95
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1261 protected virtual void miPreferencesClicked(object sender, System.EventArgs e)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1262 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1263 FrmPreferences form = new FrmPreferences(Preferences);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1264 form.Run();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1265 form.Hide();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1266 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1267
103
1bd748721040 * Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
1268 public override ICollection<Gtk.Action> Actions
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1269 {
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1270 get
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1271 {
103
1bd748721040 * Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
1272 List<Gtk.Action> actions = new List<Gtk.Action>();
79
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1273
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1274 foreach (ActionGroup actionGroup in this.UIManager.ActionGroups)
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1275 {
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1276 actions.AddRange(actionGroup.ListActions());
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1277 }
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1278
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1279 return actions;
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1280 }
592930d28da4 Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents: 78
diff changeset
1281 }
123
f58f69ea2435 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 110
diff changeset
1282
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1283 protected void OnTransformedXmlActionActivated(object sender, System.EventArgs e)
123
f58f69ea2435 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 110
diff changeset
1284 {
125
42d2aa87dfa7 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 123
diff changeset
1285 FrmExportXml form = new FrmExportXml(WarFoundryCore.CurrentArmy);
142
f23e5b40ca9d Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
1286 form.ParentWindow = this.GdkWindow;
125
42d2aa87dfa7 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 123
diff changeset
1287 form.Run();
42d2aa87dfa7 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 123
diff changeset
1288 form.Hide();
42d2aa87dfa7 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 123
diff changeset
1289 form.Dispose();
123
f58f69ea2435 Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents: 110
diff changeset
1290 }
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1291
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1292 protected void OnMiEditArmyActivated(object sender, System.EventArgs e)
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1293 {
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1294 FrmEditArmy form = new FrmEditArmy(commandStack, WarFoundryCore.CurrentArmy);
142
f23e5b40ca9d Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
1295 form.TransientFor = this;
f23e5b40ca9d Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
1296 form.WindowPosition = WindowPosition.CenterOnParent;
138
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1297 form.Run();
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1298 form.Hide();
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1299 form.Dispose();
33962c2ef550 Re #326: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
1300 }
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1301
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1302 protected void OnLblValidationWarningButtonReleaseEvent(object o, Gtk.ButtonReleaseEventArgs args)
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1303 {
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1304 if (args.Event.Button != (uint)MouseButton.Left)
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1305 {
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1306 return;
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1307 }
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1308
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1309 ICollection<string> failureMessages = lblValidationWarning.Data[VALIDATION_RESULTS_KEY] as ICollection<string>;
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1310
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1311 if (failureMessages != null && failureMessages.Count > 0)
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1312 {
142
f23e5b40ca9d Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
1313 ValidationFailureWidget failureWidget = new ValidationFailureWidget(failureMessages);
f23e5b40ca9d Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
1314 Dialog dialog = new SimpleDialog("Validation errors", this, DialogFlags.Modal, failureWidget);
141
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1315 dialog.Run();
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1316 dialog.Hide();
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1317 dialog.Dispose();
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1318 }
1ce4fe9ae3c1 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
1319 }
157
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1320
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1321 protected void OnAddNewFileActionActivated(object sender, EventArgs e)
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1322 {
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1323 string cancelText = Translation.GetTranslation("bttnCancel", "cancel");
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1324 string openText = Translation.GetTranslation("bttnOpen", "open");
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1325 FileChooserDialog fileDialog = new FileChooserDialog("Add data file", this, FileChooserAction.Open, cancelText, ResponseType.Cancel, openText, ResponseType.Accept);
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1326 fileDialog.SelectMultiple = true;
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1327 FileFilter filter = new FileFilter();
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1328 filter.AddPattern("*.race");
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1329 filter.AddPattern("*.system");
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1330 filter.Name = "WarFoundry data files";
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1331 fileDialog.AddFilter(filter);
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1332 int response = fileDialog.Run();
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1333 string[] filePaths = fileDialog.Filenames;
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1334 fileDialog.Hide();
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1335 fileDialog.Dispose();
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1336
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1337 if (response == (int)ResponseType.Accept)
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1338 {
159
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1339 List<Exception> exceptions = new List<Exception>();
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1340
157
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1341 foreach (string filePath in filePaths)
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1342 {
159
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1343 try
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1344 {
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1345 WarFoundryLoader.AddNewDataFile(filePath);
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1346 }
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1347 catch (Exception ex)
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1348 {
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1349 exceptions.Add(ex);
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1350 }
157
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1351 }
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1352
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1353 WarFoundryLoader.GetDefault().LoadFiles();
159
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1354
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1355 if (exceptions.Count > 0)
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1356 {
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1357 string errorMsg = MakeAddDataFileFailedMessage(exceptions);
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1358 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, errorMsg);
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1359 dialog.Run();
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1360 dialog.Hide();
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1361 dialog.Dispose();
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1362 }
157
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1363 }
2d1dd73a3289 Re #417: Improve install experience
IBBoard <dev@ibboard.co.uk>
parents: 151
diff changeset
1364 }
159
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1365
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1366 private string MakeAddDataFileFailedMessage(List<Exception> exceptions)
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1367 {
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1368 StringBuilder sb = new StringBuilder();
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1369 sb.Append("errors occurred while adding the new data files: ");
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1370
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1371 foreach (Exception ex in exceptions)
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1372 {
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1373 sb.Append("\n\t• ");
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1374 sb.Append(ex.Message);
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1375 }
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1376
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1377 return sb.ToString();
89e2442bbb60 Re #417: Improve install/first use experience
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
1378 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1379 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1380 }