From f69408e982aa989c9f0da58eceb8f2a6d77c1c71 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Mon, 30 Dec 2024 22:21:31 +0800 Subject: [PATCH] Expand Text Support mode for New Map selection dialogs (#9384) --- src/fheroes2/dialog/dialog_selectscenario.cpp | 26 ++++++++++++++++++ src/fheroes2/game/game_scenarioinfo.cpp | 27 +++++++++++++++++++ src/fheroes2/maps/maps_fileinfo.cpp | 15 ++++++++++- src/fheroes2/maps/maps_fileinfo.h | 3 +++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/fheroes2/dialog/dialog_selectscenario.cpp b/src/fheroes2/dialog/dialog_selectscenario.cpp index 1604eb32140..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 @@ -38,6 +39,7 @@ #include "icn.h" #include "image.h" #include "localevent.h" +#include "logging.h" #include "screen.h" #include "settings.h" #include "system.h" @@ -88,6 +90,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 ); @@ -423,9 +446,12 @@ void ScenarioListBox::ActionListDoubleClick( Maps::FileInfo & /* unused */ ) const Maps::FileInfo * Dialog::SelectScenario( const MapsFileInfoList & allMaps, const bool isForEditor ) { if ( allMaps.empty() ) { + outputNoMapInTextSupportMode(); 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..38ac2965f61 100644 --- a/src/fheroes2/game/game_scenarioinfo.cpp +++ b/src/fheroes2/game/game_scenarioinfo.cpp @@ -65,6 +65,23 @@ 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 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 ) @@ -227,6 +244,7 @@ namespace Players & players = conf.GetPlayers(); + showCurrentlySelectedMapInfoInTextSupportMode( mapInfo ); conf.setCurrentMapInfo( mapInfo ); updatePlayers( players, humanPlayerCount ); Game::LoadPlayers( mapInfo.filename, players ); @@ -298,6 +316,8 @@ namespace fheroes2::GameMode result = fheroes2::GameMode::QUIT_GAME; + outputNewGameInTextSupportMode(); + LocalEvent & le = LocalEvent::Get(); while ( true ) { @@ -319,9 +339,14 @@ 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 ) { + showCurrentlySelectedMapInfoInTextSupportMode( *fi ); Game::SavePlayers( currentMapName, conf.GetPlayers() ); conf.setCurrentMapInfo( *fi ); @@ -345,6 +370,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; diff --git a/src/fheroes2/maps/maps_fileinfo.cpp b/src/fheroes2/maps/maps_fileinfo.cpp index 9ed4b74c2e9..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 @@ -633,6 +633,19 @@ 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 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,