mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +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("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
|
||||
REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
|
||||
REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// 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
|
||||
{
|
||||
logGlobal->debug("Building widget CShowableAnim");
|
||||
|
@ -93,6 +93,7 @@ protected:
|
||||
std::shared_ptr<CAnimImage> buildImage(const JsonNode &) const;
|
||||
std::shared_ptr<CShowableAnim> buildAnimation(const JsonNode &) const;
|
||||
std::shared_ptr<CFilledTexture> buildTexture(const JsonNode &) const;
|
||||
std::shared_ptr<CIntObject> buildLayout(const JsonNode &);
|
||||
|
||||
//composite widgets
|
||||
std::shared_ptr<CIntObject> buildWidget(JsonNode config) const;
|
||||
|
@ -43,6 +43,12 @@
|
||||
"orientation": "horizontal",
|
||||
"itemsVisible": 0,
|
||||
"itemsTotal": 100,
|
||||
},
|
||||
"verticalLayout" : {
|
||||
"type" : "layout",
|
||||
"vertical" : true,
|
||||
"dynamic" : false,
|
||||
"distance" : 30
|
||||
}
|
||||
},
|
||||
|
||||
@ -54,7 +60,6 @@
|
||||
"image": "settingsWindow/lineHorizontal",
|
||||
"rect": { "x" : 5, "y" : 289, "w": 365, "h": 3}
|
||||
},
|
||||
|
||||
{
|
||||
"type" : "labelTitle",
|
||||
"position": {"x": 10, "y": 55},
|
||||
@ -71,69 +76,64 @@
|
||||
"text": "vcmi.systemOptions.townsGroup"
|
||||
},
|
||||
/////////////////////////////////////// Left section - Video Settings
|
||||
{
|
||||
"type" : "verticalLayout",
|
||||
"customType" : "labelDescription",
|
||||
"position" : {"x": 45, "y": 85},
|
||||
"items" : [
|
||||
{
|
||||
"name": "resolutionLabel",
|
||||
"type": "labelDescription",
|
||||
"position": {"x": 45, "y": 85},
|
||||
"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",
|
||||
"type": "buttonGear",
|
||||
"position": {"x": 10, "y": 83},
|
||||
"help": "vcmi.systemOptions.resolutionButton",
|
||||
"callback": "setGameResolution",
|
||||
},
|
||||
|
||||
{
|
||||
"name": "scalingLabel",
|
||||
"type": "labelDescription",
|
||||
"position": {"x": 45, "y": 115},
|
||||
"text": "vcmi.systemOptions.scalingButton.hover"
|
||||
},
|
||||
{
|
||||
"name": "scalingButton",
|
||||
"type": "buttonGear",
|
||||
"position": {"x": 10, "y": 113},
|
||||
"help": "vcmi.systemOptions.scalingButton",
|
||||
"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",
|
||||
"type": "checkbox",
|
||||
"help": "vcmi.systemOptions.fullscreenButton",
|
||||
"position": {"x": 10, "y": 143},
|
||||
"callback": "fullscreenChanged"
|
||||
},
|
||||
{
|
||||
"name": "framerateCheckbox",
|
||||
"type": "checkbox",
|
||||
"help": "vcmi.systemOptions.framerateButton",
|
||||
"position": {"x": 10, "y": 173},
|
||||
"callback": "framerateChanged"
|
||||
},
|
||||
{
|
||||
"name": "spellbookAnimationCheckbox",
|
||||
"type": "checkbox",
|
||||
"help": "core.help.364",
|
||||
"position": {"x": 10, "y": 203},
|
||||
"callback": "spellbookAnimationChanged"
|
||||
},
|
||||
]
|
||||
},
|
||||
/////////////////////////////////////// Right section - Audio Settings
|
||||
{
|
||||
"type" : "labelAudio",
|
||||
@ -181,49 +181,48 @@
|
||||
},
|
||||
/////////////////////////////////////// Bottom section - Towns Settings
|
||||
{
|
||||
"type" : "labelDescription",
|
||||
"type" : "verticalLayout",
|
||||
"customType" : "labelDescription",
|
||||
"position": {"x": 45, "y": 325},
|
||||
"items" : [
|
||||
{
|
||||
"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}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "availableCreaturesAsDwellingPicker",
|
||||
"type": "toggleGroup",
|
||||
"callback": "availableCreaturesAsDwellingChanged"
|
||||
},
|
||||
{
|
||||
"type" : "verticalLayout",
|
||||
"customType" : "checkbox",
|
||||
"position": {"x": 10, "y": 323},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 0,
|
||||
"type": "checkbox",
|
||||
"help": "vcmi.otherOptions.creatureGrowthAsDwellingLabel",
|
||||
"position": {"x": 0, "y": 0}
|
||||
"group" : "availableCreaturesAsDwellingPicker",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"type": "checkbox",
|
||||
"help": "vcmi.otherOptions.availableCreaturesAsDwellingLabel",
|
||||
"position": {"x": 0, "y": 30}
|
||||
"group" : "availableCreaturesAsDwellingPicker",
|
||||
"index": 1
|
||||
},
|
||||
],
|
||||
"callback": "availableCreaturesAsDwellingChanged"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "compactTownCreatureInfoCheckbox",
|
||||
"type": "checkbox",
|
||||
"help": "vcmi.otherOptions.compactTownCreatureInfo",
|
||||
"position": {"x": 10, "y": 383},
|
||||
"callback": "compactTownCreatureInfoChanged"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user