-
-
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?
Changes from all commits
332a0f4
7775059
09756de
751df95
3e1b60c
98d0701
1766211
d779ded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> * | ||
|
@@ -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 commentThe 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 commentThe 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). |
||
redraw( Interface::REDRAW_RADAR ); | ||
redraw( Interface::REDRAW_ALL & ( ~Interface::REDRAW_RADAR ) ); | ||
} | ||
} | ||
|
||
while ( res == fheroes2::GameMode::END_TURN ) { | ||
|
@@ -784,7 +790,15 @@ fheroes2::GameMode Interface::AdventureMap::StartGame() | |
// Reset environment sounds and music theme at the beginning of the human turn | ||
AudioManager::ResetAudio(); | ||
|
||
conf.SetCurrentColor( playerColor ); | ||
|
||
if ( isHotSeatGame ) { | ||
if ( conf.getInterfaceType() == InterfaceType::DYNAMIC ) { | ||
reset(); | ||
redraw( Interface::REDRAW_RADAR ); | ||
redraw( Interface::REDRAW_ALL & ( ~Interface::REDRAW_RADAR ) ); | ||
} | ||
Comment on lines
+796
to
+800
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
_iconsPanel.hideIcons( ICON_ANY ); | ||
_statusPanel.Reset(); | ||
|
||
|
@@ -804,8 +818,6 @@ fheroes2::GameMode Interface::AdventureMap::StartGame() | |
Game::DialogPlayers( playerColor, "", _( "%{color} player's turn." ) ); | ||
} | ||
|
||
conf.SetCurrentColor( playerColor ); | ||
|
||
kingdom.ActionBeforeTurn(); | ||
|
||
_iconsPanel.showIcons( ICON_ANY ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> * | ||
|
@@ -126,6 +126,27 @@ bool Race::isMagicalRace( const int race ) | |
return false; | ||
} | ||
|
||
bool Race::isEvilRace( const int race ) | ||
{ | ||
switch ( race ) { | ||
case BARB: | ||
case WRLK: | ||
case NECR: | ||
return true; | ||
case KNGT: | ||
case SORC: | ||
case WZRD: | ||
case MULT: | ||
case RAND: | ||
return false; | ||
default: | ||
assert( 0 ); | ||
break; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
uint8_t Race::IndexToRace( const int index ) | ||
{ | ||
switch ( index ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> * | ||
|
@@ -22,6 +22,7 @@ | |
***************************************************************************/ | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <sstream> | ||
|
@@ -36,6 +37,7 @@ | |
#include "game.h" | ||
#include "game_io.h" | ||
#include "logging.h" | ||
#include "race.h" | ||
#include "render_processor.h" | ||
#include "save_format_version.h" | ||
#include "screen.h" | ||
|
@@ -235,8 +237,17 @@ bool Settings::Read( const std::string & filePath ) | |
setBattleShowTurnOrder( config.StrParams( "battle turn order" ) == "on" ); | ||
} | ||
|
||
if ( config.Exists( "use evil interface" ) ) { | ||
setEvilInterface( config.StrParams( "use evil interface" ) == "on" ); | ||
Comment on lines
-238
to
-239
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( config.Exists( "interface type" ) ) { | ||
const std::string interfaceType = config.StrParams( "interface type" ); | ||
if ( interfaceType == "Good" ) { | ||
setInterfaceType( InterfaceType::GOOD ); | ||
} | ||
else if ( interfaceType == "Evil" ) { | ||
setInterfaceType( InterfaceType::EVIL ); | ||
} | ||
else { | ||
setInterfaceType( InterfaceType::DYNAMIC ); | ||
} | ||
Districh-ru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if ( config.Exists( "hide interface" ) ) { | ||
|
@@ -432,8 +443,20 @@ std::string Settings::String() const | |
os << std::endl << "# show turn order during battle: on/off" << std::endl; | ||
os << "battle turn order = " << ( _gameOptions.Modes( GAME_BATTLE_SHOW_TURN_ORDER ) ? "on" : "off" ) << std::endl; | ||
|
||
os << std::endl << "# use evil interface style: on/off" << std::endl; | ||
os << "use evil interface = " << ( _gameOptions.Modes( GAME_EVIL_INTERFACE ) ? "on" : "off" ) << std::endl; | ||
os << std::endl << "# interface type (Good/Evil/Dynamic)" << std::endl; | ||
switch ( _interfaceType ) { | ||
case GOOD: | ||
os << "interface type = Good" << std::endl; | ||
break; | ||
case EVIL: | ||
os << "interface type = Evil" << std::endl; | ||
break; | ||
case DYNAMIC: | ||
os << "interface type = Dynamic" << std::endl; | ||
Comment on lines
+449
to
+455
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,. |
||
break; | ||
default: | ||
assert( 0 ); | ||
} | ||
|
||
os << std::endl << "# hide interface elements on the adventure map: on/off" << std::endl; | ||
os << "hide interface = " << ( _gameOptions.Modes( GAME_HIDE_INTERFACE ) ? "on" : "off" ) << std::endl; | ||
|
@@ -816,16 +839,6 @@ void Settings::setHideInterface( const bool enable ) | |
} | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
else { | ||
_gameOptions.ResetModes( GAME_EVIL_INTERFACE ); | ||
} | ||
} | ||
|
||
void Settings::setScreenScalingTypeNearest( const bool enable ) | ||
{ | ||
if ( enable ) { | ||
|
@@ -883,9 +896,46 @@ bool Settings::isHideInterfaceEnabled() const | |
return _gameOptions.Modes( GAME_HIDE_INTERFACE ); | ||
} | ||
|
||
void Settings::setInterfaceType( InterfaceType type ) | ||
{ | ||
assert( type >= InterfaceType::GOOD && type <= InterfaceType::DYNAMIC ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of avoid this assertion we simply can remove |
||
_interfaceType = type; | ||
} | ||
|
||
InterfaceType Settings::getInterfaceType() const | ||
{ | ||
return _interfaceType; | ||
} | ||
|
||
bool Settings::isEvilInterfaceEnabled() const | ||
{ | ||
return _gameOptions.Modes( GAME_EVIL_INTERFACE ); | ||
switch ( _interfaceType ) { | ||
case InterfaceType::GOOD: | ||
return false; | ||
case InterfaceType::EVIL: | ||
return true; | ||
case InterfaceType::DYNAMIC: { | ||
Player * player = Settings::Get().GetPlayers().GetCurrent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is not static. We should use its own methods within the body. |
||
if ( !player ) | ||
return false; | ||
Comment on lines
+919
to
+920
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it even possible? Also, please parenthesis for this if-body. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be related to my last comment where the current player might not be set at the start of the game. I'll remove this check if I update the code once I find a way to only draw the interface once at the beginning of the game. |
||
|
||
if ( player->isControlHuman() ) { | ||
return Race::isEvilRace( player->GetRace() ); | ||
} | ||
|
||
// 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() ); | ||
} | ||
} | ||
Comment on lines
+926
to
+931
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
break; | ||
} | ||
default: | ||
assert( 0 ); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool Settings::isEditorAnimationEnabled() 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 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:Then we won't need checks in the code for non-existing types.