-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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)
3356102
to
09756de
Compare
203d29e
to
751df95
Compare
There was a problem hiding this 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
// 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() ); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os << "interface type = Good" << std::endl; | ||
break; | ||
case EVIL: | ||
os << "interface type = Evil" << std::endl; | ||
break; | ||
case DYNAMIC: | ||
os << "interface type = Dynamic" << std::endl; |
There was a problem hiding this comment.
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,.
if ( config.Exists( "use evil interface" ) ) { | ||
setEvilInterface( config.StrParams( "use evil interface" ) == "on" ); |
There was a problem hiding this comment.
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.
if ( conf.getInterfaceType() == InterfaceType::DYNAMIC ) { | ||
reset(); | ||
redraw( Interface::REDRAW_RADAR ); | ||
redraw( Interface::REDRAW_ALL & ( ~Interface::REDRAW_RADAR ) ); | ||
} |
There was a problem hiding this comment.
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 ) ); |
There was a problem hiding this comment.
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.
Hi @felix642 , I converted this pull request into a draft. Once you update it please mark it as ready for review again. |
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).