Added (inactive) code to show level pictures on worldmap
authorChristoph Sommer <mail@christoph-sommer.de>
Sat, 17 Jun 2006 11:38:43 +0000 (11:38 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sat, 17 Jun 2006 11:38:43 +0000 (11:38 +0000)
SVN-Revision: 3670

src/file_system.cpp
src/file_system.hpp
src/statistics.cpp
src/worldmap/level.cpp
src/worldmap/level.hpp
src/worldmap/worldmap.cpp

index e5721dc..cb8f426 100644 (file)
@@ -47,6 +47,15 @@ std::string basename(const std::string& filename)
   return filename.substr(p+1, filename.size()-p-1);
 }
 
+std::string strip_extension(const std::string& filename)
+{
+  std::string::size_type p = filename.find_last_of('.');
+  if(p == std::string::npos)
+    return filename;
+
+  return filename.substr(0, p);
+}
+
 std::string normalize(const std::string& filename)
 {
   std::vector<std::string> path_stack;
index 306fbc9..9c14bac 100644 (file)
@@ -27,6 +27,12 @@ namespace FileSystem
 {
   std::string dirname(const std::string& filename);
   std::string basename(const std::string& filename);
+
+  /**
+   * remove everything starting from and including the last dot
+   */
+  std::string strip_extension(const std::string& filename);
+
   /**
    * normalize filename so that "blup/bla/blo/../../bar" will become
    * "blup/bar"
index 731dc4d..5a9cc64 100644 (file)
@@ -75,8 +75,19 @@ Statistics::write(lisp::Writer& writer)
 #define TOTAL_DISPLAY_TIME  5
 #define FADING_TIME         1
 
-#define WMAP_INFO_LEFT_X  520
-#define WMAP_INFO_RIGHT_X 740
+const float WMAP_INFO_LEFT_X = (800 - 320) + 32;
+const float WMAP_INFO_RIGHT_X = 800 - 32;
+const float WMAP_INFO_TOP_Y1 = 600 - 128 - 16;
+const float WMAP_INFO_TOP_Y2 = 600 - 128;
+
+namespace {
+  inline const char* chain(const char* c1, const char* c2) {
+    return (std::string(c1) + std::string(c2)).c_str();
+  }
+  inline const char* chain(const char* c1, const char* c2, const char* c3) {
+    return (std::string(c1) + std::string(c2) + std::string(c3)).c_str();
+  }
+}
 
 void
 Statistics::draw_worldmap_info(DrawingContext& context)
@@ -84,7 +95,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   // skip draw if level was never played
   if (coins == nv_coins) return;
 
-  context.draw_text(white_small_text, _("- Best Level Statistics -"), Vector((WMAP_INFO_LEFT_X + WMAP_INFO_RIGHT_X) / 2, 470), CENTER_ALLIGN, LAYER_GUI);
+  context.draw_text(white_small_text, ::chain("- ", _("Best Level Statistics"), " -"), Vector((WMAP_INFO_LEFT_X + WMAP_INFO_RIGHT_X) / 2, WMAP_INFO_TOP_Y1), CENTER_ALLIGN, LAYER_GUI);
 
   float alpha;
   if(timer.get_timegone() < FADING_TIME)
@@ -134,8 +145,8 @@ Statistics::draw_worldmap_info(DrawingContext& context)
     if (display_stat > 3) display_stat = 0;
   }
 
-  context.draw_text(white_small_text, caption_buf, Vector(WMAP_INFO_LEFT_X, 490), LEFT_ALLIGN, LAYER_GUI);
-  context.draw_text(white_small_text, stat_buf, Vector(WMAP_INFO_RIGHT_X, 490), RIGHT_ALLIGN, LAYER_GUI);
+  context.draw_text(white_small_text, caption_buf, Vector(WMAP_INFO_LEFT_X, WMAP_INFO_TOP_Y2), LEFT_ALLIGN, LAYER_GUI);
+  context.draw_text(white_small_text, stat_buf, Vector(WMAP_INFO_RIGHT_X, WMAP_INFO_TOP_Y2), RIGHT_ALLIGN, LAYER_GUI);
   context.pop_transform();
 }
 
index 51f2a81..fbc6b0b 100644 (file)
 #include "sprite/sprite_manager.hpp"
 #include "sprite/sprite.hpp"
 #include "video/drawing_context.hpp"
+#include "log.hpp"
+#include "file_system.hpp"
 
 namespace WorldMapNS
 {
 
 LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
-  : solved(false), auto_path(true)
+  : solved(false), auto_path(true), basedir(basedir), picture_cached(false), picture(0)
 {
   lisp->get("x", pos.x);
   lisp->get("y", pos.y);
@@ -52,6 +54,7 @@ LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
 
 LevelTile::~LevelTile()
 {
+  delete picture;
 }
 
 void
@@ -65,4 +68,17 @@ LevelTile::update(float )
 {
 }
 
+const Surface*
+LevelTile::get_picture()
+{
+  if (picture_cached) return picture;
+  picture_cached = true;
+  std::string fname = FileSystem::strip_extension(basedir + name)+".jpg";
+  if (!PHYSFS_exists(fname.c_str())) {
+       return 0;
+  }
+  picture = new Surface(fname);
+  return picture;
+}
+
 }
index ce59cd2..d8a48e9 100644 (file)
@@ -25,6 +25,7 @@
 #include "math/vector.hpp"
 #include "game_object.hpp"
 #include "statistics.hpp"
+#include "video/surface.hpp"
 
 class Sprite;
 
@@ -55,6 +56,15 @@ public:
 
   /** If false, disables the auto walking after finishing a level */
   bool auto_path;
+
+  /** return Surface of level picture or 0 if no picture is available */
+  const Surface* get_picture();
+
+private:
+  std::string basedir;
+  bool picture_cached;
+  Surface* picture;
+
 };
 
 }
index 8ae1a65..a8cd5e4 100644 (file)
@@ -628,6 +628,19 @@ WorldMap::draw_status(DrawingContext& context)
               SCREEN_HEIGHT - white_text->get_height() - 30),
             CENTER_ALLIGN, LAYER_FOREGROUND1);
         
+        // if level is solved, draw level picture behind stats
+        /*
+        if (level->solved) {
+          if (const Surface* picture = level->get_picture()) {
+            Vector pos = Vector(SCREEN_WIDTH - picture->get_width(), SCREEN_HEIGHT - picture->get_height());
+            context.push_transform();
+            context.set_alpha(0.5);
+            context.draw_surface(picture, pos, LAYER_FOREGROUND1-1);
+            context.pop_transform();
+          }
+        }
+        */
+        
         level->statistics.draw_worldmap_info(context);
         break;
       }