From 293b1eb5ebf9f486ce9a89398319f646f2a29c3b Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sat, 10 Aug 2024 22:32:13 -0500 Subject: Implement subslots & pass to spin() --- src/screen.c | 79 +++++++++++++++++++++++++++++++++++++++++++----------------- src/screen.h | 13 +++++++++- 2 files changed, 69 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/screen.c b/src/screen.c index 8393e07..00381d2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -60,6 +60,10 @@ static const char *phrases[] = { ":3", "You think Jack Rhysider will interview me now?", "Check out \"Darknet Diaries\"", + "Chill and losing it since 2016", + "POOL'S CLOSED", + "I've been diagnosed with snaids", + "My balls itch", // by @danielsprofile on telegram "Daniel Spears loves femboys", @@ -87,30 +91,35 @@ static const char *menu_choices[] = { }; static struct funcholder userfuncs[] = { - {.callback = spin, .type = FH_SPIN, .params = {.spinp = {.bannerwin = NULL, .phrasenum = 0}}}, - {.callback = buy, .type = FH_BUY, .params = {.buyp = {.numspins = 3, .price = 1}}}, - {.callback = quit, .type = FH_QUIT, .params = {.quitp = {.REPLACEME = NULL}}} + {.callback = spin, .type = FH_SPIN}, + {.callback = buy, .type = FH_BUY}, + {.callback = quit, .type = FH_QUIT} }; -void intercleanup(int signum) { - // Only want to handle interrupts - if(signum != SIGINT) - abort(); +void catcher(int signum, siginfo_t *info, void *ucontext) { + // This is retarded lol, but makes gcc happy + info->si_code = info->si_code; + ucontext = ucontext; - endwin(); - error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt"); - exit(0); + switch(signum) { + case SIGINT: + endwin(); + error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt"); + exit(0); + + case SIGWINCH: + endwin(); + error(1, 0, "[VX-GAMBLEGROUND] User changed window size and I haven't implemented code to handle it yet"); + abort(); // Makes gcc happy (angry about implicit fallthrough) + + default: + abort(); + } return; } -static const struct sigaction handlers[] = { - { // intercleanup - .sa_flags = 0, - .sa_mask = SIGINT, - .sa_handler = intercleanup - } -}; +static struct sigaction handler = {.sa_flags = SA_SIGINFO, .sa_mask = SIGINT | SIGWINCH, .sa_sigaction = catcher}; // Initialize sodium, curses, and set the proper locale. Exits on error, returns 0 otherwise static int doinit(void) { @@ -123,8 +132,8 @@ static int doinit(void) { if(initscr() == NULL) // Initialize curses error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); - if(sigaction(SIGINT, &handlers[0], NULL) < 0) - error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal handler"); + if(sigaction(SIGINT, &handler, NULL) < 0 || sigaction(SIGWINCH, &handler, NULL) < 0) + error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal catcher"); return 0; } @@ -239,6 +248,7 @@ int main() { MENU *menu; // The actual menu object int c; // Integer for storing keys from user input + struct slotholder slots; getmaxyx(stdscr, row, col); if(row < 0 || col < 0) { @@ -268,22 +278,41 @@ int main() { init_custom_menu_format(menuholder, menu, (int []){1, col}, O_ONEVALUE | O_IGNORECASE, O_SHOWDESC | O_NONCYCLIC); - WINDOW *slots = newwin(row - 2, col, 1, 0); - if(slots == NULL) { + slots.slotwin = newwin(row - 2, col, 1, 0); + if(slots.slotwin == NULL) { endwin(); error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window"); } + /* const char *sampletext = "Lmao longer sample"; mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); wnoutrefresh(slots); + */ + + /* + int sy, sx; + getmaxyx(slots, sy, sx); + WINDOW *TEST = derwin(slots, sy, sx/3, 0, 0); + wbkgd(TEST, COLOR_PAIR(CCP_TESTING)); + waddstr(TEST, "lol"); + wnoutrefresh(TEST); + //*/ + + getmaxyx(slots.slotwin, slots.sloty, slots.slotx); + for(size_t i = 0; i < STATIC_ARRSIZE(slots.subslots); i++) { + slots.subslots[i].subslot = derwin(slots.slotwin, slots.sloty, slots.slotx/3, 0, slots.slotx/3 * i); + wbkgd(slots.subslots[i].subslot, COLOR_PAIR((slots.subslots[i].color = CCP_RED + i))); + mvwaddstr(slots.subslots[i].subslot, slots.sloty/2, slots.slotx/3/2 - 2, "lol"); + wnoutrefresh(slots.subslots[i].subslot); + } doupdate(); userfuncs[0].params.spinp.bannerwin = banner; - userfuncs[0].params.spinp.phrasenum = randomnum; userfuncs[0].params.spinp.menuholder = menuholder; userfuncs[0].params.spinp.menu = menu; + userfuncs[0].params.spinp.slots = &slots; // Get user input and deal with the menu while((c = wgetch(menuholder)) != KEY_F(4)) { @@ -361,6 +390,12 @@ int spin(void *spinp) { set_menu_back(p->menu, COLOR_PAIR(color)); wnoutrefresh(p->menuholder); + for(size_t subs = 0; subs < STATIC_ARRSIZE(p->slots->subslots); subs++) { + p->slots->subslots[subs].color = rangemod(p->slots->subslots[subs].color, 1, CCP_RED, CCP_WHITE); + wbkgd(p->slots->subslots[subs].subslot, COLOR_PAIR(p->slots->subslots[subs].color)); + wnoutrefresh(p->slots->subslots[subs].subslot); + } + doupdate(); nanosleep(&sleeper, NULL); } diff --git a/src/screen.h b/src/screen.h index 5afbe6e..93297ee 100644 --- a/src/screen.h +++ b/src/screen.h @@ -66,6 +66,17 @@ enum customcolor_pairs { #define COLORWIDTH (CCP_WHITE - CCP_RED) #define NUMCOLORPAIRS (COLORWIDTH + 1) +struct slotholder { + WINDOW *slotwin; + int slotx; + int sloty; + + struct subslot { + WINDOW *subslot; + enum customcolor_pairs color; + + } subslots[3]; +}; struct funcholder { int (*callback)(void*); @@ -82,7 +93,7 @@ struct funcholder { union param { struct spinp { WINDOW *bannerwin; - int phrasenum; + struct slotholder *slots; WINDOW *menuholder; MENU *menu; -- cgit v1.2.3