Don't create race gui for no graphics

This commit is contained in:
Benau
2020-02-14 13:23:32 +08:00
parent cf83e4c86c
commit 0912ca041b
8 changed files with 48 additions and 35 deletions

View File

@@ -211,9 +211,9 @@ bool LocalPlayerController::action(PlayerAction action, int value,
*/
void LocalPlayerController::steer(int ticks, int steer_val)
{
if(UserConfigParams::m_gamepad_debug)
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
if (gui_base && UserConfigParams::m_gamepad_debug)
{
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
gui_base->clearAllMessages();
gui_base->addMessage(StringUtils::insertValues(L"steer_val %i", steer_val),
m_kart, 1.0f,

View File

@@ -143,16 +143,18 @@ void SpareTireAI::crashed(const AbstractKart *k)
if (dynamic_cast<const SpareTireAI*>(k->getController()) != NULL) return;
// Tell players that they can have at most 3 lives
RaceGUIBase* r = World::getWorld()->getRaceGUI();
if (m_tsb_world->getKartLife(k->getWorldKartId()) == 3)
{
World::getWorld()->getRaceGUI()->addMessage
(_("You can have at most 3 lives!"), k, 2.0f);
if (r)
r->addMessage(_("You can have at most 3 lives!"), k, 2.0f);
}
// Otherwise add one life for that kart
else
{
m_tsb_world->addKartLife(k->getWorldKartId());
World::getWorld()->getRaceGUI()->addMessage(_("+1 life."), k, 2.0f);
if (r)
r->addMessage(_("+1 life."), k, 2.0f);
}
unspawn();

View File

@@ -204,7 +204,7 @@ void CaptureTheFlag::updateGraphics(float dt)
}
m_blue_flag_status = m_blue_flag->getStatus();
}
if (!msg.empty())
if (m_race_gui && !msg.empty())
m_race_gui->addMessage(msg, NULL, 1.5f);
#endif
} // updateGraphics
@@ -418,7 +418,8 @@ void CaptureTheFlag::ctfScored(int kart_id, bool red_team_scored,
// Don't set animation and show message if receiving in live join
if (isStartPhase())
return;
m_race_gui->addMessage(scored_msg, NULL, 3.0f);
if (m_race_gui)
m_race_gui->addMessage(scored_msg, NULL, 3.0f);
kart->getKartModel()
->setAnimation(KartModel::AF_WIN_START, true/*play_non_loop*/);
m_scored_sound->play();

View File

@@ -413,7 +413,7 @@ void LinearWorld::newLap(unsigned int kart_index)
// Last lap message (kart_index's assert in previous block already)
if (raceHasLaps() && kart_info.m_finished_laps+1 == lap_count)
{
if (lap_count > 1 && !isLiveJoinWorld())
if (lap_count > 1 && !isLiveJoinWorld() && m_race_gui)
{
m_race_gui->addMessage(_("Final lap!"), kart,
3.0f, GUIEngine::getSkin()->getColor("font::normal"), true,
@@ -442,7 +442,7 @@ void LinearWorld::newLap(unsigned int kart_index)
}
}
else if (raceHasLaps() && kart_info.m_finished_laps > 0 &&
kart_info.m_finished_laps+1 < lap_count && !isLiveJoinWorld())
kart_info.m_finished_laps+1 < lap_count && !isLiveJoinWorld() && m_race_gui)
{
m_race_gui->addMessage(_("Lap %i", kart_info.m_finished_laps+1), kart,
2.0f, GUIEngine::getSkin()->getColor("font::normal"), true,
@@ -540,12 +540,13 @@ void LinearWorld::newLap(unsigned int kart_index)
irr::core::stringw m_fastest_lap_message =
_C("fastest_lap", "%s by %s", s.c_str(), kart_name);
m_race_gui->addMessage(m_fastest_lap_message, NULL,
4.0f, video::SColor(255, 255, 255, 255), false);
m_race_gui->addMessage(_("New fastest lap"), NULL,
4.0f, video::SColor(255, 255, 255, 255), false);
if (m_race_gui)
{
m_race_gui->addMessage(m_fastest_lap_message, NULL, 4.0f,
video::SColor(255, 255, 255, 255), false);
m_race_gui->addMessage(_("New fastest lap"), NULL, 4.0f,
video::SColor(255, 255, 255, 255), false);
}
} // end if new fastest lap
kart_info.m_lap_start_ticks = getTimeTicks();
@@ -1083,7 +1084,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
if (kart->getKartAnimation())
ki.m_wrong_way_timer = 0;
if (ki.m_wrong_way_timer > 1.0f)
if (ki.m_wrong_way_timer > 1.0f && m_race_gui)
{
m_race_gui->addMessage(_("WRONG WAY!"), kart,
/* time */ -1.0f,

View File

@@ -638,9 +638,12 @@ void ThreeStrikesBattle::spawnSpareTireKarts()
unsigned int spawn_sta = unsigned(ratio);
if (spawn_sta > m_spare_tire_karts.size())
spawn_sta = (int)m_spare_tire_karts.size();
m_race_gui->addMessage(_P("%i spare tire kart has been spawned!",
"%i spare tire karts have been spawned!",
spawn_sta), NULL, 2.0f);
if (m_race_gui)
{
m_race_gui->addMessage(_P("%i spare tire kart has been spawned!",
"%i spare tire karts have been spawned!",
spawn_sta), NULL, 2.0f);
}
for (unsigned int i = 0; i < spawn_sta; i++)
{
SpareTireAI* sta = dynamic_cast<SpareTireAI*>

View File

@@ -252,7 +252,8 @@ void World::init()
loadCustomModels();
main_loop->renderGUI(7100);
// Must be called after all karts are created
m_race_gui->init();
if (m_race_gui)
m_race_gui->init();
powerup_manager->computeWeightsForRace(race_manager->getNumberOfKarts());
main_loop->renderGUI(7200);
@@ -387,7 +388,8 @@ void World::reset(bool restart)
Track::getCurrentTrack()->reset();
// Reset the race gui.
m_race_gui->reset();
if (m_race_gui)
m_race_gui->reset();
// Start music from beginning
music_manager->stopMusic();
@@ -414,7 +416,8 @@ void World::reset(bool restart)
void World::createRaceGUI()
{
m_race_gui = new RaceGUI();
if (!ProfileWorld::isNoGraphics())
m_race_gui = new RaceGUI();
}
//-----------------------------------------------------------------------------
@@ -725,19 +728,17 @@ void World::terminateRace()
assert(m_saved_race_gui==NULL);
m_saved_race_gui = m_race_gui;
RaceResultGUI* results = RaceResultGUI::getInstance();
m_race_gui = results;
if (best_highscore_rank > 0)
if (!ProfileWorld::isNoGraphics())
{
results->setHighscore(best_highscore_rank);
}
else
{
results->clearHighscores();
RaceResultGUI* results = RaceResultGUI::getInstance();
m_race_gui = results;
if (best_highscore_rank > 0)
results->setHighscore(best_highscore_rank);
else
results->clearHighscores();
results->push();
}
results->push();
WorldStatus::terminateRace();
} // terminateRace
@@ -1314,7 +1315,7 @@ void World::eliminateKart(int kart_id, bool notify_of_elimination)
if (kart->isGhostKart()) return;
// Display a message about the eliminated kart in the race gui
if (notify_of_elimination)
if (m_race_gui && notify_of_elimination)
{
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
{

View File

@@ -146,16 +146,18 @@ namespace Scripting
void clearOverlayMessages()
{
World::getWorld()->getRaceGUI()->clearAllMessages();
if (World::getWorld()->getRaceGUI())
World::getWorld()->getRaceGUI()->clearAllMessages();
}
/** Display text in the center of the screen for a few seconds */
void displayOverlayMessage(std::string* input)
{
if (!World::getWorld()->getRaceGUI())
return;
irr::core::stringw msg = StringUtils::utf8ToWide(*input);
std::vector<core::stringw> parts =
StringUtils::split(msg, '\n', false);
for (unsigned int n = 0; n < parts.size(); n++)
{
World::getWorld()->getRaceGUI()

View File

@@ -1154,6 +1154,9 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
void Track::loadMinimap()
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
//Create the minimap resizing it as necessary.
core::dimension2du mini_map_size = World::getWorld()->getRaceGUI()->getMiniMapSize();