running: tweaks
[neverball] / ball / st_time_out.c
1 /*
2  * Copyright (C) 2007 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 "game.h"
16 #include "util.h"
17 #include "progress.h"
18 #include "demo.h"
19 #include "audio.h"
20 #include "gui.h"
21 #include "config.h"
22
23 #include "st_over.h"
24 #include "st_start.h"
25 #include "st_save.h"
26 #include "st_time_out.h"
27 #include "st_level.h"
28 #include "st_shared.h"
29 #include "st_play.h"
30
31 /*---------------------------------------------------------------------------*/
32
33 #define TIME_OUT_NEXT 1
34 #define TIME_OUT_SAME 2
35 #define TIME_OUT_SAVE 3
36 #define TIME_OUT_BACK 4
37 #define TIME_OUT_OVER 5
38
39 static int time_out_action(int i)
40 {
41     audio_play(AUD_MENU, 1.0f);
42
43     switch (i)
44     {
45     case TIME_OUT_BACK:
46         /* Fall through. */
47
48     case TIME_OUT_OVER:
49         progress_stop();
50         return goto_state(&st_over);
51
52     case TIME_OUT_SAVE:
53         progress_stop();
54         return goto_save(&st_time_out, &st_time_out);
55
56     case TIME_OUT_NEXT:
57         if (progress_next())
58             return goto_state(&st_level);
59         break;
60
61     case TIME_OUT_SAME:
62         if (progress_same())
63             return goto_state(&st_level);
64         break;
65     }
66
67     return 1;
68 }
69
70 static int time_out_enter(void)
71 {
72     int id, jd, kd;
73
74     if ((id = gui_vstack(0)))
75     {
76         kd = gui_label(id, _("Time's Up!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
77
78         gui_space(id);
79
80         if ((jd = gui_harray(id)))
81         {
82             if (progress_dead())
83                 gui_start(jd, _("Exit"), GUI_SML, TIME_OUT_OVER, 0);
84
85             if (progress_next_avail())
86                 gui_start(jd, _("Next Level"), GUI_SML, TIME_OUT_NEXT, 0);
87
88             if (progress_same_avail())
89                 gui_start(jd, _("Retry Level"), GUI_SML, TIME_OUT_SAME, 0);
90
91             if (demo_saved())
92                 gui_state(jd, _("Save Replay"), GUI_SML, TIME_OUT_SAVE, 0);
93         }
94         gui_space(id);
95
96         gui_pulse(kd, 1.2f);
97         gui_layout(id, 0, 0);
98     }
99
100     audio_music_fade_out(2.0f);
101     /* audio_play(AUD_TIME, 1.0f); */
102
103     config_clr_grab();
104
105     return id;
106 }
107
108 static int time_out_keybd(int c, int d)
109 {
110     if (d)
111     {
112         if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
113         {
114             if (progress_same())
115                 goto_state(&st_play_ready);
116         }
117     }
118     return 1;
119 }
120
121 static int time_out_buttn(int b, int d)
122 {
123     if (d)
124     {
125         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
126             return time_out_action(gui_token(gui_click()));
127         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
128             return time_out_action(TIME_OUT_BACK);
129     }
130     return 1;
131 }
132
133 /*---------------------------------------------------------------------------*/
134
135 struct state st_time_out = {
136     time_out_enter,
137     shared_leave,
138     shared_paint,
139     shared_timer,
140     shared_point,
141     shared_stick,
142     shared_angle,
143     shared_click,
144     time_out_keybd,
145     time_out_buttn,
146     1, 0
147 };
148