• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

FreeTrainの進化系を目指す


Commit MetaInfo

Revision43 (tree)
Time2016-05-09 00:32:10
Authorc477

Log Message

MainFrameを置き換えやすくするため、MainクラスをApplicationContextに変更

Change Summary

Incremental Difference

--- trunk/starter/Starter.cs (revision 42)
+++ trunk/starter/Starter.cs (revision 43)
@@ -35,7 +35,7 @@
3535
3636 private static void run( string[] args ) {
3737 // start the game
38- Application.Run(new MainFrame(args));
38+ Application.Run(new Main(args));
3939 }
4040
4141
--- trunk/framework/framework/Main.cs (revision 42)
+++ trunk/framework/framework/Main.cs (revision 43)
@@ -20,101 +20,100 @@
2020 /// <summary>
2121 /// Entry point to other static instances in the NeoFreeTrain framework.
2222 /// </summary>
23- public sealed class Main
24- {
25- // no instantiation
26- private Main() {}
23+ // [参考] https://msdn.microsoft.com/ja-jp/library/system.windows.forms.applicationcontext(v=vs.110).aspx
24+ public sealed class Main : ApplicationContext {
25+
26+ public Main(string[] args) {
27+ I18n.LoadFile(Directories.AppBaseDir + "nftfw.resource.xml");
2728
28- /// <summary> the main window frame </summary>
29- private static MainFrame theFrame;
30- public static IBarHostFrame mainFrame
31- { get{ return theFrame; } }
29+ theFrame = CreateFrame();
3230
33- /// <summary> Main resources. </summary>
31+ // Handle the ApplicationExit event to know when the application is exiting.
32+ Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
33+
34+ InitDirectoriesAndAssemblies(args);
35+
36+ using (Splash s = new Splash()) {
37+ s.Show();
38+ ProgressMonitor monitor = CreateProgressMonitor(new ProgressHandler(s.updateMessage));
39+ InitPlugins(monitor);
40+ }
41+
42+ FireInitCompleteEvent();
43+ }
44+
45+ /// <summary> the main window frame </summary>
46+ private static IBarHostFrame theFrame;
47+ public static IBarHostFrame mainFrame { get { return theFrame; } }
48+
49+ private EventHandler InitComplete;
50+
51+ /// <summary> Main resources. </summary>
3452 //public static readonly NftProperties resources = NftProperties.LoadFromFile(Directories.AppBaseDir + "nftfw.resource.xml", false);
3553
36- /// <summary> Plug-ins. </summary>
37- public static readonly PluginManager pluginManager = new PluginManager();
54+ /// <summary> Plug-ins. </summary>
55+ public static readonly PluginManager pluginManager = new PluginManager();
3856
39- #region sound and BGM
40-/*
41- /// <summary>
42- /// Handles BGM playback.
43- /// Should be instanciated by attaching the main window.
44- /// </summary>
45- public static BGMManager bgmManager { get { return _bgmManager; } }
57+ // Exit entire application.
58+ public void Exit() {
59+ ExitThread();
60+ }
4661
47- /// <summary>
48- /// Handles SFX.
49- /// Should be instanciated by attaching the main window.
50- /// </summary>
51- public static SoundEffectManager soundEffectManager { get { return _soundEffectManager; } }
52-
62+ private IBarHostFrame CreateFrame() {
63+ MainFrame frame = new MainFrame(null);
64+ frame.FormClosed += delegate(object o, FormClosedEventArgs arg) {
65+ Exit();
66+ };
67+
68+ InitComplete += delegate(object o, EventArgs arg){
69+ frame.Show();
70+ };
71+ return frame;
72+ }
5373
54- private static SoundEffectManager _soundEffectManager;
55- private static BGMManager _bgmManager;
56-*/
57- #endregion
58-
59- /// <summary>
60- /// Initializes the framework.
61- /// Should be called once and only once.
62- /// </summary>
63- /// <param name="additionalPluginDirs">
64- /// additional directories from which plug-ins are loaded.
65- /// </param>
66- /// <param name="owner">application's main window.</param>
67- /// <param name="bgmMenuItem">"BGM" sub-menu</param>
68- /// <param name="progressHandler">
69- /// Receives initializtion progress report. Can be null.
70- /// </param>
71- public static void init( string[] args, MainFrame frame )
72- {
73- I18n.LoadFile(Directories.AppBaseDir + "nftfw.resource.xml");
74- Hashtable h_args = paresArgs(args);
74+ private void InitDirectoriesAndAssemblies(string[] args) {
75+ Hashtable h_args = paresArgs(args);
7576 InitializeAssemblies();
7677 Directories.Initialize(h_args);
78+ }
7779
78- //InformationService service = new InformationService();
79- theFrame = frame;
80- // To avoid ReBar trouble, we need to show MainFrame
81- // before Splash window created.
80+ private void InitPlugins(ProgressMonitor monitor) {
81+ new FiberSample().Test();
8282
83- using(Splash s = new Splash())
84- {
85- s.Show();
86- new FiberSample().Test();
87- ProgressMonitor monitor = new ProgressMonitor(2);
88- monitor.SetMaximum(1,5);
89- monitor.OnProgress += new ProgressHandler(s.updateMessage);
90- Application.DoEvents();
91- // load global modules;
92- GlobalModules.Initialize();
93- // load plug-ins
94- Main.pluginManager.init(new string[]{Directories.PluginDir}, monitor);
95- }
83+ Application.DoEvents();
84+ // load global modules;
85+ GlobalModules.Initialize();
86+ // load plug-ins
87+ Main.pluginManager.init(new string[] { Directories.PluginDir }, monitor);
88+ }
9689
97- //new PluginListDialog().ShowDialog();
90+ private void OnApplicationExit(object sender, EventArgs e) {
91+ Debug.WriteLine("## Application Exit ##");
92+ }
9893
99-
100-// _soundEffectManager = new SoundEffectManager(owner);
101-// _bgmManager = new BGMManager(bgmMenuItem);
102- }
94+ private ProgressMonitor CreateProgressMonitor(ProgressHandler progressHandler) {
95+ ProgressMonitor monitor = new ProgressMonitor(2);
96+ monitor.SetMaximum(1, 5);
97+ if (progressHandler != null) monitor.OnProgress += progressHandler;
98+ return monitor;
99+ }
103100
104- private static Hashtable paresArgs(string[] args)
105- {
106- Hashtable table = new Hashtable();
107- for(int i=0;i<args.Length;i++)
108- {
109- string[] v = args[i].Split(new char[]{'='},2);
110- if(v.Length==2)
111- table.Add(v[0].ToUpper(),v[1]);
112- else
113- table.Add(v[0].ToUpper(),string.Empty);
114- }
115- return table;
116- }
101+ private static Hashtable paresArgs(string[] args) {
102+ Hashtable table = new Hashtable();
103+ for (int i = 0; i < args.Length; i++) {
104+ string[] v = args[i].Split(new char[] { '=' }, 2);
105+ if (v.Length == 2)
106+ table.Add(v[0].ToUpper(), v[1]);
107+ else
108+ table.Add(v[0].ToUpper(), string.Empty);
109+ }
110+ return table;
111+ }
117112
113+ private void FireInitCompleteEvent() {
114+ if (InitComplete != null) InitComplete(this, new EventArgs());
115+ }
116+
118117 private static void InitializeAssemblies() {
119118 AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(AssemblyInitializer);
120119 Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
@@ -125,14 +124,15 @@
125124
126125 private static void AssemblyInitializer(object sender, AssemblyLoadEventArgs args) {
127126 Assembly asm = args.LoadedAssembly;
128- if (asm.GlobalAssemblyCache)
127+ if (asm.GlobalAssemblyCache)
129128 return;
130129 // force static constructors in types specified by InitializeOnLoad
131130 object[] attributes = asm.GetCustomAttributes(typeof(InitializeOnLoadAttribute), false);
132131 foreach (InitializeOnLoadAttribute attr in attributes) {
133132 System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(attr.Type.TypeHandle);
134- Debug.WriteLine("Init class on load assembly: class="+attr.Type.FullName+ ", module="+ Path.GetFileName(asm.CodeBase));
133+ Debug.WriteLine("Init class on load assembly: class=" + attr.Type.FullName + ", module=" + Path.GetFileName(asm.CodeBase));
135134 }
136135 }
136+
137137 }
138138 }
--- trunk/framework/ui/mainframe/MainFrame.cs (revision 42)
+++ trunk/framework/ui/mainframe/MainFrame.cs (revision 43)
@@ -57,8 +57,7 @@
5757 Debug.WriteLine(", b2="+GC.GetGeneration(b2));
5858 }
5959 */
60- Main.init(args, this);
61- Show();
60+
6261 }
6362
6463 void MainFrame_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
@@ -389,7 +388,11 @@
389388 public void SetStatusText(string txt) {
390389 messageLabel.Text = txt;
391390 }
392- #endregion
393391
394- }
392+ public IToolWindowsManager ToolWindows {
393+ get { return toolWindowsManager; }
394+ }
395+ #endregion
396+
397+ }
395398 }