2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
25 /*---------------------------------------------------------------------------*/
31 #define SET_GROUP 4 /* number of sets in one screen */
36 static int last_set; /* TODO: Use config instead of a global variable */
38 static int set_action(int i)
40 audio_play(AUD_MENU, 1.0f);
43 return goto_state(&st_title);
44 else if (i == SET_PREV)
46 last_set = ((last_set/SET_GROUP)-1)*SET_GROUP;
47 return goto_state(&st_set);
49 else if (i == SET_NEXT)
51 last_set = ((last_set/SET_GROUP)+1)*SET_GROUP;
52 return goto_state(&st_set);
54 else if (set_exists(i))
58 return goto_state(&st_start);
63 static int set_enter(void)
65 int w = config_get_d(CONFIG_WIDTH);
66 int h = config_get_d(CONFIG_HEIGHT);
67 int b = last_set / SET_GROUP;
74 audio_music_fade_to(0.5f, "bgm/inter.ogg");
75 audio_play(AUD_START, 1.f);
77 if ((id = gui_vstack(0)))
79 if ((jd = gui_hstack(id)))
81 gui_label(jd, "Level Set", GUI_SML, GUI_ALL, gui_yel, gui_red);
83 gui_state(jd, "Back", GUI_SML, SET_BACK, 0);
86 if ((jd = gui_harray(id)))
88 shot_id = gui_image(jd, set_shot(last_set), 7 * w / 16, 7 * h / 16);
90 if ((kd = gui_varray(jd)))
93 for(i=b*SET_GROUP; i<(b+1)*SET_GROUP && set_exists(i); i++)
96 gui_start(kd, set_name(i), GUI_SML, i, 0);
98 gui_state(kd, set_name(i), GUI_SML, i, 0);
101 /* Display Prev/Next buttons */
104 gui_state(ld, "Next", GUI_SML, SET_NEXT, 0);
106 gui_label(ld, "Next", GUI_SML, GUI_ALL, gui_gry, gui_gry);
108 gui_state(ld, "Prev", GUI_SML, SET_PREV, 0);
110 gui_label(ld, "Prev", GUI_SML, GUI_ALL, gui_gry, gui_gry);
112 /* Display empty slots */
113 for(; i<(b+1)*SET_GROUP; i++)
119 desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht);
121 gui_layout(id, 0, 0);
126 static void set_leave(int id)
131 static void set_paint(int id, float st)
138 static void set_timer(int id, float dt)
144 static void set_point(int id, int x, int y, int dx, int dy)
148 if ((jd = gui_point(id, x, y)))
150 int i = gui_token(jd);
153 gui_set_image(shot_id, set_shot(i));
154 gui_set_multi(desc_id, set_desc(i));
160 static void set_stick(int id, int a, int v)
164 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
165 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
167 if ((jd = gui_stick(id, x, y)))
169 int i = gui_token(jd);
173 gui_set_image(shot_id, set_shot(i));
174 gui_set_multi(desc_id, set_desc(i));
180 static int set_click(int b, int d)
182 return (b < 0 && d == 1) ? set_action(gui_token(gui_click())) : 1;
185 static int set_keybd(int c, int d)
187 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
190 static int set_buttn(int b, int d)
194 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
195 return set_action(gui_token(gui_click()));
196 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
197 return goto_state(&st_title);
198 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
199 return goto_state(&st_title);
204 /*---------------------------------------------------------------------------*/
206 struct state st_set = {