1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

* better fix for #184 (should fix all related issues)

* fixed #214, #121, #100
This commit is contained in:
Michał W. Urbańczyk
2009-11-13 21:01:33 +00:00
parent a6f61e33bd
commit 4151310be6
3 changed files with 69 additions and 28 deletions

View File

@@ -434,7 +434,7 @@ void CMinimap::show( SDL_Surface * to )
} }
CTerrainRect::CTerrainRect() CTerrainRect::CTerrainRect()
:currentPath(NULL) :currentPath(NULL), curHoveredTile(-1,-1,-1)
{ {
tilesw=(ADVOPT.advmapW+31)/32; tilesw=(ADVOPT.advmapW+31)/32;
tilesh=(ADVOPT.advmapH+31)/32; tilesh=(ADVOPT.advmapH+31)/32;
@@ -466,6 +466,7 @@ void CTerrainRect::deactivate()
deactivateRClick(); deactivateRClick();
deactivateHover(); deactivateHover();
deactivateMouseMove(); deactivateMouseMove();
curHoveredTile = int3(-1,-1,-1); //we lost info about hovered tile when disabling
}; };
void CTerrainRect::clickLeft(tribool down, bool previousState) void CTerrainRect::clickLeft(tribool down, bool previousState)
{ {
@@ -564,10 +565,12 @@ void CTerrainRect::clickRight(tribool down, bool previousState)
return; return;
std::vector < const CGObjectInstance * > objs = LOCPLINT->cb->getBlockingObjs(mp); std::vector < const CGObjectInstance * > objs = LOCPLINT->cb->getBlockingObjs(mp);
if(!objs.size()) { if(!objs.size())
{
// Bare or undiscovered terrain // Bare or undiscovered terrain
const TerrainTile * tile = LOCPLINT->cb->getTileInfo(mp); const TerrainTile * tile = LOCPLINT->cb->getTileInfo(mp);
if (tile) { if (tile)
{
CSimpleWindow * temp = CMessage::genWindow(VLC->generaltexth->terrainNames[tile->tertype],LOCPLINT->playerID,true); CSimpleWindow * temp = CMessage::genWindow(VLC->generaltexth->terrainNames[tile->tertype],LOCPLINT->playerID,true);
CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true); CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true);
GH.pushInt(rcpi); GH.pushInt(rcpi);
@@ -1410,7 +1413,9 @@ void CInfoBar::newDay(int Day)
} }
} }
pom = 0; pom = 0;
activateTimer(); if(!(active & TIME))
activateTimer();
toNextTick = 500; toNextTick = 500;
blitAnim(mode); blitAnim(mode);
} }
@@ -1459,6 +1464,18 @@ void CInfoBar::show( SDL_Surface * to )
} }
void CInfoBar::activate()
{
//CIntObject::activate();
}
void CInfoBar::deactivate()
{
//CIntObject::deactivate();
if(active & TIME)
deactivateTimer();
}
CAdvMapInt::CAdvMapInt(int Player) CAdvMapInt::CAdvMapInt(int Player)
:player(Player), :player(Player),
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG), statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
@@ -1643,8 +1660,10 @@ void CAdvMapInt::activate()
heroList.activate(); heroList.activate();
townList.activate(); townList.activate();
terrain.activate(); terrain.activate();
infoBar.activate();
LOCPLINT->cingconsole->activate(); LOCPLINT->cingconsole->activate();
GH.fakeMouseMove(); //to restore the cursor
} }
void CAdvMapInt::deactivate() void CAdvMapInt::deactivate()
{ {
@@ -1666,8 +1685,7 @@ void CAdvMapInt::deactivate()
heroList.deactivate(); heroList.deactivate();
townList.deactivate(); townList.deactivate();
terrain.deactivate(); terrain.deactivate();
if(std::find(GH.timeinterested.begin(),GH.timeinterested.end(),&infoBar)!=GH.timeinterested.end()) infoBar.deactivate();
infoBar.deactivate();
infoBar.mode=-1; infoBar.mode=-1;
LOCPLINT->cingconsole->deactivate(); LOCPLINT->cingconsole->deactivate();

View File

@@ -127,6 +127,8 @@ public:
void blitAnim(int mode);//0 - day, 1 - week void blitAnim(int mode);//0 - day, 1 - week
CDefHandler * getAnim(int mode); CDefHandler * getAnim(int mode);
void show(SDL_Surface * to); void show(SDL_Surface * to);
void activate();
void deactivate();
}; };
/*****************************/ /*****************************/
class CAdvMapInt : public CIntObject //adventure map interface class CAdvMapInt : public CIntObject //adventure map interface

View File

@@ -1522,6 +1522,10 @@ void CBattleInterface::show(SDL_Surface * to)
if(preSize > 0 && pendingAnims.size() == 0) if(preSize > 0 && pendingAnims.size() == 0)
{ {
//action finished, restore the interface
if(!active)
activate();
//restoring good directions of stacks //restoring good directions of stacks
for(std::map<int, CStack>::const_iterator it = stacks.begin(); it != stacks.end(); ++it) for(std::map<int, CStack>::const_iterator it = stacks.begin(); it != stacks.end(); ++it)
{ {
@@ -1704,7 +1708,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
CGI->curh->changeGraphic(1,3); CGI->curh->changeGraphic(1,3);
//setting console text //setting console text
char buf[500]; char buf[500];
//calculating esimated dmg //calculating estimated dmg
std::pair<ui32, ui32> estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID); std::pair<ui32, ui32> estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID);
std::ostringstream estDmg; std::ostringstream estDmg;
estDmg << estimatedDmg.first << " - " << estimatedDmg.second; estDmg << estimatedDmg.first << " - " << estimatedDmg.second;
@@ -1738,16 +1742,21 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
// Exclude directions which cannot be attacked from. // Exclude directions which cannot be attacked from.
// Check to the left. // Check to the left.
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber - 1)) { if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber - 1))
{
sectorCursor[0] = -1; sectorCursor[0] = -1;
} }
// Check top left, top right as well as above for 2-hex creatures. // Check top left, top right as well as above for 2-hex creatures.
if (myNumber/BFIELD_WIDTH == 0) { if (myNumber/BFIELD_WIDTH == 0)
{
sectorCursor[1] = -1; sectorCursor[1] = -1;
sectorCursor[2] = -1; sectorCursor[2] = -1;
aboveAttackable = false; aboveAttackable = false;
} else { }
if (doubleWide) { else
{
if (doubleWide)
{
bool attackRow[4] = {true, true, true, true}; bool attackRow[4] = {true, true, true, true};
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 2 + zigzagCorrection)) if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 2 + zigzagCorrection))
@@ -1765,7 +1774,9 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
aboveAttackable = false; aboveAttackable = false;
if (!(attackRow[2] && attackRow[3])) if (!(attackRow[2] && attackRow[3]))
sectorCursor[2] = -1; sectorCursor[2] = -1;
} else { }
else
{
if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection)) if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection))
sectorCursor[1] = -1; sectorCursor[1] = -1;
if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH + zigzagCorrection)) if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH + zigzagCorrection))
@@ -1773,16 +1784,21 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
} }
} }
// Check to the right. // Check to the right.
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(shadedHexes, myNumber + 1)) { if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(shadedHexes, myNumber + 1))
{
sectorCursor[3] = -1; sectorCursor[3] = -1;
} }
// Check bottom right, bottom left as well as below for 2-hex creatures. // Check bottom right, bottom left as well as below for 2-hex creatures.
if (myNumber/BFIELD_WIDTH == BFIELD_HEIGHT - 1) { if (myNumber/BFIELD_WIDTH == BFIELD_HEIGHT - 1)
{
sectorCursor[4] = -1; sectorCursor[4] = -1;
sectorCursor[5] = -1; sectorCursor[5] = -1;
belowAttackable = false; belowAttackable = false;
} else { }
if (doubleWide) { else
{
if (doubleWide)
{
bool attackRow[4] = {true, true, true, true}; bool attackRow[4] = {true, true, true, true};
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 2 + zigzagCorrection)) if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 2 + zigzagCorrection))
@@ -1800,7 +1816,9 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
belowAttackable = false; belowAttackable = false;
if (!(attackRow[2] && attackRow[3])) if (!(attackRow[2] && attackRow[3]))
sectorCursor[4] = -1; sectorCursor[4] = -1;
} else { }
else
{
if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH + zigzagCorrection)) if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH + zigzagCorrection))
sectorCursor[4] = -1; sectorCursor[4] = -1;
if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection)) if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection))
@@ -1810,7 +1828,8 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
// Determine index from sector. // Determine index from sector.
int cursorIndex; int cursorIndex;
if (doubleWide) { if (doubleWide)
{
sectorCursor.insert(sectorCursor.begin() + 5, belowAttackable ? 13 : -1); sectorCursor.insert(sectorCursor.begin() + 5, belowAttackable ? 13 : -1);
sectorCursor.insert(sectorCursor.begin() + 2, aboveAttackable ? 14 : -1); sectorCursor.insert(sectorCursor.begin() + 2, aboveAttackable ? 14 : -1);
@@ -1824,7 +1843,9 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
cursorIndex = 6; cursorIndex = 6;
else else
cursorIndex = (int) sector + 2; cursorIndex = (int) sector + 2;
} else { }
else
{
cursorIndex = sector; cursorIndex = sector;
} }
@@ -1837,7 +1858,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
//setting console info //setting console info
char buf[500]; char buf[500];
//calculating esimated dmg //calculating estimated dmg
std::pair<ui32, ui32> estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID); std::pair<ui32, ui32> estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID);
std::ostringstream estDmg; std::ostringstream estDmg;
estDmg << estimatedDmg.first << " - " << estimatedDmg.second; estDmg << estimatedDmg.first << " - " << estimatedDmg.second;
@@ -1985,9 +2006,6 @@ void CBattleInterface::clickRight(tribool down, bool previousState)
void CBattleInterface::bOptionsf() void CBattleInterface::bOptionsf()
{ {
if(activeStack < 0) //workaround to prevent crashing calls in the middle of movement (action)
return; //TODO: disable options button during action (other buttons should be disabled as well)
if(spellDestSelectMode) //we are casting a spell if(spellDestSelectMode) //we are casting a spell
return; return;
@@ -2726,6 +2744,9 @@ void CBattleInterface::activateStack()
bSpell->block(!defendingHeroInstance->getArt(17)); bSpell->block(!defendingHeroInstance->getArt(17));
} }
GH.fakeMouseMove(); GH.fakeMouseMove();
if(!pendingAnims.size() && !active)
activate();
} }
float CBattleInterface::getAnimSpeedMultiplier() const float CBattleInterface::getAnimSpeedMultiplier() const
@@ -3008,9 +3029,9 @@ void CBattleInterface::projectileShowHelper(SDL_Surface * to)
void CBattleInterface::endAction(const BattleAction* action) void CBattleInterface::endAction(const BattleAction* action)
{ {
//if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))) //activating interface when move is finished //if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))) //activating interface when move is finished
{ // {
activate(); // activate();
} // }
if(action->actionType == 1) if(action->actionType == 1)
{ {
if(action->side) if(action->side)
@@ -3076,8 +3097,8 @@ void CBattleInterface::startAction(const BattleAction* action)
} }
} }
if(active)
deactivate(); deactivate();
char txt[400]; char txt[400];