1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Continue refactoring

This commit is contained in:
nordsoft 2022-12-16 00:57:10 +04:00
parent 2371e3e9a2
commit 1d4209d97e
4 changed files with 28 additions and 18 deletions

View File

@ -271,5 +271,14 @@ std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildWidget(const JsonN
{
return buildLabelGroup(config);
}
if(type == "custom")
{
return buildCustomWidget(config);
}
return std::shared_ptr<CIntObject>(nullptr);
}
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildCustomWidget(const JsonNode & config) const
{
return nullptr;
}

View File

@ -42,6 +42,8 @@ protected:
return std::dynamic_pointer_cast<T>(iter->second);
}
virtual std::shared_ptr<CIntObject> buildCustomWidget(const JsonNode & config) const;
private: //field deserializers
//basic serializers
Point readPosition(const JsonNode &) const;
@ -62,7 +64,6 @@ private: //field deserializers
std::shared_ptr<CIntObject> buildWidget(const JsonNode & config) const;
private:
std::map<std::string, std::shared_ptr<CIntObject>> widgets;

View File

@ -100,12 +100,12 @@ RandomMapTab::RandomMapTab():
//new callbacks available only from mod
addCallback("templateSelection", [&](int)
{
GH.pushIntT<TemplatesDropBox>(this, int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()});
GH.pushIntT<TemplatesDropBox>(*this, int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()});
});
addCallback("teamAlignments", [&](int)
{
GH.pushIntT<TeamAlignmentsWidget>(this);
GH.pushIntT<TeamAlignmentsWidget>(*this);
});
for(auto road : VLC->terrainTypeHandler->roads())
@ -302,7 +302,7 @@ std::vector<int> RandomMapTab::getPossibleMapSizes()
return {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_GIANT};
}
TemplatesDropBox::ListItem::ListItem(TemplatesDropBox * _dropBox, Point position)
TemplatesDropBox::ListItem::ListItem(TemplatesDropBox & _dropBox, Point position)
: CIntObject(LCLICK | HOVER, position),
dropBox(_dropBox)
{
@ -352,12 +352,12 @@ void TemplatesDropBox::ListItem::clickLeft(tribool down, bool previousState)
{
if(down && hovered)
{
dropBox->setTemplate(item);
dropBox.setTemplate(item);
}
}
TemplatesDropBox::TemplatesDropBox(RandomMapTab * randomMapTab, int3 size):
TemplatesDropBox::TemplatesDropBox(RandomMapTab & randomMapTab, int3 size):
CIntObject(LCLICK | HOVER),
randomMapTab(randomMapTab)
{
@ -366,15 +366,15 @@ TemplatesDropBox::TemplatesDropBox(RandomMapTab * randomMapTab, int3 size):
curItems.insert(curItems.begin(), nullptr); //default template
OBJ_CONSTRUCTION;
pos = randomMapTab->pos.topLeft();
pos.w = randomMapTab->pos.w;
pos.h = randomMapTab->pos.h;
pos = randomMapTab.pos.topLeft();
pos.w = randomMapTab.pos.w;
pos.h = randomMapTab.pos.h;
background = std::make_shared<CPicture>("List10Bk", 158, 76);
int positionsToShow = 10;
for(int i = 0; i < positionsToShow; i++)
listItems.push_back(std::make_shared<ListItem>(this, Point(158, 76 + i * 25)));
listItems.push_back(std::make_shared<ListItem>(*this, Point(158, 76 + i * 25)));
slider = std::make_shared<CSlider>(Point(212 + 158, 76), 252, std::bind(&TemplatesDropBox::sliderMove, this, _1), positionsToShow, (int)curItems.size(), 0, false, CSlider::BLUE);
@ -422,12 +422,12 @@ void TemplatesDropBox::updateListItems()
void TemplatesDropBox::setTemplate(const CRmgTemplate * tmpl)
{
randomMapTab->setTemplate(tmpl);
randomMapTab.setTemplate(tmpl);
assert(GH.topInt().get() == this);
GH.popInt(GH.topInt());
}
TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab * randomMapTab):
TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
CIntObject(),
randomMapTab(randomMapTab)
{

View File

@ -55,10 +55,10 @@ class TemplatesDropBox : public CIntObject
{
std::shared_ptr<CLabel> labelName;
std::shared_ptr<CPicture> hoverImage;
TemplatesDropBox * dropBox;
TemplatesDropBox & dropBox;
const CRmgTemplate * item = nullptr;
ListItem(TemplatesDropBox *, Point position);
ListItem(TemplatesDropBox &, Point position);
void updateItem(int index, const CRmgTemplate * item = nullptr);
void hover(bool on) override;
@ -66,7 +66,7 @@ class TemplatesDropBox : public CIntObject
};
public:
TemplatesDropBox(RandomMapTab * randomMapTab, int3 size);
TemplatesDropBox(RandomMapTab & randomMapTab, int3 size);
void hover(bool on) override;
void clickLeft(tribool down, bool previousState) override;
@ -77,7 +77,7 @@ private:
void sliderMove(int slidPos);
void updateListItems();
RandomMapTab * randomMapTab;
RandomMapTab & randomMapTab;
std::shared_ptr<CPicture> background;
std::vector<std::shared_ptr<ListItem>> listItems;
std::shared_ptr<CSlider> slider;
@ -89,11 +89,11 @@ private:
class TeamAlignmentsWidget: public CIntObject
{
public:
TeamAlignmentsWidget(RandomMapTab * randomMapTab);
TeamAlignmentsWidget(RandomMapTab & randomMapTab);
private:
RandomMapTab * randomMapTab;
RandomMapTab & randomMapTab;
std::shared_ptr<CFilledTexture> background;
std::shared_ptr<CLabelGroup> labels;