tennis.map: Texture tweak
[neverball] / ball / st_done.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 <string.h>
16
17 #include "gui.h"
18 #include "set.h"
19 #include "util.h"
20 #include "demo.h"
21 #include "progress.h"
22 #include "audio.h"
23 #include "config.h"
24
25 #include "game_common.h"
26
27 #include "st_done.h"
28 #include "st_level.h"
29 #include "st_name.h"
30 #include "st_shared.h"
31
32 /*---------------------------------------------------------------------------*/
33
34 #define DONE_OK   1
35
36 static int resume;
37
38 static int done_action(int i)
39 {
40     audio_play(AUD_MENU, 1.0f);
41
42     switch (i)
43     {
44     case DONE_OK:
45         return goto_state(&st_exit);
46
47     case GUI_NAME:
48         return goto_name(&st_done, &st_done, 0);
49
50     case GUI_SCORE_COIN:
51     case GUI_SCORE_TIME:
52     case GUI_SCORE_GOAL:
53         gui_score_set(i);
54         return goto_state(&st_done);
55     }
56     return 1;
57 }
58
59 static int done_gui(void)
60 {
61     const char *s1 = _("New Set Record");
62     const char *s2 = _("Set Complete");
63
64     int id;
65
66     int high = progress_set_high();
67
68
69     if ((id = gui_vstack(0)))
70     {
71         int gid;
72
73         if (high)
74             gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
75         else
76             gid = gui_label(id, s2, GUI_MED, GUI_ALL, gui_blu, gui_grn);
77
78         gui_space(id);
79         gui_score_board(id, GUI_SCORE_COIN | GUI_SCORE_TIME, 1, high);
80         gui_space(id);
81
82         gui_start(id, _("Select Level"), GUI_SML, DONE_OK, 0);
83
84         if (!resume)
85             gui_pulse(gid, 1.2f);
86
87         gui_layout(id, 0, 0);
88     }
89
90     set_score_board(set_score(curr_set(), SCORE_COIN), progress_score_rank(),
91                     set_score(curr_set(), SCORE_TIME), progress_times_rank(),
92                     NULL, -1);
93
94     return id;
95 }
96
97 static int done_enter(struct state *st, struct state *prev)
98 {
99     if (prev == &st_name)
100         progress_rename(1);
101
102     resume = (prev == &st_done);
103
104     return done_gui();
105 }
106
107 static int done_keybd(int c, int d)
108 {
109     if (d && config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
110         return done_action(gui_score_next(gui_score_get()));
111
112     return 1;
113 }
114
115 static int done_buttn(int b, int d)
116 {
117     if (d)
118     {
119         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
120             return done_action(gui_token(gui_click()));
121         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
122             return done_action(DONE_OK);
123     }
124     return 1;
125 }
126
127 /*---------------------------------------------------------------------------*/
128
129 struct state st_done = {
130     done_enter,
131     shared_leave,
132     shared_paint,
133     shared_timer,
134     shared_point,
135     shared_stick,
136     shared_angle,
137     shared_click,
138     done_keybd,
139     done_buttn
140 };