annotate MainWindow.cs @ 12:4a724378d66a

Re #247: Implement menu options in Qt# app * Hook up army close (can now create, save and close armies) Re #242: Create Qt# UI for WarFoundry * Fix initial window title
author IBBoard <dev@ibboard.co.uk>
date Fri, 05 Feb 2010 20:57:44 +0000
parents 72bcf6457227
children dbe784f0802c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (MainWindow.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
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.
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System.Collections.Generic;
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using Qyoto;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
7 using log4net;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
8 using IBBoard.Commands;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
9 using IBBoard.IO;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
10 using IBBoard.WarFoundry.API;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
11 using IBBoard.WarFoundry.API.Factories;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
12 using IBBoard.WarFoundry.API.Objects;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
13 using IBBoard.WarFoundry.API.Savers;
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
15 namespace IBBoard.WarFoundry.GUI.QtSharp
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
17 public class MainWindow : QMainWindow
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
19 private static readonly string AppTitle = "WarFoundry";
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
20
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
21 private Ui_MainWindowLayout layout;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
22 private readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
23 private string loadedFilePath;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
24 private CommandStack commandStack;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
25 private QFileDialog saveArmyDialog;
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
26
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
27 public MainWindow ()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
28 {
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
29 layout = new Ui_MainWindowLayout();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
30 layout.SetupUi(this);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
31 WindowIcon = new QIcon("icons/App.png");
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
32 SetAppTitle();
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
33 saveArmyDialog = new QFileDialog(this);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
34 saveArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptSave;
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
35 SetUpActionIcons();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
36 ConnectMenuActions();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
37 SetUpToolbar();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
38 layout.unitTabs.Clear();
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
39 WarFoundryCore.ArmyChanged+= HandleWarFoundryCoreArmyChanged;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
40 CommandStack.CommandStackUpdated+= HandleCommandStackCommandStackUpdated;
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
41 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
42
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
43 private void SetUpActionIcons()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
44 {
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
45 layout.actionCreateArmy.icon = new QIcon("icons/ui/filenew.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
46 layout.actionOpenArmy.icon = new QIcon("icons/ui/fileopen.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
47 layout.actionSaveArmy.icon = new QIcon("icons/ui/filesave.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
48 layout.actionSaveArmyAs.icon = new QIcon("icons/ui/filesaveas.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
49 layout.menuExportArmyAs.icon = new QIcon("icons/ui/export.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
50 layout.actionCloseArmy.icon = new QIcon("icons/ui/window-close.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
51 layout.actionExit.icon = new QIcon("icons/ui/exit.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
52 layout.actionUndo.icon = new QIcon("icons/ui/edit-undo.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
53 layout.actionRedo.icon = new QIcon("icons/ui/edit-redo.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
54 layout.actionAbout.icon = new QIcon("icons/ui/help-about.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
55 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
56
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
57 private void ConnectMenuActions()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
58 {
6
bbf40d66dfe4 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
59 QObject.Connect(layout.actionCreateArmy, SIGNAL("triggered()"), CreateNewArmy);
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
60 QObject.Connect(layout.actionUndo, SIGNAL("triggered()"), UndoAction);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
61 QObject.Connect(layout.actionRedo, SIGNAL("triggered()"), RedoAction);
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
62 QObject.Connect(layout.actionSaveArmyAs, SIGNAL("triggered()"), DoSaveCurrentArmyAs);
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
63 QObject.Connect(layout.actionSaveArmy, SIGNAL("triggered()"), DoSaveCurrentArmy);
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
64 QObject.Connect(layout.actionCloseArmy, SIGNAL("triggered()"), CloseArmy);
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
65 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
66
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
67 private void CreateNewArmy()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
68 {
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
69 NewArmyDialog dialog = new NewArmyDialog(this);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
70 int result = dialog.Exec ();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
71
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
72 if (result == (int)QDialog.DialogCode.Accepted)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
73 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
74 try
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
75 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
76 CurrentArmy = new Army(dialog.GetSelectedRace(), dialog.GetArmyName(), dialog.GetArmySize());
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
77 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
78 catch (RequiredDataMissingException ex)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
79 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
80 log.Error("Required data missing from race file", ex);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
81 QMessageBox.Warning(this, "Invalid race file data", "the race file for the requested data could not be loaded as it did not contain some required data");
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
82 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
83 catch (InvalidFileException ex)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
84 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
85 log.Error("Race file was invalid", ex);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
86 QMessageBox.Warning(this, ex.Message, "invalid race file");
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
87 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
88 }
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
89 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
90
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
91 private void SetUpToolbar()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
92 {
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
93 List<QAction> actions = new List<QAction>(){
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
94 layout.actionCreateArmy,
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
95 layout.actionOpenArmy,
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
96 layout.actionSaveArmy};
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
97 layout.toolBar.AddActions(actions);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
98 layout.toolBar.AddSeparator();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
99 layout.toolBar.AddAction(layout.actionUndo);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
100 layout.toolBar.AddAction(layout.actionRedo);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
101 layout.toolBar.AddSeparator();
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
102 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
103
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
104 private void HandleWarFoundryCoreArmyChanged(Army oldValue, Army newValue)
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
105 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
106 CommandStack.Reset();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
107 loadedFilePath = null;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
108 layout.actionSaveArmy.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
109 SetPointsPanelText();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
110 SetAppTitle();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
111 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
112
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
113 private void SetPointsPanelText ()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
114 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
115 //TODO: implement panel and points panel
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
116 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
117
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
118
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
119 private void SetAppTitle()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
120 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
121 string str = AppTitle;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
122
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
123 if (CurrentGameSystem!=null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
124 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
125 str+= " - " + CurrentGameSystem.Name;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
126
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
127 if (CurrentArmy!=null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
128 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
129 str+= " - " + CurrentArmy.Name;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
130 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
131 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
132
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
133 this.WindowTitle = str;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
134 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
135
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
136 public CommandStack CommandStack
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
137 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
138 get
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
139 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
140 if (commandStack == null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
141 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
142 commandStack = new CommandStack();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
143 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
144
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
145 return commandStack;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
146 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
147 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
148
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
149 private void HandleCommandStackCommandStackUpdated()
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
150 {
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
151 layout.actionSaveArmy.Enabled = CommandStack.IsDirty();
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
152 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
153
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
154 private void UndoAction()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
155 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
156 if (commandStack.CanUndo())
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
157 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
158 commandStack.Undo();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
159 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
160 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
161
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
162 private void RedoAction()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
163 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
164 if (commandStack.CanRedo())
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
165 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
166 commandStack.Redo();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
167 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
168 }
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
169
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
170 private void DoSaveCurrentArmy()
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
171 {
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
172 SaveCurrentArmy();
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
173 }
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
174
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
175 private bool SaveCurrentArmy()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
176 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
177 bool saved = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
178
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
179 string filePath = loadedFilePath;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
180
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
181 if (filePath == null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
182 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
183 filePath = PromptForArmyFilePath();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
184 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
185
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
186 if (filePath != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
187 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
188 saved = SaveCurrentArmyToFile(filePath);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
189 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
190
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
191 return saved;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
192 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
193
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
194 private void DoSaveCurrentArmyAs()
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
195 {
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
196 SaveCurrentArmyAs();
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
197 }
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
198
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
199 private bool SaveCurrentArmyAs()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
200 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
201 bool saved = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
202 string filePath = PromptForArmyFilePath();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
203
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
204 if (filePath != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
205 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
206 saved = SaveCurrentArmyToFile(filePath);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
207 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
208
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
209 return saved;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
210 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
211
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
212 private bool SaveCurrentArmyToFile(string filePath)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
213 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
214 if (WarFoundrySaver.GetSaver().Save(CurrentArmy, filePath))
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
215 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
216 loadedFilePath = filePath;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
217 layout.actionSaveArmy.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
218 CommandStack.setCleanMark();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
219 return true;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
220 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
221 else
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
222 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
223 QMessageBox.Critical(this, "file save failed", "file save failed - check log for details");
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
224 return false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
225 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
226 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
227
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
228 private string PromptForArmyFilePath()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
229 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
230 int result = saveArmyDialog.Exec();
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
231 string path = null;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
232
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
233 if (result == (int)QDialog.DialogCode.Accepted)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
234 {
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
235 path = saveArmyDialog.SelectedFiles()[0];
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
236 }
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
237
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
238 return path;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
239 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
240
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
241 public GameSystem CurrentGameSystem
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
242 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
243 get { return WarFoundryCore.CurrentGameSystem; }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
244 set { WarFoundryCore.CurrentGameSystem = value; }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
245 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
246
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
247 public Army CurrentArmy
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
248 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
249 get { return WarFoundryCore.CurrentArmy; }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
250 set { SetArmy(value); }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
251 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
252
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
253 private void SetArmy(Army newArmy)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
254 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
255 IgnoreArmy(CurrentArmy);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
256 CloseAllUnitWindows();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
257
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
258 if (newArmy == null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
259 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
260 SetNullArmyState();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
261 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
262 else
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
263 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
264 WarFoundryCore.CurrentGameSystem = newArmy.GameSystem;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
265 ListenToArmy(newArmy);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
266 SetNonNullArmyState(newArmy);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
267 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
268
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
269 WarFoundryCore.CurrentArmy = newArmy;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
270 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
271
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
272 private void IgnoreArmy(Army oldArmy)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
273 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
274 if (oldArmy != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
275 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
276 oldArmy.UnitAdded -= UnitAddedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
277 oldArmy.UnitRemoved -= UnitRemovedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
278 oldArmy.PointsValueChanged -= PointsValueChangedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
279 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
280 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
281 private void UnitAddedMethod(object unitObj)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
282 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
283 if (unitObj is Unit)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
284 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
285 Unit unit = (Unit)unitObj;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
286 //TODO set error panel
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
287 //sbErrorPanel.Text = "";
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
288 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
289 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
290
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
291 private void UnitRemovedMethod(object unitObj)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
292 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
293 if (unitObj is Unit)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
294 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
295 Unit unit = (Unit)unitObj;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
296 //TODO set error panel
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
297 //sbErrorPanel.Text = "";
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
298
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
299 //TODO check if window is open, and close it if it is
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
300
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
301 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
302 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
303
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
304 private void PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
305 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
306 if (obj is Army)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
307 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
308 SetPointsPanelText();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
309 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
310 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
311
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
312 private void CloseAllUnitWindows()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
313 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
314 // FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
315 //
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
316 // foreach (FrmUnit window in unitForms)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
317 // {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
318 // window.Close();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
319 // }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
320 //
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
321 // unitWindows.Clear();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
322 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
323
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
324 private void ListenToArmy(Army newArmy)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
325 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
326 if (newArmy != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
327 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
328 newArmy.UnitAdded += UnitAddedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
329 newArmy.UnitRemoved += UnitRemovedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
330 newArmy.PointsValueChanged += PointsValueChangedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
331 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
332 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
333
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
334 private void SetNullArmyState()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
335 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
336 layout.actionSaveArmyAs.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
337 layout.actionCloseArmy.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
338 layout.menuExportArmyAs.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
339 DisableCategoryButtons();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
340 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
341
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
342 void DisableCategoryButtons ()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
343 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
344 //TODO handle category buttons
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
345 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
346
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
347
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
348 private void SetNonNullArmyState(Army newArmy)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
349 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
350 SetCategoryButtons(newArmy.Race.Categories);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
351 EnableCategoryButtons();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
352 layout.actionSaveArmyAs.Enabled = true;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
353 layout.actionCloseArmy.Enabled = true;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
354 layout.menuExportArmyAs.Enabled = true;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
355 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
356
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
357 void SetCategoryButtons (Category[] categories)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
358 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
359 //TODO create category buttons
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
360 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
361
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
362 void EnableCategoryButtons ()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
363 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
364 //TODO enable category buttons
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
365 }
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
366
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
367 private void CloseArmy()
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
368 {
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
369 CurrentArmy = null;
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
370 }
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371 }
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
372 }