1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

improve extraoptions

This commit is contained in:
Laserlicht 2024-05-14 00:33:30 +02:00 committed by GitHub
parent 58d1c93c1b
commit 941c1576c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -230,6 +230,16 @@ void CLobbyScreen::toggleChat()
void CLobbyScreen::updateAfterStateChange() 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(CSH->mi)
{ {
if (tabOpt) if (tabOpt)

View File

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

View File

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