From: Christoph Sommer Date: Tue, 25 Jul 2006 00:30:30 +0000 (+0000) Subject: In-game HUD now uses icons instead of text / X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=249ccffa03ded6f1ba06cce346f91d96d8ce3ed5;p=supertux.git In-game HUD now uses icons instead of text / Number of coins smoothly "counts" up- and downward SVN-Revision: 4085 --- diff --git a/data/images/engine/hud/coins-0.png b/data/images/engine/hud/coins-0.png new file mode 100644 index 000000000..9ab0b4a56 Binary files /dev/null and b/data/images/engine/hud/coins-0.png differ diff --git a/data/images/engine/hud/time-0.png b/data/images/engine/hud/time-0.png new file mode 100644 index 000000000..69ef34dfe Binary files /dev/null and b/data/images/engine/hud/time-0.png differ diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index 29419292f..591176344 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -42,6 +42,7 @@ LevelTime::LevelTime(const lisp::Lisp& reader) { reader.get("time", time_left); if(time_left <= 0) throw std::runtime_error("No or invalid leveltime specified"); + time_surface.reset(new Surface("images/engine/hud/time-0.png")); } void @@ -65,13 +66,14 @@ LevelTime::draw(DrawingContext& context) if ((time_left > TIME_WARNING) || (int(game_time * 2.5) % 2)) { std::stringstream ss; ss << int(time_left); - std::string time = ss.str(); + std::string time_text = ss.str(); - float caption_width = white_text->get_text_width(_("TIME")) + white_text->get_text_width(" "); - float all_width = caption_width + white_text->get_text_width(time); - - context.draw_text(white_text, _("TIME"), Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_text(gold_text, time, Vector((SCREEN_WIDTH - all_width)/2 + caption_width, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1); + Surface* time_surf = time_surface.get(); + if (time_surf) { + float all_width = time_surf->get_width() + white_text->get_text_width(time_text); + context.draw_surface(time_surf, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1); + context.draw_text(gold_text, time_text, Vector((SCREEN_WIDTH - all_width)/2 + time_surf->get_width(), BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1); + } } context.pop_transform(); diff --git a/src/object/level_time.hpp b/src/object/level_time.hpp index 335f87806..b96709adc 100644 --- a/src/object/level_time.hpp +++ b/src/object/level_time.hpp @@ -20,9 +20,11 @@ #ifndef __LEVELTIME_H__ #define __LEVELTIME_H__ +#include #include "game_object.hpp" #include "timer.hpp" #include "lisp/lisp.hpp" +#include "video/surface.hpp" class LevelTime : public GameObject { @@ -34,6 +36,7 @@ public: void stop(); private: + std::auto_ptr time_surface; bool running; float time_left; }; diff --git a/src/player_status.cpp b/src/player_status.cpp index ee8647701..f638bca92 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -46,7 +46,7 @@ PlayerStatus::PlayerStatus() { reset(); - tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite")); + coin_surface.reset(new Surface("images/engine/hud/coins-0.png")); Console::instance->registerCommand("coins", this); } @@ -132,16 +132,29 @@ PlayerStatus::read(const lisp::Lisp& lisp) void PlayerStatus::draw(DrawingContext& context) { + static int displayed_coins = -1; + static int next_count = 0; + + if (displayed_coins == -1) displayed_coins = coins; + if (++next_count > 2) { + next_count = 0; + if (displayed_coins < coins) displayed_coins++; + if (displayed_coins > coins) displayed_coins--; + } + displayed_coins = std::min(std::max(displayed_coins, 0), 9999); + + std::stringstream ss; + ss << displayed_coins; + std::string coins_text = ss.str(); + context.push_transform(); context.set_translation(Vector(0, 0)); - char str[60]; - - int displayCoins = std::max(player_status->coins, 0); - snprintf(str, sizeof(str), "%d", displayCoins); - const char* coinstext = _("COINS"); - context.draw_text(white_text, coinstext, Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1); + Surface* coin_surf = coin_surface.get(); + if (coin_surf) { + context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - gold_text->get_text_width(coins_text), BORDER_Y + 1), LAYER_FOREGROUND1); + } + context.draw_text(gold_text, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1); context.pop_transform(); } diff --git a/src/player_status.hpp b/src/player_status.hpp index 155972524..bf5cc272d 100644 --- a/src/player_status.hpp +++ b/src/player_status.hpp @@ -27,6 +27,7 @@ #include "serializable.hpp" #include "sprite/sprite.hpp" #include "console.hpp" +#include "video/surface.hpp" static const float BORDER_X = 10; static const float BORDER_Y = 10; @@ -69,7 +70,7 @@ private: // don't use this PlayerStatus(const PlayerStatus& other); - std::auto_ptr tux_life; + std::auto_ptr coin_surface; }; // global player state