Fix repeated animation on return from replay save screen
[neverball] / ball / st_goal.c
index 62d4d03..4d622a8 100644 (file)
@@ -49,9 +49,6 @@ static int balls_id;
 static int coins_id;
 static int score_id;
 
-/* Bread crumbs. */
-
-static int new_name;
 static int resume;
 
 static int goal_action(int i)
@@ -68,15 +65,10 @@ static int goal_action(int i)
         return goto_state(&st_over);
 
     case GOAL_SAVE:
-        resume = 1;
-
         progress_stop();
         return goto_save(&st_goal, &st_goal);
 
     case GUI_NAME:
-        new_name = 1;
-        resume = 1;
-
         progress_stop();
         return goto_name(&st_goal, &st_goal, 0);
 
@@ -89,11 +81,10 @@ static int goal_action(int i)
         progress_stop();
         return goto_state(&st_start);
 
-    case GUI_MOST_COINS:
-    case GUI_BEST_TIMES:
-    case GUI_FAST_UNLOCK:
+    case GUI_SCORE_COIN:
+    case GUI_SCORE_TIME:
+    case GUI_SCORE_GOAL:
         gui_score_set(i);
-        resume = 1;
         return goto_state(&st_goal);
 
     case GOAL_NEXT:
@@ -110,22 +101,15 @@ static int goal_action(int i)
     return 1;
 }
 
-static int goal_enter(void)
+static int goal_gui(void)
 {
     const char *s1 = _("New Record");
     const char *s2 = _("GOAL");
 
-    int id, jd, kd;
-
-    const struct level *l = get_level(curr_level());
+    int id, jd, kd, ld, md;
 
     int high = progress_lvl_high();
-
-    if (new_name)
-    {
-        progress_rename(0);
-        new_name = 0;
-    }
+    int level = curr_level();
 
     if ((id = gui_vstack(0)))
     {
@@ -169,31 +153,42 @@ static int goal_enter(void)
 
             if ((jd = gui_hstack(id)))
             {
+                gui_filler(jd);
 
-                if ((kd = gui_harray(jd)))
-                {
-                    balls_id = gui_count(kd, 100, GUI_MED, GUI_NE);
-                    gui_label(kd, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
-                }
-                if ((kd = gui_harray(jd)))
+                if ((kd = gui_vstack(jd)))
                 {
-                    score_id = gui_count(kd, 1000, GUI_MED, 0);
-                    gui_label(kd, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
+                    if ((ld = gui_hstack(kd)))
+                    {
+                        if ((md = gui_harray(ld)))
+                        {
+                            balls_id = gui_count(md, 100, GUI_MED, GUI_NE);
+                            gui_label(md, _("Balls"), GUI_SML, 0,
+                                      gui_wht, gui_wht);
+                        }
+                        if ((md = gui_harray(ld)))
+                        {
+                            score_id = gui_count(md, 1000, GUI_MED, 0);
+                            gui_label(md, _("Score"), GUI_SML, 0,
+                                      gui_wht, gui_wht);
+                        }
+                        if ((md = gui_harray(ld)))
+                        {
+                            coins_id = gui_count(md, 100, GUI_MED, 0);
+                            gui_label(md, _("Coins"), GUI_SML, GUI_NW,
+                                      gui_wht, gui_wht);
+                        }
+
+                        gui_set_count(balls_id, balls);
+                        gui_set_count(score_id, score);
+                        gui_set_count(coins_id, coins);
+                    }
+
+                    gui_label(kd, msg, GUI_SML, GUI_BOT, 0, 0);
                 }
-                if ((kd = gui_harray(jd)))
-                {
-                    coins_id = gui_count(kd, 100, GUI_MED, 0);
-                    gui_label(kd, _("Coins"), GUI_SML, GUI_NW, gui_wht, gui_wht);
-                }
-
-                gui_set_count(balls_id, balls);
-                gui_set_count(score_id, score);
-                gui_set_count(coins_id, coins);
 
+                gui_filler(jd);
             }
 
-            gui_label(id, msg, GUI_SML, GUI_BOT, 0, 0);
-
             gui_space(id);
         }
         else
@@ -201,10 +196,9 @@ static int goal_enter(void)
             balls_id = score_id = coins_id = 0;
         }
 
-        if ((jd = gui_hstack(id)))
-            gui_score_board(jd, GUI_MOST_COINS |
-                                GUI_BEST_TIMES |
-                                GUI_FAST_UNLOCK, 1, high);
+        gui_score_board(id, (GUI_SCORE_COIN |
+                             GUI_SCORE_TIME |
+                             GUI_SCORE_GOAL), 1, high);
 
         gui_space(id);
 
@@ -232,54 +226,62 @@ static int goal_enter(void)
 
     }
 
-    set_score_board(&l->score.most_coins,  progress_coin_rank(),
-                    &l->score.best_times,  progress_time_rank(),
-                    &l->score.fast_unlock, progress_goal_rank());
+    set_score_board(level_score(level, SCORE_COIN), progress_coin_rank(),
+                    level_score(level, SCORE_TIME), progress_time_rank(),
+                    level_score(level, SCORE_GOAL), progress_goal_rank());
 
-    audio_music_fade_out(2.0f);
-
-    config_clr_grab();
-
-    /* Reset hack. */
-    resume = 0;
 
     return id;
 }
 
