X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=ball%2Fst_set.c;h=663e9d5ac01ad71786cd21ce6ef31b52f8dcb9c4;hb=9a5b5f027b27b45b4926604f48cf00904b37ec64;hp=5429a92f6336264bf8022cea78635f8b6e31cebb;hpb=0f17528baaf530edc2b7b5d0f5f616d0c39f8dc7;p=neverball diff --git a/ball/st_set.c b/ball/st_set.c index 5429a92..663e9d5 100644 --- a/ball/st_set.c +++ b/ball/st_set.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003 Robert Kooima * * NEVERBALL is free software; you can redistribute it and/or modify @@ -14,9 +14,12 @@ #include "gui.h" #include "set.h" +#include "levels.h" #include "game.h" #include "audio.h" #include "config.h" +#include "util.h" +#include "st_shared.h" #include "st_set.h" #include "st_title.h" @@ -24,57 +27,146 @@ /*---------------------------------------------------------------------------*/ -#define SET_BACK -1 -#define SET_PREV -2 -#define SET_NEXT -3 +#define SET_STEP 5 -#define SET_GROUP 4 /* number of sets in one screen */ +static int total = 0; +static int first = 0; static int shot_id; static int desc_id; +static int do_init = 1; +static int do_init_audio = 1; + static int set_action(int i) { audio_play(AUD_MENU, 1.0f); - switch(i) + switch (i) { - case SET_BACK: + case GUI_BACK: + set_free(); return goto_state(&st_title); + break; + + case GUI_PREV: + + first -= SET_STEP; + + do_init = 0; + return goto_state(&st_set); + + break; + + case GUI_NEXT: + + first += SET_STEP; + + do_init = 0; + return goto_state(&st_set); + + break; + + case GUI_OFFIC: + + first = 0; + + config_set_d(CONFIG_SHOW_CONTRIBUTIONS, 0); + + do_init = 1; + do_init_audio = 0; + return goto_state(&st_set); + + break; + + case GUI_CONTRIB: + + first = 0; + + config_set_d(CONFIG_SHOW_CONTRIBUTIONS, 1); + + do_init = 1; + do_init_audio = 0; + return goto_state(&st_set); + + break; + + case GUI_NULL: + return 1; + break; - case SET_PREV: - config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)-1)*SET_GROUP); - return goto_state(&st_set); - - case SET_NEXT: - config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)+1)*SET_GROUP); - return goto_state(&st_set); - default: - if (set_exists(i)) - { - config_set_d(CONFIG_LAST_SET, i); - set_goto(i); - return goto_state(&st_start); - } + if (set_exists(i, 0)) + { + set_goto(i); + return goto_state(&st_start); + } } + return 1; } +static int gui_set(int id, int i) +{ + if (set_exists(i, config_get_d(CONFIG_SHOW_CONTRIBUTIONS) + 1)) + { + gui_state(id, set_name(i), GUI_SML, i, 0); + return 1; + } + else + { + return 0; + } + return 0; +} + static int set_enter(void) { int w = config_get_d(CONFIG_WIDTH); int h = config_get_d(CONFIG_HEIGHT); - int last_set = config_get_d(CONFIG_LAST_SET); - int b = last_set / SET_GROUP; + + int id, jd, kd; + int i; - int id, jd, kd, ld; + int j, n; + j = n = 0; - set_init(); + for(i = 0; i < MAXSET; i++) + { + if (set_exists(i, 2)) + { + n = 1; + break; + } + n = 0; + } - audio_music_fade_to(0.5f, "bgm/inter.ogg"); - audio_play(AUD_START, 1.f); + if (do_init) + { + total = set_init(config_get_d(CONFIG_SHOW_CONTRIBUTIONS)); + if (do_init_audio) + { + audio_music_fade_to(0.5f, "bgm/inter.ogg"); + audio_play(AUD_START, 1.f); + /* We need to recheck for contributions on true initialization */ + for(i = 0; i < MAXSET; i++) + { + if (set_exists(i, 2)) + { + n = 1; + break; + } + n = 0; + } + } + } + + if(config_get_d(CONFIG_SHOW_CONTRIBUTIONS)) + n = 1; + + do_init_audio = 1; + do_init = 1; if ((id = gui_vstack(0))) { @@ -82,112 +174,57 @@ static int set_enter(void) { gui_label(jd, _("Level Set"), GUI_SML, GUI_ALL, gui_yel, gui_red); gui_filler(jd); - gui_state(jd, _("Back"), GUI_SML, SET_BACK, 0); + gui_back_prev_next(jd, first > 0, first + SET_STEP < total, n); } if ((jd = gui_harray(id))) { - shot_id = gui_image(jd, set_shot(last_set), 7 * w / 16, 7 * h / 16); + shot_id = gui_image(jd, set_shot(first), 7 * w / 16, 7 * h / 16); if ((kd = gui_varray(jd))) - { - /* Display levels */ - for(i=b*SET_GROUP; i<(b+1)*SET_GROUP && set_exists(i); i++) - { - if(last_set == i) - gui_start(kd, _(set_name(i)), GUI_SML, i, 0); - else - gui_state(kd, _(set_name(i)), GUI_SML, i, 0); - } - - /* Display Prev/Next buttons */ - ld = gui_harray(kd); - if (set_exists(i)) - gui_state(ld, _("Next"), GUI_SML, SET_NEXT, 0); - else - gui_label(ld, _("Next"), GUI_SML, GUI_ALL, gui_gry, gui_gry); - if (b>0) - gui_state(ld, _("Prev"), GUI_SML, SET_PREV, 0); - else - gui_label(ld, _("Prev"), GUI_SML, GUI_ALL, gui_gry, gui_gry); - - /* Display empty slots */ - for(; i<(b+1)*SET_GROUP; i++) - gui_filler(kd); - } + { + for (i = first; i < MAXSET; i++) + { + if(j==5) + break; + j += gui_set(kd, i); + } + for (i = 0; i < 5 - j && i < MAXSET; i++) + { + gui_label(kd, "", GUI_SML, GUI_ALL, 0, 0); + } + } } gui_space(id); - desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht); + desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, + gui_yel, gui_wht); gui_layout(id, 0, 0); } return id; } -static void set_leave(int id) -{ - gui_delete(id); -} - -static void set_paint(int id, float st) -{ - game_draw(0, st); - config_pop_matrix(); - gui_paint(id); -} - -static void set_timer(int id, float dt) +static void set_over(int i) { - gui_timer(id, dt); - audio_timer(dt); + gui_set_image(shot_id, set_shot(i)); + gui_set_multi(desc_id, set_desc(i)); } static void set_point(int id, int x, int y, int dx, int dy) { - int jd; - - if ((jd = gui_point(id, x, y))) - { - int i = gui_token(jd); - - if (set_exists(i)) - { - gui_set_image(shot_id, set_shot(i)); - gui_set_multi(desc_id, _(set_desc(i))); - gui_pulse(jd, 1.2f); - } - } + int jd = shared_point_basic(id, x, y); + int i = gui_token(jd); + if (jd && set_exists(i, 0)) + set_over(i); } static void set_stick(int id, int a, int v) { - int jd; - - int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0; - int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0; - - if ((jd = gui_stick(id, x, y))) - { - int i = gui_token(jd); - - if (set_exists(i)) - { - gui_set_image(shot_id, set_shot(i)); - gui_set_multi(desc_id, _(set_desc(i))); - gui_pulse(jd, 1.2f); - } - } -} - -static int set_click(int b, int d) -{ - return (b < 0 && d == 1) ? set_action(gui_token(gui_click())) : 1; -} - -static int set_keybd(int c, int d) -{ - return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1; + int jd = shared_stick_basic(id, a, v); + int i = gui_token(jd); + if (jd && set_exists(i, 0)) + set_over(i); } static int set_buttn(int b, int d) @@ -196,10 +233,8 @@ static int set_buttn(int b, int d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) return set_action(gui_token(gui_click())); - if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) - return goto_state(&st_title); if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b)) - return goto_state(&st_title); + return set_action(GUI_BACK); } return 1; } @@ -208,13 +243,14 @@ static int set_buttn(int b, int d) struct state st_set = { set_enter, - set_leave, - set_paint, - set_timer, + shared_leave, + shared_paint, + shared_timer, set_point, set_stick, - set_click, - set_keybd, + shared_angle, + shared_click, + NULL, set_buttn, 1, 0 };