1 | #include <ncurses.h> |
2 |
|
3 | #include "text.h" |
4 | #include "title.h" |
5 |
|
6 | #include "../state.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' || ch == KEY_DOWN) { |
32 | if (state->page_selection != 3) { |
33 | state->page_selection++; |
34 | } else { |
35 | beep(); |
36 | } |
37 | } else if (ch == 'k' || ch == 'K' || ch == KEY_UP) { |
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 | if (state->page_selection == 3) { // QUIT |
45 | return 1; |
46 | } |
47 | } |
48 |
|
49 | // setup |
50 | attron(A_BOLD); |
51 |
|
52 | // draw splash screen |
53 | int vdisplace = 0; |
54 | if (COLS > 130 && LINES > 18) { |
55 | for (int i = 0; i < 7; i++) { |
56 | const char *this_splash = title_screen_splash[i]; |
57 | mvprintw(centery() - 6 + i, centerx(this_splash), this_splash); |
58 | vdisplace = 2; |
59 | } |
60 | } else if (COLS > 85 && LINES > 14) { |
61 | for (int i = 0; i < 5; i++) { |
62 | const char *this_splash = title_screen_splash_small[i]; |
63 | mvprintw(centery() - 5 + i, centerx(this_splash), this_splash); |
64 | vdisplace = 1; |
65 | } |
66 | } else { |
67 | mvprintw(centery() - 3, centerx(title_screen_splash_text), title_screen_splash_text); |
68 | vdisplace = -1; |
69 | } |
70 |
|
71 | // draw button inputs |
72 | for (int i = 0; i < 4; i++) { |
73 | if (state->page_selection == i) attron(A_STANDOUT); |
74 | mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), title_screen_buttons[i]); |
75 | if (state->page_selection == i) attroff(A_STANDOUT); |
76 | } |
77 |
|
78 | // write copyright line @ bottom |
79 | attroff(A_BOLD); |
80 | mvprintw(LINES - 1, centerx(title_screen_copyright), title_screen_copyright); |
81 |
|
82 | return 0; |
83 | } |
84 |
|