Fixed a problem with Makefile.mingw where make wasn't rebuilding targets
[neverball] / ball / st_level.c
index 2a6702b..cbd157e 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
 
 #include "gui.h"
 #include "game.h"
-#include "level.h"
+#include "set.h"
+#include "levels.h"
 #include "audio.h"
 #include "config.h"
+#include "st_shared.h"
 
 #include "st_level.h"
 #include "st_play.h"
-#include "st_over.h"
+#include "st_start.h"
 
 /*---------------------------------------------------------------------------*/
 
+static int level_ok;
+
 static int level_enter(void)
 {
-    int id, jd;
+    int id, jd, kd, ld;
+    const char *ln;
+    const struct level_game *lg = curr_lg();
+    int b;
+    const float *textcol1, *textcol2;
+
+    /* Load the level */
+    level_ok = level_play_go();
 
     if ((id = gui_vstack(0)))
     {
-        if ((jd = gui_hstack(id)))
+        if (lg->mode == MODE_SINGLE)
         {
+            gui_label(id, _("Single Level"), GUI_LRG, GUI_TOP, 0, 0);
+        }
+        else if ((jd = gui_hstack(id)))
+        {
+            ln = lg->level->repr;
+            b = lg->level->is_bonus;
+            textcol1 = b ? gui_wht : 0;
+            textcol2 = b ? gui_grn : 0;
+
             gui_filler(jd);
-            gui_count(jd, curr_level(), GUI_LRG, GUI_NE | GUI_SE);
-            gui_label(jd, _("Level "),     GUI_LRG, GUI_NW | GUI_SW, 0, 0);
+
+            if ((kd = gui_vstack(jd)))
+            {
+                gui_label(kd, _(curr_set()->name), GUI_SML,
+                          GUI_ALL, gui_wht, gui_wht);
+                gui_space(kd);
+
+                if ((ld = gui_hstack(kd)))
+                {
+                    gui_label(ld, ln,          GUI_LRG, GUI_NE,
+                              textcol1, textcol2);
+                    gui_label(ld, _("Level "), GUI_LRG, GUI_NW,
+                              textcol1, textcol2);
+                }
+
+                gui_label(kd, mode_to_str(lg->mode, 1), GUI_SML, GUI_BOT,
+                          gui_wht, gui_wht);
+
+            }
             gui_filler(jd);
         }
         gui_space(id);
-        gui_multi(id, _(curr_intro()), GUI_SML, GUI_ALL, gui_wht, gui_wht);
+
+        if (!level_ok)
+            gui_label(id, _("Cannot load the level file."), GUI_SML, GUI_ALL,
+                      gui_red, gui_red);
+        else if (lg->level->message[0] != '\0')
+            gui_multi(id, _(lg->level->message), GUI_SML, GUI_ALL, gui_wht,
+                      gui_wht);
 
         gui_layout(id, 0, 0);
     }
@@ -48,34 +91,23 @@ static int level_enter(void)
     return id;
 }
 
-static void level_leave(int id)
-{
-    gui_delete(id);
-}
-
 static void level_timer(int id, float dt)
 {
     game_step_fade(dt);
     audio_timer(dt);
 }
 
-static void level_paint(int id, float st)
-{
-    game_draw(0, st);
-    gui_paint(id);
-}
-
 static int level_click(int b, int d)
 {
-    return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
+    if (b < 0 && d == 1)
+        return level_ok ? goto_state(&st_play_ready) : goto_end_level();
+    return 1;
 }
 
 static int level_keybd(int c, int d)
 {
-    if (d && c == SDLK_ESCAPE)
-        goto_state(&st_over);
     if (d && c == SDLK_F12)
-        goto_state(&st_poser);
+        return goto_state(&st_poser);
     return 1;
 }
 
@@ -84,9 +116,14 @@ static int level_buttn(int b, int d)
     if (d)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
-            return goto_state(&st_play_ready);
+        {
+            if (level_ok)
+                return goto_state(&st_play_ready);
+            else
+                return goto_end_level();
+        }
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return goto_state(&st_over);
+            return goto_end_level();
     }
     return 1;
 }
@@ -98,17 +135,17 @@ static void poser_paint(int id, float st)
     game_draw(1, st);
 }
 
-static int poser_keybd(int c, int d)
+static int poser_buttn(int c, int d)
 {
-    return (d && c == SDLK_ESCAPE) ? goto_state(&st_level) : 1;
+    return (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c)) ? goto_state(&st_level) : 1;
 }
 
 /*---------------------------------------------------------------------------*/
 
 struct state st_level = {
     level_enter,
-    level_leave,
-    level_paint,
+    shared_leave,
+    shared_paint,
     level_timer,
     NULL,
     NULL,
@@ -126,7 +163,7 @@ struct state st_poser = {
     NULL,
     NULL,
     NULL,
-    poser_keybd,
     NULL,
+    poser_buttn,
     1, 0
 };