Skip to content

Commit

Permalink
Race Result GUI improvements
Browse files Browse the repository at this point in the history
- Consolidate duplicated per-team code in the CTF player score drawing
- Don't assume the value of the extra wait time after race results have been displayed
- Tweak timings for the GP UI, in particular increase the duration of points transfer from new to total from 1.0s to 2.0s
- Use a lambda for a minor code quality improvement
  • Loading branch information
Alayan-stk-2 committed Dec 30, 2024
1 parent 6a9dbc2 commit 05f3452
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 73 deletions.
130 changes: 57 additions & 73 deletions src/states_screens/race_result_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ void RaceResultGUI::enableAllButtons()
operations->setActive(true);
operations->setFocusForPlayer(PLAYER_ID_GAME_MASTER);

auto makeContinueButton
{
[](GUIEngine::IconButtonWidget *button)
{
button->setLabel(_("Continue"));
button->setImage("gui/icons/green_check.png");
}
};

if (RaceManager::get()->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX)
{
enableGPProgress();
Expand All @@ -260,8 +269,7 @@ void RaceResultGUI::enableAllButtons()
// If we're in a network world, change the buttons text
if (World::getWorld()->isNetworkWorld())
{
right->setLabel(_("Continue"));
right->setImage("gui/icons/green_check.png");
makeContinueButton(right);
right->setVisible(true);
operations->select("right", PLAYER_ID_GAME_MASTER);
middle->setVisible(false);
Expand All @@ -283,25 +291,22 @@ void RaceResultGUI::enableAllButtons()
(RaceManager::get()->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX ||
RaceManager::get()->getTrackNumber() + 1 == RaceManager::get()->getNumOfTracks() ) )
{
middle->setLabel(_("Continue"));
middle->setImage("gui/icons/green_check.png");
makeContinueButton(middle);
middle->setVisible(true);
operations->select("middle", PLAYER_ID_GAME_MASTER);
}
else if (RaceManager::get()->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX)
{
// In case of a GP:
// ----------------
middle->setLabel(_("Continue"));
middle->setImage("gui/icons/green_check.png");
makeContinueButton(middle);
middle->setVisible(false);
middle->setFocusable(false);
left->setVisible(false);
left->setFocusable(false);

// Two continue buttons to make sure the buttons in the bar is balanced
right->setLabel(_("Continue"));
right->setImage("gui/icons/green_check.png");
makeContinueButton(right);
right->setVisible(true);

if (RaceManager::get()->getTrackNumber() + 1 < RaceManager::get()->getNumOfTracks())
Expand Down Expand Up @@ -652,7 +657,6 @@ void RaceResultGUI::displayCTFResults()
//Draw win text
core::stringw result_text;
video::SColor color = video::SColor(255, 255, 255, 255);
video::SColor red_color = video::SColor(255, 255, 0, 0);
gui::IGUIFont* font = GUIEngine::getTitleFont();
int team_icon_height = font->getDimension(L"A").Height;
int current_x = UserConfigParams::m_width / 2;
Expand Down Expand Up @@ -718,18 +722,44 @@ void RaceResultGUI::displayCTFResults()

// The red team player scores:
current_y += rect.Height / 2 + rect.Height / 4;
font = GUIEngine::getSmallFont();
drawCTFScorers(KART_TEAM_RED, current_x, current_y, height);
current_x += UserConfigParams::m_width / 2;
drawCTFScorers(KART_TEAM_BLUE, current_x, current_y, height);
#endif
} // displayCTFResults

//-----------------------------------------------------------------------------
/** Displays the CTF scorers for a team
* \param team The team for which to draw the scorers
* \param x Left limit of the scorers lists (both blue and red)
* \param y Top limit of the scorers lists
* \param height Maximum y of the table area (??) */
void RaceResultGUI::drawCTFScorers(KartTeam team, int x, int y, int height)
{
#ifndef SERVER_ONLY
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>(World::getWorld());
gui::IGUIFont* font = GUIEngine::getSmallFont();
irr::video::ITexture* kart_icon;

int prev_y = current_y;
core::stringw result_text;
video::SColor color = video::SColor(255, 255, 255, 255);
video::SColor red_color = video::SColor(255, 255, 0, 0);

int current_x = x;
int current_y = y;
core::dimension2du rect;
core::rect<s32> pos(current_x, current_y, current_x, current_y);

const unsigned num_karts = ctf->getNumKarts();
for (unsigned int i = 0; i < num_karts; i++)
{
AbstractKart* kart = ctf->getKartAtPosition(i + 1);
unsigned kart_id = kart->getWorldKartId();
if (ctf->getKartTeam(kart_id) != KART_TEAM_RED)
if (ctf->getKartTeam(kart_id) != team)
continue;
result_text = kart->getController()->getName();

// add the country flag if available
if (RaceManager::get()->getKartGlobalPlayerId(kart_id) > -1)
{
const core::stringw& flag = StringUtils::getCountryFlag(
Expand All @@ -747,9 +777,9 @@ void RaceResultGUI::displayCTFResults()
}
else
{
result_text.append(
StringUtils::toWString(ctf->getKartScore(kart_id)));
result_text.append(StringUtils::toWString(ctf->getKartScore(kart_id)));
}

rect = font->getDimension(result_text.c_str());
current_y += rect.Height;

Expand All @@ -760,63 +790,15 @@ void RaceResultGUI::displayCTFResults()
kart->getController()->isLocalPlayerController() ?
red_color : color, true, false);
kart_icon = kart->getKartProperties()->getIconMaterial()->getTexture();
source_rect = core::recti(core::vector2di(0, 0), kart_icon->getSize());
core::recti source_rect = core::recti(core::vector2di(0, 0), kart_icon->getSize());
irr::u32 offset_x =
(irr::u32)(font->getDimension(result_text.c_str()).Width / 1.5f);
dest_rect = core::recti(current_x - offset_x - m_width_icon, current_y,
current_x - offset_x, current_y + m_width_icon);
draw2DImage(kart_icon, dest_rect, source_rect, NULL, NULL, true);
}

// The blue team player scores:
current_y = prev_y;
current_x += UserConfigParams::m_width / 2;
for (unsigned int i = 0; i < num_karts; i++)
{
AbstractKart* kart = ctf->getKartAtPosition(i + 1);
unsigned kart_id = kart->getWorldKartId();
if (ctf->getKartTeam(kart_id) != KART_TEAM_BLUE)
continue;
result_text = kart->getController()->getName();
if (RaceManager::get()->getKartGlobalPlayerId(kart_id) > -1)
{
const core::stringw& flag = StringUtils::getCountryFlag(
RaceManager::get()->getKartInfo(kart_id).getCountryCode());
if (!flag.empty())
{
result_text += L" ";
result_text += flag;
}
}
result_text.append(" ");
if (kart->isEliminated())
{
continue;
}
else
{
result_text.append(
StringUtils::toWString(ctf->getKartScore(kart_id)));
}
rect = font->getDimension(result_text.c_str());
current_y += rect.Height;

if (current_y > height) break;

pos = core::rect<s32>(current_x, current_y, current_x, current_y);
font->draw(result_text, pos,
kart->getController()->isLocalPlayerController() ?
red_color : color, true, false);
kart_icon = kart->getKartProperties()->getIconMaterial()->getTexture();
source_rect = core::recti(core::vector2di(0, 0), kart_icon->getSize());
irr::u32 offset_x = (irr::u32)
(font->getDimension(result_text.c_str()).Width / 1.5f);
dest_rect = core::recti(current_x - offset_x - m_width_icon, current_y,
core::recti dest_rect = core::recti(current_x - offset_x - m_width_icon, current_y,
current_x - offset_x, current_y + m_width_icon);
draw2DImage(kart_icon, dest_rect, source_rect, NULL, NULL, true);
}
#endif
} // displayCTFResults
} // drawCTFScorers

//-----------------------------------------------------------------------------
void RaceResultGUI::unload()
Expand Down Expand Up @@ -982,11 +964,12 @@ void RaceResultGUI::determineTableLayout()
// The time the first phase is being displayed: add the start time
// of the last kart to the duration of the scroll plus some time
// of rest before the next phase starts
m_extra_scroll_time = 1.0f;
m_time_overall_scroll = (num_karts - 1)*m_time_between_rows
+ m_time_single_scroll + 2.0f;
+ m_time_single_scroll + m_extra_scroll_time;

// The time to increase the number of points.
m_time_for_points = 1.0f;
m_time_for_points = 2.0f;

// Determine text height
r = m_font->getDimension(L"Y");
Expand Down Expand Up @@ -1121,6 +1104,9 @@ void RaceResultGUI::renderGlobal(float dt)
assert(World::getWorld()->getPhase() == WorldStatus::RESULT_DISPLAY_PHASE);
unsigned int num_karts = (unsigned int)m_all_row_infos.size();
float time_overall_scroll = m_time_overall_scroll;
// TODO after 1.5: Avoid the point increase being too slow for low point amounts
// float time_for_points = std::min(0.3f + 0.2f*m_most_points, m_time_for_points);
float time_for_points = m_time_for_points;

// First: Update the finite state machine
// ======================================
Expand All @@ -1140,7 +1126,7 @@ void RaceResultGUI::renderGlobal(float dt)
// GP mode has a continue button so no extra time is needed
if (RaceManager::get()->getMajorMode() ==
RaceManager::MAJOR_MODE_GRAND_PRIX)
time_overall_scroll -= 2.0f;
time_overall_scroll -= m_extra_scroll_time;
if (m_timer > time_overall_scroll)
{
// Make sure that all lines are aligned to the left
Expand Down Expand Up @@ -1189,7 +1175,7 @@ void RaceResultGUI::renderGlobal(float dt)
break;
case RR_INCREASE_POINTS:
// Have one second delay before the resorting starts.
if (m_timer > 1 + m_time_for_points)
if (m_timer > 1 + time_for_points)
{
m_animation_state = RR_RESORT_TABLE;
if (m_gp_position_was_changed)
Expand Down Expand Up @@ -1286,15 +1272,13 @@ void RaceResultGUI::renderGlobal(float dt)
{
WorldWithRank *wwr = dynamic_cast<WorldWithRank*>(World::getWorld());
assert(wwr);
ri->m_current_displayed_points +=
dt * m_most_points / m_time_for_points;
ri->m_current_displayed_points += dt * m_most_points / time_for_points;
if (ri->m_current_displayed_points > ri->m_new_overall_points)
{
ri->m_current_displayed_points =
(float)ri->m_new_overall_points;
}
ri->m_new_points -=
dt * m_most_points / m_time_for_points;
ri->m_new_points -= dt * m_most_points / time_for_points;
if (ri->m_new_points < 0)
ri->m_new_points = 0;
break;
Expand Down
4 changes: 4 additions & 0 deletions src/states_screens/race_result_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class RaceResultGUI : public RaceGUIBase,
This includes a small waiting time at the end. */
float m_time_overall_scroll;

/** The small waiting time for the above. */
float m_extra_scroll_time;

/** Distance between each row of the race results */
unsigned int m_distance_between_rows;

Expand Down Expand Up @@ -213,6 +216,7 @@ class RaceResultGUI : public RaceGUIBase,
int displayLapDifficulty(int x, int y, bool increase_density);
int displayChallengeInfo(int x, int y, bool increase_density);
void displayCTFResults();
void drawCTFScorers(KartTeam team, int x, int y, int height);
void displaySoccerResults();
void drawTeamScorers(KartTeam team, int x, int y, int height);
void displayBenchmarkSummary();
Expand Down

0 comments on commit 05f3452

Please sign in to comment.