Subversion Repositories Kolibri OS

Rev

Rev 5225 | Rev 5291 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5225 Rev 5243
1
#include "rsgamemenu.h"
1
#include "rsgamemenu.h"
2
 
2
 
3
#include "rsgame.h"
3
#include "rsgame.h"
4
 
4
 
5
#include "rskos.h"
5
#include "rskos.h"
-
 
6
 
-
 
7
#include "strings.h"
6
 
8
 
7
PRSFUNC0 menu_actions[] = {
9
PRSFUNC0 menu_actions[] = {
8
    /* a */ &menu_action_start,     
10
    /* a */ &menu_action_start,     
9
    /* b */ &menu_action_exit,
11
    /* b */ &menu_action_exit,
10
    /* c */ &menu_action_change_window_scale
12
    /* c */ &menu_action_change_window_scale
11
};
13
};
12
 
14
 
13
char window_scale_str[] = "c< 2X >";
15
char window_scale_str[] = "c< 2X >";
-
 
16
 
-
 
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
 
14
 
27
 
15
char* menu_main_titles[] = {
28
char* menu_main_titles[] = {
16
    "a5TART",
29
    "a"L_START,
17
    "15ETTING5",
30
    "1"L_SETTINGS,
18
    "2ABOUT",
31
    "2"L_ABOUT,
19
    "bQUIT",
32
    "b"L_QUIT,
20
    0
33
    0
21
};
34
};
22
 
35
 
23
char* menu_settings_titles[] = {
36
char* menu_settings_titles[] = {
24
    " WINDOW SCALE:",
37
    " "L_WINDOW_SCALE,
25
    window_scale_str,
38
    window_scale_str,
26
    " ",
39
    " ",
27
    "0DONE",
40
    "0"L_DONE,
28
    0
41
    0
29
};
42
};
30
 
43
 
31
char* menu_about_titles[] = {
44
char* menu_about_titles[] = {
32
    " DEVELOPED BY",
45
    " "L_DEVELOPED_BY,
33
    " ROMAN SHUVALOV",
46
    " "L_ROMAN_SHUVALOV,
34
    " ",
47
    " ",
35
    "0DONE",
48
    "0"L_DONE,
36
    0
49
    0
37
};
50
};
38
 
51
 
39
char **menu_titles[] = {
52
char **menu_titles[] = {
40
    /* 0 */ menu_main_titles,
53
    /* 0 */ menu_main_titles,
41
    /* 1 */ menu_settings_titles,
54
    /* 1 */ menu_settings_titles,
42
    /* 2 */ menu_about_titles,
55
    /* 2 */ menu_about_titles,
43
    0
56
    0
44
};
57
};
45
 
58
 
46
 
59
 
47
void menu_cursor_down() {
60
void menu_cursor_down() {
48
    int new_index = game.menu_item_index+1;
61
    int new_index = game.menu_item_index+1;
49
    while ( (menu_titles[game.menu_index][new_index]) ) {
62
    while ( (menu_titles[game.menu_index][new_index]) ) {
50
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
63
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
51
            game.menu_item_index = new_index;
64
            game.menu_item_index = new_index;
52
            game_ding(1);
65
            game_ding(1);
53
            return;
66
            return;
54
        };
67
        };
55
        new_index++;
68
        new_index++;
56
    };
69
    };
57
};
70
};
58
 
71
 
59
void menu_cursor_up() {
72
void menu_cursor_up() {
60
    int new_index = game.menu_item_index-1;
73
    int new_index = game.menu_item_index-1;
61
    while ( new_index+1 ) {
74
    while ( new_index+1 ) {
62
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
75
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
63
            game.menu_item_index = new_index;
76
            game.menu_item_index = new_index;
64
            game_ding(1);
77
            game_ding(1);
65
            return;
78
            return;
66
        };
79
        };
67
        new_index--;
80
        new_index--;
68
    };
81
    };
69
};
82
};
70
 
83
 
71
void menu_open(int i) {
84
void menu_open(int i) {
72
    
85
    
73
    game.menu_index = i;
86
    game.menu_index = i;
74
    
87
    
75
    game.menu_item_index = -1;
88
    game.menu_item_index = -1;
76
    // (menu_cursor_down without sound)
89
    // (menu_cursor_down without sound)
77
    int new_index = game.menu_item_index+1;
90
    int new_index = game.menu_item_index+1;
78
    while ( (menu_titles[game.menu_index][new_index]) ) {
91
    while ( (menu_titles[game.menu_index][new_index]) ) {
79
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
92
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
80
            game.menu_item_index = new_index;
93
            game.menu_item_index = new_index;
81
            return;
94
            return;
82
        };
95
        };
83
        new_index++;
96
        new_index++;
84
    };
97
    };
85
    
98
    
86
};
99
};
87
 
100
 
88
void menu_cursor_click() {
101
void menu_cursor_click() {
89
    
102
    
90
    char c = menu_titles[game.menu_index][game.menu_item_index][0];
103
    char c = menu_titles[game.menu_index][game.menu_item_index][0];
91
    
104
    
92
    game_ding(0);
105
    game_ding(0);
93
    
106
    
94
    if (c > '9') {
107
    if (c > '9') {
95
        // action: call function
108
        // action: call function
96
        menu_actions[c - 'a']();
109
        menu_actions[c - 'a']();
97
    }
110
    }
98
    else {
111
    else {
99
        // action: navigate to menu
112
        // action: navigate to menu
100
        menu_open(c - '0');
113
        menu_open(c - '0');
101
    };
114
    };
102
    
115
    
103
//    DEBUG10f("click: %c \n", c);
116
//    DEBUG10f("click: %c \n", c);
104
    
117
    
105
};
118
};
106
 
119
 
107
void menu_action_start() {
120
void menu_action_start() {
108
    game.status = STATUS_PLAYING;
121
    game.status = STATUS_PLAYING;
109
    
122
    
110
    game.tx = GAME_WIDTH/2 - 50;
123
    game.tx = GAME_WIDTH/2 - 50;
111
    game.ty = GAME_HEIGHT/2 - 10;
124
    game.ty = GAME_HEIGHT/2 - 10;
112
    
125
    
113
};
126
};
114
 
127
 
115
void menu_action_exit() {
128
void menu_action_exit() {
116
    #ifndef RS_LINUX
129
    #ifdef RS_KOS
117
        GameTerm();
130
        GameTerm();
118
    #endif
131
    #endif
119
    rskos_exit();
132
    rskos_exit();
120
};
133
};
121
 
134
 
122
void menu_action_change_window_scale() {
135
void menu_action_change_window_scale() {
123
    game_change_window_scale(1);
136
    game_change_window_scale(1);
124
};
137
};