-static void goal_timer(int id, float dt)
+static int goal_enter(struct state *st, struct state *prev)
 {
-    static float t = 0.0f;
+    if (prev == &st_name)
+        progress_rename(0);
 
-    t += dt;
+    audio_music_fade_out(2.0f);
+    video_clr_grab();
+    resume = (prev == &st_goal || prev == &st_name || prev == &st_save);
+    return goal_gui();
+}
 
-    if (time_state() < 1.f)
-    {
-        game_server_step(dt);
-        game_client_step(demo_file());
-    }
-    else if (t > 0.05f && coins_id)
+static void goal_timer(int id, float dt)
+{
+    if (!resume)
     {
-        int coins = gui_value(coins_id);
+        static float t = 0.0f;
+
+        t += dt;
 
-        if (coins > 0)
+        if (time_state() < 1.f)
+        {
+            game_server_step(dt);
+            game_client_sync(demo_fp);
+        }
+        else if (t > 0.05f && coins_id)
         {
-            int score = gui_value(score_id);
-            int balls = gui_value(balls_id);
+            int coins = gui_value(coins_id);
 
-            gui_set_count(coins_id, coins - 1);
-            gui_pulse(coins_id, 1.1f);
+            if (coins > 0)
+            {
+                int score = gui_value(score_id);
+                int balls = gui_value(balls_id);
 
-            gui_set_count(score_id, score + 1);
-            gui_pulse(score_id, 1.1f);
+                gui_set_count(coins_id, coins - 1);
+                gui_pulse(coins_id, 1.1f);
 
-            if (progress_reward_ball(score + 1))
-            {
-                gui_set_count(balls_id, balls + 1);
-                gui_pulse(balls_id, 2.0f);
-                audio_play(AUD_BALL, 1.0f);
+                gui_set_count(score_id, score + 1);
+                gui_pulse(score_id, 1.1f);
+
+                if (progress_reward_ball(score + 1))
+                {
+                    gui_set_count(balls_id, balls + 1);
+                    gui_pulse(balls_id, 2.0f);
+                    audio_play(AUD_BALL, 1.0f);
+                }
             }
+            t = 0.0f;
         }
-        t = 0.0f;
     }
 
     gui_timer(id, dt);
@@ -310,19 +312,11 @@ static int goal_buttn(int b, int d)
     return 1;
 }
 
-static void goal_leave(int id)
-{
-    /* HACK:  don't run animation if only "visiting" a state. */
-    st_goal.timer = resume ? shared_timer : goal_timer;
-
-    gui_delete(id);
-}
-
 /*---------------------------------------------------------------------------*/
 
 struct state st_goal = {
     goal_enter,
-    goal_leave,
+    shared_leave,
     shared_paint,
     goal_timer,
     shared_point,