From 1d4209d97ec09d4958a1588ed079f7acb076b60f Mon Sep 17 00:00:00 2001 From: nordsoft Date: Fri, 16 Dec 2022 00:57:10 +0400 Subject: [PATCH] Continue refactoring --- client/gui/InterfaceObjectConfigurable.cpp | 9 +++++++++ client/gui/InterfaceObjectConfigurable.h | 3 ++- client/lobby/RandomMapTab.cpp | 22 +++++++++++----------- client/lobby/RandomMapTab.h | 12 ++++++------ 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index ddce4753e..130cfec71 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -271,5 +271,14 @@ std::shared_ptr InterfaceObjectConfigurable::buildWidget(const JsonN { return buildLabelGroup(config); } + if(type == "custom") + { + return buildCustomWidget(config); + } return std::shared_ptr(nullptr); } + +std::shared_ptr InterfaceObjectConfigurable::buildCustomWidget(const JsonNode & config) const +{ + return nullptr; +} diff --git a/client/gui/InterfaceObjectConfigurable.h b/client/gui/InterfaceObjectConfigurable.h index 51f23d7be..cae184738 100644 --- a/client/gui/InterfaceObjectConfigurable.h +++ b/client/gui/InterfaceObjectConfigurable.h @@ -42,6 +42,8 @@ protected: return std::dynamic_pointer_cast(iter->second); } + virtual std::shared_ptr 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 buildWidget(const JsonNode & config) const; - private: std::map> widgets; diff --git a/client/lobby/RandomMapTab.cpp b/client/lobby/RandomMapTab.cpp index dca4cc604..37f6a8829 100644 --- a/client/lobby/RandomMapTab.cpp +++ b/client/lobby/RandomMapTab.cpp @@ -100,12 +100,12 @@ RandomMapTab::RandomMapTab(): //new callbacks available only from mod addCallback("templateSelection", [&](int) { - GH.pushIntT(this, int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()}); + GH.pushIntT(*this, int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()}); }); addCallback("teamAlignments", [&](int) { - GH.pushIntT(this); + GH.pushIntT(*this); }); for(auto road : VLC->terrainTypeHandler->roads()) @@ -302,7 +302,7 @@ std::vector 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("List10Bk", 158, 76); int positionsToShow = 10; for(int i = 0; i < positionsToShow; i++) - listItems.push_back(std::make_shared(this, Point(158, 76 + i * 25))); + listItems.push_back(std::make_shared(*this, Point(158, 76 + i * 25))); slider = std::make_shared(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) { diff --git a/client/lobby/RandomMapTab.h b/client/lobby/RandomMapTab.h index df6530142..aee146e1f 100644 --- a/client/lobby/RandomMapTab.h +++ b/client/lobby/RandomMapTab.h @@ -55,10 +55,10 @@ class TemplatesDropBox : public CIntObject { std::shared_ptr labelName; std::shared_ptr 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 background; std::vector> listItems; std::shared_ptr 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 background; std::shared_ptr labels;