fixed broken 1-time animations in sprites, fixed collision code returning no-collisio...
[supertux.git] / src / high_scores.cpp
index cb3d410..86b1eb6 100644 (file)
 
 /* Open the highscore file: */
 
-#include <string.h>
-#include <stdlib.h>
+#include <config.h>
 
-#include "globals.h"
+#include <cstring>
+#include <cstdlib>
+
+#include "app/globals.h"
 #include "high_scores.h"
-#include "menu.h"
-#include "screen.h"
-#include "texture.h"
-#include "setup.h"
-#include "lispreader.h"
+#include "gui/menu.h"
+#include "video/drawing_context.h"
+#include "video/screen.h"
+#include "video/surface.h"
+#include "app/setup.h"
+#include "utils/lispreader.h"
+#include "resources.h"
+
+using namespace SuperTux;
 
 #ifdef WIN32
 const char * highscore_filename = "/st_highscore.dat";
@@ -69,8 +75,8 @@ void load_hs(void)
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-highscore") == 0)
     {
       LispReader reader(lisp_cdr(root_obj));
-      reader.read_int("score",  &hs_score);
-      reader.read_string("name", &hs_name);
+      reader.read_int("score",  hs_score);
+      reader.read_string("name", hs_name);
     }
  
   fclose(fi);
@@ -84,31 +90,31 @@ void save_hs(int score)
   Surface* bkgd;
   SDL_Event event;
 
-  bkgd = new Surface(datadir + "/images/highscore/highscore.png", IGNORE_ALPHA);
+  DrawingContext context;
+  bkgd = new Surface(datadir + "/images/highscore/highscore.png", false);
 
   hs_score = score;
 
   Menu::set_current(highscore_menu);
 
-  if(!highscore_menu->item[0].input)
-    highscore_menu->item[0].input = (char*) malloc(strlen(hs_name.c_str()) + 1);
-
-  strcpy(highscore_menu->item[0].input,hs_name.c_str());
+  highscore_menu->item[0].input = hs_name;
 
   /* ask for player's name */
   while(Menu::current())
     {
-      bkgd->draw_bg();
+      context.draw_surface(bkgd, Vector(0, 0), LAYER_BACKGROUND0);
 
-      blue_text->drawf("Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
-      blue_text->draw("Your score:", 150, 180, 1, NO_UPDATE);
+      context.draw_text(blue_text, "Congratulations", 
+          Vector(screen->w/2, 130), CENTER_ALLIGN, LAYER_FOREGROUND1);
+      context.draw_text(blue_text, "Your score:", Vector(150, 180),
+          LEFT_ALLIGN, LAYER_FOREGROUND1);
       sprintf(str, "%d", hs_score);
-      yellow_nums->draw(str, 350, 170, 1, NO_UPDATE);
+      context.draw_text(yellow_nums, str, Vector(250, 170), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
-      Menu::current()->draw();
+      Menu::current()->draw(context);
       Menu::current()->action();
 
-      flipscreen();
+      context.do_drawing();
 
       while(SDL_PollEvent(&event))
         if(event.type == SDL_KEYDOWN)
@@ -117,8 +123,7 @@ void save_hs(int score)
       switch (highscore_menu->check())
         {
         case 0:
-          if(highscore_menu->item[0].input != NULL)
-            hs_name = highscore_menu->item[0].input;
+          hs_name = highscore_menu->item[0].input;
           break;
         }
 
@@ -134,8 +139,8 @@ void save_hs(int score)
   /* Save data file: */
   filename = highscore_filename;
 
-  fcreatedir(filename.c_str());
-  if(fwriteable(filename.c_str()))
+  FileSystem::fcreatedir(filename.c_str());
+  if(FileSystem::fwriteable(filename.c_str()))
     {
       fi = fopen(filename.c_str(), "w");
       if (fi == NULL)
@@ -156,18 +161,4 @@ void save_hs(int score)
       fprintf( fi,")");
       fclose(fi);
     }
-
-/*
-  fi = opendata(highscore_filename, "w");
-  if (fi != NULL)
-    {
-      fprintf(fi, "# Supertux highscore file\n\n");
-
-      fprintf(fi, "name=%s\n", hs_name);
-      fprintf(fi, "highscore=%d\n", hs_score);
-
-      fprintf(fi, "# (File automatically created.)\n");
-
-      fclose(fi);
-    }*/
 }