-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcDlgMan.cpp
313 lines (261 loc) · 6.87 KB
/
cDlgMan.cpp
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include "cDlgMan.h"
cDlgMan::cDlgMan()
{
textures.clear();
labels.clear();
m_title.clear();
strings.clear();
m_record.clear();
}
cDlgMan::~cDlgMan()
{
vector<cTexture>::iterator iter = textures.begin();
while (iter != textures.end()) {
iter->cleanTexMemory();
iter++;
}
textures.clear();
labels.clear();
m_title.clear();
strings.clear();
m_record.clear();
}
cDlgMan::cDlgMan(const string title, const string maxTime, const string bestTime)
{
m_title = title;
textures.clear();
labels.clear();
strings.clear();
m_record.clear();
if (m_title == PAUSE)
createPauseDlg(maxTime, bestTime);
}
cDlgMan::cDlgMan(const string title, const int m, const int s)
{
m_title = title;
textures.clear();
labels.clear();
strings.clear();
createFewEnergyDlg(m, s);
}
cDlgMan::cDlgMan(const string title, const int m, const int s, const string maxTime, const string bestTime)
{
m_title = title;
textures.clear();
labels.clear();
strings.clear();
createWinDlg(m, s, maxTime, bestTime);
}
cDlgMan::cDlgMan(const string title)
{
m_title = title;
textures.clear();
labels.clear();
strings.clear();
createLossDlg();
}
void cDlgMan::createBackground(const string fileName)
{
float xy[8];
xy[0] = -0.5;
xy[1] = -0.5;
xy[2] = 0.5;
xy[3] = -0.5;
xy[4] = 0.5;
xy[5] = 0.5;
xy[6] = -0.5;
xy[7] = 0.5;
cTexture tex = cTexture(1, m_title, xy, 0, 0, 640, 640, fileName.c_str());
textures.push_back(tex);
}
void cDlgMan::createButtons()
{
float xy1[8] = { -0.4, -0.4, -0.25, -0.4, -0.25, -0.25, -0.4, -0.25 };
cTexture tex = cTexture(2, "Yes", xy1, 0, 0, 100, 100, "Dlgs\\Yes.png");
textures.push_back(tex);
float xy2[8] = { 0.25, -0.4, 0.4, -0.4, 0.4, -0.25, 0.25, -0.25 };
tex = cTexture(3, "No", xy2, 0, 0, 100, 100, "Dlgs\\No.png");
textures.push_back(tex);
}
void cDlgMan::createPauseDlg(const string maxTime, const string bestTime)
{
createBackground("Dlgs\\pause.png");
createButtons();
if (maxTime != "") {
int pos_col[5] = { WinWidth / 2 + 100, WinHeight / 2 + 50, 0, 0, 255 };
cLabel lab = cLabel(FONT, pos_col);
labels.push_back(lab);
string str = maxTime;
strings.push_back(AddZeroToTime(str));
}
if (bestTime != "") {
int pos_col1[5] = { WinWidth / 2 + 100, WinHeight / 2 + 20, 0, 0, 255 };
cLabel lab = cLabel(FONT, pos_col1);
labels.push_back(lab);
string str = bestTime;//subtractionTimes(maxTime, bestTime);
strings.push_back(AddZeroToTime(str));
m_record = str;
}
}
void cDlgMan::createWinDlg(const int m, const int s, const string maxTime, const string bestTime)
{
sTime s_myTime = { m, s };
string str_myTime = sTimeToStr(s_myTime);
str_myTime = subtractionTimes(maxTime, str_myTime);
sTime s_bestTime = getTime(bestTime);
s_myTime = getTime(str_myTime);
bool res = compareTimes(s_myTime, s_bestTime);
if (!res) createBackground("Dlgs\\win.png");
else createBackground("Dlgs\\win_rec.png");
createButtons();
strings.push_back(AddZeroToTime(str_myTime));
int pos_col[5] = { WinWidth / 2 + 100, WinHeight / 2 + 50, 0, 0, 255 };
cLabel label = cLabel(FONT, pos_col);
labels.push_back(label);
if (bestTime != "")
{
strings.push_back(AddZeroToTime(bestTime));
int pos_col1[5] = { WinWidth / 2 + 100, WinHeight / 2 + 20, 0, 0, 255 };
label = cLabel(FONT, pos_col1);
labels.push_back(label);
if (compareTimes(getTime(str_myTime), getTime(bestTime)))
m_record = AddZeroToTime(str_myTime);
else
m_record = AddZeroToTime(bestTime);
}
}
void cDlgMan::createLossDlg()
{
createBackground("Dlgs\\loss.png");
createButtons();
}
void cDlgMan::createFewEnergyDlg(const int yourEnergy, const int roomEnergy)
{
createBackground("Dlgs\\few.png");
float xy1[8] = { -0.1, -0.4, 0.1, -0.4, 0.1, -0.25, -0.1, -0.25 };
cTexture tex = cTexture(2, "OK", xy1, 0, 0, 100, 100, "Dlgs\\OK.png");
textures.push_back(tex);
int pos_col[5] = { WinWidth / 2 + 100, WinHeight / 2 + 30, 0, 0, 255 };
cLabel label = cLabel(FONT, pos_col);
labels.push_back(label);
int pos_col1[5] = { WinWidth / 2 + 100, WinHeight / 2 - 2, 0, 0, 255 };
label = cLabel(FONT, pos_col1);
labels.push_back(label);
char ye[10];
_itoa_s(yourEnergy, ye, size_t(10), 10);
string str = string(ye);
strings.push_back(str);
char re[10];
_itoa_s(roomEnergy, re, size_t(10), 10);
str = string(re);
strings.push_back(str);
}
void cDlgMan::Draw(const bool named)
{
glPushMatrix();
glTranslatef(0.0, 0.0, 0.02);
vector<cTexture>::iterator iter = textures.begin();
while (iter != textures.end()) {
iter->drawQuad(named);
iter++;
}
glPopMatrix();
}
void cDlgMan::DrawLabel()
{
unsigned int i = 0;
vector<cLabel>::iterator ter = labels.begin();
while (ter != labels.end() && i <= strings.size()) {
char str[50];
memset(str, 0, sizeof(str));
strncpy_s(str, 50, strings.at(i).c_str(), sizeof(str) - 1);
ter->OutputLabel(str);
i++;
ter++;
}
}
//ôóíêöèè äëÿ ðàáîòû ñ âûâîäîì âðåìåíè (êîðîòêèé ôîðìàò)
sTime cDlgMan::getTime(const string bestTime)
{
string bTime = bestTime;
string p1 = "", p2 = "";
int sym = -1;
for (unsigned int i = 0; i < bTime.length(); i++) {
char ch = bTime[i];
if (strncmp(&ch, ":", 1) != 0 && sym == -1)
p1 = p1 + ch; else
if (strncmp(&ch, ":", 1) != 0 && sym > -1)
p2 = p2 + ch; else
if (strncmp(&ch, ":", 1) == 0)
sym = i;
}
sTime time = { 0, 0 };
time.min = atoi(p1.c_str());
time.sec = atoi(p2.c_str());
return time;
}
bool cDlgMan::compareTimes(sTime time1, sTime time2)
{
bool res = false;
if (time1.min > time2.min) res = false;
else
if (time1.min < time2.min) res = true;
else
if (time1.min == time2.min) {
if (time1.sec >= time2.sec) res = false;
else
if (time1.sec < time2.sec) res = true;
}
return res;//Time1 > Time2 : false; Time1 < Time2 : true
}
string cDlgMan::sTimeToStr(const sTime time)
{
int min = time.min;
int sec = time.sec;
char chM[10];
memset(chM, 0, sizeof(chM));
_itoa_s(min, chM, 10, 10);
string str1 = string(chM);
char chS[10];
_itoa_s(sec, chS, 10, 10);
string str2 = string(chS);
string res = str1 + ":" + str2;
return res;
}
string cDlgMan::subtractionTimes(const string maxTime, const string bestTime)
{
string res = "";
sTime time1 = getTime(maxTime);
sTime time2 = getTime(bestTime);
sTime resTime = { 0, 0 };
resTime.sec = time1.sec - time2.sec;
resTime.min = time1.min - time2.min;
if (resTime.sec < 0) {
resTime.sec = g_max_sec + resTime.sec;
resTime.min = resTime.min - 1;
}
if (resTime.min < 0) resTime.min = 0;
res = sTimeToStr(resTime);
return res;
}
string cDlgMan::AddZeroToTime(const string str)
{
string rec = str;
string p1 = "", p2 = "";
int sym = -1;
for (unsigned int i = 0; i < rec.length(); i++) {
char ch = rec[i];
if (strncmp(&ch, ":", 1) != 0 && sym == -1)
p1 = p1 + ch; else
if (strncmp(&ch, ":", 1) != 0 && sym > -1)
p2 = p2 + ch; else
if (strncmp(&ch, ":", 1) == 0)
sym = i;
}
if (p1.length() == 1)
p1.insert(0, "0");
if (p2.length() == 1)
p2.insert(0, "0");
rec = p1 + ":" + p2;
return rec;
}