1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-06 23:26:26 +02:00

unlimited replay option

This commit is contained in:
Laserlicht 2023-12-28 20:48:19 +01:00
parent a3e27b859e
commit cb9c4bbaf0
17 changed files with 133 additions and 38 deletions

View File

@ -309,7 +309,9 @@
"vcmi.optionsTab.extraOptions.help" : "Additional settings for the game.", "vcmi.optionsTab.extraOptions.help" : "Additional settings for the game.",
"vcmi.optionsTab.cheatAllowed.hover" : "Allow cheats", "vcmi.optionsTab.cheatAllowed.hover" : "Allow cheats",
"vcmi.optionsTab.unlimitedReplay.hover" : "Unlimited battle replay",
"vcmi.optionsTab.cheatAllowed.help" : "{Allow cheats}\nAllows the inputs of cheats during the game.", "vcmi.optionsTab.cheatAllowed.help" : "{Allow cheats}\nAllows the inputs of cheats during the game.",
"vcmi.optionsTab.unlimitedReplay.help" : "{Unlimited battle replay}\nNo limit of replaying battles.",
// Custom victory conditions for H3 campaigns and HotA maps // Custom victory conditions for H3 campaigns and HotA maps
"vcmi.map.victoryCondition.daysPassed.toOthers" : "The enemy has managed to survive till this day. Victory is theirs!", "vcmi.map.victoryCondition.daysPassed.toOthers" : "The enemy has managed to survive till this day. Victory is theirs!",

View File

@ -303,7 +303,9 @@
"vcmi.optionsTab.extraOptions.help" : "Zusätzliche Einstellungen für das Spiel.", "vcmi.optionsTab.extraOptions.help" : "Zusätzliche Einstellungen für das Spiel.",
"vcmi.optionsTab.cheatAllowed.hover" : "Cheats erlauben", "vcmi.optionsTab.cheatAllowed.hover" : "Cheats erlauben",
"vcmi.optionsTab.unlimitedReplay.hover" : "Unbegrenzte Kampfwiederholung",
"vcmi.optionsTab.cheatAllowed.help" : "{Cheats erlauben}\nErlaubt die Eingabe von Cheats während des Spiels.", "vcmi.optionsTab.cheatAllowed.help" : "{Cheats erlauben}\nErlaubt die Eingabe von Cheats während des Spiels.",
"vcmi.optionsTab.unlimitedReplay.help" : "{Unbegrenzte Kampfwiederholung}\nKämpfe lassen sich unbegrenzt wiederholen.",
// Custom victory conditions for H3 campaigns and HotA maps // Custom victory conditions for H3 campaigns and HotA maps
"vcmi.map.victoryCondition.daysPassed.toOthers" : "Der Feind hat es geschafft, bis zum heutigen Tag zu überleben. Der Sieg gehört ihm!", "vcmi.map.victoryCondition.daysPassed.toOthers" : "Der Feind hat es geschafft, bis zum heutigen Tag zu überleben. Der Sieg gehört ihm!",

View File

@ -507,11 +507,11 @@ void CServerHandler::setTurnTimerInfo(const TurnTimerInfo & info) const
sendLobbyPack(lstt); sendLobbyPack(lstt);
} }
void CServerHandler::setCheatAllowedInfo(bool allowed) const void CServerHandler::setExtraOptionsInfo(const ExtraOptionsInfo & info) const
{ {
LobbySetCheatAllowed lsca; LobbySetExtraOptions lseo;
lsca.allowed = allowed; lseo.extraOptionsInfo = info;
sendLobbyPack(lsca); sendLobbyPack(lseo);
} }
void CServerHandler::sendMessage(const std::string & txt) const void CServerHandler::sendMessage(const std::string & txt) const

View File

