DisplayLayerFlag.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonAI.ZoneClient;
  5. using System.Drawing;
  6. using GameEditorPlugin.Win32.Runtime;
  7. using CommonAI.Zone.ZoneEditor;
  8. using CommonAI.Zone;
  9. using CommonLang;
  10. using CommonAI.Zone.Helper;
  11. using CommonAI.RTS;
  12. using CommonLang.Vector;
  13. using GameEditorPlugin.Tools;
  14. using CommonLang.Vector;
  15. using CommonFroms.Drawing;
  16. namespace GameEditorPlugin.Win32.BattleClient
  17. {
  18. public class DisplayGameFlag : DisplayObject
  19. {
  20. readonly public ZoneFlag Flag;
  21. readonly public DisplayLayerWorld world;
  22. readonly public Pen pen;
  23. readonly public SolidBrush brush;
  24. public string Name { get { return Flag.Name; } }
  25. protected bool mIsRect = false;
  26. protected RectangleF mLocalBounds;
  27. public DisplayGameFlag(DisplayLayerWorld wd, ZoneFlag data)
  28. {
  29. this.world = wd;
  30. this.Flag = data;
  31. this.pen = new Pen(Color.FromArgb(Flag.EditorData.Color));
  32. this.brush = new SolidBrush(Color.FromArgb(Flag.EditorData.Color));
  33. }
  34. public override void render(Graphics g)
  35. {
  36. float penscale = 1f / world.getCameraScale();
  37. pen.Width = penscale;
  38. if (mIsRect)
  39. {
  40. g.FillRectangle(brush, mLocalBounds);
  41. }
  42. else
  43. {
  44. g.FillEllipse(brush, mLocalBounds);
  45. }
  46. }
  47. public override bool Visible { get { return true; } }
  48. public override float X { get { return Flag.X; } }
  49. public override float Y { get { return Flag.Y; } }
  50. public override float Z { get { return 0; } }
  51. public override RectangleF LocalBounds { get { return mLocalBounds; } }
  52. }
  53. public class DisplayGameDecoration : DisplayGameFlag
  54. {
  55. private ZoneEditorDecoration LayerFlag;
  56. public DisplayGameDecoration(DisplayLayerWorld wd, ZoneEditorDecoration zed) :
  57. base(wd, zed)
  58. {
  59. DecorationData rg = zed.Data as DecorationData;
  60. this.mLocalBounds = new RectangleF(-rg.W / 2, -rg.H / 2, rg.W, rg.H);
  61. this.mIsRect = rg.RegionType == DecorationData.Shape.RECTANGLE ? true : false;
  62. LayerFlag = zed;
  63. }
  64. public override void renderName(Graphics g, Font font, Brush brush)
  65. {
  66. if (world.ShowFlagName)
  67. {
  68. SizeF fsize = g.MeasureString(this.Name, font);
  69. g.DrawString(LayerFlag.Name, font, brush, -fsize.Width / 2, -fsize.Height);
  70. }
  71. }
  72. public override void render(Graphics g)
  73. {
  74. float penscale = 1f / world.getCameraScale();
  75. pen.Width = penscale;
  76. var Data = LayerFlag.Data;
  77. if (LayerFlag.Enable && Data.Blockable)
  78. {
  79. var brush = new SolidBrush(Color.FromArgb(0x80, pen.Color));
  80. if (Data.RegionType == DecorationData.Shape.RECTANGLE)
  81. {
  82. g.FillRectangle(brush, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  83. }
  84. else if (Data.RegionType == DecorationData.Shape.ROUND)
  85. {
  86. g.FillEllipse(brush, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  87. }
  88. else if (Data.RegionType == DecorationData.Shape.STRIP)
  89. {
  90. float line_r = Data.W / 2;
  91. Line2 line = new Line2(0, 0, 0, 0);
  92. MathVector.movePolar(line.p, Data.StripDirection, -Data.H / 2);
  93. MathVector.movePolar(line.q, Data.StripDirection, +Data.H / 2);
  94. DrawingUtils.FillLineRect(g, brush, line.p.X, line.p.Y, line.q.X, line.q.Y, line_r);
  95. }
  96. }
  97. if (Data.RegionType == DecorationData.Shape.RECTANGLE)
  98. {
  99. g.DrawRectangle(pen, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  100. }
  101. else if (Data.RegionType == DecorationData.Shape.ROUND)
  102. {
  103. g.DrawEllipse(pen, -Data.W / 2, -Data.H / 2, Data.W, Data.H);
  104. }
  105. else if (Data.RegionType == DecorationData.Shape.STRIP)
  106. {
  107. float line_r = Data.W / 2;
  108. Line2 line = new Line2(0, 0, 0, 0);
  109. MathVector.movePolar(line.p, Data.StripDirection, -Data.H / 2);
  110. MathVector.movePolar(line.q, Data.StripDirection, +Data.H / 2);
  111. DrawingUtils.DrawLineRect(g, pen, line.p.X, line.p.Y, line.q.X, line.q.Y, line_r);
  112. }
  113. }
  114. }
  115. }