1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Correct placement for hero misc artifacts in kingdom overview

This commit is contained in:
AlexVinS 2015-02-14 18:34:27 +03:00
parent c8a16bb324
commit 0b546a9b9f
3 changed files with 51 additions and 29 deletions

View File

@ -281,8 +281,6 @@ void CArtPlace::select ()
} }
} }
//int backpackCorrection = -(slotID - Arts::BACKPACK_START < ourOwner->backpackPos);
CCS->curh->dragAndDropCursor(new CAnimImage("artifact", ourArt->artType->iconIndex)); CCS->curh->dragAndDropCursor(new CAnimImage("artifact", ourArt->artType->iconIndex));
ourOwner->commonInfo->src.setTo(this, false); ourOwner->commonInfo->src.setTo(this, false);
ourOwner->markPossibleSlots(ourArt); ourOwner->markPossibleSlots(ourArt);
@ -353,7 +351,7 @@ bool CArtPlace::fitsHere(const CArtifactInstance * art) const
if(!art) if(!art)
return true; return true;
// Anything can but War Machines can be placed in backpack. // Anything but War Machines can be placed in backpack.
if (slotID >= GameConstants::BACKPACK_START) if (slotID >= GameConstants::BACKPACK_START)
return !CGI->arth->isBigArtifact(art->artType->id); return !CGI->arth->isBigArtifact(art->artType->id);
@ -456,15 +454,17 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
backpackPos = 0; backpackPos = 0;
// Fill the slots for worn artifacts and backpack. // Fill the slots for worn artifacts and backpack.
for (int g = 0; g < artWorn.size() ; g++)
setSlotData(artWorn[g], ArtifactPosition(g)); for(auto p : artWorn)
{
setSlotData(p.second, p.first);
}
scrollBackpack(0); scrollBackpack(0);
} }
void CArtifactsOfHero::dispose() void CArtifactsOfHero::dispose()
{ {
//vstd::clear_pointer(curHero);
//unmarkSlots(false);
CCS->curh->dragAndDropCursor(nullptr); CCS->curh->dragAndDropCursor(nullptr);
} }
@ -540,8 +540,8 @@ void CArtifactsOfHero::scrollBackpack(int dir)
void CArtifactsOfHero::markPossibleSlots(const CArtifactInstance* art) void CArtifactsOfHero::markPossibleSlots(const CArtifactInstance* art)
{ {
for(CArtifactsOfHero *aoh : commonInfo->participants) for(CArtifactsOfHero *aoh : commonInfo->participants)
for(CArtPlace *place : aoh->artWorn) for(auto p : aoh->artWorn)
place->selectSlot(art->canBePutAt(ArtifactLocation(aoh->curHero, place->slotID), true)); p.second->selectSlot(art->canBePutAt(ArtifactLocation(aoh->curHero, p.second->slotID), true));
safeRedraw(); safeRedraw();
} }
@ -563,8 +563,8 @@ void CArtifactsOfHero::unmarkSlots(bool withRedraw /*= true*/)
void CArtifactsOfHero::unmarkLocalSlots(bool withRedraw /*= true*/) void CArtifactsOfHero::unmarkLocalSlots(bool withRedraw /*= true*/)
{ {
for(CArtPlace *place : artWorn) for(auto p : artWorn)
place->selectSlot(false); p.second->selectSlot(false);
for(CArtPlace *place : backpack) for(CArtPlace *place : backpack)
place->selectSlot(false); place->selectSlot(false);
@ -604,7 +604,7 @@ void CArtifactsOfHero::eraseSlotData (CArtPlace* artPlace, ArtifactPosition slot
artPlace->setArtifact(nullptr); artPlace->setArtifact(nullptr);
} }
CArtifactsOfHero::CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack, CArtifactsOfHero::CArtifactsOfHero(std::map<ArtifactPosition, CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
CButton *leftScroll, CButton *rightScroll, bool createCommonPart): CButton *leftScroll, CButton *rightScroll, bool createCommonPart):
curHero(nullptr), curHero(nullptr),
@ -620,10 +620,10 @@ CArtifactsOfHero::CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector
} }
// Init slots for worn artifacts. // Init slots for worn artifacts.
for (size_t g = 0; g < artWorn.size() ; g++) for (auto p : artWorn)
{ {
artWorn[g]->ourOwner = this; p.second->ourOwner = this;
eraseSlotData(artWorn[g], ArtifactPosition(g)); eraseSlotData(p.second, p.first);
} }
// Init slots for the backpack. // Init slots for the backpack.
@ -648,7 +648,6 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
pos += position; pos += position;
artWorn.resize(GameConstants::BACKPACK_START);
std::vector<Point> slotPos = std::vector<Point> slotPos =
{ {
@ -841,9 +840,9 @@ CArtPlace * CArtifactsOfHero::getArtPlace(int slot)
{ {
if(slot < GameConstants::BACKPACK_START) if(slot < GameConstants::BACKPACK_START)
{ {
if(slot >= artWorn.size() || slot < 0) if(artWorn.find(slot) == artWorn.end())
{ {
logGlobal->errorStream() << "CArtifactsOfHero::getArtPlace: invalid slot " << slot << "; maximum is " << artWorn.size()-1; logGlobal->errorStream() << "CArtifactsOfHero::getArtPlace: invalid slot " << slot;
return nullptr; return nullptr;
} }
@ -854,9 +853,8 @@ CArtPlace * CArtifactsOfHero::getArtPlace(int slot)
for(CArtPlace *ap : backpack) for(CArtPlace *ap : backpack)
if(ap->slotID == slot) if(ap->slotID == slot)
return ap; return ap;
return nullptr;
} }
return nullptr;
} }
void CArtifactsOfHero::artifactAssembled(const ArtifactLocation &al) void CArtifactsOfHero::artifactAssembled(const ArtifactLocation &al)
@ -873,9 +871,8 @@ void CArtifactsOfHero::artifactDisassembled(const ArtifactLocation &al)
void CArtifactsOfHero::updateWornSlots(bool redrawParent /*= true*/) void CArtifactsOfHero::updateWornSlots(bool redrawParent /*= true*/)
{ {
for(int i = 0; i < artWorn.size(); i++) for(auto p : artWorn)
updateSlot(ArtifactPosition(i)); updateSlot(p.first);
if(redrawParent) if(redrawParent)
updateParentWindow(); updateParentWindow();

View File

@ -80,8 +80,9 @@ public:
class CArtifactsOfHero : public CIntObject class CArtifactsOfHero : public CIntObject
{ {
const CGHeroInstance * curHero; const CGHeroInstance * curHero;
std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 std::map<ArtifactPosition, CArtPlace *> artWorn;
std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!) std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
int backpackPos; //number of first art visible in backpack (in hero's vector) int backpackPos; //number of first art visible in backpack (in hero's vector)
@ -137,7 +138,7 @@ public:
CArtifactsOfHero(const Point& position, bool createCommonPart = false); CArtifactsOfHero(const Point& position, bool createCommonPart = false);
//Alternative constructor, used if custom artifacts positioning required (Kingdom interface) //Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack, CArtifactsOfHero(std::map<ArtifactPosition, CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
CButton *leftScroll, CButton *rightScroll, bool createCommonPart = false); CButton *leftScroll, CButton *rightScroll, bool createCommonPart = false);
~CArtifactsOfHero(); //d-tor ~CArtifactsOfHero(); //d-tor
void updateParentWindow(); void updateParentWindow();

View File

@ -879,10 +879,34 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart *
backpack->recActions = DISPOSE | SHARE_POS; backpack->recActions = DISPOSE | SHARE_POS;
name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, Colors::WHITE, hero->name); name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, Colors::WHITE, hero->name);
//layout is not trivial: MACH4 - catapult - excluded, MISC[x] rearranged
assert(arts1->arts.size() == 9);
assert(arts2->arts.size() == 9);
std::map<ArtifactPosition, CArtPlace*> arts =
{
{ArtifactPosition::HEAD, arts1->arts[0]},
{ArtifactPosition::SHOULDERS,arts1->arts[1]},
{ArtifactPosition::NECK,arts1->arts[2]},
{ArtifactPosition::RIGHT_HAND,arts1->arts[3]},
{ArtifactPosition::LEFT_HAND,arts1->arts[4]},
{ArtifactPosition::TORSO, arts1->arts[5]},
{ArtifactPosition::RIGHT_RING,arts1->arts[6]},
{ArtifactPosition::LEFT_RING, arts1->arts[7]},
{ArtifactPosition::FEET, arts1->arts[8]},
{ArtifactPosition::MISC1, arts2->arts[0]},
{ArtifactPosition::MISC2, arts2->arts[1]},
{ArtifactPosition::MISC3, arts2->arts[2]},
{ArtifactPosition::MISC4, arts2->arts[3]},
{ArtifactPosition::MISC5, arts2->arts[4]},
{ArtifactPosition::MACH1, arts2->arts[5]},
{ArtifactPosition::MACH2, arts2->arts[6]},
{ArtifactPosition::MACH3, arts2->arts[7]},
{ArtifactPosition::SPELLBOOK, arts2->arts[8]}
};
std::vector<CArtPlace*> arts;
arts.insert(arts.end(), arts1->arts.begin(), arts1->arts.end());
arts.insert(arts.end(), arts2->arts.begin(), arts2->arts.end());
heroArts = new CArtifactsOfHero(arts, backpack->arts, backpack->btnLeft, backpack->btnRight, false); heroArts = new CArtifactsOfHero(arts, backpack->arts, backpack->btnLeft, backpack->btnRight, false);
heroArts->commonInfo = artsCommonPart; heroArts->commonInfo = artsCommonPart;