From 589b1cfdde80874c045650e5e95c98a531188cbe Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 25 Dec 2024 22:34:31 +0800 Subject: [PATCH 1/4] Expand Text Support mode for New Map selection dialogs A tiny step forward. Relates to #5270 --- src/fheroes2/dialog/dialog_selectscenario.cpp | 24 +++++++++++++++++++ src/fheroes2/game/game_scenarioinfo.cpp | 18 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/fheroes2/dialog/dialog_selectscenario.cpp b/src/fheroes2/dialog/dialog_selectscenario.cpp index 1604eb32140..964010f67a5 100644 --- a/src/fheroes2/dialog/dialog_selectscenario.cpp +++ b/src/fheroes2/dialog/dialog_selectscenario.cpp @@ -38,6 +38,7 @@ #include "icn.h" #include "image.h" #include "localevent.h" +#include "logging.h" #include "screen.h" #include "settings.h" #include "system.h" @@ -88,6 +89,27 @@ namespace Maps::MapSize currentMapFilter = Maps::ZERO; + void outputMapSelectionInTextSupportMode() + { + START_TEXT_SUPPORT_MODE + COUT( "Choose Map\n" ) + + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::MAIN_MENU_MAP_SIZE_SMALL ) << " to view only maps of size small (36 x 36)." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::MAIN_MENU_MAP_SIZE_MEDIUM ) << " to view only maps of size medium (72 x 72)." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::MAIN_MENU_MAP_SIZE_LARGE ) << " to view only maps of size large (108 x 108)." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::MAIN_MENU_MAP_SIZE_EXTRA_LARGE ) << " to view only maps of size extra large (144 x 144)." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::MAIN_MENU_MAP_SIZE_EXTRA_LARGE ) << " to view all maps, regardless of size." ) + + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::DEFAULT_CANCEL ) << " to close the dialog and return to the previous menu." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::DEFAULT_OKAY ) << " to select the map." ) + } + + void outputNoMapInTextSupportMode() + { + START_TEXT_SUPPORT_MODE + COUT( "No maps exist for the chosen type. Returning to the previous menu." ) + } + void ShowToolTip( const std::string & header, const std::string & body ) { fheroes2::showStandardTextMessage( header, body, Dialog::ZERO ); @@ -426,6 +448,8 @@ const Maps::FileInfo * Dialog::SelectScenario( const MapsFileInfoList & allMaps, return nullptr; } + outputMapSelectionInTextSupportMode(); + fheroes2::Display & display = fheroes2::Display::instance(); LocalEvent & le = LocalEvent::Get(); diff --git a/src/fheroes2/game/game_scenarioinfo.cpp b/src/fheroes2/game/game_scenarioinfo.cpp index 10204174609..92e88ab897f 100644 --- a/src/fheroes2/game/game_scenarioinfo.cpp +++ b/src/fheroes2/game/game_scenarioinfo.cpp @@ -65,6 +65,16 @@ namespace { + void outputNewGameInTextSupportMode() + { + START_TEXT_SUPPORT_MODE + COUT( "Select Map for New Game\n" ) + + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::MAIN_MENU_SELECT_MAP ) << " to select a map." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::DEFAULT_CANCEL ) << " to close the dialog and return to the Main Menu." ) + COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::DEFAULT_OKAY ) << " to start the chosen map." ) + } + void updatePlayers( Players & players, const int humanPlayerCount ) { if ( humanPlayerCount < 2 ) @@ -298,6 +308,8 @@ namespace fheroes2::GameMode result = fheroes2::GameMode::QUIT_GAME; + outputNewGameInTextSupportMode(); + LocalEvent & le = LocalEvent::Get(); while ( true ) { @@ -319,6 +331,10 @@ namespace // click select if ( HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_SELECT_MAP ) || le.MouseClickLeft( buttonSelectMaps.area() ) ) { const Maps::FileInfo * fi = Dialog::SelectScenario( lists, false ); + + // The previous dialog might still have a pressed button event. We have to clean the state. + le.reset(); + const std::string currentMapName = conf.getCurrentMapInfo().filename; if ( fi && fi->filename != currentMapName ) { @@ -345,6 +361,8 @@ namespace coordDifficulty[Game::getDifficulty()].y - levelCursorOffset ); // From 0 to 4, see: Difficulty enum } display.render(); + + outputNewGameInTextSupportMode(); } else if ( Game::HotKeyPressEvent( Game::HotKeyEvent::DEFAULT_CANCEL ) || le.MouseClickLeft( buttonCancel.area() ) ) { result = fheroes2::GameMode::MAIN_MENU; From f186caa3a1de45b84021bdcc1e7fed344b2a92b7 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 25 Dec 2024 22:49:41 +0800 Subject: [PATCH 2/4] Add more information --- src/fheroes2/dialog/dialog_selectscenario.cpp | 1 + src/fheroes2/game/game_scenarioinfo.cpp | 9 +++++++++ src/fheroes2/maps/maps_fileinfo.cpp | 14 ++++++++++++++ src/fheroes2/maps/maps_fileinfo.h | 3 +++ 4 files changed, 27 insertions(+) diff --git a/src/fheroes2/dialog/dialog_selectscenario.cpp b/src/fheroes2/dialog/dialog_selectscenario.cpp index 964010f67a5..e22b8892c9a 100644 --- a/src/fheroes2/dialog/dialog_selectscenario.cpp +++ b/src/fheroes2/dialog/dialog_selectscenario.cpp @@ -445,6 +445,7 @@ void ScenarioListBox::ActionListDoubleClick( Maps::FileInfo & /* unused */ ) const Maps::FileInfo * Dialog::SelectScenario( const MapsFileInfoList & allMaps, const bool isForEditor ) { if ( allMaps.empty() ) { + outputNoMapInTextSupportMode(); return nullptr; } diff --git a/src/fheroes2/game/game_scenarioinfo.cpp b/src/fheroes2/game/game_scenarioinfo.cpp index 92e88ab897f..38ac2965f61 100644 --- a/src/fheroes2/game/game_scenarioinfo.cpp +++ b/src/fheroes2/game/game_scenarioinfo.cpp @@ -75,6 +75,13 @@ namespace COUT( "Press " << Game::getHotKeyNameByEventId( Game::HotKeyEvent::DEFAULT_OKAY ) << " to start the chosen map." ) } + void showCurrentlySelectedMapInfoInTextSupportMode( const Maps::FileInfo & mapInfo ) + { + START_TEXT_SUPPORT_MODE + COUT( "Currently selected map:\n" ) + COUT( mapInfo.getSummary() ) + } + void updatePlayers( Players & players, const int humanPlayerCount ) { if ( humanPlayerCount < 2 ) @@ -237,6 +244,7 @@ namespace Players & players = conf.GetPlayers(); + showCurrentlySelectedMapInfoInTextSupportMode( mapInfo ); conf.setCurrentMapInfo( mapInfo ); updatePlayers( players, humanPlayerCount ); Game::LoadPlayers( mapInfo.filename, players ); @@ -338,6 +346,7 @@ namespace const std::string currentMapName = conf.getCurrentMapInfo().filename; if ( fi && fi->filename != currentMapName ) { + showCurrentlySelectedMapInfoInTextSupportMode( *fi ); Game::SavePlayers( currentMapName, conf.GetPlayers() ); conf.setCurrentMapInfo( *fi ); diff --git a/src/fheroes2/maps/maps_fileinfo.cpp b/src/fheroes2/maps/maps_fileinfo.cpp index 9ed4b74c2e9..8012049f826 100644 --- a/src/fheroes2/maps/maps_fileinfo.cpp +++ b/src/fheroes2/maps/maps_fileinfo.cpp @@ -633,6 +633,20 @@ bool Maps::FileInfo::WinsCompAlsoWins() const return compAlsoWins && ( ( GameOver::WINS_TOWN | GameOver::WINS_GOLD ) & ConditionWins() ); } +std::string Maps::FileInfo::getSummary() const +{ + std::ostringstream os; + + os << "Map information:" << std::endl + << "Map name: " << name << std::endl + << "File name: " << filename << std::endl + << "Description: " << description << std::endl + << "Size: " << width << "x" << height << std::endl + << "Difficulty: " << Difficulty::String( difficulty ) << std::endl; + + return os.str(); +} + OStreamBase & Maps::operator<<( OStreamBase & stream, const FileInfo & fi ) { // Only the filename part of the path to the map file is saved diff --git a/src/fheroes2/maps/maps_fileinfo.h b/src/fheroes2/maps/maps_fileinfo.h index ab6694c3eb0..b0da8710917 100644 --- a/src/fheroes2/maps/maps_fileinfo.h +++ b/src/fheroes2/maps/maps_fileinfo.h @@ -156,6 +156,9 @@ namespace Maps return {}; } + // This method is mostly used for Text Support mode or debug purposes. + std::string getSummary() const; + enum VictoryCondition : uint8_t { VICTORY_DEFEAT_EVERYONE = 0, From 31eaf379a35b83e1617a4ab66b61cf12abc45ba2 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 25 Dec 2024 22:51:59 +0800 Subject: [PATCH 3/4] Remove extra line --- src/fheroes2/maps/maps_fileinfo.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fheroes2/maps/maps_fileinfo.cpp b/src/fheroes2/maps/maps_fileinfo.cpp index 8012049f826..c2677c4daf9 100644 --- a/src/fheroes2/maps/maps_fileinfo.cpp +++ b/src/fheroes2/maps/maps_fileinfo.cpp @@ -637,8 +637,7 @@ std::string Maps::FileInfo::getSummary() const { std::ostringstream os; - os << "Map information:" << std::endl - << "Map name: " << name << std::endl + os << "Map name: " << name << std::endl << "File name: " << filename << std::endl << "Description: " << description << std::endl << "Size: " << width << "x" << height << std::endl From 26fa16e8e0bc22620d3ea223ab86d7967299ee89 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 25 Dec 2024 23:02:09 +0800 Subject: [PATCH 4/4] Make IWYU happy --- src/fheroes2/dialog/dialog_selectscenario.cpp | 1 + src/fheroes2/maps/maps_fileinfo.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fheroes2/dialog/dialog_selectscenario.cpp b/src/fheroes2/dialog/dialog_selectscenario.cpp index e22b8892c9a..78387eaa219 100644 --- a/src/fheroes2/dialog/dialog_selectscenario.cpp +++ b/src/fheroes2/dialog/dialog_selectscenario.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/src/fheroes2/maps/maps_fileinfo.cpp b/src/fheroes2/maps/maps_fileinfo.cpp index c2677c4daf9..313790f5fe0 100644 --- a/src/fheroes2/maps/maps_fileinfo.cpp +++ b/src/fheroes2/maps/maps_fileinfo.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include