Rev 5225 | Rev 5291 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5225 | alpine | 1 | #include "rsgamemenu.h" |
2 | |||
3 | #include "rsgame.h" |
||
4 | |||
5 | #include "rskos.h" |
||
6 | |||
5243 | alpine | 7 | #include "strings.h" |
8 | |||
5225 | alpine | 9 | PRSFUNC0 menu_actions[] = { |
10 | /* a */ &menu_action_start, |
||
11 | /* b */ &menu_action_exit, |
||
12 | /* c */ &menu_action_change_window_scale |
||
13 | }; |
||
14 | |||
15 | char window_scale_str[] = "c< 2X >"; |
||
16 | |||
5243 | alpine | 17 | /* |
18 | First char: |
||
19 | - letter a...z means action (a = 0th, b = 1st, c = 2nd, see menu_actions[] above) |
||
20 | - number 0...9 means goto menu #0, #1, #2... see menu_titles[] below |
||
21 | - space ' ' means no action, menu item is unselectable |
||
22 | - empty string "" is now allowed and can cause segfault |
||
23 | String from second char is label of menu item |
||
24 | |||
25 | */ |
||
26 | |||
27 | |||
5225 | alpine | 28 | char* menu_main_titles[] = { |
5243 | alpine | 29 | "a"L_START, |
30 | "1"L_SETTINGS, |
||
31 | "2"L_ABOUT, |
||
32 | "b"L_QUIT, |
||
5225 | alpine | 33 | |
34 | }; |
||
35 | |||
36 | char* menu_settings_titles[] = { |
||
5243 | alpine | 37 | " "L_WINDOW_SCALE, |
5225 | alpine | 38 | window_scale_str, |
39 | " ", |
||
5243 | alpine | 40 | "0"L_DONE, |
5225 | alpine | 41 | |
42 | }; |
||
43 | |||
44 | char* menu_about_titles[] = { |
||
5243 | alpine | 45 | " "L_DEVELOPED_BY, |
46 | " "L_ROMAN_SHUVALOV, |
||
5225 | alpine | 47 | " ", |
5243 | alpine | 48 | "0"L_DONE, |
5225 | alpine | 49 | |
50 | }; |
||
51 | |||
52 | char **menu_titles[] = { |
||
53 | /* 0 */ menu_main_titles, |
||
54 | /* 1 */ menu_settings_titles, |
||
55 | /* 2 */ menu_about_titles, |
||
56 | |||
57 | }; |
||
58 | |||
59 | |||
60 | void menu_cursor_down() { |
||
61 | int new_index = game.menu_item_index+1; |
||
62 | while ( (menu_titles[game.menu_index][new_index]) ) { |
||
63 | if ((menu_titles[game.menu_index][new_index][0] != ' ')) { |
||
64 | game.menu_item_index = new_index; |
||
65 | game_ding(1); |
||
66 | return; |
||
67 | }; |
||
68 | new_index++; |
||
69 | }; |
||
70 | }; |
||
71 | |||
72 | void menu_cursor_up() { |
||
73 | int new_index = game.menu_item_index-1; |
||
74 | while ( new_index+1 ) { |
||
75 | if ((menu_titles[game.menu_index][new_index][0] != ' ')) { |
||
76 | game.menu_item_index = new_index; |
||
77 | game_ding(1); |
||
78 | return; |
||
79 | }; |
||
80 | new_index--; |
||
81 | }; |
||
82 | }; |
||
83 | |||
84 | void menu_open(int i) { |
||
85 | |||
86 | game.menu_index = i; |
||
87 | |||
88 | game.menu_item_index = -1; |
||
89 | // (menu_cursor_down without sound) |
||
90 | int new_index = game.menu_item_index+1; |
||
91 | while ( (menu_titles[game.menu_index][new_index]) ) { |
||
92 | if ((menu_titles[game.menu_index][new_index][0] != ' ')) { |
||
93 | game.menu_item_index = new_index; |
||
94 | return; |
||
95 | }; |
||
96 | new_index++; |
||
97 | }; |
||
98 | |||
99 | }; |
||
100 | |||
101 | void menu_cursor_click() { |
||
102 | |||
103 | char c = menu_titles[game.menu_index][game.menu_item_index][0]; |
||
104 | |||
105 | game_ding(0); |
||
106 | |||
107 | if (c > '9') { |
||
108 | // action: call function |
||
109 | menu_actions[c - 'a'](); |
||
110 | } |
||
111 | else { |
||
112 | // action: navigate to menu |
||
113 | menu_open(c - '0'); |
||
114 | }; |
||
115 | |||
116 | // DEBUG10f("click: %c \n", c); |
||
117 | |||
118 | }; |
||
119 | |||
120 | void menu_action_start() { |
||
121 | game.status = STATUS_PLAYING; |
||
122 | |||
123 | game.tx = GAME_WIDTH/2 - 50; |
||
124 | game.ty = GAME_HEIGHT/2 - 10; |
||
125 | |||
126 | }; |
||
127 | |||
128 | void menu_action_exit() { |
||
5243 | alpine | 129 | #ifdef RS_KOS |
5225 | alpine | 130 | GameTerm(); |
131 | #endif |
||
132 | rskos_exit(); |
||
133 | }; |
||
134 | |||
135 | void menu_action_change_window_scale() { |
||
136 | game_change_window_scale(1); |
||
137 | };> |