Show (online) player name in race GUI

This commit is contained in:
Benau
2018-04-15 16:17:43 +08:00
parent d6af63da67
commit d30faece9c
6 changed files with 32 additions and 4 deletions

View File

@@ -383,3 +383,11 @@ bool LocalPlayerController::canGetAchievements() const
{
return m_player->getConstProfile() == PlayerManager::getCurrentPlayer();
} // canGetAchievements
// ----------------------------------------------------------------------------
core::stringw LocalPlayerController::getName() const
{
if (NetworkConfig::get()->isNetworking())
return PlayerController::getName();
return m_player->getProfile()->getName();
} // getName

View File

@@ -78,7 +78,7 @@ public:
virtual bool isLocalPlayerController() const OVERRIDE {return true;}
// ------------------------------------------------------------------------
/** Returns the name of the player profile. */
core::stringw getName() const OVERRIDE { return m_player->getProfile()->getName(); }
core::stringw getName() const OVERRIDE;
}; // LocalPlayerController

View File

@@ -29,6 +29,10 @@
#include "karts/skidding.hpp"
#include "karts/rescue_animation.hpp"
#include "modes/world.hpp"
#include "network/game_setup.hpp"
#include "network/network_config.hpp"
#include "network/network_player_profile.hpp"
#include "network/protocols/lobby_protocol.hpp"
#include "race/history.hpp"
#include "states_screens/race_gui_base.hpp"
#include "utils/constants.hpp"
@@ -384,4 +388,17 @@ void PlayerController::rewindTo(BareNetworkString *buffer)
m_steer_val = buffer->getUInt32();
m_steer_val_l = buffer->getUInt32();
m_steer_val_r = buffer->getUInt32();
} // rewindTo
} // rewindTo
// ----------------------------------------------------------------------------
core::stringw PlayerController::getName() const
{
if (NetworkConfig::get()->isNetworking())
{
auto& players = LobbyProtocol::get<LobbyProtocol>()->getGameSetup()
->getPlayers();
if (auto player = players.at(m_kart->getWorldKartId()).lock())
return player->getName();
}
return m_kart->getName();
} // getName

View File

@@ -93,6 +93,9 @@ public:
virtual void finishedRace(float time) OVERRIDE
{
} // finishedRace
// ------------------------------------------------------------------------
/** Returns the name of the player profile. */
core::stringw getName() const OVERRIDE;
}; // class PlayerController

View File

@@ -385,7 +385,7 @@ void LinearWorld::newLap(unsigned int kart_index)
// Store the temporary string because clang would mess this up
// (remove the stringw before the wchar_t* is used).
const core::stringw &kart_name = kart->getName();
const core::stringw &kart_name = kart->getController()->getName();
//I18N: as in "fastest lap: 60 seconds by Wilber"
irr::core::stringw m_fastest_lap_message =

View File

@@ -1214,7 +1214,7 @@ void World::eliminateKart(int kart_id, bool notify_of_elimination)
{
// Store the temporary string because clang would mess this up
// (remove the stringw before the wchar_t* is used).
const core::stringw &kart_name = kart->getName();
const core::stringw &kart_name = kart->getController()->getName();
m_race_gui->addMessage(_("'%s' has been eliminated.",
kart_name),
camera->getKart(),