mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-28 03:57:02 +02:00
Template selections works
This commit is contained in:
parent
f90cb1be90
commit
1e2abae62b
@ -28,6 +28,7 @@
|
|||||||
#include "../../lib/mapping/CMapInfo.h"
|
#include "../../lib/mapping/CMapInfo.h"
|
||||||
#include "../../lib/rmg/CMapGenOptions.h"
|
#include "../../lib/rmg/CMapGenOptions.h"
|
||||||
#include "../../lib/CModHandler.h"
|
#include "../../lib/CModHandler.h"
|
||||||
|
#include "../../lib/rmg/CRmgTemplateStorage.h"
|
||||||
|
|
||||||
RandomMapTab::RandomMapTab():
|
RandomMapTab::RandomMapTab():
|
||||||
InterfaceObjectConfigurable()
|
InterfaceObjectConfigurable()
|
||||||
@ -108,7 +109,7 @@ RandomMapTab::RandomMapTab():
|
|||||||
//new callbacks available only from mod
|
//new callbacks available only from mod
|
||||||
addCallback("templateSelection", [&](int)
|
addCallback("templateSelection", [&](int)
|
||||||
{
|
{
|
||||||
GH.pushInt(std::shared_ptr<TemplatesDropBox>(new TemplatesDropBox(mapGenOptions)));
|
GH.pushInt(std::make_shared<TemplatesDropBox>(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -190,6 +191,18 @@ void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> opts)
|
|||||||
w->setSelected(opts->getMonsterStrength());
|
w->setSelected(opts->getMonsterStrength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RandomMapTab::setTemplate(const CRmgTemplate * tmpl)
|
||||||
|
{
|
||||||
|
mapGenOptions->setMapTemplate(tmpl);
|
||||||
|
if(auto w = widget<CButton>("templateButton"))
|
||||||
|
{
|
||||||
|
if(tmpl)
|
||||||
|
w->addTextOverlay(tmpl->getName(), EFonts::FONT_SMALL);
|
||||||
|
else
|
||||||
|
w->addTextOverlay("default", EFonts::FONT_SMALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RandomMapTab::deactivateButtonsFrom(CToggleGroup * group, int startId)
|
void RandomMapTab::deactivateButtonsFrom(CToggleGroup * group, int startId)
|
||||||
{
|
{
|
||||||
logGlobal->debug("Blocking buttons from %d", startId);
|
logGlobal->debug("Blocking buttons from %d", startId);
|
||||||
@ -255,11 +268,12 @@ 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)
|
TemplatesDropBox::ListItem::ListItem(TemplatesDropBox * _dropBox, Point position)
|
||||||
: CIntObject(LCLICK | HOVER, position)
|
: CIntObject(LCLICK | HOVER, position),
|
||||||
|
dropBox(_dropBox)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
labelName = std::make_shared<CLabel>(0, 0, FONT_SMALL, EAlignment::TOPLEFT, Colors::WHITE, text);
|
labelName = std::make_shared<CLabel>(0, 0, FONT_SMALL, EAlignment::TOPLEFT, Colors::WHITE);
|
||||||
labelName->setAutoRedraw(false);
|
labelName->setAutoRedraw(false);
|
||||||
|
|
||||||
hoverImage = std::make_shared<CPicture>("List10Sl", 0, 0);
|
hoverImage = std::make_shared<CPicture>("List10Sl", 0, 0);
|
||||||
@ -270,26 +284,63 @@ TemplatesDropBox::ListItem::ListItem(Point position, const std::string & text)
|
|||||||
type |= REDRAW_PARENT;
|
type |= REDRAW_PARENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::ListItem::updateItem(int idx, const CRmgTemplate * _item)
|
||||||
|
{
|
||||||
|
item = _item;
|
||||||
|
if(item)
|
||||||
|
{
|
||||||
|
labelName->setText(item->getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(idx)
|
||||||
|
labelName->setText("");
|
||||||
|
else
|
||||||
|
labelName->setText("default");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TemplatesDropBox::ListItem::hover(bool on)
|
void TemplatesDropBox::ListItem::hover(bool on)
|
||||||
|
{
|
||||||
|
if(labelName->getText().empty())
|
||||||
|
{
|
||||||
|
hovered = false;
|
||||||
|
hoverImage->visible = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
hoverImage->visible = on;
|
hoverImage->visible = on;
|
||||||
|
}
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatesDropBox::TemplatesDropBox(std::shared_ptr<CMapGenOptions> options):
|
void TemplatesDropBox::ListItem::clickLeft(tribool down, bool previousState)
|
||||||
CIntObject(LCLICK | HOVER),
|
|
||||||
mapGenOptions(options)
|
|
||||||
{
|
{
|
||||||
|
if(down && hovered)
|
||||||
|
{
|
||||||
|
dropBox->setTemplate(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TemplatesDropBox::TemplatesDropBox(RandomMapTab * randomMapTab):
|
||||||
|
CIntObject(LCLICK | HOVER),
|
||||||
|
randomMapTab(randomMapTab)
|
||||||
|
{
|
||||||
|
curItems = VLC->tplh->getTemplates();
|
||||||
|
curItems.insert(curItems.begin(), nullptr); //default template
|
||||||
|
|
||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
background = std::make_shared<CPicture>("List10Bk", 158, 76);
|
background = std::make_shared<CPicture>("List10Bk", 158, 76);
|
||||||
|
|
||||||
int positionsToShow = 10;
|
int positionsToShow = 10;
|
||||||
|
|
||||||
for(int i = 0; i < positionsToShow; i++)
|
for(int i = 0; i < positionsToShow; i++)
|
||||||
listItems.push_back(std::make_shared<ListItem>(Point(158, 76 + i * 25), "test" + std::to_string(i)));
|
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, 20, 0, false, CSlider::BLUE);
|
slider = std::make_shared<CSlider>(Point(212 + 158, 76), 252, std::bind(&TemplatesDropBox::sliderMove, this, _1), positionsToShow, (int)curItems.size(), 0, false, CSlider::BLUE);
|
||||||
|
|
||||||
|
updateListItems();
|
||||||
pos = background->pos;
|
pos = background->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +348,7 @@ void TemplatesDropBox::sliderMove(int slidPos)
|
|||||||
{
|
{
|
||||||
if(!slider)
|
if(!slider)
|
||||||
return; // ignore spurious call when slider is being created
|
return; // ignore spurious call when slider is being created
|
||||||
//updateListItems();
|
updateListItems();
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,9 +359,33 @@ void TemplatesDropBox::hover(bool on)
|
|||||||
|
|
||||||
void TemplatesDropBox::clickLeft(tribool down, bool previousState)
|
void TemplatesDropBox::clickLeft(tribool down, bool previousState)
|
||||||
{
|
{
|
||||||
if(!hovered)
|
if(down && !hovered)
|
||||||
{
|
{
|
||||||
assert(GH.topInt().get() == this);
|
assert(GH.topInt().get() == this);
|
||||||
GH.popInt(GH.topInt());
|
GH.popInt(GH.topInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::updateListItems()
|
||||||
|
{
|
||||||
|
int elemIdx = slider->getValue();
|
||||||
|
for(auto item : listItems)
|
||||||
|
{
|
||||||
|
if(elemIdx < curItems.size())
|
||||||
|
{
|
||||||
|
item->updateItem(elemIdx, curItems[elemIdx]);
|
||||||
|
elemIdx++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item->updateItem(elemIdx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplatesDropBox::setTemplate(const CRmgTemplate * tmpl)
|
||||||
|
{
|
||||||
|
randomMapTab->setTemplate(tmpl);
|
||||||
|
assert(GH.topInt().get() == this);
|
||||||
|
GH.popInt(GH.topInt());
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "../../lib/FunctionList.h"
|
#include "../../lib/FunctionList.h"
|
||||||
#include "../../lib/GameConstants.h"
|
#include "../../lib/GameConstants.h"
|
||||||
|
#include "../../lib/rmg/CRmgTemplate.h"
|
||||||
#include "../gui/InterfaceObjectConfigurable.h"
|
#include "../gui/InterfaceObjectConfigurable.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
@ -33,6 +34,7 @@ public:
|
|||||||
|
|
||||||
void updateMapInfoByHost();
|
void updateMapInfoByHost();
|
||||||
void setMapGenOptions(std::shared_ptr<CMapGenOptions> opts);
|
void setMapGenOptions(std::shared_ptr<CMapGenOptions> opts);
|
||||||
|
void setTemplate(const CRmgTemplate *);
|
||||||
|
|
||||||
CFunctionList<void(std::shared_ptr<CMapInfo>, std::shared_ptr<CMapGenOptions>)> mapInfoChanged;
|
CFunctionList<void(std::shared_ptr<CMapInfo>, std::shared_ptr<CMapGenOptions>)> mapInfoChanged;
|
||||||
|
|
||||||
@ -52,26 +54,33 @@ class TemplatesDropBox : public CIntObject
|
|||||||
{
|
{
|
||||||
std::shared_ptr<CLabel> labelName;
|
std::shared_ptr<CLabel> labelName;
|
||||||
std::shared_ptr<CPicture> hoverImage;
|
std::shared_ptr<CPicture> hoverImage;
|
||||||
ListItem(Point position, const std::string & text);
|
TemplatesDropBox * dropBox;
|
||||||
void updateItem(int info = 0, bool selected = false);
|
const CRmgTemplate * item = nullptr;
|
||||||
|
|
||||||
void hover(bool on) override;
|
ListItem(TemplatesDropBox *, Point position);
|
||||||
};
|
void updateItem(int index, const CRmgTemplate * item = nullptr);
|
||||||
|
|
||||||
public:
|
|
||||||
TemplatesDropBox(std::shared_ptr<CMapGenOptions> options);
|
|
||||||
|
|
||||||
void hover(bool on) override;
|
void hover(bool on) override;
|
||||||
void clickLeft(tribool down, bool previousState) override;
|
void clickLeft(tribool down, bool previousState) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
TemplatesDropBox(RandomMapTab * randomMapTab);
|
||||||
|
|
||||||
|
void hover(bool on) override;
|
||||||
|
void clickLeft(tribool down, bool previousState) override;
|
||||||
|
void setTemplate(const CRmgTemplate *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void sliderMove(int slidPos);
|
void sliderMove(int slidPos);
|
||||||
|
void updateListItems();
|
||||||
|
|
||||||
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
RandomMapTab * randomMapTab;
|
||||||
|
|
||||||
std::shared_ptr<CPicture> background;
|
std::shared_ptr<CPicture> background;
|
||||||
std::vector<std::shared_ptr<ListItem>> listItems;
|
std::vector<std::shared_ptr<ListItem>> listItems;
|
||||||
std::shared_ptr<CSlider> slider;
|
std::shared_ptr<CSlider> slider;
|
||||||
|
|
||||||
|
std::vector<const CRmgTemplate *> curItems;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user