From 59b2bb4940bda8d7e3730279e7f8544b961b2157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 11 Feb 2009 17:03:30 +0000 Subject: [PATCH] * fixed scrolling behind window problem (now it's possible to scroll with CTRL + arrows) * proper updating resdatabar after building structure in town or buying creatures (non 800x600 res) * fixed blinking resdatabar in town screen when buying (800x600) * updating blockmap/visitmap of randomized objects * blocked "save" command during battle * cannot select heroes for computer player (pregame) * fixed mouse slow downs in pregame --- CAdvmapInterface.cpp | 82 ++++++++++++++++++--------------------- CAdvmapInterface.h | 6 +-- CCastleInterface.cpp | 6 +-- CCastleInterface.h | 2 +- CGameState.cpp | 3 ++ CMT.cpp | 2 +- CPlayerInterface.cpp | 33 ++++++++++------ CPlayerInterface.h | 91 +++++++++++++++++++++++++++++++++++++++++++- CPreGame.cpp | 16 +++++--- SDL_Extensions.h | 1 - client/Client.cpp | 6 +++ 11 files changed, 176 insertions(+), 72 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 3ef980c2d..6f5250201 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -1167,10 +1167,7 @@ townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlis LOCPLINT->adventureInt=this; bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic); graphics->blueToPlayersAdv(bg,player); - scrollingLeft = false; - scrollingRight = false; - scrollingUp = false ; - scrollingDown = false ; + scrollingDir = 0; updateScreen = false; anim=0; animValHitCount=0; //animation frame @@ -1365,43 +1362,32 @@ void CAdvMapInt::update() updateScreen = true; } ++heroAnim; - if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0 && !LOCPLINT->showingDialog->get()) + + //if advmap needs updating AND (no dialog is shown OR ctrl is pressed) + if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0 + && + (!LOCPLINT->showingDialog->get() + && !LOCPLINT->curint->subInt) + || SDL_GetKeyState(NULL)[SDLK_LCTRL] + || SDL_GetKeyState(NULL)[SDLK_RCTRL] + ) { - if(scrollingLeft) + if( (scrollingDir & LEFT) && (position.x>-Woff) ) + position.x--; + + if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - terrain.tilesw + Woff) ) + position.x++; + + if( (scrollingDir & UP) && (position.y>-Hoff) ) + position.y--; + + if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - terrain.tilesh + Hoff) ) + position.y++; + + if(scrollingDir) { - if(position.x>-Woff) - { - position.x--; - updateScreen = true; - updateMinimap=true; - } - } - if(scrollingRight) - { - if(position.x < CGI->mh->map->width - terrain.tilesw + Woff ) - { - position.x++; - updateScreen = true; - updateMinimap=true; - } - } - if(scrollingUp) - { - if(position.y>-Hoff) - { - position.y--; - updateScreen = true; - updateMinimap=true; - } - } - if(scrollingDown) - { - if(position.y < CGI->mh->map->height - terrain.tilesh + Hoff) - { - position.y++; - updateScreen = true; - updateMinimap=true; - } + updateScreen = true; + updateMinimap=true; } } if(updateScreen) @@ -1438,25 +1424,31 @@ void CAdvMapInt::centerOn(int3 on) } void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) { - bool CAdvMapInt::* scrollDir; + ui8 Dir; switch(key.keysym.sym) { case SDLK_UP: - scrollDir = &CAdvMapInt::scrollingUp; + Dir = UP; break; case SDLK_LEFT: - scrollDir = &CAdvMapInt::scrollingLeft; + Dir = LEFT; break; case SDLK_RIGHT: - scrollDir = &CAdvMapInt::scrollingRight; + Dir = RIGHT; break; case SDLK_DOWN: - scrollDir = &CAdvMapInt::scrollingDown; + Dir = DOWN; break; default: return; } - this->*scrollDir = key.state==SDL_PRESSED; + if(key.state == SDL_PRESSED //arrow is pressed + && (SDL_GetKeyState(NULL)[SDLK_LCTRL] + || SDL_GetKeyState(NULL)[SDLK_RCTRL]) + ) + scrollingDir |= Dir; + else + scrollingDir &= ~Dir; } void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client) { diff --git a/CAdvmapInterface.h b/CAdvmapInterface.h index d202317cd..661486810 100644 --- a/CAdvmapInterface.h +++ b/CAdvmapInterface.h @@ -110,10 +110,8 @@ public: std::vector gems; - bool scrollingLeft ; - bool scrollingRight ; - bool scrollingUp ; - bool scrollingDown ; + enum{LEFT=1, RIGHT=2, UP=4, DOWN=8}; + ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN bool updateScreen, updateMinimap ; unsigned char anim, animValHitCount; //animation frame unsigned char heroAnim, heroAnimValHitCount; //animation frame diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index eeeb4fc40..f9577f54b 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -1336,6 +1336,7 @@ void CFortScreen::show( SDL_Surface * to) void CFortScreen::activate() { LOCPLINT->curint->subInt = this; + LOCPLINT->statusbar = LOCPLINT->castleInt->statusbar; exit->activate(); for (size_t i=0;ipos = positions[i]; + recAreas.back()->pos = positions[i] + pos; } } } diff --git a/CCastleInterface.h b/CCastleInterface.h index 1ef132cea..cc036014f 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -167,7 +167,7 @@ public: CMinorResDataBar resdatabar; AdventureMapButton *exit; SDL_Surface * bg; - std::vector positions; + std::vector positions; std::vector recAreas; std::vector crePics; diff --git a/CGameState.cpp b/CGameState.cpp index 6daf11fdb..ba7116809 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -1146,12 +1146,15 @@ void CGameState::randomizeObject(CGObjectInstance *cur) //we have to replace normal random object cur->ID = ran.first; cur->subID = ran.second; + map->removeBlockVisTiles(cur); //recalculate blockvis tiles - picked object might have different than random placeholder map->defy.push_back(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]); if(!cur->defInfo) { tlog1<<"*BIG* WARNING: Missing def declaration for "<ID<<" "<subID<addBlockVisTiles(cur); } int CGameState::getDate(int mode) const diff --git a/CMT.cpp b/CMT.cpp index 55facf305..cbfcfd03b 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -290,7 +290,7 @@ void processCommand(const std::string &message, CClient *&client) std::cin >> i; if(!i) return; - else if(i < 0 || i >= conf.guiOptions.size()) + else if(i < 0 || i > conf.guiOptions.size()) { tlog1 << "Invalid resolution ID! Not a number between 0 and " << conf.guiOptions.size() << ". No settings changed.\n"; } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index b7d3eb6f5..a584026b0 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -900,9 +900,9 @@ void CSelWindow::close() } } LOCPLINT->curint->activate(); + LOCPLINT->showingDialog->setn(false); LOCPLINT->cb->selectionMade(ret,ID); delete this; - //call owner with selection result } CButtonBase::CButtonBase() { @@ -1748,6 +1748,7 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent) { + //sending active, hovered hoverable objects hover() call std::vector hlp; for(std::list::iterator i=hoverable.begin(); i != hoverable.end();i++) { @@ -1763,6 +1764,8 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent) } for(int i=0; ihover(true); + + //sending active, MotionInterested objects mouseMoved() call std::list miCopy = motioninterested; for(std::list::iterator i=miCopy.begin(); i != miCopy.end();i++) { @@ -1771,39 +1774,41 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent) (*i)->mouseMoved(sEvent->motion); } } + + //adventure map scrolling with mouse if(!SDL_GetKeyState(NULL)[SDLK_LCTRL]) { if(sEvent->motion.x<15) { - LOCPLINT->adventureInt->scrollingLeft = true; + adventureInt->scrollingDir |= CAdvMapInt::LEFT; } else { - LOCPLINT->adventureInt->scrollingLeft = false; + adventureInt->scrollingDir &= ~CAdvMapInt::LEFT; } if(sEvent->motion.x>screen->w-15) { - LOCPLINT->adventureInt->scrollingRight = true; + adventureInt->scrollingDir |= CAdvMapInt::RIGHT; } else { - LOCPLINT->adventureInt->scrollingRight = false; + adventureInt->scrollingDir &= ~CAdvMapInt::RIGHT; } if(sEvent->motion.y<15) { - LOCPLINT->adventureInt->scrollingUp = true; + adventureInt->scrollingDir |= CAdvMapInt::UP; } else { - LOCPLINT->adventureInt->scrollingUp = false; + adventureInt->scrollingDir &= ~CAdvMapInt::UP; } if(sEvent->motion.y>screen->h-15) { - LOCPLINT->adventureInt->scrollingDown = true; + adventureInt->scrollingDir |= CAdvMapInt::DOWN; } else { - LOCPLINT->adventureInt->scrollingDown = false; + adventureInt->scrollingDir &= ~CAdvMapInt::DOWN; } } } @@ -1910,14 +1915,17 @@ void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero) void CPlayerInterface::receivedResource(int type, int val) { boost::unique_lock un(*pim); - if(curint==adventureInt || curint==castleInt) + if(curint==adventureInt || screen->h > 600 || screen->w > 800) adventureInt->resdatabar.draw(); + if(curint==castleInt && !curint->subInt) + castleInt->resdatabar->draw(); } void CPlayerInterface::showSelDialog(std::string &text, const std::vector &components, ui32 askID) //void CPlayerInterface::showSelDialog(std::string text, std::vector & components, int askID) { boost::unique_lock un(*pim); + LOCPLINT->showingDialog->setn(true); adventureInt->hide(); //dezaktywacja starego interfejsu std::vector intComps; for(int i=0;icond.wait(un); } boost::unique_lock un(*pim); + LOCPLINT->showingDialog->setn(true); CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback); curint->deactivate(); lw->activate(); @@ -2257,8 +2266,8 @@ void CPlayerInterface::showInfoDialog(std::string &text, const std::vector & components) { - showingDialog->set(true); boost::unique_lock un(*pim); + showingDialog->set(true); curint->deactivate(); //dezaktywacja starego interfejsu std::vector > > pom; @@ -2272,6 +2281,7 @@ void CPlayerInterface::showInfoDialog(std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool deactivateCur, bool DelComps) { boost::unique_lock un(*pim); + LOCPLINT->showingDialog->setn(true); if(deactivateCur) curint->deactivate(); //dezaktywacja starego interfejsu std::vector > > pom; @@ -2295,6 +2305,7 @@ void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector &components, ui32 askID ) { boost::unique_lock un(*pim); + LOCPLINT->showingDialog->setn(false); curint->deactivate(); //dezaktywacja starego interfejsu std::vector intComps; diff --git a/CPlayerInterface.h b/CPlayerInterface.h index cf51ca171..4aa5e38d2 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -39,6 +39,89 @@ namespace boost class recursive_mutex; }; +struct Point +{ + int x, y; + + //constructors + Point(){}; + Point(int X, int Y) + :x(X),y(Y) + {}; + Point(const int3 &a) + :x(a.x),y(a.y) + {} + + + + Point operator+(const Point &b) + { + return Point(x+b.x,y+b.y); + } + Point operator-(const Point &b) + { + return Point(x+b.x,y+b.y); + } + bool operator<(const Point &b) + { + return x < b.x && y < b.y; + } +}; + +struct Rect : public SDL_Rect +{ + Rect() + { + x = y = w = h = -1; + } + Rect(int X, int Y, int W, int H) + { + x = X; + y = Y; + w = W; + h = H; + }; + Rect(const SDL_Rect & r) + { + x = r.x; + y = r.y; + w = r.w; + h = r.h; + }; + bool isIn(int qx, int qy) + { + if (qx > x && qxy && qycastle<0) + if (ourOpt->castle<0 + || !ourOpt->human + ) { break; } @@ -579,6 +581,11 @@ void Options::PlayerFlag::press(bool down) break; CPG->ret.playerInfos[i].human = true; CPG->ret.playerInfos[j].human = false; + if(CPG->ret.playerInfos[j].hero >= 0) + { + CPG->ret.playerInfos[j].hero = -1; + CPG->ourOptions->showIcon(0,j,false); + } std::string pom = CPG->ret.playerInfos[i].name; CPG->ret.playerInfos[i].name = CPG->ret.playerInfos[j].name; CPG->ret.playerInfos[j].name = pom; @@ -2007,7 +2014,7 @@ StartInfo CPreGame::runLoop() { try { - if(SDL_PollEvent(&sEvent)) //wait for event... + while(SDL_PollEvent(&sEvent)) //handle all events { menuItems * current = currentItems(); if(sEvent.type==SDL_QUIT) @@ -2267,9 +2274,8 @@ StartInfo CPreGame::runLoop() hideBox(); } } - } - catch(...) - { continue; } + } HANDLE_EXCEPTION + CGI->curh->draw1(); SDL_Flip(screen); CGI->curh->draw2(); diff --git a/SDL_Extensions.h b/SDL_Extensions.h index d338eedc2..90cf36008 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -3,7 +3,6 @@ #include "SDL.h" #include "SDL_ttf.h" - extern SDL_Surface * screen; extern SDL_Color tytulowy, tlo, zwykly ; extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; diff --git a/client/Client.cpp b/client/Client.cpp index cf0e8ff2a..79a8de00b 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -626,6 +626,12 @@ void CClient::close() void CClient::save(const std::string & fname) { + if(gs->curB) + { + tlog1 << "Game cannot be saved during battle!\n"; + return; + } + *serv << ui16(98) << fname; }