@ -72,7 +72,7 @@ public:
virtual void setDifficulty(int to) const = 0; virtual void setDifficulty(int to) const = 0;
virtual void setTurnTimerInfo(const TurnTimerInfo &) const = 0; virtual void setTurnTimerInfo(const TurnTimerInfo &) const = 0;
virtual void setSimturnsInfo(const SimturnsInfo &) const = 0; virtual void setSimturnsInfo(const SimturnsInfo &) const = 0;
virtual void setCheatAllowedInfo(bool allowed) const = 0; virtual void setExtraOptionsInfo(const ExtraOptionsInfo & info) const = 0;
virtual void sendMessage(const std::string & txt) const = 0; virtual void sendMessage(const std::string & txt) const = 0;
virtual void sendGuiAction(ui8 action) const = 0; // TODO: possibly get rid of it? virtual void sendGuiAction(ui8 action) const = 0; // TODO: possibly get rid of it?
virtual void sendStartGame(bool allowOnlyAI = false) const = 0; virtual void sendStartGame(bool allowOnlyAI = false) const = 0;
@ -159,7 +159,7 @@ public:
void setDifficulty(int to) const override; void setDifficulty(int to) const override;
void setTurnTimerInfo(const TurnTimerInfo &) const override; void setTurnTimerInfo(const TurnTimerInfo &) const override;
void setSimturnsInfo(const SimturnsInfo &) const override; void setSimturnsInfo(const SimturnsInfo &) const override;
void setCheatAllowedInfo(bool allowed) const override; void setExtraOptionsInfo(const ExtraOptionsInfo &) const override;
void sendMessage(const std::string & txt) const override; void sendMessage(const std::string & txt) const override;
void sendGuiAction(ui8 action) const override; void sendGuiAction(ui8 action) const override;
void sendRestartGame() const override; void sendRestartGame() const override;

View File

@ -471,7 +471,7 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
exit = std::make_shared<CButton>(Point(384, 505), AnimationPath::builtin("iok6432.def"), std::make_pair("", ""), [&](){ bExitf();}, EShortcut::GLOBAL_ACCEPT); exit = std::make_shared<CButton>(Point(384, 505), AnimationPath::builtin("iok6432.def"), std::make_pair("", ""), [&](){ bExitf();}, EShortcut::GLOBAL_ACCEPT);
exit->setBorderColor(Colors::METALLIC_GOLD); exit->setBorderColor(Colors::METALLIC_GOLD);
if(allowReplay) if(allowReplay || owner.cb->getStartInfo()->extraOptionsInfo.unlimitedReplay)
{ {
repeat = std::make_shared<CButton>(Point(24, 505), AnimationPath::builtin("icn6432.def"), std::make_pair("", ""), [&](){ bRepeatf();}, EShortcut::GLOBAL_CANCEL); repeat = std::make_shared<CButton>(Point(24, 505), AnimationPath::builtin("icn6432.def"), std::make_pair("", ""), [&](){ bRepeatf();}, EShortcut::GLOBAL_CANCEL);
repeat->setBorderColor(Colors::METALLIC_GOLD); repeat->setBorderColor(Colors::METALLIC_GOLD);

View File

@ -91,7 +91,15 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
}); });
addCallback("setCheatAllowed", [&](int index){ addCallback("setCheatAllowed", [&](int index){
CSH->setCheatAllowedInfo(index); ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
info.cheatsAllowed = index;
CSH->setExtraOptionsInfo(info);
});
addCallback("setUnlimitedReplay", [&](int index){
ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
info.unlimitedReplay = index;
CSH->setExtraOptionsInfo(info);
}); });
addCallback("setTurnTimerAccumulate", [&](int index){ addCallback("setTurnTimerAccumulate", [&](int index){
@ -391,5 +399,8 @@ void OptionsTabBase::recreate()
} }
if(auto buttonCheatAllowed = widget<CToggleButton>("buttonCheatAllowed")) if(auto buttonCheatAllowed = widget<CToggleButton>("buttonCheatAllowed"))
buttonCheatAllowed->setSelectedSilent(SEL->getStartInfo()->cheatAllowed); buttonCheatAllowed->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.cheatsAllowed);
if(auto buttonUnlimitedReplay = widget<CToggleButton>("buttonUnlimitedReplay"))
buttonUnlimitedReplay->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.unlimitedReplay);
} }

View File

@ -1,4 +1,6 @@
{ {
"library" : "config/widgets/settings/library.json",
"items": "items":
[ [
{ {
@ -52,21 +54,48 @@
"color": [24, 41, 90, 255] "color": [24, 41, 90, 255]
}, },
{ {
"name": "buttonCheatAllowed", "name": "ExtraOptionsButtons",
"type" : "verticalLayout",
"customType" : "toggleButton",
"position": {"x": 70, "y": 100}, "position": {"x": 70, "y": 100},
"type": "toggleButton", "items":
[
{
"name": "buttonCheatAllowed",
"image": "lobby/checkbox", "image": "lobby/checkbox",
"callback" : "setCheatAllowed", "callback" : "setCheatAllowed",
"selected" : true "selected" : true
}, },
{
"name": "buttonUnlimitedReplay",
"image": "lobby/checkbox",
"callback" : "setUnlimitedReplay",
"selected" : true
}
]
},
{
"name": "ExtraOptionsLabels",
"type" : "verticalLayout",
"customType" : "label",
"position": {"x": 110, "y": 103},
"items":
[
{ {
"name": "labelCheatAllowed", "name": "labelCheatAllowed",
"type": "label",
"font": "small", "font": "small",
"alignment": "left", "alignment": "left",
"color": "yellow", "color": "yellow",
"text": "vcmi.optionsTab.cheatAllowed.hover", "text": "vcmi.optionsTab.cheatAllowed.hover"
"position": {"x": 110, "y": 103} },
{
"name": "labelUnlimitedReplay",
"font": "small",
"alignment": "left",
"color": "yellow",
"text": "vcmi.optionsTab.unlimitedReplay.hover"
}
]
} }
] ]
} }

