-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.h
238 lines (216 loc) · 6.46 KB
/
helper.h
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
#pragma once
#include "fundamentals.h"
void gotoxy(int x, int y)
{
// Set console cursor position
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void changeSystemColor(string bg = theme.background, string fg = theme.foreground)
{
string command = "color " + bg + fg;
const char* commandCStr = command.c_str();
system(commandCStr);
}
void animateText(string sentence)
{
for (int j = 0; j < sentence.length(); j++)
{
// skip the text if enter is pressed during the animation, put changes here
Sleep(20);
if ((GetAsyncKeyState(VK_RETURN) & 0x8000) && j > 2)
{
for (int k = j; k < sentence.length(); k++)
{
cout << sentence[k];
}
Sleep(300);
break;
}
cout << sentence[j];
}
}
void cleanDialogueBox()
{
for (int i = 0; i < dialogueBoxHeight - 2; i++)
{
gotoxy(dialogueBoxStart.x + 1, dialogueBoxStart.y + 1 + i);
for (int i = 0; i < dialogueBoxWidth - 2; i++)
{
cout << " ";
}
}
}
void customPrint(int x, int y, int width, const std::string& text, int& linesTaken)
{
// Initial position
int currentX = x;
int currentY = y;
// Iterate through each character in the text
for (char ch : text)
{
// Check if the current position exceeds the specified width
if (currentX - x >= width)
{
// Move to the next line
currentX = x;
currentY++;
linesTaken++;
}
// Set the cursor position and print the character
gotoxy(currentX, currentY);
std::cout << ch;
// Move to the next column
currentX++;
}
}
void enableBGText(WORD backgroundColor)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, backgroundColor);
}
void disableBGText()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
changeSystemColor(theme.background, theme.foreground);
}
int getConsoleWidth()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
return csbi.dwSize.X;
}
int getConsoleHeight()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
return csbi.dwSize.Y;
}
char getCharacterAtPosition(int x, int y)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE)
{
std::cerr << "Invalid handle." << std::endl;
return '\0';
}
COORD coord = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
DWORD charsRead;
char charBuffer;
if (!ReadConsoleOutputCharacterA(hConsole, &charBuffer, 1, coord, &charsRead))
{
std::cerr << "ReadConsoleOutputCharacterA failed." << std::endl;
return '\0';
}
return charBuffer;
}
int getASCIIAtPosition(int x, int y)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE)
{
std::cerr << "Invalid handle." << std::endl;
return 0; // Return 0 to indicate an error
}
COORD coord = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
DWORD charsRead;
char charBuffer;
if (!ReadConsoleOutputCharacterA(hConsole, &charBuffer, 1, coord, &charsRead))
{
std::cerr << "ReadConsoleOutputCharacterA failed." << std::endl;
return 0; // Return 0 to indicate an error
}
// Convert the character to ASCII value (cast to int)
int asciiValue = static_cast<int>(charBuffer);
return asciiValue;
}
void loadingbar()
{
system("cls");
printf("\e[?251");
SetConsoleCP(437);
SetConsoleOutputCP(437);
int bar1 = 177, bar2 = 219;
cout << "\n\n\n\t\t\t\t\t\t\t\t\t Loading...";
cout << "\n\n\n\t\t\t\t\t\t\t\t\t";
for (int i = 1; i <= 25; i++)
cout << (char)bar1;
cout << "\r\t\t\t\t\t\t\t\t\t";
for (int i = 0; i <= 25; i++)
{
if (_kbhit())
{
char key = _getch();
if (key == '\t')
{
// Skip loading if Tab key is pressed
cout << "\n\t\t\t\t\t\t\t\t\tLoading skipped by user.\n";
return;
}
}
cout << (char)bar2;
Sleep(50);
}
}
void centerText(const string& text)
{
int width = getConsoleWidth();
if (width > 0)
{
int padding = (width - static_cast<int>(text.length())) / 2;
for (int i = 0; i < padding; i++)
{
cout << " ";
}
cout << text; // Display centered text.
}
else
{
cerr << "Unable to determine console width." << endl; // Print an error message if console width cannot be determined.
}
}
string toLowerCase(string answer)
{
for (char& c : answer)
{
c = tolower(c);
}
return answer;
}
// void playAudio(const char *filePath)
// {
// PlaySound(TEXT("C:/Users/Track Computers/Desktop/track.wav"), NULL, SND_FILENAME | SND_ASYNC);
// }
void cursorPosition(int x, int y)
{
COORD coordinates;
coordinates.X = x;
coordinates.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordinates);
}
void loadingScreen()
{
cout << setw(115) << "______ _ _ _____ ____ _____ ____ _ _ _____ _____ _____ _____ _____ _____ _____" << endl;
cout << setw(115) << " | | | | | | | | | | | | | | | | | | | | | " << endl;
cout << setw(115) << " | | | | | | | | | -| | | | | | | | | | | | " << endl;
cout << setw(115) << " | |___| |____ |___| | | |__| | | |____ |____ |___| | |___| |___| |____" << endl;
cout << setw(115) << " | | | | |\\ | | | | | | | | | | | | | " << endl;
cout << setw(115) << " | | | | | \\ | | | | | | | | | | | | | | " << endl;
cout << setw(115) << " | | | |____ | \\ |___| | |___| |____ |____ ____| |___| | | | |____" << endl;
cout << endl
<< endl;
cout << setw(60) << "Loading... ";
for (int i = 0; i < 22; i++)
{
cout << char(177);
}
for (int i = 0; i < 22; i++)
{
cursorPosition(60 + i, 11);
Sleep(25);
cout << char(178);
}
}