Skip to content

Commit

Permalink
Expand Text Support mode for New Map selection dialogs (#9384)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub authored Dec 30, 2024
1 parent 22556eb commit f69408e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/fheroes2/dialog/dialog_selectscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <ostream>
#include <string>
#include <vector>

Expand All @@ -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"
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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();

Expand Down
27 changes: 27 additions & 0 deletions src/fheroes2/game/game_scenarioinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -227,6 +244,7 @@ namespace

Players & players = conf.GetPlayers();

showCurrentlySelectedMapInfoInTextSupportMode( mapInfo );
conf.setCurrentMapInfo( mapInfo );
updatePlayers( players, humanPlayerCount );
Game::LoadPlayers( mapInfo.filename, players );
Expand Down Expand Up @@ -298,6 +316,8 @@ namespace

fheroes2::GameMode result = fheroes2::GameMode::QUIT_GAME;

outputNewGameInTextSupportMode();

LocalEvent & le = LocalEvent::Get();

while ( true ) {
Expand All @@ -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 );

Expand All @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion src/fheroes2/maps/maps_fileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <list>
#include <locale>
#include <map>
#include <ostream>
#include <sstream>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/fheroes2/maps/maps_fileinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f69408e

Please sign in to comment.