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;
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)
{

View File

@ -110,10 +110,8 @@ public:
std::vector<CDefHandler *> 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

View File

@ -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;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,206,421);
draw(owner,true);
resdatabar.pos.x += pos.x;
resdatabar.pos.y += pos.y;
resdatabar.pos += pos;
}
void CFortScreen::draw( CCastleInterface * owner, bool first)
@ -1449,7 +1449,7 @@ void CFortScreen::draw( CCastleInterface * owner, bool first)
if(present)
{
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;
AdventureMapButton *exit;
SDL_Surface * bg;
std::vector<SDL_Rect> positions;
std::vector<Rect> positions;
std::vector<RecArea*> recAreas;
std::vector<CCreaturePic*> crePics;

View File

@ -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 "<<cur->ID<<" "<<cur->subID<<std::endl;
return;
}
map->addBlockVisTiles(cur);
}
int CGameState::getDate(int mode) const

View File

@ -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";
}

View File

@ -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<Hoverable*> hlp;
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++)
hlp[i]->hover(true);
//sending active, MotionInterested objects mouseMoved() call
std::list<MotionInterested*> miCopy = motioninterested;
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);
}
}
//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<boost::recursive_mutex> 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<Component*> &components, ui32 askID)
//void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(true);
adventureInt->hide(); //dezaktywacja starego interfejsu
std::vector<CSelectableComponent*> intComps;
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);
}
boost::unique_lock<boost::recursive_mutex> 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<Compo
}
void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<SComponent*> & components)
{
showingDialog->set(true);
boost::unique_lock<boost::recursive_mutex> un(*pim);
showingDialog->set(true);
curint->deactivate(); //dezaktywacja starego interfejsu
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)
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(true);
if(deactivateCur)
curint->deactivate(); //dezaktywacja starego interfejsu
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 )
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT->showingDialog->setn(false);
curint->deactivate(); //dezaktywacja starego interfejsu
std::vector<SComponent*> intComps;

View File

@ -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 && 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
{
public:
@ -76,8 +159,14 @@ public:
class CIntObject //interface object
{
public:
SDL_Rect pos;
Rect pos;
int ID;
//virtual bool isIn(int x, int y)
//{
// return pos.isIn(x,y);
//}
virtual ~CIntObject(){};
};
class CSimpleWindow : public virtual CIntObject, public IShowable
{

View File

@ -515,7 +515,9 @@ void Options::OptionSwitch::press(bool down)
}
case 0: //hero change
{
if (ourOpt->castle<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();

View File

@ -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;

View File

@ -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;
}