1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Do not show desktop-only options on mobile systems

This commit is contained in:
Ivan Savenko 2023-05-19 23:19:43 +03:00
parent d18b240d6d
commit 20ec747440
3 changed files with 30 additions and 0 deletions

View File

@ -115,6 +115,11 @@ void InterfaceObjectConfigurable::build(const JsonNode &config)
addWidget(item["name"].String(), buildWidget(item));
}
void InterfaceObjectConfigurable::addConditional(const std::string & name, bool active)
{
conditionals[name] = active;
}
void InterfaceObjectConfigurable::addWidget(const std::string & namePreferred, std::shared_ptr<CIntObject> widget)
{
static const std::string unnamedObjectPrefix = "__widget_";
@ -502,6 +507,21 @@ std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildLayout(const JsonN
if (item["type"].String().empty())
item["type"].String() = customType;
if (!item["created"].isNull())
{
std::string name = item["created"].String();
if (conditionals.count(name) != 0)
{
if (!conditionals.at(name))
continue;
}
else
{
logMod->warn("Unknown condition %s in widget!", name);
}
}
auto widget = buildWidget(item);
addWidget(item["name"].String(), widget);

View File

@ -51,6 +51,8 @@ protected:
//must be called after adding callbacks
void build(const JsonNode & config);
void addConditional(const std::string & name, bool active);
void addWidget(const std::string & name, std::shared_ptr<CIntObject> widget);
void addCallback(const std::string & callbackName, std::function<void(int)> callback);
@ -110,5 +112,6 @@ private:
std::map<std::string, BuilderFunction> builders;
std::map<std::string, std::shared_ptr<CIntObject>> widgets;
std::map<std::string, std::function<void(int)>> callbacks;
std::map<std::string, bool> conditionals;
std::map<EShortcut, ShortcutState> shortcuts;
};

View File

@ -78,6 +78,13 @@ GeneralOptionsTab::GeneralOptionsTab()
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
type |= REDRAW_PARENT;
addConditional("mobile", false);
addConditional("desktop", true);
#ifdef VCMI_MOBILE
addConditional("mobile", true);
addConditional("desktop", false);
#endif
const JsonNode config(ResourceID("config/widgets/settings/generalOptionsTab.json"));
addCallback("spellbookAnimationChanged", [](bool value)
{