Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic interface option #9413

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

felix642
Copy link
Contributor

@felix642 felix642 commented Jan 5, 2025

Added dynamic interface (good / evil) based on the player's race.
Relates to: #1329 (Despite the title, this issue also references the ability to hide the hero's path which was not added in this PR so we can't close it yet).

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

src/fheroes2/system/settings.cpp Outdated Show resolved Hide resolved
@oleg-derevenetz oleg-derevenetz added improvement New feature, request or improvement ui UI/GUI related stuff labels Jan 5, 2025
@oleg-derevenetz oleg-derevenetz added this to the 1.1.6 milestone Jan 5, 2025
@ihhub ihhub requested review from ihhub and Districh-ru January 6, 2025 11:38
Copy link
Collaborator

@Districh-ru Districh-ru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @felix642, I missed Dynamic interface option after the original game. Thanks for making this PR!
I left several comments to make it a bit better. Could you please check them when you have time?

src/fheroes2/dialog/dialog_interface_settings.cpp Outdated Show resolved Hide resolved
src/fheroes2/dialog/dialog_interface_settings.cpp Outdated Show resolved Hide resolved
src/fheroes2/game/game_startgame.cpp Outdated Show resolved Hide resolved
src/fheroes2/system/settings.cpp Show resolved Hide resolved
@Districh-ru Districh-ru self-requested a review January 20, 2025 18:49
@Districh-ru Districh-ru self-requested a review January 25, 2025 16:24
@Districh-ru Districh-ru self-requested a review January 25, 2025 16:52
Copy link
Collaborator

@Districh-ru Districh-ru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

@ihhub ihhub requested a review from Branikolog January 26, 2025 13:12
Copy link
Owner

@ihhub ihhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @felix642 , I put several comments here. Would you mind to take a look?

@@ -735,6 +735,12 @@ fheroes2::GameMode Interface::AdventureMap::StartGame()

// Fully update fog directions if there will be only one human player.
Interface::GameArea::updateMapFogDirections();

if ( conf.getInterfaceType() == InterfaceType::DYNAMIC ) {
reset();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. At line 702 we call reset and then we are calling it here. The code looks more like a hack. Could you please explain why we cannot do the same at line 702?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because when the game is first drawn (L. 702 - 710), the current player has not been selected yet (L. 734).
This code was added to redraw the interface to make sure that it matches the current player, but you're right, there should be a way to only draw the interface once, I'll check if I can move some code around to make it happen.

GOOD = 0,
EVIL = 1,
DYNAMIC = 2,
COUNT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either all entries have no value or all of them. SonarQube will complain about this warning.

@@ -379,6 +389,7 @@ class Settings
int ai_speed;
int scroll_speed;
int battle_speed;
InterfaceType _interfaceType;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This member doesn't have default value.

@@ -191,6 +199,9 @@ class Settings
bool isHideInterfaceEnabled() const;
bool isEvilInterfaceEnabled() const;

void setInterfaceType( InterfaceType type );
InterfaceType getInterfaceType() const;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be inlined.

void Settings::setEvilInterface( const bool enable )
{
if ( enable ) {
_gameOptions.SetModes( GAME_EVIL_INTERFACE );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GAME_EVIL_INTERFACE must be renamed into UNUSED_GAME_EVIL_INTERFACE as we are no longer supporting it.

Comment on lines +926 to +931
// Keep the UI of the last player during the AI turn
for ( auto iter = Settings::Get().GetPlayers().rbegin(); iter < Settings::Get().GetPlayers().rend(); ++iter ) {
if ( *iter && ( *iter )->isControlHuman() ) {
return Race::isEvilRace( ( *iter )->GetRace() );
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check this? UI Interface changes only during player's turn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some parts of the UI is updated during the AI's turn.
Mainly the top part with the shield:
image

If I remove this code, the background of the shield will change color very rapidly based on the AI factions

Comment on lines +449 to +455
os << "interface type = Good" << std::endl;
break;
case EVIL:
os << "interface type = Evil" << std::endl;
break;
case DYNAMIC:
os << "interface type = Dynamic" << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of settings have values starting from a capital letter. Please keep it the same way,.

Comment on lines -238 to -239
if ( config.Exists( "use evil interface" ) ) {
setEvilInterface( config.StrParams( "use evil interface" ) == "on" );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are breaking the existing settings players set. We should read the value of the previous setting.

Comment on lines +796 to +800
if ( conf.getInterfaceType() == InterfaceType::DYNAMIC ) {
reset();
redraw( Interface::REDRAW_RADAR );
redraw( Interface::REDRAW_ALL & ( ~Interface::REDRAW_RADAR ) );
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to rebuild everything even if the interface type is going to be the same?

@@ -287,7 +297,7 @@ namespace fheroes2
windowType = showConfigurationWindow( saveConfiguration );
break;
case SelectedWindow::InterfaceType:
conf.setEvilInterface( !conf.isEvilInterfaceEnabled() );
conf.setInterfaceType( static_cast<InterfaceType>( ( conf.getInterfaceType() + 1 ) % InterfaceType::COUNT ) );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where InterfaceType::COUNT is really needed. We can simply do this for the code to avoid having an extra enumeration entry:

if ( conf.getInterfaceType() == InterfaceType::DYNAMIC ) {
    conf.setInterfaceType( InterfaceType::GOOD );
}
else if ( conf.getInterfaceType() == InterfaceType::GOOD ) {
    conf.setInterfaceType( InterfaceType::BAD );
}
else {
    conf.setInterfaceType( InterfaceType::DYNAMIC );
}

Then we won't need checks in the code for non-existing types.

@ihhub ihhub marked this pull request as draft January 30, 2025 05:35
@ihhub
Copy link
Owner

ihhub commented Jan 30, 2025

Hi @felix642 , I converted this pull request into a draft. Once you update it please mark it as ready for review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement New feature, request or improvement ui UI/GUI related stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants