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 set_action(int i)
38 audio_play(AUD_MENU, 1.0f);
43 return goto_state(&st_title);
46 config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)-1)*SET_GROUP);
47 return goto_state(&st_set);
50 config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)+1)*SET_GROUP);
51 return goto_state(&st_set);
56 config_set_d(CONFIG_LAST_SET, i);
58 return goto_state(&st_start);
64 static int set_enter(void)
66 int w = config_get_d(CONFIG_WIDTH);
67 int h = config_get_d(CONFIG_HEIGHT);
68 int last_set = config_get_d(CONFIG_LAST_SET);
69 int b = last_set / SET_GROUP;
76 audio_music_fade_to(0.5f, "bgm/inter.ogg");
77 audio_play(AUD_START, 1.f);
79 if ((id = gui_vstack(0)))
81 if ((jd = gui_hstack(id)))
83 gui_label(jd, _("Level Set"), GUI_SML, GUI_ALL, gui_yel, gui_red);
85 gui_state(jd, _("Back"), GUI_SML, SET_BACK, 0);
88 if ((jd = gui_harray(id)))
90 shot_id = gui_image(jd, set_shot(last_set), 7 * w / 16, 7 * h / 16);
92 if ((kd = gui_varray(jd)))
95 for(i=b*SET_GROUP; i<(b+1)*SET_GROUP && set_exists(i); i++)
98 gui_start(kd, _(set_name(i)), GUI_SML, i, 0);
100 gui_state(kd, _(set_name(i)), GUI_SML, i, 0);
103 /* Display Prev/Next buttons */
106 gui_state(ld, _("Next"), GUI_SML, SET_NEXT, 0);
108 gui_label(ld, _("Next"), GUI_SML, GUI_ALL, gui_gry, gui_gry);
110 gui_state(ld, _("Prev"), GUI_SML, SET_PREV, 0);
112 gui_label(ld, _("Prev"), GUI_SML, GUI_ALL, gui_gry, gui_gry);
114 /* Display empty slots */
115 for(; i<(b+1)*SET_GROUP; i++)
121 desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht);
123 gui_layout(id, 0, 0);
128 static void set_leave(int id)
133 static void set_paint(int id, float st)
140 static void set_timer(int id, float dt)
146 static void set_point(int id, int x, int y, int dx, int dy)
150 if ((jd = gui_point(id, x, y)))
152 int i = gui_token(jd);
156 gui_set_image(shot_id, set_shot(i));
157 gui_set_multi(desc_id, _(set_desc(i)));
163 static void set_stick(int id, int a, int v)
167 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
168 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
170 if ((jd = gui_stick(id, x, y)))
172 int i = gui_token(jd);
176 gui_set_image(shot_id, set_shot(i));
177 gui_set_multi(desc_id, _(set_desc(i)));
183 static int set_click(int b, int d)
185 return (b < 0 && d == 1) ? set_action(gui_token(gui_click())) : 1;
188 static int set_keybd(int c, int d)
190 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
193 static int set_buttn(int b, int d)
197 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
198 return set_action(gui_token(gui_click()));
199 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
200 return goto_state(&st_title);
201 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
202 return goto_state(&st_title);
207 /*---------------------------------------------------------------------------*/
209 struct state st_set = {