From 043f54698b2044a97072215d573e6a07bd162973 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Thu, 5 Oct 2023 23:34:29 +0200 Subject: [PATCH] Fix translations in map editor / fix crash on game end --- client/CServerHandler.cpp | 7 +++++-- lib/mapping/CMapHeader.cpp | 2 +- mapeditor/mapsettings/loseconditions.cpp | 10 +++++++++- mapeditor/mapsettings/victoryconditions.cpp | 10 +++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index ab647e2b6..91828e68d 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -681,8 +681,11 @@ void CServerHandler::endGameplay(bool closeConnection, bool restart) } } - c->enterLobbyConnectionMode(); - c->disableStackSendingByID(); + if(c) + { + c->enterLobbyConnectionMode(); + c->disableStackSendingByID(); + } //reset settings Settings saveSession = settings.write["server"]["reconnect"]; diff --git a/lib/mapping/CMapHeader.cpp b/lib/mapping/CMapHeader.cpp index 44e7f9442..c86a923b8 100644 --- a/lib/mapping/CMapHeader.cpp +++ b/lib/mapping/CMapHeader.cpp @@ -157,7 +157,7 @@ void CMapHeader::registerMapStrings() mapLanguages.insert(translation.first); } - if(maxStrings == 0 || mapBaseLanguages.empty()) + if(maxStrings == 0 || mapLanguages.empty()) { logGlobal->info("Map %s doesn't have any supported translation", name.toString()); return; diff --git a/mapeditor/mapsettings/loseconditions.cpp b/mapeditor/mapsettings/loseconditions.cpp index 3e155060d..e19962734 100644 --- a/mapeditor/mapsettings/loseconditions.cpp +++ b/mapeditor/mapsettings/loseconditions.cpp @@ -117,7 +117,7 @@ void LoseConditions::initialize(MapController & c) void LoseConditions::update() { //loss messages - controller->map()->defeatMessage = MetaString::createFromTextID(mapRegisterLocalizedString("map", *controller->map(), TextIdentifier("header", "defeatMessage"), ui->defeatMessageEdit->text().toStdString())); + bool customMessage = true; //loss conditions EventCondition defeatCondition(EventCondition::DAYS_WITHOUT_TOWN); @@ -138,6 +138,7 @@ void LoseConditions::update() controller->map()->triggeredEvents.push_back(standardDefeat); controller->map()->defeatIconIndex = 3; controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.0"); + customMessage = false; } else { @@ -163,6 +164,7 @@ void LoseConditions::update() specialDefeat.onFulfill.appendTextID("core.genrltxt.251"); specialDefeat.trigger = EventExpression(noneOf); controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.1"); + customMessage = false; break; } @@ -177,6 +179,7 @@ void LoseConditions::update() specialDefeat.onFulfill.appendTextID("core.genrltxt.253"); specialDefeat.trigger = EventExpression(noneOf); controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.2"); + customMessage = false; break; } @@ -187,6 +190,7 @@ void LoseConditions::update() specialDefeat.onFulfill.appendTextID("core.genrltxt.254"); specialDefeat.trigger = EventExpression(cond); controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.3"); + customMessage = false; break; } @@ -215,6 +219,10 @@ void LoseConditions::update() controller->map()->triggeredEvents.push_back(specialDefeat); } + if(customMessage) + { + controller->map()->defeatMessage = MetaString::createFromTextID(mapRegisterLocalizedString("map", *controller->map(), TextIdentifier("header", "defeatMessage"), ui->defeatMessageEdit->text().toStdString())); + } } void LoseConditions::on_loseComboBox_currentIndexChanged(int index) diff --git a/mapeditor/mapsettings/victoryconditions.cpp b/mapeditor/mapsettings/victoryconditions.cpp index 43131386b..f1db91643 100644 --- a/mapeditor/mapsettings/victoryconditions.cpp +++ b/mapeditor/mapsettings/victoryconditions.cpp @@ -179,7 +179,7 @@ void VictoryConditions::initialize(MapController & c) void VictoryConditions::update() { //victory messages - controller->map()->victoryMessage = MetaString::createFromTextID(mapRegisterLocalizedString("map", *controller->map(), TextIdentifier("header", "victoryMessage"), ui->victoryMessageEdit->text().toStdString())); + bool customMessage = true; //victory conditions EventCondition victoryCondition(EventCondition::STANDARD_WIN); @@ -199,6 +199,7 @@ void VictoryConditions::update() controller->map()->triggeredEvents.push_back(standardVictory); controller->map()->victoryIconIndex = 11; controller->map()->victoryMessage = MetaString::createFromTextID("core.vcdesc.0"); + customMessage = false; } else { @@ -211,6 +212,7 @@ void VictoryConditions::update() controller->map()->victoryIconIndex = vicCondition; controller->map()->victoryMessage = MetaString::createFromTextID("core.vcdesc." + std::to_string(vicCondition + 1)); + customMessage = false; switch(vicCondition) { @@ -327,9 +329,15 @@ void VictoryConditions::update() controller->map()->victoryMessage.appendRawString(" / "); controller->map()->victoryMessage.appendTextID("core.vcdesc.0"); controller->map()->triggeredEvents.push_back(standardVictory); + customMessage = false; } controller->map()->triggeredEvents.push_back(specialVictory); } + + if(customMessage) + { + controller->map()->victoryMessage = MetaString::createFromTextID(mapRegisterLocalizedString("map", *controller->map(), TextIdentifier("header", "victoryMessage"), ui->victoryMessageEdit->text().toStdString())); + } } VictoryConditions::~VictoryConditions()