Un-internationalised the title strings and updated POs once again.
[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 "game.h"
18 #include "audio.h"
19 #include "config.h"
20 #include "util.h"
21 #include "st_shared.h"
22
23 #include "st_set.h"
24 #include "st_title.h"
25 #include "st_start.h"
26
27 /*---------------------------------------------------------------------------*/
28
29 #define SET_BACK -1
30 #define SET_PREV -2
31 #define SET_NEXT -3
32 #define SET_NULL -4
33
34 #define SET_GROUP 5 /* number of sets in one screen */
35
36 static int shot_id;
37 static int desc_id;
38
39 static int set_action(int i)
40 {
41     audio_play(AUD_MENU, 1.0f);
42
43     switch(i)
44     {
45     case GUI_BACK:
46         return goto_state(&st_title);
47
48     case GUI_PREV:
49         config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)-1)*SET_GROUP);
50         return goto_state(&st_set);
51     
52     case GUI_NEXT:
53         config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)+1)*SET_GROUP);
54         return goto_state(&st_set);
55
56     case GUI_NULL:
57         return 1;
58     
59     default:
60         if (set_exists(i))
61         {
62             config_set_d(CONFIG_LAST_SET, i);
63             set_goto(i);
64             return goto_state(&st_start);
65         }
66     }
67     return 1;
68 }
69
70 static int set_enter(void)
71 {
72     int w = config_get_d(CONFIG_WIDTH);
73     int h = config_get_d(CONFIG_HEIGHT);
74     int last_set = config_get_d(CONFIG_LAST_SET);
75     int b = last_set / SET_GROUP;
76     int i;
77
78     int id, jd, kd;
79
80     set_init();
81
82     audio_music_fade_to(0.5f, "bgm/inter.ogg");
83     audio_play(AUD_START, 1.f);
84
85     if ((id = gui_vstack(0)))
86     {
87         if ((jd = gui_hstack(id)))
88         {
89             gui_label(jd, _("Level Set"), GUI_SML, GUI_ALL, gui_yel, gui_red);
90             gui_filler(jd);
91             gui_back_prev_next(jd, b>0, set_exists((b+1)*SET_GROUP));
92         }
93
94         if ((jd = gui_harray(id)))
95         {
96             shot_id = gui_image(jd, set_shot(last_set), 7 * w / 16, 7 * h / 16);
97
98             if ((kd = gui_varray(jd)))
99             {
100                 /* Display levels */
101                 for(i=b*SET_GROUP; i<(b+1)*SET_GROUP && set_exists(i); i++)
102                 {
103                     if(last_set == i)
104                         gui_start(kd, _(set_name(i)), GUI_SML, i, 0);
105                     else
106                         gui_state(kd, _(set_name(i)), GUI_SML, i, 0);
107                 }
108                 
109                 /* Display empty slots */
110                 for(; i<(b+1)*SET_GROUP; i++)
111                     gui_filler(kd);
112             }          
113         }
114
115         gui_space(id);
116         desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht);
117
118         gui_layout(id, 0, 0);
119     }
120     return id;
121 }
122
123 static void set_over(int i)
124 {
125     gui_set_image(shot_id, set_shot(i));
126     gui_set_multi(desc_id, _(set_desc(i)));
127 }
128
129 static void set_point(int id, int x, int y, int dx, int dy)
130 {
131     int jd = shared_point_basic(id, x, y);
132     int i  = gui_token(jd);
133     if (jd && set_exists(i))
134         set_over(i);
135 }
136
137 static void set_stick(int id, int a, int v)
138 {
139     int jd = shared_stick_basic(id, a, v);
140     int i  = gui_token(jd);
141     if (jd && set_exists(i))
142         set_over(i);
143 }
144
145 static int set_buttn(int b, int d)
146 {
147     if (d)
148     {
149         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
150             return set_action(gui_token(gui_click()));
151         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
152             return set_action(GUI_BACK);
153     }
154     return 1;
155 }
156
157 /*---------------------------------------------------------------------------*/
158
159 struct state st_set = {
160     set_enter,
161     shared_leave,
162     shared_paint,
163     shared_timer,
164     set_point,
165     set_stick,
166     shared_click,
167     NULL,
168     set_buttn,
169     1, 0
170 };