From ef146ea92ea53c84903cc5ba624520fb7b288522 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sat, 17 Jun 2006 11:38:43 +0000 Subject: [PATCH] Added (inactive) code to show level pictures on worldmap SVN-Revision: 3670 --- src/file_system.cpp | 9 +++++++++ src/file_system.hpp | 6 ++++++ src/statistics.cpp | 21 ++++++++++++++++----- src/worldmap/level.cpp | 18 +++++++++++++++++- src/worldmap/level.hpp | 10 ++++++++++ src/worldmap/worldmap.cpp | 13 +++++++++++++ 6 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/file_system.cpp b/src/file_system.cpp index e5721dc8e..cb8f426d9 100644 --- a/src/file_system.cpp +++ b/src/file_system.cpp @@ -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 path_stack; diff --git a/src/file_system.hpp b/src/file_system.hpp index 306fbc9c6..9c14bac0a 100644 --- a/src/file_system.hpp +++ b/src/file_system.hpp @@ -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" diff --git a/src/statistics.cpp b/src/statistics.cpp index 731dc4d3f..5a9cc64b0 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -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(); } diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index 51f2a81b3..fbc6b0bdb 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -25,12 +25,14 @@ #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; +} + } diff --git a/src/worldmap/level.hpp b/src/worldmap/level.hpp index ce59cd277..d8a48e92f 100644 --- a/src/worldmap/level.hpp +++ b/src/worldmap/level.hpp @@ -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; + }; } diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 8ae1a65a3..a8cd5e4a3 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -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; } -- 2.11.0