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.
26 #include "game_common.h"
27 #include "game_server.h"
28 #include "game_client.h"
29 #include "game_proxy.h"
37 #include "st_shared.h"
39 /*---------------------------------------------------------------------------*/
41 static int init_title_level(void)
43 if (game_client_init("map-medium/title.sol"))
47 cmd.type = CMD_GOAL_OPEN;
50 game_client_sync(NULL);
57 static const char *pick_demo(Array items)
59 struct dir_item *item;
60 return (item = array_rnd(items)) ? item->path : NULL;
63 /*---------------------------------------------------------------------------*/
65 static float real_time = 0.0f;
70 static int play_id = 0;
78 static int title_action(int i)
80 static const char keyphrase[] = "CHEAT";
81 static char queue[sizeof (keyphrase)] = "";
83 size_t queue_len = strlen(queue);
85 audio_play(AUD_MENU, 1.0f);
90 if (strlen(config_get_s(CONFIG_PLAYER)) == 0)
91 return goto_name(&st_set, &st_title, 0);
93 return goto_state(&st_set);
97 case TITLE_HELP: return goto_state(&st_help); break;
98 case TITLE_DEMO: return goto_state(&st_demo); break;
99 case TITLE_CONF: return goto_state(&st_conf); break;
100 case TITLE_EXIT: return 0; break;
104 /* Let the queue fill up. */
106 if (queue_len < sizeof (queue) - 1)
108 queue[queue_len] = (char) i;
109 queue[queue_len + 1] = '\0';
112 /* Advance the queue before adding the new element. */
118 for (k = 1; k < queue_len; k++)
119 queue[k - 1] = queue[k];
121 queue[queue_len - 1] = (char) i;
124 if (strcmp(queue, keyphrase) == 0)
127 gui_set_label(play_id, sgettext("menu^Cheat"));
128 gui_pulse(play_id, 1.2f);
130 else if (config_cheat())
133 gui_set_label(play_id, sgettext("menu^Play"));
134 gui_pulse(play_id, 1.2f);
142 static int title_gui(void)
146 /* Build the title GUI. */
148 if ((id = gui_vstack(0)))
150 gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
154 if ((jd = gui_harray(id)))
158 if ((kd = gui_varray(jd)))
161 play_id = gui_start(kd, sgettext("menu^Cheat"),
162 GUI_MED, TITLE_PLAY, 1);
164 play_id = gui_start(kd, sgettext("menu^Play"),
165 GUI_MED, TITLE_PLAY, 1);
167 gui_state(kd, sgettext("menu^Replay"), GUI_MED, TITLE_DEMO, 0);
168 gui_state(kd, sgettext("menu^Help"), GUI_MED, TITLE_HELP, 0);
169 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
170 gui_state(kd, sgettext("menu^Exit"), GUI_MED, TITLE_EXIT, 0);
175 gui_layout(id, 0, 0);
181 static int title_enter(struct state *st, struct state *prev)
183 /* Start the title screen music. */
185 audio_music_fade_to(0.5f, "bgm/title.ogg");
187 /* Initialize the title level for display. */
194 SDL_EnableUNICODE(1);
199 static void title_leave(struct state *st, struct state *next, int id)
203 demo_dir_free(items);
207 SDL_EnableUNICODE(0);
212 static void title_timer(int id, float dt)
214 static const char *demo = NULL;
220 case 0: /* Mode 0: Pan across title level. */
222 if (real_time <= 20.0f)
224 game_client_fly(fcosf(V_PI * real_time / 20.0f));
234 case 1: /* Mode 1: Fade out. Load demo level. */
236 if (real_time > 1.0f)
239 items = demo_dir_scan();
241 if ((demo = pick_demo(items)))
243 demo_replay_init(demo, NULL, NULL, NULL, NULL, NULL);
244 game_client_fly(0.0f);
257 case 2: /* Mode 2: Run demo. */
259 if (!demo_replay_step(dt))
268 case 3: /* Mode 3: Fade out. Load title level. */
270 if (real_time > 1.0f)
284 static int title_keybd(int c, int d)
286 if (d && (c & 0xFF80) == 0 && c > ' ')
287 return title_action(c);
291 static int title_buttn(int b, int d)
295 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
296 return title_action(gui_token(gui_click()));
297 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
303 /*---------------------------------------------------------------------------*/
305 struct state st_title = {