/
PlayerNameState.cs
229 lines (192 loc) · 7.95 KB
/
PlayerNameState.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using Engine;
using OpenTK.Input;
using System.Drawing;
using System.Reflection;
using QuickFont;
// XML parser
using System.Xml;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
namespace U5Designs
{
class PlayerNameState : GameState
{
internal GameEngine eng;
Stack<XmlNodeList> savedGameStates;
Stack<string> savedGameChoices;
MainMenuState _ms;
QFont saveFont, title, saveFontHighlighted;
/** Naming Stuff **/
String name;
char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
int _max_name_length = 20; // Set the max length for the character name here
float start_x;
// A container which will hold the list of available saved games
protected Vector3 eye, lookat;
MouseDevice mouse;
// testing buttons
//Obstacle play_button_npress, play_button_press, load_button_npress, load_button_press, quit_button_press, quit_button_npress;
private int numOfButtons;
int _cur_butn = 0;
OpenTK.Input.KeyboardState _old_state;
// New Buttons
Texture menu;
public bool enterdown, escapedown;
public bool clickdown = false;
double cnt;
public PlayerNameState(GameEngine engine, MainMenuState ms)
{
eng = engine;
mouse = eng.Mouse;
savedGameStates = new Stack<XmlNodeList>();
savedGameChoices = new Stack<string>();
_ms = ms;
Assembly assembly = Assembly.GetExecutingAssembly();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
lookat = new Vector3(0, 0, 2);
eye = new Vector3(0, 0, 5);
_old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard
eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png"));
menu = eng.StateTextureManager.GetTexture("menu");
saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true));
saveFont.Options.DropShadowActive = true;
start_x = saveFont.Measure("Name: ").Width;
//title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true));
title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true));
title.Options.DropShadowActive = true;
name = "";
numOfButtons = savedGameChoices.Count - 1;
}
public override void MakeActive()
{
GL.Disable(EnableCap.Lighting);
GL.Disable(EnableCap.Light0);
GL.MatrixMode(MatrixMode.Projection);
Matrix4 projection = Matrix4.CreateOrthographic(1280, 720, 1.0f, 6400.0f);
GL.LoadMatrix(ref projection);
if (eng.Keyboard[Key.Escape])
{
escapedown = true;
}
if (eng.Keyboard[Key.Enter])
enterdown = true;
}
public override void Update(FrameEventArgs e)
{
DealWithInput();
//MouseInput();
cnt += e.Time;
}
public override void Draw(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
GL.ClearColor(0.15f, 0.15f, 0.15f, 1.0f);
Matrix4 modelview = Matrix4.LookAt(eye, lookat, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
GL.Disable(EnableCap.DepthTest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
// Draw the background
menu.Draw2DTexture();
drawSaves();
GL.Enable(EnableCap.DepthTest);
}
// Draw stuff
public void drawSaves()
{
GL.PushMatrix();
GL.Scale(1, -1, 1);
float startY = -(title.Measure("A").Height * 2.0f);
title.Print("Character Name", new Vector2(-(title.Measure("Character Name").Width / 2), startY));
title.Options.DropShadowActive = false;
// Draw non highlighted string
float yOffset = startY + title.Measure("C").Height + 10;
saveFont.Options.DropShadowActive = false;
saveFont.Print("Name: " + name, new Vector2(-(start_x), yOffset));
GL.PopMatrix();
}
private void DealWithInput()
{
OpenTK.Input.KeyboardState _new_state = OpenTK.Input.Keyboard.GetState();
// Loop over all available keys and type out to the screen
for (int i = 0; i < (int)Key.LastKey; i++)
{
Key k = (Key)i; // 49 = enter
bool current = _new_state.IsKeyDown(k);
bool previous = _old_state.IsKeyDown(k);
if (current && !previous)
{
// new key pressed
//NewKeyDownDetected(k);
for (int i2 = 0; i2 < alpha.Length; i2++)
{
if (k.ToString().CompareTo(alpha[i2].ToString()) == 0)
{
name += k.ToString();
}
}
if (i == 53 && name.Length > 0)
{
name = name.Remove(name.Length - 1);
}
}
else if (!current && previous)
{
//NewKeyUpDetected(k);
}
else
{
// Constant keypress
}
}
_old_state = _new_state;
if ((eng.Keyboard[Key.Escape] || (eng.Keyboard[Key.Tilde])) && !escapedown)
{
eng.Exit();
}
else if (!eng.Keyboard[Key.Escape] && !eng.Keyboard[Key.Tilde])
{
escapedown = false;
}
//********************** enter
if (eng.Keyboard[Key.Enter] && !enterdown)
{
enterdown = true;
loadPlayState(0); // Load game
}
else if (!eng.Keyboard[Key.Enter])
{
enterdown = false;
}
//Minus - Toggle fullscreen
if (eng.Keyboard[Key.Minus])
{
eng.toggleFullScreen();
}
}
/** This loads the chosen game **/
internal void loadPlayState(int lvl)
{
eng._player_name = name;
StoryInstructionState sis = new StoryInstructionState(eng, _ms);
eng.ChangeState(sis);
//PlayState ps = new PlayState(eng, _ms, lvl);
//LoadScreenState ls = new LoadScreenState(eng, ps, lvl);
//eng.ChangeState(ls);
}
}
}