Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace GUIapp
  4. {
  5.  
  6. public abstract class GuiMenuCreator
  7. {
  8. public abstract GuiManager Instantiate(string option, System.Action exit);
  9. }
  10.  
  11. public class GuiConstructor : GuiMenuCreator
  12. {
  13. public override GuiManager Instantiate(string option, System.Action exit)
  14. {
  15. GuiManager guiManager = new GUIapp.GuiManager();
  16. switch (option)
  17. {
  18. default:
  19. {
  20. GuiElementCreator buttonConstructor = new ButtonConstructor();
  21. GuiElementCreator labelConstructor = new LabelConstructor();
  22. guiManager.elements = new List<GuiElement>();
  23. guiManager.elements.Add(labelConstructor.Instantiate("Hi Ahmed!", new Point(0, 0), 10, Colour.Black));
  24. guiManager.elements.Add(buttonConstructor.Instantiate("Click me", new Point(0, 100), 10, Colour.Black, 100, 30,
  25. () => {
  26. guiManager.elements = new List<GuiElement>();
  27. guiManager.elements.Add(buttonConstructor.Instantiate("Exit", new Point(0, 0), 10, Colour.Black, 100, 30,
  28. () => {
  29. exit();
  30. }
  31. ));
  32. }
  33. ));
  34. break;
  35. }
  36. }
  37. return guiManager;
  38. }
  39. }
  40.  
  41. public abstract class GuiElementCreator
  42. {
  43. public abstract GuiElement Instantiate(string content, Point top_left_corner, int size, Colour color);
  44. public abstract GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action);
  45. }
  46.  
  47. public abstract class GuiElement : Drawable, Updateable
  48. {
  49. public Point top_left_corner;
  50. public GuiElement(Point top_left_corner)
  51. {
  52. this.top_left_corner = top_left_corner;
  53. }
  54. public abstract void Draw(DrawVisitor visitor);
  55. public abstract void Update(UpdateVisitor visitor, float dt);
  56.  
  57. }
  58. public class ButtonConstructor : GuiElementCreator
  59. {
  60. public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color)
  61. {
  62. return new Button(new Label(text, top_left_corner, size, color),text, top_left_corner, size, color, 40, 40, () => { });
  63. }
  64.  
  65. public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action)
  66. {
  67. return new Button(new Label(text, top_left_corner, size, color),text, top_left_corner, size, color, 40, 40, action);
  68. }
  69. }
  70. public class LabelConstructor : GuiElementCreator
  71. {
  72. public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color)
  73. {
  74. return new Label(text, top_left_corner, size, color);
  75. }
  76.  
  77. public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action)
  78. {
  79. return new Label(text, top_left_corner, size, color);
  80. }
  81. }
  82. public class Label : GuiElement
  83. {
  84. public string content;
  85.  
  86. public int size;
  87. public Colour color;
  88.  
  89. public Label(string content, Point top_left_corner, int size, Colour color) : base(top_left_corner)
  90. {
  91. this.size = size;
  92. this.color = color;
  93. this.content = content;
  94. }
  95.  
  96. public override void Draw(DrawVisitor visitor)
  97. {
  98. visitor.DrawLabel(this);
  99. }
  100. public override void Update(UpdateVisitor visitor, float dt) { }
  101.  
  102.  
  103. }
  104. public abstract class GuiDecorator : GuiElement
  105. {
  106. public GuiElement element;
  107.  
  108. public GuiDecorator(GuiElement element,Point top_left_corner) :base(top_left_corner){
  109. this.element = element;
  110. }
  111.  
  112. }
  113.  
  114. public class Button : GuiDecorator
  115. {
  116. public float width, height;
  117. public Action action;
  118. public Colour color;
  119. public Button(GuiElement element,string text, Point top_left_corner, int size, Colour color, float width, float height, Action action) : base(element,top_left_corner)
  120. {
  121. this.action = action;
  122. this.width = width;
  123. this.height = height;
  124. this.color = color;
  125. }
  126. public override void Draw(DrawVisitor visitor)
  127. {
  128. visitor.DrawButton(this);
  129. base.element.Draw(visitor);
  130. }
  131. public bool is_intersecting(Point point)
  132. {
  133. return point.X > top_left_corner.X && point.Y > top_left_corner.Y &&
  134. point.X < top_left_corner.X + width && point.Y < top_left_corner.Y + height;
  135. }
  136. public override void Update(UpdateVisitor visitor, float dt)
  137. {
  138. visitor.UpdateButton(this, dt);
  139. }
  140.  
  141. }
  142.  
  143.  
  144. public class GuiManager : Updateable, Drawable
  145. {
  146. public List<GuiElement> elements;
  147.  
  148. public void Draw(DrawVisitor visitor)
  149. {
  150. visitor.DrawGui(this);
  151. }
  152.  
  153. public void Update(UpdateVisitor visitor, float dt)
  154. {
  155. visitor.UpdateGui(this, dt);
  156. }
  157. }
  158.  
  159.  
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement