-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuscreen.cpp
More file actions
339 lines (282 loc) · 15.7 KB
/
menuscreen.cpp
File metadata and controls
339 lines (282 loc) · 15.7 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include "color.h"
#include "inputmanager.h"
#include "menuscreen.h"
#include "uicomponents.h"
#include "rlgl.h"
#include "raylib.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <utility>
extern Font DOHYEON_REGULAR;
extern Font ORBITRON_BOLD;
MenuScreen::MenuScreen() {
// main buttons
menus.push_back(Menu{});
menus.back().addButton(40, 342, 360, 65, "PRACTICE", true, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(40, 442, 360, 65, "CALIBRATE", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(40, 542, 360, 65, "SETTINGS", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(40, 642, 360, 65, "CREDITS", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(40, 742, 360, 65, "EXIT", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
// practice set buttons
menus.push_back(Menu{});
menus.back().addButton(442, 342, 360, 65, "PEEKING", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(442, 442, 360, 65, "TRACKING", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(442, 542, 360, 65, "FLICKING", true, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(442, 642, 360, 65, "MICRO", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(442, 742, 360, 65, "REACTION", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
menus.back().addButton(442, 842, 360, 65, "HEADSHOT", false, BUTTON_STYLE_0, SELECTED_STYLE_0, DOHYEON_REGULAR);
// menu screen begin button
menus.push_back(Menu{});
menus.back().addButton(1640, 944, 240, 65, "BEGIN", true, BUTTON_STYLE_1, BUTTON_STYLE_1, DOHYEON_REGULAR);
//pause menu
menus.push_back(Menu{});
menus.back().addButton(725, 439, 480, 65, "RESUME", true, BUTTON_STYLE_2, BUTTON_STYLE_2, DOHYEON_REGULAR);
menus.back().addButton(725, 535, 480, 65, "RESTART", true, BUTTON_STYLE_2, BUTTON_STYLE_2, DOHYEON_REGULAR);
menus.back().addButton(725, 631, 480, 65, "EXIT TASK", true, BUTTON_STYLE_3, BUTTON_STYLE_2, DOHYEON_REGULAR);
}
std::pair<std::string, std::string> MenuScreen::getDateTime() {
std::time_t now = std::time(nullptr);
std::tm local_tm = *std::localtime(&now);
// Format date
std::ostringstream ossDate;
ossDate << std::put_time(&local_tm, "%B %d, %Y");
std::string date = ossDate.str();
// Format time
std::ostringstream ossTime;
ossTime << std::put_time(&local_tm, " | %I:%M %p");
std::string time = ossTime.str();
if (time[3] == '0')
time.erase(3, 1);
return make_pair(date, time);
}
void MenuScreen::drawStat(float aspectScale, int offsetX, int offsetY, int x, std::string statTitle, std::string statValue) {
#define SCL(val) ((float)(val) * aspectScale)
Vector2 statTitleSize = MeasureTextEx(DOHYEON_REGULAR, statTitle.c_str(), SCL(20), 1);
Vector2 statValueSize = MeasureTextEx(DOHYEON_REGULAR, statValue.c_str(), SCL(40), 1);
DrawTextEx(DOHYEON_REGULAR, statValue.c_str(), Vector2{offsetX + SCL(x) - statValueSize.x, offsetY + SCL(124)}, SCL(40), 1, GRAY_6_COLOR_100);
DrawTextEx(DOHYEON_REGULAR, statTitle.c_str(), Vector2{offsetX + SCL(x) - statTitleSize.x, offsetY + SCL(176)}, SCL(20), 1, GRAY_4_COLOR_100);
#undef SCL
}
MenuAction MenuScreen::renderMenu(int screenWidth, int screenHeight, int offsetX, int offsetY, int scaledWidth, int scaledHeight, InputManager& input, int nativeWidth, int nativeHeight, Shader& gradientShader, TaskData& taskData) {
float aspectScale = (float)scaledWidth / (float)nativeWidth;
#define SCL(val) ((float)(val) * aspectScale)
int centerX = offsetX + scaledWidth / 2; // new top left for 16:9 (0,0)
int centerY = offsetY + scaledHeight / 2;
DrawRectangle(offsetX, offsetY, scaledWidth, scaledHeight, BACKGROUND_COLOR_100); // background
//top right pattern
for (int i{0}; i < 12; ++i) {
Vector2 points[5] = {
Vector2{offsetX + SCL(490 + i * 120), offsetY + SCL(50)},
Vector2{offsetX + SCL(680 + i * 120), offsetY + SCL(240)},
Vector2{offsetX + SCL(740 + i * 120), offsetY + SCL(240)},
Vector2{offsetX + SCL(550 + i * 120), offsetY + SCL(50)},
};
DrawTriangleFan(points, 4, GRAY_0_COLOR_40);
}
DrawRectangle(offsetX + SCL(490), offsetY + SCL(20), SCL(200), SCL(240), BACKGROUND_COLOR_100);
DrawRectangle(offsetX + SCL(1880), offsetY + SCL(20), SCL(40), SCL(240), BACKGROUND_COLOR_100);
Gradient::drawGradientRect( // background PRIMARY_0 accent gradient
gradientShader,
Rectangle{ (float)offsetX, (float)offsetY, (float)SCL(500), (float)scaledHeight },
hexToColor("#273A3B", 1.0f),
BACKGROUND_COLOR_100,
false
);
DrawRectangle(offsetX + SCL(40), offsetY + SCL(20), SCL(726), SCL(4), GRAY_7_COLOR_80); // top accent bar
DrawTriangle(
Vector2{(float)offsetX + SCL(740), (float)offsetY + SCL(24)},
Vector2{(float)offsetX + SCL(766), (float)offsetY + SCL(50)},
Vector2{(float)offsetX + SCL(766), (float)offsetY + SCL(24)},
GRAY_7_COLOR_80
);
Gradient::drawGradientRect(
gradientShader,
Rectangle{ (float)offsetX + SCL(766), (float)offsetY + SCL(20), (float)SCL(1114), (float)SCL(30) },
GRAY_7_COLOR_80,
GRAY_7_COLOR_40,
false
);
DrawRectangle(offsetX + SCL(1527), offsetY + SCL(30), SCL(100), SCL(10), GRAY_5_COLOR_80); //top accent bar details
DrawRectangle(offsetX + SCL(1647), offsetY + SCL(30), SCL(100), SCL(10), PRIMARY_0_COLOR_100);
DrawRectangle(offsetX + SCL(1767), offsetY + SCL(30), SCL(100), SCL(10), GRAY_5_COLOR_80);
std::pair<std::string, std::string> dateTime = getDateTime();
DrawTextEx(DOHYEON_REGULAR, dateTime.first.c_str(), Vector2{offsetX + SCL(766), offsetY + SCL(25)}, SCL(22), 1, PRIMARY_1_COLOR_100);
Vector2 dateSize = MeasureTextEx(DOHYEON_REGULAR, dateTime.first.c_str(), SCL(22), 1);
DrawTextEx(DOHYEON_REGULAR, dateTime.second.c_str(), Vector2{offsetX + SCL(766) + dateSize.x, offsetY + SCL(25)}, SCL(22), 1, PRIMARY_2_COLOR_100);
DrawRectangle(offsetX + SCL(40), offsetY + SCL(40), SCL(10), SCL(200), GRAY_7_COLOR_100); // title gradient vertical start
Gradient::drawGradientRect( // title gradient backing
gradientShader,
Rectangle{ (float)offsetX + SCL(50), (float)offsetY + SCL(40), (float)SCL(600), (float)SCL(200) },
hexToColor("#16846B", 1.0f),
hexToColor("#16846B", 0.0f),
false
);
DrawTextEx(ORBITRON_BOLD, "aimfly", Vector2{offsetX + SCL(80), offsetY + SCL(57)}, SCL(125), 1, WHITE_COLOR_100);
DrawTextEx(DOHYEON_REGULAR, "VALORANT aim trainer", Vector2{offsetX + SCL(80), offsetY + SCL(158)}, SCL(27), 1, WHITE_COLOR_80);
DrawRectangle(offsetX + SCL(757), offsetY + SCL(109), SCL(200), SCL(2), GRAY_3_COLOR_100); // stat panel accent line
DrawLineEx(Vector2{static_cast<float>(offsetX + SCL(956)), static_cast<float>(offsetY + SCL(110))}, Vector2{static_cast<float>(offsetX + SCL(1018)), static_cast<float>(offsetY + SCL(170))}, 2.4f * aspectScale, GRAY_3_COLOR_100);
DrawRectangle(offsetX + SCL(1017), offsetY + SCL(169), SCL(800), SCL(2), GRAY_3_COLOR_100);
DrawTextEx(DOHYEON_REGULAR, "PLAY TIME", Vector2{offsetX + SCL(757), offsetY + SCL(86)}, SCL(20), 1, GRAY_4_COLOR_100);
DrawTextEx(DOHYEON_REGULAR, "100hr", Vector2{offsetX + SCL(757), offsetY + SCL(120)}, SCL(40), 1, GRAY_6_COLOR_100);
std::string accuracyStr = std::to_string(taskData.shots == 0 ? 0 : 100.0 * taskData.hits / taskData.shots);
accuracyStr = accuracyStr.substr(0, 5);
drawStat(aspectScale, offsetX, offsetY, 1217, "TIME", std::to_string(static_cast<int>(taskData.taskDuration)) + "s");
drawStat(aspectScale, offsetX, offsetY, 1417, "SCORE", std::to_string(taskData.score));
drawStat(aspectScale, offsetX, offsetY, 1617, "ACCURACY", accuracyStr + "%");
drawStat(aspectScale, offsetX, offsetY, 1817, "AVG TIME", std::to_string(static_cast<int>(taskData.timePerTarget * 1000)) + "ms");
DrawRectangle(offsetX + SCL(761), offsetY + SCL(219), SCL(4), SCL(4), GRAY_5_COLOR_80); // stat panel accent
DrawRectangle(offsetX + SCL(780), offsetY + SCL(219), SCL(213), SCL(4), GRAY_5_COLOR_80);
for (int i{}; i < 5; ++i) {
DrawRectangle(offsetX + SCL(20), offsetY + SCL(422 + i * 100), SCL(300), SCL(2), GRAY_2_COLOR_100); //selection column 1 separator bars
DrawTriangle(
Vector2{(float)offsetX + SCL(67), (float)offsetY + SCL(424 + i * 100)},
Vector2{(float)offsetX + SCL(67), (float)offsetY + SCL(428 + i * 100)},
Vector2{(float)offsetX + SCL(71), (float)offsetY + SCL(424 + i * 100)},
GRAY_2_COLOR_100
);
DrawRectangle(offsetX + SCL(20), offsetY + SCL(424 + i * 100), SCL(47), SCL(4), GRAY_2_COLOR_100);
DrawRectangle(offsetX + SCL(10), offsetY + SCL(434 + i * 100), SCL(4), SCL(4), GRAY_5_COLOR_100); //selection column 1 accent
}
DrawRectangle(offsetX + SCL(442), offsetY + SCL(336), SCL(360), SCL(2), GRAY_2_COLOR_100); //selection column 2 upper border
DrawTriangle(
Vector2{(float)offsetX + SCL(742), (float)offsetY + SCL(336)},
Vector2{(float)offsetX + SCL(746), (float)offsetY + SCL(336)},
Vector2{(float)offsetX + SCL(746), (float)offsetY + SCL(332)},
GRAY_2_COLOR_100
);
DrawRectangle(offsetX + SCL(746), offsetY + SCL(332), SCL(56), SCL(4), GRAY_2_COLOR_100);
DrawRectangle(offsetX + SCL(842), offsetY + SCL(336), SCL(1038), SCL(2), GRAY_2_COLOR_100); //details pane upper border
DrawTriangle(
Vector2{(float)offsetX + SCL(1820), (float)offsetY + SCL(336)},
Vector2{(float)offsetX + SCL(1824), (float)offsetY + SCL(336)},
Vector2{(float)offsetX + SCL(1824), (float)offsetY + SCL(332)},
GRAY_2_COLOR_100
);
DrawRectangle(offsetX + SCL(1824), offsetY + SCL(332), SCL(56), SCL(4), GRAY_2_COLOR_100);
DrawRectangle(offsetX + SCL(842), offsetY + SCL(910), SCL(1038), SCL(2), GRAY_2_COLOR_100); //details pane lower border
DrawTextEx(DOHYEON_REGULAR, "v0.0.0", Vector2{offsetX + SCL(10), offsetY + SCL(1045)}, SCL(20), 1, GRAY_1_COLOR_100); //version text
DrawRectangle(offsetX + SCL(10), offsetY + SCL(1068), SCL(100), SCL(6), GRAY_1_COLOR_100); //bottom left accent
DrawRectangle(offsetX + SCL(140), offsetY + SCL(1068), SCL(100), SCL(6), GRAY_6_COLOR_100);
DrawRectangle(offsetX + SCL(270), offsetY + SCL(1068), SCL(100), SCL(6), GRAY_1_COLOR_100);
DrawRectangle(offsetX + SCL(400), offsetY + SCL(1068), SCL(100), SCL(6), GRAY_1_COLOR_100);
Vector2 mousePos = input.getMousePosition();
bool mouseClicked = input.isMousePressed(MOUSE_LEFT_BUTTON);
for (int i{}; i < 3; ++i) {
if (!menus[i].visible) continue;
for (int j{}; j < menus[i].buttons.size(); ++j) {
if (menus[i].buttons[j].clicked(offsetX, offsetY, aspectScale, mousePos, mouseClicked)) {
menus[i].selectedIndex = j;
}
}
for (int j{}; j < menus[i].buttons.size(); ++j) {
menus[i].buttons[j].isSelected = (j == menus[i].selectedIndex);
menus[i].buttons[j].draw(offsetX, offsetY, aspectScale, mousePos, mouseClicked);
}
}
for (int i{}; i < 3; ++i) {
if (!menus[i].visible) continue;
for (int j{}; j < menus[i].buttons.size(); ++j) {
if (menus[i].buttons[j].clicked(offsetX, offsetY, aspectScale, mousePos, mouseClicked)) {
auto it = buttonActions.find(menus[i].buttons[j].text);
if (it != buttonActions.end()) {
std::cout << menus[i].buttons[j].text << std::endl;
return it->second;
}
}
}
}
static bool gridInitialized = false;
if (!gridInitialized) {
gridMenus.push_back(GridMenu{});
std::vector<std::string> taskNames = {
"thing",
"another thing",
"b",
"d"
};
gridMenus.back().generateGrid(taskNames, SCL(842), SCL(338), SCL(1038), SCL(572), offsetX, offsetY, aspectScale);
gridInitialized = true;
}
// Render grid boxes
for (int i{}; i < gridMenus.size(); ++i) {
gridMenus[i].renderGridBoxes(input);
}
#undef SCL
return MenuAction::NONE; // default on load
}
MenuAction MenuScreen::renderPauseOverlay(int screenWidth, int screenHeight, int offsetX, int offsetY, int scaledWidth, int scaledHeight, InputManager& input, int nativeWidth, int nativeHeight, Shader& gradientShader) {
float aspectScale = (float)scaledWidth / (float)nativeWidth;
#define SCL(val) ((float)(val) * aspectScale)
int centerX = offsetX + scaledWidth / 2; // new top left for 16:9 (0,0)
int centerY = offsetY + scaledHeight / 2;
DrawRectangle(offsetX + SCL(0), offsetY + SCL(0), SCL(1920), SCL(1080), BACKGROUND_COLOR_80);
DrawRectangle(offsetX + SCL(695), offsetY + SCL(354), SCL(10), SCL(372), GRAY_6_COLOR_100); //panel gradient start
Gradient::drawGradientRect( // panel gradient
gradientShader,
Rectangle{(float)offsetX + SCL(705), (float)offsetY + SCL(354), (float)SCL(520), (float)SCL(372)},
PRIMARY_0_COLOR_100,
PRIMARY_0_COLOR_20,
false
);
//DrawRectangle(offsetX + SCL(725), offsetY + SCL(360), SCL(163), SCL(50), GRAY_2_COLOR_100);
DrawTextEx(ORBITRON_BOLD, "paused", Vector2{offsetX + SCL(725), offsetY + SCL(360)}, SCL(50), 1, GRAY_6_COLOR_100);
DrawRectangle(offsetX + SCL(725), offsetY + SCL(421), SCL(480), SCL(2), GRAY_5_COLOR_100); //selection column 2 upper border
DrawTriangle(
Vector2{(float)offsetX + SCL(1145), (float)offsetY + SCL(421)},
Vector2{(float)offsetX + SCL(1149), (float)offsetY + SCL(421)},
Vector2{(float)offsetX + SCL(1149), (float)offsetY + SCL(417)},
GRAY_5_COLOR_100
);
DrawRectangle(offsetX + SCL(1149), offsetY + SCL(417), SCL(56), SCL(4), GRAY_5_COLOR_100);
Vector2 mousePos = input.getMousePosition();
bool mouseClicked = input.isMousePressed(MOUSE_LEFT_BUTTON);
for (int i{3}; i < 4; ++i) {
if (!menus[i].visible) continue;
for (int j{}; j < menus[i].buttons.size(); ++j) {
if (menus[i].buttons[j].clicked(offsetX, offsetY, aspectScale, mousePos, mouseClicked)) {
menus[i].selectedIndex = j;
}
}
for (int j{}; j < menus[i].buttons.size(); ++j) {
menus[i].buttons[j].isSelected = (j == menus[i].selectedIndex);
menus[i].buttons[j].draw(offsetX, offsetY, aspectScale, mousePos, mouseClicked);
}
}
for (int i{3}; i < 4; ++i) {
if (!menus[i].visible) continue;
for (int j{}; j < menus[i].buttons.size(); ++j) {
if (menus[i].buttons[j].clicked(offsetX, offsetY, aspectScale, mousePos, mouseClicked)) {
auto it = buttonActions.find(menus[i].buttons[j].text);
if (it != buttonActions.end()) {
std::cout << menus[i].buttons[j].text << std::endl;
return it->second;
}
}
}
}
#undef SCL
return MenuAction::NONE; //default on load
}
void MenuScreen::renderCountdown(int screenWidth, int screenHeight, int offsetX, int offsetY, int scaledWidth, int scaledHeight, InputManager& input, int nativeWidth, int nativeHeight, Shader& gradientShader, Task& task) {
float aspectScale = (float)scaledWidth / (float)nativeWidth;
#define SCL(val) ((float)(val) * aspectScale)
int centerX = offsetX + scaledWidth / 2; // new top left for 16:9 (0,0)
int centerY = offsetY + scaledHeight / 2;;
DrawRectangle(offsetX + SCL(0), offsetY + SCL(0), SCL(1920), SCL(1080), BACKGROUND_COLOR_80);
DrawRectangle(offsetX + SCL(910), offsetY + SCL(495), SCL(10), SCL(90), GRAY_6_COLOR_100); //panel gradient start
Gradient::drawGradientRect( // panel gradient
gradientShader,
Rectangle{(float)offsetX + SCL(920), (float)offsetY + SCL(495), (float)SCL(90), (float)SCL(90)},
PRIMARY_0_COLOR_100,
PRIMARY_0_COLOR_20,
false
);
//DrawRectangle(offsetX + SCL(960 - 30), offsetY + SCL(540 - 30), 60, 60, PRIMARY_0_COLOR_100);
DrawTextEx(ORBITRON_BOLD, std::to_string(-static_cast<int>(task.time) + 1).c_str(), Vector2{offsetX + SCL(945), offsetY + SCL(515)}, SCL(50), 1, GRAY_6_COLOR_100);
#undef SCL
}