diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index 5196df21c..889cd04cb 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -65,14 +65,36 @@ void InterfaceObjectConfigurable::deleteWidget(const std::string & name) widgets.erase(iter); } +void InterfaceObjectConfigurable::loadCustomBuilders(const JsonNode & config) +{ + for(auto & item : config.Struct()) + { + std::string typeName = item.first; + JsonNode baseConfig = item.second; + + auto const & functor = [this, baseConfig](const JsonNode & widgetConfig) -> std::shared_ptr + { + JsonNode actualConfig = widgetConfig; + JsonUtils::mergeCopy(actualConfig, baseConfig); + + return this->buildWidget(actualConfig); + }; + + registerBuilder(typeName, functor); + } +} + void InterfaceObjectConfigurable::build(const JsonNode &config) { OBJ_CONSTRUCTION; + logGlobal->debug("Building configurable interface object"); auto * items = &config; if(config.getType() == JsonNode::JsonType::DATA_STRUCT) { + loadCustomBuilders(config["customTypes"]); + for(auto & item : config["variables"].Struct()) { logGlobal->debug("Read variable named %s", item.first); diff --git a/client/gui/InterfaceObjectConfigurable.h b/client/gui/InterfaceObjectConfigurable.h index e99c2f4d6..39e9797bc 100644 --- a/client/gui/InterfaceObjectConfigurable.h +++ b/client/gui/InterfaceObjectConfigurable.h @@ -45,6 +45,8 @@ protected: using BuilderFunction = std::function(const JsonNode &)>; void registerBuilder(const std::string &, BuilderFunction); + + void loadCustomBuilders(const JsonNode & config); //must be called after adding callbacks void build(const JsonNode & config); diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index 42a1544c9..17aae72fc 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -1,4 +1,51 @@ { + "customTypes" : { + "labelTitle" : { + "type": "label", + "font": "medium", + "alignment": "left", + "color": "yellow" + }, + "labelAudio" : { + "type": "label", + "font": "medium", + "alignment": "center", + "color": "yellow" + }, + "labelDescription" : { + "type": "label", + "font": "medium", + "alignment": "left", + "color": "white" + }, + "checkbox" : { + "type": "toggleButton", + "image": "sysopchk.def", + }, + "buttonGear" : { + "type": "button", + "image": "settingsWindow/button32", + "items": + [ + { + "name": "gearIcon", + "type": "picture", + "image": "settingsWindow/gear", + "position": {"x": 0, "y": 0 } + } + ] + }, + "audioSlider" : { + "type": "slider", + "scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 }, + "size": 200, + "style": "brown", + "orientation": "horizontal", + "itemsVisible": 0, + "itemsTotal": 100, + } + }, + "items": [ { @@ -9,151 +56,95 @@ }, { - "name": "settingGroupTitles", - "type": "labelGroup", - "font": "medium", - "alignment": "left", - "color": "yellow", - "items": - [ - { - "position": {"x": 10, "y": 55}, - "text": "vcmi.systemOptions.videoGroup" - }, - { - "position": {"x": 380, "y": 55}, - "text": "vcmi.systemOptions.audioGroup" - }, - { - "position": {"x": 10, "y": 295}, - "text": "vcmi.systemOptions.townsGroup" - } - ] + "type" : "labelTitle", + "position": {"x": 10, "y": 55}, + "text": "vcmi.systemOptions.videoGroup" + }, + { + "type" : "labelTitle", + "position": {"x": 380, "y": 55}, + "text": "vcmi.systemOptions.audioGroup" + }, + { + "type" : "labelTitle", + "position": {"x": 10, "y": 295}, + "text": "vcmi.systemOptions.townsGroup" }, /////////////////////////////////////// Left section - Video Settings { "name": "resolutionLabel", - "type": "label", - "font": "medium", - "alignment": "left", - "color": "white", + "type": "labelDescription", "position": {"x": 45, "y": 85}, "text": "vcmi.systemOptions.resolutionButton.hover" }, { "name": "resolutionButton", - "type": "button", + "type": "buttonGear", "position": {"x": 10, "y": 83}, - "image": "settingsWindow/button32", "help": "vcmi.systemOptions.resolutionButton", "callback": "setGameResolution", - "items": - [ - { - "name": "gearIcon", - "type": "picture", - "image": "settingsWindow/gear", - "position": {"x": 0, "y": 0 } - } - ] }, { "name": "scalingLabel", - "type": "label", - "font": "medium", - "alignment": "left", - "color": "white", + "type": "labelDescription", "position": {"x": 45, "y": 115}, "text": "vcmi.systemOptions.scalingButton.hover" }, { "name": "scalingButton", - "type": "button", + "type": "buttonGear", "position": {"x": 10, "y": 113}, - "image": "settingsWindow/button32", "help": "vcmi.systemOptions.scalingButton", "callback": "setGameScaling", - "items": - [ - { - "name": "gearIcon", - "type": "picture", - "image": "settingsWindow/gear", - "position": {"x": 0, "y": 0 } - } - ] }, - { - "name": "topCheckboxesLabels", - "type": "labelGroup", - "font": "medium", - "alignment": "left", - "color": "white", - "items": - [ - { - "position": {"x": 45, "y": 145}, - "text": "vcmi.systemOptions.fullscreenButton.hover" - }, - { - "position": {"x": 45, "y": 175}, - "text": "vcmi.systemOptions.framerateButton.hover" - }, - { - "position": {"x": 45, "y": 205}, - "text": "core.genrltxt.577" - }, - - ] + "type" : "labelDescription", + "position": {"x": 45, "y": 145}, + "text": "vcmi.systemOptions.fullscreenButton.hover" + }, + { + "type" : "labelDescription", + "position": {"x": 45, "y": 175}, + "text": "vcmi.systemOptions.framerateButton.hover" + }, + { + "type" : "labelDescription", + "position": {"x": 45, "y": 205}, + "text": "core.genrltxt.577" }, { "name": "fullscreenCheckbox", - "type": "toggleButton", - "image": "sysopchk.def", + "type": "checkbox", "help": "vcmi.systemOptions.fullscreenButton", "position": {"x": 10, "y": 143}, "callback": "fullscreenChanged" }, { "name": "framerateCheckbox", - "type": "toggleButton", - "image": "sysopchk.def", + "type": "checkbox", "help": "vcmi.systemOptions.framerateButton", "position": {"x": 10, "y": 173}, "callback": "framerateChanged" }, - { "name": "spellbookAnimationCheckbox", - "type": "toggleButton", - "image": "sysopchk.def", + "type": "checkbox", "help": "core.help.364", "position": {"x": 10, "y": 203}, "callback": "spellbookAnimationChanged" }, - /////////////////////////////////////// Right section - Audio Settings { - "name": "settingAudioTitles", - "type": "labelGroup", - "font": "medium", - "alignment": "center", - "color": "yellow", - "items": - [ - { - "position": {"x": 460, "y": 98}, - "text": "core.genrltxt.394" // Music Volume - }, - { - "position": {"x": 460, "y": 158}, - "text": "core.genrltxt.395" // Effects volume - } - ] + "type" : "labelAudio", + "position": {"x": 460, "y": 98}, + "text": "core.genrltxt.394" // Music Volume + }, + { + "type" : "labelAudio", + "position": {"x": 460, "y": 158}, + "text": "core.genrltxt.395" // Effects volume }, - { "name": "frameMusic", "type": "picture", @@ -162,74 +153,47 @@ }, { "name": "musicSlider", - "type": "slider", + "type": "audioSlider", "position": {"x": 385, "y": 115}, - "scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 }, - "size": 200, - "style": "brown", - "orientation": "horizontal", - "itemsVisible": 0, - "itemsTotal": 100, "callback": "setMusic" }, { "name": "musicValueLabel", - "type": "label", - "font": "medium", - "alignment": "center", - "color": "yellow", + "type": "labelAudio", "position": {"x": 565, "y": 98} }, - { "name": "frameSound", "type": "picture", "image": "settingsWindow/frameAudio", "position": {"x": 380, "y": 140 } }, - { "name": "soundVolumeSlider", - "type": "slider", + "type": "audioSlider", "position": {"x": 385, "y": 175}, - "scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 }, - "size": 200, - "style": "brown", - "orientation": "horizontal", - "itemsVisible": 0, - "itemsTotal": 100, "callback": "setVolume" }, { "name": "soundValueLabel", - "type": "label", - "font": "medium", - "alignment": "center", - "color": "yellow", + "type": "labelAudio", "position": {"x": 565, "y": 158} }, /////////////////////////////////////// Bottom section - Towns Settings { - "name": "townCheckboxesLabels", - "type": "labelGroup", - "font": "medium", - "alignment": "left", - "color": "white", - "items": - [ - { - "text": "vcmi.otherOptions.creatureGrowthAsDwellingLabel.hover", - "position": {"x": 45, "y": 325} - }, - { - "text": "vcmi.otherOptions.availableCreaturesAsDwellingLabel.hover", - "position": {"x": 45, "y": 355} - }, - { - "text": "vcmi.otherOptions.compactTownCreatureInfo.hover", - "position": {"x": 45, "y": 385} - } - ] + "type" : "labelDescription", + "text": "vcmi.otherOptions.creatureGrowthAsDwellingLabel.hover", + "position": {"x": 45, "y": 325} + }, + { + "type" : "labelDescription", + "text": "vcmi.otherOptions.availableCreaturesAsDwellingLabel.hover", + "position": {"x": 45, "y": 355} + }, + { + "type" : "labelDescription", + "text": "vcmi.otherOptions.compactTownCreatureInfo.hover", + "position": {"x": 45, "y": 385} }, { @@ -240,15 +204,13 @@ [ { "index": 0, - "type": "toggleButton", - "image": "sysopchk.def", + "type": "checkbox", "help": "vcmi.otherOptions.creatureGrowthAsDwellingLabel", "position": {"x": 0, "y": 0} }, { "index": 1, - "type": "toggleButton", - "image": "sysopchk.def", + "type": "checkbox", "help": "vcmi.otherOptions.availableCreaturesAsDwellingLabel", "position": {"x": 0, "y": 30} }, @@ -258,8 +220,7 @@ { "name": "compactTownCreatureInfoCheckbox", - "type": "toggleButton", - "image": "sysopchk.def", + "type": "checkbox", "help": "vcmi.otherOptions.compactTownCreatureInfo", "position": {"x": 10, "y": 383}, "callback": "compactTownCreatureInfoChanged"