Import from neverball-1.4.0.tar.gz
[neverball-archive.git] / ball / st_set.c
blobef6a54dd7806438293ed01a2aad50b2b3a26f5ef
1 /*
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.
15 #include "gui.h"
16 #include "set.h"
17 #include "game.h"
18 #include "audio.h"
19 #include "config.h"
21 #include "st_title.h"
22 #include "st_start.h"
24 /*---------------------------------------------------------------------------*/
26 #define SET_BACK -1
28 static int shot_id;
29 static int desc_id;
31 static int set_action(int i)
33 audio_play(AUD_MENU, 1.0f);
35 if (i == SET_BACK)
36 return goto_state(&st_title);
38 if (0 <= i && i <= 5)
40 set_goto(i);
41 return goto_state(&st_start);
43 return 1;
46 static void gui_set(int id, int i)
48 if (set_exists(i))
49 gui_state(id, set_name(i), GUI_SML, i, 0);
50 else
51 gui_label(id, "", GUI_SML, GUI_ALL, 0, 0);
54 static int set_enter(void)
56 int w = config_get_d(CONFIG_WIDTH);
57 int h = config_get_d(CONFIG_HEIGHT);
59 int id, jd, kd;
61 set_init();
63 audio_music_fade_to(0.5f, "bgm/inter.ogg");
64 audio_play(AUD_START, 1.f);
66 if ((id = gui_vstack(0)))
68 if ((jd = gui_harray(id)))
70 gui_label(jd, "Level Set", GUI_SML, GUI_ALL, gui_yel, gui_red);
71 gui_filler(jd);
72 gui_filler(jd);
73 gui_start(jd, "Back", GUI_SML, SET_BACK, 0);
76 if ((jd = gui_harray(id)))
78 shot_id = gui_image(jd, "shot-rlk/easy.jpg", 7 * w / 16, 7 * h / 16);
80 if ((kd = gui_varray(jd)))
82 gui_set(kd, 0);
83 gui_set(kd, 1);
84 gui_set(kd, 2);
85 gui_set(kd, 3);
86 gui_set(kd, 4);
90 gui_space(id);
91 desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht);
93 gui_layout(id, 0, 0);
95 return id;
98 static void set_leave(int id)
100 gui_delete(id);
103 static void set_paint(int id, float st)
105 game_draw(0, st);
106 config_pop_matrix();
107 gui_paint(id);
110 static void set_timer(int id, float dt)
112 gui_timer(id, dt);
113 audio_timer(dt);
116 static void set_point(int id, int x, int y, int dx, int dy)
118 int jd;
120 if ((jd = gui_point(id, x, y)))
122 int i = gui_token(jd);
124 gui_set_image(shot_id, set_shot(i));
125 gui_set_multi(desc_id, set_desc(i));
126 gui_pulse(jd, 1.2f);
130 static void set_stick(int id, int a, int v)
132 int jd;
134 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
135 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
137 if ((jd = gui_stick(id, x, y)))
139 int i = gui_token(jd);
141 gui_set_image(shot_id, set_shot(i));
142 gui_set_multi(desc_id, set_desc(i));
143 gui_pulse(jd, 1.2f);
147 static int set_click(int b, int d)
149 return (b < 0 && d == 1) ? set_action(gui_token(gui_click())) : 1;
152 static int set_keybd(int c, int d)
154 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
157 static int set_buttn(int b, int d)
159 if (d)
161 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
162 return set_action(gui_token(gui_click()));
163 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
164 return goto_state(&st_title);
165 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
166 return goto_state(&st_title);
168 return 1;
171 /*---------------------------------------------------------------------------*/
173 struct state st_set = {
174 set_enter,
175 set_leave,
176 set_paint,
177 set_timer,
178 set_point,
179 set_stick,
180 set_click,
181 set_keybd,
182 set_buttn,
183 1, 0