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