1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

reworking slot selection

This commit is contained in:
SoundSSGood
2023-11-19 19:49:59 +02:00
parent 6c828d1be9
commit b246e24811
8 changed files with 103 additions and 47 deletions

View File

@@ -76,12 +76,10 @@ void CArtPlace::setInternals(const CArtifactInstance * artInst)
}
CArtPlace::CArtPlace(Point position, const CArtifactInstance * art)
: ourArt(art)
: SelectableSlot(Rect(position, Point(44, 44)), Point(1, 1))
, ourArt(art)
, locked(false)
{
pos += position;
pos.w = pos.h = 44;
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
imageIndex = 0;
@@ -92,9 +90,6 @@ CArtPlace::CArtPlace(Point position, const CArtifactInstance * art)
image = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), imageIndex);
image->disable();
selection = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), ArtifactID::ART_SELECTION, 0, -1, -1);
selection->visible = false;
}
const CArtifactInstance * CArtPlace::getArt()
@@ -170,16 +165,6 @@ bool CArtPlace::isLocked() const
return locked;
}
void CArtPlace::selectSlot(bool on)
{
selection->visible = on;
}
bool CArtPlace::isSelected() const
{
return selection->visible;
}
void CArtPlace::clickPressed(const Point & cursorPosition)
{
if(clickPressedCallback)
@@ -201,12 +186,6 @@ void CArtPlace::gesture(bool on, const Point & initialPosition, const Point & fi
gestureCallback(*this, initialPosition);
}
void CArtPlace::showAll(Canvas & to)
{
CIntObject::showAll(to);
selection->showAll(to);
}
void CArtPlace::setArtifact(const CArtifactInstance * art)
{
setInternals(art);

View File

@@ -29,7 +29,7 @@ public:
virtual void artifactAssembled(const ArtifactLocation & artLoc)=0;
};
class CArtPlace : public LRClickableAreaWTextComp
class CArtPlace : public LRClickableAreaWTextComp, public SelectableSlot
{
public:
using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
@@ -40,9 +40,6 @@ public:
const CArtifactInstance * getArt();
void lockSlot(bool on);
bool isLocked() const;
void selectSlot(bool on);
bool isSelected() const;
void showAll(Canvas & to) override;
void setArtifact(const CArtifactInstance * art);
void setClickPressedCallback(ClickFunctor callback);
void setShowPopupCallback(ClickFunctor callback);
@@ -55,7 +52,6 @@ protected:
std::shared_ptr<CAnimImage> image;
const CArtifactInstance * ourArt;
int imageIndex;
std::shared_ptr<CAnimImage> selection;
bool locked;
ClickFunctor clickPressedCallback;
ClickFunctor showPopupCallback;

View File

@@ -19,6 +19,11 @@ CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position)
std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2),
position,
std::bind(&CArtifactsOfHeroMarket::scrollBackpack, this, _1));
for(auto slot : artWorn)
slot.second->selection->lineWidth = 2;
for(auto slot : backpack)
slot->selection->lineWidth = 2;
};
void CArtifactsOfHeroMarket::scrollBackpack(int offset)

View File

@@ -9,6 +9,7 @@
*/
#include "StdInc.h"
#include "CTradeBase.h"
#include "MiscWidgets.h"
#include "../gui/CGuiHandler.h"
#include "../render/Canvas.h"
@@ -268,6 +269,7 @@ SResourcesPanel::SResourcesPanel(CTradeableItem::ClickPressedFunctor clickPresse
slots.emplace_back(std::make_shared<CTradeableItem>(slotsPos[res.num], EType::RESOURCE, res.num, true, res.num));
slots.back()->clickPressedCallback = clickPressedCallback;
slots.back()->pos.w = 69; slots.back()->pos.h = 66;
slots.back()->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[res.num], slots.back()->pos.dimensions()));
}
}
@@ -277,6 +279,12 @@ void SResourcesPanel::updateSlots()
updateSubtitles();
}
void SResourcesPanel::deselect()
{
for(auto & slot : slots)
slot->selection->selectSlot(false);
}
CTradeBase::CTradeBase(const IMarket * market, const CGHeroInstance * hero)
: market(market)
, hero(hero)

View File

@@ -17,6 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN
class IMarket;
class CGHeroInstance;
class SelectableSlot;
VCMI_LIB_NAMESPACE_END
@@ -50,7 +51,7 @@ public:
const CArtifactInstance * getArtInstance() const;
void setArtInstance(const CArtifactInstance * art);
CFunctionList<void()> callback;
std::unique_ptr<SelectableSlot> selection;
bool downSelection;
void showAllAt(const Point & dstPos, const std::string & customSub, Canvas & to);
@@ -84,6 +85,7 @@ struct SResourcesPanel : public CIntObject
SResourcesPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, updatePanelFunctor updateSubtitles);
void updateSlots();
void deselect();
};
class CTradeBase

View File

