diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index 4e781e155..2bab53c20 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -90,7 +90,7 @@ void AdventureMapButton::activate() KeyInterested::activate(); } -void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key) +void AdventureMapButton::keyPressed (const SDL_KeyboardEvent & key) { //TODO: check if it's shortcut } @@ -272,7 +272,7 @@ void CSlider::sliderClicked() } } -void CSlider::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent) { float v = sEvent.x - pos.x - 24; v/= (pos.w - 48); diff --git a/AdventureMapButton.h b/AdventureMapButton.h index 07e923e93..e44d0dbf1 100644 --- a/AdventureMapButton.h +++ b/AdventureMapButton.h @@ -17,7 +17,7 @@ public: virtual void clickLeft (tribool down); void hover (bool on); void block(bool on); //if button is blocked then it'll change it's graphic to inactive (offset==2) and won't react on l-clicks - void keyPressed (SDL_KeyboardEvent & key); + void keyPressed (const SDL_KeyboardEvent & key); void activate(); // makes button active void deactivate(); // makes button inactive (but doesn't delete) @@ -78,7 +78,7 @@ public: void sliderClicked(); void moveLeft(); void clickLeft (tribool down); - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); void moveRight(); void moveTo(int to); void block(bool on); diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 1827eadf5..f5d25611c 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -219,7 +219,7 @@ void CMinimap::hover (bool on) else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt) LOCPLINT->adventureInt->statusbar.clear(); } -void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CMinimap::mouseMoved (const SDL_MouseMotionEvent & sEvent) { if (pressedL) { @@ -395,7 +395,7 @@ endchkpt: void CTerrainRect::clickRight(tribool down) { } -void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) { int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y)); if (pom!=curHoveredTile) @@ -438,7 +438,7 @@ void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent) } CGI->curh->changeGraphic(0,0); } -void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){} +void CTerrainRect::keyPressed (const SDL_KeyboardEvent & key){} void CTerrainRect::hover(bool on) { if (!on) @@ -698,7 +698,7 @@ void CTerrainRect::show() } } -int3 CTerrainRect::whichTileIsIt(int x, int y) +int3 CTerrainRect::whichTileIsIt(const int & x, const int & y) { int3 ret; ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32); @@ -1048,6 +1048,11 @@ void CAdvMapInt::fadventureOPtions() } void CAdvMapInt::fsystemOptions() { + LOCPLINT->curint->deactivate(); + + CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57)); + sysopWindow->activate(); + LOCPLINT->objsToBlit.push_back(sysopWindow); } void CAdvMapInt::fnextHero() { diff --git a/CAdvmapInterface.h b/CAdvmapInterface.h index fb6e183ba..51602125d 100644 --- a/CAdvmapInterface.h +++ b/CAdvmapInterface.h @@ -34,7 +34,7 @@ public: void clickRight (tribool down); void clickLeft (tribool down); void hover (bool on); - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); void activate(); // makes button active void deactivate(); // makes button inactive (but don't deletes) void hideTile(int3 pos); //puts FoW @@ -56,11 +56,11 @@ public: void clickLeft(tribool down); void clickRight(tribool down); void hover(bool on); - void mouseMoved (SDL_MouseMotionEvent & sEvent); - void keyPressed (SDL_KeyboardEvent & key); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); + void keyPressed (const SDL_KeyboardEvent & key); void show(); void showPath(); - int3 whichTileIsIt(int x, int y); //x,y are cursor position + int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position int3 whichTileIsIt(); //uses current cursor pos }; class CResDataBar diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 874d83052..3c3f3ab0e 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -248,6 +248,7 @@ void CBattleInterface::setPrintMouseShadow(bool set) void CBattleInterface::activate() { + MotionInterested::activate(); subInt = NULL; bOptions->activate(); bSurrender->activate(); @@ -270,6 +271,7 @@ void CBattleInterface::activate() void CBattleInterface::deactivate() { + MotionInterested::deactivate(); bOptions->deactivate(); bSurrender->deactivate(); bFlee->deactivate(); @@ -461,6 +463,85 @@ void CBattleInterface::show(SDL_Surface * to) } } +void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) +{ + if(activeStack>=0) + { + int myNumber = -1; //number of hovered tile + for(int g=0; g<187; ++g) + { + if(bfield[g].hovered && bfield[g].strictHovered) + { + myNumber = g; + break; + } + } + if(myNumber == -1) + { + CGI->curh->changeGraphic(1, 6); + } + else + { + if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end()) + { + CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber); + if(shere) + { + if(shere->owner == LOCPLINT->playerID) //our stack + CGI->curh->changeGraphic(1,5); + else if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isShooting()) //we can shoot enemy + CGI->curh->changeGraphic(1,3); + else if(isTileAttackable(myNumber)) //available enemy (melee attackable) + { + int fromHex = -1; + for(int b=0; b<187; ++b) + if(bfield[b].hovered && !bfield[b].strictHovered) + { + fromHex = b; + break; + } + if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16) + { + switch(BattleInfo::mutualPosition(fromHex, myNumber)) + { + case 0: + CGI->curh->changeGraphic(1,12); + break; + case 1: + CGI->curh->changeGraphic(1,7); + break; + case 2: + CGI->curh->changeGraphic(1,8); + break; + case 3: + CGI->curh->changeGraphic(1,9); + break; + case 4: + CGI->curh->changeGraphic(1,10); + break; + case 5: + CGI->curh->changeGraphic(1,11); + break; + } + } + } + else //unavailable enemy + CGI->curh->changeGraphic(1,0); + } + else //empty unavailable tile + CGI->curh->changeGraphic(1,0); + } + else //available tile + { + if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying()) + CGI->curh->changeGraphic(1,2); + else + CGI->curh->changeGraphic(1,1); + } + } + } +} + bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick) { if(creAnims[number]==NULL) @@ -518,7 +599,6 @@ void CBattleInterface::bSurrenderf() void CBattleInterface::bFleef() { - CFunctionList ony = boost::bind(&CBattleInterface::activate,this); ony += boost::bind(&CBattleInterface::reallyFlee,this); LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, boost::bind(&CBattleInterface::activate,this), true, false); @@ -951,6 +1031,16 @@ void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 addit activeStack = -1; } +bool CBattleInterface::isTileAttackable(int number) +{ + for(int b=0; bowner != attackingHeroInstance->tempOwner) //attacking { - std::vector n = BattleInfo::neighbouringTiles(whichOne); - for(int i=0;i n = BattleInfo::neighbouringTiles(whichOne); + //for(int i=0;icurh->number) { - //TODO: now we are using first available tile, but in the future we should add possibility of choosing from which tile we want to attack - if(vstd::contains(shadedHexes,n[i])) - { - giveCommand(6,n[i],activeStack,whichOne); - return; - } + case 12: + giveCommand(6,whichOne + ( (whichOne/17)%2 ? 17 : 18 ),activeStack,whichOne); + break; + case 7: + giveCommand(6,whichOne + ( (whichOne/17)%2 ? 16 : 17 ),activeStack,whichOne); + break; + case 8: + giveCommand(6,whichOne - 1,activeStack,whichOne); + break; + case 9: + giveCommand(6,whichOne - ( (whichOne/17)%2 ? 18 : 17 ),activeStack,whichOne); + break; + case 10: + giveCommand(6,whichOne - ( (whichOne/17)%2 ? 17 : 16 ),activeStack,whichOne); + break; + case 11: + giveCommand(6,whichOne + 1,activeStack,whichOne); + break; } } } @@ -1089,6 +1200,8 @@ float CBattleInterface::getAnimSpeedMultiplier() const return 2.2f; case 4: return 1.0f; + default: + return 0.0f; } } @@ -1415,7 +1528,7 @@ void CBattleHero::clickLeft(boost::logic::tribool down) } } -CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero) +CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero) { dh = CDefHandler::giveDef( defName ); for(int i=0; iourImages.size(); ++i) //transforming images @@ -1508,7 +1621,7 @@ CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strict { } -void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent) +void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) { if(myInterface->cellShade) { @@ -1519,31 +1632,6 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent) else //hovered pixel is inside hex { strictHovered = true; - if(myInterface->activeStack>=0) - { - if(std::find(myInterface->shadedHexes.begin(),myInterface->shadedHexes.end(),myNumber) == myInterface->shadedHexes.end()) - { - CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber); - if(shere) - { - if(shere->owner == LOCPLINT->playerID) //our stack - CGI->curh->changeGraphic(1,5); - else if(LOCPLINT->cb->battleGetStackByID(myInterface->activeStack)->creature->isShooting()) //we can shoot enemy - CGI->curh->changeGraphic(1,3); - else //unavailable enemy - CGI->curh->changeGraphic(1,0); - } - else //empty unavailable tile - CGI->curh->changeGraphic(1,0); - } - else //available tile - { - if(LOCPLINT->cb->battleGetStackByID(myInterface->activeStack)->creature->isFlying()) - CGI->curh->changeGraphic(1,2); - else - CGI->curh->changeGraphic(1,1); - } - } } } @@ -1555,7 +1643,7 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent) { char tabh[160]; CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber); - std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; + const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); myInterface->console->alterTxt = std::string(tabh); setAlterText = true; @@ -1632,7 +1720,7 @@ void CBattleConsole::show(SDL_Surface * to) } } -bool CBattleConsole::addText(std::string text) +bool CBattleConsole::addText(const std::string & text) { if(text.size()>70) return false; //text too long! @@ -1661,7 +1749,7 @@ void CBattleConsole::eraseText(unsigned int pos) } } -void CBattleConsole::changeTextAt(std::string text, unsigned int pos) +void CBattleConsole::changeTextAt(const std::string & text, unsigned int pos) { if(pos >= texts.size()) //no such pos return; diff --git a/CBattleInterface.h b/CBattleInterface.h index a8d90082d..945ed2c77 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -27,7 +27,7 @@ public: void activate(); void deactivate(); void clickLeft(boost::logic::tribool down); - CBattleHero(std::string defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero); //c-tor + CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero); //c-tor ~CBattleHero(); //d-tor }; @@ -48,7 +48,7 @@ public: void hover (bool on); void activate(); void deactivate(); - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); void clickLeft(boost::logic::tribool down); void clickRight(boost::logic::tribool down); CBattleHex(); @@ -69,9 +69,9 @@ public: CBattleConsole(); //c-tor ~CBattleConsole(); //d-tor void show(SDL_Surface * to = 0); - bool addText(std::string text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) + bool addText(const std::string & text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) void eraseText(unsigned int pos); //erases added text at position pos - void changeTextAt(std::string text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one + void changeTextAt(const std::string & text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one void scrollUp(unsigned int by = 1); //scrolls console up by 'by' positions void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions }; @@ -112,7 +112,7 @@ public: void show(SDL_Surface * to = 0); }; -class CBattleInterface : public CMainInterface +class CBattleInterface : public CMainInterface, public MotionInterested { private: SDL_Surface * background, * menu, * amountBasic, * amountNormal, * cellBorders, * backgroundWithHexes; @@ -160,6 +160,7 @@ private: std::list projectiles; void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1); + bool isTileAttackable(int number); //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor ~CBattleInterface(); //d-tor @@ -198,6 +199,7 @@ public: void activate(); void deactivate(); void show(SDL_Surface * to = NULL); + void mouseMoved(const SDL_MouseMotionEvent &sEvent); bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing //call-ins diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index dc7b0d66b..259cbbec7 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -143,7 +143,7 @@ void CBuildingRect::clickRight (tribool down) } } -void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) { if(area) { diff --git a/CCastleInterface.h b/CCastleInterface.h index dedaf517e..fc476f709 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -26,7 +26,7 @@ public: void hover(bool on); void clickLeft (tribool down); void clickRight (tribool down); - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); }; class CHeroGSlot : public ClickableL, public ClickableR, public Hoverable { diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index 8166d229b..4ecfcf285 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -18,13 +18,13 @@ void CCursorHandler::initCursor() SDL_ShowCursor(SDL_DISABLE); } -void CCursorHandler::changeGraphic(int type, int no) +void CCursorHandler::changeGraphic(const int & type, const int & no) { mode = type; number = no; } -void CCursorHandler::cursorMove(int x, int y) +void CCursorHandler::cursorMove(const int & x, const int & y) { xpos = x; ypos = y; diff --git a/CCursorHandler.h b/CCursorHandler.h index ffdf649b3..4f26bc939 100644 --- a/CCursorHandler.h +++ b/CCursorHandler.h @@ -16,8 +16,8 @@ public: std::vector cursors; int xpos, ypos; //position of cursor void initCursor(); //inits cursorHandler - void cursorMove(int x, int y); //change cursor's positions to (x, y) - void changeGraphic(int type, int no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) + void cursorMove(const int & x, const int & y); //change cursor's positions to (x, y) + void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) void draw1(); void draw2(); void hide(){Show=0;}; diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 7bfba07fe..0b7909233 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2269,7 +2269,7 @@ void CStatusBar::clear() SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y); SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom); } -void CStatusBar::print(std::string text) +void CStatusBar::print(const std::string & text) { current=text; SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y); @@ -2432,7 +2432,7 @@ void CHeroList::clickLeft(tribool down) } } -void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CHeroList::mouseMoved (const SDL_MouseMotionEvent & sEvent) { if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y)) { @@ -2502,7 +2502,7 @@ void CHeroList::clickRight(tribool down) void CHeroList::hover (bool on) { } -void CHeroList::keyPressed (SDL_KeyboardEvent & key) +void CHeroList::keyPressed (const SDL_KeyboardEvent & key) { } void CHeroList::updateHList() @@ -2617,7 +2617,7 @@ void CTownList::select(int which) fun(); } -void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CTownList::mouseMoved (const SDL_MouseMotionEvent & sEvent) { if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y)) { @@ -2749,7 +2749,7 @@ void CTownList::hover (bool on) { } -void CTownList::keyPressed (SDL_KeyboardEvent & key) +void CTownList::keyPressed (const SDL_KeyboardEvent & key) { } @@ -3070,7 +3070,7 @@ void CSplitWindow::show(SDL_Surface * to) anim->blitPic(screen,pos.x+20,pos.y+54,false); anim->blitPic(screen,pos.x+177,pos.y+54,false); } -void CSplitWindow::keyPressed (SDL_KeyboardEvent & key) +void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key) { //TODO: make manual typing possible } @@ -3287,7 +3287,7 @@ void CCreInfoWindow::dismissF() dsm(); close(); } -void CCreInfoWindow::keyPressed (SDL_KeyboardEvent & key) +void CCreInfoWindow::keyPressed (const SDL_KeyboardEvent & key) { } void CCreInfoWindow::deactivate() @@ -3732,4 +3732,88 @@ void CMarketplaceWindow::selectionChanged(bool side) rSubs[i] = oss.str(); } } -} \ No newline at end of file +} + +CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos) +{ + this->pos = pos; + background = BitmapHandler::loadBitmap("SysOpbck.bmp", true); + graphics->blueToPlayersAdv(background, LOCPLINT->playerID); + + //printing texts + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[568], 240, 32, GEOR16, tytulowy, background); //window title + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[569], 122, 65, GEOR16, tytulowy, background); //hero speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[570], 122, 131, GEOR16, tytulowy, background); //enemy speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[571], 122, 197, GEOR16, tytulowy, background); //map scroll speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[20], 122, 263, GEOR16, tytulowy, background); //video quality + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 348, GEOR16, tytulowy, background); //music volume + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 414, GEOR16, tytulowy, background); //effects volume + + CSDL_Ext::printAt(CGI->generaltexth->allTexts[572], 283, 57, GEOR16, zwykly, background); //show move path + CSDL_Ext::printAt(CGI->generaltexth->allTexts[573], 283, 89, GEOR16, zwykly, background); //show hero reminder + CSDL_Ext::printAt(CGI->generaltexth->allTexts[574], 283, 121, GEOR16, zwykly, background); //quick combat + CSDL_Ext::printAt(CGI->generaltexth->allTexts[575], 283, 153, GEOR16, zwykly, background); //video subtitles + CSDL_Ext::printAt(CGI->generaltexth->allTexts[576], 283, 185, GEOR16, zwykly, background); //town building outlines + CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 283, 217, GEOR16, zwykly, background); //spell book animation + + //setting up buttons + quitGame = new AdventureMapButton (CGI->preth->zelp[324].first, CGI->preth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 405, 471, "soquit.def", false, NULL, false); + std::swap(quitGame->imgs[0][0], quitGame->imgs[0][1]); + backToMap = new AdventureMapButton (CGI->preth->zelp[325].first, CGI->preth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 516, 471, "soretrn.def", false, NULL, false); + std::swap(backToMap->imgs[0][0], backToMap->imgs[0][1]); +} + +CSystemOptionsWindow::~CSystemOptionsWindow() +{ + SDL_FreeSurface(background); + + delete quitGame; + delete backToMap; +} + +void CSystemOptionsWindow::bquitf() +{ + this->deactivate(); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector(), boost::bind(exit, 0), boost::bind(&CSystemOptionsWindow::activate, this), false, false); +} + +void CSystemOptionsWindow::breturnf() +{ + deactivate(); + + for(int g=0; gobjsToBlit.size(); ++g) + { + if(dynamic_cast(LOCPLINT->objsToBlit[g])) + { + LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g); + break; + } + } + + delete this; + LOCPLINT->curint->activate(); +} + +void CSystemOptionsWindow::activate() +{ + quitGame->activate(); + backToMap->activate(); +} + +void CSystemOptionsWindow::deactivate() +{ + quitGame->deactivate(); + backToMap->deactivate(); +} + +void CSystemOptionsWindow::show(SDL_Surface *to) +{ + //evaluating to + if(!to) + to = screen; + + SDL_BlitSurface(background, NULL, to, &pos); + + quitGame->show(to); + backToMap->show(to); +} diff --git a/CPlayerInterface.h b/CPlayerInterface.h index d0f6915d6..9624f8651 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -44,7 +44,7 @@ class IStatusBar { public: virtual ~IStatusBar(){}; //d-tor - virtual void print(std::string text)=0; //prints text and refreshes statusbar + virtual void print(const std::string & text)=0; //prints text and refreshes statusbar virtual void clear()=0;//clears statusbar and refreshes virtual void show()=0; //shows statusbar (with current text) virtual std::string getCurrent()=0; @@ -134,7 +134,7 @@ class KeyInterested : public virtual CIntObject { public: virtual ~KeyInterested(){}; - virtual void keyPressed (SDL_KeyboardEvent & key)=0; + virtual void keyPressed (const SDL_KeyboardEvent & key)=0; virtual void activate()=0; virtual void deactivate()=0; }; @@ -144,7 +144,7 @@ public: bool strongInterest; //if true - report all mouse movements, if not - only when hovered MotionInterested(){strongInterest=false;}; virtual ~MotionInterested(){}; - virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0; + virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; virtual void activate()=0; virtual void deactivate()=0; }; @@ -400,7 +400,7 @@ public: CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor ~CStatusBar(); //d-tor - void print(std::string text); //prints text and refreshes statusbar + void print(const std::string & text); //prints text and refreshes statusbar void clear();//clears statusbar and refreshes void show(); //shows statusbar (with current text) std::string getCurrent(); @@ -424,7 +424,7 @@ public: void clickLeft(boost::logic::tribool down); void activate(); void deactivate(); - virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0; + virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; virtual void genList()=0; virtual void select(int which)=0; virtual void draw()=0; @@ -441,11 +441,11 @@ public: int getPosOfHero(const CArmedInstance* h); void genList(); void select(int which); - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); void clickLeft(boost::logic::tribool down); void clickRight(boost::logic::tribool down); void hover (bool on); - void keyPressed (SDL_KeyboardEvent & key); + void keyPressed (const SDL_KeyboardEvent & key); void updateHList(); void updateMove(const CGHeroInstance* which); //draws move points bar void redrawAllOne(int which); @@ -465,11 +465,11 @@ public: ~CTownList(); void genList(); void select(int which); - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); void clickLeft(boost::logic::tribool down); void clickRight(boost::logic::tribool down); void hover (bool on); - void keyPressed (SDL_KeyboardEvent & key); + void keyPressed (const SDL_KeyboardEvent & key); void draw(); }; @@ -534,7 +534,7 @@ public: void close(); void deactivate(); void show(SDL_Surface * to = NULL); - void keyPressed (SDL_KeyboardEvent & key); + void keyPressed (const SDL_KeyboardEvent & key); void sliderMoved(int to); }; @@ -560,7 +560,7 @@ public: void close(); void clickRight(boost::logic::tribool down); void dismissF(); - void keyPressed (SDL_KeyboardEvent & key); + void keyPressed (const SDL_KeyboardEvent & key); void deactivate(); void show(SDL_Surface * to = NULL); void onUpgradeYes(); @@ -636,6 +636,24 @@ public: void clear(); }; +class CSystemOptionsWindow : public IShowActivable, public CIntObject +{ +private: + SDL_Surface * background; //background of window + AdventureMapButton * quitGame, * backToMap; +public: + CSystemOptionsWindow(const SDL_Rect & pos); //c-tor + ~CSystemOptionsWindow(); //d-tor + + //functions for butons + void bquitf(); //quit game + void breturnf(); //return to game + + void activate(); + void deactivate(); + void show(SDL_Surface * to = NULL); +}; + extern CPlayerInterface * LOCPLINT; #endif //CPLAYERINTERFACE_H diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 1de8ee97e..22953f51d 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -69,7 +69,7 @@ void updateRect (SDL_Rect * rect, SDL_Surface * scr) { SDL_UpdateRect(scr,rect->x,rect->y,rect->w,rect->h); } -void CSDL_Ext::printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst) +void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst) { std::vector * ws = CMessage::breakText(text,charpr); std::vector wesu; @@ -97,7 +97,7 @@ void CSDL_Ext::printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, SDL_FreeSurface(wesu[i]); delete ws; } -void CSDL_Ext::printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst) +void CSDL_Ext::printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst) { std::vector * ws = CMessage::breakText(text,charpr); std::vector wesu; @@ -116,7 +116,7 @@ void CSDL_Ext::printAtWB(std::string text, int x, int y, TTF_Font * font, int ch SDL_FreeSurface(wesu[i]); delete ws; } -void CSDL_Ext::printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality, bool refresh) +void CSDL_Ext::printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality, bool refresh) { if(text.length()==0) return; SDL_Surface * temp; @@ -145,7 +145,7 @@ void CSDL_Ext::printAtMiddle(std::string text, int x, int y, TTF_Font * font, SD SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h); SDL_FreeSurface(temp); } -void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) +void CSDL_Ext::printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) { if (text.length()==0) return; @@ -174,7 +174,7 @@ void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Colo SDL_UpdateRect(dst,x,y,temp->w,temp->h); SDL_FreeSurface(temp); } -void CSDL_Ext::printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) +void CSDL_Ext::printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) { if (text.length()==0) return; @@ -204,7 +204,7 @@ void CSDL_Ext::printTo(std::string text, int x, int y, TTF_Font * font, SDL_Colo SDL_FreeSurface(temp); } -void CSDL_Ext::printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) +void CSDL_Ext::printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) { if (text.length()==0) return; diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 2b87efe39..8d01d1fa6 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -36,12 +36,12 @@ namespace CSDL_Ext SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface 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=screen, 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 printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, 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=screen, unsigned char quality = 2, bool refresh = false); // 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=screen); - void printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); - void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest + void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, 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 printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, 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(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest + void printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); + void printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); + void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest void update(SDL_Surface * what = screen); //updates whole surface (default - main screen) void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color); void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index 995c4ac45..d215eb276 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -16,7 +16,7 @@ extern SDL_Surface * screen; extern SDL_Color tytulowy, zwykly ; extern TTF_Font *GEOR16; -SpellbookInteractiveArea::SpellbookInteractiveArea(SDL_Rect & myRect, boost::function funcL, std::string textR, boost::function funcHon, boost::function funcHoff) +SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff) { pos = myRect; onLeft = funcL; diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index 89a552aec..f25b7f2ea 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -21,7 +21,7 @@ public: void activate(); void deactivate(); - SpellbookInteractiveArea(SDL_Rect & myRect, boost::function funcL, std::string textR, boost::function funcHon, boost::function funcHoff);//c-tor + SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff);//c-tor }; class CSpellWindow : public IShowActivable, public CIntObject