add infos in Modes and Secrets tabs
[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 "levels.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 #define DONE_NAME 2
35
36 extern struct state st_done_bis;
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_start);
46
47     case DONE_NAME:
48         return goto_name(&st_done_bis, &st_done_bis);
49     }
50     return 1;
51 }
52
53 static int done_init(int *gidp)
54 {
55     const char *s1 = _("New Challenge Record");
56     const char *s2 = _("Challenge Complete");
57
58     int id, jd;
59
60     int high = (curr_lg()->times_rank < 3) || (curr_lg()->score_rank < 3);
61
62     if ((id = gui_vstack(0)))
63     {
64         int gid;
65
66         if (high)
67             gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
68         else
69             gid = gui_label(id, s2, GUI_MED, GUI_ALL, gui_blu, gui_grn);
70
71         if (gidp)
72             *gidp = gid;
73
74         gui_space(id);
75
76         if ((jd = gui_harray(id)))
77         {
78             gui_most_coins(jd, 1);
79             gui_best_times(jd, 1);
80         }
81
82         gui_space(id);
83
84         if ((jd = gui_harray(id)))
85         {
86             if (high)
87                gui_state(jd, _("Change Player Name"), GUI_SML, DONE_NAME, 0);
88             gui_start(jd, _("OK"), GUI_SML, DONE_OK, 0);
89         }
90
91         gui_layout(id, 0, 0);
92     }
93
94     set_best_times(&curr_set()->time_score, curr_lg()->times_rank, 0);
95     set_most_coins(&curr_set()->coin_score, curr_lg()->score_rank);
96
97     return id;
98 }
99
100 static int done_enter(void)
101 {
102     int gid, r;
103
104     r = done_init(&gid);
105     gui_pulse(gid, 1.2f);
106     return r;
107 }
108
109 static int done_bis_enter(void)
110 {
111     level_update_player_name();
112     return done_init(NULL);
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_click,
137     NULL,
138     done_buttn,
139     1, 0
140 };
141
142 struct state st_done_bis = {
143     done_bis_enter,
144     shared_leave,
145     shared_paint,
146     shared_timer,
147     shared_point,
148     shared_stick,
149     shared_click,
150     NULL,
151     done_buttn,
152     1, 0
153 };
154