Skip to content

Commit

Permalink
Properly draw powerup stack HUD in multiplayer
Browse files Browse the repository at this point in the history
`PlayerStatusHUD` now properly draws powerup stack counts for multiple players, instead of stacking them in one place on the screen. Also adds an indication as to which player a powerup stack count refers to.

Additionally cleans up `PlayerStatusHUD` draw code.

Fixes #2714.
  • Loading branch information
Vankata453 committed Dec 28, 2023
1 parent 4dc16f6 commit ef111b4
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions src/supertux/player_status_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include "supertux/player_status_hud.hpp"

#include <sstream>

#include "supertux/game_object.hpp"
#include "supertux/player_status.hpp"
#include "supertux/resources.hpp"
Expand Down Expand Up @@ -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));
Expand All @@ -92,52 +88,60 @@ PlayerStatusHUD::draw(DrawingContext& context)
LAYER_HUD,
PlayerStatusHUD::text_color);
}
std::string ammo_text;

hudpos += static_cast<float>(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<float>(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<float>(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<float>(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<float>(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<float>(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<float>(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<float>(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();
Expand Down

0 comments on commit ef111b4

Please sign in to comment.