annotate FrmMainWindow.cs @ 79:592930d28da4

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