-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddType.cs
124 lines (115 loc) · 4.57 KB
/
AddType.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using SwinGameSDK;
using System.Text;
using System.Threading.Tasks;
namespace MyGame
{
class AddType : Action
{
private ActType _type;
private int _x, _y, _width, _height, _textX, _textY, _boxX;
private bool _exitType, _nameDone, _colorDone;
private Planner planner;
private string _name, _typeName;
private Color[] _possibleColors;
private Color _color;
public AddType(Planner _planner) : base("addtype")
{
_x = 10; _y = 50; _width = 525; _height = 200;
_textX = 30 + 10; _textY = _y + 5; _boxX = _textX + 170;
planner = _planner;
_possibleColors = new Color[] {Color.AliceBlue,Color.BlueViolet,Color.DarkGreen,Color.DarkMagenta,Color.DarkRed,Color.OrangeRed, Color.DarkOrange,Color.Orange };
_typeName = "";
}
public override bool Execute()
{
//if type returned then add to menu typelist return false means "we dont need add type action any more"
_type = TypeBox();
if (_type != null)
{
planner.Menu.ActTypes.Add(_type);
_type = null;
_typeName = "";
return false;//returns false becuase type added
}
else if(_type== null &_exitType==true) { _typeName = ""; _exitType = false; return false; }//returns false becuase exit clicked
return true;
}
public void DrawTypeBox()
{
SwinGame.FillRectangle(Color.LightGray, _x, _y, _width, _height);
//draw text box, label, text input
SwinGame.FillRectangle(Color.White, _boxX, _textY, _width/7, _height/20);
SwinGame.DrawText("Type Name", Color.Black, _textX, _textY);
SwinGame.DrawText(_typeName, Color.Black, _boxX, _textY);
//draw other labels
SwinGame.DrawText("Exit", Color.Black, _width-50, _textY);
SwinGame.DrawText("Type Colour",Color.Black,_textX,_textY+15);
//draw possible type colors
int colorX = 30;
foreach (Color color in _possibleColors) {
SwinGame.FillRectangle(color, colorX, 85, 20, 20);
colorX = colorX + 30;
}
}
public ActType TypeBox()
{
Font font = Text.LoadFont("Arial", 12);
Input.StartReadingText(Color.Black, 100, font, _boxX, _y);
while (_exitType == false & SwinGame.WindowCloseRequested() == false)
{
SwinGame.ProcessEvents();
SwinGame.ClearScreen(Color.White);
DrawTypeBox();
_name = Input.TextReadAsASCII();
CheckExit();
CheckNameDone();//enter pressed
ChooseColor();//color square clicked, only if _nameDone = true
if (_name != null && _color != null && _nameDone && _colorDone)
{
_colorDone = false;
_nameDone = false;
Input.EndReadingText();
return new ActType(_color, _name);
}
SwinGame.RefreshScreen(60);
}
return null;
}
private void CheckNameDone()
{
if (SwinGame.KeyTyped(KeyCode.ReturnKey) == true)
{
_nameDone = true;
_typeName = _name;
Input.EndReadingText();
}
}
private void CheckExit()
{
if ((SwinGame.MouseClicked(MouseButton.LeftButton)) & (SwinGame.PointInRect(SwinGame.MousePosition(), _width-50,_textY, 50, 10)))
{
_exitType = true;
Input.EndReadingText();
}
}
private void ChooseColor()
{
if (_nameDone)
{
int x = 30;
foreach (Color color in _possibleColors)
{
if ((SwinGame.MouseClicked(MouseButton.LeftButton)) & (SwinGame.PointInRect(SwinGame.MousePosition(), x, 85, 20, 20)))
{
_color = color;
_colorDone = true;
}
x = x + 30;
}
}
}
}
}