-
-
Notifications
You must be signed in to change notification settings - Fork 388
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 2 commits
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) 2023 - 2024 * | ||
* Copyright (C) 2023 - 2025 * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
|
@@ -63,18 +63,28 @@ namespace | |
void drawInterfaceType( const fheroes2::Rect & optionRoi ) | ||
{ | ||
const Settings & conf = Settings::Get(); | ||
const bool isEvilInterface = conf.isEvilInterfaceEnabled(); | ||
const fheroes2::Sprite & interfaceThemeIcon = fheroes2::AGG::GetICN( ICN::SPANEL, isEvilInterface ? 17 : 16 ); | ||
const InterfaceType interfaceType = conf.getInterfaceType(); | ||
|
||
const fheroes2::Sprite * interfaceThemeIcon; | ||
std::string value; | ||
if ( isEvilInterface ) { | ||
value = _( "Evil" ); | ||
} | ||
else { | ||
switch ( interfaceType ) { | ||
case DYNAMIC: | ||
interfaceThemeIcon = &fheroes2::AGG::GetICN( ICN::SPANEL, 15 ); | ||
value = _( "Dynamic" ); | ||
break; | ||
case GOOD: | ||
interfaceThemeIcon = &fheroes2::AGG::GetICN( ICN::SPANEL, 16 ); | ||
value = _( "Good" ); | ||
break; | ||
case EVIL: | ||
interfaceThemeIcon = &fheroes2::AGG::GetICN( ICN::SPANEL, 17 ); | ||
value = _( "Evil" ); | ||
break; | ||
default: | ||
assert( 0 ); | ||
} | ||
|
||
fheroes2::drawOption( optionRoi, interfaceThemeIcon, _( "Interface Type" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); | ||
fheroes2::drawOption( optionRoi, *interfaceThemeIcon, _( "Interface Type" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); | ||
} | ||
|
||
void drawInterfacePresence( const fheroes2::Rect & optionRoi ) | ||
|
@@ -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::DYNAMIC + 1 ) ) ); | ||
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. To be more consistent with the other code we can add |
||
updateUI(); | ||
saveConfiguration = true; | ||
|
||
|
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]> * | ||
|
@@ -784,6 +784,13 @@ fheroes2::GameMode Interface::AdventureMap::StartGame() | |
// Reset environment sounds and music theme at the beginning of the human turn | ||
AudioManager::ResetAudio(); | ||
|
||
conf.SetCurrentColor( playerColor ); | ||
if ( conf.getInterfaceType() == InterfaceType::DYNAMIC ) { | ||
reset(); | ||
redraw( Interface::REDRAW_RADAR ); | ||
redraw( Interface::REDRAW_ALL & ( ~Interface::REDRAW_RADAR ) ); | ||
} | ||
Comment on lines
+788
to
+792
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. In single-player game the race of the player is never changed so should we do this ( |
||
|
||
if ( isHotSeatGame ) { | ||
_iconsPanel.hideIcons( ICON_ANY ); | ||
_statusPanel.Reset(); | ||
|
@@ -804,8 +811,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]> * | ||
|
@@ -36,6 +36,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 +236,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" ); | ||
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 +442,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; | ||
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 +838,6 @@ void Settings::setHideInterface( const bool enable ) | |
} | ||
} | ||
|
||
void Settings::setEvilInterface( const bool enable ) | ||
{ | ||
if ( enable ) { | ||
_gameOptions.SetModes( GAME_EVIL_INTERFACE ); | ||
} | ||
else { | ||
_gameOptions.ResetModes( GAME_EVIL_INTERFACE ); | ||
} | ||
} | ||
|
||
void Settings::setScreenScalingTypeNearest( const bool enable ) | ||
{ | ||
if ( enable ) { | ||
|
@@ -883,9 +895,46 @@ bool Settings::isHideInterfaceEnabled() const | |
return _gameOptions.Modes( GAME_HIDE_INTERFACE ); | ||
} | ||
|
||
void Settings::setInterfaceType( InterfaceType type ) | ||
{ | ||
assert( type >= InterfaceType::GOOD && type <= InterfaceType::DYNAMIC ); | ||
_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(); | ||
if ( !player ) | ||
return false; | ||
|
||
if ( player->isControlHuman() ) { | ||
const int race = player->GetRace(); | ||
return race == Race::WRLK || race == Race::NECR || race == Race::BARB; | ||
felix642 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// 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() ) { | ||
const int race = ( *iter )->GetRace(); | ||
return race == Race::WRLK || race == Race::NECR || race == Race::BARB; | ||
} | ||
} | ||
return false; | ||
} | ||
default: | ||
assert( 0 ); | ||
} | ||
} | ||
|
||
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.
We can make
uint32_t icnIndex;
and then set its value by theinterfaceType
and then use it inconst fheroes2::Sprite & interfaceThemeIcon = fheroes2::AGG::GetICN( ICN::SPANEL, icnIndex );
Doing this we will not duplicate the
GetICN()
call code and will not make a pointer to Sprite.What do you think?