Fix some next level pb with practice mode. Fix #58
[neverball] / ball / st_set.c
index 02fc826..5816d85 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "gui.h"
 #include "set.h"
+#include "levels.h"
 #include "game.h"
 #include "audio.h"
 #include "config.h"
@@ -67,6 +68,21 @@ static int set_action(int i)
     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_unlocked(s)) 
+       jd = gui_label(id, _(s->name), GUI_SML, GUI_ALL, gui_grn, gui_wht);
+    else
+       jd = gui_label(id, _(s->name), GUI_SML, GUI_ALL, gui_wht, gui_wht);
+    
+    gui_active(jd, i, 0);
+}
+
 static int set_enter(void)
 {
     int w = config_get_d(CONFIG_WIDTH);
@@ -77,7 +93,16 @@ static int set_enter(void)
 
     int id, jd, kd;
 
+
     set_init();
+    
+    /* Reset last set if it do not exists */
+    if (!set_exists(last_set))
+    {
+       b = 0;
+       last_set = 0;
+       config_set_d(CONFIG_LAST_SET, 0);
+    }
 
     audio_music_fade_to(0.5f, "bgm/inter.ogg");
     audio_play(AUD_START, 1.f);
@@ -93,18 +118,13 @@ static int set_enter(void)
 
         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, get_set(last_set)->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++)
-               {
-                   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);
-               }
+                   gui_set(kd, i);
                
                /* Display empty slots */
                for(; i<(b+1)*SET_GROUP; i++)
@@ -122,8 +142,8 @@ static int set_enter(void)
 
 static void set_over(int i)
 {
-    gui_set_image(shot_id, set_shot(i));
-    gui_set_multi(desc_id, _(set_desc(i)));
+    gui_set_image(shot_id, get_set(i)->shot);
+    gui_set_multi(desc_id, _(get_set(i)->desc));
 }
 
 static void set_point(int id, int x, int y, int dx, int dy)