update copyright info, also add a copiright template to add at the top of sourcefiles
[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 "level.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 high;
39 static int time_i;
40 static int coin_i;
41
42 static int done_action(int i)
43 {
44     audio_play(AUD_MENU, 1.0f);
45
46     switch (i)
47     {
48     case DONE_OK:
49         return goto_state(&st_start);
50
51     case DONE_NAME:
52         return goto_name(&st_done_bis, &st_done_bis);
53     }
54     return 1;
55 }
56
57 static int done_init(int * gidp)
58 {
59     const char *s1 = _("New Challenge Record");
60     const char *s2 = _("Challenge Complete");
61
62     int id, jd;
63
64     if ((id = gui_vstack(0)))
65     {
66         int gid;
67
68         if (high)
69             gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
70         else
71             gid = gui_label(id, s2, GUI_MED, GUI_ALL, gui_blu, gui_grn);
72
73         if (gidp)
74             *gidp = gid;
75
76         gui_space(id);
77
78         if ((jd = gui_harray(id)))
79         {
80             gui_most_coins(jd, 3, 1);
81             gui_best_times(jd, 3, 1);
82         }
83
84         gui_space(id);
85         
86         if ((jd = gui_harray(id)))
87         {
88             if (high)
89                gui_state(jd, _("Change Player Name"), GUI_SML, DONE_NAME, 0);
90             gui_start(jd, _("OK"), GUI_SML, DONE_OK, 0);
91         }
92
93         gui_layout(id, 0, 0);
94     }
95
96     set_most_coins(0, coin_i);
97     set_best_times(0, time_i);
98
99     return id;
100 }
101
102 static int done_enter(void)
103 {
104     int gid, r;
105     
106     time_i = 3;
107     coin_i = 3;
108     high   = level_done(&time_i, &coin_i);
109     
110     r = done_init(&gid);
111     gui_pulse(gid, 1.2f);    
112     return r;
113 }
114
115 static int done_bis_enter(void)
116 {
117     char player[MAXNAM];
118     config_get_s(CONFIG_PLAYER, player, MAXNAM);
119     level_name(0, player, time_i, coin_i);
120     return done_init(NULL);
121 }
122
123 static int done_buttn(int b, int d)
124 {
125     if (d)
126     {
127         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
128             return done_action(gui_token(gui_click()));
129         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
130             return done_action(DONE_OK);
131     }
132     return 1;
133 }
134
135 /*---------------------------------------------------------------------------*/
136
137 struct state st_done = {
138     done_enter,
139     shared_leave,
140     shared_paint,
141     shared_timer,
142     shared_point,
143     shared_stick,
144     shared_click,
145     NULL,
146     done_buttn,
147     1, 0
148 };
149
150 struct state st_done_bis = {
151     done_bis_enter,
152     shared_leave,
153     shared_paint,
154     shared_timer,
155     shared_point,
156     shared_stick,
157     shared_click,
158     NULL,
159     done_buttn,
160     1, 0
161 };
162