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 | state->last_page = Title; |
58 | return draw_help_screen(state, 0); |
59 | } |
60 | case 3: { |
61 | state->page = About; |
62 | return draw_about_screen(state, 0); |
63 | } |
64 | case 4: { // QUIT |
65 | return 1; |
66 | } |
67 | } |
68 | break; |
69 | } |
70 | case 27: |
71 | return 1; |
72 | case 0: |
73 | break; |
74 | default: |
75 | beep(); |
76 | } |
77 |
|
78 | int vdisplace = 0; |
79 |
|
80 | // draw splash screen |
81 | attron(A_BOLD | COLOR_PAIR(5)); |
82 | if (COLS > 130 && LINES > 18) { |
83 | for (int i = 0; i < 7; i++) { |
84 | const char *this_splash = title_screen_splash[i]; |
85 | mvprintw(centery() - 6 + i, centerx(this_splash), "%s", this_splash); |
86 | vdisplace = 2; |
87 | } |
88 | } else if (COLS > 85 && LINES > 14) { |
89 | for (int i = 0; i < 5; i++) { |
90 | const char *this_splash = title_screen_splash_small[i]; |
91 | mvprintw(centery() - 5 + i, centerx(this_splash), "%s", this_splash); |
92 | vdisplace = 1; |
93 | } |
94 | } else { |
95 | mvprintw(centery() - 3, centerx(title_screen_splash_text), "%s", title_screen_splash_text); |
96 | vdisplace = -1; |
97 | } |
98 |
|
99 | // draw button inputs |
100 | for (int i = 0; i < 5; i++) { |
101 | if (state->page_selection == i) attron(A_STANDOUT); |
102 | mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), "%s", title_screen_buttons[i]); |
103 | if (state->page_selection == i) attroff(A_STANDOUT); |
104 | } |
105 | attroff(A_BOLD); |
106 |
|
107 | // write copyright line @ bottom |
108 | mvprintw(LINES - 1, centerx(copyright_line), "%s", copyright_line); |
109 |
|
110 | attroff(COLOR_PAIR(5)); |
111 |
|
112 | return 0; |
113 | } |
114 |
|