locales: Improved words-fr.png texture
[neverball] / ball / st_pause.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 "config.h"
17 #include "game.h"
18 #include "progress.h"
19 #include "level.h"
20 #include "audio.h"
21 #include "hud.h"
22
23 #include "st_play.h"
24 #include "st_over.h"
25 #include "st_shared.h"
26 #include "st_pause.h"
27
28 #define PAUSE_CONTINUE 1
29 #define PAUSE_RESTART  2
30 #define PAUSE_EXIT     3
31
32 /*---------------------------------------------------------------------------*/
33
34 static struct state *st_continue;
35 static int paused;
36
37 int goto_pause(void)
38 {
39     st_continue = curr_state();
40     paused = 1;
41     return goto_state(&st_pause);
42 }
43
44 int is_paused(void)
45 {
46     return paused;
47 }
48
49 void clear_pause(void)
50 {
51     paused = 0;
52 }
53
54 /*---------------------------------------------------------------------------*/
55
56 static int pause_action(int i)
57 {
58     audio_play(AUD_MENU, 1.0f);
59
60     switch(i)
61     {
62     case PAUSE_CONTINUE:
63         SDL_PauseAudio(0);
64         config_set_grab(0);
65         return goto_state(st_continue);
66
67     case PAUSE_RESTART:
68         if (progress_same())
69         {
70             clear_pause();
71             SDL_PauseAudio(0);
72             config_set_grab(1);
73             return goto_state(&st_play_ready);
74         }
75         break;
76
77     case PAUSE_EXIT:
78         progress_stat(GAME_NONE);
79         progress_stop();
80         clear_pause();
81         SDL_PauseAudio(0);
82         audio_music_stop();
83         return goto_state(&st_over);
84     }
85
86     return 1;
87 }
88
89 /*---------------------------------------------------------------------------*/
90
91 static int pause_enter(void)
92 {
93     int id, jd, title_id;
94
95     config_clr_grab();
96     SDL_PauseAudio(1);
97
98     /* Build the pause GUI. */
99
100     if ((id = gui_vstack(0)))
101     {
102         title_id = gui_label(id, _("Paused"), GUI_LRG, GUI_ALL, 0, 0);
103
104         gui_space(id);
105
106         if ((jd = gui_harray(id)))
107         {
108             gui_state(jd, _("Quit"), GUI_SML, PAUSE_EXIT, 0);
109
110             if (progress_same_avail())
111                 gui_state(jd, _("Restart"), GUI_SML, PAUSE_RESTART, 0);
112
113             gui_start(jd, _("Continue"), GUI_SML, PAUSE_CONTINUE, 1);
114         }
115
116         gui_pulse(title_id, 1.2f);
117         gui_layout(id, 0, 0);
118     }
119
120     hud_update(0);
121
122     return id;
123 }
124
125 static void pause_paint(int id, float t)
126 {
127     shared_paint(id, t);
128     hud_paint();
129 }
130
131 static void pause_timer(int id, float dt)
132 {
133     gui_timer(id, dt);
134     hud_timer (dt);
135 }
136
137 static int pause_keybd(int c, int d)
138 {
139     if (d)
140     {
141         if (config_tst_d(CONFIG_KEY_PAUSE, c))
142             return pause_action(PAUSE_CONTINUE);
143
144         if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
145             return pause_action(PAUSE_RESTART);
146     }
147     return 1;
148 }
149
150 static int pause_buttn(int b, int d)
151 {
152     if (d)
153     {
154         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
155             return pause_action(gui_token(gui_click()));
156
157         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
158             return pause_action(PAUSE_CONTINUE);
159     }
160     return 1;
161 }
162
163 /*---------------------------------------------------------------------------*/
164
165 struct state st_pause = {
166     pause_enter,
167     shared_leave,
168     pause_paint,
169     pause_timer,
170     shared_point,
171     shared_stick,
172     shared_angle,
173     shared_click,
174     pause_keybd,
175     pause_buttn,
176     1, 0
177 };