2 * Copyright (C) 2003-2010 Neverball authors
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.
29 #include "game_server.h"
30 #include "game_proxy.h"
31 #include "game_client.h"
32 #include "game_common.h"
36 #include "st_shared.h"
47 static char ball_file[64];
51 static int has_ball_sols(struct dir_item *item)
53 char *solid, *inner, *outer;
56 solid = concat_string(item->path,
58 base_name(item->path),
61 inner = concat_string(item->path,
63 base_name(item->path),
66 outer = concat_string(item->path,
68 base_name(item->path),
72 yes = (fs_exists(solid) || fs_exists(inner) || fs_exists(outer));
81 static void scan_balls(void)
85 SAFECPY(ball_file, config_get_s(CONFIG_BALL_FILE));
87 if ((balls = fs_dir_scan("ball", has_ball_sols)))
89 for (i = 0; i < array_len(balls); i++)
91 const char *path = DIR_ITEM_GET(balls, i)->path;
93 if (strncmp(ball_file, path, strlen(path)) == 0)
102 static void free_balls(void)
108 static void set_curr_ball(void)
110 sprintf(ball_file, "%s/%s",
111 DIR_ITEM_GET(balls, curr_ball)->path,
112 base_name(DIR_ITEM_GET(balls, curr_ball)->path));
114 config_set_s(CONFIG_BALL_FILE, ball_file);
119 gui_set_label(name_id, base_name(ball_file));
122 static int ball_action(int i)
124 audio_play(AUD_MENU, 1.0f);
129 if (++curr_ball == array_len(balls))
137 if (--curr_ball == -1)
138 curr_ball = array_len(balls) - 1;
145 goto_state(&st_conf);
152 static void load_ball_demo(void)
156 /* "g" is a stupid hack to keep the goal locked. */
158 demo_replay_init("gui/ball.nbr", &g, NULL, NULL, NULL, NULL);
159 audio_music_fade_to(0.0f, "bgm/inter.ogg");
163 back_init("back/gui.png");
166 static int ball_gui(void)
171 if ((id = gui_vstack(0)))
173 if ((jd = gui_harray(id)))
175 gui_label(jd, _("Ball Model"), GUI_SML, GUI_ALL, 0, 0);
177 gui_start(jd, _("Back"), GUI_SML, BALL_BACK, 0);
182 if ((jd = gui_hstack(id)))
184 gui_state(jd, " > ", GUI_SML, BALL_NEXT, 0);
186 name_id = gui_label(jd, "very-long-ball-name",
190 gui_set_trunc(name_id, TRUNC_TAIL);
191 gui_set_fill(name_id);
193 gui_state(jd, " < ", GUI_SML, BALL_PREV, 0);
196 for (i = 0; i < 12; i++)
199 gui_layout(id, 0, 0);
201 gui_set_label(name_id, base_name(ball_file));
207 static int ball_enter(struct state *st, struct state *prev)
215 static void ball_leave(struct state *st, struct state *next, int id)
223 static void ball_paint(int id, float t)
225 video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
231 game_client_draw(POSE_BALL, t);
235 static void ball_timer(int id, float dt)
239 if (!demo_replay_step(dt))
245 game_client_blend(demo_replay_blend());
248 static int ball_buttn(int b, int d)
252 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
253 return ball_action(gui_token(gui_click()));
255 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
256 return ball_action(BALL_BACK);
261 struct state st_ball = {