annotate MainWindow.cs @ 26:55d4f16c982b

Fixes #250: QtSharp app doesn't always quit properly * Override Close event to dispose of file dialogs (open and save) * Remove unnecessary event handler hooked to close * Change app initialisation to match pattern used by Synapse * Create file dialogs without specifying "this" as parent - seems to be main fix, for some reason.
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Jul 2010 16:03:14 +0000
parents 9641addafffe
children 5ee15def17e7
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;
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
5 using System.IO;
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using Qyoto;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
8 using log4net;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
9 using IBBoard.Commands;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
10 using IBBoard.IO;
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
11 using IBBoard.Lang;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
12 using IBBoard.WarFoundry.API;
21
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
13 using IBBoard.WarFoundry.API.Exporters;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
14 using IBBoard.WarFoundry.API.Factories;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
15 using IBBoard.WarFoundry.API.Objects;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
16 using IBBoard.WarFoundry.API.Savers;
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
18 namespace IBBoard.WarFoundry.GUI.QtSharp
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
20 public class MainWindow : QMainWindow
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
22 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
23
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
24 private Ui_MainWindowLayout layout;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
25 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
26 private string loadedFilePath;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
27 private CommandStack commandStack;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
28 private QFileDialog saveArmyDialog;
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
29 private QFileDialog openArmyDialog;
20
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
30 private Preferences preferences;
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
31
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
32 public MainWindow ()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
33 {
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
34 layout = new Ui_MainWindowLayout();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
35 layout.SetupUi(this);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
36 WindowIcon = new QIcon("icons/App.png");
20
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
37 Preferences = new Preferences("WarFoundryQt");
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
38
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
39 try
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
40 {
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
41 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
42 }
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
43 catch (TranslationLoadException ex)
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
44 {
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
45 log.Error(ex);
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
46 QMessageBox.Critical(this, "Translation loading failed", ex.Message);
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
47 }
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
48
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
49 SetAppTitle();
26
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
50 saveArmyDialog = new QFileDialog();
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
51 saveArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptSave;
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
52 saveArmyDialog.fileMode = QFileDialog.FileMode.AnyFile;
18
ab016fcda350 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 17
diff changeset
53 saveArmyDialog.SetDirectory(new QDir(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
26
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
54 openArmyDialog = new QFileDialog();
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
55 openArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptOpen;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
56 openArmyDialog.fileMode = QFileDialog.FileMode.ExistingFile;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
57 openArmyDialog.SetNameFilter("*.army");
18
ab016fcda350 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 17
diff changeset
58 openArmyDialog.SetDirectory(new QDir(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
59 SetUpActionIcons();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
60 ConnectMenuActions();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
61 SetUpToolbar();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
62 layout.unitTabs.Clear();
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
63 WarFoundryCore.ArmyChanged+= HandleWarFoundryCoreArmyChanged;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
64 CommandStack.CommandStackUpdated+= HandleCommandStackCommandStackUpdated;
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
26
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
67 protected override void CloseEvent(QCloseEvent arg1)
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
68 {
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
69 base.CloseEvent(arg1);
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
70 saveArmyDialog.Dispose();
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
71 openArmyDialog.Dispose();
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
72 }
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
73
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
74 private void SetUpActionIcons()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
75 {
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
76 layout.actionCreateArmy.icon = new QIcon("icons/ui/filenew.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
77 layout.actionOpenArmy.icon = new QIcon("icons/ui/fileopen.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
78 layout.actionSaveArmy.icon = new QIcon("icons/ui/filesave.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
79 layout.actionSaveArmyAs.icon = new QIcon("icons/ui/filesaveas.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
80 layout.menuExportArmyAs.icon = new QIcon("icons/ui/export.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
81 layout.actionCloseArmy.icon = new QIcon("icons/ui/window-close.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
82 layout.actionExit.icon = new QIcon("icons/ui/exit.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
83 layout.actionUndo.icon = new QIcon("icons/ui/edit-undo.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
84 layout.actionRedo.icon = new QIcon("icons/ui/edit-redo.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
85 layout.actionAbout.icon = new QIcon("icons/ui/help-about.png");
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
86 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
87
16
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
88 private void ConnectMenuActions()
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
89 {
16
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
90 ConnectMenuAction(layout.actionCreateArmy, CreateNewArmy);
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
91 ConnectMenuAction(layout.actionUndo, UndoAction);
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
92 ConnectMenuAction(layout.actionRedo,RedoAction);
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
93 ConnectMenuAction(layout.actionSaveArmyAs, DoSaveCurrentArmyAs);
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
94 ConnectMenuAction(layout.actionSaveArmy, DoSaveCurrentArmy);
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
95 ConnectMenuAction(layout.actionCloseArmy, DoCloseArmy);
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
96 ConnectMenuAction(layout.actionOpenArmy, DoOpenArmy);
21
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
97 ConnectMenuAction(layout.actionExportBasicHtml, DoExportBasicHTML);
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
98 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
99
16
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
100 private void ConnectMenuAction(QAction menuAction, SlotFunc method)
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
101 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
102 QObject.Connect(menuAction, SIGNAL("triggered()"), method);
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
103 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
104
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
105 private void CreateNewArmy()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
106 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
107 if (CloseCurrentArmy())
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
108 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
109 NewArmyDialog dialog = new NewArmyDialog(this);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
110 int result = dialog.Exec ();
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
111
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
112 if (result == (int)QDialog.DialogCode.Accepted)
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
113 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
114 try
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
115 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
116 CurrentArmy = new Army(dialog.GetSelectedRace(), dialog.GetArmyName(), dialog.GetArmySize());
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
117 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
118 catch (RequiredDataMissingException ex)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
119 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
120 log.Error("Required data missing from race file", ex);
17
8f9f757f2099 Re #242: Create Qyoto GUI
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
121 QMessageBox.Critical(this, "Invalid race file data", "the race file for the requested data could not be loaded as it did not contain some required data");
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
122 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
123 catch (InvalidFileException ex)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
124 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
125 log.Error("Race file was invalid", ex);
17
8f9f757f2099 Re #242: Create Qyoto GUI
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
126 QMessageBox.Critical(this, "invalid race file", ex.Message);
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
127 }
10
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 }
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
130 }
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
131
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
132 private void SetUpToolbar()
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
133 {
13
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
134 layout.toolBar.AddAction(layout.actionCreateArmy);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
135 layout.toolBar.AddAction(layout.actionOpenArmy);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
136 layout.toolBar.AddAction(layout.actionSaveArmy);
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
137 layout.toolBar.AddSeparator();
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
138 layout.toolBar.AddAction(layout.actionUndo);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
139 layout.toolBar.AddAction(layout.actionRedo);
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
140 layout.toolBar.AddSeparator();
10
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
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
143 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
144 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
145 CommandStack.Reset();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
146 loadedFilePath = null;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
147 layout.actionSaveArmy.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
148 SetPointsPanelText();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
149 SetAppTitle();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
150 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
151
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
152 private void SetPointsPanelText ()
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 //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
155 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
156
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 private void SetAppTitle()
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 string str = AppTitle;
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 if (CurrentGameSystem!=null)
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 str+= " - " + CurrentGameSystem.Name;
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 if (CurrentArmy!=null)
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 str+= " - " + CurrentArmy.Name;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
169 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
170 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
171
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
172 this.WindowTitle = str;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
173 }
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 public CommandStack CommandStack
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 get
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 if (commandStack == null)
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 commandStack = new CommandStack();
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
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
184 return commandStack;
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 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
187
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
188 private void HandleCommandStackCommandStackUpdated()
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
189 {
13
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
190 layout.actionUndo.Enabled = CommandStack.CanUndo();
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
191 layout.actionRedo.Enabled = CommandStack.CanRedo();
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
192 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
193 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
194
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
195 private void UndoAction()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
196 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
197 if (commandStack.CanUndo())
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
198 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
199 commandStack.Undo();
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 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
202
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
203 private void RedoAction()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
204 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
205 if (commandStack.CanRedo())
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
206 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
207 commandStack.Redo();
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 }
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
210
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
211 private void DoOpenArmy()
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
212 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
213 OpenArmy();
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
214 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
215
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
216 private bool OpenArmy()
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
217 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
218 log.Debug("Opening army");
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
219 string newFilePath = PromptForFilePath (openArmyDialog);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
220 bool openedFile = false;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
221
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
222 if (newFilePath != null && CloseCurrentArmy())
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
223 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
224 try
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
225 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
226 log.DebugFormat("Opening {0}", newFilePath);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
227 CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath));
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
228 loadedFilePath = newFilePath;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
229 openedFile = true;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
230 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
231 catch (RequiredDataMissingException ex)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
232 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
233 log.Error(ex);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
234 QMessageBox.Critical(this, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), ex.Message);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
235 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
236 catch (InvalidFileException ex)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
237 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
238 log.Error(ex);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
239 QMessageBox.Critical(this, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), ex.Message);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
240 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
241 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
242
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
243 return openedFile;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
244 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
245
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
246 private void DoSaveCurrentArmy()
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
247 {
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
248 SaveCurrentArmy();
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
249 }
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
250
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
251 private bool SaveCurrentArmy()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
252 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
253 log.Debug("Save current army");
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
254 bool saved = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
255
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
256 string filePath = loadedFilePath;
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 (filePath == 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 filePath = PromptForArmyFilePath();
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
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
263 if (filePath != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
264 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
265 saved = SaveCurrentArmyToFile(filePath);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
266 }
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 return saved;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
269 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
270
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
271 private void DoSaveCurrentArmyAs()
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
272 {
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
273 SaveCurrentArmyAs();
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
274 }
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
275
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
276 private bool SaveCurrentArmyAs()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
277 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
278 log.Debug("Saving current army as a different file");
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
279 bool saved = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
280 string filePath = PromptForArmyFilePath();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
281
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
282 if (filePath != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
283 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
284 saved = SaveCurrentArmyToFile(filePath);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
285 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
286
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
287 return saved;
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 private bool SaveCurrentArmyToFile(string filePath)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
291 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
292 log.DebugFormat("Save to {0}", filePath);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
293
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
294 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
295 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
296 log.Debug("Army saved");
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
297 loadedFilePath = filePath;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
298 layout.actionSaveArmy.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
299 CommandStack.setCleanMark();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
300 return true;
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 else
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
303 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
304 log.Debug("Save failed");
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
305 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
306 return false;
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 }
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 private string PromptForArmyFilePath()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
311 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
312 return PromptForFilePath (saveArmyDialog);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
313 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
314
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
315 private string PromptForFilePath(QFileDialog qFileDialog)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
316 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
317 int result = qFileDialog.Exec();
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
318 string path = null;
10
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 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
321 {
15
03ed32fdc706 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
322 path = qFileDialog.SelectedFiles()[0];
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
323 }
11
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
324
72bcf6457227 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
325 return path;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
326 }
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 public GameSystem CurrentGameSystem
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
329 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
330 get { return WarFoundryCore.CurrentGameSystem; }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
331 set { WarFoundryCore.CurrentGameSystem = value; }
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 public Army CurrentArmy
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 get { return WarFoundryCore.CurrentArmy; }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
337 set { SetArmy(value); }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
338 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
339
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
340 private void SetArmy(Army newArmy)
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 IgnoreArmy(CurrentArmy);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
343 CloseAllUnitWindows();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
344
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
345 if (newArmy == null)
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 SetNullArmyState();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
348 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
349 else
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
350 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
351 WarFoundryCore.CurrentGameSystem = newArmy.GameSystem;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
352 ListenToArmy(newArmy);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
353 SetNonNullArmyState(newArmy);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
354 }
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 WarFoundryCore.CurrentArmy = newArmy;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
357 }
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 private void IgnoreArmy(Army oldArmy)
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 if (oldArmy != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
362 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
363 oldArmy.UnitAdded -= UnitAddedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
364 oldArmy.UnitRemoved -= UnitRemovedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
365 oldArmy.PointsValueChanged -= PointsValueChangedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
366 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
367 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
368 private void UnitAddedMethod(object unitObj)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
369 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
370 if (unitObj is Unit)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
371 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
372 Unit unit = (Unit)unitObj;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
373 //TODO set error panel
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
374 //sbErrorPanel.Text = "";
13
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
375 //TODO add unit to tree
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
376 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
377 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
378
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
379 private void UnitRemovedMethod(object unitObj)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
380 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
381 if (unitObj is Unit)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
382 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
383 Unit unit = (Unit)unitObj;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
384 //TODO set error panel
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
385 //sbErrorPanel.Text = "";
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
386
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
387 //TODO check if window is open, and close it if it is
13
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
388 //TODO remove unit from tree
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
389 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
390 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
391
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
392 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
393 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
394 if (obj is Army)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
395 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
396 SetPointsPanelText();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
397 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
398 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
399
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
400 private void CloseAllUnitWindows()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
401 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
402 // FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
403 //
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
404 // foreach (FrmUnit window in unitForms)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
405 // {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
406 // window.Close();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
407 // }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
408 //
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
409 // unitWindows.Clear();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
410 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
411
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
412 private void ListenToArmy(Army newArmy)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
413 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
414 if (newArmy != null)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
415 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
416 newArmy.UnitAdded += UnitAddedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
417 newArmy.UnitRemoved += UnitRemovedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
418 newArmy.PointsValueChanged += PointsValueChangedMethod;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
419 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
420 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
421
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
422 private void SetNullArmyState()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
423 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
424 layout.actionSaveArmyAs.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
425 layout.actionCloseArmy.Enabled = false;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
426 layout.menuExportArmyAs.Enabled = false;
21
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
427
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
428 foreach (QAction exportAction in layout.menuExportArmyAs.Actions())
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
429 {
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
430 exportAction.Enabled = false;
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
431 }
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
432
13
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
433 layout.armyTree.SetModel(new QStandardItemModel());
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
434 DisableCategoryButtons();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
435 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
436
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
437 void DisableCategoryButtons ()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
438 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
439 //TODO handle category buttons
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
440 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
441
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
442
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
443 private void SetNonNullArmyState(Army newArmy)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
444 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
445 SetCategoryButtons(newArmy.Race.Categories);
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
446 EnableCategoryButtons();
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
447 layout.actionSaveArmyAs.Enabled = true;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
448 layout.actionCloseArmy.Enabled = true;
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
449 layout.menuExportArmyAs.Enabled = true;
21
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
450
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
451 foreach (QAction exportAction in layout.menuExportArmyAs.Actions())
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
452 {
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
453 exportAction.Enabled = true;
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
454 }
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
455
13
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
456 FillArmyTree(newArmy);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
457 }
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
458
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
459 private void FillArmyTree (Army army)
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
460 {
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
461 QStandardItemModel treeModel = new QStandardItemModel();
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
462 List<string> headers = new List<string>();
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
463 headers.Add(army.Name);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
464 treeModel.SetHorizontalHeaderLabels(headers);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
465
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
466 foreach (var category in army.Categories)
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
467 {
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
468 QStandardItem item = CreateTreeItem(category);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
469 treeModel.AppendRow(item);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
470 CreateUnitNodes(category, item);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
471 }
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
472
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
473 layout.armyTree.SetModel(treeModel);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
474 }
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
475
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
476 private QStandardItem CreateTreeItem(WarFoundryObject obj)
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
477 {
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
478 QVariant wrappedObject = QVariant.FromValue<WarFoundryObject>(obj);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
479 QStandardItem item = new QStandardItem(obj.Name);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
480 item.SetData(wrappedObject);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
481 return item;
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
482 }
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
483
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
484 private void CreateUnitNodes(ArmyCategory category, QStandardItem categoryItem)
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
485 {
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
486 foreach (Unit unit in category.GetUnits())
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
487 {
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
488 CreateTreeSubItem(unit, categoryItem);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
489 }
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
490 }
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
491
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
492 private QStandardItem CreateTreeSubItem(WarFoundryObject obj, QStandardItem rootItem)
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
493 {
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
494 QStandardItem item = CreateTreeItem(obj);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
495 rootItem.AppendRow(item);
dbe784f0802c Re #246: Create army tree implementation
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
496 return item;
10
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
497 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
498
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
499 void SetCategoryButtons (Category[] categories)
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
500 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
501 //TODO create category buttons
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
502 }
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
503
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
504 void EnableCategoryButtons ()
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
505 {
3d0c9cf1b924 Fixes #243: Create "New Army" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
506 //TODO enable category buttons
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
507 }
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
508
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
509 private void DoCloseArmy()
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
510 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
511 CloseCurrentArmy();
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
512 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
513
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
514 private bool CloseCurrentArmy()
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
515 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
516 bool closed = false;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
517
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
518 if (CurrentArmy!=null)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
519 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
520 log.Debug("Closing "+CurrentArmy.Name);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
521 bool canClose = false;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
522
16
d211d01efa44 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
523 if (CommandStack.IsDirty())
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
524 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
525 log.Debug("Unsaved changes");
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
526 string saveChanges = Translation.GetTranslation("SaveChangesQuestion", "the army \"{0}\" has been modified\r\nsave changes before closing army?", CurrentArmy.Name);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
527 string saveChangesTitle = Translation.GetTranslation("SaveChangesTitle", "unsaved changes");
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
528 QMessageBox.StandardButton response = QMessageBox.Question(this, saveChangesTitle, saveChanges, (uint) (QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel), QMessageBox.StandardButton.Cancel);
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
529
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
530 if (response == QMessageBox.StandardButton.Yes)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
531 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
532 canClose = SaveCurrentArmy();
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
533 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
534 else if (response == QMessageBox.StandardButton.No)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
535 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
536 log.Debug("User didn't save army");
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
537 canClose = true;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
538 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
539 //else they said cancel and we default to "canClose = false" so do nothing
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
540 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
541 else
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
542 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
543 canClose = true;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
544 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
545
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
546 if (canClose)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
547 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
548 CurrentArmy = null;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
549 closed = true;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
550 }
24
9641addafffe Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
551
9641addafffe Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
552 log.Debug("Army "+(closed ? "" : "not")+" closed");
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
553 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
554 else
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
555 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
556 //pretend we succeeded
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
557 closed = true;
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
558 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
559
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
560 return closed;
12
4a724378d66a Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
561 }
20
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
562
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
563 public Preferences Preferences
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
564 {
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
565 get { return preferences; }
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
566 set { preferences = value; }
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
567 }
21
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
568
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
569 private void DoExportBasicHTML()
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
570 {
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
571 log.Debug("Exporting to HTML");
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
572 QFileDialog fileDialog = new QFileDialog(this);
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
573 fileDialog.acceptMode = QFileDialog.AcceptMode.AcceptSave;
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
574 fileDialog.fileMode = QFileDialog.FileMode.AnyFile;
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
575 fileDialog.SetDirectory(new QDir(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
576 log.Debug("Requesting export path");
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
577 int result = fileDialog.Exec();
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
578
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
579 if (result == (int)QDialog.DialogCode.Accepted)
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
580 {
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
581 string path = fileDialog.SelectedFiles()[0];
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
582 log.DebugFormat("Exporting to {0}", path);
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
583 WarFoundryHtmlExporter.GetDefault().ExportArmy(CurrentArmy, path);
24
9641addafffe Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 21
diff changeset
584 log.Debug("Exported");
21
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
585 }
d6e95d51b9a4 Re #247: Implement menu options in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
586 }
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 }
3
ac1bf60edf63 Re #242: Qt# UI
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
588 }