Fix order of ghost replay difficulties depending on race result

This commit is contained in:
Benau 2021-12-23 00:47:57 +08:00
parent c09305b236
commit 7dc8f3e958
4 changed files with 27 additions and 13 deletions

View File

@ -32,11 +32,13 @@
#include "LinearMath/btQuaternion.h"
GhostKart::GhostKart(const std::string& ident, unsigned int world_kart_id,
int position, float color_hue)
int position, float color_hue,
const ReplayPlay::ReplayData& rd)
: Kart(ident, world_kart_id,
position, btTransform(btQuaternion(0, 0, 0, 1)),
HANDICAP_NONE,
std::make_shared<RenderInfo>(color_hue, true/*transparent*/))
std::make_shared<RenderInfo>(color_hue, true/*transparent*/)),
m_replay_data(rd)
{
} // GhostKart

View File

@ -20,7 +20,7 @@
#define HEADER_GHOST_KART_HPP
#include "karts/kart.hpp"
#include "replay/replay_base.hpp"
#include "replay/replay_play.hpp"
#include "utils/cpp2011.hpp"
#include "LinearMath/btTransform.h"
@ -46,6 +46,8 @@ private:
std::vector<ReplayBase::KartReplayEvent> m_all_replay_events;
ReplayPlay::ReplayData m_replay_data;
unsigned int m_last_egg_idx = 0;
// ----------------------------------------------------------------------------
@ -54,7 +56,8 @@ private:
public:
GhostKart(const std::string& ident, unsigned int world_kart_id,
int position, float color_hue);
int position, float color_hue,
const ReplayPlay::ReplayData& rd);
virtual void update(int ticks) OVERRIDE;
virtual void updateGraphics(float dt) OVERRIDE;
virtual void reset() OVERRIDE;
@ -101,6 +104,9 @@ public:
virtual void kartIsInRestNow() OVERRIDE {}
// ------------------------------------------------------------------------
virtual void makeKartRest() OVERRIDE {}
// ------------------------------------------------------------------------
const ReplayPlay::ReplayData& getReplayData() const
{ return m_replay_data; }
}; // GhostKart
#endif

View File

@ -382,7 +382,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line, bool second_replay)
ReplayData &rd = m_replay_file_list[replay_index];
m_ghost_karts.push_back(std::make_shared<GhostKart>
(rd.m_kart_list.at(kart_num-first_loaded_f_num), kart_num, kart_num + 1,
rd.m_kart_color.at(kart_num-first_loaded_f_num)));
rd.m_kart_color.at(kart_num-first_loaded_f_num), rd));
m_ghost_karts[kart_num]->init(RaceManager::KT_GHOST);
Controller* controller = new GhostController(getGhostKart(kart_num).get(),
rd.m_name_list[kart_num-first_loaded_f_num]);

View File

@ -39,10 +39,10 @@
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/controller/end_controller.hpp"
#include "karts/controller/local_player_controller.hpp"
#include "karts/ghost_kart.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/cutscene_world.hpp"
@ -1964,14 +1964,20 @@ void RaceResultGUI::unload()
core::stringw difficulty_two;
if (RaceManager::get()->hasGhostKarts() && ReplayPlay::get()->isSecondReplayEnabled())
{
unsigned idw = ReplayPlay::get()->getCurrentReplayFileIndex();
unsigned idx = ReplayPlay::get()->getSecondReplayFileIndex();
const ReplayPlay::ReplayData& rd1 = ReplayPlay::get()->getReplayData(idw);
const ReplayPlay::ReplayData& rd2 = ReplayPlay::get()->getReplayData(idx);
difficulty_one = RaceManager::get()->getDifficultyName((RaceManager::Difficulty)rd1.m_difficulty);
difficulty_two = RaceManager::get()->getDifficultyName((RaceManager::Difficulty)rd2.m_difficulty);
WorldWithRank* wwr = dynamic_cast<WorldWithRank*>(World::getWorld());
for (unsigned k = 0; k < wwr->getNumKarts(); k++)
{
GhostKart* gk = dynamic_cast<GhostKart*>(wwr->getKartAtPosition(k + 1));
if (!gk)
continue;
const ReplayPlay::ReplayData& rd = gk->getReplayData();
if (difficulty_one.empty())
difficulty_one = RaceManager::get()->getDifficultyName((RaceManager::Difficulty)rd.m_difficulty);
else if (difficulty_two.empty())
difficulty_two = RaceManager::get()->getDifficultyName((RaceManager::Difficulty)rd.m_difficulty);
}
if (difficulty_one != difficulty_two)
difficulty_name = difficulty_one +" / "+ difficulty_two;
difficulty_name = difficulty_one + L" / " + difficulty_two;
else
difficulty_name = difficulty_one;
}