|
@@ -37,6 +37,8 @@
|
|
|
#include <queue>
|
|
|
#include <sstream>
|
|
|
#include "../lib/NetPacks.h"
|
|
|
+#include "CSpellWindow.h"
|
|
|
+#include "CHeroWindow.h"
|
|
|
|
|
|
/*
|
|
|
* GUIClasses.cpp, part of VCMI engine
|
|
@@ -3209,6 +3211,409 @@ CRClickPopupInt::~CRClickPopupInt()
|
|
|
delete inner;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*,
|
|
|
+ spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
|
|
|
+ warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
|
|
|
+ misc5(false), feet(false), lRing(false), rRing(false), torso(false),
|
|
|
+ lHand(false), rHand(false), neck(false), shoulders(false), head(false) */{}
|
|
|
+void CArtPlace::activate()
|
|
|
+{
|
|
|
+ if(!active)
|
|
|
+ {
|
|
|
+ //ClickableL::activate();
|
|
|
+ LRClickableAreaWTextComp::activate();
|
|
|
+ active = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+void CArtPlace::clickLeft(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ //LRClickableAreaWTextComp::clickLeft(down);
|
|
|
+
|
|
|
+ if(ourArt && !down) //we are spellbook
|
|
|
+ {
|
|
|
+ if(ourArt->id == 0)
|
|
|
+ {
|
|
|
+ CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ourOwner->curHero);
|
|
|
+ LOCPLINT->pushInt(spellWindow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!down && !clicked && pressedL) //not clicked before
|
|
|
+ {
|
|
|
+ if(ourArt && ourArt->id == 0)
|
|
|
+ return; //this is handled separately
|
|
|
+ if(!ourOwner->activeArtPlace) //nothing has bewn clicked
|
|
|
+ {
|
|
|
+ if(ourArt) //to prevent selecting empty slots (bugfix to what GrayFace reported)
|
|
|
+ {
|
|
|
+ clicked = true;
|
|
|
+ ourOwner->activeArtPlace = this;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //perform artifact substitution
|
|
|
+ {
|
|
|
+ if(slotID >= 19) //we are an backpack slot - remove active artifact and put it to the last free pos in backpack
|
|
|
+ { //TODO: putting artifacts in the middle of backpack (pushing following arts)
|
|
|
+
|
|
|
+ LOCPLINT->cb->swapArtifacts(ourOwner->curHero,ourOwner->activeArtPlace->slotID,ourOwner->curHero,ourOwner->curHero->artifacts.size()+19);
|
|
|
+ }
|
|
|
+ //check if swap is possible
|
|
|
+ else if(this->fitsHere(ourOwner->activeArtPlace->ourArt) && ourOwner->activeArtPlace->fitsHere(this->ourArt))
|
|
|
+ {
|
|
|
+ int destSlot = slotID,
|
|
|
+ srcSlot = ourOwner->activeArtPlace->slotID;
|
|
|
+
|
|
|
+ LOCPLINT->cb->swapArtifacts(ourOwner->curHero,destSlot,ourOwner->curHero,srcSlot);
|
|
|
+
|
|
|
+ ourOwner->activeArtPlace->clicked = false;
|
|
|
+ ourOwner->activeArtPlace = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(!down && clicked)
|
|
|
+ {
|
|
|
+ if(ourArt && ourArt->id == 0)
|
|
|
+ return; //this is handled separately
|
|
|
+ clicked = false;
|
|
|
+ ourOwner->activeArtPlace = NULL;
|
|
|
+ }
|
|
|
+ ClickableL::clickLeft(down);
|
|
|
+}
|
|
|
+void CArtPlace::clickRight(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ if(text.size()) //if there is no description, do nothing ;]
|
|
|
+ LRClickableAreaWTextComp::clickRight(down);
|
|
|
+}
|
|
|
+void CArtPlace::deactivate()
|
|
|
+{
|
|
|
+ if(active)
|
|
|
+ {
|
|
|
+ active = false;
|
|
|
+ //ClickableL::deactivate();
|
|
|
+ LRClickableAreaWTextComp::deactivate();
|
|
|
+ }
|
|
|
+}
|
|
|
+void CArtPlace::show(SDL_Surface *to)
|
|
|
+{
|
|
|
+ if(ourArt)
|
|
|
+ {
|
|
|
+ blitAt(graphics->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to);
|
|
|
+ }
|
|
|
+ if(clicked && active)
|
|
|
+ {
|
|
|
+ for(int i=0; i<pos.h; ++i)
|
|
|
+ {
|
|
|
+ for(int j=0; j<pos.w; ++j)
|
|
|
+ {
|
|
|
+ if(i==0 || j==0 || i==pos.h-1 || j==pos.w-1)
|
|
|
+ {
|
|
|
+ CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x+j, pos.y+i, 240, 220, 120);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+bool CArtPlace::fitsHere(const CArtifact * art)
|
|
|
+{
|
|
|
+ if(!art)
|
|
|
+ return true; //you can have no artifact somewhere
|
|
|
+ if(slotID > 18 || vstd::contains(art->possibleSlots,slotID)) //backpack or right slot
|
|
|
+ return true;
|
|
|
+ return false;
|
|
|
+}
|
|
|
+CArtPlace::~CArtPlace()
|
|
|
+{
|
|
|
+ deactivate();
|
|
|
+}
|
|
|
+
|
|
|
+void LClickableArea::activate()
|
|
|
+{
|
|
|
+ ClickableL::activate();
|
|
|
+}
|
|
|
+void LClickableArea::deactivate()
|
|
|
+{
|
|
|
+ ClickableL::deactivate();
|
|
|
+}
|
|
|
+void LClickableArea::clickLeft(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ //if(!down)
|
|
|
+ //{
|
|
|
+ // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
|
|
+ //}
|
|
|
+}
|
|
|
+
|
|
|
+void RClickableArea::activate()
|
|
|
+{
|
|
|
+ ClickableR::activate();
|
|
|
+}
|
|
|
+void RClickableArea::deactivate()
|
|
|
+{
|
|
|
+ ClickableR::deactivate();
|
|
|
+}
|
|
|
+void RClickableArea::clickRight(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ //if(!down)
|
|
|
+ //{
|
|
|
+ // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
|
|
+ //}
|
|
|
+}
|
|
|
+
|
|
|
+void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ if(!down && pressedL)
|
|
|
+ {
|
|
|
+ LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(), soundBase::sound_todo);
|
|
|
+ }
|
|
|
+ ClickableL::clickLeft(down);
|
|
|
+}
|
|
|
+void LRClickableAreaWText::clickRight(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ LOCPLINT->adventureInt->handleRightClick(text, down, this);
|
|
|
+}
|
|
|
+void LRClickableAreaWText::activate()
|
|
|
+{
|
|
|
+ LClickableArea::activate();
|
|
|
+ RClickableArea::activate();
|
|
|
+ Hoverable::activate();
|
|
|
+}
|
|
|
+void LRClickableAreaWText::deactivate()
|
|
|
+{
|
|
|
+ LClickableArea::deactivate();
|
|
|
+ RClickableArea::deactivate();
|
|
|
+ Hoverable::deactivate();
|
|
|
+}
|
|
|
+void LRClickableAreaWText::hover(bool on)
|
|
|
+{
|
|
|
+ Hoverable::hover(on);
|
|
|
+ if (on)
|
|
|
+ LOCPLINT->statusbar->print(hoverText);
|
|
|
+ else if (LOCPLINT->statusbar->getCurrent()==hoverText)
|
|
|
+ LOCPLINT->statusbar->clear();
|
|
|
+}
|
|
|
+
|
|
|
+void LClickableAreaHero::clickLeft(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ if(!down)
|
|
|
+ {
|
|
|
+ owner->deactivate();
|
|
|
+ const CGHeroInstance * buf = LOCPLINT->getWHero(id);
|
|
|
+ owner->setHero(buf);
|
|
|
+ owner->redrawCurBack();
|
|
|
+ owner->activate();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ if((!down) && pressedL)
|
|
|
+ {
|
|
|
+ std::vector<SComponent*> comp(1, new SComponent(SComponent::Etype(baseType), type, bonus));
|
|
|
+ LOCPLINT->showInfoDialog(text, comp, soundBase::sound_todo);
|
|
|
+ }
|
|
|
+ ClickableL::clickLeft(down);
|
|
|
+}
|
|
|
+void LRClickableAreaWTextComp::clickRight(boost::logic::tribool down)
|
|
|
+{
|
|
|
+ LOCPLINT->adventureInt->handleRightClick(text, down, this);
|
|
|
+}
|
|
|
+void LRClickableAreaWTextComp::activate()
|
|
|
+{
|
|
|
+ LClickableArea::activate();
|
|
|
+ RClickableArea::activate();
|
|
|
+ Hoverable::activate();
|
|
|
+}
|
|
|
+void LRClickableAreaWTextComp::deactivate()
|
|
|
+{
|
|
|
+ LClickableArea::deactivate();
|
|
|
+ RClickableArea::deactivate();
|
|
|
+ Hoverable::deactivate();
|
|
|
+}
|
|
|
+void LRClickableAreaWTextComp::hover(bool on)
|
|
|
+{
|
|
|
+ Hoverable::hover(on);
|
|
|
+ if (on)
|
|
|
+ LOCPLINT->statusbar->print(hoverText);
|
|
|
+ else if (LOCPLINT->statusbar->getCurrent()==hoverText)
|
|
|
+ LOCPLINT->statusbar->clear();
|
|
|
+}
|
|
|
+
|
|
|
+void CArtifactsOfHero::activate()
|
|
|
+{
|
|
|
+ for(size_t f=0; f<artWorn.size(); ++f)
|
|
|
+ {
|
|
|
+ if(artWorn[f])
|
|
|
+ artWorn[f]->activate();
|
|
|
+ }
|
|
|
+ for(size_t f=0; f<backpack.size(); ++f)
|
|
|
+ {
|
|
|
+ if(backpack[f])
|
|
|
+ backpack[f]->activate();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CArtifactsOfHero::deactivate()
|
|
|
+{
|
|
|
+ for(size_t f=0; f<artWorn.size(); ++f)
|
|
|
+ {
|
|
|
+ if(artWorn[f])
|
|
|
+ artWorn[f]->deactivate();
|
|
|
+ }
|
|
|
+ for(size_t f=0; f<backpack.size(); ++f)
|
|
|
+ {
|
|
|
+ if(backpack[f])
|
|
|
+ backpack[f]->deactivate();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CArtifactsOfHero::show(SDL_Surface * to)
|
|
|
+{
|
|
|
+ for(size_t d=0; d<artWorn.size(); ++d)
|
|
|
+ {
|
|
|
+ artWorn[d]->show(to);
|
|
|
+ }
|
|
|
+ for(size_t d=0; d<backpack.size(); ++d)
|
|
|
+ {
|
|
|
+ backpack[d]->show(to);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
|
|
|
+{
|
|
|
+ curHero = hero;
|
|
|
+ char bufor[400];
|
|
|
+
|
|
|
+ for(size_t g=0; g<artWorn.size(); ++g)
|
|
|
+ {
|
|
|
+ delete artWorn[g];
|
|
|
+ }
|
|
|
+ for(size_t g=0; g<backpack.size(); ++g)
|
|
|
+ {
|
|
|
+ delete backpack[g];
|
|
|
+ }
|
|
|
+ backpack.clear();
|
|
|
+
|
|
|
+ std::vector<SDL_Rect> slotPos;
|
|
|
+ backpackPos = 0;
|
|
|
+
|
|
|
+ slotPos += genRect(44,44,pos.x+509,pos.y+30), genRect(44,44,pos.x+567,pos.y+240), genRect(44,44,pos.x+509,pos.y+80),
|
|
|
+ genRect(44,44,pos.x+383,pos.y+68), genRect(44,44,pos.x+564,pos.y+183), genRect(44,44,pos.x+509,pos.y+130),
|
|
|
+ genRect(44,44,pos.x+431,pos.y+68), genRect(44,44,pos.x+610,pos.y+183), genRect(44,44,pos.x+515,pos.y+295),
|
|
|
+ genRect(44,44,pos.x+383,pos.y+143), genRect(44,44,pos.x+399,pos.y+194), genRect(44,44,pos.x+415,pos.y+245),
|
|
|
+ genRect(44,44,pos.x+431,pos.y+296), genRect(44,44,pos.x+564,pos.y+30), genRect(44,44,pos.x+610,pos.y+30),
|
|
|
+ genRect(44,44,pos.x+610,pos.y+76), genRect(44,44,pos.x+610,pos.y+122), genRect(44,44,pos.x+610,pos.y+310),
|
|
|
+ genRect(44,44,pos.x+381,pos.y+296);
|
|
|
+
|
|
|
+ for (int g = 0; g < 19 ; g++)
|
|
|
+ {
|
|
|
+ artWorn[g] = new CArtPlace(hero->getArt(g));
|
|
|
+ artWorn[g]->pos = slotPos[g];
|
|
|
+ if(hero->getArt(g))
|
|
|
+ artWorn[g]->text = hero->getArt(g)->Description();
|
|
|
+ artWorn[g]->ourOwner = this;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(size_t g=0; g<artWorn.size(); ++g)
|
|
|
+ {
|
|
|
+ artWorn[g]->slotID = g;
|
|
|
+ if(artWorn[g]->ourArt)
|
|
|
+ {
|
|
|
+ sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), artWorn[g]->ourArt->Name().c_str());
|
|
|
+ artWorn[g]->hoverText = std::string(bufor);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ artWorn[g]->hoverText = CGI->generaltexth->allTexts[507];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(size_t s=0; s<5; ++s)
|
|
|
+ {
|
|
|
+ CArtPlace * add;
|
|
|
+ if( s < curHero->artifacts.size() )
|
|
|
+ {
|
|
|
+ add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]);
|
|
|
+ sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), add->ourArt->Name().c_str());
|
|
|
+ add->hoverText = bufor;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ add = new CArtPlace(NULL);
|
|
|
+ add->hoverText = CGI->generaltexth->allTexts[507];
|
|
|
+ }
|
|
|
+ add->pos.x = pos.x + 403 + 46*s;
|
|
|
+ add->pos.y = pos.y + 365;
|
|
|
+ add->pos.h = add->pos.w = 44;
|
|
|
+ if(s<hero->artifacts.size() && hero->artifacts[s])
|
|
|
+ {
|
|
|
+ add->text = hero->getArt(19+s)->Description();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ add->text = std::string();
|
|
|
+ }
|
|
|
+ add->ourOwner = this;
|
|
|
+ add->slotID = 19+s;
|
|
|
+ backpack.push_back(add);
|
|
|
+ }
|
|
|
+ activeArtPlace = NULL;
|
|
|
+}
|
|
|
+
|
|
|
+void CArtifactsOfHero::dispose()
|
|
|
+{
|
|
|
+ curHero = NULL;
|
|
|
+ for(size_t g=0; g<artWorn.size(); ++g)
|
|
|
+ {
|
|
|
+ delete artWorn[g];
|
|
|
+ artWorn[g] = NULL;
|
|
|
+ }
|
|
|
+ for(size_t g=0; g<backpack.size(); ++g)
|
|
|
+ {
|
|
|
+ delete backpack[g];
|
|
|
+ backpack[g] = NULL;
|
|
|
+ }
|
|
|
+ backpack.clear();
|
|
|
+ activeArtPlace = NULL;
|
|
|
+}
|
|
|
+
|
|
|
+void CArtifactsOfHero::scrollBackpack(int dir)
|
|
|
+{
|
|
|
+ backpackPos += dir + curHero->artifacts.size();
|
|
|
+ backpackPos %= curHero->artifacts.size();
|
|
|
+
|
|
|
+ for(size_t s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
|
|
|
+ {
|
|
|
+ CArtPlace *cur = backpack[s];
|
|
|
+ cur->slotID = 19+((s+backpackPos)%curHero->artifacts.size());
|
|
|
+ cur->ourArt = curHero->getArt(cur->slotID);
|
|
|
+
|
|
|
+ if(cur->ourArt)
|
|
|
+ cur->text = cur->ourArt->Description();
|
|
|
+ else
|
|
|
+ cur->text = std::string();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+CArtifactsOfHero::CArtifactsOfHero(const SDL_Rect & position) :
|
|
|
+ activeArtPlace(NULL), backpackPos(0)
|
|
|
+{
|
|
|
+ pos = position;
|
|
|
+ artWorn.resize(19);
|
|
|
+}
|
|
|
+
|
|
|
+CArtifactsOfHero::~CArtifactsOfHero()
|
|
|
+{
|
|
|
+ for(size_t g=0; g<artWorn.size(); ++g)
|
|
|
+ {
|
|
|
+ delete artWorn[g];
|
|
|
+ }
|
|
|
+ artWorn.clear();
|
|
|
+ for(size_t g=0; g<backpack.size(); ++g)
|
|
|
+ {
|
|
|
+ delete backpack[g];
|
|
|
+ }
|
|
|
+ backpack.clear();
|
|
|
+}
|
|
|
+
|
|
|
void CExchangeWindow::close()
|
|
|
{
|
|
|
LOCPLINT->popIntTotally(this);
|
|
@@ -3217,11 +3622,17 @@ void CExchangeWindow::close()
|
|
|
void CExchangeWindow::activate()
|
|
|
{
|
|
|
quit->activate();
|
|
|
+
|
|
|
+ art1->activate();
|
|
|
+ art2->activate();
|
|
|
}
|
|
|
|
|
|
void CExchangeWindow::deactivate()
|
|
|
{
|
|
|
quit->deactivate();
|
|
|
+
|
|
|
+ art1->deactivate();
|
|
|
+ art2->deactivate();
|
|
|
}
|
|
|
|
|
|
void CExchangeWindow::show(SDL_Surface * to)
|
|
@@ -3233,6 +3644,9 @@ void CExchangeWindow::show(SDL_Surface * to)
|
|
|
//printing border around window
|
|
|
if(screen->w != 800 || screen->h !=600)
|
|
|
CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
|
|
|
+
|
|
|
+ art1->show(to);
|
|
|
+ art2->show(to);
|
|
|
}
|
|
|
|
|
|
CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) //c-tor
|
|
@@ -3240,6 +3654,11 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) //c-tor
|
|
|
hero1inst = LOCPLINT->cb->getHeroInfo(hero1, 2);
|
|
|
hero2inst = LOCPLINT->cb->getHeroInfo(hero2, 2);
|
|
|
|
|
|
+ art1 = new CArtifactsOfHero(genRect(600, 800, -334, 150));
|
|
|
+ art1->setHero(hero1inst);
|
|
|
+ art2 = new CArtifactsOfHero(genRect(600, 800, 96, 150));
|
|
|
+ art2->setHero(hero2inst);
|
|
|
+
|
|
|
SDL_Surface * bgtemp; //loaded as 8bpp surface
|
|
|
bgtemp = BitmapHandler::loadBitmap("TRADE2.BMP");
|
|
|
graphics->blueToPlayersAdv(bgtemp, hero1inst->tempOwner);
|
|
@@ -3297,4 +3716,8 @@ CExchangeWindow::~CExchangeWindow() //d-tor
|
|
|
{
|
|
|
SDL_FreeSurface(bg);
|
|
|
delete quit;
|
|
|
-}
|
|
|
+ delete art1;
|
|
|
+ delete art2;
|
|
|
+}
|
|
|
+
|
|
|
+
|