mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Implemented simple layout to simplify widget json definitions
This commit is contained in:
@ -46,6 +46,7 @@ InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset)
|
|||||||
REGISTER_BUILDER("button", &InterfaceObjectConfigurable::buildButton);
|
REGISTER_BUILDER("button", &InterfaceObjectConfigurable::buildButton);
|
||||||
REGISTER_BUILDER("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
|
REGISTER_BUILDER("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
|
||||||
REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
|
REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
|
||||||
|
REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
|
void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
|
||||||
@ -468,6 +469,54 @@ std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const
|
|||||||
return std::make_shared<CFilledTexture>(image, rect);
|
return std::make_shared<CFilledTexture>(image, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Small helper class that provides ownership for shared_ptr's of child elements
|
||||||
|
class InterfaceLayoutWidget : public CIntObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::vector<std::shared_ptr<CIntObject>> ownedChildren;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildLayout(const JsonNode & config)
|
||||||
|
{
|
||||||
|
logGlobal->debug("Building widget Layout");
|
||||||
|
bool vertical = config["vertical"].Bool();
|
||||||
|
bool horizontal = config["horizontal"].Bool();
|
||||||
|
bool dynamic = config["dynamic"].Bool();
|
||||||
|
int distance = config["distance"].Integer();
|
||||||
|
std::string customType = config["customType"].String();
|
||||||
|
auto position = readPosition(config["position"]);
|
||||||
|
|
||||||
|
auto result = std::make_shared<InterfaceLayoutWidget>();
|
||||||
|
result->moveBy(position);
|
||||||
|
Point layoutPosition;
|
||||||
|
|
||||||
|
for(auto item : config["items"].Vector())
|
||||||
|
{
|
||||||
|
if (item["type"].String().empty())
|
||||||
|
item["type"].String() = customType;
|
||||||
|
|
||||||
|
auto widget = buildWidget(item);
|
||||||
|
|
||||||
|
addWidget(item["name"].String(), widget);
|
||||||
|
result->ownedChildren.push_back(widget);
|
||||||
|
result->addChild(widget.get(), false);
|
||||||
|
|
||||||
|
widget->moveBy(position + layoutPosition);
|
||||||
|
|
||||||
|
if (dynamic && vertical)
|
||||||
|
layoutPosition.y += widget->pos.h;
|
||||||
|
if (dynamic && horizontal)
|
||||||
|
layoutPosition.x += widget->pos.w;
|
||||||
|
|
||||||
|
if (vertical)
|
||||||
|
layoutPosition.y += distance;
|
||||||
|
if (horizontal)
|
||||||
|
layoutPosition.x += distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<CShowableAnim> InterfaceObjectConfigurable::buildAnimation(const JsonNode & config) const
|
std::shared_ptr<CShowableAnim> InterfaceObjectConfigurable::buildAnimation(const JsonNode & config) const
|
||||||
{
|
{
|
||||||
logGlobal->debug("Building widget CShowableAnim");
|
logGlobal->debug("Building widget CShowableAnim");
|
||||||
|
@ -93,6 +93,7 @@ protected:
|
|||||||
std::shared_ptr<CAnimImage> buildImage(const JsonNode &) const;
|
std::shared_ptr<CAnimImage> buildImage(const JsonNode &) const;
|
||||||
std::shared_ptr<CShowableAnim> buildAnimation(const JsonNode &) const;
|
std::shared_ptr<CShowableAnim> buildAnimation(const JsonNode &) const;
|
||||||
std::shared_ptr<CFilledTexture> buildTexture(const JsonNode &) const;
|
std::shared_ptr<CFilledTexture> buildTexture(const JsonNode &) const;
|
||||||
|
std::shared_ptr<CIntObject> buildLayout(const JsonNode &);
|
||||||
|
|
||||||
//composite widgets
|
//composite widgets
|
||||||
std::shared_ptr<CIntObject> buildWidget(JsonNode config) const;
|
std::shared_ptr<CIntObject> buildWidget(JsonNode config) const;
|
||||||
|
@ -43,6 +43,12 @@
|
|||||||
"orientation": "horizontal",
|
"orientation": "horizontal",
|
||||||
"itemsVisible": 0,
|
"itemsVisible": 0,
|
||||||
"itemsTotal": 100,
|
"itemsTotal": 100,
|
||||||
|
},
|
||||||
|
"verticalLayout" : {
|
||||||
|
"type" : "layout",
|
||||||
|
"vertical" : true,
|
||||||
|
"dynamic" : false,
|
||||||
|
"distance" : 30
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -54,7 +60,6 @@
|
|||||||
"image": "settingsWindow/lineHorizontal",
|
"image": "settingsWindow/lineHorizontal",
|
||||||
"rect": { "x" : 5, "y" : 289, "w": 365, "h": 3}
|
"rect": { "x" : 5, "y" : 289, "w": 365, "h": 3}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"type" : "labelTitle",
|
"type" : "labelTitle",
|
||||||
"position": {"x": 10, "y": 55},
|
"position": {"x": 10, "y": 55},
|
||||||
@ -71,69 +76,64 @@
|
|||||||
"text": "vcmi.systemOptions.townsGroup"
|
"text": "vcmi.systemOptions.townsGroup"
|
||||||
},
|
},
|
||||||
/////////////////////////////////////// Left section - Video Settings
|
/////////////////////////////////////// Left section - Video Settings
|
||||||
|
{
|
||||||
|
"type" : "verticalLayout",
|
||||||
|
"customType" : "labelDescription",
|
||||||
|
"position" : {"x": 45, "y": 85},
|
||||||
|
"items" : [
|
||||||
{
|
{
|
||||||
"name": "resolutionLabel",
|
"name": "resolutionLabel",
|
||||||
"type": "labelDescription",
|
|
||||||
"position": {"x": 45, "y": 85},
|
|
||||||
"text": "vcmi.systemOptions.resolutionButton.hover"
|
"text": "vcmi.systemOptions.resolutionButton.hover"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "scalingLabel",
|
||||||
|
"text": "vcmi.systemOptions.scalingButton.hover"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "vcmi.systemOptions.fullscreenButton.hover"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "vcmi.systemOptions.framerateButton.hover"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "core.genrltxt.577"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type" : "verticalLayout",
|
||||||
|
"customType" : "checkbox",
|
||||||
|
"position" : {"x": 10, "y": 83},
|
||||||
|
"items" : [
|
||||||
{
|
{
|
||||||
"name": "resolutionButton",
|
"name": "resolutionButton",
|
||||||
"type": "buttonGear",
|
"type": "buttonGear",
|
||||||
"position": {"x": 10, "y": 83},
|
|
||||||
"help": "vcmi.systemOptions.resolutionButton",
|
"help": "vcmi.systemOptions.resolutionButton",
|
||||||
"callback": "setGameResolution",
|
"callback": "setGameResolution",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
"name": "scalingLabel",
|
|
||||||
"type": "labelDescription",
|
|
||||||
"position": {"x": 45, "y": 115},
|
|
||||||
"text": "vcmi.systemOptions.scalingButton.hover"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "scalingButton",
|
"name": "scalingButton",
|
||||||
"type": "buttonGear",
|
"type": "buttonGear",
|
||||||
"position": {"x": 10, "y": 113},
|
|
||||||
"help": "vcmi.systemOptions.scalingButton",
|
"help": "vcmi.systemOptions.scalingButton",
|
||||||
"callback": "setGameScaling",
|
"callback": "setGameScaling",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"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",
|
"name": "fullscreenCheckbox",
|
||||||
"type": "checkbox",
|
|
||||||
"help": "vcmi.systemOptions.fullscreenButton",
|
"help": "vcmi.systemOptions.fullscreenButton",
|
||||||
"position": {"x": 10, "y": 143},
|
|
||||||
"callback": "fullscreenChanged"
|
"callback": "fullscreenChanged"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "framerateCheckbox",
|
"name": "framerateCheckbox",
|
||||||
"type": "checkbox",
|
|
||||||
"help": "vcmi.systemOptions.framerateButton",
|
"help": "vcmi.systemOptions.framerateButton",
|
||||||
"position": {"x": 10, "y": 173},
|
|
||||||
"callback": "framerateChanged"
|
"callback": "framerateChanged"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "spellbookAnimationCheckbox",
|
"name": "spellbookAnimationCheckbox",
|
||||||
"type": "checkbox",
|
|
||||||
"help": "core.help.364",
|
"help": "core.help.364",
|
||||||
"position": {"x": 10, "y": 203},
|
|
||||||
"callback": "spellbookAnimationChanged"
|
"callback": "spellbookAnimationChanged"
|
||||||
},
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
/////////////////////////////////////// Right section - Audio Settings
|
/////////////////////////////////////// Right section - Audio Settings
|
||||||
{
|
{
|
||||||
"type" : "labelAudio",
|
"type" : "labelAudio",
|
||||||
@ -181,49 +181,48 @@
|
|||||||
},
|
},
|
||||||
/////////////////////////////////////// Bottom section - Towns Settings
|
/////////////////////////////////////// Bottom section - Towns Settings
|
||||||
{
|
{
|
||||||
"type" : "labelDescription",
|
"type" : "verticalLayout",
|
||||||
|
"customType" : "labelDescription",
|
||||||
|
"position": {"x": 45, "y": 325},
|
||||||
|
"items" : [
|
||||||
|
{
|
||||||
"text": "vcmi.otherOptions.creatureGrowthAsDwellingLabel.hover",
|
"text": "vcmi.otherOptions.creatureGrowthAsDwellingLabel.hover",
|
||||||
"position": {"x": 45, "y": 325}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type" : "labelDescription",
|
|
||||||
"text": "vcmi.otherOptions.availableCreaturesAsDwellingLabel.hover",
|
"text": "vcmi.otherOptions.availableCreaturesAsDwellingLabel.hover",
|
||||||
"position": {"x": 45, "y": 355}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type" : "labelDescription",
|
|
||||||
"text": "vcmi.otherOptions.compactTownCreatureInfo.hover",
|
"text": "vcmi.otherOptions.compactTownCreatureInfo.hover",
|
||||||
"position": {"x": 45, "y": 385}
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "availableCreaturesAsDwellingPicker",
|
"name": "availableCreaturesAsDwellingPicker",
|
||||||
"type": "toggleGroup",
|
"type": "toggleGroup",
|
||||||
|
"callback": "availableCreaturesAsDwellingChanged"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type" : "verticalLayout",
|
||||||
|
"customType" : "checkbox",
|
||||||
"position": {"x": 10, "y": 323},
|
"position": {"x": 10, "y": 323},
|
||||||
"items":
|
"items":
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": 0,
|
|
||||||
"type": "checkbox",
|
|
||||||
"help": "vcmi.otherOptions.creatureGrowthAsDwellingLabel",
|
"help": "vcmi.otherOptions.creatureGrowthAsDwellingLabel",
|
||||||
"position": {"x": 0, "y": 0}
|
"group" : "availableCreaturesAsDwellingPicker",
|
||||||
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"index": 1,
|
|
||||||
"type": "checkbox",
|
|
||||||
"help": "vcmi.otherOptions.availableCreaturesAsDwellingLabel",
|
"help": "vcmi.otherOptions.availableCreaturesAsDwellingLabel",
|
||||||
"position": {"x": 0, "y": 30}
|
"group" : "availableCreaturesAsDwellingPicker",
|
||||||
|
"index": 1
|
||||||
},
|
},
|
||||||
],
|
|
||||||
"callback": "availableCreaturesAsDwellingChanged"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "compactTownCreatureInfoCheckbox",
|
"name": "compactTownCreatureInfoCheckbox",
|
||||||
"type": "checkbox",
|
|
||||||
"help": "vcmi.otherOptions.compactTownCreatureInfo",
|
"help": "vcmi.otherOptions.compactTownCreatureInfo",
|
||||||
"position": {"x": 10, "y": 383},
|
|
||||||
"callback": "compactTownCreatureInfoChanged"
|
"callback": "compactTownCreatureInfoChanged"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user