Skip to content

Commit

Permalink
Fix Mana dialog text and default Exp value display
Browse files Browse the repository at this point in the history
  • Loading branch information
Districh-ru committed Apr 2, 2024
1 parent 5325e10 commit d03bafe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/fheroes2/heroes/heroes_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable
dst_pt.y = dialogRoi.y + ( isEditor ? 76 : 86 );
ExperienceIndicator experienceInfo( this );
experienceInfo.SetPos( dst_pt );
if ( isEditor ) {
experienceInfo.setDefaultState( useDefaultExperience );
}
experienceInfo.Redraw();

// Spell points indicator.
Expand All @@ -279,6 +282,9 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable
dst_pt.y += 2;
SpellPointsIndicator spellPointsInfo( this );
spellPointsInfo.SetPos( dst_pt );
if ( isEditor ) {
spellPointsInfo.setDefaultState( useDefaultSpellPoints );
}
spellPointsInfo.Redraw();

// Color "crest" icon.
Expand Down Expand Up @@ -500,6 +506,7 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable
if ( Dialog::SelectCount( _( "Set Experience value" ), 0, experienceMaxValue, value ) ) {
useDefaultExperience = false;
experience = value;
experienceInfo.setDefaultState( useDefaultExperience );
experienceInfo.Redraw();
drawTitleText( name, _race, true );
needRedraw = true;
Expand All @@ -508,6 +515,7 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable
else if ( le.MouseClickRight() ) {
useDefaultExperience = true;
experience = GetStartingXp();
experienceInfo.setDefaultState( useDefaultExperience );
experienceInfo.Redraw();
drawTitleText( name, _race, true );
needRedraw = true;
Expand All @@ -525,9 +533,10 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable

if ( le.MouseClickLeft() ) {
uint32_t value = GetSpellPoints();
if ( Dialog::SelectCount( message, 0, spellPointsMaxValue, value ) ) {
if ( Dialog::SelectCount( _( "Set Spell Points value" ), 0, spellPointsMaxValue, value ) ) {
useDefaultSpellPoints = false;
SetSpellPoints( value );
spellPointsInfo.setDefaultState( useDefaultSpellPoints );
spellPointsInfo.Redraw();
needRedraw = true;
}
Expand All @@ -536,6 +545,7 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable
// Reset spell points modification.
useDefaultSpellPoints = true;
SetSpellPoints( GetMaxSpellPoints() );
spellPointsInfo.setDefaultState( useDefaultSpellPoints );
spellPointsInfo.Redraw();
needRedraw = true;
}
Expand Down Expand Up @@ -589,6 +599,7 @@ int Heroes::OpenDialog( const bool readonly, const bool fade, const bool disable
if ( useDefaultSpellPoints ) {
SetSpellPoints( GetMaxSpellPoints() );
}

spellPointsInfo.Redraw();
needRedraw = true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/fheroes2/heroes/heroes_indicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void ExperienceIndicator::Redraw() const
const fheroes2::Sprite & sprite = fheroes2::AGG::GetICN( ICN::HSICONS, 1 );
fheroes2::Blit( sprite, display, _area.x, _area.y );

const fheroes2::Text text( std::to_string( _hero->GetExperience() ), fheroes2::FontType::smallWhite() );
const fheroes2::Text text( _isDefault ? "-" : std::to_string( _hero->GetExperience() ), fheroes2::FontType::smallWhite() );
text.draw( _area.x + 17 - text.width() / 2, _area.y + 25, display );
}

Expand Down Expand Up @@ -240,7 +240,9 @@ void SpellPointsIndicator::Redraw() const
const fheroes2::Sprite & sprite = fheroes2::AGG::GetICN( ICN::HSICONS, 8 );
fheroes2::Blit( sprite, display, _area.x, _area.y );

const fheroes2::Text text( std::to_string( _hero->GetSpellPoints() ) + "/" + std::to_string( _hero->GetMaxSpellPoints() ), fheroes2::FontType::smallWhite() );
const fheroes2::Text text( _isDefault ? std::to_string( _hero->GetMaxSpellPoints() )
: std::to_string( _hero->GetSpellPoints() ) + "/" + std::to_string( _hero->GetMaxSpellPoints() ),
fheroes2::FontType::smallWhite() );
text.draw( _area.x + sprite.width() / 2 - text.width() / 2, _area.y + 23, display );
}

Expand Down
22 changes: 21 additions & 1 deletion src/fheroes2/heroes/heroes_indicator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2023 *
* Copyright (C) 2019 - 2024 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
Expand Down Expand Up @@ -110,6 +110,16 @@ class ExperienceIndicator : public HeroesIndicator

void Redraw() const;
void QueueEventProcessing() const;

// Set if default value is used. Use this method only in Editor!
void setDefaultState( const bool isDefault )
{
_isDefault = isDefault;
}

private:
// This state is used in Editor to show that default value is used.
bool _isDefault{ false };
};

class SpellPointsIndicator : public HeroesIndicator
Expand All @@ -119,6 +129,16 @@ class SpellPointsIndicator : public HeroesIndicator

void Redraw() const;
void QueueEventProcessing() const;

// Set if default value is used. Use this method only in Editor!
void setDefaultState( const bool isDefault )
{
_isDefault = isDefault;
}

private:
// This state is used in Editor to show that default value is used.
bool _isDefault{ false };
};

#endif

0 comments on commit d03bafe

Please sign in to comment.