From 92395acfc927e5d775a69d83e9a632fb2c25506d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?= <60141446+felix642@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:41:17 -0500 Subject: [PATCH] Improved morale ui when all troops are undead (#9398) --- src/fheroes2/army/army.cpp | 7 +------ src/fheroes2/dialog/dialog_quickinfo.cpp | 18 ++++++++++++++++-- src/fheroes2/heroes/heroes_indicator.cpp | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/fheroes2/army/army.cpp b/src/fheroes2/army/army.cpp index 479016311d1..ceb28826861 100644 --- a/src/fheroes2/army/army.cpp +++ b/src/fheroes2/army/army.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2024 * + * Copyright (C) 2019 - 2025 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -1205,18 +1205,13 @@ int Army::GetMoraleModificator( std::string * strs ) const // different race penalty std::set races; bool hasUndead = false; - bool allUndead = true; for ( const Troop * troop : *this ) if ( troop->isValid() ) { races.insert( troop->GetRace() ); hasUndead = hasUndead || troop->isUndead(); - allUndead = allUndead && troop->isUndead(); } - if ( allUndead ) - return Morale::NORMAL; - int result = Morale::NORMAL; // check castle modificator diff --git a/src/fheroes2/dialog/dialog_quickinfo.cpp b/src/fheroes2/dialog/dialog_quickinfo.cpp index 7a168b7c08e..da03e174d59 100644 --- a/src/fheroes2/dialog/dialog_quickinfo.cpp +++ b/src/fheroes2/dialog/dialog_quickinfo.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2024 * + * Copyright (C) 2019 - 2025 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -55,6 +55,7 @@ #include "maps_tiles_helper.h" #include "math_base.h" #include "mp2.h" +#include "pal.h" #include "profit.h" #include "resource.h" #include "screen.h" @@ -760,7 +761,20 @@ namespace // morale if ( isFullInfo ) { const int32_t morale = hero.GetMorale(); - const fheroes2::Sprite & sprite = fheroes2::AGG::GetICN( ICN::MINILKMR, ( 0 > morale ? 3 : ( 0 < morale ? 4 : 5 ) ) ); + + uint32_t spriteInx = 5; + if ( morale < 0 ) { + spriteInx = 3; + } + else if ( morale > 0 ) { + spriteInx = 4; + } + + fheroes2::Sprite sprite = fheroes2::AGG::GetICN( ICN::MINILKMR, spriteInx ); + if ( hero.GetArmy().AllTroopsAreUndead() ) { + fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::GRAY ) ); + fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::DARKENING ) ); + } uint32_t count = ( 0 == morale ? 1 : std::abs( morale ) ); dst_pt.x = cur_rt.x + 10; dst_pt.y = cur_rt.y + ( count == 1 ? 20 : 13 ); diff --git a/src/fheroes2/heroes/heroes_indicator.cpp b/src/fheroes2/heroes/heroes_indicator.cpp index d86f0b94cff..50c084bf705 100644 --- a/src/fheroes2/heroes/heroes_indicator.cpp +++ b/src/fheroes2/heroes/heroes_indicator.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2024 * + * Copyright (C) 2019 - 2025 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -33,7 +33,9 @@ #include "dialog.h" #include "heroes.h" #include "icn.h" +#include "image.h" #include "localevent.h" +#include "pal.h" #include "screen.h" #include "tools.h" #include "translations.h" @@ -149,12 +151,22 @@ void MoraleIndicator::Redraw() _description.append( modificators ); } + uint32_t spriteInx = 7; + if ( _morale < Morale::NORMAL ) { + spriteInx = 5; + } + else if ( _morale > Morale::NORMAL ) { + spriteInx = 4; + } + + fheroes2::Sprite sprite = fheroes2::AGG::GetICN( ICN::HSICONS, spriteInx ); if ( _hero->GetArmy().AllTroopsAreUndead() ) { _description.append( "\n\n" ); _description.append( _( "Entire army is undead, so morale does not apply." ) ); + fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::GRAY ) ); + fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::DARKENING ) ); } - const fheroes2::Sprite & sprite = fheroes2::AGG::GetICN( ICN::HSICONS, ( 0 > _morale ? 5 : ( 0 < _morale ? 4 : 7 ) ) ); const int32_t inter = 6; int32_t count = ( 0 == _morale ? 1 : std::abs( _morale ) ); int32_t cx = _area.x + ( _area.width - ( sprite.width() + inter * ( count - 1 ) ) ) / 2;