| 1 | #include <ncurses.h> |
| 2 |
|
| 3 | #include "../state.h" |
| 4 | #include "pages.h" |
| 5 | #include "text.h" |
| 6 |
|
| 7 | // clang-format off |
| 8 | const char *title_screen_splash[7] = { |
| 9 | ":::: :::: ::::::::::: :::: ::: :::::::::: :::::::: ::: ::: :::::::::: :::::::::: ::::::::: :::::::::: ::::::::: ", |
| 10 | "+:+:+: :+:+:+ :+: :+:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:", |
| 11 | "+:+ +:+:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+", |
| 12 | "+#+ +:+ +#+ +#+ +#+ +:+ +#+ +#++:++# +#++:++#++ +#+ +:+ +#+ +#++:++# +#++:++# +#++:++#+ +#++:++# +#++:++#: ", |
| 13 | "+#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+", |
| 14 | "#+# #+# #+# #+# #+#+# #+# #+# #+# #+#+# #+#+# #+# #+# #+# #+# #+# #+#", |
| 15 | "### ### ########### ### #### ########## ######## ### ### ########## ########## ### ########## ### ###"}; |
| 16 | const char *title_screen_splash_small[5] = { |
| 17 | " __ ___ ____ _ __ ______ _____ _ __ ______ ______ ____ ______ ____ ", |
| 18 | " / |/ // _// | / // ____// ___/| | / // ____// ____// __ \\ / ____// __ \\", |
| 19 | " / /|_/ / / / / |/ // __/ \\__ \\ | | /| / // __/ / __/ / /_/ // __/ / /_/ /", |
| 20 | " / / / /_/ / / /| // /___ ___/ / | |/ |/ // /___ / /___ / ____// /___ / _, _/ ", |
| 21 | "/_/ /_//___//_/ |_//_____/ /____/ |__/|__//_____//_____//_/ /_____//_/ |_| "}; |
| 22 | // clang-format on |
| 23 |
|
| 24 | const char *title_screen_splash_text = "MINESWEEPER"; |
| 25 | const char *title_screen_buttons[4] = {"PLAY", "OPTIONS", "HELP", "EXIT"}; |
| 26 | const char *title_screen_copyright = "Copyright (c) Joshua 'joshuas3' Stockin 2020"; |
| 27 |
|
| 28 | int draw_title_screen(game_state *state, int ch) { |
| 29 | // input handling |
| 30 | if (ch == 'j' || ch == 'J') { |
| 31 | if (state->page_selection != 3) { |
| 32 | state->page_selection++; |
| 33 | } else |
| 34 | beep(); |
| 35 | } else if (ch == 'k' || ch == 'K') { |
| 36 | if (state->page_selection != 0) { |
| 37 | state->page_selection--; |
| 38 | } else |
| 39 | beep(); |
| 40 | } else if (ch == 10 || ch == ' ' || ch == KEY_ENTER) { // enter key pressed, process |
| 41 | switch (state->page_selection) { |
| 42 | case 0: { |
| 43 | state->page = Game; |
| 44 | state->page_selection = 0; |
| 45 | state->board->current_cell = 75; |
| 46 | return draw_game(state, 0); |
| 47 | } |
| 48 | case 1: { |
| 49 | state->page = Options; |
| 50 | state->page_selection = 0; |
| 51 | return draw_options_screen(state, 0); |
| 52 | } |
| 53 | case 2: { // HELP |
| 54 | state->page = Help; |
| 55 | return draw_help_screen(state, 0); |
| 56 | } |
| 57 | case 3: { // QUIT |
| 58 | return 1; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 |
|
| 63 | int vdisplace = 0; |
| 64 |
|
| 65 | // draw splash screen |
| 66 | attron(A_BOLD | COLOR_PAIR(4)); |
| 67 | if (COLS > 130 && LINES > 18) { |
| 68 | for (int i = 0; i < 7; i++) { |
| 69 | const char *this_splash = title_screen_splash[i]; |
| 70 | mvprintw(centery() - 6 + i, centerx(this_splash), this_splash); |
| 71 | vdisplace = 2; |
| 72 | } |
| 73 | } else if (COLS > 85 && LINES > 14) { |
| 74 | for (int i = 0; i < 5; i++) { |
| 75 | const char *this_splash = title_screen_splash_small[i]; |
| 76 | mvprintw(centery() - 5 + i, centerx(this_splash), this_splash); |
| 77 | vdisplace = 1; |
| 78 | } |
| 79 | } else { |
| 80 | mvprintw(centery() - 3, centerx(title_screen_splash_text), title_screen_splash_text); |
| 81 | vdisplace = -1; |
| 82 | } |
| 83 |
|
| 84 | // draw button inputs |
| 85 | for (int i = 0; i < 4; i++) { |
| 86 | if (state->page_selection == i) attron(A_STANDOUT); |
| 87 | mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), title_screen_buttons[i]); |
| 88 | if (state->page_selection == i) attroff(A_STANDOUT); |
| 89 | } |
| 90 | attroff(A_BOLD); |
| 91 |
|
| 92 | // write copyright line @ bottom |
| 93 | mvprintw(LINES - 1, centerx(title_screen_copyright), title_screen_copyright); |
| 94 |
|
| 95 | attroff(COLOR_PAIR(4)); |
| 96 |
|
| 97 | return 0; |
| 98 | } |
| 99 |
|