Those sets haven't been merged.
[neverball] / ball / st_set.c
index fa9837a..2402a1b 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
 
 /*---------------------------------------------------------------------------*/
 
-#define SET_BACK -1
-#define SET_PREV -2
-#define SET_NEXT -3
-#define SET_NULL -4
+#define SET_STEP    5
 
-#define SET_GROUP 5 /* number of sets in one screen */
+static int total = 0;
+static int first = 0;
 
 static int shot_id;
 static int desc_id;
 
+static int should_prompt = 1;
+
 static int set_action(int i)
 {
     audio_play(AUD_MENU, 1.0f);
 
-    switch(i)
+    switch (i)
     {
     case GUI_BACK:
         return goto_state(&st_title);
+        break;
 
     case GUI_PREV:
-       config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)-1)*SET_GROUP);
-       return goto_state(&st_set);
-    
+
+        first -= SET_STEP;
+
+        should_prompt = 0;
+        return goto_state(&st_set);
+
+        break;
+
     case GUI_NEXT:
-       config_set_d(CONFIG_LAST_SET, ((config_get_d(CONFIG_LAST_SET)/SET_GROUP)+1)*SET_GROUP);
-       return goto_state(&st_set);
+
+        first += SET_STEP;
+
+        should_prompt = 0;
+        return goto_state(&st_set);
+
+        break;
 
     case GUI_NULL:
-       return 1;
-    
+        return 1;
+        break;
+
     default:
-       if (set_exists(i))
-       {
-           config_set_d(CONFIG_LAST_SET, i);
-           set_goto(i);
-           return goto_state(&st_start);
-       }
+        if (set_exists(i))
+        {
+            set_goto(i);
+            return goto_state(&st_start);
+        }
     }
+
     return 1;
 }
 
 static void gui_set(int id, int i)
 {
-    const struct set *s = get_set(i);
-    int jd;
-    
-    if (set_completed(s)) 
-       jd = gui_label(id, _(s->name), GUI_SML, GUI_ALL, gui_yel, gui_wht);
-    else if (set_extra_bonus_opened(s)) 
-       jd = gui_label(id, _(s->name), GUI_SML, GUI_ALL, gui_grn, gui_wht);
+    const struct set *s;
+
+    if ((s = get_set(i)))
+        gui_state(id, _(s->name), GUI_SML, i, 0);
     else
-       jd = gui_label(id, _(s->name), GUI_SML, GUI_ALL, gui_wht, gui_wht);
-    
-    gui_active(jd, i, 0);
+        gui_label(id, "", GUI_SML, GUI_ALL, 0, 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 i;
 
     int id, jd, kd;
 
-    if (!set_exists(last_set))
-    {
-       b = 0;
-       last_set = 0;
-    }
+    int i;
 
-    set_init();
+    total = set_init();
 
     audio_music_fade_to(0.5f, "bgm/inter.ogg");
-    audio_play(AUD_START, 1.f);
+
+    if (should_prompt)
+        audio_play(AUD_START, 1.f);
+    else should_prompt = 1;
 
     if ((id = gui_vstack(0)))
     {
@@ -110,27 +113,24 @@ static int set_enter(void)
         {
             gui_label(jd, _("Level Set"), GUI_SML, GUI_ALL, gui_yel, gui_red);
             gui_filler(jd);
-           gui_back_prev_next(jd, b>0, set_exists((b+1)*SET_GROUP));
+            gui_back_prev_next(jd, first > 0, first + SET_STEP < total);
         }
 
         if ((jd = gui_harray(id)))
         {
-            shot_id = gui_image(jd, get_set(last_set)->shot, 7 * w / 16, 7 * h / 16);
+            shot_id = gui_image(jd, get_set(first)->shot,
+                                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++)
-                   gui_set(kd, i);
-               
-               /* Display empty slots */
-               for(; i<(b+1)*SET_GROUP; i++)
-                   gui_filler(kd);
-           }          
+            {
+                for (i = first; i < first + SET_STEP; i++)
+                    gui_set(kd, i);
+            }
         }
 
         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);
     }
@@ -148,7 +148,7 @@ static void set_point(int id, int x, int y, int dx, int dy)
     int jd = shared_point_basic(id, x, y);
     int i  = gui_token(jd);
     if (jd && set_exists(i))
-       set_over(i);
+        set_over(i);
 }
 
 static void set_stick(int id, int a, int v)
@@ -156,7 +156,7 @@ static void set_stick(int id, int a, int v)
     int jd = shared_stick_basic(id, a, v);
     int i  = gui_token(jd);
     if (jd && set_exists(i))
-       set_over(i);
+        set_over(i);
 }
 
 static int set_buttn(int b, int d)
@@ -180,6 +180,7 @@ struct state st_set = {
     shared_timer,
     set_point,
     set_stick,
+    shared_angle,
     shared_click,
     NULL,
     set_buttn,