Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace GUIapp
- {
- public abstract class GuiMenuCreator
- {
- public abstract GuiManager Instantiate(string option, System.Action exit);
- }
- public class GuiConstructor : GuiMenuCreator
- {
- public override GuiManager Instantiate(string option, System.Action exit)
- {
- GuiManager guiManager = new GUIapp.GuiManager();
- switch (option)
- {
- default:
- {
- GuiElementCreator buttonConstructor = new ButtonConstructor();
- GuiElementCreator labelConstructor = new LabelConstructor();
- guiManager.elements = new List<GuiElement>();
- guiManager.elements.Add(new Clickable(labelConstructor.Instantiate("Click me new", new Point(0, 200), 10, Colour.Black), 100, 20, () => exit()));
- guiManager.elements.Add(new Clickable(labelConstructor.Instantiate("Click me", new Point(0, 100), 10, Colour.Black
- ), 100, 20, () => {
- guiManager.elements = new List<GuiElement>();
- guiManager.elements.Add(new Clickable(labelConstructor.Instantiate("Exit ExitExitExitExitExitExit", new Point(0, 0), 10, Colour.Black), 250, 20, () => {
- exit();
- }));
- }));
- // guiManager.elements.Add(buttonConstructor.Instantiate("Click me", new Point(0, 100), 10, Colour.Black, 100, 30,
- // () => {
- // guiManager.elements = new List<GuiElement>();
- // guiManager.elements.Add(buttonConstructor.Instantiate("Exit", new Point(0, 0), 10, Colour.Black, 100, 30,
- // () => {
- // exit();
- // }
- // ));
- // }
- // ));
- break;
- }
- }
- return guiManager;
- }
- }
- public abstract class GuiElementCreator
- {
- public abstract GuiElement Instantiate(string content, Point top_left_corner, int size, Colour color);
- public abstract GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action);
- }
- public interface GuiElement : Drawable, Updateable {
- Point Position();
- }
- public abstract class GuiDecorator : GuiElement {
- protected GuiElement element;
- public GuiDecorator(GuiElement element) {
- this.element = element;
- }
- public Point Position() {
- return element.Position();
- }
- public virtual void Draw(DrawVisitor visitor)
- {
- element.Draw(visitor);
- }
- public virtual void Update(UpdateVisitor visitor, float dt)
- {
- element.Update(visitor, dt);
- }
- }
- public class Clickable : GuiDecorator {
- private GuiElementCreator buttonConstructor = new ButtonConstructor();
- private GuiElement button;
- public Clickable(GuiElement element, float width, float height, Action action): base(element) {
- this.button = buttonConstructor.Instantiate("", element.Position(), 10, Colour.Black, width, height, action);
- }
- public new Point Position() {
- return element.Position();
- }
- public override void Draw(DrawVisitor visitor)
- {
- button.Draw(visitor);
- element.Draw(visitor);
- }
- public override void Update(UpdateVisitor visitor, float dt)
- {
- button.Update(visitor, dt);
- element.Update(visitor, dt);
- }
- }
- public class ButtonConstructor : GuiElementCreator
- {
- public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color)
- {
- return new Button(text, top_left_corner, size, color, 40, 40, () => { });
- }
- public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action)
- {
- return new Button(text, top_left_corner, size, color, width, height, action);
- }
- }
- public class LabelConstructor : GuiElementCreator
- {
- public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color)
- {
- return new Label(text, top_left_corner, size, color);
- }
- public override GuiElement Instantiate(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action)
- {
- return new Label(text, top_left_corner, size, color);
- }
- }
- public class Label : GuiElement
- {
- public string content;
- public int size;
- public Colour color;
- public Point p;
- public Label(string content, Point top_left_corner, int size, Colour color)
- {
- this.size = size;
- this.color = color;
- this.content = content;
- this.p = top_left_corner;
- }
- public Point Position() {
- return p;
- }
- public void Draw(DrawVisitor visitor)
- {
- visitor.DrawLabel(this);
- }
- public void Update(UpdateVisitor visitor, float dt)
- {
- visitor.UpdateLabel(this, dt);
- }
- }
- public class Button : GuiElement
- {
- public float width, height;
- public Action action;
- public Colour color;
- public Point p;
- public Button(string text, Point top_left_corner, int size, Colour color, float width, float height, Action action)
- {
- this.action = action;
- this.width = width;
- this.height = height;
- this.color = color;
- this.p = top_left_corner;
- }
- public Point Position() {
- return this.p;
- }
- public void Draw(DrawVisitor visitor)
- {
- visitor.DrawButton(this);
- }
- public bool is_intersecting(Point point)
- {
- return point.X > p.X && point.Y > p.Y &&
- point.X < p.X + width && point.Y < p.Y + height;
- }
- public void Update(UpdateVisitor visitor, float dt)
- {
- visitor.UpdateButton(this, dt);
- }
- }
- public class GuiManager : Updateable, Drawable
- {
- public List<GuiElement> elements;
- public void Draw(DrawVisitor visitor)
- {
- visitor.DrawGui(this);
- }
- public void Update(UpdateVisitor visitor, float dt)
- {
- visitor.UpdateGui(this, dt);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement