浏览代码

improve extraoptions

Laserlicht 1 年之前
父节点
当前提交
941c1576c5
共有 3 个文件被更改,包括 18 次插入2 次删除
  1. 10 0
      client/lobby/CLobbyScreen.cpp
  2. 7 2
      client/lobby/OptionsTabBase.cpp
  3. 1 0
      lib/gameState/CGameState.cpp

+ 10 - 0
client/lobby/CLobbyScreen.cpp

@@ -230,6 +230,16 @@ void CLobbyScreen::toggleChat()
 
 void CLobbyScreen::updateAfterStateChange()
 {
+	if(CSH->isHost() && screenType == ESelectionScreen::newGame)
+	{
+		bool isMultiplayer = CSH->loadMode == ELoadMode::MULTI;
+		ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
+		info.cheatsAllowed = isMultiplayer ? persistentStorage["startExtraOptions"]["multiPlayer"]["cheatsAllowed"].Bool() : !persistentStorage["startExtraOptions"]["singlePlayer"]["cheatsNotAllowed"].Bool();
+		info.unlimitedReplay = persistentStorage["startExtraOptions"][isMultiplayer ? "multiPlayer" : "singlePlayer"]["unlimitedReplay"].Bool();
+		if(info.cheatsAllowed != CSH->si->extraOptionsInfo.cheatsAllowed || info.unlimitedReplay != CSH->si->extraOptionsInfo.unlimitedReplay)
+			CSH->setExtraOptionsInfo(info);
+	}
+
 	if(CSH->mi)
 	{
 		if (tabOpt)

+ 7 - 2
client/lobby/OptionsTabBase.cpp

@@ -22,6 +22,7 @@
 #include "../../lib/Languages.h"
 #include "../../lib/MetaString.h"
 #include "../../lib/CGeneralTextHandler.h"
+#include "../../lib/CConfigHandler.h"
 
 static std::string timeToString(int time)
 {
@@ -100,12 +101,18 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
 	});
 
 	addCallback("setCheatAllowed", [&](int index){
+		bool isMultiplayer = CSH->loadMode == ELoadMode::MULTI;
+		Settings entry = persistentStorage.write["startExtraOptions"][isMultiplayer ? "multiPlayer" : "singlePlayer"][isMultiplayer ? "cheatsAllowed" : "cheatsNotAllowed"];
+		entry->Bool() = isMultiplayer ? index : !index;
 		ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
 		info.cheatsAllowed = index;
 		CSH->setExtraOptionsInfo(info);
 	});
 
 	addCallback("setUnlimitedReplay", [&](int index){
+		bool isMultiplayer = CSH->loadMode == ELoadMode::MULTI;
+		Settings entry = persistentStorage.write["startExtraOptions"][isMultiplayer ? "multiPlayer" : "singlePlayer"]["unlimitedReplay"];
+		entry->Bool() = index;
 		ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
 		info.unlimitedReplay = index;
 		CSH->setExtraOptionsInfo(info);
@@ -410,13 +417,11 @@ void OptionsTabBase::recreate(bool campaign)
 	if(auto buttonCheatAllowed = widget<CToggleButton>("buttonCheatAllowed"))
 	{
 		buttonCheatAllowed->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.cheatsAllowed);
-		buttonCheatAllowed->block(SEL->screenType == ESelectionScreen::loadGame);
 	}
 
 	if(auto buttonUnlimitedReplay = widget<CToggleButton>("buttonUnlimitedReplay"))
 	{
 		buttonUnlimitedReplay->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.unlimitedReplay);
-		buttonUnlimitedReplay->block(SEL->screenType == ESelectionScreen::loadGame);
 	}
 
 	if(auto textureCampaignOverdraw = widget<CFilledTexture>("textureCampaignOverdraw"))

+ 1 - 0
lib/gameState/CGameState.cpp

@@ -296,6 +296,7 @@ void CGameState::updateOnLoad(StartInfo * si)
 	scenarioOps->playerInfos = si->playerInfos;
 	for(auto & i : si->playerInfos)
 		gs->players[i.first].human = i.second.isControlledByHuman();
+	scenarioOps->extraOptionsInfo = si->extraOptionsInfo;
 }
 
 void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking)