mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Implement giving commander artifacts back to hero
This commit is contained in:
parent
baeb3c9e55
commit
96fa0fb6d4
@ -960,7 +960,7 @@ void CArtPlace::clickRight(tribool down, bool previousState)
|
|||||||
LRClickableAreaWTextComp::clickRight(down, previousState);
|
LRClickableAreaWTextComp::clickRight(down, previousState);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCommanderArtPlace::CCommanderArtPlace(Point position, const CArtifactInstance * Art) : CArtPlace(position, Art)
|
CCommanderArtPlace::CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * Art) : CArtPlace(position, Art), commanderOwner(commanderOwner), commanderSlotID(artSlot.num)
|
||||||
{
|
{
|
||||||
createImage();
|
createImage();
|
||||||
setArtifact(Art);
|
setArtifact(Art);
|
||||||
@ -968,8 +968,9 @@ CCommanderArtPlace::CCommanderArtPlace(Point position, const CArtifactInstance *
|
|||||||
|
|
||||||
void CCommanderArtPlace::clickLeft(tribool down, bool previousState)
|
void CCommanderArtPlace::clickLeft(tribool down, bool previousState)
|
||||||
{
|
{
|
||||||
if(ourArt && text.size())
|
if (down && ourArt && text.size())
|
||||||
CArtPlace::clickLeft(down, previousState);
|
LOCPLINT->showYesNoDialog("Do you want to give this artifact back to hero?", [this] { returnArtToHeroCallback(); }, [] {});
|
||||||
|
//CArtPlace::clickLeft(down, previousState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCommanderArtPlace::clickRight(tribool down, bool previousState)
|
void CCommanderArtPlace::clickRight(tribool down, bool previousState)
|
||||||
@ -991,6 +992,22 @@ void CCommanderArtPlace::createImage()
|
|||||||
image->disable();
|
image->disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCommanderArtPlace::returnArtToHeroCallback()
|
||||||
|
{
|
||||||
|
ArtifactPosition artifactPos = commanderSlotID;;
|
||||||
|
ArtifactPosition freeSlot = ourArt->firstBackpackSlot(commanderOwner);
|
||||||
|
|
||||||
|
ArtifactLocation src(commanderOwner->commander.get(), artifactPos);
|
||||||
|
ArtifactLocation dst(commanderOwner, freeSlot);
|
||||||
|
|
||||||
|
if (ourArt->canBePutAt(dst, true))
|
||||||
|
{
|
||||||
|
LOCPLINT->cb->swapArtifacts(src, dst);
|
||||||
|
setArtifact(nullptr);
|
||||||
|
parent->redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CCommanderArtPlace::setArtifact(const CArtifactInstance * art)
|
void CCommanderArtPlace::setArtifact(const CArtifactInstance * art)
|
||||||
{
|
{
|
||||||
baseType = -1; //by default we don't store any component
|
baseType = -1; //by default we don't store any component
|
||||||
|
@ -59,9 +59,13 @@ public:
|
|||||||
class CCommanderArtPlace : public CArtPlace
|
class CCommanderArtPlace : public CArtPlace
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
const CGHeroInstance * commanderOwner;
|
||||||
|
ArtifactPosition commanderSlotID;
|
||||||
|
|
||||||
void createImage() override;
|
void createImage() override;
|
||||||
|
void returnArtToHeroCallback();
|
||||||
public:
|
public:
|
||||||
CCommanderArtPlace(Point position, const CArtifactInstance * Art = nullptr); //c-tor
|
CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * Art = nullptr); //c-tor
|
||||||
void clickLeft(tribool down, bool previousState) override;
|
void clickLeft(tribool down, bool previousState) override;
|
||||||
void clickRight(tribool down, bool previousState) override;
|
void clickRight(tribool down, bool previousState) override;
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ void CStackWindow::CWindowSection::createCommander()
|
|||||||
{
|
{
|
||||||
Point artPos = getArtifactPos(equippedArtifact.first);
|
Point artPos = getArtifactPos(equippedArtifact.first);
|
||||||
//auto icon = new CClickableObject(new CAnimImage("artifact", equippedArtifact.second.artifact.get()->artType.get()->iconIndex, 0, artPos.x, artPos.y), [=] {});
|
//auto icon = new CClickableObject(new CAnimImage("artifact", equippedArtifact.second.artifact.get()->artType.get()->iconIndex, 0, artPos.x, artPos.y), [=] {});
|
||||||
auto icon = new CCommanderArtPlace(artPos, equippedArtifact.second.artifact);
|
auto icon = new CCommanderArtPlace(artPos, parent->info->owner, equippedArtifact.first, equippedArtifact.second.artifact);
|
||||||
|
|
||||||
//TODO: Use CArtPlace or equivalent instead of CClickableObject and handle commander artifact actions to match WOG (return artifact to hero etc.)
|
//TODO: Use CArtPlace or equivalent instead of CClickableObject and handle commander artifact actions to match WOG (return artifact to hero etc.)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user