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