2 * Copyright (C) 2003 Robert Kooima
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.
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.
22 #include "st_shared.h"
25 #include "game_common.h"
26 #include "game_server.h"
27 #include "game_client.h"
28 #include "game_proxy.h"
37 /*---------------------------------------------------------------------------*/
39 static int init_title_level(void)
41 if (game_client_init("map-medium/title.sol"))
45 cmd.type = CMD_GOAL_OPEN;
48 game_client_step(NULL);
55 /*---------------------------------------------------------------------------*/
57 static float real_time = 0.0f;
60 static int play_id = 0;
68 static int title_action(int i)
70 static const char keyphrase[] = "CHEAT";
71 static char queue[sizeof (keyphrase)] = "";
73 size_t queue_len = strlen(queue);
77 audio_play(AUD_MENU, 1.0f);
82 config_get_s(CONFIG_PLAYER, player, MAXNAM);
84 if (strlen(player) == 0)
85 return goto_name(&st_set, &st_title, 0);
87 return goto_state(&st_set);
91 case TITLE_HELP: return goto_state(&st_help); break;
92 case TITLE_DEMO: return goto_state(&st_demo); break;
93 case TITLE_CONF: return goto_state(&st_conf); break;
94 case TITLE_EXIT: return 0; break;
98 /* Let the queue fill up. */
100 if (queue_len < sizeof (queue) - 1)
102 queue[queue_len] = (char) i;
103 queue[queue_len + 1] = '\0';
106 /* Advance the queue before adding the new element. */
112 for (k = 1; k < queue_len; k++)
113 queue[k - 1] = queue[k];
115 queue[queue_len - 1] = (char) i;
118 if (strcmp(queue, keyphrase) == 0)
121 gui_set_label(play_id, sgettext("menu^Cheat"));
122 gui_pulse(play_id, 1.2f);
124 else if (config_cheat())
127 gui_set_label(play_id, sgettext("menu^Play"));
128 gui_pulse(play_id, 1.2f);
136 static int title_enter(void)
140 /* Build the title GUI. */
142 if ((id = gui_vstack(0)))
144 gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
148 if ((jd = gui_harray(id)))
152 if ((kd = gui_varray(jd)))
155 play_id = gui_start(kd, sgettext("menu^Cheat"),
156 GUI_MED, TITLE_PLAY, 1);
158 play_id = gui_start(kd, sgettext("menu^Play"),
159 GUI_MED, TITLE_PLAY, 1);
161 gui_state(kd, sgettext("menu^Replay"), GUI_MED, TITLE_DEMO, 0);
162 gui_state(kd, sgettext("menu^Help"), GUI_MED, TITLE_HELP, 0);
163 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
164 gui_state(kd, sgettext("menu^Exit"), GUI_MED, TITLE_EXIT, 0);
169 gui_layout(id, 0, 0);
172 /* Start the title screen music. */
174 audio_music_fade_to(0.5f, "bgm/title.ogg");
176 /* Initialize the title level for display. */
183 SDL_EnableUNICODE(1);
188 static void title_leave(int id)
190 SDL_EnableUNICODE(0);
195 static void title_timer(int id, float dt)
197 static const char *demo = NULL;
203 case 0: /* Mode 0: Pan across title level. */
205 if (real_time <= 20.0f)
207 game_set_fly(fcosf(V_PI * real_time / 20.0f),
209 game_client_step(NULL);
219 case 1: /* Mode 1: Fade out. Load demo level. */
221 if (real_time > 1.0f)
223 if ((demo = demo_pick()))
225 demo_replay_init(demo, NULL, NULL, NULL, NULL, NULL);
226 game_set_fly(0.0f, game_client_file());
227 game_client_step(NULL);
240 case 2: /* Mode 2: Run demo. */
242 if (!demo_replay_step(dt))
251 case 3: /* Mode 3: Fade out. Load title level. */
253 if (real_time > 1.0f)
267 static int title_keybd(int c, int d)
269 if (d && (c & 0xFF80) == 0 && c > ' ')
270 return title_action(c);
274 static int title_buttn(int b, int d)
278 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
279 return title_action(gui_token(gui_click()));
280 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
286 /*---------------------------------------------------------------------------*/
288 struct state st_title = {