From 8da051febf0856061aa70e249d5b2982ea9b353b Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sat, 26 Jan 2008 19:36:31 +0000 Subject: [PATCH] =?UTF-8?q?Wsp=C3=B3lne=20zmiany=20(Common=20changes)=20*?= =?UTF-8?q?=20fixed=20heroWindow=20*=20started=20making=20garrisons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CCallback.cpp | 20 ++++ CCallback.h | 2 + CCastleInterface.cpp | 28 +++-- CCastleInterface.h | 1 + CConsoleHandler.cpp | 3 + CHeroWindow.cpp | 49 +++------ CPlayerInterface.cpp | 246 ++++++++++++++++++++++++++++++++++++++++++- CPlayerInterface.h | 45 ++++++++ SDL_Extensions.h | 2 +- 9 files changed, 348 insertions(+), 48 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index a3767bd30..ed48978c6 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -373,6 +373,26 @@ int CCallback::getHeroSerial(const CGHeroInstance * hero) } return -1; } + +int CCallback::swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2) +{ + CCreatureSet *S1=const_cast(s1), *S2 = const_cast(s2);//todo - ugly + if (false) + { + //TODO: check if we are allowed to swap these creatures + return -1; + } + //if(S1->slots[p1].first) + { + //if(s2->slots[p2].first) + { + CCreature * pom = S2->slots[p2].first; + S2->slots[p2].first = S1->slots[p1].first; + S1->slots[p1].first = pom; + } + } + return -1; +} int CCallback::getMySerial() { return gs->players[player].serial; diff --git a/CCallback.h b/CCallback.h index 3e4e0a80b..75d24308f 100644 --- a/CCallback.h +++ b/CCallback.h @@ -34,6 +34,7 @@ public: virtual int getMyColor()=0; virtual int getMySerial()=0; virtual int getHeroSerial(const CGHeroInstance * hero)=0; + virtual int swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it! }; struct HeroMoveDetails @@ -78,6 +79,7 @@ public: int getMyColor(); int getHeroSerial(const CGHeroInstance * hero); int getMySerial(); + int swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2); //friends friend int _tmain(int argc, _TCHAR* argv[]); diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 5a9022f29..59a300793 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -155,7 +155,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) flag = CGI->spriteh->giveDef("CREST58.DEF"); CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID); exit = new AdventureMapButton - (CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate); + (CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,false); exit->bitmapOffset = 4; for (std::set::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++) @@ -173,6 +173,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) } std::sort(buildings.begin(),buildings.end(),srthlp); + garr = new CGarrisonInt(305,387,4,32,townInt,241,13,&town->garrison,(town->garrisonHero)?(&town->garrisonHero->army):(NULL)); if(Activate) { @@ -281,23 +282,25 @@ void CCastleInterface::showAll(SDL_Surface * to) //flag blitAt(flag->ourImages[town->getOwner()].bitmap,241,387,to); + //print garrison - for( - std::map >::const_iterator i=town->garrison.slots.begin(); - i!=town->garrison.slots.end(); - i++ - ) - { - blitAt(CGI->creh->bigImgs[i->second.first->idNumber],305+(62*(i->first)),387,to); - itoa(i->second.second,temp,10); - CSDL_Ext::printTo(temp,305+(62*(i->first))+57,387+61,GEOR13,zwykly,to); - } + //for( + // std::map >::const_iterator i=town->garrison.slots.begin(); + // i!=town->garrison.slots.end(); + // i++ + // ) + //{ + // blitAt(CGI->creh->bigImgs[i->second.first->idNumber],305+(62*(i->first)),387,to); + // itoa(i->second.second,temp,10); + // CSDL_Ext::printTo(temp,305+(62*(i->first))+57,387+61,GEOR13,zwykly,to); + //} show(); } void CCastleInterface::show(SDL_Surface * to) { if (!to) to=ekran; + garr->show(); count++; if(count==5) { @@ -333,12 +336,15 @@ void CCastleInterface::show(SDL_Surface * to) } void CCastleInterface::activate() { + garr->activate(); LOCPLINT->curint = this; + exit->activate(); for(int i=0;iactivate(); } void CCastleInterface::deactivate() { + garr->deactivate(); exit->deactivate(); for(int i=0;ideactivate(); diff --git a/CCastleInterface.h b/CCastleInterface.h index 5abd60920..f081aa91c 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -38,6 +38,7 @@ public: CDefHandler *hall,*fort, *bigTownPic, *flag; + CGarrisonInt * garr; AdventureMapButton * exit; std::vector buildings; //building id, building def, structure struct, border, filling diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index 9a7a3126d..54f45bf88 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -31,6 +31,9 @@ int internalFunc(void * callback) int heronum; int3 dest; + if(pom==std::string("die, fool")) + exit(0); + switch (*cn.c_str()) { case 'P': diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 38a9036e9..93fb0b3e4 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -118,7 +118,8 @@ void CHeroWindow::show(SDL_Surface *to) { if(!to) to=ekran; - blitAt(curBack,pos.x,pos.y,to); + if(curBack) + blitAt(curBack,pos.x,pos.y,to); quitButton->show(); dismissButton->show(); questlogButton->show(); @@ -192,106 +193,87 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artFeet->pos.x = 515; artFeet->pos.y = 295; artFeet->pos.h = artFeet->pos.w = 44; - artFeet->activate(); artHead = new CArtPlace(hero->artHead); artHead->pos.x = 509; artHead->pos.y = 30; artHead->pos.h = artHead->pos.h = 44; - artHead->activate(); artLHand = new CArtPlace(hero->artLHand); artLHand->pos.x = 564; artLHand->pos.y = 183; artLHand->pos.h = artLHand->pos.h = 44; - artLHand->activate(); artLRing = new CArtPlace(hero->artLRing); artLRing->pos.x = 610; artLRing->pos.y = 183; artLRing->pos.h = artLRing->pos.h = 44; - artLRing->activate(); artMach1 = new CArtPlace(hero->artMach1); artMach1->pos.x = 564; artMach1->pos.y = 30; artMach1->pos.h = artMach1->pos.h = 44; - artMach1->activate(); artMach2 = new CArtPlace(hero->artMach2); artMach2->pos.x = 610; artMach2->pos.y = 30; artMach2->pos.h = artMach2->pos.h = 44; - artMach2->activate(); artMach3 = new CArtPlace(hero->artMach3); artMach3->pos.x = 610; artMach3->pos.y = 76; artMach3->pos.h = artMach3->pos.h = 44; - artMach3->activate(); artMach4 = new CArtPlace(hero->artMach4); artMach4->pos.x = 610; artMach4->pos.y = 122; artMach4->pos.h = artMach4->pos.h = 44; - artMach4->activate(); artMisc1 = new CArtPlace(hero->artMisc1); artMisc1->pos.x = 383; artMisc1->pos.y = 143; artMisc1->pos.h = artMisc1->pos.h = 44; - artMisc1->activate(); artMisc2 = new CArtPlace(hero->artMisc2); artMisc2->pos.x = 399; artMisc2->pos.y = 194; artMisc2->pos.h = artMisc2->pos.h = 44; - artMisc2->activate(); artMisc3 = new CArtPlace(hero->artMisc3); artMisc3->pos.x = 415; artMisc3->pos.y = 245; artMisc3->pos.h = artMisc3->pos.h = 44; - artMisc3->activate(); artMisc4 = new CArtPlace(hero->artMisc4); artMisc4->pos.x = 431; artMisc4->pos.y = 296; artMisc4->pos.h = artMisc4->pos.h = 44; - artMisc4->activate(); artMisc5 = new CArtPlace(hero->artMisc5); artMisc5->pos.x = 381; artMisc5->pos.y = 296; artMisc5->pos.h = artMisc5->pos.h = 44; - artMisc5->activate(); artNeck = new CArtPlace(hero->artNeck); artNeck->pos.x = 508; artNeck->pos.y = 79; artNeck->pos.h = artNeck->pos.h = 44; - artNeck->activate(); artRhand = new CArtPlace(hero->artRhand); artRhand->pos.x = 383; artRhand->pos.y = 68; artRhand->pos.h = artRhand->pos.h = 44; - artRhand->activate(); artRRing = new CArtPlace(hero->artRRing); artRRing->pos.x = 431; artRRing->pos.y = 68; artRRing->pos.h = artRRing->pos.h = 44; - artRRing->activate(); artShoulders = new CArtPlace(hero->artShoulders); artShoulders->pos.x = 567; artShoulders->pos.y = 240; artShoulders->pos.h = artShoulders->pos.h = 44; - artShoulders->activate(); artSpellBook = new CArtPlace(hero->artSpellBook); artSpellBook->pos.x = 610; artSpellBook->pos.y = 310; artSpellBook->pos.h = artSpellBook->pos.h = 44; - artSpellBook->activate(); artTorso = new CArtPlace(hero->artTorso); artTorso->pos.x = 509; artTorso->pos.y = 130; artTorso->pos.h = artTorso->pos.h = 44; - artTorso->activate(); for(int s=0; s<5 && sartifacts.size(); ++s) { CArtPlace * add = new CArtPlace(curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]); add->pos.x = 403 + 46*s; add->pos.y = 365; add->pos.h = add->pos.h = 44; - add->activate(); backpack.push_back(add); } + redrawCurBack(); } void CHeroWindow::quit() @@ -303,19 +285,7 @@ void CHeroWindow::quit() LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+i); } } - quitButton->deactivate(); - dismissButton->deactivate(); - questlogButton->deactivate(); - gar1button->deactivate(); - gar2button->deactivate(); - gar3button->deactivate(); - gar4button->deactivate(); - leftArtRoll->deactivate(); - rightArtRoll->deactivate(); - for(int g=0; gdeactivate(); - } + deactivate(); LOCPLINT->adventureInt->show(); @@ -326,7 +296,6 @@ void CHeroWindow::quit() if(dynamic_cast(LOCPLINT->lclickable[v])) LOCPLINT->lclickable.erase(LOCPLINT->lclickable.begin()+v); }*/ - portraitArea->deactivate(); delete artFeet; artFeet = 0; @@ -435,6 +404,10 @@ void CHeroWindow::activate() if(backpack[f]) backpack[f]->activate(); } + for(int e=0; eactivate(); + } //LOCPLINT->lclickable.push_back(artFeet); } @@ -499,6 +472,10 @@ void CHeroWindow::deactivate() if(backpack[f]) backpack[f]->deactivate(); } + for(int e=0; edeactivate(); + } } void CHeroWindow::dismissCurrent() @@ -784,8 +761,10 @@ void LClickableAreaHero::clickLeft(boost::logic::tribool down) { if(!down) { + owner->deactivate(); const CGHeroInstance * buf = LOCPLINT->cb->getHeroInfo(owner->player, id, false); owner->setHero(buf); owner->redrawCurBack(); + owner->activate(); } } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index ddd66be3a..9cf61bfa7 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -28,6 +28,250 @@ public: return (*a.first)<(*b.first); } } ocmptwo_cgin ; + +void CGarrisonSlot::hover (bool on) +{ +} +void CGarrisonSlot::clickRight (tribool down) +{ +} +void CGarrisonSlot::clickLeft(tribool down) +{ + if(owner->ignoreEvent) + { + owner->ignoreEvent = false; + return; + } + if(down) + { + if(owner->highlighted) + { + LOCPLINT->cb->swapCreatures( + (!upg)?(owner->set1):(owner->set2), + (!owner->highlighted->upg)?(owner->set1):(owner->set2), + ID,owner->highlighted->ID); + owner->highlighted = NULL; + owner->recreateSlots(); + } + else + { + owner->highlighted = this; + } + } +} +void CGarrisonSlot::activate() +{ + ClickableL::activate(); + ClickableR::activate(); + Hoverable::activate(); +} +void CGarrisonSlot::deactivate() +{ + ClickableL::deactivate(); + ClickableR::deactivate(); + Hoverable::deactivate(); +} +CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, const CCreature * Creature, int Count) +{ + upg = 0; + count = Count; + ID = IID; + creature = Creature; + pos.x = x; + pos.y = y; + pos.w = 58; + pos.h = 64; + owner = Owner; +} +void CGarrisonSlot::show() +{ + if(creature) + { + blitAtWR(CGI->creh->bigImgs[creature->idNumber],pos); + } + else + { + SDL_Rect jakis1 = genRect(pos.w,pos.h,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos; + SDL_BlitSurface(owner->sur,&jakis1,ekran,&jakis2); + SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h); + } +} +CGarrisonInt::~CGarrisonInt() +{ + if(sup) + { + for(int i=0;isize();i++) + delete (*sup)[i]; + delete sup; + } + if(sdown) + { + for(int i=0;isize();i++) + delete (*sdown)[i]; + delete sdown; + } +} + +void CGarrisonInt::show() +{ + if(sup) + { + for(int i = 0; isize(); i++) + if((*sup)[i]) + (*sup)[i]->show(); + } + if(sdown) + { + for(int i = 0; isize(); i++) + if((*sdown)[i]) + (*sdown)[i]->show(); + } + if(highlighted) + { + blitAt(CGI->creh->bigImgs[-1],highlighted->pos); + } +} +void CGarrisonInt::deactiveteSlots() +{ + if(sup) + { + for(int i = 0; isize(); i++) + { + if((*sup)[i]) + { + (*sup)[i]->deactivate(); + } + } + } + if(sdown) + { + for(int i = 0; isize(); i++) + { + if((*sdown)[i]) + { + (*sdown)[i]->deactivate(); + } + } + } +} +void CGarrisonInt::activeteSlots() +{ + if(sup) + { + for(int i = 0; isize(); i++) + { + if((*sup)[i]) + { + (*sup)[i]->activate(); + } + } + } + if(sdown) + { + for(int i = 0; isize(); i++) + { + if((*sdown)[i]) + { + (*sdown)[i]->activate(); + } + } + } +} +void CGarrisonInt::createSlots() +{ + if(set1) + { + sup = new std::vector(7,(CGarrisonSlot *)(NULL)); + for + (std::map >::const_iterator i=set1->slots.begin(); + i!=set1->slots.end(); i++) + { + (*sup)[i->first] = + new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, i->second.first,i->second.second); + } + for(int i=0; isize(); i++) + if((*sup)[i] == NULL) + (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i, NULL, 0); + } + if(set2) + { + sdown = new std::vector(7,(CGarrisonSlot *)(NULL)); + for + (std::map >::const_iterator i=set2->slots.begin(); + i!=set2->slots.end(); i++) + { + (*sdown)[i->first] = + new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first, i->second.first,i->second.second); + } + for(int i=0; isize(); i++) + if((*sdown)[i] == NULL) + (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i, NULL, 0); + } +} +void CGarrisonInt::deleteSlots() +{ + if(sup) + { + for(int i = 0; isize(); i++) + { + if((*sup)[i]) + { + delete (*sup)[i]; + } + } + } + if(sdown) + { + for(int i = 0; isize(); i++) + { + if((*sdown)[i]) + { + delete (*sdown)[i]; + } + } + } +} +void CGarrisonInt::recreateSlots() +{ + deactiveteSlots(); + deleteSlots(); + createSlots(); + activeteSlots(); + show(); +} +CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CCreatureSet * s1, const CCreatureSet *s2) + :interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),set1(s1),set2(s2), + offx(OX),offy(OY) +{ + + ignoreEvent = false; + pos.x=(x); + pos.y=(y); + pos.w=(58); + pos.h=(64); + createSlots(); +} + +void CGarrisonInt::activate() +{ + if(sup) + { + for(int i = 0; isize(); i++) + if((*sup)[i]) + (*sup)[i]->activate(); + } + if(sdown) + { + for(int i = 0; isize(); i++) + if((*sdown)[i]) + (*sdown)[i]->activate(); + } +} +void CGarrisonInt::deactivate() +{ + deactiveteSlots(); +} + CInfoWindow::CInfoWindow() :okb(NMessage::ok,NULL,&CInfoWindow::okClicked) { @@ -1582,6 +1826,6 @@ void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero) { adventureInt->heroWindow->setHero(hero); this->objsToBlit.push_back(adventureInt->heroWindow); - adventureInt->heroWindow->activate(); adventureInt->hide(); + adventureInt->heroWindow->activate(); } \ No newline at end of file diff --git a/CPlayerInterface.h b/CPlayerInterface.h index cfebe9ecc..c6aa09422 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -178,6 +178,51 @@ public: void select(bool on); SDL_Surface * getImg(); }; +class CGarrisonInt; +class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable +{ +public: + CGarrisonInt *owner; + const CCreature * creature; + int count; + int upg; //upper garrison + + virtual void hover (bool on); + void clickRight (tribool down); + void clickLeft(tribool down); + void activate(); + void deactivate(); + void show(); + CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, const CCreature * Creature=NULL, int Count=0); +}; + +class CGarrisonInt :public CIntObject +{ +public: + int interx, intery; + CGarrisonSlot *highlighted; + + SDL_Surface *sur; + int offx, offy; + bool ignoreEvent; + + const CCreatureSet *set1; + const CCreatureSet *set2; + + std::vector *sup, *sdown; + + void activate(); + void deactivate(); + void show(); + void activeteSlots(); + void deactiveteSlots(); + void deleteSlots(); + void createSlots(); + void recreateSlots(); + + CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CCreatureSet * s1, const CCreatureSet *s2=NULL); + ~CGarrisonInt(); +}; class CPlayerInterface : public CGameInterface { diff --git a/SDL_Extensions.h b/SDL_Extensions.h index babea5735..c9283cc94 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -29,7 +29,7 @@ namespace CSDL_Ext SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform Uint32 colorToUint32(const SDL_Color * color); //little endian only - void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); + void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest void printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran); void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest