added object remove_listener so that you can get a message if some objects are remove...
[supertux.git] / src / statistics.cpp
index 5c57313..dc3e83a 100644 (file)
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //  02111-1307, USA.
 
-#include "utils/lispreader.h"
-#include "utils/lispwriter.h"
+#include <config.h>
+
 #include "video/drawing_context.h"
 #include "app/gettext.h"
 #include "app/globals.h"
+#include "lisp/lisp.h"
 #include "resources.h"
 #include "statistics.h"
 
@@ -56,7 +57,6 @@ return std::min(a, b);
 
 Statistics::Statistics()
 {
-  timer.init(true);
   display_stat = 1;
 
   for(int i = 0; i < NUM_STATS; i++)
@@ -69,23 +69,21 @@ Statistics::~Statistics()
 }
 
 void
-Statistics::parse(LispReader& reader)
+Statistics::parse(const lisp::Lisp& reader)
 {
-  for(int i = 0; i < NUM_STATS; i++)
-    {
-    reader.read_int(stat_name_to_string(i).c_str(), stats[i][SPLAYER]);
-    reader.read_int((stat_name_to_string(i) + "-total").c_str(), stats[i][STOTAL]);
-    }
+  for(int i = 0; i < NUM_STATS; i++) {
+    reader.get(stat_name_to_string(i).c_str(), stats[i][SPLAYER]);
+    reader.get((stat_name_to_string(i) + "-total").c_str(), stats[i][STOTAL]);
+  }
 }
 
 void
-Statistics::write(LispWriter& writer)
+Statistics::write(lisp::Writer& writer)
 {
-  for(int i = 0; i < NUM_STATS; i++)
-    {
+  for(int i = 0; i < NUM_STATS; i++) {
     writer.write_int(stat_name_to_string(i), stats[i][SPLAYER]);
     writer.write_int(stat_name_to_string(i) + "-total", stats[i][STOTAL]);
-    }
+  }
 }
 
 #define TOTAL_DISPLAY_TIME 3400
@@ -100,7 +98,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   if(stats[SCORE_STAT][SPLAYER] == -1)  // not initialized yet
     return;
 
-  if(!timer.check())
+  if(timer.check())
     {
     timer.start(TOTAL_DISPLAY_TIME);
     display_stat++;
@@ -108,14 +106,6 @@ Statistics::draw_worldmap_info(DrawingContext& context)
       display_stat = 1;
     }
 
-  int alpha;
-  if(timer.get_gone() < FADING_TIME)
-    alpha = timer.get_gone() * 255 / FADING_TIME;
-  else if(timer.get_left() < FADING_TIME)
-    alpha = timer.get_left() * 255 / FADING_TIME;
-  else
-    alpha = 255;
-
   char str[128];
 
   context.draw_text(white_small_text, _("- Best Level Statistics -"),
@@ -130,6 +120,17 @@ Statistics::draw_worldmap_info(DrawingContext& context)
 
   // draw other small info
 
+  int alpha;
+  if(timer.get_timegone() < FADING_TIME)
+    alpha = int(timer.get_timegone() * 255 / FADING_TIME);
+  else if(timer.get_timeleft() < FADING_TIME)
+    alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
+  else
+    alpha = 255;
+
+  context.push_transform();
+  context.set_alpha(alpha);
+
   if(display_stat == COINS_COLLECTED_STAT)
     sprintf(str, _("Max coins collected:"));
   else if(display_stat == BADGUYS_KILLED_STAT)
@@ -137,7 +138,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   else// if(display_stat == TIME_NEEDED_STAT)
     sprintf(str, _("Min time needed:"));
 
-  context.draw_text(white_small_text, str, Vector(WMAP_INFO_LEFT_X, 508), LEFT_ALLIGN, LAYER_GUI, NONE_EFFECT, alpha);
+  context.draw_text(white_small_text, str, Vector(WMAP_INFO_LEFT_X, 508), LEFT_ALLIGN, LAYER_GUI);
 
   if(display_stat == COINS_COLLECTED_STAT)
     sprintf(str, "%d/%d", stats[COINS_COLLECTED_STAT][SPLAYER],
@@ -149,7 +150,9 @@ Statistics::draw_worldmap_info(DrawingContext& context)
     sprintf(str, "%d/%d", stats[TIME_NEEDED_STAT][SPLAYER],
                           stats[TIME_NEEDED_STAT][STOTAL]);
 
-  context.draw_text(white_small_text, str, Vector(WMAP_INFO_RIGHT_X, 508), RIGHT_ALLIGN, LAYER_GUI, NONE_EFFECT, alpha);
+  context.draw_text(white_small_text, str, Vector(WMAP_INFO_RIGHT_X, 508), RIGHT_ALLIGN, LAYER_GUI);
+
+  context.pop_transform();
 }
 
 void