1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* 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
This commit is contained in:
Michał W. Urbańczyk 2009-02-11 17:03:30 +00:00
parent 489bd1e4f2
commit 59b2bb4940
11 changed files with 176 additions and 72 deletions

View File

@ -1167,10 +1167,7 @@ townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlis
LOCPLINT->adventureInt=this; LOCPLINT->adventureInt=this;
bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic); bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
graphics->blueToPlayersAdv(bg,player); graphics->blueToPlayersAdv(bg,player);
scrollingLeft = false; scrollingDir = 0;
scrollingRight = false;
scrollingUp = false ;
scrollingDown = false ;
updateScreen = false; updateScreen = false;
anim=0; anim=0;
animValHitCount=0; //animation frame animValHitCount=0; //animation frame
@ -1365,43 +1362,32 @@ void CAdvMapInt::update()
updateScreen = true; updateScreen = true;
} }
++heroAnim; ++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) updateScreen = true;
{ updateMinimap=true;
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;
}
} }
} }
if(updateScreen) if(updateScreen)
@ -1438,25 +1424,31 @@ void CAdvMapInt::centerOn(int3 on)
} }
void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
{ {
bool CAdvMapInt::* scrollDir; ui8 Dir;
switch(key.keysym.sym) switch(key.keysym.sym)
{ {
case SDLK_UP: case SDLK_UP:
scrollDir = &CAdvMapInt::scrollingUp; Dir = UP;
break; break;
case SDLK_LEFT: case SDLK_LEFT:
scrollDir = &CAdvMapInt::scrollingLeft; Dir = LEFT;
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
scrollDir = &CAdvMapInt::scrollingRight; Dir = RIGHT;
break; break;
case SDLK_DOWN: case SDLK_DOWN:
scrollDir = &CAdvMapInt::scrollingDown; Dir = DOWN;
break; break;
default: default:
return; 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) void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
{ {

View File

@ -110,10 +110,8 @@ public:
std::vector<CDefHandler *> gems; std::vector<CDefHandler *> gems;
bool scrollingLeft ; enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
bool scrollingRight ; ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
bool scrollingUp ;
bool scrollingDown ;
bool updateScreen, updateMinimap ; bool updateScreen, updateMinimap ;
unsigned char anim, animValHitCount; //animation frame unsigned char anim, animValHitCount; //animation frame
unsigned char heroAnim, heroAnimValHitCount; //animation frame unsigned char heroAnim, heroAnimValHitCount; //animation frame

View File

@ -1336,6 +1336,7 @@ void CFortScreen::show( SDL_Surface * to)
void CFortScreen::activate() void CFortScreen::activate()
{ {
LOCPLINT->curint->subInt = this; LOCPLINT->curint->subInt = this;
LOCPLINT->statusbar = LOCPLINT->castleInt->statusbar;
exit->activate(); exit->activate();
for (size_t i=0;i<recAreas.size(); ++i) for (size_t i=0;i<recAreas.size(); ++i)
{ {
@ -1373,8 +1374,7 @@ CFortScreen::CFortScreen( CCastleInterface * owner )
genRect(126,386,10,288),genRect(126,386,404,288), genRect(126,386,10,288),genRect(126,386,404,288),
genRect(126,386,206,421); genRect(126,386,206,421);
draw(owner,true); draw(owner,true);
resdatabar.pos.x += pos.x; resdatabar.pos += pos;
resdatabar.pos.y += pos.y;
} }
void CFortScreen::draw( CCastleInterface * owner, bool first) void CFortScreen::draw( CCastleInterface * owner, bool first)
@ -1449,7 +1449,7 @@ void CFortScreen::draw( CCastleInterface * owner, bool first)
if(present) if(present)
{ {
recAreas.push_back(new RecArea(30+i+upgraded*7)); recAreas.push_back(new RecArea(30+i+upgraded*7));
recAreas[recAreas.size()-1]->pos = positions[i]; recAreas.back()->pos = positions[i] + pos;
} }
} }
} }

View File

@ -167,7 +167,7 @@ public:
CMinorResDataBar resdatabar; CMinorResDataBar resdatabar;
AdventureMapButton *exit; AdventureMapButton *exit;
SDL_Surface * bg; SDL_Surface * bg;
std::vector<SDL_Rect> positions; std::vector<Rect> positions;
std::vector<RecArea*> recAreas; std::vector<RecArea*> recAreas;
std::vector<CCreaturePic*> crePics; std::vector<CCreaturePic*> crePics;

View File

@ -1146,12 +1146,15 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
//we have to replace normal random object //we have to replace normal random object
cur->ID = ran.first; cur->ID = ran.first;
cur->subID = ran.second; 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]); map->defy.push_back(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]);
if(!cur->defInfo) if(!cur->defInfo)
{ {
tlog1<<"*BIG* WARNING: Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl; tlog1<<"*BIG* WARNING: Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl;
return; return;
} }
map->addBlockVisTiles(cur);
} }
int CGameState::getDate(int mode) const int CGameState::getDate(int mode) const

