Those sets haven't been merged.
[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 /* Bread crumbs. */
37
38 static int new_name;
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 DONE_NAME:
50         new_name = 1;
51         return goto_name(&st_done, &st_done, 0);
52     }
53     return 1;
54 }
55
56 static int done_enter(void)
57 {
58     const char *s1 = _("New Set Record");
59     const char *s2 = _("Set Complete");
60
61     int id, jd;
62
63     int high = (curr_lg()->times_rank < 3) || (curr_lg()->score_rank < 3);
64
65     if (new_name)
66     {
67         level_update_player_name();
68         new_name = 0;
69     }
70
71     if ((id = gui_vstack(0)))
72     {
73         int gid;
74
75         if (high)
76             gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
77         else
78             gid = gui_label(id, s2, GUI_MED, GUI_ALL, gui_blu, gui_grn);
79
80         gui_space(id);
81
82         if ((jd = gui_harray(id)))
83         {
84             gui_most_coins(jd, 1);
85             gui_best_times(jd, 1);
86         }
87
88         gui_space(id);
89
90         if ((jd = gui_harray(id)))
91         {
92             /* FIXME, I'm ugly. */
93
94             if (high)
95                gui_state(jd, _("Change Player Name"), GUI_SML, DONE_NAME, 0);
96
97             gui_start(jd, _("OK"), GUI_SML, DONE_OK, 0);
98         }
99
100         gui_layout(id, 0, 0);
101         gui_pulse(gid, 1.2f);
102     }
103
104     set_best_times(&curr_set()->time_score, curr_lg()->times_rank, 0);
105     set_most_coins(&curr_set()->coin_score, curr_lg()->score_rank);
106
107     return id;
108 }
109
110 static int done_buttn(int b, int d)
111 {
112     if (d)
113     {
114         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
115             return done_action(gui_token(gui_click()));
116         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
117             return done_action(DONE_OK);
118     }
119     return 1;
120 }
121
122 /*---------------------------------------------------------------------------*/
123
124 struct state st_done = {
125     done_enter,
126     shared_leave,
127     shared_paint,
128     shared_timer,
129     shared_point,
130     shared_stick,
131     shared_angle,
132     shared_click,
133     NULL,
134     done_buttn,
135     1, 0
136 };