21
lib/ExtraOptionsInfo.cpp Normal file
View File

@ -0,0 +1,21 @@
/*
* ExtraOptionsInfo.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "ExtraOptionsInfo.h"
VCMI_LIB_NAMESPACE_BEGIN
bool ExtraOptionsInfo::operator == (const ExtraOptionsInfo & other) const
{
return cheatsAllowed == other.cheatsAllowed &&
unlimitedReplay == other.unlimitedReplay;
}
VCMI_LIB_NAMESPACE_END

30
lib/ExtraOptionsInfo.h Normal file
View File

@ -0,0 +1,30 @@
/*
* ExtraOptionsInfo.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
VCMI_LIB_NAMESPACE_BEGIN
struct DLL_LINKAGE ExtraOptionsInfo
{
bool cheatsAllowed = true;
bool unlimitedReplay = false;
bool operator == (const ExtraOptionsInfo & other) const;
template <typename Handler>
void serialize(Handler &h, const int version)
{
h & cheatsAllowed;
h & unlimitedReplay;
}
};
VCMI_LIB_NAMESPACE_END

View File

@ -13,6 +13,7 @@
#include "GameConstants.h" #include "GameConstants.h"
#include "TurnTimerInfo.h" #include "TurnTimerInfo.h"
#include "ExtraOptionsInfo.h"
#include "campaign/CampaignConstants.h" #include "campaign/CampaignConstants.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -105,8 +106,6 @@ struct DLL_LINKAGE StartInfo
EMode mode; EMode mode;
ui8 difficulty; //0=easy; 4=impossible ui8 difficulty; //0=easy; 4=impossible
bool cheatAllowed;
using TPlayerInfos = std::map<PlayerColor, PlayerSettings>; using TPlayerInfos = std::map<PlayerColor, PlayerSettings>;
TPlayerInfos playerInfos; //color indexed TPlayerInfos playerInfos; //color indexed
@ -117,6 +116,7 @@ struct DLL_LINKAGE StartInfo
std::string fileURI; std::string fileURI;
SimturnsInfo simturnsInfo; SimturnsInfo simturnsInfo;
TurnTimerInfo turnTimerInfo; TurnTimerInfo turnTimerInfo;
ExtraOptionsInfo extraOptionsInfo;
std::string mapname; // empty for random map, otherwise name of the map or savegame std::string mapname; // empty for random map, otherwise name of the map or savegame
bool createRandomMap() const { return mapGenOptions != nullptr; } bool createRandomMap() const { return mapGenOptions != nullptr; }
std::shared_ptr<CMapGenOptions> mapGenOptions; std::shared_ptr<CMapGenOptions> mapGenOptions;
@ -144,16 +144,16 @@ struct DLL_LINKAGE StartInfo
h & simturnsInfo; h & simturnsInfo;
h & turnTimerInfo; h & turnTimerInfo;
if(version >= 832) if(version >= 832)
h & cheatAllowed; h & extraOptionsInfo;
else else
cheatAllowed = true; extraOptionsInfo = ExtraOptionsInfo();
h & mapname; h & mapname;
h & mapGenOptions; h & mapGenOptions;
h & campState; h & campState;
} }
StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0), StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0),
mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(nullptr))), fileURI(""), cheatAllowed(true) mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(nullptr))), fileURI("")
{ {
} }

View File

@ -164,7 +164,7 @@ public:
virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) {} virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) {}
virtual void visitLobbySetSimturns(LobbySetSimturns & pack) {} virtual void visitLobbySetSimturns(LobbySetSimturns & pack) {}
virtual void visitLobbySetTurnTime(LobbySetTurnTime & pack) {} virtual void visitLobbySetTurnTime(LobbySetTurnTime & pack) {}
virtual void visitLobbySetCheatAllowed(LobbySetCheatAllowed & pack) {} virtual void visitLobbySetExtraOptions(LobbySetExtraOptions & pack) {}
virtual void visitLobbySetDifficulty(LobbySetDifficulty & pack) {} virtual void visitLobbySetDifficulty(LobbySetDifficulty & pack) {}
virtual void visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack) {} virtual void visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack) {}
virtual void visitLobbyShowMessage(LobbyShowMessage & pack) {} virtual void visitLobbyShowMessage(LobbyShowMessage & pack) {}

View File

@ -770,9 +770,9 @@ void LobbySetTurnTime::visitTyped(ICPackVisitor & visitor)
visitor.visitLobbySetTurnTime(*this); visitor.visitLobbySetTurnTime(*this);
} }
void LobbySetCheatAllowed::visitTyped(ICPackVisitor & visitor) void LobbySetExtraOptions::visitTyped(ICPackVisitor & visitor)
{ {
visitor.visitLobbySetCheatAllowed(*this); visitor.visitLobbySetExtraOptions(*this);
} }
void LobbySetDifficulty::visitTyped(ICPackVisitor & visitor) void LobbySetDifficulty::visitTyped(ICPackVisitor & visitor)

View File

@ -287,15 +287,15 @@ struct DLL_LINKAGE LobbySetTurnTime : public CLobbyPackToServer
} }
}; };
struct DLL_LINKAGE LobbySetCheatAllowed : public CLobbyPackToServer struct DLL_LINKAGE LobbySetExtraOptions : public CLobbyPackToServer
{ {
bool allowed; ExtraOptionsInfo extraOptionsInfo;
void visitTyped(ICPackVisitor & visitor) override; void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & allowed; h & extraOptionsInfo;
} }
}; };

View File

@ -57,7 +57,7 @@ void registerTypesLobbyPacks(Serializer &s)
s.template registerType<CLobbyPackToServer, LobbySetSimturns>(); s.template registerType<CLobbyPackToServer, LobbySetSimturns>();
s.template registerType<CLobbyPackToServer, LobbySetDifficulty>(); s.template registerType<CLobbyPackToServer, LobbySetDifficulty>();
s.template registerType<CLobbyPackToServer, LobbyForceSetPlayer>(); s.template registerType<CLobbyPackToServer, LobbyForceSetPlayer>();
s.template registerType<CLobbyPackToServer, LobbySetCheatAllowed>(); s.template registerType<CLobbyPackToServer, LobbySetExtraOptions>();
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -88,7 +88,7 @@ public:
virtual void visitLobbySetPlayer(LobbySetPlayer & pack) override; virtual void visitLobbySetPlayer(LobbySetPlayer & pack) override;
virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) override; virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) override;
virtual void visitLobbySetTurnTime(LobbySetTurnTime & pack) override; virtual void visitLobbySetTurnTime(LobbySetTurnTime & pack) override;
virtual void visitLobbySetCheatAllowed(LobbySetCheatAllowed & pack) override; virtual void visitLobbySetExtraOptions(LobbySetExtraOptions & pack) override;
virtual void visitLobbySetSimturns(LobbySetSimturns & pack) override; virtual void visitLobbySetSimturns(LobbySetSimturns & pack) override;
virtual void visitLobbySetDifficulty(LobbySetDifficulty & pack) override; virtual void visitLobbySetDifficulty(LobbySetDifficulty & pack) override;
virtual void visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack) override; virtual void visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack) override;

View File

@ -414,9 +414,9 @@ void ApplyOnServerNetPackVisitor::visitLobbySetTurnTime(LobbySetTurnTime & pack)
result = true; result = true;
} }
void ApplyOnServerNetPackVisitor::visitLobbySetCheatAllowed(LobbySetCheatAllowed & pack) void ApplyOnServerNetPackVisitor::visitLobbySetExtraOptions(LobbySetExtraOptions & pack)
{ {
srv.si->cheatAllowed = pack.allowed; srv.si->extraOptionsInfo = pack.extraOptionsInfo;
result = true; result = true;
} }

View File

@ -440,7 +440,7 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
std::vector<std::string> words; std::vector<std::string> words;
boost::split(words, cheat, boost::is_any_of("\t\r\n ")); boost::split(words, cheat, boost::is_any_of("\t\r\n "));
if (words.empty() || !gameHandler->getStartInfo()->cheatAllowed) if (words.empty() || !gameHandler->getStartInfo()->extraOptionsInfo.cheatsAllowed)
return false; return false;
//Make cheat name case-insensitive, but keep words/parameters (e.g. creature name) as it //Make cheat name case-insensitive, but keep words/parameters (e.g. creature name) as it