FreeTrainの進化系を目指す
調査ツール実装、それに絡んで各種イベントハンドラなどの実装、関連クラスの再設計
| @@ -97,6 +97,7 @@ | ||
| 97 | 97 | <item mid="EXIT|EXIT" caption="終了(&X)">ゲームを終了します。</item> |
| 98 | 98 | </item> |
| 99 | 99 | <item mid="VIEW" caption="表示(&V)"> |
| 100 | + <item mid="TOOL|INSPECTOR" caption="調査ツール"/> | |
| 100 | 101 | </item> |
| 101 | 102 | <item mid="BUILD" caption="建設(&B)"> |
| 102 | 103 | </item> |
| @@ -283,6 +284,17 @@ | ||
| 283 | 284 | <command type="ModalForm" menupath="FILE\GAME|NEWMAP" /> |
| 284 | 285 | </contribution> |
| 285 | 286 | |
| 287 | + <!--<contribution type="SubForm" id="InspectorTool"> | |
| 288 | + <name>調査ツール</name> | |
| 289 | + <class name="nft.ui.core.InspectorTool" codebase=".UI"/> | |
| 290 | + <options>permanent</options> | |
| 291 | + </contribution>--> | |
| 292 | + <contribution type="Command" id="C_InspectorTool"> | |
| 293 | + <name>調査ツール</name> | |
| 294 | + <class name="nft.ui.core.InspectorTool" codebase=".UI"/> | |
| 295 | + <command type="SubForm" menupath="VIEW\TOOL|INSPECTOR" /> | |
| 296 | + </contribution> | |
| 297 | + | |
| 286 | 298 | <contribution type="TerrainGenerator" id="FlatTerrainGenerator"> |
| 287 | 299 | <name>シンプル平坦マップ</name> |
| 288 | 300 | <description>真っ平らな地形を生成します</description> |
| @@ -189,5 +189,69 @@ | ||
| 189 | 189 | yield break; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | + public ArrangedTerrainPieces GetTerrainPieces(InterCardinalDirection viewUpper) { | |
| 193 | + ITerrainPiece p1,p2; | |
| 194 | + TerrainPieceTemplate.TerrainPolygonSet T1,T2; | |
| 195 | + if (revOrder[Direction.ToZeroBaseIndex(viewUpper)]) { | |
| 196 | + p1 = P1; | |
| 197 | + p2 = P2; | |
| 198 | + } else { | |
| 199 | + p2 = P1; | |
| 200 | + p1 = P2; | |
| 201 | + } | |
| 202 | + T1 = p1.Template.GetPolygons(viewUpper); | |
| 203 | + T2 = p2.Template.GetPolygons(viewUpper); | |
| 204 | + ArrangedTerrainPieces set = new ArrangedTerrainPieces(); | |
| 205 | + | |
| 206 | + set.Pieces = new ITerrainPiece[] { p1, p2 }; | |
| 207 | + set.PolygonSets = new TerrainPieceTemplate.TerrainPolygonSet[] { T1, T2 }; | |
| 208 | + SetPieceForCliffPolygons(ref set, 0, T1); | |
| 209 | + SetPieceForCliffPolygons(ref set, 1, T2); | |
| 210 | + return set; | |
| 211 | + } | |
| 212 | + | |
| 213 | + protected void SetPieceForCliffPolygons(ref ArrangedTerrainPieces store, int index, TerrainPieceTemplate.TerrainPolygonSet tps) { | |
| 214 | + ViewDirection8 diagSide = tps.Ground.DiagonalSide; | |
| 215 | + if (diagSide == ViewDirection8.FRONT) { | |
| 216 | + store.Index4DiagonalCliff = index; | |
| 217 | + } else { | |
| 218 | + if (diagSide != ViewDirection8.LEFT) { | |
| 219 | + store.Index4LeftCliff = index; | |
| 220 | + } | |
| 221 | + if (diagSide != ViewDirection8.RIGHT) { | |
| 222 | + store.Index4RightCliff = index; | |
| 223 | + } | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + public class ArrangedTerrainPieces { | |
| 228 | + public ITerrainPiece[] Pieces; | |
| 229 | + public TerrainPieceTemplate.TerrainPolygonSet[] PolygonSets; | |
| 230 | + public int Index4DiagonalCliff; | |
| 231 | + public int Index4LeftCliff; | |
| 232 | + public int Index4RightCliff; | |
| 233 | + | |
| 234 | + #region shortcut properties | |
| 235 | + public CliffPolygon CliffDiagonal { | |
| 236 | + get { return PolygonSets[Index4DiagonalCliff].CliffDiagonal; } | |
| 237 | + } | |
| 238 | + public CliffPolygon CliffLeft { | |
| 239 | + get { return PolygonSets[Index4LeftCliff].CliffLeft; } | |
| 240 | + } | |
| 241 | + public CliffPolygon CliffRight { | |
| 242 | + get { return PolygonSets[Index4RightCliff].CliffRight; } | |
| 243 | + } | |
| 244 | + | |
| 245 | + public int BaseHeightDiagonal { | |
| 246 | + get { return Pieces[Index4DiagonalCliff].BaseHeight; } | |
| 247 | + } | |
| 248 | + public int BaseHeightLeft{ | |
| 249 | + get { return Pieces[Index4LeftCliff].BaseHeight; } | |
| 250 | + } | |
| 251 | + public int BaseHeightRight { | |
| 252 | + get { return Pieces[Index4RightCliff].BaseHeight; } | |
| 253 | + } | |
| 254 | + #endregion | |
| 255 | + } | |
| 192 | 256 | } |
| 193 | 257 | } |
| @@ -14,12 +14,13 @@ | ||
| 14 | 14 | [Serializable] |
| 15 | 15 | public class GameImpl : IGame |
| 16 | 16 | { |
| 17 | + public event EventHandler Closing; | |
| 18 | + | |
| 17 | 19 | protected Calendar calender; |
| 18 | 20 | protected Clock clock; |
| 19 | 21 | |
| 20 | 22 | protected string name; |
| 21 | 23 | protected TerrainMapImpl terrains; |
| 22 | - protected IPointerHandler activeHandler; | |
| 23 | 24 | protected ViewCollection views; |
| 24 | 25 | protected bool modified; |
| 25 | 26 | protected bool closed; |
| @@ -60,7 +61,12 @@ | ||
| 60 | 61 | |
| 61 | 62 | public virtual void Close() |
| 62 | 63 | { |
| 63 | - closed = true; | |
| 64 | + if (!closed) { | |
| 65 | + closed = true; | |
| 66 | + if (Closing != null) { | |
| 67 | + Closing(this, new EventArgs()); | |
| 68 | + } | |
| 69 | + } | |
| 64 | 70 | calender = null; |
| 65 | 71 | clock = null; |
| 66 | 72 | if (terrains != null) { |
| @@ -120,19 +126,6 @@ | ||
| 120 | 126 | set{ name = value; } |
| 121 | 127 | } |
| 122 | 128 | |
| 123 | - public IPointerHandler ActiveController { | |
| 124 | - get { | |
| 125 | - return activeHandler; | |
| 126 | - } | |
| 127 | - set { | |
| 128 | - if (activeHandler != null) { | |
| 129 | - activeHandler.OnDetach(this); | |
| 130 | - } | |
| 131 | - activeHandler = value; | |
| 132 | - activeHandler.OnAttach(this); | |
| 133 | - } | |
| 134 | - } | |
| 135 | - | |
| 136 | 129 | public ViewCollection Views { |
| 137 | 130 | get { |
| 138 | 131 | return views; |
| @@ -0,0 +1,42 @@ | ||
| 1 | +using nft.core.game; | |
| 2 | +using nft.core.geometry; | |
| 3 | +using nft.core.view; | |
| 4 | +using nft.framework.drawing; | |
| 5 | +using System; | |
| 6 | +using System.Collections.Generic; | |
| 7 | +using System.Drawing; | |
| 8 | +using System.Text; | |
| 9 | +using Geocon = nft.core.geometry.GeometricConstants; | |
| 10 | + | |
| 11 | +namespace nft.impl.view { | |
| 12 | + public class SelectionInfo { | |
| 13 | + public readonly IGame Game; | |
| 14 | + public readonly SceneBuilder SceneBuilder; | |
| 15 | + public readonly Point ScreenPosition; // position of mouse cursor. | |
| 16 | + | |
| 17 | + public SelectionInfo(IGame game, SceneBuilder builder, Point screen) { | |
| 18 | + this.Game = game; | |
| 19 | + this.SceneBuilder = builder; | |
| 20 | + this.ScreenPosition = screen; | |
| 21 | + } | |
| 22 | + | |
| 23 | + // Fields that indicates current selection -- | |
| 24 | + public PointF3D WorldPosition; // simple 2D/3D conversion of coordination. | |
| 25 | + public Location Location; // in grid unit | |
| 26 | + public Point Offset; | |
| 27 | + public UInt32 HitTestValue; | |
| 28 | + public ITerrainPiece TerrainPiece; | |
| 29 | + public ITerrainPolygon Polygon; | |
| 30 | + public object Object; | |
| 31 | + // -- End of fields | |
| 32 | + | |
| 33 | + public ISurface Surface { | |
| 34 | + get { return SceneBuilder.surface; } | |
| 35 | + } | |
| 36 | + | |
| 37 | + public ITerrainMap TerrainMap { | |
| 38 | + get { return SceneBuilder.game.TerrainMap; } | |
| 39 | + } | |
| 40 | + | |
| 41 | + } | |
| 42 | +} |
| @@ -49,32 +49,37 @@ | ||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - internal static bool ResolveTerrain(SceneBuilder sb, Point mousePos, out ITerrainPolygon pol, out PointF3D p3dv) { | |
| 53 | - pol = null; | |
| 52 | + internal static bool ResolveTerrain(ref SelectionInfo info) { | |
| 53 | + Point mousePos = info.ScreenPosition; | |
| 54 | 54 | //mousePos.Y++; |
| 55 | 55 | Debug.Write("ResolveTerrain: mouse=(" + mousePos.X + "," + mousePos.Y + ")"); |
| 56 | - p3dv = sb.surface.ToWorldPosition(mousePos); | |
| 57 | - UInt32 idx = sb.surface.HitTestAt(mousePos.X, mousePos.Y); | |
| 58 | - TerrainMapImpl map = sb.game.TerrainMap; | |
| 56 | + PointF3D p3dv = info.Surface.ToWorldPosition(mousePos); | |
| 57 | + UInt32 idx = info.Surface.HitTestAt(mousePos.X, mousePos.Y); | |
| 58 | + info.HitTestValue = idx; | |
| 59 | + TerrainMapImpl map = info.TerrainMap as TerrainMapImpl; | |
| 59 | 60 | if (AdjustPointForGround(ref p3dv, idx)) { |
| 61 | + info.WorldPosition = p3dv; | |
| 60 | 62 | int gx = (int)Math.Round(p3dv.X / Geocon.UnitWidthPixel); |
| 61 | 63 | int gy = (int)Math.Round(p3dv.Y / Geocon.UnitWidthPixel); |
| 64 | + PointF3D p3d = new PointF3D(gx * Geocon.UnitWidthPixel, gy * Geocon.UnitWidthPixel, 0); | |
| 65 | + Point rep = info.Surface.ToScreenPosition(p3d); | |
| 66 | + int xoff = mousePos.X - rep.X; | |
| 67 | + int yoff = mousePos.Y - rep.Y; | |
| 62 | 68 | Debug.Write(":Ground->(" + p3dv.X + "," + p3dv.Y + ") : grid[" + gx + "," + gy + "]"); |
| 63 | - Location l = sb.cdUtil.IsometricGridToLocation(gx, gy, 0); | |
| 64 | - foreach (ITerrainPiece p in map[l.X, l.Y, sb.upperDir]) { | |
| 65 | - TerrainPieceTemplate.TerrainPolygonSet tpset = p.Template.GetPolygons(sb.upperDir); | |
| 69 | + Location l = info.SceneBuilder.cdUtil.IsometricGridToLocation(gx, gy, 0); | |
| 70 | + InterCardinalDirection updir = info.SceneBuilder.upperDir; | |
| 71 | + foreach (ITerrainPiece p in map[l.X, l.Y, updir]) { | |
| 72 | + TerrainPieceTemplate.TerrainPolygonSet tpset = p.Template.GetPolygons(updir); | |
| 66 | 73 | if (tpset.Ground.IsVisible) { |
| 67 | - PointF3D p3d = new PointF3D(gx * Geocon.UnitWidthPixel, gy * Geocon.UnitWidthPixel, 0); | |
| 68 | - Point rep = sb.surface.ToScreenPosition(p3d); | |
| 69 | - int xoff = mousePos.X - rep.X; | |
| 70 | - int yoff = mousePos.Y - rep.Y; | |
| 71 | 74 | int h1 = p.BaseHeight * Geocon.UnitHeightPixel; |
| 72 | - yoff += h1; | |
| 73 | - //Debug.Write("!"); | |
| 74 | - if (TerrainUtil.IsInnerPoint2D(tpset.Ground.GetVerticis(sb.scaler), new Point(xoff, yoff))) { | |
| 75 | + Point offset = new Point(xoff, yoff+h1); | |
| 76 | + if (TerrainUtil.IsInnerPoint2D(tpset.Ground.GetVerticis(info.SceneBuilder.scaler), offset)) { | |
| 75 | 77 | Debug.WriteLine("+(" + xoff + "," + yoff + ")"); |
| 76 | - pol = tpset.Ground; | |
| 77 | - sb.CreateMarker(gx, gy, SceneBuilder.TrMk_Ground); | |
| 78 | + info.TerrainPiece = p; | |
| 79 | + info.Polygon = tpset.Ground; | |
| 80 | + info.Offset = offset; | |
| 81 | + info.Location = new Location(l.X, l.Y, p.BaseHeight); | |
| 82 | + info.SceneBuilder.CreateMarker(gx, gy, SceneBuilder.TrMk_Ground); | |
| 78 | 83 | break; |
| 79 | 84 | //} else if (pol == null) { |
| 80 | 85 | // pol = tpset.Ground; |
| @@ -82,32 +87,51 @@ | ||
| 82 | 87 | } |
| 83 | 88 | } |
| 84 | 89 | //Debug.WriteLineIf(pol == null, "WTF!?"); |
| 85 | - return pol != null; | |
| 90 | + return info.Polygon != null; | |
| 86 | 91 | } else if (AdjustPointForCliff(ref p3dv, idx)) { |
| 92 | + info.WorldPosition = p3dv; | |
| 87 | 93 | int gx = (int)Math.Round(p3dv.X / Geocon.UnitWidthPixel); |
| 88 | 94 | int gy = (int)Math.Round(p3dv.Y / Geocon.UnitWidthPixel); |
| 95 | + PointF3D p3d = new PointF3D(gx * Geocon.UnitWidthPixel, gy * Geocon.UnitWidthPixel, 0); | |
| 96 | + Point rep = info.Surface.ToScreenPosition(p3d); | |
| 97 | + int xoff = mousePos.X - rep.X; | |
| 98 | + int yoff = mousePos.Y - rep.Y; | |
| 89 | 99 | Debug.Write(":Cliff->(" + p3dv.X + "," + p3dv.Y + ") : grid[" + gx + "," + gy + "]"); |
| 90 | - Location l = sb.cdUtil.IsometricGridToLocation(gx, gy, 0); | |
| 91 | - foreach (ITerrainPiece p in map[l.X, l.Y, sb.upperDir]) { | |
| 100 | + Location l = info.SceneBuilder.cdUtil.IsometricGridToLocation(gx, gy, 0); | |
| 101 | + InterCardinalDirection updir = info.SceneBuilder.upperDir; | |
| 102 | + UInt32 testval = (idx & Mask_CliffPolygon_D); | |
| 103 | + TerrainPiecePair pair = map[l.X, l.Y]; | |
| 104 | + if (pair != null) { | |
| 105 | + TerrainPiecePair.ArrangedTerrainPieces atp = pair.GetTerrainPieces(updir); | |
| 92 | 106 | //if (p.BaseHeight < p3dv.Z) continue; |
| 93 | - TerrainPieceTemplate.TerrainPolygonSet tpset = p.Template.GetPolygons(sb.upperDir); | |
| 94 | - UInt32 testval = (idx & Mask_CliffPolygon_D); | |
| 95 | 107 | if (testval == Mask_CliffPolygon_D) { |
| 96 | 108 | Debug.WriteLine(":Diagonal"); |
| 97 | - pol = tpset.CliffDiagonal; | |
| 98 | - sb.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffDiag); | |
| 109 | + info.Polygon = atp.CliffDiagonal; | |
| 110 | + info.TerrainPiece = atp.Pieces[atp.Index4DiagonalCliff]; | |
| 111 | + info.Location = new Location(l.X, l.Y, info.TerrainPiece.BaseHeight); | |
| 112 | + int h1 = info.TerrainPiece.BaseHeight * Geocon.UnitHeightPixel; | |
| 113 | + info.Offset = new Point(xoff, yoff + h1); | |
| 114 | + info.SceneBuilder.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffDiag); | |
| 99 | 115 | } else if (testval == Mask_CliffPolygon_R) { |
| 100 | 116 | Debug.WriteLine(":Right"); |
| 101 | - pol = tpset.CliffRight; | |
| 102 | - sb.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffRight); | |
| 117 | + info.Polygon = atp.CliffRight; | |
| 118 | + info.TerrainPiece = atp.Pieces[atp.Index4RightCliff]; | |
| 119 | + info.Location = new Location(l.X, l.Y, info.TerrainPiece.BaseHeight); | |
| 120 | + int h1 = info.TerrainPiece.BaseHeight * Geocon.UnitHeightPixel; | |
| 121 | + info.Offset = new Point(xoff, yoff + h1); | |
| 122 | + info.SceneBuilder.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffRight); | |
| 103 | 123 | } else { |
| 104 | 124 | Debug.WriteLine(":Left"); |
| 105 | - pol = tpset.CliffLeft; | |
| 106 | - sb.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffLeft); | |
| 125 | + info.Polygon = atp.CliffLeft; | |
| 126 | + info.TerrainPiece = atp.Pieces[atp.Index4LeftCliff]; | |
| 127 | + info.Location = new Location(l.X, l.Y, info.TerrainPiece.BaseHeight); | |
| 128 | + int h1 = info.TerrainPiece.BaseHeight * Geocon.UnitHeightPixel; | |
| 129 | + info.Offset = new Point(xoff, yoff + h1); | |
| 130 | + info.SceneBuilder.CreateMarker(gx, gy, SceneBuilder.TrMk_CliffLeft); | |
| 107 | 131 | } |
| 132 | + //Debug.WriteLineIf(pol == null, "WTF2!?"); | |
| 133 | + return info.TerrainPiece != null; | |
| 108 | 134 | } |
| 109 | - //Debug.WriteLineIf(pol == null, "WTF2!?"); | |
| 110 | - return pol != null; | |
| 111 | 135 | } |
| 112 | 136 | //Debug.WriteLine("--"); |
| 113 | 137 | return false; |
| @@ -27,15 +27,39 @@ | ||
| 27 | 27 | renderPanel.OnSurfacePrepared += new EventHandler(SurfaceReady); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | + #region Internal event handlers | |
| 31 | + protected PointerEventArgs MakeArg(MouseEventArgs e) { | |
| 32 | + return new PointerEventArgs(e, builder.game, builder.surface); | |
| 33 | + } | |
| 30 | 34 | void EventTarget_MouseMove(object sender, MouseEventArgs e) { |
| 31 | 35 | if (prepared) { |
| 36 | + if (MouseCursorMove != null) MouseCursorMove(MakeArg(e)); | |
| 32 | 37 | //UInt32 u = renderPanel.Surface.HitTestAt(e.X, e.Y); |
| 33 | - object o = builder.GetObjectAt(e.Location); | |
| 38 | + //object o = builder.GetObjectAt(e.Location); | |
| 34 | 39 | renderPanel.Refresh(); |
| 35 | 40 | } |
| 36 | 41 | } |
| 37 | 42 | |
| 43 | + void EventTarget_MouseDown(object sender, MouseEventArgs e) { | |
| 44 | + if (MouseButtonDown != null) MouseButtonDown(MakeArg(e)); | |
| 45 | + } | |
| 46 | + void EventTarget_MouseUp(object sender, MouseEventArgs e) { | |
| 47 | + if (MouseButtonUp != null) MouseButtonUp(MakeArg(e)); | |
| 48 | + } | |
| 49 | + void Parent_LostFocus(object sender, EventArgs e) { | |
| 50 | + if (Activated != null) Activated(new ViewEventArgs(this)); | |
| 51 | + } | |
| 52 | + | |
| 53 | + void Parent_GotFocus(object sender, EventArgs e) { | |
| 54 | + // Do nothing | |
| 55 | + } | |
| 56 | + #endregion | |
| 57 | + | |
| 38 | 58 | #region IView implementations |
| 59 | + public ISurface Surface { | |
| 60 | + get { return renderPanel.Surface; } | |
| 61 | + } | |
| 62 | + | |
| 39 | 63 | public SceneBuilder SceneBuilder { |
| 40 | 64 | get { return builder; } |
| 41 | 65 | } |
| @@ -55,6 +79,10 @@ | ||
| 55 | 79 | |
| 56 | 80 | public event ViewEventHandler OnClose; |
| 57 | 81 | public event ViewQueryEventHandler QueryClose; |
| 82 | + public event ViewEventHandler Activated; | |
| 83 | + public event PointerEventHandler MouseCursorMove; | |
| 84 | + public event PointerEventHandler MouseButtonDown; | |
| 85 | + public event PointerEventHandler MouseButtonUp; | |
| 58 | 86 | #endregion |
| 59 | 87 | |
| 60 | 88 | void OnTouchPanelScroll(object sender, ScrollEventArgs e) { |
| @@ -73,7 +101,11 @@ | ||
| 73 | 101 | Size szu = new Size(Geocon.UnitWidthPixel, Geocon.HalfOf_UnitWidthPixel); |
| 74 | 102 | Size szc = builder.ContentSize; |
| 75 | 103 | InitScroll(szc, szu); |
| 76 | - renderPanel.EventTarget.MouseMove += new MouseEventHandler(EventTarget_MouseMove); | |
| 104 | + renderPanel.EventTarget.MouseMove += EventTarget_MouseMove; | |
| 105 | + renderPanel.EventTarget.MouseDown += EventTarget_MouseDown; | |
| 106 | + renderPanel.EventTarget.MouseUp += EventTarget_MouseUp; | |
| 107 | + Parent.GotFocus += Parent_GotFocus; | |
| 108 | + Parent.LostFocus += Parent_LostFocus; | |
| 77 | 109 | SetupCloseConfirmation(); |
| 78 | 110 | this.ResumeLayout(false); |
| 79 | 111 | } |
| @@ -220,6 +252,7 @@ | ||
| 220 | 252 | } |
| 221 | 253 | #endregion |
| 222 | 254 | |
| 255 | + | |
| 223 | 256 | } |
| 224 | 257 | |
| 225 | 258 | /// <summary> |
| @@ -103,7 +103,6 @@ | ||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | Stopwatch watch0 = new Stopwatch(); |
| 106 | - int xxx = 0; | |
| 107 | 106 | public IEnumerator<I3DObject> GetEnumerator() { |
| 108 | 107 | InterCardinalDirection dir = upperDir; |
| 109 | 108 | TerrainMapImpl map = game.TerrainMap; |
| @@ -209,6 +208,84 @@ | ||
| 209 | 208 | Debug.WriteLine(string.Format("time={0}ms", watch0.ElapsedMilliseconds)); |
| 210 | 209 | } |
| 211 | 210 | |
| 211 | + public IEnumerable<I3DObject> GetTerrainsAt(int gridX, int gridY) { | |
| 212 | + // 概ね GetEnumerator() のループ内と同じだが、崖のチェックをしない(必ず描画) | |
| 213 | + InterCardinalDirection dir = UpperDirection; | |
| 214 | + TerrainMapImpl map = game.TerrainMap; | |
| 215 | + Size3D sz = map.Size; | |
| 216 | + // terrain assembl loop | |
| 217 | + | |
| 218 | + Point3DV pv = new Point3DV(gridX * Geocon.UnitWidthPixel, gridY * Geocon.UnitWidthPixel, 0); | |
| 219 | + Location l = cdUtil.IsometricGridToLocation(gridX, gridY, 0); | |
| 220 | + int x = l.X; | |
| 221 | + int y = l.Y; | |
| 222 | + if (x < 0 || y < 0 || x >= sz.sx || y >= sz.sy) { | |
| 223 | + // out of map | |
| 224 | + yield break; | |
| 225 | + } | |
| 226 | + TerrainPiecePair pair = map[x, y]; | |
| 227 | + if (pair == null) { | |
| 228 | + yield break; | |
| 229 | + } | |
| 230 | + TerrainPiecePair.ArrangedTerrainPieces atp = pair.GetTerrainPieces(UpperDirection); | |
| 231 | + ITerrainPlate plate; | |
| 232 | + int hgap = 0; | |
| 233 | + for (int i = 0; i < atp.Pieces.Length; i++) { | |
| 234 | + ITerrainPiece p = atp.Pieces[i]; | |
| 235 | + TerrainPieceTemplate.TerrainPolygonSet tpset = atp.PolygonSets[i]; | |
| 236 | + pv.VZ = p.BaseHeight * Geocon.UnitHeightPixel; | |
| 237 | + if (tpset.Ground.IsVisible) { | |
| 238 | + plate = apparents.DefaultLandTexture.Get(l, tpset.Ground, pv); | |
| 239 | + plate.Location = new PointF3D(pv.VX, pv.VY, pv.VZ); | |
| 240 | + yield return plate; | |
| 241 | + } | |
| 242 | + } | |
| 243 | + CliffPolygon cp; | |
| 244 | + // Process Left Cliff | |
| 245 | + cp = atp.CliffLeft; | |
| 246 | + hgap = atp.BaseHeightLeft * Geocon.UnitHeightPixel; | |
| 247 | + pv.VZ = 0; | |
| 248 | + if (cp == null && hgap > 0) { | |
| 249 | + cp = CliffPolygon.LeftUnitCliff; | |
| 250 | + hgap -= Geocon.TerrainStepHeightInUnit; | |
| 251 | + pv.VZ -= Geocon.TerrainStepHeightInUnit; | |
| 252 | + } | |
| 253 | + if (cp != null) { | |
| 254 | + plate = apparents.DefaultCliffTexture.Get(cp, hgap, pv); | |
| 255 | + plate.Location = new PointF3D(pv.VX, pv.VY, pv.VZ); | |
| 256 | + yield return plate; | |
| 257 | + } | |
| 258 | + // Process Right Cliff | |
| 259 | + cp = atp.CliffRight; | |
| 260 | + hgap = atp.BaseHeightRight * Geocon.UnitHeightPixel; | |
| 261 | + pv.VZ = 0; | |
| 262 | + if (cp == null && hgap > 0) { | |
| 263 | + cp = CliffPolygon.RightUnitCliff; | |
| 264 | + hgap -= Geocon.TerrainStepHeightInUnit; | |
| 265 | + pv.VZ -= Geocon.TerrainStepHeightInUnit; | |
| 266 | + } | |
| 267 | + if (cp != null) { | |
| 268 | + plate = apparents.DefaultCliffTexture.Get(cp, hgap, pv); | |
| 269 | + plate.Location = new PointF3D(pv.VX, pv.VY, pv.VZ); | |
| 270 | + yield return plate; | |
| 271 | + } | |
| 272 | + // Process Diagonal Cliff | |
| 273 | + cp = atp.CliffDiagonal; | |
| 274 | + hgap = atp.BaseHeightDiagonal * Geocon.UnitHeightPixel; | |
| 275 | + pv.VZ = 0; | |
| 276 | + if (cp == null && hgap > 0) { | |
| 277 | + cp = CliffPolygon.DiagonalUnitCliff; | |
| 278 | + hgap -= Geocon.TerrainStepHeightInUnit; | |
| 279 | + pv.VZ -= Geocon.TerrainStepHeightInUnit; | |
| 280 | + } | |
| 281 | + if (cp != null) { | |
| 282 | + plate = apparents.DefaultCliffTexture.Get(cp, hgap, pv); | |
| 283 | + plate.Location = new PointF3D(pv.VX, pv.VY, pv.VZ); | |
| 284 | + yield return plate; | |
| 285 | + } | |
| 286 | + | |
| 287 | + } | |
| 288 | + | |
| 212 | 289 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { |
| 213 | 290 | return GetEnumerator(); //??? |
| 214 | 291 | } |
| @@ -280,13 +357,14 @@ | ||
| 280 | 357 | return new Point(isx - d, isy - d); |
| 281 | 358 | } |
| 282 | 359 | |
| 283 | - public object GetObjectAt(Point spos) { | |
| 360 | + public SelectionInfo GetObjectAt(Point spos) { | |
| 284 | 361 | ITerrainPolygon pol; |
| 285 | 362 | PointF3D p3dv; |
| 286 | 363 | marker0 = null; |
| 287 | - if (DrawIndexUtil.ResolveTerrain(this, spos, out pol, out p3dv)) { | |
| 364 | + SelectionInfo info = new SelectionInfo(game, this, spos); | |
| 365 | + if (DrawIndexUtil.ResolveTerrain(ref info)) { | |
| 288 | 366 | |
| 289 | - return pol; | |
| 367 | + return info; | |
| 290 | 368 | } |
| 291 | 369 | return null; |
| 292 | 370 | } |
| @@ -427,5 +505,6 @@ | ||
| 427 | 505 | return cliff; |
| 428 | 506 | } |
| 429 | 507 | |
| 508 | + | |
| 430 | 509 | } |
| 431 | 510 | } |
| @@ -0,0 +1,28 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections; | |
| 3 | +using System.Diagnostics; | |
| 4 | +using System.Drawing; | |
| 5 | +using System.Reflection; | |
| 6 | +using System.Xml; | |
| 7 | +using nft.framework; | |
| 8 | +using nft.framework.plugin; | |
| 9 | +using nft.core.game; | |
| 10 | +using nft.util; | |
| 11 | +using System.Windows.Forms; | |
| 12 | +using nft.contributions.ui; | |
| 13 | + | |
| 14 | +namespace nft.contributions.game | |
| 15 | +{ | |
| 16 | + /// <summary> | |
| 17 | + /// CommandEntityContributuion の概要の説明です。 | |
| 18 | + /// </summary> | |
| 19 | + public class CtbGameTool : CtbSubform | |
| 20 | + { | |
| 21 | + public CtbGameTool(Plugin p, ParamsReader e) | |
| 22 | + : base(p, e) | |
| 23 | + { | |
| 24 | + | |
| 25 | + } | |
| 26 | + } | |
| 27 | + | |
| 28 | +} |
| @@ -15,13 +15,15 @@ | ||
| 15 | 15 | void Start(); |
| 16 | 16 | void Close(); |
| 17 | 17 | bool Closed {get;} |
| 18 | - // if false, no need to save the game. | |
| 18 | + | |
| 19 | + event EventHandler Closing; | |
| 20 | + // if false, no need to save the game. | |
| 19 | 21 | bool Modified {get;} |
| 20 | 22 | Clock Clock {get;} |
| 21 | 23 | IClimateController ClimateController {get;} |
| 22 | 24 | string Name {get;set;} |
| 23 | - IPointerHandler ActiveController {get; set;} | |
| 24 | - //World world {get;} | |
| 25 | + | |
| 26 | + //World world {get;} | |
| 25 | 27 | ViewCollection Views {get;} |
| 26 | 28 | //Return if prepare for close the game. |
| 27 | 29 | bool ConfirmClose(); |
| @@ -32,19 +32,25 @@ | ||
| 32 | 32 | protected MainFrame theFrame; |
| 33 | 33 | protected IGameMode _curMode; |
| 34 | 34 | protected IGame _curGame; |
| 35 | + protected ToolCollection tools; | |
| 35 | 36 | /// <summary> |
| 36 | 37 | /// Fired after a new world is loaded/created. |
| 37 | 38 | /// </summary> |
| 38 | - public event EventHandler OnNewGame; | |
| 39 | + public event GameEventHandler OnGameStart; | |
| 40 | + public event GameEventHandler OnGameClose; | |
| 39 | 41 | |
| 40 | 42 | protected GameManager(MainFrame mainFrame) |
| 41 | 43 | { |
| 42 | 44 | this.theFrame = mainFrame; |
| 45 | + this.tools = new ToolCollection(this); | |
| 43 | 46 | theFrame.ActiveViewChanged += new EventHandler<EventArgs>(theFrame_ActiveViewChanged); |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | public IGameMode CurrentMode { get{ return _curMode; } } |
| 47 | 50 | public IGame CurrentGame { get{ return _curGame; } } |
| 51 | + | |
| 52 | + public ToolCollection Tools { get { return tools; } } | |
| 53 | + | |
| 48 | 54 | [Obsolete] |
| 49 | 55 | public void SetGame(IGame newgame, IGameMode mode, bool prompt){} |
| 50 | 56 |
| @@ -54,19 +60,18 @@ | ||
| 54 | 60 | |
| 55 | 61 | public virtual void NewGameFromMap(string name, ITerrainMap map, Calendar cal, IGameMode mode, bool prompt) |
| 56 | 62 | { |
| 57 | - IGame newgame = CreateGame(name, map, cal); | |
| 58 | 63 | if(_curGame != null) |
| 59 | 64 | { |
| 60 | - if( prompt ) | |
| 61 | - if( !ConfirmCloseGame() ) return; | |
| 62 | - else | |
| 63 | - _curGame.Close(); | |
| 65 | + if (prompt) { | |
| 66 | + if (!ConfirmCloseGame()) return; | |
| 67 | + } else { | |
| 68 | + DetachCurrentGame(); | |
| 69 | + } | |
| 70 | + | |
| 64 | 71 | } |
| 65 | - _curGame = newgame; | |
| 72 | + IGame newgame = CreateGame(name, map, cal); | |
| 73 | + AttachCurrentGame(newgame); | |
| 66 | 74 | _curMode = mode; |
| 67 | - //theFrame.SetSubTitle( ); | |
| 68 | - _curGame.Views.OpenNew(); | |
| 69 | - _curGame.Start(); | |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | 77 | protected virtual IGame CreateGame(string name, ITerrainMap map, Calendar cal) { |
| @@ -74,6 +79,32 @@ | ||
| 74 | 79 | return new GameImpl(name, map, cal); |
| 75 | 80 | } |
| 76 | 81 | |
| 82 | + protected virtual void AttachCurrentGame(IGame gm) { | |
| 83 | + _curGame = gm; | |
| 84 | + _curGame.Closing += Game_Closing; | |
| 85 | + _curGame.Start(); | |
| 86 | + if (OnGameStart != null) { | |
| 87 | + OnGameStart(new GameEventArgs(_curGame)); | |
| 88 | + } | |
| 89 | + _curGame.Views.OpenNew(); | |
| 90 | + } | |
| 91 | + | |
| 92 | + void Game_Closing(object sender, EventArgs e) { | |
| 93 | + if (_curGame == sender) { | |
| 94 | + DetachCurrentGame(); | |
| 95 | + } | |
| 96 | + } | |
| 97 | + protected virtual void DetachCurrentGame() { | |
| 98 | + if (!_curGame.Closed) { | |
| 99 | + _curGame.Closing -= Game_Closing; | |
| 100 | + _curGame.Close(); | |
| 101 | + } | |
| 102 | + if (OnGameClose != null) { | |
| 103 | + OnGameClose(new GameEventArgs(_curGame)); | |
| 104 | + } | |
| 105 | + _curGame = null; | |
| 106 | + } | |
| 107 | + | |
| 77 | 108 | public event EventHandler ActiveViewChanged; |
| 78 | 109 | |
| 79 | 110 | /// 使われてない. |
| @@ -13,14 +13,17 @@ | ||
| 13 | 13 | return GlobalModules.GetModule(typeof(IGameViewFactory)) as IGameViewFactory; |
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | - | |
| 16 | + | |
| 17 | + | |
| 17 | 18 | protected List<IView> views; |
| 18 | 19 | protected IGame game; |
| 19 | 20 | protected IView current; |
| 21 | + protected IEnumerable<IPointerHandler> awakeTools; | |
| 20 | 22 | |
| 21 | 23 | public ViewCollection(IGame _game) { |
| 22 | 24 | game = _game; |
| 23 | 25 | views = new List<IView>(); |
| 26 | + awakeTools = new ToolEnumerator(); | |
| 24 | 27 | } |
| 25 | 28 | |
| 26 | 29 | public IGame Game { |
| @@ -88,16 +91,42 @@ | ||
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | protected virtual IView CreateView() { |
| 91 | - IView v = ViewFactory.Create(game, Location.UNPLACED); | |
| 92 | - v.OnClose += new ViewEventHandler(OnViewClose); | |
| 93 | - v.QueryClose += new ViewQueryEventHandler(QueryViewClose); | |
| 94 | + IView v = ViewFactory.Create(game, Location.UNPLACED); | |
| 95 | + v.MouseCursorMove += ViewMouseMove; | |
| 96 | + v.MouseButtonDown += ViewMouseBtnDown; | |
| 97 | + v.MouseButtonUp += ViewMouseBtnUp; | |
| 98 | + v.Activated += ViewActivated; | |
| 99 | + v.OnClose += OnViewClose; | |
| 100 | + v.QueryClose += QueryViewClose; | |
| 94 | 101 | return v; |
| 95 | 102 | } |
| 96 | 103 | |
| 104 | + void ViewActivated(ViewEventArgs ea) { | |
| 105 | + SetActive(ea.View); | |
| 106 | + } | |
| 107 | + | |
| 108 | + void ViewMouseBtnUp(PointerEventArgs pe) { | |
| 109 | + foreach (IPointerHandler h in awakeTools) { | |
| 110 | + h.OnMouseButtonUp(pe); | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + void ViewMouseBtnDown(PointerEventArgs pe) { | |
| 115 | + foreach (IPointerHandler h in awakeTools) { | |
| 116 | + h.OnMouseButtonDown(pe); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + void ViewMouseMove(PointerEventArgs pe) { | |
| 121 | + foreach (IPointerHandler h in awakeTools) { | |
| 122 | + h.OnMouseMove(pe); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + | |
| 97 | 126 | protected virtual void OnViewClose(ViewEventArgs ea) { |
| 98 | 127 | IView v = ea.View; |
| 99 | - v.OnClose -= new ViewEventHandler(OnViewClose); | |
| 100 | - v.QueryClose -= new ViewQueryEventHandler(OnViewClose); | |
| 128 | + v.OnClose -= OnViewClose; | |
| 129 | + v.QueryClose -= OnViewClose; | |
| 101 | 130 | if (PrimaryView == v && !game.Closed) { |
| 102 | 131 | game.Close(); |
| 103 | 132 | } |
| @@ -123,5 +152,16 @@ | ||
| 123 | 152 | return GetEnumerator(); |
| 124 | 153 | } |
| 125 | 154 | #endregion |
| 155 | + | |
| 156 | + class ToolEnumerator : IEnumerable<IPointerHandler> { | |
| 157 | + | |
| 158 | + public IEnumerator<IPointerHandler> GetEnumerator() { | |
| 159 | + return GameManager.theInstance.Tools.EnumAwakeTools(); | |
| 160 | + } | |
| 161 | + | |
| 162 | + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { | |
| 163 | + return GetEnumerator(); | |
| 164 | + } | |
| 165 | + } | |
| 126 | 166 | } |
| 127 | 167 | } |
| @@ -0,0 +1,15 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | + | |
| 5 | +namespace nft.core.game { | |
| 6 | + public delegate void GameEventHandler(GameEventArgs args); | |
| 7 | + | |
| 8 | + public class GameEventArgs : EventArgs{ | |
| 9 | + public readonly IGame Game; | |
| 10 | + public GameEventArgs(IGame game) { | |
| 11 | + this.Game = game; | |
| 12 | + } | |
| 13 | + } | |
| 14 | + | |
| 15 | +} |
| @@ -0,0 +1,106 @@ | ||
| 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 | +using System.Windows.Forms; | |
| 8 | + | |
| 9 | +namespace nft.core.game { | |
| 10 | + public class ToolCollection : IEnumerable<IPointerHandler>{ | |
| 11 | + | |
| 12 | + protected List<IPointerHandler> modelesses; | |
| 13 | + protected List<IPointerHandler> modals; | |
| 14 | + protected IPointerHandler current; | |
| 15 | + protected GameManager manager; | |
| 16 | + | |
| 17 | + public ToolCollection(GameManager gm) { | |
| 18 | + manager = gm; | |
| 19 | + modals = new List<IPointerHandler>(); | |
| 20 | + modelesses = new List<IPointerHandler>(); | |
| 21 | + current = null; | |
| 22 | + manager.OnGameStart += ManagerOnGameStart; | |
| 23 | + manager.OnGameClose += ManagerOnGameClose; | |
| 24 | + } | |
| 25 | + | |
| 26 | + protected virtual void ManagerOnGameStart(GameEventArgs args) { | |
| 27 | + IGame g = args.Game; | |
| 28 | + foreach (IPointerHandler h in this) { | |
| 29 | + h.OnAttach(g); | |
| 30 | + } | |
| 31 | + } | |
| 32 | + | |
| 33 | + protected virtual void ManagerOnGameClose(GameEventArgs args) { | |
| 34 | + IGame g = args.Game; | |
| 35 | + foreach (IPointerHandler h in this) { | |
| 36 | + h.OnDetach(g); | |
| 37 | + } | |
| 38 | + } | |
| 39 | + | |
| 40 | + public virtual IPointerHandler ActiveTool { | |
| 41 | + get { | |
| 42 | + return current; | |
| 43 | + } | |
| 44 | + set { | |
| 45 | + if (value != null && modals.Contains(value)) { | |
| 46 | + current = value; | |
| 47 | + } else { | |
| 48 | + current = null; | |
| 49 | + } | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void Add(IPointerHandler h) { | |
| 54 | + this.Add(h, true); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void Add(IPointerHandler h, bool modal) { | |
| 58 | + if (modal) { | |
| 59 | + modals.Add(h); | |
| 60 | + } else { | |
| 61 | + modelesses.Add(h); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + public void Remove(IPointerHandler h) { | |
| 66 | + this.Remove(h, true); | |
| 67 | + } | |
| 68 | + | |
| 69 | + public void Remove(IPointerHandler h, bool modal) { | |
| 70 | + if (modal) { | |
| 71 | + modals.Remove(h); | |
| 72 | + } else { | |
| 73 | + modelesses.Remove(h); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + public IList<IPointerHandler> ModalTools { | |
| 78 | + get { return new List<IPointerHandler>(modals); } | |
| 79 | + } | |
| 80 | + | |
| 81 | + public IList<IPointerHandler> ModelessTools { | |
| 82 | + get { return new List<IPointerHandler>(modelesses); } | |
| 83 | + } | |
| 84 | + | |
| 85 | + public IEnumerator<IPointerHandler> EnumAwakeTools() { | |
| 86 | + if (current != null) { | |
| 87 | + yield return current; | |
| 88 | + } | |
| 89 | + foreach (IPointerHandler h in modelesses) yield return h; | |
| 90 | + } | |
| 91 | + | |
| 92 | + | |
| 93 | + #region IEnumerable implementation | |
| 94 | + public IEnumerator<IPointerHandler> GetEnumerator() | |
| 95 | + { | |
| 96 | + foreach (IPointerHandler h in modals) yield return h; | |
| 97 | + foreach (IPointerHandler h in modelesses) yield return h; | |
| 98 | + } | |
| 99 | + | |
| 100 | + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
| 101 | + { | |
| 102 | + return GetEnumerator(); | |
| 103 | + } | |
| 104 | + #endregion | |
| 105 | + } | |
| 106 | +} |
| @@ -10,7 +10,8 @@ | ||
| 10 | 10 | protected IGame game; |
| 11 | 11 | protected ISurface surface; |
| 12 | 12 | |
| 13 | - public PointerEventArgs(IGame gm, ISurface surf) { | |
| 13 | + public PointerEventArgs(MouseEventArgs org, IGame gm, ISurface surf) { | |
| 14 | + this.eventOrg = org; | |
| 14 | 15 | this.game = gm; |
| 15 | 16 | this.surface = surf; |
| 16 | 17 | } |
| @@ -3,14 +3,25 @@ | ||
| 3 | 3 | using System.Text; |
| 4 | 4 | using nft.impl.view; |
| 5 | 5 | using nft.core.geometry; |
| 6 | +using nft.core.game; | |
| 7 | +using nft.framework.drawing; | |
| 6 | 8 | |
| 7 | 9 | namespace nft.core.view { |
| 8 | 10 | public delegate void ViewEventHandler(ViewEventArgs ea); |
| 9 | 11 | public delegate void ViewQueryEventHandler(ViewQueryEventArgs ea); |
| 12 | + public delegate void PointerEventHandler(PointerEventArgs pe); | |
| 10 | 13 | public interface IView { |
| 11 | 14 | event ViewEventHandler OnClose; |
| 12 | 15 | event ViewQueryEventHandler QueryClose; |
| 16 | + event ViewEventHandler Activated; | |
| 17 | + event PointerEventHandler MouseCursorMove; | |
| 18 | + event PointerEventHandler MouseButtonDown; | |
| 19 | + event PointerEventHandler MouseButtonUp; | |
| 13 | 20 | |
| 21 | + ISurface Surface { | |
| 22 | + get; | |
| 23 | + } | |
| 24 | + | |
| 14 | 25 | SceneBuilder SceneBuilder { |
| 15 | 26 | get; |
| 16 | 27 | } |
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | <properties name="framework"> |
| 4 | 4 | <properties name="Directories"> |
| 5 | 5 | <property name="Directory '{0}' is not exist. Do you want to create?">{0}は存在しません。 |
| 6 | - 作成しますか?</property> | |
| 6 | +作成しますか?</property> | |
| 7 | 7 | <property name="Failed to create a directory '{0}'. Use default path instead.">{0}は作成できませんでした。 |
| 8 | - 標準の設定を使用します。</property> | |
| 8 | +標準の設定を使用します。</property> | |
| 9 | 9 | </properties> |
| 10 | 10 | <properties name="PluginListDialog"> |
| 11 | 11 | <property name="Uncheck to forbid cpu using this plug-in.">コンピューターに使わせたくないプラグインは、 |
| @@ -13,36 +13,31 @@ | ||
| 13 | 13 | <property name="This contribution cannot invalidate.">このコントリビューションは無効化できません。</property> |
| 14 | 14 | </properties> |
| 15 | 15 | <properties name="nft.framework.plugin"> |
| 16 | - <property name="Too many plug-in load errors! Check out remaining errors in the 'Plug-in List'."> | |
| 17 | - プラグインロードエラーが多すぎます。以降のエラーは省略します。 | |
| 18 | - エラーの発生したプラグインを確認するには、プラグイン一覧をご覧下さい。 | |
| 16 | + <property name="Too many plug-in load errors! Check out remaining errors in the 'Plug-in List'.">プラグインロードエラーが多すぎます。以降のエラーは省略します。 | |
| 17 | +エラーの発生したプラグインを確認するには、プラグイン一覧をご覧下さい。 | |
| 19 | 18 | </property> |
| 20 | - <property name="Dependent plug-in:{1} (required for the plug-in:{0}) is not found."> | |
| 21 | - プラグイン{0}に必要な | |
| 22 | - プラグイン{1}が見つかりません。 | |
| 19 | + <property name="Dependent plug-in:{1} (required for the plug-in:{0}) is not found.">プラグイン{0}に必要な | |
| 20 | +プラグイン{1}が見つかりません。 | |
| 23 | 21 | </property> |
| 24 | - <property name="Failed to load contribution[{1}] (ID={2}) from the file '{0}'."> | |
| 25 | - ファイル{0} | |
| 26 | - からのコントリビューション[{1}]のロードに失敗しました。 | |
| 27 | - ID={2} | |
| 22 | + <property name="Failed to load contribution[{1}] (ID={2}) from the file '{0}'.">ファイル {0} | |
| 23 | +からのコントリビューション[{1}]のロードに失敗しました。 | |
| 24 | + ID={2} | |
| 28 | 25 | </property> |
| 29 | 26 | <property name="Failed to load plug-in:{0}.">プラグイン{0}がロードできませんでした。</property> |
| 30 | - <property name="Failed to initialize contribution[{1}] in the plug-in:{0}."> | |
| 31 | - プラグイン{0}内のコントリビューション[{1}]が初期化できませんでした。 | |
| 32 | - ID={2} | |
| 27 | + <property name="Failed to initialize contribution[{1}] in the plug-in:{0}.">プラグイン{0}内のコントリビューション[{1}]が初期化できませんでした。 | |
| 28 | + ID={2} | |
| 33 | 29 | </property> |
| 34 | - <property name="Failed to create CommandEntity[type={0}, class={1}, method={2}]."> | |
| 35 | - コマンドコントリビューションを初期化できません。 | |
| 36 | - Type={0} | |
| 37 | - Class={1} | |
| 38 | - Method={2} | |
| 30 | + <property name="Failed to create CommandEntity[type={0}, class={1}, method={2}].">コマンドコントリビューションを初期化できません。 | |
| 31 | + Type={0} | |
| 32 | + Class={1} | |
| 33 | + Method={2} | |
| 39 | 34 | </property> |
| 40 | 35 | <property name="An attribute '{1}' is required for the node '{0}'.">XMLノード[{0}]には[{1}]属性が必要です。 |
| 41 | - ソース:{2}</property> | |
| 36 | + ソース:{2}</property> | |
| 42 | 37 | <property name="Failed to create an instance of the class '{0}'.">指定されたクラス[{0}]のインスタンス作成に失敗しました。 |
| 43 | - ソース:{1}</property> | |
| 38 | + ソース:{1}</property> | |
| 44 | 39 | <property name="Cannot cast the class'{0}' to the class'{1}'.">クラス[{0}]を[{1}]にキャストできません。 |
| 45 | - ソース:{2}</property> | |
| 40 | + ソース:{2}</property> | |
| 46 | 41 | </properties> |
| 47 | 42 | <properties name="GlobalModules"> |
| 48 | 43 | <property name="ERROR while loading a core module.">コア・モジュール読み込みエラー</property> |
| @@ -98,12 +98,14 @@ | ||
| 98 | 98 | public static Type loadTypeFromManifest( ParamsReader e ) { |
| 99 | 99 | string typeName = e["name"].InnerText; |
| 100 | 100 | Assembly a; |
| 101 | + string s; | |
| 101 | 102 | ParamsReader cb = e["codebase"]; |
| 102 | 103 | if( cb.IsNull ) { |
| 103 | 104 | // load the class from the FreeTrain.Main.dll |
| 104 | 105 | a = Assembly.GetExecutingAssembly(); |
| 106 | + s = a.ManifestModule.Name; | |
| 105 | 107 | } else { |
| 106 | - string s = cb.InnerText; | |
| 108 | + s = cb.InnerText; | |
| 107 | 109 | // if start with '.', it's abbreviation of nft.XXX.dll |
| 108 | 110 | // at the application base directory. |
| 109 | 111 | if(s.StartsWith(".")) |
| @@ -117,7 +119,16 @@ | ||
| 117 | 119 | } |
| 118 | 120 | PluginSerializationBinder.registerAssembly(a); |
| 119 | 121 | //Debug.Assert(typeName != null); |
| 120 | - return a.GetType(typeName,true); | |
| 122 | + try | |
| 123 | + { | |
| 124 | + return a.GetType(typeName, true); | |
| 125 | + } | |
| 126 | + catch (TypeLoadException te) | |
| 127 | + { | |
| 128 | + string msg = string.Format("[{1}]にクラス名='{0}'が見つかりませんでした。表記を確認してください。", typeName, s); | |
| 129 | + Debug.WriteLine(msg); | |
| 130 | + throw new FormatException(msg, te); | |
| 131 | + } | |
| 121 | 132 | } |
| 122 | 133 | |
| 123 | 134 | public static Type loadTypeFromManifest(ParamsReader e, Type required) { |
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | /// <returns></returns> |
| 57 | 57 | public static string F(string name, params object[] args) { |
| 58 | 58 | string ret = _T1(name, ToGroupCandidates(1), true); |
| 59 | - return String.Format(ret,ToString(args)); | |
| 59 | + return String.Format(ret,args); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /// <summary> |
| @@ -6,30 +6,14 @@ | ||
| 6 | 6 | using WeifenLuo.WinFormsUI.Docking; |
| 7 | 7 | using nft.ui.mainframe; |
| 8 | 8 | using nft.framework.plugin; |
| 9 | +using nft.ui.docking; | |
| 9 | 10 | |
| 10 | 11 | namespace nft.ui.command { |
| 11 | 12 | /// <summary> |
| 12 | 13 | /// |
| 13 | 14 | /// </summary> |
| 14 | - public class SubformCommand : ICommandEntity_Old { | |
| 15 | - static SubformCommand() { | |
| 16 | - ((MainFrame)Main.mainFrame).DockingManager.RegisterResolver(ResolveDockContent); | |
| 17 | - } | |
| 15 | + public class SubformCommand : ICommandEntity_Old, IDockContentFactory { | |
| 18 | 16 | |
| 19 | - public static DockContent ResolveDockContent(string persist) { | |
| 20 | - int n = persist.IndexOf(CtbSubform.SepalatorPersist); | |
| 21 | - string id = persist.Substring(0, n); | |
| 22 | - string nam = persist.Substring(n + CtbSubform.SepalatorPersist.Length); | |
| 23 | - CtbCommandEntity ctb = PluginManager.theInstance.GetContribution(id) as CtbCommandEntity; | |
| 24 | - if (ctb != null) { | |
| 25 | - SubformCommand sc = ctb.CommandEntity as SubformCommand; | |
| 26 | - if (sc != null) { | |
| 27 | - return sc.innerCtb.GetContent(nam, true).Parent as DockContent; | |
| 28 | - } | |
| 29 | - } | |
| 30 | - return null; | |
| 31 | - } | |
| 32 | - | |
| 33 | 17 | readonly CtbSubform innerCtb; |
| 34 | 18 | |
| 35 | 19 | public SubformCommand(ParamsReader e) { |
| @@ -39,5 +23,9 @@ | ||
| 39 | 23 | public void CommandExecuted(CommandUI_Old cmdUI, object sender) { |
| 40 | 24 | innerCtb.Show(""); |
| 41 | 25 | } |
| 26 | + | |
| 27 | + public DockContent CreateDockContent(string subkey) { | |
| 28 | + return innerCtb.GetContent(subkey, true).Parent as DockContent; | |
| 29 | + } | |
| 42 | 30 | } |
| 43 | 31 | } |
| @@ -26,6 +26,8 @@ | ||
| 26 | 26 | resolvers = new List<ContentsResolver>(); |
| 27 | 27 | DockPanelCustomizer.SetupFactories(dockPanel); |
| 28 | 28 | deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString); |
| 29 | + // Regsiter default resolver which find from contributions. | |
| 30 | + RegisterResolver(new ContentsResolver(DockContentContributionResolver.ResolveDockContent)); | |
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | protected static String LayoutFilePath { |
| @@ -33,7 +35,7 @@ | ||
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | public void RegisterResolver(ContentsResolver cr) { |
| 36 | - resolvers.Add(cr); | |
| 38 | + resolvers.Insert(0,cr); // latest order | |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | public void SaveLayout(){ |
| @@ -55,7 +57,7 @@ | ||
| 55 | 57 | } |
| 56 | 58 | |
| 57 | 59 | public void LoadLayout() { |
| 58 | - dockPanel.LoadFromXml(LayoutFilePath, deserializeDockContent); | |
| 60 | + dockPanel.LoadFromXml(LayoutFilePath, deserializeDockContent); | |
| 59 | 61 | } |
| 60 | 62 | |
| 61 | 63 | internal protected DockPanel DockPanel { get { return dockPanel; } } |
| @@ -20,6 +20,14 @@ | ||
| 20 | 20 | public enum StyleOption : int { Default = 0, NoShrink = 1, NoClose = 2, Tempolaly = 4, NoSaveLayout = 8 } |
| 21 | 21 | |
| 22 | 22 | public abstract class SubformHolder { |
| 23 | + protected static List<SubformHolder> all_holders = new List<SubformHolder>(); | |
| 24 | + | |
| 25 | + public static IList<SubformHolder> LiveHolders { | |
| 26 | + get { | |
| 27 | + return all_holders; | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 23 | 31 | /// <summary> Fired when the content is closed by the user. </summary> |
| 24 | 32 | public event EventHandler OnHidden; |
| 25 | 33 | /// <summary> Fired when the content is shown by the user.</summary> |
| @@ -114,6 +122,7 @@ | ||
| 114 | 122 | } |
| 115 | 123 | |
| 116 | 124 | void cmpDocking_Disposed(object sender, EventArgs e) { |
| 125 | + all_holders.Remove(this); | |
| 117 | 126 | if (OnDisposed != null) OnDisposed(this, e); |
| 118 | 127 | content = null; |
| 119 | 128 | cmpDocking = null; |
| @@ -133,6 +142,9 @@ | ||
| 133 | 142 | setupDockComponent(); |
| 134 | 143 | SetContent(); |
| 135 | 144 | } |
| 145 | + if (!all_holders.Contains(this)) { | |
| 146 | + all_holders.Add(this); | |
| 147 | + } | |
| 136 | 148 | cmpDocking.Show(getDockPanel()); |
| 137 | 149 | /* 何で必要だったか忘れた… |
| 138 | 150 | if (cmpDocking.DockState == DockState.Hidden || cmpDocking.DockState == DockState.Unknown) { |
| @@ -0,0 +1,27 @@ | ||
| 1 | +using nft.framework.plugin; | |
| 2 | +using System; | |
| 3 | +using System.Collections.Generic; | |
| 4 | +using System.Text; | |
| 5 | +using WeifenLuo.WinFormsUI.Docking; | |
| 6 | + | |
| 7 | +namespace nft.ui.docking { | |
| 8 | + public interface IDockContentFactory { | |
| 9 | + DockContent CreateDockContent(string subkey); | |
| 10 | + } | |
| 11 | + | |
| 12 | + public class DockContentContributionResolver { | |
| 13 | + public static readonly string SepalatorPersist = "::"; | |
| 14 | + public static DockContent ResolveDockContent(string persist) { | |
| 15 | + int n = persist.IndexOf(SepalatorPersist); | |
| 16 | + string id = persist.Substring(0, n); | |
| 17 | + string nam = persist.Substring(n + SepalatorPersist.Length); | |
| 18 | + Contribution ctb = PluginManager.theInstance.GetContribution(id); | |
| 19 | + IDockContentFactory fct = ctb as IDockContentFactory; | |
| 20 | + if (fct != null) { | |
| 21 | + return fct.CreateDockContent(nam); | |
| 22 | + } else { | |
| 23 | + return null; | |
| 24 | + } | |
| 25 | + } | |
| 26 | + } | |
| 27 | +} |
| @@ -11,10 +11,20 @@ | ||
| 11 | 11 | bool Visible { get; set; } |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public interface IxControl<T> : IxControl | |
| 14 | + public delegate bool Validator<T>(T testVal, T prevVal); | |
| 15 | + | |
| 16 | + public interface IxInput<T> : IxControl | |
| 15 | 17 | { |
| 16 | 18 | T Value { get; set; } |
| 17 | 19 | bool IsValid(); // return true if the value is valid. |
| 20 | + Validator<T> validator { get; set; } | |
| 18 | 21 | event XFormEvent ValueChanged; |
| 19 | 22 | } |
| 23 | + | |
| 24 | + public interface IxControlGroup : IxControl | |
| 25 | + { | |
| 26 | + IxControl this[string name] {get;} | |
| 27 | + IxInput<T> Get<T>(string name); | |
| 28 | + IEnumerator<IxControl> EnumChildren(); | |
| 29 | + } | |
| 20 | 30 | } |
| @@ -6,12 +6,8 @@ | ||
| 6 | 6 | { |
| 7 | 7 | public delegate bool XFormEvent(IxForm sender, IxControl related); |
| 8 | 8 | |
| 9 | - public interface IxForm | |
| 9 | + public interface IxForm : IxControlGroup | |
| 10 | 10 | { |
| 11 | - string Name { get; } | |
| 12 | - IxControl Find(string name); | |
| 13 | - IEnumerator<IxControl> EnumControls(); | |
| 14 | - bool Visible { get; set; } | |
| 15 | 11 | |
| 16 | 12 | event XFormEvent OnOpen; |
| 17 | 13 | event XFormEvent OnClose; |
| @@ -58,10 +58,14 @@ | ||
| 58 | 58 | // } |
| 59 | 59 | infoText.Append("Operating System", Environment.OSVersion.ToString()); |
| 60 | 60 | GlobalMemoryInfo info = new GlobalMemoryInfo(); |
| 61 | + string proctxt = string.Format("{0} (Cores={1})", Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER") | |
| 62 | + ,Environment.ProcessorCount); | |
| 63 | + infoText.Append("Processor", proctxt); | |
| 61 | 64 | string memtext = string.Format("Physical {0:#,##0,,}MB/{1:#,##0,,}MB, Virtual {2:#,##0,,}MB/{3:#,##0,,}MB", |
| 62 | 65 | info.PhysicalMemAvailable,info.PhysicalMemTotal, |
| 63 | 66 | info.VirtualMemAvailable,info.VirtualMemTotal); |
| 64 | 67 | infoText.Append("System Memory", memtext); |
| 68 | + infoText.Append("Process Context Memory", string.Format("{0:#,##,,}MB", Environment.WorkingSet)); | |
| 65 | 69 | if (OnSystemInfoRequested != null) { |
| 66 | 70 | Delegate[] delegates = OnSystemInfoRequested.GetInvocationList(); |
| 67 | 71 | foreach (Delegate d in delegates) { |
| @@ -6,6 +6,8 @@ | ||
| 6 | 6 | using nft.framework; |
| 7 | 7 | using nft.framework.plugin; |
| 8 | 8 | using nft.util; |
| 9 | +using nft.ui.docking; | |
| 10 | +using WeifenLuo.WinFormsUI.Docking; | |
| 9 | 11 | |
| 10 | 12 | namespace nft.contributions.ui |
| 11 | 13 | { |
| @@ -12,7 +14,7 @@ | ||
| 12 | 14 | /// <summary> |
| 13 | 15 | /// CtbCommandEntity の概要の説明です。 |
| 14 | 16 | /// </summary> |
| 15 | - public class CtbCommandEntity : Contribution | |
| 17 | + public class CtbCommandEntity : Contribution, IDockContentFactory | |
| 16 | 18 | { |
| 17 | 19 | protected enum MethodType { Static, Instance, Constructor }; |
| 18 | 20 | protected readonly string commandType; |
| @@ -104,5 +106,16 @@ | ||
| 104 | 106 | throw new Exception(string.Format(templ,targetType.FullName,path),e); |
| 105 | 107 | } |
| 106 | 108 | } |
| 109 | + | |
| 110 | + /// <summary> | |
| 111 | + /// Called from DockManagerEx as a owner of SubFrom command. | |
| 112 | + /// </summary> | |
| 113 | + /// <param name="subkey"></param> | |
| 114 | + /// <returns></returns> | |
| 115 | + public DockContent CreateDockContent(string subkey) { | |
| 116 | + IDockContentFactory factory = entity as IDockContentFactory; | |
| 117 | + return factory!=null ? factory.CreateDockContent(subkey) : null; | |
| 118 | + } | |
| 119 | + | |
| 107 | 120 | } |
| 108 | 121 | } |
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | /// sub-form can float or docking. (can auto-shrink or no-shrink while docking). |
| 20 | 20 | /// you can forbid some of style to each form by specifing several options. |
| 21 | 21 | /// </summary> |
| 22 | - public class CtbSubform : Contribution | |
| 22 | + public class CtbSubform : Contribution, IDockContentFactory | |
| 23 | 23 | { |
| 24 | 24 | public static class PredefinedOptions { |
| 25 | 25 | public static readonly string Multiple = "multiple"; |
| @@ -30,23 +30,7 @@ | ||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public static readonly string SepalatorPersist = "::"; |
| 33 | - | |
| 34 | - static CtbSubform() { | |
| 35 | - ((MainFrame)Main.mainFrame).DockingManager.RegisterResolver(ResolveDockContent); | |
| 36 | - } | |
| 37 | - | |
| 38 | - public static DockContent ResolveDockContent(string persist) { | |
| 39 | - int n = persist.IndexOf(SepalatorPersist); | |
| 40 | - string id = persist.Substring(0, n); | |
| 41 | - string nam = persist.Substring(n + SepalatorPersist.Length); | |
| 42 | - CtbSubform ctb = PluginManager.theInstance.GetContribution(id) as CtbSubform; | |
| 43 | - if (ctb != null) { | |
| 44 | - return ctb.GetContent(nam, true).Parent as DockContent; | |
| 45 | - } else { | |
| 46 | - return null; | |
| 47 | - } | |
| 48 | - } | |
| 49 | - | |
| 33 | + | |
| 50 | 34 | /// <summary> |
| 51 | 35 | /// |
| 52 | 36 | /// </summary> |
| @@ -112,7 +96,7 @@ | ||
| 112 | 96 | return GetContent(name, true); |
| 113 | 97 | } |
| 114 | 98 | |
| 115 | - internal protected SubformHolder GetHolder(string name, bool create) { | |
| 99 | + internal protected virtual SubformHolder GetHolder(string name, bool create) { | |
| 116 | 100 | string key = IsSingleton ? "" : name; |
| 117 | 101 | SubformHolder holder; |
| 118 | 102 | if (!contentMap.TryGetValue(key, out holder) && create) { |
| @@ -128,8 +112,12 @@ | ||
| 128 | 112 | Control c = (Control)Activator.CreateInstance(windowType); |
| 129 | 113 | c.Name = name; |
| 130 | 114 | return c; |
| 131 | - } | |
| 115 | + } | |
| 132 | 116 | |
| 117 | + public DockContent CreateDockContent(string subkey) { | |
| 118 | + return GetContent(subkey, true).Parent as DockContent; | |
| 119 | + } | |
| 120 | + | |
| 133 | 121 | protected IList<string> options; |
| 134 | 122 | /// <summary> |
| 135 | 123 | /// enumerate all option strings |
| @@ -182,7 +170,7 @@ | ||
| 182 | 170 | /// Show sub-form window. |
| 183 | 171 | /// </summary> |
| 184 | 172 | /// <param name="name">key for muliple forms (ignored for singleton)</param> |
| 185 | - public void Show(string name) { | |
| 173 | + public virtual void Show(string name) { | |
| 186 | 174 | SubformHolder h = GetHolder(name, true); |
| 187 | 175 | h.Show(); |
| 188 | 176 | } |
| @@ -191,7 +179,7 @@ | ||
| 191 | 179 | /// Hide sub-form window. 'Suicidal' form will be disposed. |
| 192 | 180 | /// </summary> |
| 193 | 181 | /// <param name="name">key for muliple forms (ignored for singleton)</param> |
| 194 | - public void Hide(string name) { | |
| 182 | + public virtual void Hide(string name) { | |
| 195 | 183 | SubformHolder h = GetHolder(name, false); |
| 196 | 184 | if (h != null) { |
| 197 | 185 | h.Hide(); |
| @@ -237,6 +225,7 @@ | ||
| 237 | 225 | } |
| 238 | 226 | |
| 239 | 227 | public class CtbFormHolder : SubformHolder { |
| 228 | + | |
| 240 | 229 | public static CtbFormHolder Create(CtbSubform ctb, string key) { |
| 241 | 230 | LayoutState state = LayoutState.Right; |
| 242 | 231 | LayoutStyle style = LayoutStyle.AllSide | LayoutStyle.Float; |
| @@ -258,5 +247,6 @@ | ||
| 258 | 247 | } |
| 259 | 248 | |
| 260 | 249 | } |
| 261 | - } | |
| 250 | + | |
| 251 | + } | |
| 262 | 252 | } |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | using System; |
| 2 | +using System.Diagnostics; | |
| 2 | 3 | using System.Runtime.InteropServices; |
| 3 | 4 | |
| 4 | 5 | namespace nft.win32util |
| @@ -9,36 +10,41 @@ | ||
| 9 | 10 | /// </summary> |
| 10 | 11 | public class GlobalMemoryInfo |
| 11 | 12 | { |
| 13 | + [return: MarshalAs(UnmanagedType.Bool)] | |
| 14 | + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
| 15 | + extern static bool GlobalMemoryStatusEx([In,Out] MemoryStatusEx lpBuffer); | |
| 16 | + | |
| 17 | + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] | |
| 18 | + public class MemoryStatusEx { | |
| 19 | + public uint dwLength; | |
| 20 | + public uint dwMemoryLoad; | |
| 21 | + public ulong ullTotalPhys; // physical memory total | |
| 22 | + public ulong ullAvailPhys; // physical memory available | |
| 23 | + public ulong ullTotalPageFile; // page files total | |
| 24 | + public ulong ullAvailPageFile; // page files available | |
| 25 | + public ulong ullTotalVirtual; // virtual memory total | |
| 26 | + public ulong ullAvailVirtual; // virtual memory available | |
| 27 | + public ulong ullAvailExtendedVirtual; | |
| 28 | + public MemoryStatusEx() { | |
| 29 | + this.dwLength = (uint)Marshal.SizeOf(typeof(MemoryStatusEx)); | |
| 30 | + } | |
| 31 | + } | |
| 12 | 32 | |
| 13 | - [DllImport("kernel32.dll")] | |
| 14 | - extern static void GlobalMemoryStatus(ref MemoryStatus lpBuffer) ; | |
| 33 | + private readonly MemoryStatusEx msinfo; | |
| 15 | 34 | |
| 16 | - struct MemoryStatus | |
| 17 | - { | |
| 18 | - public int dwLength ; | |
| 19 | - public int dwMemoryLoad ; | |
| 20 | - public int dwTotalPhys ; // physical memory total | |
| 21 | - public int dwAvailPhys ; // physical memory available | |
| 22 | - public int dwTotalPageFile ; // page files total | |
| 23 | - public int dwAvailPageFile ; // page files available | |
| 24 | - public int dwTotalVirtual ; // virtual memory total | |
| 25 | - public int dwAvailVirtual ; // virtual memory available | |
| 26 | - } | |
| 27 | - | |
| 28 | - private readonly MemoryStatus msinfo; | |
| 29 | - | |
| 30 | 35 | public GlobalMemoryInfo() |
| 31 | 36 | { |
| 32 | - msinfo = new MemoryStatus(); | |
| 33 | - msinfo.dwLength = Marshal.SizeOf(msinfo); | |
| 34 | - GlobalMemoryStatus(ref msinfo); | |
| 37 | + msinfo = new MemoryStatusEx(); | |
| 38 | + if (!GlobalMemoryStatusEx(msinfo)) { | |
| 39 | + Debug.WriteLine(Marshal.GetLastWin32Error()); | |
| 40 | + } | |
| 35 | 41 | } |
| 36 | 42 | |
| 37 | - public int PhysicalMemTotal { get { return msinfo.dwTotalPhys; } } | |
| 38 | - public int PhysicalMemAvailable { get { return msinfo.dwAvailPhys; } } | |
| 39 | - public int PageFileTotal { get { return msinfo.dwTotalPageFile; } } | |
| 40 | - public int PageFileAvailable { get { return msinfo.dwAvailPageFile; } } | |
| 41 | - public int VirtualMemTotal { get { return msinfo.dwTotalVirtual; } } | |
| 42 | - public int VirtualMemAvailable { get { return msinfo.dwAvailVirtual; } } | |
| 43 | + public ulong PhysicalMemTotal { get { return msinfo.ullTotalPhys; } } | |
| 44 | + public ulong PhysicalMemAvailable { get { return msinfo.ullAvailPhys; } } | |
| 45 | + public ulong PageFileTotal { get { return msinfo.ullTotalPageFile; } } | |
| 46 | + public ulong PageFileAvailable { get { return msinfo.ullAvailPageFile; } } | |
| 47 | + public ulong VirtualMemTotal { get { return msinfo.ullTotalVirtual; } } | |
| 48 | + public ulong VirtualMemAvailable { get { return msinfo.ullAvailVirtual; } } | |
| 43 | 49 | } |
| 44 | 50 | } |
| @@ -47,20 +47,30 @@ | ||
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public IxControl Find(string name) { | |
| 51 | - IxControl c; | |
| 52 | - if (!ctrCache.TryGetValue(name, out c)) { | |
| 53 | - Control c0 = entity.Controls[name]; | |
| 54 | - if (c0 != null) { | |
| 55 | - c = CreateWrapperFor(c0); | |
| 56 | - ctrCache.Add(name, c); | |
| 50 | + public IxControl this[string name] { | |
| 51 | + get | |
| 52 | + { | |
| 53 | + IxControl c; | |
| 54 | + if (!ctrCache.TryGetValue(name, out c)) | |
| 55 | + { | |
| 56 | + Control c0 = entity.Controls[name]; | |
| 57 | + if (c0 != null) | |
| 58 | + { | |
| 59 | + c = CreateWrapperFor(c0); | |
| 60 | + ctrCache.Add(name, c); | |
| 61 | + } | |
| 57 | 62 | } |
| 63 | + return c; | |
| 58 | 64 | } |
| 59 | - return c; | |
| 60 | 65 | } |
| 61 | 66 | |
| 67 | + public IxInput<T> Get<T>(string name) | |
| 68 | + { | |
| 69 | + return this[name] as IxInput<T>; | |
| 70 | + } | |
| 71 | + | |
| 62 | 72 | protected IxControl Find(Control c) { |
| 63 | - return Find(c.Name); | |
| 73 | + return this[c.Name]; | |
| 64 | 74 | } |
| 65 | 75 | |
| 66 | 76 | protected WinControlWrapper CreateWrapperFor(Control c) { |
| @@ -69,7 +79,7 @@ | ||
| 69 | 79 | return w; |
| 70 | 80 | } |
| 71 | 81 | |
| 72 | - public IEnumerator<IxControl> EnumControls() { | |
| 82 | + public IEnumerator<IxControl> EnumChildren() { | |
| 73 | 83 | return new ControlEnumerator(this).GetEnumerator(); |
| 74 | 84 | } |
| 75 | 85 |
| @@ -93,6 +103,19 @@ | ||
| 93 | 103 | } |
| 94 | 104 | } |
| 95 | 105 | |
| 106 | + | |
| 107 | + public bool Enabled | |
| 108 | + { | |
| 109 | + get | |
| 110 | + { | |
| 111 | + throw new NotImplementedException(); | |
| 112 | + } | |
| 113 | + set | |
| 114 | + { | |
| 115 | + throw new NotImplementedException(); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 96 | 119 | public bool Visible { |
| 97 | 120 | get { |
| 98 | 121 | return entity.Visible; |
| @@ -111,5 +134,6 @@ | ||
| 111 | 134 | public event XFormEvent ControlValuesChanged; |
| 112 | 135 | |
| 113 | 136 | public event XFormEvent OnApply; |
| 137 | + | |
| 114 | 138 | } |
| 115 | 139 | } |
| @@ -0,0 +1,71 @@ | ||
| 1 | +namespace nft.ui.core | |
| 2 | +{ | |
| 3 | + partial class InspectorTool | |
| 4 | + { | |
| 5 | + /// <summary> | |
| 6 | + /// 必要なデザイナー変数です。 | |
| 7 | + /// </summary> | |
| 8 | + private System.ComponentModel.IContainer components = null; | |
| 9 | + | |
| 10 | + /// <summary> | |
| 11 | + /// 使用中のリソースをすべてクリーンアップします。 | |
| 12 | + /// </summary> | |
| 13 | + /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param> | |
| 14 | + protected override void Dispose(bool disposing) | |
| 15 | + { | |
| 16 | + if (disposing && (components != null)) | |
| 17 | + { | |
| 18 | + components.Dispose(); | |
| 19 | + } | |
| 20 | + base.Dispose(disposing); | |
| 21 | + } | |
| 22 | + | |
| 23 | + #region コンポーネント デザイナーで生成されたコード | |
| 24 | + | |
| 25 | + /// <summary> | |
| 26 | + /// デザイナー サポートに必要なメソッドです。このメソッドの内容を | |
| 27 | + /// コード エディターで変更しないでください。 | |
| 28 | + /// </summary> | |
| 29 | + private void InitializeComponent() | |
| 30 | + { | |
| 31 | + this.lbStatus = new System.Windows.Forms.Label(); | |
| 32 | + this.renderViewPanel = new nft.framework.drawing.RenderViewPanel(); | |
| 33 | + this.SuspendLayout(); | |
| 34 | + // | |
| 35 | + // lbStatus | |
| 36 | + // | |
| 37 | + this.lbStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
| 38 | + this.lbStatus.Dock = System.Windows.Forms.DockStyle.Bottom; | |
| 39 | + this.lbStatus.Location = new System.Drawing.Point(0, 166); | |
| 40 | + this.lbStatus.Name = "lbStatus"; | |
| 41 | + this.lbStatus.Size = new System.Drawing.Size(200, 74); | |
| 42 | + this.lbStatus.TabIndex = 3; | |
| 43 | + this.lbStatus.Text = "..."; | |
| 44 | + // | |
| 45 | + // renderViewPanel | |
| 46 | + // | |
| 47 | + this.renderViewPanel.Dock = System.Windows.Forms.DockStyle.Fill; | |
| 48 | + this.renderViewPanel.Location = new System.Drawing.Point(0, 0); | |
| 49 | + this.renderViewPanel.Name = "renderViewPanel"; | |
| 50 | + this.renderViewPanel.Size = new System.Drawing.Size(200, 240); | |
| 51 | + this.renderViewPanel.SurfaceUsage = nft.framework.drawing.SurfaceUsage.Normal; | |
| 52 | + this.renderViewPanel.TabIndex = 2; | |
| 53 | + // | |
| 54 | + // InspectorTool | |
| 55 | + // | |
| 56 | + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); | |
| 57 | + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; | |
| 58 | + this.Controls.Add(this.lbStatus); | |
| 59 | + this.Controls.Add(this.renderViewPanel); | |
| 60 | + this.Name = "InspectorTool"; | |
| 61 | + this.Size = new System.Drawing.Size(200, 240); | |
| 62 | + this.ResumeLayout(false); | |
| 63 | + | |
| 64 | + } | |
| 65 | + | |
| 66 | + #endregion | |
| 67 | + | |
| 68 | + private System.Windows.Forms.Label lbStatus; | |
| 69 | + private framework.drawing.RenderViewPanel renderViewPanel; | |
| 70 | + } | |
| 71 | +} |
| @@ -0,0 +1,88 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.ComponentModel; | |
| 4 | +using System.Drawing; | |
| 5 | +using System.Data; | |
| 6 | +using System.Text; | |
| 7 | +using System.Windows.Forms; | |
| 8 | +using nft.core.game; | |
| 9 | +using nft.core.view; | |
| 10 | +using nft.impl.view; | |
| 11 | +using nft.framework.drawing; | |
| 12 | +using nft.impl.game; | |
| 13 | +using Geocon = nft.core.geometry.GeometricConstants; | |
| 14 | + | |
| 15 | +namespace nft.ui.core | |
| 16 | +{ | |
| 17 | + public partial class InspectorTool : UserControl, IPointerHandler | |
| 18 | + { | |
| 19 | + public InspectorTool() | |
| 20 | + { | |
| 21 | + InitializeComponent(); | |
| 22 | + } | |
| 23 | + | |
| 24 | + protected override void OnLoad(EventArgs e) | |
| 25 | + { | |
| 26 | + base.OnLoad(e); | |
| 27 | + GameManager.theInstance.Tools.Add(this, false); | |
| 28 | + } | |
| 29 | + | |
| 30 | + #region IPointerHandler implementation | |
| 31 | + protected IGame game; | |
| 32 | + public void OnAttach(IGame g) | |
| 33 | + { | |
| 34 | + this.game = g; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void OnDetach(IGame g) | |
| 38 | + { | |
| 39 | + this.game = null; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void OnMouseButtonDown(PointerEventArgs args) | |
| 43 | + { | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void OnMouseButtonUp(PointerEventArgs args) | |
| 47 | + { | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void OnMouseMove(PointerEventArgs args) | |
| 51 | + { | |
| 52 | + IView view = args.Game.Views.ActiveView; | |
| 53 | + Point pos = args.OriginalEventArgs.Location; | |
| 54 | + SelectionInfo si = view.SceneBuilder.GetObjectAt(pos); | |
| 55 | + if (si != null) { | |
| 56 | + if (si.Polygon != null) { | |
| 57 | + lbStatus.Text = String.Format("HT={0:X6},PID={1:X6}", si.HitTestValue, si.Polygon.ID); | |
| 58 | + } else { | |
| 59 | + lbStatus.Text = String.Format("HT={0:X6},PID=N/A", si.HitTestValue); | |
| 60 | + } | |
| 61 | + this.renderViewPanel.Surface.Objects = ToRenderObjects(si); | |
| 62 | + } else { | |
| 63 | + lbStatus.Text = "N/A"; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + protected IEnumerable<I3DObject> ToRenderObjects(SelectionInfo si) { | |
| 68 | + if (si.TerrainPiece != null) { | |
| 69 | + int x = si.Location.X; | |
| 70 | + int y = si.Location.Y; | |
| 71 | + int h = si.TerrainPiece.BaseHeight * Geocon.UnitHeightPixel; | |
| 72 | + IEnumerable<I3DObject> terrains = si.SceneBuilder.GetTerrainsAt(x, y); | |
| 73 | + x *= Geocon.UnitWidthPixel; | |
| 74 | + y *= Geocon.UnitWidthPixel; | |
| 75 | + PointF3D pt; | |
| 76 | + foreach (I3DObject obj in terrains) { | |
| 77 | + ITerrainPlate p = obj as ITerrainPlate; | |
| 78 | + pt = p.Location; | |
| 79 | + p.Location = new PointF3D(pt.X - x, pt.Y - y, pt.Z - h); | |
| 80 | + yield return p; | |
| 81 | + } | |
| 82 | + | |
| 83 | + } | |
| 84 | + yield break; | |
| 85 | + } | |
| 86 | + #endregion | |
| 87 | + } | |
| 88 | +} |
| @@ -25,19 +25,10 @@ | ||
| 25 | 25 | /// the contents of this method with the code editor. |
| 26 | 26 | /// </summary> |
| 27 | 27 | private void InitializeComponent() { |
| 28 | + this.lbStatus = new System.Windows.Forms.Label(); | |
| 28 | 29 | this.renderViewPanel = new nft.framework.drawing.RenderViewPanel(); |
| 29 | - this.lbStatus = new System.Windows.Forms.Label(); | |
| 30 | 30 | this.SuspendLayout(); |
| 31 | 31 | // |
| 32 | - // renderViewPanel | |
| 33 | - // | |
| 34 | - this.renderViewPanel.Dock = System.Windows.Forms.DockStyle.Fill; | |
| 35 | - this.renderViewPanel.Location = new System.Drawing.Point(0, 0); | |
| 36 | - this.renderViewPanel.Name = "renderViewPanel"; | |
| 37 | - this.renderViewPanel.Size = new System.Drawing.Size(232, 268); | |
| 38 | - this.renderViewPanel.SurfaceUsage = nft.framework.drawing.SurfaceUsage.Normal; | |
| 39 | - this.renderViewPanel.TabIndex = 0; | |
| 40 | - // | |
| 41 | 32 | // lbStatus |
| 42 | 33 | // |
| 43 | 34 | this.lbStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; |
| @@ -48,6 +39,15 @@ | ||
| 48 | 39 | this.lbStatus.TabIndex = 1; |
| 49 | 40 | this.lbStatus.Text = "..."; |
| 50 | 41 | // |
| 42 | + // renderViewPanel | |
| 43 | + // | |
| 44 | + this.renderViewPanel.Dock = System.Windows.Forms.DockStyle.Fill; | |
| 45 | + this.renderViewPanel.Location = new System.Drawing.Point(0, 0); | |
| 46 | + this.renderViewPanel.Name = "renderViewPanel"; | |
| 47 | + this.renderViewPanel.Size = new System.Drawing.Size(232, 268); | |
| 48 | + this.renderViewPanel.SurfaceUsage = nft.framework.drawing.SurfaceUsage.Normal; | |
| 49 | + this.renderViewPanel.TabIndex = 0; | |
| 50 | + // | |
| 51 | 51 | // InspectToolForm |
| 52 | 52 | // |
| 53 | 53 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); |