From 60b976b6c839aba12ce39cd8278b5b25e12fd72c Mon Sep 17 00:00:00 2001 From: Oleg Derevenetz Date: Fri, 20 Dec 2024 19:38:30 +0300 Subject: [PATCH] Display a description of the mechanics of right-clicking on devices with touch input (#9346) --- docs/README_android.md | 4 +-- src/engine/system.cpp | 6 ++++ src/engine/system.h | 3 ++ src/fheroes2/dialog/dialog_resolution.h | 5 +-- src/fheroes2/game/game_mainmenu.cpp | 41 ++++++++++--------------- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/docs/README_android.md b/docs/README_android.md index b442223bfe4..cc15b1a8cca 100644 --- a/docs/README_android.md +++ b/docs/README_android.md @@ -22,8 +22,8 @@ your Heroes 2 installation directory. ## Controls To simulate a right-click to get info on various items, you need to first touch and keep touching on the item of interest -and then touch anywhere else on the screen. You can then remove your first finger from the screen and keep viewing the info -on the item. +and then touch anywhere else on the screen. While holding the second finger, you can remove the first one from the screen +and keep viewing the information on the item. By default normal adventure map scrolling on the borders of the screen is disabled. To pane the viewing area around you need to press anywhere on the adventure map and slide around to change where you are viewing. diff --git a/src/engine/system.cpp b/src/engine/system.cpp index 5cc24979b00..c1f0f69aa19 100644 --- a/src/engine/system.cpp +++ b/src/engine/system.cpp @@ -56,6 +56,7 @@ #pragma GCC diagnostic ignored "-Wswitch-default" #endif +#include #include #if defined( ANDROID ) @@ -273,6 +274,11 @@ bool System::isHandheldDevice() #endif } +bool System::isTouchInputAvailable() +{ + return SDL_GetNumTouchDevices() > 0; +} + bool System::isVirtualKeyboardSupported() { #if defined( ANDROID ) || defined( TARGET_PS_VITA ) || defined( TARGET_NINTENDO_SWITCH ) diff --git a/src/engine/system.h b/src/engine/system.h index c7daa1d0850..60d1d268b8d 100644 --- a/src/engine/system.h +++ b/src/engine/system.h @@ -34,6 +34,9 @@ namespace System { bool isHandheldDevice(); + // Returns true if the target platform supports touch input, otherwise returns false. + bool isTouchInputAvailable(); + bool isVirtualKeyboardSupported(); // Returns true if target platform supports shell-level globbing (Unix-like platforms with POSIX-compatible shells). diff --git a/src/fheroes2/dialog/dialog_resolution.h b/src/fheroes2/dialog/dialog_resolution.h index 04631e18a78..adbbdbfcef4 100644 --- a/src/fheroes2/dialog/dialog_resolution.h +++ b/src/fheroes2/dialog/dialog_resolution.h @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2020 - 2022 * + * Copyright (C) 2020 - 2024 * * * * 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 * @@ -22,5 +22,6 @@ namespace Dialog { - bool SelectResolution(); // returns true if a new resolution is set + // Returns true if the screen resolution has been changed, otherwise returns false. + bool SelectResolution(); } diff --git a/src/fheroes2/game/game_mainmenu.cpp b/src/fheroes2/game/game_mainmenu.cpp index 08f5f329b76..fc664951a87 100644 --- a/src/fheroes2/game/game_mainmenu.cpp +++ b/src/fheroes2/game/game_mainmenu.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "agg_image.h" @@ -58,7 +59,6 @@ #include "ui_button.h" #include "ui_dialog.h" #include "ui_language.h" -#include "ui_text.h" #include "ui_tool.h" namespace @@ -232,40 +232,33 @@ fheroes2::GameMode Game::MainMenu( const bool isFirstGameRun ) fheroes2::Display & display = fheroes2::Display::instance(); - // image background fheroes2::drawMainMenuScreen(); + if ( isFirstGameRun ) { // Fade in Main Menu image before showing messages. This also resets the "need fade" state to have no fade-in after these messages. fheroes2::validateFadeInAndRender(); fheroes2::selectLanguage( fheroes2::getSupportedLanguages(), fheroes2::getLanguageFromAbbreviation( conf.getGameLanguage() ), true ); - if ( System::isHandheldDevice() ) { - // Handheld devices should use the minimal game's resolution. Users on handheld devices aren't asked to choose resolution. - fheroes2::showStandardTextMessage( _( "Greetings!" ), _( "Welcome to Heroes of Might and Magic II powered by fheroes2 engine!" ), Dialog::OK ); - } - else { - fheroes2::showStandardTextMessage( - _( "Greetings!" ), - _( "Welcome to Heroes of Might and Magic II powered by the fheroes2 engine!\nBefore starting the game, please select a game resolution." ), Dialog::OK ); - const bool isResolutionChanged = Dialog::SelectResolution(); - if ( isResolutionChanged ) { - fheroes2::drawMainMenuScreen(); + { + std::string body( _( "Welcome to Heroes of Might and Magic II powered by fheroes2 engine!" ) ); + + if ( System::isTouchInputAvailable() ) { + body += _( + "\n\nTo simulate a right-click with a touch to get info on various items, you need to first touch and keep touching on the item of interest and then touch anywhere else on the screen. While holding the second finger, you can remove the first one from the screen and keep viewing the information on the item." ); } - } - fheroes2::Text header( _( "Please Remember" ), fheroes2::FontType::normalYellow() ); + // Handheld devices should use the minimal game's resolution. Users on handheld devices aren't asked to choose resolution. + if ( !System::isHandheldDevice() ) { + body += _( "\n\nBefore starting the game, please select a game resolution." ); + } - fheroes2::MultiFontText body; - body.add( { _( "You can always change the language, resolution and settings of the game by clicking on the " ), fheroes2::FontType::normalWhite() } ); - body.add( { _( "door" ), fheroes2::FontType::normalYellow() } ); - body.add( { _( " on the left side of the Main Menu, or with the " ), fheroes2::FontType::normalWhite() } ); - body.add( { _( "CONFIG" ), fheroes2::FontType::normalYellow() } ); - body.add( { _( " button from the " ), fheroes2::FontType::normalWhite() } ); - body.add( { _( "NEW GAME" ), fheroes2::FontType::normalYellow() } ); - body.add( { _( " menu. \n\nEnjoy the game!" ), fheroes2::FontType::normalWhite() } ); + fheroes2::showStandardTextMessage( _( "Greetings!" ), std::move( body ), Dialog::OK ); - fheroes2::showMessage( header, body, Dialog::OK ); + if ( !System::isHandheldDevice() && Dialog::SelectResolution() ) { + fheroes2::drawMainMenuScreen(); + } + } conf.resetFirstGameRun(); conf.Save( Settings::configFileName );