Skip to content
Permalink
Browse files

Correct placement for hero misc artifacts in kingdom overview

  • Loading branch information
alexvins committed Feb 14, 2015
1 parent c8a16bb commit 0b546a9b9fc448275cd49058509484b248c1574c
Showing with 51 additions and 29 deletions.
  1. +20 −23 client/widgets/CArtifactHolder.cpp
  2. +4 −3 client/widgets/CArtifactHolder.h
  3. +27 −3 client/windows/CKingdomInterface.cpp
@@ -281,8 +281,6 @@ void CArtPlace::select ()
}
}

//int backpackCorrection = -(slotID - Arts::BACKPACK_START < ourOwner->backpackPos);

CCS->curh->dragAndDropCursor(new CAnimImage("artifact", ourArt->artType->iconIndex));
ourOwner->commonInfo->src.setTo(this, false);
ourOwner->markPossibleSlots(ourArt);
@@ -353,7 +351,7 @@ bool CArtPlace::fitsHere(const CArtifactInstance * art) const
if(!art)
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)
return !CGI->arth->isBigArtifact(art->artType->id);

@@ -456,15 +454,17 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
backpackPos = 0;

// 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);
}

void CArtifactsOfHero::dispose()
{
//vstd::clear_pointer(curHero);
//unmarkSlots(false);
CCS->curh->dragAndDropCursor(nullptr);
}

@@ -540,8 +540,8 @@ void CArtifactsOfHero::scrollBackpack(int dir)
void CArtifactsOfHero::markPossibleSlots(const CArtifactInstance* art)
{
for(CArtifactsOfHero *aoh : commonInfo->participants)
for(CArtPlace *place : aoh->artWorn)
place->selectSlot(art->canBePutAt(ArtifactLocation(aoh->curHero, place->slotID), true));
for(auto p : aoh->artWorn)
p.second->selectSlot(art->canBePutAt(ArtifactLocation(aoh->curHero, p.second->slotID), true));

safeRedraw();
}
@@ -563,8 +563,8 @@ void CArtifactsOfHero::unmarkSlots(bool withRedraw /*= true*/)

void CArtifactsOfHero::unmarkLocalSlots(bool withRedraw /*= true*/)
{
for(CArtPlace *place : artWorn)
place->selectSlot(false);
for(auto p : artWorn)
p.second->selectSlot(false);
for(CArtPlace *place : backpack)
place->selectSlot(false);

@@ -604,7 +604,7 @@ void CArtifactsOfHero::eraseSlotData (CArtPlace* artPlace, ArtifactPosition slot
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):

curHero(nullptr),
@@ -620,10 +620,10 @@ CArtifactsOfHero::CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector
}

// Init slots for worn artifacts.
for (size_t g = 0; g < artWorn.size() ; g++)
for (auto p : artWorn)
{
artWorn[g]->ourOwner = this;
eraseSlotData(artWorn[g], ArtifactPosition(g));
p.second->ourOwner = this;
eraseSlotData(p.second, p.first);
}

// Init slots for the backpack.
@@ -648,7 +648,6 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart

OBJ_CONSTRUCTION_CAPTURING_ALL;
pos += position;
artWorn.resize(GameConstants::BACKPACK_START);

std::vector<Point> slotPos =
{
@@ -841,9 +840,9 @@ CArtPlace * CArtifactsOfHero::getArtPlace(int slot)
{
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;
}

@@ -854,9 +853,8 @@ CArtPlace * CArtifactsOfHero::getArtPlace(int slot)
for(CArtPlace *ap : backpack)
if(ap->slotID == slot)
return ap;
return nullptr;
}

return nullptr;
}

void CArtifactsOfHero::artifactAssembled(const ArtifactLocation &al)
@@ -873,9 +871,8 @@ void CArtifactsOfHero::artifactDisassembled(const ArtifactLocation &al)

void CArtifactsOfHero::updateWornSlots(bool redrawParent /*= true*/)
{
for(int i = 0; i < artWorn.size(); i++)
updateSlot(ArtifactPosition(i));

for(auto p : artWorn)
updateSlot(p.first);

if(redrawParent)
updateParentWindow();
@@ -80,8 +80,9 @@ class CArtPlace: public LRClickableAreaWTextComp
class CArtifactsOfHero : public CIntObject
{
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!)
int backpackPos; //number of first art visible in backpack (in hero's vector)

@@ -137,7 +138,7 @@ class CArtifactsOfHero : public CIntObject

CArtifactsOfHero(const Point& position, bool createCommonPart = false);
//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);
~CArtifactsOfHero(); //d-tor
void updateParentWindow();
@@ -879,10 +879,34 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart *
backpack->recActions = DISPOSE | SHARE_POS;

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->commonInfo = artsCommonPart;

0 comments on commit 0b546a9

Please sign in to comment.
You can’t perform that action at this time.