EditorDisplay.Objects.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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 CommonAI.Zone.ZoneEditor.Plugin.EditorToScene;
  9. using CommonAI.Zone.ZoneEditor.Plugin.SceneToEditor;
  10. using CommonAI.Zone;
  11. using CommonAI.Zone.ZoneEditor;
  12. using CommonAI.RTS;
  13. using CommonLang.Vector;
  14. using System.Collections;
  15. using CommonAI.Zone.Instance;
  16. using CommonLang;
  17. using GameEditorPlugin.Win32;
  18. using CommonFroms.Drawing;
  19. using CommonAI.RTS.Manhattan;
  20. using GameEditorPlugin.Tools;
  21. using CommonAI.Zone.Helper;
  22. namespace GameEditorPlugin.Win32.Editor
  23. {
  24. public abstract class EditorObject : DisplayObject
  25. {
  26. readonly private SceneObjectData Data;
  27. readonly public EditorWorld world;
  28. readonly public Pen pen;
  29. readonly public Pen pen_hight;
  30. readonly public SolidBrush brush;
  31. public bool Selected = false;
  32. public abstract bool Pickable { get; }
  33. public abstract float Direction { get; set; }
  34. public abstract bool IsDirectionality { get; }
  35. public EditorObject(EditorWorld wd, SceneObjectData data)
  36. {
  37. this.world = wd;
  38. this.Data = data;
  39. this.pen = new Pen(Color.FromArgb(data.Color));
  40. this.pen_hight = new Pen(Color.White);
  41. this.brush = new SolidBrush(Color.FromArgb(data.Color));
  42. }
  43. public virtual bool touch(float x, float y)
  44. {
  45. return CMath.includeRectPoint2(
  46. this.X + this.LocalBounds.X,
  47. this.Y + this.LocalBounds.Y,
  48. this.LocalBounds.Width,
  49. this.LocalBounds.Height,
  50. x, y);
  51. }
  52. public string Name { get { return Data.Name; } set { Data.Name = value; } }
  53. public override float X { get { return Data.X; } }
  54. public override float Y { get { return Data.Y; } }
  55. public override float Z { get { return 0; } }
  56. public void SetPos(float x, float y)
  57. {
  58. this.Data.X = x;
  59. this.Data.Y = y;
  60. }
  61. public override void render_begin(Graphics g)
  62. {
  63. float penscale = 1f / world.getCameraScale();
  64. pen.Width = pen_hight.Width = penscale;
  65. }
  66. public override void render_end(Graphics g)
  67. {
  68. base.render_end(g);
  69. if (Selected) this.render_selected(g);
  70. }
  71. protected virtual void render_selected(Graphics g)
  72. {
  73. g.DrawEllipse(pen_hight, LocalBounds);
  74. if (IsDirectionality)
  75. {
  76. float r = Math.Max(LocalBounds.Width, LocalBounds.Height) * 1.25f * 0.5f;
  77. g.DrawLine(pen_hight, 0, 0,
  78. (float)Math.Cos(Direction) * r,
  79. (float)Math.Sin(Direction) * r);
  80. }
  81. }
  82. public virtual void render_in_terrain(Graphics g) { }
  83. }
  84. public class EditorUnit : EditorObject
  85. {
  86. readonly public UnitData Data;
  87. readonly public UnitInfo Info;
  88. private RectangleF mLocalBounds;
  89. private static Pen pen_hitbody = new Pen(Color.Green);
  90. private static Pen pen_guardrange = new Pen(Color.Yellow);
  91. public override RectangleF LocalBounds { get { return mLocalBounds; } }
  92. public override bool Pickable { get { return EditorDisplayPanel.ShowUnit; } }
  93. public override bool Visible { get { return EditorDisplayPanel.ShowAll || Pickable; } }
  94. public override float Direction { get { return Data.Direction; } set { this.Data.Direction = value; } }
  95. public override bool IsDirectionality { get { return true; } }
  96. public EditorUnit(EditorWorld wd, MsgPutUnit unit)
  97. : base(wd, unit.Data)
  98. {
  99. this.Data = unit.Data;
  100. this.Info = unit.UnitData;
  101. if (Info != null)
  102. {
  103. this.mLocalBounds = new RectangleF(
  104. -Info.BodySize,
  105. -Info.BodySize,
  106. Info.BodySize * 2,
  107. Info.BodySize * 2);
  108. }
  109. else
  110. {
  111. this.mLocalBounds = new RectangleF(-1, -1, 2, 2);
  112. }
  113. }
  114. public override bool touch(float x, float y)
  115. {
  116. if (Info != null)
  117. {
  118. return CMath.includeRoundPoint(this.X, this.Y, this.Info.BodySize, x, y);
  119. }
  120. return base.touch(x, y);
  121. }
  122. public override void render(Graphics g)
  123. {
  124. float penscale = 1f / world.getCameraScale();
  125. pen.Width = pen_hight.Width = pen_hitbody.Width = pen_guardrange.Width = penscale;
  126. g.DrawEllipse(pen, mLocalBounds);
  127. if (Selected)
  128. {
  129. g.FillEllipse(brush, mLocalBounds);
  130. if(Info != null)
  131. {
  132. g.DrawArc(pen_hitbody, -Info.BodyHitSize, -Info.BodyHitSize, Info.BodyHitSize * 2, Info.BodyHitSize * 2, 0, 360);
  133. g.DrawArc(pen_guardrange, -Info.GuardRange, -Info.GuardRange, Info.GuardRange * 2, Info.GuardRange * 2, 0, 360);
  134. }
  135. g.DrawLine(pen_hight, 0, 0,
  136. (float)Math.Cos(Data.Direction) * mLocalBounds.Width,
  137. (float)Math.Sin(Data.Direction) * mLocalBounds.Width);
  138. }
  139. else
  140. {
  141. g.DrawLine(pen, 0, 0,
  142. (float)Math.Cos(Data.Direction) * mLocalBounds.Width,
  143. (float)Math.Sin(Data.Direction) * mLocalBounds.Width);
  144. }
  145. }
  146. }
  147. public class EditorItem : EditorObject
  148. {
  149. readonly public ItemData Data;
  150. readonly public ItemTemplate Info;
  151. private RectangleF mLocalBounds;
  152. public override RectangleF LocalBounds { get { return mLocalBounds; } }
  153. public override bool Pickable { get { return EditorDisplayPanel.ShowItem; } }
  154. public override bool Visible { get { return EditorDisplayPanel.ShowAll || Pickable; } }
  155. public override float Direction { get { return Data.Direction; } set { this.Data.Direction = value; } }
  156. public override bool IsDirectionality { get { return true; } }
  157. public EditorItem(EditorWorld wd, MsgPutItem item)
  158. : base(wd, item.Data)
  159. {
  160. this.Data = item.Data;
  161. this.Info = item.Item;
  162. if (Info != null)
  163. {
  164. this.mLocalBounds = new RectangleF(
  165. -Info.BodySize,
  166. -Info.BodySize,
  167. Info.BodySize * 2,
  168. Info.BodySize * 2);
  169. }
  170. else
  171. {
  172. this.mLocalBounds = new RectangleF(-1, -1, 2, 2);
  173. }
  174. }
  175. public override bool touch(float x, float y)
  176. {
  177. if (Info != null)
  178. {
  179. return CMath.includeRoundPoint(this.X, this.Y, this.Info.BodySize, x, y);
  180. }
  181. return base.touch(x, y);
  182. }
  183. public override void render(Graphics g)
  184. {
  185. float penscale = 1f / world.getCameraScale();
  186. pen.Width = pen_hight.Width = penscale;
  187. g.DrawEllipse(pen, mLocalBounds);
  188. if (Selected)
  189. {
  190. g.FillEllipse(brush, mLocalBounds);
  191. g.DrawLine(pen_hight, 0, 0,
  192. (float)Math.Cos(Data.Direction) * mLocalBounds.Width,
  193. (float)Math.Sin(Data.Direction) * mLocalBounds.Width);
  194. }
  195. else
  196. {
  197. g.DrawLine(pen, 0, 0,
  198. (float)Math.Cos(Data.Direction) * mLocalBounds.Width,
  199. (float)Math.Sin(Data.Direction) * mLocalBounds.Width);
  200. }
  201. }
  202. }
  203. public class EditorRegion : EditorObject
  204. {
  205. readonly public RegionData Data;
  206. public override bool Pickable { get { return EditorDisplayPanel.ShowRegion; } }
  207. public override bool Visible { get { return EditorDisplayPanel.ShowAll || Pickable; } }
  208. public override float Direction { get { return 0; } set { } }
  209. public override bool IsDirectionality { get { return false; } }
  210. public override RectangleF LocalBounds
  211. {
  212. get
  213. {
  214. if (Data.RegionType == RegionData.Shape.RECTANGLE)
  215. {
  216. return new RectangleF(-Data.W / 2, -Data.H / 2, Data.W, Data.H);
  217. }
  218. else if (Data.RegionType == RegionData.Shape.ROUND)
  219. {
  220. return new RectangleF(-Data.W / 2, -Data.W / 2, Data.W, Data.W);
  221. }
  222. else
  223. {
  224. return new RectangleF(-Data.W / 2, -Data.W / 2, Data.W, Data.W);
  225. }
  226. }
  227. }
  228. public EditorRegion(EditorWorld wd, MsgPutRegion data)
  229. : base(wd, data.Data)
  230. {
  231. this.Data = data.Data;
  232. }
  233. public override bool touch(float x, float y)
  234. {
  235. if (Data.RegionType == RegionData.Shape.RECTANGLE)
  236. {
  237. return base.touch(x, y);
  238. }
  239. else if(Data.RegionType == RegionData.Shape.ROUND)
  240. {
  241. return CMath.includeRoundPoint(X, Y, Data.W / 2, x, y);
  242. }
  243. else if (Data.RegionType == RegionData.Shape.STRIP)
  244. {
  245. float line_r = Data.W / 2;
  246. Vector2 p = new Vector2(X, Y);
  247. Vector2 q = new Vector2(X, Y);
  248. MathVector.movePolar(p, Data.StripDirection, -Data.H / 2);
  249. MathVector.movePolar(q, Data.StripDirection, +Data.H / 2);
  250. return CMath.includeStripWidthPoint(p.X, p.Y, q.X, q.Y, line_r, x, y);
  251. }
  252. return base.touch(x, y);
  253. }
  254. public override void render(Graphics g)
  255. {
  256. float penscale = 1f / world.getCameraScale();
  257. pen.Width = pen_hight.Width = penscale;
  258. if (Data.RegionType == RegionData.Shape.RECTANGLE)
  259. {
  260. g.DrawRectangle(pen, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  261. if (Selected)
  262. {
  263. g.FillRectangle(brush, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  264. }
  265. }
  266. else if (Data.RegionType == RegionData.Shape.ROUND)
  267. {
  268. g.DrawEllipse(pen, -Data.W / 2, -Data.W / 2, Data.W, Data.W);
  269. if (Selected)
  270. {
  271. g.FillEllipse(brush, -Data.W / 2, -Data.W / 2, Data.W, Data.W);
  272. }
  273. }
  274. else if (Data.RegionType == RegionData.Shape.STRIP)
  275. {
  276. float line_r = Data.W / 2;
  277. Line2 line = new Line2(0, 0, 0, 0);
  278. MathVector.movePolar(line.p, Data.StripDirection, -Data.H / 2);
  279. MathVector.movePolar(line.q, Data.StripDirection, +Data.H / 2);
  280. DrawingUtils.FillLineRect(g, brush, line.p.X, line.p.Y, line.q.X, line.q.Y, line_r);
  281. }
  282. }
  283. }
  284. public class EditorDecoration : EditorObject
  285. {
  286. private static SolidBrush deco_block_brush = new SolidBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
  287. readonly public DecorationData Data;
  288. public override bool Pickable { get { return EditorDisplayPanel.ShowDecoration; } }
  289. public override bool Visible { get { return EditorDisplayPanel.ShowAll || Pickable; } }
  290. public override bool IsDirectionality { get { return true; } }
  291. public override float Direction
  292. {
  293. get { return Data.Direction; }
  294. set
  295. {
  296. if (Data.RegionType == DecorationData.Shape.STRIP)
  297. {
  298. this.Data.StripDirection = value;
  299. }
  300. this.Data.Direction = value;
  301. }
  302. }
  303. public override RectangleF LocalBounds
  304. {
  305. get
  306. {
  307. if (Data.RegionType == DecorationData.Shape.STRIP)
  308. {
  309. return new RectangleF(-Data.W / 2, -Data.W / 2, Data.W, Data.W);
  310. }
  311. else
  312. {
  313. return new RectangleF(-Data.W / 2, -Data.H / 2, Data.W, Data.H);
  314. }
  315. }
  316. }
  317. public EditorDecoration(EditorWorld wd, MsgPutDecoration data)
  318. : base(wd, data.Data)
  319. {
  320. this.Data = data.Data;
  321. }
  322. public override bool touch(float x, float y)
  323. {
  324. if (Data.RegionType == DecorationData.Shape.RECTANGLE)
  325. {
  326. return base.touch(x, y);
  327. }
  328. else if (Data.RegionType == DecorationData.Shape.ROUND)
  329. {
  330. return CMath.includeEllipsePoint(X, Y, Data.W / 2, Data.H / 2, x, y);
  331. }
  332. else if (Data.RegionType == DecorationData.Shape.STRIP)
  333. {
  334. float line_r = Data.W / 2;
  335. Vector2 p = new Vector2(X, Y);
  336. Vector2 q = new Vector2(X, Y);
  337. MathVector.movePolar(p, Data.StripDirection, -Data.H / 2);
  338. MathVector.movePolar(q, Data.StripDirection, +Data.H / 2);
  339. return CMath.includeStripWidthPoint(p.X, p.Y, q.X, q.Y, line_r, x, y);
  340. }
  341. return base.touch(x, y);
  342. }
  343. public override void render(Graphics g)
  344. {
  345. float penscale = 1f / world.getCameraScale();
  346. pen.Width = pen_hight.Width = penscale;
  347. if (Data.RegionType == DecorationData.Shape.RECTANGLE)
  348. {
  349. if (Selected)
  350. {
  351. g.FillRectangle(brush, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  352. }
  353. g.DrawRectangle(pen, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  354. }
  355. else if (Data.RegionType == DecorationData.Shape.ROUND)
  356. {
  357. if (Selected)
  358. {
  359. g.FillEllipse(brush, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  360. }
  361. g.DrawEllipse(pen, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  362. }
  363. else if (Data.RegionType == DecorationData.Shape.STRIP)
  364. {
  365. float line_r = Data.W / 2;
  366. Line2 line = new Line2(0, 0, 0, 0);
  367. MathVector.movePolar(line.p, Data.StripDirection, -Data.H / 2);
  368. MathVector.movePolar(line.q, Data.StripDirection, +Data.H / 2);
  369. if (Selected)
  370. {
  371. DrawingUtils.FillLineRect(g, brush, line.p.X, line.p.Y, line.q.X, line.q.Y, line_r);
  372. }
  373. g.DrawEllipse(pen, -Data.W / 2, -Data.W / 2, Data.W, Data.W);
  374. DrawingUtils.DrawLineRect(g, pen, line.p.X, line.p.Y, line.q.X, line.q.Y, line_r);
  375. }
  376. if (this.Selected)
  377. {
  378. using (var pts = ListObjectPool<CommonLang.Geometry.Vector2>.AllocAutoRelease())
  379. {
  380. var pen_res = new Pen(Color.Yellow);
  381. pen_res.Width = penscale;
  382. Data.GetResourcePoints(pts);
  383. var st = g.Save();
  384. try
  385. {
  386. if (Data.ShapDirectionality) { g.RotateTransform(CMath.RadiansToDegrees(Data.StripDirection)); }
  387. foreach (var pt in pts)
  388. {
  389. DrawingUtils.DrawCross(g, pen_res, pt.X, pt.Y, 2 * penscale);
  390. }
  391. }
  392. finally
  393. {
  394. g.Restore(st);
  395. }
  396. }
  397. }
  398. }
  399. public override void render_begin(Graphics g)
  400. {
  401. base.render_begin(g);
  402. }
  403. public override void render_in_terrain(Graphics g)
  404. {
  405. if (this.Data.Blockable)
  406. {
  407. if (this.Selected || this.Pickable)
  408. {
  409. var ed = this;
  410. var bounds = ed.LocalBounds;
  411. AstarManhattan.ForEachTerrainAction action = (bx, by) =>
  412. {
  413. g.FillRectangle(deco_block_brush, bx * world.CellW, by * world.CellH, world.CellW, world.CellH);
  414. };
  415. var mmap = world.ManhattanMap;
  416. switch (ed.Data.RegionType)
  417. {
  418. case DecorationData.Shape.RECTANGLE:
  419. AstarManhattan.ForEachTerrainRect(mmap, ed.X + bounds.X, ed.Y + bounds.Y, bounds.Width, bounds.Height, action);
  420. break;
  421. case DecorationData.Shape.ROUND:
  422. AstarManhattan.ForEachTerrainEllipse(mmap, ed.X + bounds.X, ed.Y + bounds.Y, bounds.Width, bounds.Height, action);
  423. break;
  424. case DecorationData.Shape.STRIP:
  425. Line2 line = new Line2(Data.X, Data.Y, Data.X, Data.Y);
  426. MathVector.movePolar(line.p, Data.StripDirection, -Data.H / 2);
  427. MathVector.movePolar(line.q, Data.StripDirection, +Data.H / 2);
  428. AstarManhattan.ForEachTerrainStripWidth(mmap, line.p.X, line.p.Y, line.q.X, line.q.Y, Data.W / 2, action);
  429. break;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. public class EditorPoint : EditorObject
  436. {
  437. readonly public PointData Data;
  438. private static Pen pen_link = new Pen(Color.FromArgb(0x80, 0x80, 0x80, 0xFF));
  439. private static Brush brush_link = new SolidBrush(Color.FromArgb(0x80, 0x80, 0x80, 0xFF));
  440. public override RectangleF LocalBounds
  441. {
  442. get
  443. {
  444. float penscale = 1f / world.getCameraScale();
  445. float ds = -4 * penscale;
  446. float dw = 8 * penscale;
  447. return new RectangleF(ds, ds, dw, dw);
  448. }
  449. }
  450. public override bool Pickable { get { return EditorDisplayPanel.ShowPoint; } }
  451. public override bool Visible { get { return EditorDisplayPanel.ShowAll || Pickable; } }
  452. public override float Direction { get { return 0; } set { } }
  453. public override bool IsDirectionality { get { return false; } }
  454. public EditorPoint(EditorWorld wd, MsgPutPoint data)
  455. : base(wd, data.Data)
  456. {
  457. this.Data = data.Data;
  458. }
  459. public override bool touch(float x, float y)
  460. {
  461. float penscale = 1f / world.getCameraScale();
  462. return CMath.includeRoundPoint(this.X, this.Y, 4 * penscale, x, y);
  463. }
  464. public override void render(Graphics g)
  465. {
  466. float penscale = 1f / world.getCameraScale();
  467. pen_link.Width = pen.Width = pen_hight.Width = penscale;
  468. if (Data.NextNames != null)
  469. {
  470. float dw = 4 * penscale;
  471. float cw = 12 * penscale;
  472. float ch = 16 * penscale;
  473. foreach (string next in Data.NextNames)
  474. {
  475. EditorObject nextobb = world.GetObject(next);
  476. if (nextobb != null)
  477. {
  478. float ox = nextobb.X - X;
  479. float oy = nextobb.Y - Y;
  480. if (Selected)
  481. {
  482. DrawingUtils.FillCursor(g, brush_link, 0, 0, ox, oy, dw, cw, ch);
  483. }
  484. DrawingUtils.DrawCursor(g, pen_link, 0, 0, ox, oy, dw, cw, ch);
  485. }
  486. }
  487. }
  488. {
  489. float ds = -4 * penscale;
  490. float dw = 8 * penscale;
  491. g.DrawEllipse(pen, ds, ds, dw, dw);
  492. if (Selected)
  493. {
  494. g.FillEllipse(brush, ds, ds, dw, dw);
  495. }
  496. }
  497. }
  498. }
  499. public class EditorArea : EditorObject
  500. {
  501. readonly public AreaData Data;
  502. private Pen pen_link;
  503. private Pen pen_border;
  504. private Vector2 old_pos = new Vector2();
  505. private Vector2 old_size = new Vector2();
  506. private bool area_dirty = true;
  507. private ManhattanMapAreaGenerator.ContinuousMapNode area_blocks;
  508. public override RectangleF LocalBounds
  509. {
  510. get
  511. {
  512. float penscale = 1f / world.getCameraScale();
  513. float ds = -4 * penscale;
  514. float dw = 8 * penscale;
  515. return new RectangleF(ds, ds, dw, dw);
  516. }
  517. }
  518. public override bool Pickable { get { return EditorDisplayPanel.ShowArea; } }
  519. public override bool Visible { get { return EditorDisplayPanel.ShowAll || Pickable; } }
  520. public override float Direction { get { return 0; } set { } }
  521. public override bool IsDirectionality { get { return false; } }
  522. public EditorArea(EditorWorld wd, MsgPutArea data)
  523. : base(wd, data.Data)
  524. {
  525. this.Data = data.Data;
  526. var bc = Color.FromArgb((0xFFFFFF & data.Data.Color));
  527. this.pen_link = new Pen(Color.FromArgb(0x40, bc));
  528. this.pen_border = new Pen(Color.FromArgb(0xFF, bc));
  529. }
  530. public override bool touch(float x, float y)
  531. {
  532. float penscale = 1f / world.getCameraScale();
  533. return CMath.includeRoundPoint(this.X, this.Y, 4 * penscale, x, y);
  534. }
  535. public override void render(Graphics g)
  536. {
  537. float penscale = 1f / world.getCameraScale();
  538. pen_border.Width = pen_link.Width = pen.Width = pen_hight.Width = penscale;
  539. {
  540. float ds = -4 * penscale;
  541. float dw = 8 * penscale;
  542. g.DrawEllipse(pen, ds, ds, dw, dw);
  543. if (Selected)
  544. {
  545. g.FillEllipse(brush, ds, ds, dw, dw);
  546. }
  547. }
  548. if (Selected)
  549. {
  550. g.DrawRectangle(pen_hight, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  551. }
  552. if (world.IsAreaDirty || old_pos.X != X || old_pos.Y != Y || old_size.X != Data.W || old_size.Y != Data.H)
  553. {
  554. this.area_dirty = true;
  555. }
  556. this.old_pos.SetX(X);
  557. this.old_pos.SetY(Y);
  558. this.old_size.SetX(Data.W);
  559. this.old_size.SetY(Data.H);
  560. }
  561. public override void render_in_terrain(Graphics g)
  562. {
  563. if (this.Selected || this.Pickable)
  564. {
  565. if (area_dirty)
  566. {
  567. area_dirty = false;
  568. area_blocks = world.MapAreaGenerator.GetContinuousMapNode(X, Y, Data.W / 2, Data.H / 2);
  569. }
  570. if (area_blocks != null)
  571. {
  572. int current_value;
  573. if (world.MapAreaGenerator.TryGetValue(X, Y, out current_value))
  574. {
  575. int sx, sy;
  576. int sw = world.CellW;
  577. int sh = world.CellH;
  578. foreach (var index in area_blocks)
  579. {
  580. sx = index.BX * sw;
  581. sy = index.BY * sh;
  582. g.DrawRectangle(pen_link, sx, sy, sw, sh);
  583. if (area_blocks.GetIndex(index.BX, index.BY - 1) == null)
  584. g.DrawLine(pen_border, sx, sy, sx + sw, sy);
  585. if (area_blocks.GetIndex(index.BX, index.BY + 1) == null)
  586. g.DrawLine(pen_border, sx, sy + sh, sx + sw, sy + sh);
  587. if (area_blocks.GetIndex(index.BX - 1, index.BY) == null)
  588. g.DrawLine(pen_border, sx, sy, sx, sy + sh);
  589. if (area_blocks.GetIndex(index.BX + 1, index.BY) == null)
  590. g.DrawLine(pen_border, sx + sw, sy, sx + sw, sy + sh);
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. }