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