summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2024-08-30 16:23:06 -0500
committer@syxhe <https://t.me/syxhe>2024-08-30 16:23:06 -0500
commitb1b00b4a8aad8ea97c318aab597b9468c536e656 (patch)
tree2b74c230b212a655b1e55d192e71e0f4ced7650b /src/screen.c
parent9497cdd0d6d1483f559aacf3f8f2bbb6a11716ab (diff)
Restructure screen & add header defs
Diffstat (limited to 'src/screen.c')
-rw-r--r--src/screen.c465
1 files changed, 189 insertions, 276 deletions
diff --git a/src/screen.c b/src/screen.c
index 5fe2822..7018c2a 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -5,6 +5,9 @@
5 * files back. To do this, I am using curses and probably the menu library to create the TUI. Once I figure 5 * files back. To do this, I am using curses and probably the menu library to create the TUI. Once I figure
6 * out how to actually do this, everything should work hopefully maybe 6 * out how to actually do this, everything should work hopefully maybe
7 * 7 *
8 * DEAR HACKER, PLEASE PLEASE DO NOT BOTHER LEARNING CURSES FOR A JOKE. IT WAS A BAD IDEA AND IF YOU'RE RESTARDED
9 * LIKE ME SUNKEN COST WILL KICK IN AND IT WILL NAG AT YOU UNTIL IT'S DONE. DO NOT MAKE THE SAME MISTAKE I MADE.
10 * RUN, RUN FOR THE SAKE OF ALL THAT'S HOLY AND OTHERWISE
8 */ 11 */
9 12
10#define _GNU_SOURCE 13#define _GNU_SOURCE
@@ -24,87 +27,7 @@
24#include <stdlib.h> 27#include <stdlib.h>
25#include <string.h> 28#include <string.h>
26 29
27static const char *phrases[] = { 30//////////////////////////////////// SPECIFICALLY USEFUL FUNCS ////////////////////////////////////
28 // By @syxhe on telegram
29 "WE CLOWN IN THIS MF, TAKE YO SENSITIVE ASS BACK TO @GENTOOMEMES",
30 "R.I.P VxHeaven",
31 "tmp(2) nuked by Smelly",
32 "99% of Ransomware Operators quit before compromising a bank",
33 "Equation Group wuz here",
34 "Lazarus wuz here",
35 "LockBit wuz here",
36 "Sponsored by Equation Group",
37 "Sponsored by Lazarus",
38 "Sponsored by LockBit",
39 "Free my boy Ross Ulbricht he did nothing wrong",
40 "Stay off the dark web, kids",
41 "FREE BITCOIN JUST 3 SPINS AWAY",
42 "We all glow in the dark",
43 "Shoutouts to Simpleflips",
44 "Shoutouts to BugHunter",
45 "Shoutouts to EyeDeeKay",
46 ":beecat:",
47 ":3",
48 "You think Jack Rhysider will interview me now?",
49 "Check out \"Darknet Diaries\"",
50 "Chill and losing it since 2016",
51 "POOL'S CLOSED",
52 "I've been diagnosed with snaids",
53 "My balls itch",
54 "We killin filez and shiit",
55 "lonix users BTFO once again",
56 "This space left intentionally blank",
57 "Thinking of a way out is self-centered at best",
58 "Searching for the punchline to an infinite jest?",
59 "Still learning what it means to feel",
60 "Killroy was NOT here",
61 "Go fuck yourself lmao",
62 "It's so over",
63 "We're so back",
64 "It never even began",
65 "Pepito they shot Trump",
66 "This shit ain't nothing to me man",
67 "I'm him, I will continue to be him",
68 "THERE ARE MOSQUITOS IN YOUR URETHRA, GET THEM OUT!!!",
69 "Something wicked this way comes",
70 "Schizo hour",
71 "Man I could really use some Chicken Bouillon rn",
72 "Fuck my digital footprint, I need a digital footjob",
73 "Having my weekly \"Ted was right\" moment",
74 "Why aren't you in the gym?",
75 "Proof?",
76 "I've gone completely mental",
77 "The rage consumes me",
78 "Go outside. Now.",
79 "Beautiful Day Sunny Morning",
80 "Fuck crypto all my homies hate crypto",
81 "stfu fedsmoker is my dad he'll eat you alive",
82 "Almost dog in hot car'd myself",
83
84 // by @danielsprofile on telegram
85 "Daniel Spears loves femboys",
86 "LizardSquad > Razer",
87 "Sponsored by Major League Gaming",
88 "Sponsored by LemonParty.org",
89 "Sponsored by FTX",
90 "RIP Harambe",
91 "Shoutout Elliot Alderson",
92 "Ted Kaczynski was right",
93 "The FBI watches me jerk off to MILFs lol",
94 "robux generator free online 2024 100% working undetected",
95 "Doge wuz here",
96 "We like Fortnite we like Fortnite",
97 "We live in a society",
98 "Hab you seen a alien pls?",
99 "using a flipperzero makes me an APT, right?",
100 "Subscribe to PewDiePie",
101};
102
103static const char *menu_choices[] = {
104 "Spin",
105 "Buy spins",
106 "Quit"
107};
108 31
109void catcher(int signum, siginfo_t *info, void *ucontext) { 32void catcher(int signum, siginfo_t *info, void *ucontext) {
110 // This is retarded lol, but makes gcc happy 33 // This is retarded lol, but makes gcc happy
@@ -113,26 +36,24 @@ void catcher(int signum, siginfo_t *info, void *ucontext) {
113 36
114 switch(signum) { 37 switch(signum) {
115 case SIGINT: 38 case SIGINT:
116 endwin(); 39 endwin();
117 error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt"); 40 error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt");
118 exit(0); 41 exit(0);
119 42
120 case SIGWINCH: 43 case SIGWINCH:
121 endwin(); 44 endwin();
122 error(1, 0, "[VX-GAMBLEGROUND] User changed window size and I haven't implemented code to handle it yet"); 45 error(1, 0, "[VX-GAMBLEGROUND] User changed window size and I haven't implemented code to handle it yet");
123 abort(); // Makes gcc happy (angry about implicit fallthrough) 46 abort(); // Makes gcc happy (angry about implicit fallthrough)
124 47
125 default: 48 default:
126 abort(); 49 abort();
127 } 50 }
128 51
129 return; 52 return;
130} 53}
131 54
132static struct sigaction handler = {.sa_flags = SA_SIGINFO, .sa_mask = SIGINT | SIGWINCH, .sa_sigaction = catcher};
133
134// Initialize sodium, curses, and set the proper locale. Exits on error, returns 0 otherwise 55// Initialize sodium, curses, and set the proper locale. Exits on error, returns 0 otherwise
135static int doinit(void) { 56int doinit(const struct sigaction *handler) {
136 if(sodium_init() < 0) 57 if(sodium_init() < 0)
137 error(1, errno, "[VX-GAMBLEGROUND] Could not initialize sodium"); 58 error(1, errno, "[VX-GAMBLEGROUND] Could not initialize sodium");
138 59
@@ -142,8 +63,8 @@ static int doinit(void) {
142 if(initscr() == NULL) // Initialize curses 63 if(initscr() == NULL) // Initialize curses
143 error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); 64 error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen");
144 65
145 if(sigaction(SIGINT, &handler, NULL) < 0 || sigaction(SIGWINCH, &handler, NULL) < 0) 66 if(sigaction(SIGINT, handler, NULL) < 0 || sigaction(SIGWINCH, handler, NULL) < 0)
146 error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal catcher"); 67 error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal handlers");
147 68
148 69
149 cbreak(); // Disables character buffering 70 cbreak(); // Disables character buffering
@@ -154,69 +75,53 @@ static int doinit(void) {
154} 75}
155 76
156// Initialize colors & define a few custom colors & color pairs. Exits on error, returns 0 otherwise 77// Initialize colors & define a few custom colors & color pairs. Exits on error, returns 0 otherwise
157static int docolors(void) { 78int docolors(void) {
158 if(has_colors() && can_change_color()) { // Init colors if available & create color pairings 79 // Idk what possessed me to put this entire thing in an if-statement instead of using an early return
159 start_color(); 80 // Whatever, it's fixed now
160 81
161 // Init colors here 82 if(!has_colors() && !can_change_color()) {
162 // TODO: FIGURE OUT WHY COLORS ARE SO FUCKEY
163 /* The colors were being weird because I was being retarded and redefining already existing colors
164 // to numbers well outside curses' 0-1000 range. Making an enum that redefined the already existing
165 // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so
166 // use a normal terminal for accurate colors */
167
168 init_rgb_color(CC_RED, 255, 0, 0);
169 init_rgb_color(CC_ORANGE, 255, 128, 0);
170 init_rgb_color(CC_YELLOW, 255, 255, 0);
171 init_rgb_color(CC_GREEN, 0, 255, 0);
172 init_rgb_color(CC_BLUE, 0, 0, 255);
173 init_rgb_color(CC_PURPLE, 128, 0, 255);
174 init_rgb_color(CC_MAGENTA, 255, 0, 255);
175 init_rgb_color(CC_WHITE, 255, 255, 255);
176 init_rgb_color(CC_BLACK, 0, 0, 0);
177
178 init_rgb_color(CC_WINNING, 232, 185, 35);
179
180
181 init_pair(CCP_TESTING, CC_RED, CC_WHITE);
182 init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE);
183
184 init_pair(CCP_RED, CC_WHITE, CC_RED);
185 init_pair(CCP_ORANGE, CC_BLACK, CC_ORANGE);
186 init_pair(CCP_YELLOW, CC_BLACK, CC_YELLOW);
187 init_pair(CCP_GREEN, CC_BLACK, CC_GREEN);
188 init_pair(CCP_BLUE, CC_WHITE, CC_BLUE);
189 init_pair(CCP_PURPLE, CC_WHITE, CC_PURPLE);
190 init_pair(CCP_MAGENTA, CC_WHITE, CC_MAGENTA);
191 init_pair(CCP_WHITE, CC_BLACK, CC_WHITE);
192
193 init_pair(CCP_WINNING1, CC_WHITE, CC_WINNING);
194 init_pair(CCP_WINNING2, CC_WINNING, CC_WHITE);
195 } else {
196 endwin(); 83 endwin();
197 error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal"); 84 error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal");
198 } 85 }
199 86
200 return 0; 87 // Necessary for color
201} 88 start_color();
202 89
203static WINDOW* create_banner(int col, int randomnum) { 90 // Init everything
204 // Create the banner window 91 init_rgb_color(CC_RED, 255, 0, 0);
205 WINDOW *phrase = newwin(1, col, 0, 0); 92 init_rgb_color(CC_ORANGE, 255, 128, 0);
206 if(phrase == NULL) { 93 init_rgb_color(CC_YELLOW, 255, 255, 0);
207 endwin(); 94 init_rgb_color(CC_GREEN, 0, 255, 0);
208 error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); 95 init_rgb_color(CC_BLUE, 0, 0, 255);
209 } 96 init_rgb_color(CC_PURPLE, 128, 0, 255);
210 wbkgd(phrase, COLOR_PAIR(CCP_BANNER)); 97 init_rgb_color(CC_MAGENTA, 255, 0, 255);
211 mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); 98 init_rgb_color(CC_WHITE, 255, 255, 255);
212 waddstr(phrase, phrases[randomnum]); 99 init_rgb_color(CC_BLACK, 0, 0, 0);
213 wnoutrefresh(phrase);
214 100
215 return phrase; 101 init_rgb_color(CC_WINNING, 232, 185, 35);
102
103
104 // Create pairs
105 init_pair(CCP_TESTING, CC_RED, CC_WHITE);
106 init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE);
107
108 init_pair(CCP_RED, CC_WHITE, CC_RED);
109 init_pair(CCP_ORANGE, CC_BLACK, CC_ORANGE);
110 init_pair(CCP_YELLOW, CC_BLACK, CC_YELLOW);
111 init_pair(CCP_GREEN, CC_BLACK, CC_GREEN);
112 init_pair(CCP_BLUE, CC_WHITE, CC_BLUE);
113 init_pair(CCP_PURPLE, CC_WHITE, CC_PURPLE);
114 init_pair(CCP_MAGENTA, CC_WHITE, CC_MAGENTA);
115 init_pair(CCP_WHITE, CC_BLACK, CC_WHITE);
116
117 init_pair(CCP_WINNING1, CC_WHITE, CC_WINNING);
118 init_pair(CCP_WINNING2, CC_WINNING, CC_WHITE);
119
120 return 0;
216} 121}
217 122
218// I will figure out how to properly pass a void pointer eventually (if I care enough) 123// I will figure out how to properly pass a void pointer eventually (if I care enough)
219static int init_items(ITEM *items[], const char *menuopts[], size_t menuopts_size, struct funcholder usrptrs[]) { 124int init_items(ITEM *items[], const char *menuopts[], size_t menuopts_size, struct funcholder usrptrs[]) {
220 for(size_t i = 0; i < menuopts_size; i++) { 125 for(size_t i = 0; i < menuopts_size; i++) {
221 items[i] = new_item(menuopts[i], NULL); 126 items[i] = new_item(menuopts[i], NULL);
222 set_item_userptr(items[i], (void*)&usrptrs[i]); 127 set_item_userptr(items[i], (void*)&usrptrs[i]);
@@ -226,30 +131,7 @@ static int init_items(ITEM *items[], const char *menuopts[], size_t menuopts_siz
226 return 0; 131 return 0;
227} 132}
228 133
229static int mvwcreate_box(WINDOW *win, int y, int x, int height, int width, const chtype chars[6]) { 134int init_slotholder(struct slotholder *slots) {
230 const chtype * realchars = chars;
231 if(chars == NULL)
232 realchars = (const chtype []){ACS_VLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER};
233
234 // Vertical lines
235 mvwvline(win, y, x, realchars[0], height);
236 mvwvline(win, y, x + width - 1, realchars[0], height);
237
238 // Horizontal lines
239 mvwhline(win, y, x, realchars[1], width - 1);
240 mvwhline(win, y + height - 1, x, realchars[1], width) - 1;
241
242 // Corners
243 mvwaddch(win, y, x, realchars[2]); // Upper left corner
244 mvwaddch(win, y, x + width - 1, realchars[3]); // Upper right corner
245 mvwaddch(win, y + height - 1, x, realchars[4]); // Lower left corner
246 mvwaddch(win, y + height - 1, x + width - 1, realchars[5]); // Lower right corner
247
248 // Yeah I'm not happy about the magic numbers either, but this combo of shit makes the box draw correctly
249 return 0;
250}
251
252static int init_slotholder(struct slotholder *slots) {
253 mvwaddstr(slots->slotwin, 0, 1, "Spins: 3, Price: 1"); 135 mvwaddstr(slots->slotwin, 0, 1, "Spins: 3, Price: 1");
254 wnoutrefresh(slots->slotwin); 136 wnoutrefresh(slots->slotwin);
255 137
@@ -275,8 +157,7 @@ static int init_slotholder(struct slotholder *slots) {
275 return 0; 157 return 0;
276} 158}
277 159
278 160int init_custom_menu_format(WINDOW *menuholder, MENU *menu, const int fmtdim[2], Menu_Options toggleon, Menu_Options toggleoff) {
279static int init_custom_menu_format(WINDOW *menuholder, MENU *menu, const int fmtdim[2], Menu_Options toggleon, Menu_Options toggleoff) {
280 // Set menu options & format 161 // Set menu options & format
281 set_menu_format(menu, fmtdim[0], fmtdim[1]); 162 set_menu_format(menu, fmtdim[0], fmtdim[1]);
282 menu_opts_on(menu, toggleon); 163 menu_opts_on(menu, toggleon);
@@ -300,120 +181,70 @@ static int init_custom_menu_format(WINDOW *menuholder, MENU *menu, const int fmt
300 return 0; 181 return 0;
301} 182}
302 183
303int main() { 184WINDOW* create_banner(int col, int randomnum) {
304 doinit(); 185 // Create the banner window
305 docolors(); 186 WINDOW *phrase = newwin(1, col, 0, 0);
306 187 if(phrase == NULL) {
307 // Variable definitions
308 ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items
309 struct funcholder *p = NULL;
310 struct params params; // Function pointer used for callbacks in the menu driver
311 WINDOW *menuholder = NULL; // The window for displaying the menu
312 int row = -1, col = -1; // The rows and columns of the main screen
313 uint32_t randomnum; // A random number for getting the banner phrase
314 MENU *menu; // The actual menu object
315 int c; // Integer for storing keys from user input
316
317 struct funcholder userfuncs[] = {
318 {.callback = spin, .type = FH_SPIN},
319 {.callback = buy, .type = FH_BUY},
320 {.callback = quit, .type = FH_QUIT},
321 {0}
322 };
323
324 struct slotholder slots;
325
326 getmaxyx(stdscr, row, col);
327 if(row < 0 || col < 0) {
328 endwin(); 188 endwin();
329 error(1, 0, "[VX-GAMBLEGROUND] Couldn't get max terminal size for some reason"); 189 error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window");
330 } 190 }
191 wbkgd(phrase, COLOR_PAIR(CCP_BANNER));
192 mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: ");
193 waddstr(phrase, phrases[randomnum]);
194 wnoutrefresh(phrase);
331 195
332 randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases) + 1); 196 return phrase;
333 197}
334 WINDOW *banner = create_banner(col, randomnum);
335 init_items(items, menu_choices, STATIC_ARRSIZE(menu_choices), userfuncs);
336
337 // No point in moving this into a function
338 menu = new_menu(items);
339 if(menu == NULL) {
340 endwin();
341 error(1, errno, "Could not create menu");
342 }
343 198
344 // Set up the menuholder & init everything 199int handle_menuitem(MENU *menu, struct params *params) {
345 menuholder = newwin(1, col, row - 1, 0); 200 struct funcholder *p = (struct funcholder *)item_userptr(current_item(menu));
346 keypad(menuholder, TRUE); 201 switch(p->type) {
347 init_custom_menu_format(menuholder, menu, (int []){1, col}, O_ONEVALUE | O_IGNORECASE, O_SHOWDESC | O_NONCYCLIC); 202 case FH_SPIN: case FH_BUY:
203 p->callback((void*)params);
204 break;
348 205
206 case FH_QUIT:
207 p->callback(NULL);
208 break;
349 209
350 slots.slotwin = newwin(row - 2, col, 1, 0); 210 default:
351 if(slots.slotwin == NULL) {
352 endwin(); 211 endwin();
353 error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window"); 212 error(1, ENOTSUP, "SHIT BROKE");
354 } 213 }
355 214
356 init_slotholder(&slots); 215 return 0;
357 216}
358 doupdate();
359
360 params.bannerwin = banner;
361 params.menu = menu;
362 params.menuholder = menuholder;
363 params.numspins = 3;
364 params.price = 1;
365 params.slots = &slots;
366 217
218int handle_input(WINDOW *menuholder, MENU *menu, struct params *params) {
219 int c;
367 // Get user input and deal with the menu 220 // Get user input and deal with the menu
368 while((c = wgetch(menuholder)) != KEY_F(4)) { 221 while((c = wgetch(menuholder)) != KEY_F(4)) {
369 switch(c) { 222 switch(c) {
370 case KEY_DOWN: 223 case KEY_DOWN:
371 menu_driver(menu, REQ_DOWN_ITEM); 224 menu_driver(menu, REQ_DOWN_ITEM);
372 break; 225 break;
373 226
374 case KEY_UP: 227 case KEY_UP:
375 menu_driver(menu, REQ_UP_ITEM); 228 menu_driver(menu, REQ_UP_ITEM);
376 break; 229 break;
377 230
378 case KEY_LEFT: 231 case KEY_LEFT:
379 menu_driver(menu, REQ_LEFT_ITEM); 232 menu_driver(menu, REQ_LEFT_ITEM);
380 break; 233 break;
381 234
382 case KEY_RIGHT: 235 case KEY_RIGHT:
383 menu_driver(menu, REQ_RIGHT_ITEM); 236 menu_driver(menu, REQ_RIGHT_ITEM);
384 break; 237 break;
385 238
386 case KEY_ENTER: case FUCKED_UP_ENTER: // Enter 239 case KEY_ENTER: case FUCKED_UP_ENTER: // Enter
387 p = (struct funcholder *)item_userptr(current_item(menu)); 240 handle_menuitem(menu, params);
388 switch(p->type) { 241 break;
389 case FH_SPIN: case FH_BUY:
390 p->callback((void*)&params);
391 break;
392
393 case FH_QUIT:
394 p->callback(NULL);
395 break;
396
397 default:
398 endwin();
399 error(1, ENOTSUP, "SHIT BROKE");
400 }
401
402 break;
403 242
404 default: 243 default:
405 break; 244 break;
406 } 245 }
407 } 246 }
408 247
409 // Clean up the menu
410 unpost_menu(menu);
411 free_menu(menu);
412 for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++)
413 free_item(items[i]);
414 //*/
415
416 endwin(); // Clean up curses
417 return 0; 248 return 0;
418} 249}
419 250
@@ -431,7 +262,7 @@ int spin(void *params) {
431 char *newstr = NULL; 262 char *newstr = NULL;
432 if(asprintf(&newstr, "Spins: %d, Price: %d", p->numspins, p->price) < 0) { 263 if(asprintf(&newstr, "Spins: %d, Price: %d", p->numspins, p->price) < 0) {
433 endwin(); 264 endwin();
434 error(1, errno, "[VX-GAMBLEGROUND] Shit brokey lol"); 265 error(1, errno, "[VX-GAMBLEGROUND] asprintf broke");
435 } 266 }
436 mvwaddstr(p->slots->slotwin, 0, 1, newstr); 267 mvwaddstr(p->slots->slotwin, 0, 1, newstr);
437 free(newstr); 268 free(newstr);
@@ -490,19 +321,6 @@ int spin(void *params) {
490 // Do winning anim 321 // Do winning anim
491 mvaddch(0, 0, 'J'); 322 mvaddch(0, 0, 'J');
492 for(int i = 0, color = CCP_WINNING1;; i++, color = rangemod(color, 1, CCP_WINNING1, CCP_WINNING2)) { 323 for(int i = 0, color = CCP_WINNING1;; i++, color = rangemod(color, 1, CCP_WINNING1, CCP_WINNING2)) {
493 // wbkgd(p->bannerwin, COLOR_PAIR(color));
494 // wbkgd(p->menuholder, COLOR_PAIR(color));
495
496 // wbkgd(p->slots->slotwin, COLOR_PAIR(rangemod(color, 1, CCP_WINNING1, CCP_WINNING2)));
497 // for(size_t j = 0; j < STATIC_ARRSIZE(p->slots->subslot); j++) {
498 // wbkgd(p->slots->subslot[j], COLOR_PAIR(rangemod(color, j + 1, CCP_WINNING1, CCP_WINNING2)));
499 // wnoutrefresh(p->slots->subslot[j]);
500 // }
501
502 // wnoutrefresh(p->bannerwin);
503 // wnoutrefresh(p->menuholder);
504 // wnoutrefresh(p->slots->slotwin);
505
506 bkgd(COLOR_PAIR(color)); 324 bkgd(COLOR_PAIR(color));
507 addch("JACKPOT"[rangemod(i, 1, 0, 6)]); 325 addch("JACKPOT"[rangemod(i, 1, 0, 6)]);
508 326
@@ -558,7 +376,7 @@ int buy(void *params) {
558 376
559// Quit out 377// Quit out
560int quit(void *params) { 378int quit(void *params) {
561 379 params = params; // Once agian, useless but makes gcc happy
562 380
563 endwin(); 381 endwin();
564 error(0, 0, "quit"); 382 error(0, 0, "quit");
@@ -567,7 +385,7 @@ int quit(void *params) {
567 return 0; 385 return 0;
568} 386}
569 387
570 388//////////////////////////////////// GENERALLY USEFUL FUNCTIONS ////////////////////////////////////
571 389
572float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { 390float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) {
573 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range 391 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range
@@ -584,4 +402,99 @@ static int init_rgb_color(int colornum, int red, int green, int blue) {
584 int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 402 int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
585 403
586 return init_color(colornum, nred, ngreen, nblue); 404 return init_color(colornum, nred, ngreen, nblue);
405}
406
407int mvwcreate_box(WINDOW *win, int y, int x, int height, int width, const chtype chars[6]) {
408 const chtype * realchars = chars;
409 if(chars == NULL)
410 realchars = (const chtype []){ACS_VLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER};
411
412 // Vertical lines
413 mvwvline(win, y, x, realchars[0], height);
414 mvwvline(win, y, x + width - 1, realchars[0], height);
415
416 // Horizontal lines
417 mvwhline(win, y, x, realchars[1], width - 1);
418 mvwhline(win, y + height - 1, x, realchars[1], width) - 1;
419
420 // Corners
421 mvwaddch(win, y, x, realchars[2]); // Upper left corner
422 mvwaddch(win, y, x + width - 1, realchars[3]); // Upper right corner
423 mvwaddch(win, y + height - 1, x, realchars[4]); // Lower left corner
424 mvwaddch(win, y + height - 1, x + width - 1, realchars[5]); // Lower right corner
425
426 // Yeah I'm not happy about the magic numbers either, but this combo of shit makes the box draw correctly
427 return 0;
428}
429
430//////////////////////////////////// MAIN ////////////////////////////////////
431
432int main() {
433 // I have no fucking clue why gcc complains that this isn't properly bracketed. Maybe im rarted
434 const struct sigaction handler = {
435 .sa_flags = SA_SIGINFO,
436 .sa_mask = SIGINT | SIGWINCH,
437 .sa_sigaction = catcher,
438 };
439 doinit(&handler);
440
441 docolors();
442
443 // Variable definitions
444 ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items
445 struct params params; // Function pointer used for callbacks in the menu driver
446 WINDOW *menuholder = NULL; // The window for displaying the menu
447 int row = -1, col = -1; // The rows and columns of the main screen
448 uint32_t randomnum; // A random number for getting the banner phrase
449 MENU *menu; // The actual menu object
450
451 struct slotholder slots;
452
453 getmaxyx(stdscr, row, col);
454 randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases) + 1);
455
456 WINDOW *banner = create_banner(col, randomnum);
457 init_items(items, menu_choices, STATIC_ARRSIZE(menu_choices), userfuncs);
458
459 // No point in moving this into a function
460 menu = new_menu(items);
461 if(menu == NULL) {
462 endwin();
463 error(1, errno, "Could not create menu");
464 }
465
466 // Set up the menuholder & init everything
467 menuholder = newwin(1, col, row - 1, 0);
468 keypad(menuholder, TRUE);
469 init_custom_menu_format(menuholder, menu, (int []){1, col}, O_ONEVALUE | O_IGNORECASE, O_SHOWDESC | O_NONCYCLIC);
470
471
472 slots.slotwin = newwin(row - 2, col, 1, 0);
473 if(slots.slotwin == NULL) {
474 endwin();
475 error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window");
476 }
477
478 init_slotholder(&slots);
479
480 doupdate();
481
482 params.bannerwin = banner;
483 params.menu = menu;
484 params.menuholder = menuholder;
485 params.numspins = 3;
486 params.price = 1;
487 params.slots = &slots;
488
489 handle_input(menuholder, menu, &params);
490
491 // Clean up the menu
492 unpost_menu(menu);
493 free_menu(menu);
494 for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++)
495 free_item(items[i]);
496 //*/
497
498 endwin(); // Clean up curses
499 return 0;
587} \ No newline at end of file 500} \ No newline at end of file