Remove static replay limit
[neverball] / ball / st_set.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
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.
8  *
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.
13  */
14
15 #include "gui.h"
16 #include "set.h"
17 #include "progress.h"
18 #include "audio.h"
19 #include "config.h"
20 #include "util.h"
21 #include "st_shared.h"
22
23 #include "game_common.h"
24
25 #include "st_set.h"
26 #include "st_title.h"
27 #include "st_start.h"
28
29 /*---------------------------------------------------------------------------*/
30
31 #define SET_STEP    5
32
33 static int total = 0;
34 static int first = 0;
35
36 static int shot_id;
37 static int desc_id;
38
39 static int do_init = 1;
40
41 static int set_action(int i)
42 {
43     audio_play(AUD_MENU, 1.0f);
44
45     switch (i)
46     {
47     case GUI_BACK:
48         set_free();
49         return goto_state(&st_title);
50         break;
51
52     case GUI_PREV:
53
54         first -= SET_STEP;
55
56         do_init = 0;
57         return goto_state(&st_set);
58
59         break;
60
61     case GUI_NEXT:
62
63         first += SET_STEP;
64
65         do_init = 0;
66         return goto_state(&st_set);
67
68         break;
69
70     case GUI_NULL:
71         return 1;
72         break;
73
74     default:
75         if (set_exists(i))
76         {
77             set_goto(i);
78             return goto_state(&st_start);
79         }
80     }
81
82     return 1;
83 }
84
85 static void gui_set(int id, int i)
86 {
87     if (set_exists(i))
88         gui_state(id, set_name(i), GUI_SML, i, 0);
89     else
90         gui_label(id, "", GUI_SML, GUI_ALL, 0, 0);
91 }
92
93 static int set_enter(void)
94 {
95     int w = config_get_d(CONFIG_WIDTH);
96     int h = config_get_d(CONFIG_HEIGHT);
97
98     int id, jd, kd;
99
100     int i;
101
102     if (do_init)
103     {
104         total = set_init();
105         audio_music_fade_to(0.5f, "bgm/inter.ogg");
106         audio_play(AUD_START, 1.f);
107     }
108     else do_init = 1;
109
110     if ((id = gui_vstack(0)))
111     {
112         if ((jd = gui_hstack(id)))
113         {
114             gui_label(jd, _("Level Set"), GUI_SML, GUI_ALL, gui_yel, gui_red);
115             gui_filler(jd);
116             gui_navig(jd, first > 0, first + SET_STEP < total);
117         }
118
119         if ((jd = gui_harray(id)))
120         {
121             shot_id = gui_image(jd, set_shot(first), 7 * w / 16, 7 * h / 16);
122
123             if ((kd = gui_varray(jd)))
124             {
125                 for (i = first; i < first + SET_STEP; i++)
126                     gui_set(kd, i);
127             }
128         }
129
130         gui_space(id);
131         desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL,
132                             gui_yel, gui_wht);
133
134         gui_layout(id, 0, 0);
135     }
136     return id;
137 }
138
139 static void set_over(int i)
140 {
141     gui_set_image(shot_id, set_shot(i));
142     gui_set_multi(desc_id, set_desc(i));
143 }
144
145 static void set_point(int id, int x, int y, int dx, int dy)
146 {
147     int jd = shared_point_basic(id, x, y);
148     int i  = gui_token(jd);
149     if (jd && set_exists(i))
150         set_over(i);
151 }
152
153 static void set_stick(int id, int a, int v)
154 {
155     int jd = shared_stick_basic(id, a, v);
156     int i  = gui_token(jd);
157     if (jd && set_exists(i))
158         set_over(i);
159 }
160
161 static int set_buttn(int b, int d)
162 {
163     if (d)
164     {
165         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
166             return set_action(gui_token(gui_click()));
167         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
168             return set_action(GUI_BACK);
169     }
170     return 1;
171 }
172
173 /*---------------------------------------------------------------------------*/
174
175 struct state st_set = {
176     set_enter,
177     shared_leave,
178     shared_paint,
179     shared_timer,
180     set_point,
181     set_stick,
182     shared_angle,
183     shared_click,
184     NULL,
185     set_buttn,
186     1, 0
187 };