diff --git a/src/supertux/player_status_hud.cpp b/src/supertux/player_status_hud.cpp index 2666a095eca..e9f7e4c2018 100644 --- a/src/supertux/player_status_hud.cpp +++ b/src/supertux/player_status_hud.cpp @@ -16,8 +16,6 @@ #include "supertux/player_status_hud.hpp" -#include - #include "supertux/game_object.hpp" #include "supertux/player_status.hpp" #include "supertux/resources.hpp" @@ -67,9 +65,7 @@ PlayerStatusHUD::draw(DrawingContext& context) displayed_coins = std::min(std::max(displayed_coins, 0), m_player_status.get_max_coins()); float hudpos = BORDER_Y + 1.0f; - std::ostringstream ss; - ss << displayed_coins; - std::string coins_text = ss.str(); + const std::string coins_text = std::to_string(displayed_coins); context.push_transform(); context.set_translation(Vector(0, 0)); @@ -92,52 +88,60 @@ PlayerStatusHUD::draw(DrawingContext& context) LAYER_HUD, PlayerStatusHUD::text_color); } - std::string ammo_text; - hudpos += static_cast(fire_surface->get_height()) + 3.0f; + hudpos += 8.f; for (int target = 0; target < InputManager::current()->get_num_users(); target++) { - if (m_player_status.bonus[target] == FIRE_BONUS) { + SurfacePtr surface; + std::string ammo_text; + if (m_player_status.bonus[target] == FIRE_BONUS) + { + surface = fire_surface; ammo_text = std::to_string(m_player_status.max_fire_bullets[target]); - - if (fire_surface) - { - context.color().draw_surface(fire_surface, - Vector(context.get_width() - BORDER_X - static_cast(fire_surface->get_width()) - Resources::fixed_font->get_text_width(ammo_text), - hudpos), - LAYER_HUD); - } - - context.color().draw_text(Resources::fixed_font, - ammo_text, - Vector(static_cast(context.get_width()) - BORDER_X - Resources::fixed_font->get_text_width(ammo_text), - hudpos + 13.f), - ALIGN_LEFT, - LAYER_HUD, - PlayerStatusHUD::text_color); + } + else if (m_player_status.bonus[target] == ICE_BONUS) + { + surface = ice_surface; + ammo_text = std::to_string(m_player_status.max_ice_bullets[target]); + } + else + { + continue; } - if (m_player_status.bonus[target] == ICE_BONUS) { + hudpos += static_cast(surface->get_height()); - ammo_text = std::to_string(m_player_status.max_ice_bullets[target]); + const float ammo_text_width = Resources::fixed_font->get_text_width(ammo_text); - if (ice_surface) - { - context.color().draw_surface(ice_surface, - Vector(context.get_width() - BORDER_X - static_cast(ice_surface->get_width()) - Resources::fixed_font->get_text_width(ammo_text), - hudpos), - LAYER_HUD); - } + if (InputManager::current()->get_num_users() > 1) + { + const std::string player_text = std::to_string(target + 1) + ":"; context.color().draw_text(Resources::fixed_font, - ammo_text, - Vector(static_cast(context.get_width()) - BORDER_X - Resources::fixed_font->get_text_width(ammo_text), + player_text, + Vector(context.get_width() - BORDER_X - ammo_text_width - + static_cast(surface->get_width()) - + Resources::fixed_font->get_text_width(player_text) - 3.f, hudpos + 13.f), ALIGN_LEFT, LAYER_HUD, PlayerStatusHUD::text_color); } + + context.color().draw_surface(surface, + Vector(context.get_width() - BORDER_X - ammo_text_width - + static_cast(surface->get_width()), + hudpos), + LAYER_HUD); + + context.color().draw_text(Resources::fixed_font, + ammo_text, + Vector(context.get_width() - BORDER_X - ammo_text_width, + hudpos + 13.f), + ALIGN_LEFT, + LAYER_HUD, + PlayerStatusHUD::text_color); } context.pop_transform();