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

Use kind-of-factory approach for widget builders

This commit is contained in:
nordsoft
2022-12-22 02:05:29 +04:00
parent 8f7025328f
commit e245dbaf9d
4 changed files with 34 additions and 62 deletions

View File

@ -399,6 +399,8 @@ TemplatesDropBox::TemplatesDropBox(RandomMapTab & randomMapTab, int3 size):
InterfaceObjectConfigurable(LCLICK | HOVER),
randomMapTab(randomMapTab)
{
REGISTER_BUILDER("templateListItem", &TemplatesDropBox::buildListItem);
curItems = VLC->tplh->getTemplates();
vstd::erase_if(curItems, [size](const CRmgTemplate * t){return !t->matchesSize(size);});
curItems.insert(curItems.begin(), nullptr); //default template
@ -422,16 +424,11 @@ TemplatesDropBox::TemplatesDropBox(RandomMapTab & randomMapTab, int3 size):
updateListItems();
}
std::shared_ptr<CIntObject> TemplatesDropBox::buildCustomWidget(const JsonNode & config)
std::shared_ptr<CIntObject> TemplatesDropBox::buildListItem(const JsonNode & config)
{
if(config["type"].String() == "templateListItem")
{
auto position = readPosition(config["position"]);
listItems.push_back(std::make_shared<ListItem>(config, *this, position));
return listItems.back();
}
return InterfaceObjectConfigurable::buildCustomWidget(config);
auto position = readPosition(config["position"]);
listItems.push_back(std::make_shared<ListItem>(config, *this, position));
return listItems.back();
}
void TemplatesDropBox::sliderMove(int slidPos)