Using filename instead of author and level name
[supertux.git] / src / supertux / statistics.cpp
index da9ffb1..e14f4bd 100644 (file)
@@ -95,7 +95,7 @@ Statistics::unserialize_from_squirrel(HSQUIRRELVM vm)
 }
 
 void
-Statistics::draw_worldmap_info(DrawingContext& context)
+Statistics::draw_worldmap_info(DrawingContext& context, float target_time)
 {
   // skip draw if level was never played
   if (coins == nv_coins) return;
@@ -103,6 +103,9 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   // skip draw if stats were declared invalid
   if (!valid) return;
 
+  // no sense drawing stats if there are none
+  if (total_coins + total_badguys + total_secrets == 0) return;
+
   // check to see if screen size has been changed
   if (!(WMAP_INFO_TOP_Y1 == SCREEN_HEIGHT - 100)) {
     WMAP_INFO_LEFT_X = SCREEN_WIDTH - 32 - 256;
@@ -118,7 +121,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   std::string caption_buf;
   std::string stat_buf;
   float posy = WMAP_INFO_TOP_Y2;
-  for (int stat_no = 0; stat_no < 4; stat_no++) {
+  for (int stat_no = 0; stat_no < 5; stat_no++) {
     switch (stat_no)
     {
       case 0:
@@ -130,13 +133,22 @@ Statistics::draw_worldmap_info(DrawingContext& context)
         stat_buf = frags_to_string(badguys, total_badguys);
         break;
       case 2:
-        caption_buf = _("Min time needed:");
-        stat_buf = time_to_string(time);
-        break;
-      case 3:
         caption_buf = _("Max secrets found:");
         stat_buf = secrets_to_string(secrets, total_secrets);
         break;
+      case 3:
+        caption_buf = _("Best time completed:");
+        stat_buf = time_to_string(time);
+        break;
+      case 4:
+        if(target_time){ // display target time only if defined for level
+          caption_buf = _("Level target time:");
+          stat_buf = time_to_string(target_time);
+        } else {
+          caption_buf = "";
+          stat_buf = "";
+        }
+        break;
       default:
         log_debug << "Invalid stat requested to be drawn" << std::endl;
         break;
@@ -158,6 +170,9 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, S
   // abort if we have no backdrop
   if (!backdrop) return;
 
+  // no sense drawing stats if there are none
+  if (total_coins + total_badguys + total_secrets == 0) return;
+
   int box_w = 220+110+110;
   int box_h = 30+20+20+20;
   int box_x = (int)((SCREEN_WIDTH - box_w) / 2);
@@ -267,11 +282,12 @@ Statistics::operator+=(const Statistics& s2)
 }
 
 bool
-Statistics::completed(const Statistics& stats)
+Statistics::completed(const Statistics& stats, const float target_time)
 {
   return (stats.coins == stats.total_coins && 
       stats.badguys == stats.total_badguys && 
-      stats.secrets == stats.total_secrets);
+      stats.secrets == stats.total_secrets &&
+      ((!target_time) || (stats.time <= target_time)));
 }
 
 void