• 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

Revision31 (tree)
Time2015-03-21 21:26:31
Authorc477

Log Message

ビュー周りの整備(途上) 終了確認

Change Summary

Incremental Difference

--- trunk/core/impl/game/GameImpl.cs (revision 30)
+++ trunk/core/impl/game/GameImpl.cs (revision 31)
@@ -4,6 +4,7 @@
44 using nft.core.schedule;
55 using nft.core;
66 using nft.framework;
7+using nft.util;
78
89 namespace nft.impl.game
910 {
@@ -20,8 +21,12 @@
2021 protected TerrainMapImpl terrains;
2122 protected IPointerHandler activeHandler;
2223 protected ViewCollection views;
24+ protected bool modified;
25+ protected bool closed;
2326
2427 public GameImpl(string name, ITerrainMap map, Calendar cal) {
28+ this.closed = false;
29+ this.modified = true;
2530 if (cal == null) cal = Calendar.ActiveCalendar;
2631 this.name = name;
2732 this.calender = cal;
@@ -53,17 +58,42 @@
5358 }
5459 }
5560
56- public void Close()
61+ public virtual void Close()
5762 {
58- // TODO: GameImpl.Close 実装を追加します。
63+ closed = true;
64+ calender = null;
65+ clock = null;
66+ if (terrains != null) {
67+ terrains.Dispose();
68+ terrains = null;
69+ }
70+ if (views != null) {
71+ views.CloseAll();
72+ views = null;
73+ }
5974 }
6075
76+ public bool ConfirmClose() {
77+ if (Closed) {
78+ return true;
79+ } else if(modified){
80+ string text = I18n.T("GameManager", "Unsaved game data will be lost. Are you sure?");
81+ modified = !UIUtil.ConfirmMessage(text, UIMessageType.warning, UIInformLevel.normal);
82+ }
83+ return !modified;
84+ }
85+
86+ public bool Closed {
87+ get {
88+ return closed;
89+ }
90+ }
91+
6192 public bool Modified
6293 {
6394 get
6495 {
65- // TODO: GameImpl.Modified getter 実装を追加します。
66- return false;
96+ return modified;
6797 }
6898 }
6999
--- trunk/core/impl/view/GameViewPanel.cs (revision 30)
+++ trunk/core/impl/view/GameViewPanel.cs (revision 31)
@@ -49,8 +49,12 @@
4949 }
5050
5151 public void Close() {
52+ if (OnClose != null) OnClose(new ViewEventArgs(this));
5253 this.Dispose();
5354 }
55+
56+ public event ViewEventHandler OnClose;
57+ public event ViewQueryEventHandler QueryClose;
5458 #endregion
5559
5660 void OnTouchPanelScroll(object sender, ScrollEventArgs e) {
@@ -70,9 +74,33 @@
7074 Size szc = builder.ContentSize;
7175 InitScroll(szc, szu);
7276 renderPanel.EventTarget.MouseMove += new MouseEventHandler(EventTarget_MouseMove);
77+ SetupCloseConfirmation();
7378 this.ResumeLayout(false);
7479 }
7580
81+ protected virtual void SetupCloseConfirmation() {
82+ Control c = this;
83+ Form f = null;
84+ while (null == (f = c as Form)) {
85+ c = c.Parent;
86+ if (c == null) return; // 予期せぬ状況
87+ }
88+ f.FormClosing += new FormClosingEventHandler(OnClosing);
89+ }
90+
91+ protected void OnClosing(object sender, FormClosingEventArgs e) {
92+ if (QueryClose != null) {
93+ ViewQueryEventArgs arg = new ViewQueryEventArgs(this);
94+ QueryClose(arg);
95+ e.Cancel = arg.Cancel;
96+ }
97+ }
98+
99+ protected override void Dispose(bool disposing) {
100+ base.Dispose(disposing);
101+ if (OnClose != null) OnClose(new ViewEventArgs(this));
102+ }
103+
76104 #region Designer generated
77105 private TouchPanel touchPanel;
78106 private RenderViewPanel renderPanel;
--- trunk/core/impl/view/GameViewFactory.cs (revision 30)
+++ trunk/core/impl/view/GameViewFactory.cs (revision 31)
@@ -6,6 +6,7 @@
66 using nft.ui.mainframe;
77 using nft.impl.game;
88 using nft.core.geometry;
9+using System.Windows.Forms;
910
1011 namespace nft.impl.view {
1112 public class GameViewFactory : IGameViewFactory {
--- trunk/core/impl/view/ViewController.cs (revision 30)
+++ trunk/core/impl/view/ViewController.cs (revision 31)
@@ -11,6 +11,7 @@
1111 using System.Drawing;
1212
1313 namespace nft.impl.view {
14+ [Obsolete]
1415 public class ViewController {
1516
1617 public static ICommandEntity_Old GetRotateRightCommand(String id){
--- trunk/core/debug/TestGame.cs (revision 30)
+++ trunk/core/debug/TestGame.cs (revision 31)
@@ -14,8 +14,9 @@
1414 namespace nft.debug
1515 {
1616 /// <summary>
17- /// TestGame の概要の説明です。
17+ /// 使われてません
1818 /// </summary>
19+ [Obsolete]
1920 public class TestGame : ICommandEntity_Old
2021 {
2122 static TestGame theInstance;
--- trunk/core/core/game/GameManager.cs (revision 30)
+++ trunk/core/core/game/GameManager.cs (revision 31)
@@ -40,15 +40,21 @@
4040 protected GameManager(MainFrame mainFrame)
4141 {
4242 this.theFrame = mainFrame;
43- theFrame.Closing+=new System.ComponentModel.CancelEventHandler(theFrame_Closing);
4443 theFrame.ActiveViewChanged += new EventHandler<EventArgs>(theFrame_ActiveViewChanged);
4544 }
4645
4746 public IGameMode CurrentMode { get{ return _curMode; } }
4847 public IGame CurrentGame { get{ return _curGame; } }
49- public void SetGame(IGame newgame, IGameMode mode, bool prompt)
48+ [Obsolete]
49+ public void SetGame(IGame newgame, IGameMode mode, bool prompt){}
50+
51+ public void NewGameFromMap(ITerrainMap map, IGameMode mode, bool prompt) {
52+ NewGameFromMap(null, map, Calendar.ActiveCalendar, mode, prompt);
53+ }
54+
55+ public virtual void NewGameFromMap(string name, ITerrainMap map, Calendar cal, IGameMode mode, bool prompt)
5056 {
51- if( _curGame==newgame ) return;
57+ IGame newgame = CreateGame(name, map, cal);
5258 if(_curGame != null)
5359 {
5460 if( prompt )
@@ -63,33 +69,26 @@
6369 _curGame.Start();
6470 }
6571
72+ protected virtual IGame CreateGame(string name, ITerrainMap map, Calendar cal) {
73+ if(name==null || name.Length == 0) name = I18n.T("GameManager", "NewGame");
74+ return new GameImpl(name, map, cal);
75+ }
76+
6677 public event EventHandler ActiveViewChanged;
6778
79+ /// 使われてない.
80+ [Obsolete]
6881 public GameViewPanel ActiveView {
6982 get {
70- GameViewPanel gvp = theFrame.ActiveView as GameViewPanel;
71- if (gvp != null) {
72- //MapViewDrawer drawer = dp.ViewDrawer as MapViewDrawer;
73- return gvp;
83+ if (CurrentGame != null) {
84+ return CurrentGame.Views.ActiveView as GameViewPanel;
7485 } else {
7586 return null;
7687 }
77- throw new NotImplementedException();
7888 }
7989 }
8090
81- public void NewGameFromMap(ITerrainMap map, IGameMode mode, bool prompt) {
82- if (_curGame != null) {
83- if (prompt)
84- if (!ConfirmCloseGame()) return;
85- else
86- _curGame.Close();
87- }
88- _curGame = null;
89- SetGame(new GameImpl(map, Calendar.ActiveCalendar), mode, false);
90- }
91-
92- /// <summary>
91+ /// <summary>
9392 /// Starts a new game
9493 /// </summary>
9594 protected void newGame()
@@ -124,13 +123,7 @@
124123 bool b = true;
125124 if(_curGame!=null && _curGame.Modified)
126125 {
127- string text = I18n.T("Unsaved game data will be lost. Are you sure?");
128- b = UIUtil.ConfirmMessage(text,UIMessageType.warning,UIInformLevel.normal);
129- if( b )
130- {
131- _curGame.Close();
132- _curGame=null;
133- }
126+ b = _curGame.ConfirmClose();
134127 }
135128 return b;
136129 }
@@ -261,10 +254,5 @@
261254 }
262255 }
263256
264- private void theFrame_Closing(object sender, System.ComponentModel.CancelEventArgs e)
265- {
266- e.Cancel = !ConfirmCloseGame();
267- }
268-
269257 }
270258 }
--- trunk/core/core/game/ViewCollection.cs (revision 30)
+++ trunk/core/core/game/ViewCollection.cs (revision 31)
@@ -4,6 +4,7 @@
44 using nft.core.view;
55 using nft.core.geometry;
66 using nft.framework;
7+using System.Windows.Forms;
78
89 namespace nft.core.game {
910 public class ViewCollection : IEnumerable<IView>{
@@ -15,6 +16,8 @@
1516
1617 protected List<IView> views;
1718 protected IGame game;
19+ protected IView current;
20+
1821 public ViewCollection(IGame _game) {
1922 game = _game;
2023 views = new List<IView>();
@@ -28,7 +31,7 @@
2831
2932 public virtual IView ActiveView {
3033 get {
31- return views.Count > 0 ? views[0] : null;
34+ return current;
3235 }
3336 set {
3437 if (value != null) {
@@ -37,9 +40,21 @@
3740 }
3841 }
3942
43+ public virtual IView PrimaryView {
44+ get {
45+ return views.Count>0 ? views[0] : null;
46+ }
47+ /*
48+ set {
49+ throw new NotImplementedException();
50+ }
51+ */
52+ }
53+
4054 public IView OpenNew() {
4155 IView v = CreateView();
4256 if (Add(v)) {
57+ SetActive(v);
4358 return v;
4459 }else{
4560 v.Close();
@@ -56,7 +71,7 @@
5671
5772 #region protected methods for override
5873 protected virtual bool Add(IView v) {
59- SetActive(v);
74+ views.Add(v);
6075 return true;
6176 }
6277
@@ -66,14 +81,35 @@
6681
6782 protected virtual void SetActive(IView v) {
6883 if (views.Contains(v)) {
69- views.Remove(v);
84+ current = v;
85+ } else {
86+ throw new InvalidOperationException("The view is not a member of collection.");
7087 }
71- views.Insert(0, v);
7288 }
7389
7490 protected virtual IView CreateView() {
75- return ViewFactory.Create(game, Location.UNPLACED);
91+ IView v = ViewFactory.Create(game, Location.UNPLACED);
92+ v.OnClose += new ViewEventHandler(OnViewClose);
93+ v.QueryClose += new ViewQueryEventHandler(QueryViewClose);
94+ return v;
7695 }
96+
97+ protected virtual void OnViewClose(ViewEventArgs ea) {
98+ IView v = ea.View;
99+ v.OnClose -= new ViewEventHandler(OnViewClose);
100+ v.QueryClose -= new ViewQueryEventHandler(OnViewClose);
101+ if (PrimaryView == v && !game.Closed) {
102+ game.Close();
103+ }
104+ Remove(v);
105+ }
106+
107+ protected virtual void QueryViewClose(ViewQueryEventArgs ea) {
108+ IView v = ea.View;
109+ if (PrimaryView == v) {
110+ ea.Cancel = !game.ConfirmClose();
111+ }
112+ }
77113 #endregion
78114
79115 #region IEnumerable implementation
--- trunk/core/core/game/IGame.cs (revision 30)
+++ trunk/core/core/game/IGame.cs (revision 31)
@@ -14,6 +14,7 @@
1414 {
1515 void Start();
1616 void Close();
17+ bool Closed {get;}
1718 // if false, no need to save the game.
1819 bool Modified {get;}
1920 Clock Clock {get;}
@@ -22,5 +23,7 @@
2223 IPointerHandler ActiveController {get; set;}
2324 //World world {get;}
2425 ViewCollection Views {get;}
25- }
26+ //Return if prepare for close the game.
27+ bool ConfirmClose();
28+ }
2629 }
--- trunk/core/core/view/IView.cs (revision 30)
+++ trunk/core/core/view/IView.cs (revision 31)
@@ -5,7 +5,12 @@
55 using nft.core.geometry;
66
77 namespace nft.core.view {
8+ public delegate void ViewEventHandler(ViewEventArgs ea);
9+ public delegate void ViewQueryEventHandler(ViewQueryEventArgs ea);
810 public interface IView {
11+ event ViewEventHandler OnClose;
12+ event ViewQueryEventHandler QueryClose;
13+
914 SceneBuilder SceneBuilder {
1015 get;
1116 }
@@ -17,4 +22,18 @@
1722
1823 void Close();
1924 }
25+
26+ public class ViewEventArgs : EventArgs {
27+ public readonly IView View;
28+ public ViewEventArgs(IView v) {
29+ View = v;
30+ }
31+ }
32+
33+ public class ViewQueryEventArgs : ViewEventArgs {
34+ public bool Cancel;
35+ public ViewQueryEventArgs(IView v): base(v) {
36+ Cancel = false;
37+ }
38+ }
2039 }