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

Fix color change of highlighted hex borders (#343)

This commit is contained in:
Dydzio 2017-07-17 00:15:05 +02:00 committed by ArseniyShestakov
parent b52cfe5283
commit 81ccecedca
2 changed files with 36 additions and 25 deletions

View File

@ -3055,6 +3055,31 @@ void CBattleInterface::showAbsoluteObstacles(SDL_Surface *to)
void CBattleInterface::showHighlightedHexes(SDL_Surface *to) void CBattleInterface::showHighlightedHexes(SDL_Surface *to)
{ {
bool delayedBlit = false; //workaround for blitting enemy stack hex without mouse shadow with stack range on
if(activeStack && settings["battle"]["stackRange"].Bool())
{
std::set<BattleHex> set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex);
for(BattleHex hex : set)
if(hex != currentlyHoveredHex)
showHighlightedHex(to, hex);
// display the movement shadow of the stack at b (i.e. stack under mouse)
const CStack * const shere = curInt->cb->battleGetStackByPos(currentlyHoveredHex, false);
if(shere && shere != activeStack && shere->alive())
{
std::vector<BattleHex> v = curInt->cb->battleGetAvailableHexes(shere, true);
for(BattleHex hex : v)
{
if(hex != currentlyHoveredHex)
showHighlightedHex(to, hex);
else if(!settings["battle"]["mouseShadow"].Bool())
delayedBlit = true; //blit at the end of method to avoid graphic artifacts
else
showHighlightedHex(to, hex, true); //blit now and blit 2nd time later for darker shadow - avoids graphic artifacts
}
}
}
for(int b=0; b<GameConstants::BFIELD_SIZE; ++b) for(int b=0; b<GameConstants::BFIELD_SIZE; ++b)
{ {
if(bfield[b]->strictHovered && bfield[b]->hovered) if(bfield[b]->strictHovered && bfield[b]->hovered)
@ -3069,7 +3094,7 @@ void CBattleInterface::showHighlightedHexes(SDL_Surface *to)
previouslyHoveredHex = currentlyHoveredHex; previouslyHoveredHex = currentlyHoveredHex;
currentlyHoveredHex = b; currentlyHoveredHex = b;
} }
if(settings["battle"]["mouseShadow"].Bool()) if(settings["battle"]["mouseShadow"].Bool() || delayedBlit)
{ {
const ISpellCaster *caster = nullptr; const ISpellCaster *caster = nullptr;
const CSpell *spell = nullptr; const CSpell *spell = nullptr;
@ -3095,42 +3120,28 @@ void CBattleInterface::showHighlightedHexes(SDL_Surface *to)
for(BattleHex shadedHex : shaded) for(BattleHex shadedHex : shaded)
{ {
if((shadedHex.getX() != 0) && (shadedHex.getX() != GameConstants::BFIELD_WIDTH - 1)) if((shadedHex.getX() != 0) && (shadedHex.getX() != GameConstants::BFIELD_WIDTH - 1))
showHighlightedHex(to, shadedHex); showHighlightedHex(to, shadedHex, true);
} }
} }
else if(active)//always highlight pointed hex else if(active || delayedBlit) //always highlight pointed hex, keep this condition last in this method for correct behavior
{ {
if(currentlyHoveredHex.getX() != 0 if(currentlyHoveredHex.getX() != 0
&& currentlyHoveredHex.getX() != GameConstants::BFIELD_WIDTH - 1) && currentlyHoveredHex.getX() != GameConstants::BFIELD_WIDTH - 1)
showHighlightedHex(to, currentlyHoveredHex); showHighlightedHex(to, currentlyHoveredHex, true); //keep true for OH3 behavior: hovered hex frame "thinner"
} }
} }
} }
} }
if(activeStack && settings["battle"]["stackRange"].Bool())
{
std::set<BattleHex> set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex);
for(BattleHex hex : set)
showHighlightedHex(to, hex);
// display the movement shadow of the stack at b (i.e. stack under mouse)
const CStack * const shere = curInt->cb->battleGetStackByPos(currentlyHoveredHex, false);
if(shere && shere != activeStack && shere->alive())
{
std::vector<BattleHex> v = curInt->cb->battleGetAvailableHexes(shere, true );
for(BattleHex hex : v)
showHighlightedHex(to, hex);
}
}
} }
void CBattleInterface::showHighlightedHex(SDL_Surface *to, BattleHex hex) void CBattleInterface::showHighlightedHex(SDL_Surface *to, BattleHex hex, bool darkBorder)
{ {
int x = 14 + (hex.getY() % 2 == 0 ? 22 : 0) + 44 *(hex.getX()) + pos.x; int x = 14 + (hex.getY() % 2 == 0 ? 22 : 0) + 44 *(hex.getX()) + pos.x;
int y = 86 + 42 *hex.getY() + pos.y; int y = 86 + 42 *hex.getY() + pos.y;
SDL_Rect temp_rect = genRect (cellShade->h, cellShade->w, x, y); SDL_Rect temp_rect = genRect (cellShade->h, cellShade->w, x, y);
CSDL_Ext::blit8bppAlphaTo24bpp (cellShade, nullptr, to, &temp_rect); CSDL_Ext::blit8bppAlphaTo24bpp (cellShade, nullptr, to, &temp_rect);
if(!darkBorder && settings["battle"]["cellBorders"].Bool())
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorder, nullptr, to, &temp_rect); //redraw border to make it light green instead of shaded
} }
void CBattleInterface::showProjectiles(SDL_Surface *to) void CBattleInterface::showProjectiles(SDL_Surface *to)
@ -3629,9 +3640,6 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack *activeStack)
oi->getInfo().height, backgroundWithHexes); oi->getInfo().height, backgroundWithHexes);
} }
if (settings["battle"]["cellBorders"].Bool())
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, nullptr, backgroundWithHexes, nullptr);
if (settings["battle"]["stackRange"].Bool()) if (settings["battle"]["stackRange"].Bool())
{ {
std::vector<BattleHex> hexesToShade = occupyableHexes; std::vector<BattleHex> hexesToShade = occupyableHexes;
@ -3646,6 +3654,9 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack *activeStack)
CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, nullptr, backgroundWithHexes, &temp_rect); CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, nullptr, backgroundWithHexes, &temp_rect);
} }
} }
if(settings["battle"]["cellBorders"].Bool())
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, nullptr, backgroundWithHexes, nullptr);
} }
void CBattleInterface::showPiecesOfWall(SDL_Surface *to, std::vector<int> pieces) void CBattleInterface::showPiecesOfWall(SDL_Surface *to, std::vector<int> pieces)

View File

@ -240,7 +240,7 @@ private:
void showBackgroundImage(SDL_Surface *to); void showBackgroundImage(SDL_Surface *to);
void showAbsoluteObstacles(SDL_Surface *to); void showAbsoluteObstacles(SDL_Surface *to);
void showHighlightedHexes(SDL_Surface *to); void showHighlightedHexes(SDL_Surface *to);
void showHighlightedHex(SDL_Surface *to, BattleHex hex); void showHighlightedHex(SDL_Surface *to, BattleHex hex, bool darkBorder = false);
void showInterface(SDL_Surface *to); void showInterface(SDL_Surface *to);
void showBattlefieldObjects(SDL_Surface *to); void showBattlefieldObjects(SDL_Surface *to);