View File

@ -290,7 +290,7 @@ void processCommand(const std::string &message, CClient *&client)
std::cin >> i; std::cin >> i;
if(!i) if(!i)
return; 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"; tlog1 << "Invalid resolution ID! Not a number between 0 and " << conf.guiOptions.size() << ". No settings changed.\n";
} }

View File

@ -900,9 +900,9 @@ void CSelWindow::close()
} }
} }
LOCPLINT->curint->activate(); LOCPLINT->curint->activate();
LOCPLINT->showingDialog->setn(false);
LOCPLINT->cb->selectionMade(ret,ID); LOCPLINT->cb->selectionMade(ret,ID);
delete this; delete this;
//call owner with selection result
} }
CButtonBase::CButtonBase() CButtonBase::CButtonBase()
{ {
@ -1748,6 +1748,7 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent) void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
{ {
//sending active, hovered hoverable objects hover() call
std::vector<Hoverable*> hlp; std::vector<Hoverable*> hlp;
for(std::list<Hoverable*>::iterator i=hoverable.begin(); i != hoverable.end();i++) for(std::list<Hoverable*>::iterator i=hoverable.begin(); i != hoverable.end();i++)
{ {
@ -1763,6 +1764,8 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
} }
for(int i=0; i<hlp.size();i++) for(int i=0; i<hlp.size();i++)
hlp[i]->hover(true); hlp[i]->hover(true);
//sending active, MotionInterested objects mouseMoved() call
std::list<MotionInterested*> miCopy = motioninterested; std::list<MotionInterested*> miCopy = motioninterested;
for(std::list<MotionInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++) for(std::list<MotionInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
{ {
@ -1771,39 +1774,41 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
(*i)->mouseMoved(sEvent->motion); (*i)->mouseMoved(sEvent->motion);
} }
} }
//adventure map scrolling with mouse
if(!SDL_GetKeyState(NULL)[SDLK_LCTRL]) if(!SDL_GetKeyState(NULL)[SDLK_LCTRL])
{ {
if(sEvent->motion.x<15) if(sEvent->motion.x<15)
{ {
LOCPLINT->adventureInt->scrollingLeft = true; adventureInt->scrollingDir |= CAdvMapInt::LEFT;
} }
else else
{ {
LOCPLINT->adventureInt->scrollingLeft = false; adventureInt->scrollingDir &= ~CAdvMapInt::LEFT;
} }
if(sEvent->motion.x>screen->w-15) if(sEvent->motion.x>screen->w-15)
{ {
LOCPLINT->adventureInt->scrollingRight = true; adventureInt->scrollingDir |= CAdvMapInt::RIGHT;
} }
else else
{ {
LOCPLINT->adventureInt->scrollingRight = false; adventureInt->scrollingDir &= ~CAdvMapInt::RIGHT;
} }
if(sEvent->motion.y<15) if(sEvent->motion.y<15)
{ {
LOCPLINT->adventureInt->scrollingUp = true; adventureInt->scrollingDir |= CAdvMapInt::UP;
} }
else else
{ {
LOCPLINT->adventureInt->scrollingUp = false; adventureInt->scrollingDir &= ~CAdvMapInt::UP;
} }
if(sEvent->motion.y>screen->h-15) if(sEvent->motion.y>screen->h-15)
{ {
LOCPLINT->adventureInt->scrollingDown = true; adventureInt->scrollingDir |= CAdvMapInt::DOWN;
} }
else 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) void CPlayerInterface::receivedResource(int type, int val)
{ {
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
if(curint==adventureInt || curint==castleInt) if(curint==adventureInt || screen->h > 600 || screen->w > 800)
adventureInt->resdatabar.draw(); adventureInt->resdatabar.draw();
if(curint==castleInt && !curint->subInt)
castleInt->resdatabar->draw();
} }
void CPlayerInterface::showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID) void CPlayerInterface::showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID)
//void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID) //void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
{ {
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(true);
adventureInt->hide(); //dezaktywacja starego interfejsu adventureInt->hide(); //dezaktywacja starego interfejsu
std::vector<CSelectableComponent*> intComps; std::vector<CSelectableComponent*> intComps;
for(int i=0;i<components.size();i++) for(int i=0;i<components.size();i++)
@ -1939,6 +1947,7 @@ void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, int pskill, std:
showingDialog->cond.wait(un); showingDialog->cond.wait(un);
} }
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(true);
CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback); CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback);
curint->deactivate(); curint->deactivate();
lw->activate(); lw->activate();
@ -2257,8 +2266,8 @@ void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<Compo
} }
void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<SComponent*> & components) void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<SComponent*> & components)
{ {
showingDialog->set(true);
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
showingDialog->set(true);
curint->deactivate(); //dezaktywacja starego interfejsu curint->deactivate(); //dezaktywacja starego interfejsu
std::vector<std::pair<std::string,CFunctionList<void()> > > pom; std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
@ -2272,6 +2281,7 @@ void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<SComp
void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps) void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps)
{ {
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(true);
if(deactivateCur) if(deactivateCur)
curint->deactivate(); //dezaktywacja starego interfejsu curint->deactivate(); //dezaktywacja starego interfejsu
std::vector<std::pair<std::string,CFunctionList<void()> > > pom; std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
@ -2295,6 +2305,7 @@ void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SCom
void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector<Component*> &components, ui32 askID ) void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector<Component*> &components, ui32 askID )
{ {
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(false);
curint->deactivate(); //dezaktywacja starego interfejsu curint->deactivate(); //dezaktywacja starego interfejsu
std::vector<SComponent*> intComps; std::vector<SComponent*> intComps;

View File

@ -39,6 +39,89 @@ namespace boost
class recursive_mutex; 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 && qx<x+w && qy>y && qy<y+h)
return true;
return false;
}
bool isIn(const Point &q)
{
return isIn(q.x,q.y);
}
Point topLeft()
{
return Point(x,y);
}
Point bottomRight()
{
return Point(x+w,y+h);
}
Rect operator+(const Rect &p)
{
return Rect(x+p.x,y+p.y,w,h);
}
Rect operator+(const Point &p)
{
return Rect(x+p.x,y+p.y,w,h);
}
Rect& operator+=(const Rect &p)
{
x += p.x;
y += p.y;
return *this;
}
};
class IShowable class IShowable
{ {
public: public:
@ -76,8 +159,14 @@ public:
class CIntObject //interface object class CIntObject //interface object
{ {
public: public:
SDL_Rect pos; Rect pos;
int ID; int ID;
//virtual bool isIn(int x, int y)
//{
// return pos.isIn(x,y);
//}
virtual ~CIntObject(){};
}; };
class CSimpleWindow : public virtual CIntObject, public IShowable class CSimpleWindow : public virtual CIntObject, public IShowable
{ {

View File

@ -515,7 +515,9 @@ void Options::OptionSwitch::press(bool down)
} }
case 0: //hero change case 0: //hero change
{ {
if (ourOpt->castle<0) if (ourOpt->castle<0
|| !ourOpt->human
)
{ {
break; break;
} }
@ -579,6 +581,11 @@ void Options::PlayerFlag::press(bool down)
break; break;
CPG->ret.playerInfos[i].human = true; CPG->ret.playerInfos[i].human = true;
CPG->ret.playerInfos[j].human = false; 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; std::string pom = CPG->ret.playerInfos[i].name;
CPG->ret.playerInfos[i].name = CPG->ret.playerInfos[j].name; CPG->ret.playerInfos[i].name = CPG->ret.playerInfos[j].name;
CPG->ret.playerInfos[j].name = pom; CPG->ret.playerInfos[j].name = pom;
@ -2007,7 +2014,7 @@ StartInfo CPreGame::runLoop()
{ {
try try
{ {
if(SDL_PollEvent(&sEvent)) //wait for event... while(SDL_PollEvent(&sEvent)) //handle all events
{ {
menuItems * current = currentItems(); menuItems * current = currentItems();
if(sEvent.type==SDL_QUIT) if(sEvent.type==SDL_QUIT)
@ -2267,9 +2274,8 @@ StartInfo CPreGame::runLoop()
hideBox(); hideBox();
} }
} }
} } HANDLE_EXCEPTION
catch(...)
{ continue; }
CGI->curh->draw1(); CGI->curh->draw1();
SDL_Flip(screen); SDL_Flip(screen);
CGI->curh->draw2(); CGI->curh->draw2();

View File

@ -3,7 +3,6 @@
#include "SDL.h" #include "SDL.h"
#include "SDL_ttf.h" #include "SDL_ttf.h"
extern SDL_Surface * screen; extern SDL_Surface * screen;
extern SDL_Color tytulowy, tlo, zwykly ; extern SDL_Color tytulowy, tlo, zwykly ;
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;

View File

@ -626,6 +626,12 @@ void CClient::close()
void CClient::save(const std::string & fname) void CClient::save(const std::string & fname)
{ {
if(gs->curB)
{
tlog1 << "Game cannot be saved during battle!\n";
return;
}
*serv << ui16(98) << fname; *serv << ui16(98) << fname;
} }