@@ -662,22 +662,37 @@ void CCreaturePic::setAmount(int newAmount)
}
TransparentFilledRectangle::TransparentFilledRectangle(Rect position, ColorRGBA color) :
color(color), colorLine(ColorRGBA()), drawLine(false)
color(color), colorLine(ColorRGBA()), drawLine(false), lineWidth(0)
{
pos = position + pos.topLeft();
}
TransparentFilledRectangle::TransparentFilledRectangle(Rect position, ColorRGBA color, ColorRGBA colorLine) :
color(color), colorLine(colorLine), drawLine(true)
TransparentFilledRectangle::TransparentFilledRectangle(Rect position, ColorRGBA color, ColorRGBA colorLine, int width) :
color(color), colorLine(colorLine), drawLine(true), lineWidth(width)
{
pos = position + pos.topLeft();
}
void TransparentFilledRectangle::setDrawBorder(bool on)
{
drawLine = on;
}
bool TransparentFilledRectangle::getDrawBorder()
{
return drawLine;
}
void TransparentFilledRectangle::setBorderWidth(int width)
{
lineWidth = width;
}
void TransparentFilledRectangle::showAll(Canvas & to)
{
to.drawColorBlended(pos, color);
if(drawLine)
to.drawBorder(pos, colorLine);
to.drawBorder(pos, colorLine, lineWidth);
}
SimpleLine::SimpleLine(Point pos1, Point pos2, ColorRGBA color) :
@@ -688,3 +703,32 @@ void SimpleLine::showAll(Canvas & to)
{
to.drawLine(pos1 + pos.topLeft(), pos2 + pos.topLeft(), color, color);
}
SelectableSlot::SelectableSlot(Rect area, Point oversize, const int width)
{
pos += area.topLeft();
pos.w = area.w; pos.h = area.h;
selection = std::make_unique<TransparentFilledRectangle>(
Rect(area.topLeft() - oversize, area.dimensions() + oversize * 2), Colors::TRANSPARENCY, Colors::YELLOW, width);
selectSlot(false);
}
SelectableSlot::SelectableSlot(Rect area, Point oversize)
: SelectableSlot(area, oversize, 1)
{
}
SelectableSlot::SelectableSlot(Rect area, const int width)
: SelectableSlot(area, Point(), width)
{
}
void SelectableSlot::selectSlot(bool on)
{
selection->setDrawBorder(on);
}
bool SelectableSlot::isSelected() const
{
return selection->getDrawBorder();
}

View File

@@ -252,9 +252,14 @@ class TransparentFilledRectangle : public CIntObject
ColorRGBA color;
ColorRGBA colorLine;
bool drawLine;
int lineWidth;
public:
TransparentFilledRectangle(Rect position, ColorRGBA color);
TransparentFilledRectangle(Rect position, ColorRGBA color, ColorRGBA colorLine);
TransparentFilledRectangle(Rect position, ColorRGBA color, ColorRGBA colorLine, int width = 1);
void setDrawBorder(bool on);
bool getDrawBorder();
void setBorderWidth(int width);
void showAll(Canvas & to) override;
};
@@ -267,3 +272,15 @@ public:
SimpleLine(Point pos1, Point pos2, ColorRGBA color);
void showAll(Canvas & to) override;
};
class SelectableSlot : virtual public CIntObject
{
public:
std::unique_ptr<TransparentFilledRectangle> selection;
SelectableSlot(Rect area, Point oversize, const int width);
SelectableSlot(Rect area, Point oversize);
SelectableSlot(Rect area, const int width = 1);
void selectSlot(bool on);
bool isSelected() const;
};

View File

@@ -90,10 +90,13 @@ void CTradeWindow::initItems(bool Left)
[this](std::shared_ptr<CTradeableItem> marketSlot) -> void
{
if(hLeft != marketSlot)
{
if(hLeft)
hLeft->selection->selectSlot(false);
hLeft = marketSlot;
else
return;
hLeft->selection->selectSlot(true);
selectionChanged(true);
}
},
[this]() -> void
{
@@ -110,11 +113,14 @@ void CTradeWindow::initItems(bool Left)
[this](std::shared_ptr<CTradeableItem> marketSlot) -> void
{
if(hRight != marketSlot)
{
if(hRight)
hRight->selection->selectSlot(false);
hRight = marketSlot;
else
return;
hRight->selection->selectSlot(true);
selectionChanged(false);
initSubs(false);
}
},
[this]() -> void
{
@@ -330,11 +336,6 @@ void CTradeWindow::showAll(Canvas & to)
{
CWindowObject::showAll(to);
if(hRight)
to.drawBorder(Rect::createAround(hRight->pos, 1), Colors::BRIGHT_YELLOW, 2);
if(hLeft && hLeft->type != ARTIFACT_INSTANCE)
to.drawBorder(Rect::createAround(hLeft->pos, 1), Colors::BRIGHT_YELLOW, 2);
if(readyToTrade)
{
if(hLeft)
@@ -589,6 +590,10 @@ void CMarketplaceWindow::makeDeal()
madeTransaction = true;
hLeft = nullptr;
hRight = nullptr;
if(resoursesPanelPlayer)
resoursesPanelPlayer->deselect();
if(resoursesPanelMarket)
resoursesPanelMarket->deselect();
selectionChanged(true);
}