2023-04-23 14:10:35 +02:00
|
|
|
/*
|
|
|
|
* CArtifactsOfHeroAltar.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CArtifactsOfHeroAltar.h"
|
|
|
|
|
2023-11-06 14:13:10 +02:00
|
|
|
#include "Buttons.h"
|
2023-04-23 14:10:35 +02:00
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
2023-05-17 15:52:16 +02:00
|
|
|
#include "../../lib/ArtifactUtils.h"
|
2023-04-23 14:10:35 +02:00
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
2023-10-23 15:38:05 +02:00
|
|
|
#include "../../lib/networkPacks/ArtifactLocation.h"
|
2023-04-23 14:10:35 +02:00
|
|
|
|
|
|
|
CArtifactsOfHeroAltar::CArtifactsOfHeroAltar(const Point & position)
|
|
|
|
: visibleArtSet(ArtBearer::ArtBearer::HERO)
|
|
|
|
{
|
|
|
|
init(
|
|
|
|
std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1),
|
|
|
|
std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1),
|
|
|
|
position,
|
|
|
|
std::bind(&CArtifactsOfHeroAltar::scrollBackpack, this, _1));
|
|
|
|
pickedArtFromSlot = ArtifactPosition::PRE_FIRST;
|
2023-11-06 14:13:10 +02:00
|
|
|
|
|
|
|
// The backpack is in the altar window above and to the right
|
|
|
|
for(auto & slot : backpack)
|
|
|
|
slot->moveBy(Point(2, -1));
|
|
|
|
leftBackpackRoll->moveBy(Point(2, -1));
|
|
|
|
rightBackpackRoll->moveBy(Point(2, -1));
|
2023-04-23 14:10:35 +02:00
|
|
|
};
|
|
|
|
|
2023-07-06 21:14:12 +02:00
|
|
|
CArtifactsOfHeroAltar::~CArtifactsOfHeroAltar()
|
|
|
|
{
|
|
|
|
putBackPickedArtifact();
|
|
|
|
}
|
|
|
|
|
2023-04-23 14:10:35 +02:00
|
|
|
void CArtifactsOfHeroAltar::setHero(const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
if(hero)
|
|
|
|
{
|
|
|
|
visibleArtSet.artifactsWorn = hero->artifactsWorn;
|
|
|
|
visibleArtSet.artifactsInBackpack = hero->artifactsInBackpack;
|
|
|
|
CArtifactsOfHeroBase::setHero(hero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::updateWornSlots()
|
|
|
|
{
|
|
|
|
for(auto place : artWorn)
|
|
|
|
setSlotData(getArtPlace(place.first), place.first, visibleArtSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::updateBackpackSlots()
|
|
|
|
{
|
|
|
|
for(auto artPlace : backpack)
|
|
|
|
setSlotData(getArtPlace(artPlace->slot), artPlace->slot, visibleArtSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::scrollBackpack(int offset)
|
|
|
|
{
|
|
|
|
CArtifactsOfHeroBase::scrollBackpackForArtSet(offset, visibleArtSet);
|
2023-09-03 20:41:00 +02:00
|
|
|
redraw();
|
2023-04-23 14:10:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::pickUpArtifact(CHeroArtPlace & artPlace)
|
|
|
|
{
|
|
|
|
if(const auto art = artPlace.getArt())
|
|
|
|
{
|
|
|
|
pickedArtFromSlot = artPlace.slot;
|
|
|
|
artPlace.setArtifact(nullptr);
|
|
|
|
deleteFromVisible(art);
|
|
|
|
if(ArtifactUtils::isSlotBackpack(pickedArtFromSlot))
|
|
|
|
pickedArtFromSlot = curHero->getSlotByInstance(art);
|
|
|
|
assert(pickedArtFromSlot != ArtifactPosition::PRE_FIRST);
|
2023-10-14 21:00:39 +02:00
|
|
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, pickedArtFromSlot), ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS));
|
2023-04-23 14:10:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc)
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
|
|
|
const auto pickedArtInst = curHero->getArt(ArtifactPosition::TRANSITION_POS);
|
|
|
|
assert(pickedArtInst);
|
|
|
|
visibleArtSet.putArtifact(dstLoc.slot, const_cast<CArtifactInstance*>(pickedArtInst));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::pickedArtMoveToAltar(const ArtifactPosition & slot)
|
|
|
|
{
|
|
|
|
if(ArtifactUtils::isSlotBackpack(slot) || ArtifactUtils::isSlotEquipment(slot) || slot == ArtifactPosition::TRANSITION_POS)
|
|
|
|
{
|
2023-05-17 16:05:09 +02:00
|
|
|
assert(curHero->getSlot(slot)->getArt());
|
2023-10-14 21:00:39 +02:00
|
|
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, slot), ArtifactLocation(curHero->id, pickedArtFromSlot));
|
2023-04-23 14:10:35 +02:00
|
|
|
pickedArtFromSlot = ArtifactPosition::PRE_FIRST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsOfHeroAltar::deleteFromVisible(const CArtifactInstance * artInst)
|
|
|
|
{
|
|
|
|
const auto slot = visibleArtSet.getSlotByInstance(artInst);
|
|
|
|
visibleArtSet.removeArtifact(slot);
|
|
|
|
if(ArtifactUtils::isSlotBackpack(slot))
|
|
|
|
{
|
|
|
|
scrollBackpackForArtSet(0, visibleArtSet);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-03 18:15:40 +02:00
|
|
|
for(const auto & part : artInst->getPartsInfo())
|
2023-04-23 14:10:35 +02:00
|
|
|
{
|
2023-06-18 14:21:35 +02:00
|
|
|
if(part.slot != ArtifactPosition::PRE_FIRST)
|
|
|
|
getArtPlace(part.slot)->setArtifact(nullptr);
|
2023-04-23 14:10:35 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-23 12:59:15 +02:00
|
|
|
}
|