diff options
Diffstat (limited to 'src/screen.c')
| -rw-r--r-- | src/screen.c | 140 |
1 files changed, 103 insertions, 37 deletions
diff --git a/src/screen.c b/src/screen.c index 362a1a7..77b1a3b 100644 --- a/src/screen.c +++ b/src/screen.c | |||
| @@ -32,6 +32,7 @@ SLOTS HERE | |||
| 32 | 32 | ||
| 33 | #include <stdio.h> | 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
| 35 | #include <string.h> | ||
| 35 | 36 | ||
| 36 | static const char *phrases[] = { | 37 | static const char *phrases[] = { |
| 37 | // By @syxhe on telegram | 38 | // By @syxhe on telegram |
| @@ -95,7 +96,8 @@ static int init_rgb_color(int colornum, int red, int green, int blue) { | |||
| 95 | return init_color(colornum, nred, ngreen, nblue); | 96 | return init_color(colornum, nred, ngreen, nblue); |
| 96 | } | 97 | } |
| 97 | 98 | ||
| 98 | int main() { | 99 | // Initialize sodium, curses, and set the proper locale. Exits on error, returns 0 otherwise |
| 100 | static int doinit(void) { | ||
| 99 | if(sodium_init() < 0) | 101 | if(sodium_init() < 0) |
| 100 | error(1, errno, "[VX-GAMBLEGROUND] Could not initialize sodium"); | 102 | error(1, errno, "[VX-GAMBLEGROUND] Could not initialize sodium"); |
| 101 | 103 | ||
| @@ -105,6 +107,11 @@ int main() { | |||
| 105 | if(initscr() == NULL) // Initialize curses | 107 | if(initscr() == NULL) // Initialize curses |
| 106 | error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); | 108 | error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); |
| 107 | 109 | ||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | // Initialize colors & define a few custom colors & color pairs. Exits on error, returns 0 otherwise | ||
| 114 | static int docolors(void) { | ||
| 108 | if(has_colors() && can_change_color()) { // Init colors if available & create color pairings | 115 | if(has_colors() && can_change_color()) { // Init colors if available & create color pairings |
| 109 | start_color(); | 116 | start_color(); |
| 110 | 117 | ||
| @@ -126,77 +133,110 @@ int main() { | |||
| 126 | 133 | ||
| 127 | init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); | 134 | init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); |
| 128 | init_pair(CCP_TESTING, CC_RED, CC_WHITE); | 135 | init_pair(CCP_TESTING, CC_RED, CC_WHITE); |
| 136 | } else { | ||
| 137 | endwin(); | ||
| 138 | error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal"); | ||
| 129 | } | 139 | } |
| 130 | 140 | ||
| 141 | return 0; | ||
| 142 | } | ||
| 143 | |||
| 144 | int main() { | ||
| 145 | doinit(); | ||
| 146 | docolors(); | ||
| 147 | |||
| 131 | cbreak(); // Disables character buffering | 148 | cbreak(); // Disables character buffering |
| 132 | noecho(); // Disable echoing characters | 149 | noecho(); // Disable echoing characters |
| 133 | keypad(stdscr, TRUE); // Enable keypad on the standard screen | 150 | curs_set(0); // Stop the cursor from blinking |
| 134 | curs_set(0); | 151 | |
| 152 | |||
| 153 | // Variable definitions | ||
| 154 | |||
| 155 | struct funcholder funcholder[STATIC_ARRSIZE(menu_choices)]; // Stores the function pointers used for the menu | ||
| 156 | ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items | ||
| 157 | int holder1 = -1, holder2 = -1; // Holders for the max yx of the menu subwindow | ||
| 158 | struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver | ||
| 159 | int row = -1, col = -1; // The rows and columns of the main screen | ||
| 160 | WINDOW *phrase = NULL; // The window for displaying the banner | ||
| 161 | WINDOW *menuholder; // The window for displaying the menu | ||
| 162 | int randomnum; // A random number for getting the banner phrase | ||
| 163 | MENU *menu; // The actual menu object | ||
| 164 | int c; // Integer for storing keys from user input | ||
| 165 | |||
| 135 | 166 | ||
| 136 | int row = -1, col = -1; | ||
| 137 | getmaxyx(stdscr, row, col); | 167 | getmaxyx(stdscr, row, col); |
| 138 | if(row < 0 || col < 0) | 168 | if(row < 0 || col < 0) { |
| 169 | endwin(); | ||
| 139 | error(1, 0, "[VX-GAMBLEGROUND] Couldn't get max terminal size for some reason"); | 170 | error(1, 0, "[VX-GAMBLEGROUND] Couldn't get max terminal size for some reason"); |
| 171 | } | ||
| 140 | 172 | ||
| 141 | int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); | 173 | randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); |
| 142 | if(randomnum < 0) | 174 | if(randomnum < 0) { |
| 175 | endwin(); | ||
| 143 | error(1, errno, "[VX-GAMBLEGROUND] Call to randombytes_uniform failed, can't get random phrase"); | 176 | error(1, errno, "[VX-GAMBLEGROUND] Call to randombytes_uniform failed, can't get random phrase"); |
| 177 | } | ||
| 144 | 178 | ||
| 145 | // Making this a subwindow of stdscr might be a good idea (maybe) | 179 | // Create the banner window |
| 146 | WINDOW *phrase = NULL; | ||
| 147 | phrase = newwin(1, col, 0, 0); | 180 | phrase = newwin(1, col, 0, 0); |
| 148 | if(phrase == NULL) | 181 | if(phrase == NULL) { |
| 182 | endwin(); | ||
| 149 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); | 183 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); |
| 150 | 184 | } | |
| 151 | if(has_colors()) | 185 | wbkgd(phrase, COLOR_PAIR(1)); |
| 152 | wbkgd(phrase, COLOR_PAIR(1)); | ||
| 153 | |||
| 154 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); | 186 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); |
| 155 | waddstr(phrase, phrases[randomnum]); | 187 | waddstr(phrase, phrases[randomnum]); |
| 156 | wrefresh(phrase); | 188 | wrefresh(phrase); |
| 157 | 189 | ||
| 158 | /* Dummy test for fun. Shows how windows can't be overlapping or things get weird (and that row offsets matter) | ||
| 159 | WINDOW *test = newwin(row - 1, col, 1, 0); | ||
| 160 | int rand1, rand2; | ||
| 161 | |||
| 162 | for(int c = wgetch(test);; c = wgetch(test)) { | ||
| 163 | rand1 = randombytes_uniform(row - 1); | ||
| 164 | rand2 = randombytes_uniform(col); | ||
| 165 | |||
| 166 | mvwaddch(test, rand1, rand2, c | (A_BOLD * (randombytes_random() % 2 > 0))); | ||
| 167 | } | ||
| 168 | //*/ | ||
| 169 | |||
| 170 | //* Menu example (fuck menus got damn) | ||
| 171 | ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; | ||
| 172 | MENU *menu; | ||
| 173 | WINDOW *menuholder; | ||
| 174 | 190 | ||
| 175 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) | 191 | // Set up menu items |
| 192 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) { | ||
| 193 | funcholder[i].callback = USERFUNCS[i]; | ||
| 176 | items[i] = new_item(menu_choices[i], NULL); | 194 | items[i] = new_item(menu_choices[i], NULL); |
| 195 | set_item_userptr(items[i], (void*)(&funcholder[i])); | ||
| 196 | } | ||
| 177 | items[STATIC_ARRSIZE(menu_choices)] = NULL; | 197 | items[STATIC_ARRSIZE(menu_choices)] = NULL; |
| 178 | 198 | ||
| 179 | menu = new_menu(items); | 199 | menu = new_menu(items); |
| 180 | if(menu == NULL) | 200 | if(menu == NULL) { |
| 201 | endwin(); | ||
| 181 | error(1, errno, "Could not create menu"); | 202 | error(1, errno, "Could not create menu"); |
| 203 | } | ||
| 182 | 204 | ||
| 205 | // Set menu options & format | ||
| 183 | set_menu_format(menu, 1, col); | 206 | set_menu_format(menu, 1, col); |
| 184 | menu_opts_on(menu, O_ONEVALUE | O_IGNORECASE); | 207 | menu_opts_on(menu, O_ONEVALUE | O_IGNORECASE); |
| 185 | menu_opts_off(menu, O_SHOWDESC); | 208 | menu_opts_off(menu, O_SHOWDESC | O_NONCYCLIC); |
| 186 | 209 | ||
| 187 | menuholder = newwin(1, col, row - 1, 0); | 210 | menuholder = newwin(1, col, row - 1, 0); |
| 188 | keypad(menuholder, TRUE); | 211 | keypad(menuholder, TRUE); |
| 189 | 212 | ||
| 190 | int holder1 = -1, holder2 = -1; | 213 | |
| 191 | getmaxyx(menuholder, holder1, holder2); | 214 | getmaxyx(menuholder, holder1, holder2); |
| 215 | if(holder1 < 0 || holder2 < 0) { | ||
| 216 | endwin(); | ||
| 217 | error(1, errno, "[VX-GAMBLEGROUND] Could not get bounds for menu subwindow"); | ||
| 218 | } | ||
| 192 | set_menu_win(menu, menuholder); | 219 | set_menu_win(menu, menuholder); |
| 193 | set_menu_sub(menu, derwin(menuholder, holder1, holder2, 0, 0)); | 220 | set_menu_sub(menu, derwin(menuholder, holder1, holder2, 0, 0)); |
| 194 | 221 | ||
| 195 | set_menu_mark(menu, NULL); | 222 | set_menu_mark(menu, NULL); |
| 196 | post_menu(menu); | 223 | post_menu(menu); |
| 224 | wbkgd(menuholder, COLOR_PAIR(CCP_BANNER)); | ||
| 225 | set_menu_back(menu, COLOR_PAIR(CCP_BANNER)); | ||
| 197 | wrefresh(menuholder); | 226 | wrefresh(menuholder); |
| 198 | 227 | ||
| 199 | int c; | 228 | |
| 229 | WINDOW *slots = newwin(row - 2, col, 1, 0); | ||
| 230 | if(slots == NULL) { | ||
| 231 | endwin(); | ||
| 232 | error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window"); | ||
| 233 | } | ||
| 234 | |||
| 235 | const char *sampletext = "Lmao longer sample"; | ||
| 236 | mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); | ||
| 237 | wrefresh(slots); | ||
| 238 | |||
| 239 | // Get user input and deal with the menu | ||
| 200 | while((c = wgetch(menuholder)) != KEY_F(4)) { | 240 | while((c = wgetch(menuholder)) != KEY_F(4)) { |
| 201 | switch(c) { | 241 | switch(c) { |
| 202 | case KEY_DOWN: | 242 | case KEY_DOWN: |
| @@ -215,12 +255,17 @@ int main() { | |||
| 215 | menu_driver(menu, REQ_RIGHT_ITEM); | 255 | menu_driver(menu, REQ_RIGHT_ITEM); |
| 216 | break; | 256 | break; |
| 217 | 257 | ||
| 218 | case KEY_ENTER: | 258 | case KEY_ENTER: case FUCKED_UP_ENTER: // Enter |
| 259 | //wclear(menuholder); | ||
| 260 | //mvwaddstr(menuholder, 0, 0, "This shit brokey lmao"); | ||
| 261 | |||
| 262 | p = (struct funcholder *)item_userptr(current_item(menu)); | ||
| 263 | p->callback(); | ||
| 264 | |||
| 219 | break; | 265 | break; |
| 220 | } | 266 | } |
| 221 | } | 267 | } |
| 222 | 268 | ||
| 223 | |||
| 224 | // Clean up the menu | 269 | // Clean up the menu |
| 225 | unpost_menu(menu); | 270 | unpost_menu(menu); |
| 226 | free_menu(menu); | 271 | free_menu(menu); |
| @@ -230,4 +275,25 @@ int main() { | |||
| 230 | 275 | ||
| 231 | endwin(); // Clean up curses | 276 | endwin(); // Clean up curses |
| 232 | return 0; | 277 | return 0; |
| 278 | } | ||
| 279 | |||
| 280 | // Spin the wheel | ||
| 281 | int spin(void) { | ||
| 282 | endwin(); | ||
| 283 | error(1, 0, "spin"); | ||
| 284 | return 0; | ||
| 285 | } | ||
| 286 | |||
| 287 | // Increase number of spins | ||
| 288 | int buy(void) { | ||
| 289 | endwin(); | ||
| 290 | error(1, 0, "buy"); | ||
| 291 | return 0; | ||
| 292 | } | ||
| 293 | |||
| 294 | // Quit out | ||
| 295 | int quit(void) { | ||
| 296 | endwin(); | ||
| 297 | error(1, 0, "quit"); | ||
| 298 | return 1; | ||
| 233 | } \ No newline at end of file | 299 | } \ No newline at end of file |
