1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Exchanging artifacts between slots should work again nicely. Minor fixes.

This commit is contained in:
Michał W. Urbańczyk 2010-07-21 19:50:15 +00:00
parent a8bb13cbcd
commit 2f996f14ba
6 changed files with 57 additions and 37 deletions

View File

@ -216,6 +216,10 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
}
curHero = hero;
artifs->updateState = true;
artifs->setHero(hero);
artifs->updateState = false;
//pos temporarily switched, restored later
pos.x -= 65;
pos.y -= 8;
@ -271,9 +275,6 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
spellPointsArea->text = std::string(bufor);
artifs->updateState = true;
artifs->setHero(hero);
artifs->updateState = false;
//if we have exchange window with this hero open
bool noDismiss=false;

View File

@ -1049,7 +1049,7 @@ void CKingdomInterface::CHeroItem::CArtPlace::clickLeft(tribool down, bool previ
{tlog1<<type;
if(type == 0)
{
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (screen->w - 620)/2, (screen->h - 595)/2), hero->hero, LOCPLINT);
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (screen->w - 620)/2, (screen->h - 595)/2), hero->hero, LOCPLINT, false);
GH.pushInt(spellWindow);
}
else

View File

@ -545,7 +545,12 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
{
SDLKey hlpKey = key.keysym.sym;
if(isNumKey(hlpKey, false))
hlpKey = numToDigit(hlpKey);
{
if(hlpKey == SDLK_KP_PLUS)
hlpKey = SDLK_EQUALS;
else
hlpKey = numToDigit(hlpKey);
}
static const SDLKey spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS};

View File

@ -4530,34 +4530,7 @@ void CArtPlace::select ()
//ourOwner->curHero->recreateArtBonuses();
// Update the hero bonuses.
CHeroWindow* chw = dynamic_cast<CHeroWindow*>(GH.topInt());
if (chw != NULL)
{
chw->deactivate();
chw->setHero(ourOwner->curHero);
chw->activate();
}
else if(CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt()))
{
//assert(cew); // Either an exchange- or hero window should be active if an artifact slot is selected.
cew->deactivate();
for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
{
if(cew->heroInst[g] == ourOwner->curHero)
{
cew->artifs[g]->setHero(ourOwner->curHero);
}
}
//use our copy of hero to draw window
if(cew->heroInst[0]->id == ourOwner->curHero->id)
cew->heroInst[0] = ourOwner->curHero;
else
cew->heroInst[1] = ourOwner->curHero;
cew->prepareBackground();
cew->activate();
}
ourOwner->updateParentWindow();
if (slotID >= 19)
ourOwner->scrollBackpack(backpackCorrection);
@ -4716,7 +4689,7 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
if(curHero != hero)
{
delete curHero;
curHero = new CGHeroInstance(*hero);
hero = curHero = new CGHeroInstance(*hero);
}
// Compensate backpack pos if an artifact was insertad before it.
@ -4736,7 +4709,8 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
CGI->arth->unequipArtifact(curHero->artifWorn, commonInfo->srcSlotID);
else
curHero->artifacts.erase(curHero->artifacts.begin() + (commonInfo->srcSlotID - 19));
//curHero->recreateArtBonuses();
updateParentWindow(); //TODO: evil! but does the thing
// Source <- Dest
commonInfo->srcArtifact = commonInfo->destArtifact;
@ -4932,6 +4906,46 @@ CArtifactsOfHero::~CArtifactsOfHero()
CGI->curh->dragAndDropCursor(NULL);
}
void CArtifactsOfHero::updateParentWindow()
{
if (CHeroWindow* chw = dynamic_cast<CHeroWindow*>(GH.topInt()))
{
if(updateState)
chw->curHero = curHero;
else
{
chw->deactivate();
chw->setHero(curHero);
chw->activate();
}
}
else if(CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt()))
{
//use our copy of hero to draw window
if(cew->heroInst[0]->id == curHero->id)
cew->heroInst[0] = curHero;
else
cew->heroInst[1] = curHero;
if(!updateState)
{
cew->deactivate();
for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
{
if(cew->heroInst[g] == curHero)
{
cew->artifs[g]->setHero(curHero);
}
}
cew->prepareBackground();
cew->activate();
}
}
}
void CExchangeWindow::close()
{
GH.popIntTotally(this);

View File

@ -943,7 +943,7 @@ public:
CArtifactsOfHero(const Point& position); //c-tor
~CArtifactsOfHero(); //d-tor
void updateParentWindow();
friend class CArtPlace;
};

View File

@ -1190,7 +1190,7 @@ void CGHeroInstance::updateSkill(int which, int val)
}
if (skillVal) //we don't need bonuses of other types here
{
Bonus * b = getBonus(Selector::typeSybtype(Bonus::SECONDARY_SKILL_PREMY, which) && Selector::sourceType(Bonus::SECONDARY_SKILL));
Bonus * b = bonuses.getFirst(Selector::typeSybtype(Bonus::SECONDARY_SKILL_PREMY, which) && Selector::sourceType(Bonus::SECONDARY_SKILL));
if (b) //only local hero bonus
{
b->val = skillVal;