-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.cs
184 lines (159 loc) · 5.62 KB
/
Buttons.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
namespace TicTacToe {
public class BaseButton : IPositionable {
public Vector2 _pos;
public Vector2 position { get { return _pos; } set { _pos = value; } }
public Vector2 _size;
public Vector2 _scale;
public SpriteEffects _effect;
public Color _color;
public float _z;
public BaseButton(Vector2 pos,
Vector2 size,
Vector2 scale,
SpriteEffects effect,
Color color,
float z) {
_pos = pos;
_size = size;
_scale = scale;
_effect = effect;
_color = color;
_z = z;
}
virtual public void Draw(GameTime gameTime, SpriteBatch sb) {
Vector2 end = _pos + _size;
Primitives.DrawRectangle(sb, _pos, end, Color.Multiply(Color.CornflowerBlue, 0.9f), 0.1f);
Primitives.DrawRectangle(sb, _pos, end, Color.Multiply(Color.White, 0.9f), 0.0f, 1);
}
public void DrawText(SpriteBatch sb, string text) {
Vector2 textpos = _pos + _size * new Vector2(0.05f, 0.5f);
Primitives.DrawText(sb, textpos, text, _color,
align: Primitives.TextAlign.CenterLeft);
}
public bool IsInside(Vector2 pos) {
return ((pos.X > _pos.X) && (pos.X < (_pos.X + _size.X)) &&
(pos.Y > _pos.Y) && (pos.Y < (_pos.Y + _size.Y)));
}
}
public class ClickableButton : BaseButton {
public ClickableButton(Vector2 pos,
Vector2 size,
Vector2 scale,
SpriteEffects effect,
Color color,
float z)
: base(pos, size, scale, effect, color, z) {
}
override public void Draw(GameTime gameTime, SpriteBatch sb) {
base.Draw(gameTime, sb);
}
}
public class ActionButton : ClickableButton {
public string _name;
public ActionButton(string name, Vector2 pos, Vector2 size)
: base(pos,
size,
Vector2.One,
SpriteEffects.None,
Color.White,
0.5f) {
_name = name;
}
public bool Update() {
return (MouseMgr._left_down && base.IsInside(MouseMgr._pos));
}
override public void Draw(GameTime gameTime, SpriteBatch sb) {
base.Draw(gameTime, sb);
base.DrawText(sb, _name);
}
}
public interface IOption {
void Next();
string ToString();
}
public class FirstPlayerOption : IOption {
BasePlayer.Type _type;
public FirstPlayerOption(BasePlayer.Type type = BasePlayer.Type.Human) {
_type = type;
}
void IOption.Next() {
switch (_type) {
case BasePlayer.Type.Human:
_type = BasePlayer.Type.AI;
break;
case BasePlayer.Type.AI:
_type = BasePlayer.Type.Human;
break;
default:
Debug.Assert(false, "Thats not a player type");
break;
}
}
string IOption.ToString() {
return _type.ToString();
}
public static implicit operator BasePlayer.Type(FirstPlayerOption o) {
return o._type;
}
}
public class DifficultyOption : IOption {
public BaseAI.Difficulty _difficulty;
public DifficultyOption(BaseAI.Difficulty difficulty = BaseAI.Difficulty.Normal) {
_difficulty = difficulty;
}
void IOption.Next() {
switch (_difficulty) {
case BaseAI.Difficulty.Hard:
_difficulty = BaseAI.Difficulty.Easy;
break;
case BaseAI.Difficulty.Normal:
_difficulty = BaseAI.Difficulty.Hard;
break;
case BaseAI.Difficulty.Easy:
_difficulty = BaseAI.Difficulty.Normal;
break;
default:
Debug.Assert(false, "No patric, DarkSouls is not a difficulty!");
break;
}
}
string IOption.ToString() {
return _difficulty.ToString();
}
public static implicit operator BaseAI.Difficulty(DifficultyOption d) {
return d._difficulty;
}
}
public class OptionButton : ClickableButton {
IOption _option;
public string _name;
public OptionButton(IOption option, string name, Vector2 pos, Vector2 size)
: base(pos,
size,
Vector2.One,
SpriteEffects.None,
Color.White,
0.5f) {
_option = option;
_name = name;
}
public void Update() {
if (MouseMgr._left_down && base.IsInside(MouseMgr._pos)) {
_option.Next();
}
}
override public void Draw(GameTime gameTime, SpriteBatch sb) {
base.Draw(gameTime, sb);
base.DrawText(sb, _name + ": " +_option.ToString());
}
}
}