1 | /* ncurses-minesweeper Copyright (c) 2021 Joshua 'joshuas3' Stockin |
2 | * <https://joshstock.in> |
3 | * <https://git.joshstock.in/ncurses-minesweeper> |
4 | * |
5 | * This software is licensed and distributed under the terms of the MIT License. |
6 | * See the MIT License in the LICENSE file of this project's root folder. |
7 | * |
8 | * This comment block and its contents, including this disclaimer, MUST be |
9 | * preserved in all copies or distributions of this software's source. |
10 | */ |
11 |
|
12 | #include <ncurses.h> |
13 |
|
14 | #include "../state.h" |
15 | #include "../strings.h" |
16 | #include "pages.h" |
17 | #include "text.h" |
18 |
|
19 | int draw_title_screen(game_state *state, int ch) { |
20 | switch (ch) { |
21 | case -1: |
22 | return 0; |
23 | case KEY_DOWN: { |
24 | if (state->page_selection != 4) { |
25 | state->page_selection++; |
26 | } else |
27 | beep(); |
28 | break; |
29 | } |
30 | case KEY_UP: { |
31 | if (state->page_selection != 0) { |
32 | state->page_selection--; |
33 | } else |
34 | beep(); |
35 | break; |
36 | } |
37 | case KEY_RESIZE: |
38 | clear(); |
39 | break; |
40 | case 10: |
41 | case ' ': |
42 | case KEY_ENTER: { |
43 | clear(); |
44 | switch (state->page_selection) { |
45 | case 0: { |
46 | state->page = Game; |
47 | state->page_selection = 0; |
48 | return draw_game(state, 0); |
49 | } |
50 | case 1: { |
51 | state->page = Options; |
52 | state->page_selection = 0; |
53 | return draw_options_screen(state, 0); |
54 | } |
55 | case 2: { |
56 | state->page = Help; |
57 | return draw_help_screen(state, 0); |
58 | } |
59 | case 3: { |
60 | state->page = About; |
61 | return draw_about_screen(state, 0); |
62 | } |
63 | case 4: { // QUIT |
64 | return 1; |
65 | } |
66 | } |
67 | break; |
68 | } |
69 | case 27: |
70 | return 1; |
71 | case 0: |
72 | break; |
73 | default: |
74 | beep(); |
75 | } |
76 |
|
77 | int vdisplace = 0; |
78 |
|
79 | // draw splash screen |
80 | attron(A_BOLD | COLOR_PAIR(5)); |
81 | if (COLS > 130 && LINES > 18) { |
82 | for (int i = 0; i < 7; i++) { |
83 | const char *this_splash = title_screen_splash[i]; |
84 | mvprintw(centery() - 6 + i, centerx(this_splash), this_splash); |
85 | vdisplace = 2; |
86 | } |
87 | } else if (COLS > 85 && LINES > 14) { |
88 | for (int i = 0; i < 5; i++) { |
89 | const char *this_splash = title_screen_splash_small[i]; |
90 | mvprintw(centery() - 5 + i, centerx(this_splash), this_splash); |
91 | vdisplace = 1; |
92 | } |
93 | } else { |
94 | mvprintw(centery() - 3, centerx(title_screen_splash_text), title_screen_splash_text); |
95 | vdisplace = -1; |
96 | } |
97 |
|
98 | // draw button inputs |
99 | for (int i = 0; i < 5; i++) { |
100 | if (state->page_selection == i) attron(A_STANDOUT); |
101 | mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), title_screen_buttons[i]); |
102 | if (state->page_selection == i) attroff(A_STANDOUT); |
103 | } |
104 | attroff(A_BOLD); |
105 |
|
106 | // write copyright line @ bottom |
107 | mvprintw(LINES - 1, centerx(copyright_line), copyright_line); |
108 |
|
109 | attroff(COLOR_PAIR(5)); |
110 |
|
111 | return 0; |
112 | } |
113 |
|