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 | } |
36 | } else if (ch == 'k' || ch == 'K') { |
37 | if (state->page_selection != 0) { |
38 | state->page_selection--; |
39 | } else { |
40 | beep(); |
41 | } |
42 | } else if (ch == 10 || ch == ' ' || ch == KEY_ENTER) { // enter key pressed, process |
43 | switch (state->page_selection) { |
44 | case 2: { // HELP |
45 | state->page = Help; |
46 | return draw_help_screen(state, 0); |
47 | } |
48 | case 3: { // QUIT |
49 | return 1; |
50 | } |
51 | } |
52 | } |
53 |
|
54 | // setup |
55 | attron(A_BOLD); |
56 |
|
57 | // draw splash screen |
58 | int vdisplace = 0; |
59 | if (COLS > 130 && LINES > 18) { |
60 | for (int i = 0; i < 7; i++) { |
61 | const char *this_splash = title_screen_splash[i]; |
62 | mvprintw(centery() - 6 + i, centerx(this_splash), this_splash); |
63 | vdisplace = 2; |
64 | } |
65 | } else if (COLS > 85 && LINES > 14) { |
66 | for (int i = 0; i < 5; i++) { |
67 | const char *this_splash = title_screen_splash_small[i]; |
68 | mvprintw(centery() - 5 + i, centerx(this_splash), this_splash); |
69 | vdisplace = 1; |
70 | } |
71 | } else { |
72 | mvprintw(centery() - 3, centerx(title_screen_splash_text), title_screen_splash_text); |
73 | vdisplace = -1; |
74 | } |
75 |
|
76 | // draw button inputs |
77 | for (int i = 0; i < 4; i++) { |
78 | if (state->page_selection == i) attron(A_STANDOUT); |
79 | mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), title_screen_buttons[i]); |
80 | if (state->page_selection == i) attroff(A_STANDOUT); |
81 | } |
82 |
|
83 | // write copyright line @ bottom |
84 | attroff(A_BOLD); |
85 | mvprintw(LINES - 1, centerx(title_screen_copyright), title_screen_copyright); |
86 |
|
87 | return 0; |
88 | } |
89 |
|