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