annotate Main.cs @ 32:e405b43a405b

Re #302: Handle units being added to army * Switch to a method that matches WinForms - cache objects in a dictionary rather than searching for them, since we can then work by object instead of relying on unit name Also: * Minor code clean-up
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Aug 2010 13:39:35 +0000
parents 55d4f16c982b
children
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 (Main.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;
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
5 using System.IO;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
6 using System.Collections.Generic;
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using Qyoto;
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
8 using log4net;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
9 using IBBoard;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
10 using IBBoard.WarFoundry.API;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
11 using IBBoard.WarFoundry.API.Factories.Xml;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
12 using IBBoard.WarFoundry.API.Savers;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
13
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 namespace IBBoard.WarFoundry.GUI.QtSharp
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 class MainClass
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
18 private static ILog logger = LogManager.GetLogger(typeof(MainClass));
23
d1259ec9d089 Re #250:
IBBoard <dev@ibboard.co.uk>
parents: 22
diff changeset
19 static QApplication app;
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
20
22
ff011053ec3f Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
21 public static void Main(string[] args)
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 {
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
23 try
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
24 {
22
ff011053ec3f Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
25 logger.InfoFormat("Starting application with args: {0}", args.ToString());
26
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
26 app = new QApplication(args, true);
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
27 app.QuitOnLastWindowClosed = true;
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
28 logger.Debug("Starting exec");
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
29 QApplication.Invoke(delegate
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
30 {
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
31 SetUpWarFoundryEnvironment();
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
32
26
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
33 MainWindow win = new MainWindow();
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
34 win.Show();
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
35 QApplication.SetActiveWindow(win);
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
36 });
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
37 int result = QApplication.Exec();
55d4f16c982b Fixes #250: QtSharp app doesn't always quit properly
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
38 logger.InfoFormat("Closing application - exit code {0}", result);
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
39 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
40 catch(Exception ex)
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
41 {
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
42 logger.Fatal(ex);
20
f1be1b509134 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
43 QMessageBox.Critical(null, "Unhandled exception", ex.Message+"\n\nPlease see log for more details");
14
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
44 }
61bc9b44a695 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
45
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
47
22
ff011053ec3f Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
48 private static void SetUpWarFoundryEnvironment()
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
49 {
22
ff011053ec3f Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
50 logger.Debug("Creating application environment");
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
51 //FIXME: Temporary hack to add paths and factories before we get preferences and plugins
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
52 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Path.Combine(Constants.ExecutablePath, "data")));
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
53 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
54 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
55 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
56 }
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
57
22
ff011053ec3f Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
58 private static void FileLoadingFinished(List<FileLoadFailure> failures)
5
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
59 {
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
60 foreach(FileLoadFailure failure in failures)
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
61 {
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
62 logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
63 }
1bd8febee385 Re #242: Create Qt# UI for WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
64 }
0
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 }
620c62ba4d07 Re #242: Qt# GUI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }