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;
{
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"
#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)
// 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)
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();
}
#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);
LevelTile::~LevelTile()
{
+ delete picture;
}
void
{
}
+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;
+}
+
}
#include "math/vector.hpp"
#include "game_object.hpp"
#include "statistics.hpp"
+#include "video/surface.hpp"
class Sprite;
/** 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;
+
};
}
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;
}