mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Template list prototype looks fine
This commit is contained in:
@@ -179,6 +179,15 @@ std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildWidget(const JsonN
|
|||||||
if(!config["zelp"].isNull())
|
if(!config["zelp"].isNull())
|
||||||
zelp = CGI->generaltexth->zelp[config["zelp"].Integer()];
|
zelp = CGI->generaltexth->zelp[config["zelp"].Integer()];
|
||||||
auto button = std::make_shared<CButton>(Point(x, y), image, zelp);
|
auto button = std::make_shared<CButton>(Point(x, y), image, zelp);
|
||||||
|
if(!config["items"].isNull())
|
||||||
|
{
|
||||||
|
for(const auto & item : config["items"].Vector())
|
||||||
|
{
|
||||||
|
button->addOverlay(buildWidget(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!config["callback"].isNull())
|
||||||
|
button->addCallback(std::bind(callbacks[config["callback"].String()], 0));
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
if(type == "labelGroup")
|
if(type == "labelGroup")
|
||||||
|
|||||||
@@ -105,6 +105,13 @@ RandomMapTab::RandomMapTab():
|
|||||||
updateMapInfoByHost();
|
updateMapInfoByHost();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//new callbacks available only from mod
|
||||||
|
addCallback("templateSelection", [&](int)
|
||||||
|
{
|
||||||
|
GH.pushInt(std::shared_ptr<TemplatesDropBox>(new TemplatesDropBox(mapGenOptions)));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
init(config);
|
init(config);
|
||||||
|
|
||||||
updateMapInfoByHost();
|
updateMapInfoByHost();
|
||||||
@@ -247,3 +254,63 @@ 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};
|
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(Point position, const std::string & text)
|
||||||
|
: CIntObject(LCLICK | HOVER, position)
|
||||||
|
{
|
||||||
|
OBJ_CONSTRUCTION;
|
||||||
|
labelName = std::make_shared<CLabel>(0, 0, FONT_SMALL, EAlignment::TOPLEFT, Colors::WHITE, text);
|
||||||
|
labelName->setAutoRedraw(false);
|
||||||
|
|
||||||
|
hoverImage = std::make_shared<CPicture>("List10Sl", 0, 0);
|
||||||
|
hoverImage->visible = false;
|
||||||
|
|
||||||
|
pos.w = hoverImage->pos.w;
|
||||||
|
pos.h = hoverImage->pos.h;
|
||||||
|
type |= REDRAW_PARENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::ListItem::hover(bool on)
|
||||||
|
{
|
||||||
|
hoverImage->visible = on;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplatesDropBox::TemplatesDropBox(std::shared_ptr<CMapGenOptions> options):
|
||||||
|
CIntObject(LCLICK | HOVER),
|
||||||
|
mapGenOptions(options)
|
||||||
|
{
|
||||||
|
OBJ_CONSTRUCTION;
|
||||||
|
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>(Point(158, 76 + i * 25), "test" + std::to_string(i)));
|
||||||
|
|
||||||
|
slider = std::make_shared<CSlider>(Point(212 + 158, 76), 252, std::bind(&TemplatesDropBox::sliderMove, this, _1), positionsToShow, 20, 0, false, CSlider::BLUE);
|
||||||
|
|
||||||
|
pos = background->pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::sliderMove(int slidPos)
|
||||||
|
{
|
||||||
|
if(!slider)
|
||||||
|
return; // ignore spurious call when slider is being created
|
||||||
|
//updateListItems();
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::hover(bool on)
|
||||||
|
{
|
||||||
|
hovered = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::clickLeft(tribool down, bool previousState)
|
||||||
|
{
|
||||||
|
if(!hovered)
|
||||||
|
{
|
||||||
|
assert(GH.topInt().get() == this);
|
||||||
|
GH.popInt(GH.topInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
class CToggleButton;
|
class CToggleButton;
|
||||||
class CLabel;
|
class CLabel;
|
||||||
class CLabelGroup;
|
class CLabelGroup;
|
||||||
|
class CSlider;
|
||||||
|
|
||||||
class RandomMapTab : public InterfaceObjectConfigurable
|
class RandomMapTab : public InterfaceObjectConfigurable
|
||||||
{
|
{
|
||||||
@@ -44,3 +45,33 @@ private:
|
|||||||
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
||||||
std::shared_ptr<CMapInfo> mapInfo;
|
std::shared_ptr<CMapInfo> mapInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TemplatesDropBox : public CIntObject
|
||||||
|
{
|
||||||
|
struct ListItem : public CIntObject
|
||||||
|
{
|
||||||
|
std::shared_ptr<CLabel> labelName;
|
||||||
|
std::shared_ptr<CPicture> hoverImage;
|
||||||
|
ListItem(Point position, const std::string & text);
|
||||||
|
void updateItem(int info = 0, bool selected = false);
|
||||||
|
|
||||||
|
void hover(bool on) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
TemplatesDropBox(std::shared_ptr<CMapGenOptions> options);
|
||||||
|
|
||||||
|
void hover(bool on) override;
|
||||||
|
void clickLeft(tribool down, bool previousState) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void sliderMove(int slidPos);
|
||||||
|
|
||||||
|
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
||||||
|
|
||||||
|
std::shared_ptr<CPicture> background;
|
||||||
|
std::vector<std::shared_ptr<ListItem>> listItems;
|
||||||
|
std::shared_ptr<CSlider> slider;
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user