diff options
Diffstat (limited to 'src/screen.c')
| -rw-r--r-- | src/screen.c | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/src/screen.c b/src/screen.c index 9cdac02..5ca2dc2 100644 --- a/src/screen.c +++ b/src/screen.c | |||
| @@ -31,6 +31,7 @@ SLOTS HERE | |||
| 31 | #include <menu.h> | 31 | #include <menu.h> |
| 32 | 32 | ||
| 33 | #include <stdio.h> | 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> | ||
| 34 | 35 | ||
| 35 | static const char *phrases[] = { | 36 | static const char *phrases[] = { |
| 36 | // By @syxhe on telegram | 37 | // By @syxhe on telegram |
| @@ -78,8 +79,7 @@ static const char *phrases[] = { | |||
| 78 | static const char *menu_choices[] = { | 79 | static const char *menu_choices[] = { |
| 79 | "Spin", | 80 | "Spin", |
| 80 | "Buy spins", | 81 | "Buy spins", |
| 81 | "Quit", | 82 | "Quit" |
| 82 | NULL | ||
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { | 85 | static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { |
| @@ -115,16 +115,17 @@ int main() { | |||
| 115 | // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so | 115 | // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so |
| 116 | // use a normal terminal for accurate colors */ | 116 | // use a normal terminal for accurate colors */ |
| 117 | 117 | ||
| 118 | init_rgb_color(CC_RED, 255, 0, 0); | 118 | init_rgb_color(CC_RED, 255, 0, 0); |
| 119 | init_rgb_color(CC_ORANGE, 255, 128, 0); | 119 | init_rgb_color(CC_ORANGE, 255, 128, 0); |
| 120 | init_rgb_color(CC_YELLOW, 255, 255, 0); | 120 | init_rgb_color(CC_YELLOW, 255, 255, 0); |
| 121 | init_rgb_color(CC_GREEN, 0, 255, 0); | 121 | init_rgb_color(CC_GREEN, 0, 255, 0); |
| 122 | init_rgb_color(CC_BLUE, 0, 0, 255); | 122 | init_rgb_color(CC_BLUE, 0, 0, 255); |
| 123 | init_rgb_color(CC_PURPLE, 255, 0, 255); | 123 | init_rgb_color(CC_PURPLE, 155, 0, 255); |
| 124 | init_rgb_color(CC_WHITE, 255, 255, 255); | 124 | init_rgb_color(CC_MAGENTA, 255, 0, 255); |
| 125 | 125 | init_rgb_color(CC_WHITE, 255, 255, 255); | |
| 126 | init_pair(1, CC_WHITE, CURSES_BLUE); | 126 | |
| 127 | 127 | init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); | |
| 128 | init_pair(CCP_TESTING, CC_RED, CC_WHITE); | ||
| 128 | } | 129 | } |
| 129 | 130 | ||
| 130 | cbreak(); // Disables character buffering | 131 | cbreak(); // Disables character buffering |
| @@ -134,7 +135,8 @@ int main() { | |||
| 134 | 135 | ||
| 135 | int row = -1, col = -1; | 136 | int row = -1, col = -1; |
| 136 | getmaxyx(stdscr, row, col); | 137 | getmaxyx(stdscr, row, col); |
| 137 | 138 | if(row < 0 || col < 0) | |
| 139 | error(1, 0, "[VX-GAMBLEGROUND] Couldn't get max terminal size for some reason"); | ||
| 138 | 140 | ||
| 139 | int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); | 141 | int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); |
| 140 | if(randomnum < 0) | 142 | if(randomnum < 0) |
| @@ -146,37 +148,43 @@ int main() { | |||
| 146 | if(phrase == NULL) | 148 | if(phrase == NULL) |
| 147 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); | 149 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); |
| 148 | 150 | ||
| 149 | wbkgd(phrase, COLOR_PAIR(1)); | 151 | if(has_colors()) |
| 152 | wbkgd(phrase, COLOR_PAIR(1)); | ||
| 153 | |||
| 150 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); | 154 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); |
| 151 | waddstr(phrase, phrases[randomnum]); | 155 | waddstr(phrase, phrases[randomnum]); |
| 152 | wrefresh(phrase); | 156 | wrefresh(phrase); |
| 153 | 157 | ||
| 154 | //* Dummy test for fun. Shows how windows can't be overlapping or things get weird | 158 | /* Dummy test for fun. Shows how windows can't be overlapping or things get weird (and that row offsets matter) |
| 155 | WINDOW *test = newwin(row - 1, col, 1, 0); | 159 | WINDOW *test = newwin(row - 1, col, 1, 0); |
| 160 | int rand1, rand2; | ||
| 161 | |||
| 156 | for(int c = wgetch(test);; c = wgetch(test)) { | 162 | for(int c = wgetch(test);; c = wgetch(test)) { |
| 157 | mvwaddch(test, c % row, c % col, c | (A_BOLD * (randombytes_random() % 2 > 0))); | 163 | rand1 = randombytes_uniform(row - 1); |
| 164 | rand2 = randombytes_uniform(col); | ||
| 165 | |||
| 166 | mvwaddch(test, rand1, rand2, c | (A_BOLD * (randombytes_random() % 2 > 0))); | ||
| 158 | } | 167 | } |
| 159 | //*/ | 168 | //*/ |
| 160 | 169 | ||
| 161 | /* Menu example | 170 | //* Menu example (fuck menus got damn) |
| 162 | ITEM **items; | 171 | ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; |
| 163 | MENU *menu; | 172 | MENU *menu; |
| 164 | 173 | ||
| 165 | items = calloc(STATIC_ARRSIZE(menu_choices) + 1, sizeof(ITEM*)); | ||
| 166 | if(items == NULL) | ||
| 167 | error(-1, errno, "Could not allocate space for menu items"); | ||
| 168 | |||
| 169 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) | 174 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) |
| 170 | items[i] = new_item(menu_choices[i], menu_choices[i]); | 175 | items[i] = new_item(menu_choices[i], menu_choices[i]); |
| 171 | items[STATIC_ARRSIZE(menu_choices)] = NULL; | 176 | items[STATIC_ARRSIZE(menu_choices)] = NULL; |
| 172 | 177 | ||
| 173 | menu = new_menu(items); | 178 | menu = new_menu(items); |
| 174 | mvprintw(LINES - 2, 0, "F1 to Exit"); | 179 | if(menu == NULL) |
| 180 | error(1, errno, "Could not create menu"); | ||
| 181 | |||
| 182 | // set_menu_format(menu, 3, col); | ||
| 175 | post_menu(menu); | 183 | post_menu(menu); |
| 176 | refresh(); | 184 | refresh(); |
| 177 | 185 | ||
| 178 | int c; | 186 | int c; |
| 179 | while((c = getch()) != KEY_F(1)) { | 187 | while((c = getch()) != KEY_F(4)) { |
| 180 | switch(c) { | 188 | switch(c) { |
| 181 | case KEY_DOWN: | 189 | case KEY_DOWN: |
| 182 | menu_driver(menu, REQ_DOWN_ITEM); | 190 | menu_driver(menu, REQ_DOWN_ITEM); |
| @@ -186,6 +194,14 @@ int main() { | |||
| 186 | menu_driver(menu, REQ_UP_ITEM); | 194 | menu_driver(menu, REQ_UP_ITEM); |
| 187 | break; | 195 | break; |
| 188 | 196 | ||
| 197 | case KEY_LEFT: | ||
| 198 | menu_driver(menu, REQ_LEFT_ITEM); | ||
| 199 | break; | ||
| 200 | |||
| 201 | case KEY_RIGHT: | ||
| 202 | menu_driver(menu, REQ_RIGHT_ITEM); | ||
| 203 | break; | ||
| 204 | |||
| 189 | case KEY_ENTER: | 205 | case KEY_ENTER: |
| 190 | break; | 206 | break; |
| 191 | } | 207 | } |
