FreeTrainの進化系を目指す
ビュー周りの整備(途上)
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | ・凹型(interior)/凸型(exterior)に分かれた3Dオブジェクト(線路など用) |
| 2 | -・選択UIの基本、ステータス表示の基本 InputController<-*SitePicker 見た目=skin | |
| 2 | +・選択UIの基本、ステータス表示の基本 IInputHandler-ITargetSelector<-*SitePicker 見た目=skin | |
| 3 | 3 | ・[済]MRT昼夜同時描画/HitTest用マップ |
| 4 | 4 | |
| 5 | 5 | ◎開発メモ |
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | surface = null; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - protected override void DrawCore(ISurfaceOld surfDest, Graphics g, IView owner, Rectangle rctDest, Region requestSrc) { | |
| 25 | + protected override void DrawCore(ISurfaceOld surfDest, Graphics g, IView_old owner, Rectangle rctDest, Region requestSrc) { | |
| 26 | 26 | if (surface != null) { |
| 27 | 27 | IGraphicManagerOld gm = GlobalModules.GraphicManagerOld; |
| 28 | 28 | DrawParams dp = new DrawParams(surfDest, rctDest.Location); |
| @@ -42,7 +42,7 @@ | ||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public override void Attach(IView view) { | |
| 45 | + public override void Attach(IView_old view) { | |
| 46 | 46 | base.Attach(view); |
| 47 | 47 | imgRef.AddRef(); |
| 48 | 48 | if (surface == null) { |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public override void Detach(IView view) { | |
| 54 | + public override void Detach(IView_old view) { | |
| 55 | 55 | base.Detach(view); |
| 56 | 56 | imgRef.ReleaseRef(); |
| 57 | 57 | if (AttachedViewCount == 0) { |
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | <div align="right">cCopyright by <a href="mailto:rc-nao@rocket.ne.jp">C477</a> and <a href="mailto:kk@kohsuke.org"> |
| 17 | 17 | K.Kawaguchi</a> et al, 2002- |
| 18 | 18 | <br> |
| 19 | - <a href="http://www.rocket.ne.jp/%7Enao/">http://www.rocket.ne.jp/~nao</a> | |
| 19 | + <a href="http://sourceforge.jp/users/c477/pf/NeoFT.Workshop/wiki/FrontPage">http://sourceforge.jp/users/c477/pf/NeoFT.Workshop/wiki/FrontPage</a> | |
| 20 | 20 | </div> |
| 21 | 21 | <hr align="left" size="0"> |
| 22 | 22 | <strong>NeoFT</strong> is a free software, many codes and resources are |
| @@ -10,10 +10,11 @@ | ||
| 10 | 10 | /// <summary> |
| 11 | 11 | /// IDrawableView is drawing delegate for DrawablePanel |
| 12 | 12 | /// </summary> |
| 13 | - public interface IViewDrawer : IDisposable{ | |
| 14 | - void Attach(IView view); | |
| 15 | - void Detach(IView view); | |
| 16 | - void Draw(Graphics g, IView owner, Rectangle destArea, Region requestSrc); | |
| 13 | + [Obsolete] | |
| 14 | + public interface IViewDrawer_old : IDisposable{ | |
| 15 | + void Attach(IView_old view); | |
| 16 | + void Detach(IView_old view); | |
| 17 | + void Draw(Graphics g, IView_old owner, Rectangle destArea, Region requestSrc); | |
| 17 | 18 | Size ContentSize { get; } |
| 18 | 19 | Size ScrollUnit { get; } |
| 19 | 20 | } |
| @@ -21,7 +22,8 @@ | ||
| 21 | 22 | /// <summary> |
| 22 | 23 | /// the container of IViewDrawer should implements IView |
| 23 | 24 | /// </summary> |
| 24 | - public interface IView { | |
| 25 | + [Obsolete] | |
| 26 | + public interface IView_old { | |
| 25 | 27 | /// <summary> |
| 26 | 28 | /// visible area of IViewDrawer content on this IView. |
| 27 | 29 | /// </summary> |
| @@ -52,8 +54,8 @@ | ||
| 52 | 54 | /// <summary> |
| 53 | 55 | /// Abstract class of IViewDrawer |
| 54 | 56 | /// </summary> |
| 55 | - public abstract class ViewDrawerBase : IViewDrawer{ | |
| 56 | - protected List<IView> views = new List<IView>(4); | |
| 57 | + public abstract class ViewDrawerBase : IViewDrawer_old{ | |
| 58 | + protected List<IView_old> views = new List<IView_old>(4); | |
| 57 | 59 | protected ISurfaceOld backSurface; |
| 58 | 60 | protected bool doubleBuffered = true; |
| 59 | 61 |
| @@ -62,19 +64,19 @@ | ||
| 62 | 64 | |
| 63 | 65 | public abstract Size ScrollUnit { get; } |
| 64 | 66 | |
| 65 | - public virtual void Attach(IView view) { | |
| 67 | + public virtual void Attach(IView_old view) { | |
| 66 | 68 | if (!views.Contains(view)) { |
| 67 | 69 | views.Add(view); |
| 68 | 70 | } |
| 69 | 71 | } |
| 70 | 72 | |
| 71 | - public virtual void Detach(IView view) { | |
| 73 | + public virtual void Detach(IView_old view) { | |
| 72 | 74 | if (views.Contains(view)) { |
| 73 | 75 | views.Remove(view); |
| 74 | 76 | } |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | - public virtual void Draw(Graphics g, IView owner, Rectangle destArea, Region requestSrc) { | |
| 79 | + public virtual void Draw(Graphics g, IView_old owner, Rectangle destArea, Region requestSrc) { | |
| 78 | 80 | if (DoubleBuffered) { |
| 79 | 81 | if (OffscreenSurface == null) { |
| 80 | 82 | backSurface = PrepareOffscreenSurface(); |
| @@ -109,12 +111,12 @@ | ||
| 109 | 111 | } |
| 110 | 112 | |
| 111 | 113 | protected virtual void NotifyUpdated(Region updateRgn, bool callbackImmediately) { |
| 112 | - foreach (IView vw in views) { | |
| 114 | + foreach (IView_old vw in views) { | |
| 113 | 115 | vw.NotifyUpdate(updateRgn, callbackImmediately); |
| 114 | 116 | } |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | - protected abstract void DrawCore(ISurfaceOld surfDest, Graphics g, IView owner, Rectangle rctDest, Region requestSrc); | |
| 119 | + protected abstract void DrawCore(ISurfaceOld surfDest, Graphics g, IView_old owner, Rectangle rctDest, Region requestSrc); | |
| 118 | 120 | |
| 119 | 121 | public bool DoubleBuffered { |
| 120 | 122 | get { return doubleBuffered; } |
| @@ -0,0 +1,36 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using System.Windows.Forms; | |
| 5 | +using nft.framework.drawing; | |
| 6 | + | |
| 7 | +namespace nft.core.game { | |
| 8 | + public class PointerEventArgs : EventArgs{ | |
| 9 | + protected MouseEventArgs eventOrg; | |
| 10 | + protected IGame game; | |
| 11 | + protected ISurface surface; | |
| 12 | + | |
| 13 | + public PointerEventArgs(IGame gm, ISurface surf) { | |
| 14 | + this.game = gm; | |
| 15 | + this.surface = surf; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public IGame Game { | |
| 19 | + get { | |
| 20 | + return game; | |
| 21 | + } | |
| 22 | + } | |
| 23 | + | |
| 24 | + public ISurface Surface { | |
| 25 | + get { | |
| 26 | + return surface; | |
| 27 | + } | |
| 28 | + } | |
| 29 | + | |
| 30 | + public MouseEventArgs OriginalEventArgs { | |
| 31 | + get { | |
| 32 | + return eventOrg; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + } | |
| 36 | +} |
| @@ -19,6 +19,8 @@ | ||
| 19 | 19 | Clock Clock {get;} |
| 20 | 20 | IClimateController ClimateController {get;} |
| 21 | 21 | string Name {get;set;} |
| 22 | + IPointerHandler ActiveController {get; set;} | |
| 22 | 23 | //World world {get;} |
| 24 | + ViewCollection Views {get;} | |
| 23 | 25 | } |
| 24 | 26 | } |
| @@ -11,6 +11,8 @@ | ||
| 11 | 11 | using nft.framework.drawing; |
| 12 | 12 | using System.Drawing; |
| 13 | 13 | using nft.impl.view; |
| 14 | +using nft.core.view; | |
| 15 | +using nft.core.geometry; | |
| 14 | 16 | |
| 15 | 17 | namespace nft.core.game |
| 16 | 18 | { |
| @@ -57,8 +59,7 @@ | ||
| 57 | 59 | _curGame = newgame; |
| 58 | 60 | _curMode = mode; |
| 59 | 61 | //theFrame.SetSubTitle( ); |
| 60 | - GameViewPanel f = new GameViewPanel((GameImpl)_curGame); | |
| 61 | - theFrame.AddView(_curGame.Name, f); | |
| 62 | + _curGame.Views.OpenNew(); | |
| 62 | 63 | _curGame.Start(); |
| 63 | 64 | } |
| 64 | 65 |
| @@ -0,0 +1,91 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.core.view; | |
| 5 | +using nft.core.geometry; | |
| 6 | +using nft.framework; | |
| 7 | + | |
| 8 | +namespace nft.core.game { | |
| 9 | + public class ViewCollection : IEnumerable<IView>{ | |
| 10 | + static protected IGameViewFactory ViewFactory { | |
| 11 | + get { | |
| 12 | + return GlobalModules.GetModule(typeof(IGameViewFactory)) as IGameViewFactory; | |
| 13 | + } | |
| 14 | + } | |
| 15 | + | |
| 16 | + protected List<IView> views; | |
| 17 | + protected IGame game; | |
| 18 | + public ViewCollection(IGame _game) { | |
| 19 | + game = _game; | |
| 20 | + views = new List<IView>(); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public IGame Game { | |
| 24 | + get { | |
| 25 | + return game; | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + public virtual IView ActiveView { | |
| 30 | + get { | |
| 31 | + return views.Count > 0 ? views[0] : null; | |
| 32 | + } | |
| 33 | + set { | |
| 34 | + if (value != null) { | |
| 35 | + SetActive(value); | |
| 36 | + } | |
| 37 | + } | |
| 38 | + } | |
| 39 | + | |
| 40 | + public IView OpenNew() { | |
| 41 | + IView v = CreateView(); | |
| 42 | + if (Add(v)) { | |
| 43 | + return v; | |
| 44 | + }else{ | |
| 45 | + v.Close(); | |
| 46 | + return null; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void CloseAll() { | |
| 51 | + foreach (IView v in views) { | |
| 52 | + v.Close(); | |
| 53 | + } | |
| 54 | + views.Clear(); | |
| 55 | + } | |
| 56 | + | |
| 57 | +#region protected methods for override | |
| 58 | + protected virtual bool Add(IView v) { | |
| 59 | + SetActive(v); | |
| 60 | + return true; | |
| 61 | + } | |
| 62 | + | |
| 63 | + protected virtual bool Remove(IView v) { | |
| 64 | + return views.Remove(v); | |
| 65 | + } | |
| 66 | + | |
| 67 | + protected virtual void SetActive(IView v) { | |
| 68 | + if (views.Contains(v)) { | |
| 69 | + views.Remove(v); | |
| 70 | + } | |
| 71 | + views.Insert(0, v); | |
| 72 | + } | |
| 73 | + | |
| 74 | + protected virtual IView CreateView() { | |
| 75 | + return ViewFactory.Create(game, Location.UNPLACED); | |
| 76 | + } | |
| 77 | +#endregion | |
| 78 | + | |
| 79 | + #region IEnumerable implementation | |
| 80 | + public IEnumerator<IView> GetEnumerator() | |
| 81 | + { | |
| 82 | + return views.GetEnumerator(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
| 86 | + { | |
| 87 | + return GetEnumerator(); | |
| 88 | + } | |
| 89 | + #endregion | |
| 90 | + } | |
| 91 | +} |
| @@ -7,10 +7,11 @@ | ||
| 7 | 7 | using nft.framework.drawing; |
| 8 | 8 | |
| 9 | 9 | namespace nft.core.game { |
| 10 | + [Obsolete] | |
| 10 | 11 | public interface IQuarterView { |
| 11 | 12 | ViewFactor ViewFactor { get; } |
| 12 | 13 | Control TargetControl { get; } |
| 13 | - Location GetHitSprite(IView v, Point pt, out object tag); | |
| 14 | + Location GetHitSprite(IView_old v, Point pt, out object tag); | |
| 14 | 15 | /* |
| 15 | 16 | Location ConvertMousePos(IView v, Point pt); |
| 16 | 17 | Location ConvertMousePos(IView v, Point pt, int unitHeight); |
| @@ -0,0 +1,13 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | + | |
| 5 | +namespace nft.core.game { | |
| 6 | + public interface IPointerHandler { | |
| 7 | + void OnAttach(IGame g); | |
| 8 | + void OnDetach(IGame g); | |
| 9 | + void OnMouseButtonDown(PointerEventArgs args); | |
| 10 | + void OnMouseButtonUp(PointerEventArgs args); | |
| 11 | + void OnMouseMove(PointerEventArgs args); | |
| 12 | + } | |
| 13 | +} |
| @@ -0,0 +1,20 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.impl.view; | |
| 5 | +using nft.core.geometry; | |
| 6 | + | |
| 7 | +namespace nft.core.view { | |
| 8 | + public interface IView { | |
| 9 | + SceneBuilder SceneBuilder { | |
| 10 | + get; | |
| 11 | + } | |
| 12 | + | |
| 13 | + InterCardinalDirection UpperDirection { | |
| 14 | + get; | |
| 15 | + set; | |
| 16 | + } | |
| 17 | + | |
| 18 | + void Close(); | |
| 19 | + } | |
| 20 | +} |
| @@ -0,0 +1,13 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.framework; | |
| 5 | +using nft.core.game; | |
| 6 | +using nft.core.geometry; | |
| 7 | + | |
| 8 | +namespace nft.core.view { | |
| 9 | + public interface IGameViewFactory : IGlobalModule{ | |
| 10 | + IView Create(IGame game, Location center); | |
| 11 | + IView Create(IGame game, Location center, int width, int height); | |
| 12 | + } | |
| 13 | +} |
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | this.status = stat; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - EventTypes Status { | |
| 22 | + EventTypes EventType { | |
| 23 | 23 | get { |
| 24 | 24 | return status; |
| 25 | 25 | } |
| @@ -0,0 +1,83 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.core.geometry; | |
| 5 | + | |
| 6 | +namespace nft.core.structure { | |
| 7 | + public class StructureCollection { | |
| 8 | + protected List<Lot> list; | |
| 9 | + | |
| 10 | + public StructureCollection() { | |
| 11 | + } | |
| 12 | + | |
| 13 | + public void Add(Lot l) { | |
| 14 | + list.Add(l); | |
| 15 | + } | |
| 16 | + | |
| 17 | + public void Remove(Lot l) { | |
| 18 | + list.Remove(l); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public List<Lot> GetCollidings(Lot l) { | |
| 22 | + List<Lot> result = new List<Lot>(); | |
| 23 | + foreach (Lot l2 in list) { | |
| 24 | + if (l2 == l) continue; | |
| 25 | + if (l2.IsCollide(l)) { | |
| 26 | + // TODO more detalied evaluations. | |
| 27 | + result.Add(l2); | |
| 28 | + } | |
| 29 | + } | |
| 30 | + return result; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public StructuresEnumerator GetEnumeratorForView(Rect3D region) { | |
| 34 | + return new StructuresEnumerator(this, region); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public class StructuresEnumerator : IEnumerable<Lot> { | |
| 38 | + StructureCollection lots; | |
| 39 | + Rect3D region; | |
| 40 | + internal protected StructuresEnumerator(StructureCollection lots, Rect3D region) { | |
| 41 | + this.lots = lots; | |
| 42 | + this.region = region; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public IEnumerator<Lot> GetEnumerator() { | |
| 46 | + foreach(Lot l in lots.list){ | |
| 47 | + if(region.IsIntersect(l.Bounds)){ | |
| 48 | + yield return l; | |
| 49 | + } | |
| 50 | + } | |
| 51 | + yield break; | |
| 52 | + } | |
| 53 | + | |
| 54 | + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { | |
| 55 | + return GetEnumerator(); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + public class PlanarStructuresEnumerator : IEnumerable<Lot> { | |
| 59 | + StructureCollection lots; | |
| 60 | + Rect3D region; | |
| 61 | + internal protected PlanarStructuresEnumerator(StructureCollection lots, Rect3D region) { | |
| 62 | + this.lots = lots; | |
| 63 | + this.region = region; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public IEnumerator<Lot> GetEnumerator() { | |
| 67 | + foreach (Lot l in lots.list) { | |
| 68 | + Rect3D r3d = l.Bounds; | |
| 69 | + if (region.X>r3d.X2 || region.X2<r3d.X || region.Y>r3d.Y2 || region.Y2<r3d.Y) { | |
| 70 | + continue; // Planar area (x,y) is outside of region | |
| 71 | + } | |
| 72 | + yield return l; | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { | |
| 77 | + return GetEnumerator(); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + | |
| 83 | +} |
| @@ -25,5 +25,21 @@ | ||
| 25 | 25 | public readonly object Category; |
| 26 | 26 | public readonly int Level; |
| 27 | 27 | public readonly Rect3D Bounds; |
| 28 | + | |
| 29 | + public virtual bool IsCollide(Lot other) { | |
| 30 | + return Bounds.IsIntersect(other.Bounds) && other.IsCollideDetail(this); | |
| 31 | + } | |
| 32 | + | |
| 33 | + /// <summary> | |
| 34 | + /// This method will called for advanced collision check, | |
| 35 | + /// and sholud be called ONLY when 'other' collide with the bounds of this lot. | |
| 36 | + /// So the simplest way is 'return true' if inside of this bounds is completely exclusive. | |
| 37 | + /// Or override in inherited class to implement complexed collision check. | |
| 38 | + /// </summary> | |
| 39 | + /// <param name="other"></param> | |
| 40 | + /// <returns></returns> | |
| 41 | + internal protected virtual bool IsCollideDetail(Lot other) { | |
| 42 | + return true; | |
| 43 | + } | |
| 28 | 44 | } |
| 29 | 45 | } |
| @@ -14,6 +14,10 @@ | ||
| 14 | 14 | <class name="nft.ui.WinFormManager" codebase=".UI"/> |
| 15 | 15 | <description>Form Manager based on System.Windows.Forms</description> |
| 16 | 16 | </module> |
| 17 | + <module name="Game View Factory"> | |
| 18 | + <class name="nft.impl.view.GameViewFactory" codebase=".Core"/> | |
| 19 | + <description>Default Game View Factory which produces GameViewPanel (based on System.Windows.Forms)</description> | |
| 20 | + </module> | |
| 17 | 21 | <module name="Game Time Calendar"> |
| 18 | 22 | <class name="nft.core.schedule.Calendar" codebase=".Core"/> |
| 19 | 23 | <description>Calendar For Game World</description> |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | using System.Collections.Generic; |
| 7 | 7 | using ICDir = nft.core.geometry.InterCardinalDirection; |
| 8 | 8 | using ITerrainPiece = nft.core.geometry.ITerrainPiece; |
| 9 | +using nft.core.structure; | |
| 9 | 10 | |
| 10 | 11 | namespace nft.impl.game |
| 11 | 12 | { |
| @@ -12,8 +13,8 @@ | ||
| 12 | 13 | /// <summary> |
| 13 | 14 | /// TerrainMapImplは実際に地形データを配列に展開して保持する。 |
| 14 | 15 | /// </summary> |
| 15 | - [Serializable] | |
| 16 | - public class TerrainMapImpl : ITerrainMap { | |
| 16 | + [Serializable] | |
| 17 | + public class TerrainMapImpl : ITerrainMap { | |
| 17 | 18 | protected delegate bool DiscontinuousChecker(TerrainMapImpl map, int x, int y); |
| 18 | 19 | static protected DiscontinuousChecker[] checker; |
| 19 | 20 | static TerrainMapImpl() { |
| @@ -28,9 +29,11 @@ | ||
| 28 | 29 | protected short[,] water; |
| 29 | 30 | protected int heightOffset; |
| 30 | 31 | protected Size3D size; |
| 32 | + protected StructureCollection structures = new StructureCollection(); | |
| 31 | 33 | |
| 32 | - public TerrainMapImpl(ITerrainMap source) : | |
| 33 | - this(source, new Rectangle(0,0,source.Size.sx, source.Size.sy)) {} | |
| 34 | + public TerrainMapImpl(ITerrainMap source) : | |
| 35 | + this(source, new Rectangle(0, 0, source.Size.sx, source.Size.sy)) { | |
| 36 | + } | |
| 34 | 37 | |
| 35 | 38 | public TerrainMapImpl(ITerrainMap source, Rectangle region) { |
| 36 | 39 | this.heightOffset = source.HeightOffset; |
| @@ -42,8 +45,8 @@ | ||
| 42 | 45 | } |
| 43 | 46 | this.size = new Size3D(sx, sy, source.Size.sz); |
| 44 | 47 | this.hmap = new TerrainPiecePair[sx, sy]; |
| 45 | - int ox = region.Left; | |
| 46 | - int oy = region.Top; | |
| 48 | + int ox = region.Left; | |
| 49 | + int oy = region.Top; | |
| 47 | 50 | |
| 48 | 51 | for (int x = 0; x < sx; x++) { |
| 49 | 52 | for (int y = 0; y < sy; y++) { |
| @@ -50,7 +53,7 @@ | ||
| 50 | 53 | hmap[x, y] = TerrainPiecePair.CreatePair(source, ox + x, oy + y, 1.0, CreatePiece); |
| 51 | 54 | } |
| 52 | 55 | } |
| 53 | - } | |
| 56 | + } | |
| 54 | 57 | |
| 55 | 58 | protected virtual TerrainPieceE CreatePiece(int ne, int nw, int sw, int se) { |
| 56 | 59 | return new TerrainPieceE(ne, nw, sw, se); |
| @@ -60,19 +63,23 @@ | ||
| 60 | 63 | Dispose(false); |
| 61 | 64 | } |
| 62 | 65 | |
| 63 | - #region ITerrainMap メンバ | |
| 64 | - public Size3D Size { get{ return size; } } | |
| 66 | + #region ITerrainMap メンバ | |
| 67 | + public Size3D Size { | |
| 68 | + get { | |
| 69 | + return size; | |
| 70 | + } | |
| 71 | + } | |
| 65 | 72 | |
| 66 | - public int Height(int x, int y) { | |
| 73 | + public int Height(int x, int y) { | |
| 67 | 74 | TerrainPiecePair pair = this[x, y]; |
| 68 | 75 | if (pair != null) { |
| 69 | 76 | return (short)pair.MeanHeight; |
| 70 | 77 | } else { |
| 71 | - string t = string.Format("Height({0},{1}): argument out of range.",x,y); | |
| 72 | - Debug.WriteLine(t); | |
| 73 | - return -1; | |
| 74 | - } | |
| 75 | - } | |
| 78 | + string t = string.Format("Height({0},{1}): argument out of range.", x, y); | |
| 79 | + Debug.WriteLine(t); | |
| 80 | + return -1; | |
| 81 | + } | |
| 82 | + } | |
| 76 | 83 | |
| 77 | 84 | public int DetailedHeight(double x, double y) { |
| 78 | 85 | throw new NotImplementedException(); |
| @@ -90,7 +97,11 @@ | ||
| 90 | 97 | } |
| 91 | 98 | } |
| 92 | 99 | |
| 93 | - public bool IsDetailedHeight { get { return false; } } | |
| 100 | + public bool IsDetailedHeight { | |
| 101 | + get { | |
| 102 | + return false; | |
| 103 | + } | |
| 104 | + } | |
| 94 | 105 | |
| 95 | 106 | public int WaterDepth(int x, int y) { |
| 96 | 107 | try { |
| @@ -103,21 +114,34 @@ | ||
| 103 | 114 | } |
| 104 | 115 | |
| 105 | 116 | public int HeightOffset { |
| 106 | - get { return heightOffset; } | |
| 117 | + get { | |
| 118 | + return heightOffset; | |
| 119 | + } | |
| 107 | 120 | } |
| 108 | 121 | |
| 109 | 122 | #endregion |
| 110 | 123 | |
| 124 | + public StructureCollection Structures { | |
| 125 | + get { | |
| 126 | + return structures; | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + public void GetObjectEnumerator(Rect3D hint, out IEnumerable<TerrainPiecePair> terrains, out IEnumerable<Lot> structures) { | |
| 131 | + terrains = new TerrainPairEnumerator(this, hint); | |
| 132 | + structures = this.structures.GetEnumeratorForView(hint); | |
| 133 | + } | |
| 134 | + | |
| 111 | 135 | public IEnumerable<ITerrainPiece> this[int x, int y, ICDir viewupper] { |
| 112 | 136 | get { |
| 113 | 137 | try { |
| 114 | 138 | return hmap[x, y].GetPieces(viewupper); |
| 115 | 139 | } catch (IndexOutOfRangeException) { |
| 116 | - Debug.WriteLine("The location (" + x + ", y=" + y + ") is OUTSIDE of the map{ size:(" + hmap.GetUpperBound(0) + "," + hmap.GetUpperBound(1)+")}"); | |
| 140 | + Debug.WriteLine("The location (" + x + ", y=" + y + ") is OUTSIDE of the map{ size:(" + hmap.GetUpperBound(0) + "," + hmap.GetUpperBound(1) + ")}"); | |
| 117 | 141 | return NullEnumerator(); |
| 118 | 142 | } |
| 119 | 143 | } |
| 120 | - } | |
| 144 | + } | |
| 121 | 145 | |
| 122 | 146 | [Obsolete] |
| 123 | 147 | public bool IsCliffedBounds(Direction4 cellside, int x, int y) { |
| @@ -142,7 +166,7 @@ | ||
| 142 | 166 | } |
| 143 | 167 | protected Rectangle[] districts; |
| 144 | 168 | */ |
| 145 | - | |
| 169 | + | |
| 146 | 170 | // for fail safe |
| 147 | 171 | static protected IEnumerable<ITerrainPiece> NullEnumerator() { |
| 148 | 172 | yield break; |
| @@ -198,7 +222,7 @@ | ||
| 198 | 222 | } |
| 199 | 223 | |
| 200 | 224 | static protected bool IsEastSideDiscontinuous(TerrainMapImpl map, int x, int y) { |
| 201 | - if ( y < 0 || y >= map.Size.sy || x < 0 || map.Size.sx - x <= 1) | |
| 225 | + if (y < 0 || y >= map.Size.sy || x < 0 || map.Size.sx - x <= 1) | |
| 202 | 226 | return true; |
| 203 | 227 | try { |
| 204 | 228 | TerrainPiecePair p1 = map[x, y]; |
| @@ -244,5 +268,29 @@ | ||
| 244 | 268 | } |
| 245 | 269 | } |
| 246 | 270 | #endregion |
| 271 | + | |
| 272 | + public class TerrainPairEnumerator : IEnumerable<TerrainPiecePair> { | |
| 273 | + TerrainMapImpl map; | |
| 274 | + Rect3D region; | |
| 275 | + internal protected TerrainPairEnumerator(TerrainMapImpl map, Rect3D region) { | |
| 276 | + this.map = map; | |
| 277 | + this.region = region; | |
| 278 | + } | |
| 279 | + | |
| 280 | + public IEnumerator<TerrainPiecePair> GetEnumerator() { | |
| 281 | + int x2 = region.X2; | |
| 282 | + int y2 = region.Y2; | |
| 283 | + for (int y = region.Y; y < y2; y++) { | |
| 284 | + for (int x = region.X; x < x2; x++) { | |
| 285 | + yield return map.hmap[x, y]; | |
| 286 | + } | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { | |
| 291 | + return GetEnumerator(); | |
| 292 | + } | |
| 293 | + } | |
| 294 | + | |
| 247 | 295 | } |
| 248 | 296 | } |
| @@ -18,6 +18,8 @@ | ||
| 18 | 18 | |
| 19 | 19 | protected string name; |
| 20 | 20 | protected TerrainMapImpl terrains; |
| 21 | + protected IPointerHandler activeHandler; | |
| 22 | + protected ViewCollection views; | |
| 21 | 23 | |
| 22 | 24 | public GameImpl(string name, ITerrainMap map, Calendar cal) { |
| 23 | 25 | if (cal == null) cal = Calendar.ActiveCalendar; |
| @@ -28,6 +30,7 @@ | ||
| 28 | 30 | this.terrains = (TerrainMapImpl)map; |
| 29 | 31 | else |
| 30 | 32 | this.terrains = new TerrainMapImpl(map); |
| 33 | + this.views = new ViewCollection(this); | |
| 31 | 34 | } |
| 32 | 35 | |
| 33 | 36 | public GameImpl(ITerrainMap map, Calendar cal) |
| @@ -87,6 +90,25 @@ | ||
| 87 | 90 | set{ name = value; } |
| 88 | 91 | } |
| 89 | 92 | |
| 90 | - #endregion | |
| 91 | - } | |
| 93 | + public IPointerHandler ActiveController { | |
| 94 | + get { | |
| 95 | + return activeHandler; | |
| 96 | + } | |
| 97 | + set { | |
| 98 | + if (activeHandler != null) { | |
| 99 | + activeHandler.OnDetach(this); | |
| 100 | + } | |
| 101 | + activeHandler = value; | |
| 102 | + activeHandler.OnAttach(this); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + public ViewCollection Views { | |
| 107 | + get { | |
| 108 | + return views; | |
| 109 | + } | |
| 110 | + } | |
| 111 | + #endregion | |
| 112 | + | |
| 113 | + } | |
| 92 | 114 | } |
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | using System; |
| 2 | 2 | using System.Collections.Generic; |
| 3 | 3 | using System.Text; |
| 4 | -using nft.framework.drawing; | |
| 5 | 4 | using nft.impl.game; |
| 6 | 5 | using nft.core.geometry; |
| 7 | 6 | using nft.core; |
| @@ -10,10 +9,12 @@ | ||
| 10 | 9 | using System.Drawing; |
| 11 | 10 | using System.Windows.Forms; |
| 12 | 11 | using nft.core.game; |
| 12 | +using nft.core.view; | |
| 13 | +using nft.framework.drawing; | |
| 13 | 14 | |
| 14 | 15 | namespace nft.impl.view |
| 15 | 16 | { |
| 16 | - public class GameViewPanel : UserControl | |
| 17 | + public class GameViewPanel : UserControl, IView | |
| 17 | 18 | { |
| 18 | 19 | SceneBuilder builder; |
| 19 | 20 | bool prepared; |
| @@ -34,6 +35,7 @@ | ||
| 34 | 35 | } |
| 35 | 36 | } |
| 36 | 37 | |
| 38 | + #region IView implementations | |
| 37 | 39 | public SceneBuilder SceneBuilder { |
| 38 | 40 | get { return builder; } |
| 39 | 41 | } |
| @@ -46,6 +48,11 @@ | ||
| 46 | 48 | } |
| 47 | 49 | } |
| 48 | 50 | |
| 51 | + public void Close() { | |
| 52 | + this.Dispose(); | |
| 53 | + } | |
| 54 | + #endregion | |
| 55 | + | |
| 49 | 56 | void OnTouchPanelScroll(object sender, ScrollEventArgs e) { |
| 50 | 57 | UpdateScrollParams(false); |
| 51 | 58 | } |
| @@ -184,6 +191,7 @@ | ||
| 184 | 191 | protected override void OnPaintBackground(PaintEventArgs e) { |
| 185 | 192 | } |
| 186 | 193 | #endregion |
| 194 | + | |
| 187 | 195 | } |
| 188 | 196 | |
| 189 | 197 | /// <summary> |
| @@ -0,0 +1,42 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.framework; | |
| 5 | +using nft.core.view; | |
| 6 | +using nft.ui.mainframe; | |
| 7 | +using nft.impl.game; | |
| 8 | +using nft.core.geometry; | |
| 9 | + | |
| 10 | +namespace nft.impl.view { | |
| 11 | + public class GameViewFactory : IGameViewFactory { | |
| 12 | + protected MainFrame MainFrame { | |
| 13 | + get { | |
| 14 | + return Main.mainFrame as MainFrame; | |
| 15 | + } | |
| 16 | + } | |
| 17 | + | |
| 18 | + public GameViewFactory(ParamsReader node) { | |
| 19 | + } | |
| 20 | + | |
| 21 | + #region IGameViewFactory implementation | |
| 22 | + public Type RegistType { | |
| 23 | + get { | |
| 24 | + return typeof(IGameViewFactory); | |
| 25 | + } | |
| 26 | + } | |
| 27 | + | |
| 28 | + public IView Create(core.game.IGame game, Location center) { | |
| 29 | + GameViewPanel f = new GameViewPanel((GameImpl)game); | |
| 30 | + MainFrame.AddView(game.Name, f); | |
| 31 | + if (center != Location.UNPLACED) { | |
| 32 | + // TODO scroll to the initial location | |
| 33 | + } | |
| 34 | + return f; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public IView Create(core.game.IGame game, Location center, int width, int height) { | |
| 38 | + throw new NotImplementedException(); | |
| 39 | + } | |
| 40 | + #endregion | |
| 41 | + } | |
| 42 | +} |
| @@ -0,0 +1,68 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.core.view; | |
| 5 | +using nft.impl.game; | |
| 6 | +using nft.core.game; | |
| 7 | + | |
| 8 | +namespace nft.impl.selectors { | |
| 9 | + public class CubeSelectorBase : ITargetSelector, IPointerHandler { | |
| 10 | + IGame game; | |
| 11 | + public CubeSelectorBase() { | |
| 12 | + } | |
| 13 | + | |
| 14 | + protected TerrainMapImpl TerrainMap { | |
| 15 | + get { | |
| 16 | + return ((GameImpl)game).TerrainMap; | |
| 17 | + } | |
| 18 | + } | |
| 19 | + | |
| 20 | + #region ITargetSelector implementation | |
| 21 | + public int MaxPhases { | |
| 22 | + get { | |
| 23 | + return 1; | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 27 | + public int CurrentPhase { | |
| 28 | + get { | |
| 29 | + return 1; | |
| 30 | + } | |
| 31 | + } | |
| 32 | + | |
| 33 | + public object CurrentSelection { | |
| 34 | + get { | |
| 35 | + throw new NotImplementedException(); | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + public event TargetSelectorEvent OnSelectionChanged; | |
| 40 | + | |
| 41 | + public event TargetSelectorEvent OnPhaseChanged; | |
| 42 | + | |
| 43 | + public event TargetSelectorEvent OnViewChanged; | |
| 44 | + #endregion | |
| 45 | + | |
| 46 | + #region IPointerHandler implementation | |
| 47 | + public void OnAttach(IGame g) { | |
| 48 | + this.game = g; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void OnDetach(IGame g) { | |
| 52 | + this.game = null; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public void OnMouseButtonDown(PointerEventArgs args) { | |
| 56 | + throw new NotImplementedException(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void OnMouseButtonUp(PointerEventArgs args) { | |
| 60 | + throw new NotImplementedException(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + public void OnMouseMove(PointerEventArgs args) { | |
| 64 | + throw new NotImplementedException(); | |
| 65 | + } | |
| 66 | + #endregion | |
| 67 | + } | |
| 68 | +} |