From 70155b48e12cff1601a9e798c583c5f2d0be23ce Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 30 May 2023 20:08:27 +0300 Subject: [PATCH] Only show touchscreen options on systems that have one --- client/eventsSDL/InputHandler.cpp | 5 +++++ client/eventsSDL/InputHandler.h | 3 +++ client/eventsSDL/InputSourceTouch.cpp | 5 +++++ client/eventsSDL/InputSourceTouch.h | 1 + client/windows/settings/BattleOptionsTab.cpp | 6 +++++- client/windows/settings/GeneralOptionsTab.cpp | 5 +++-- config/widgets/settings/battleOptionsTab.json | 2 ++ 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index 0831c96d4..b1135e593 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -238,6 +238,11 @@ void InputHandler::stopTextInput() textHandler->stopTextInput(); } +bool InputHandler::hasTouchInputDevice() const +{ + return fingerHandler->hasTouchInputDevice(); +} + bool InputHandler::isMouseButtonPressed(MouseButton button) const { return mouseHandler->isMouseButtonPressed(button) || fingerHandler->isMouseButtonPressed(button); diff --git a/client/eventsSDL/InputHandler.h b/client/eventsSDL/InputHandler.h index 25a9cce37..3b7fe7956 100644 --- a/client/eventsSDL/InputHandler.h +++ b/client/eventsSDL/InputHandler.h @@ -63,6 +63,9 @@ public: /// Ends any existing text input state void stopTextInput(); + /// returns true if system has active touchscreen + bool hasTouchInputDevice() const; + /// Returns true if selected mouse button is pressed at the moment bool isMouseButtonPressed(MouseButton button) const; diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 3f7bc72f0..9e305de4b 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -209,6 +209,11 @@ Point InputSourceTouch::convertTouchToMouse(const SDL_TouchFingerEvent & tfinger return Point(tfinger.x * GH.screenDimensions().x, tfinger.y * GH.screenDimensions().y); } +bool InputSourceTouch::hasTouchInputDevice() const +{ + return SDL_GetNumTouchDevices() > 0; +} + bool InputSourceTouch::isMouseButtonPressed(MouseButton button) const { if (state == TouchState::TAP_DOWN_LONG) diff --git a/client/eventsSDL/InputSourceTouch.h b/client/eventsSDL/InputSourceTouch.h index 314adc36a..114309f48 100644 --- a/client/eventsSDL/InputSourceTouch.h +++ b/client/eventsSDL/InputSourceTouch.h @@ -108,5 +108,6 @@ public: void handleUpdate(); + bool hasTouchInputDevice() const; bool isMouseButtonPressed(MouseButton button) const; }; diff --git a/client/windows/settings/BattleOptionsTab.cpp b/client/windows/settings/BattleOptionsTab.cpp index 41ee4bb43..93791552a 100644 --- a/client/windows/settings/BattleOptionsTab.cpp +++ b/client/windows/settings/BattleOptionsTab.cpp @@ -15,6 +15,7 @@ #include "../../battle/BattleInterface.h" #include "../../battle/BattleActionsController.h" #include "../../gui/CGuiHandler.h" +#include "../../eventsSDL/InputHandler.h" #include "../../../lib/filesystem/ResourceID.h" #include "../../../lib/CGeneralTextHandler.h" #include "../../widgets/Buttons.h" @@ -25,6 +26,8 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; type |= REDRAW_PARENT; + addConditional("touchscreen", GH.input().hasTouchInputDevice()); + const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json")); addCallback("viewGridChanged", [this, owner](bool value) { @@ -83,7 +86,8 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) mouseShadowCheckbox->setSelected(settings["battle"]["mouseShadow"].Bool()); std::shared_ptr touchscreenModeCheckbox = widget("touchscreenModeCheckbox"); - touchscreenModeCheckbox->setSelected(settings["battle"]["touchscreenMode"].Bool()); + if (touchscreenModeCheckbox) + touchscreenModeCheckbox->setSelected(settings["battle"]["touchscreenMode"].Bool()); std::shared_ptr skipBattleIntroMusicCheckbox = widget("skipBattleIntroMusicCheckbox"); skipBattleIntroMusicCheckbox->setSelected(settings["gameTweaks"]["skipBattleIntroMusic"].Bool()); diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index b5a368a58..cc8db39ad 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -79,11 +79,12 @@ GeneralOptionsTab::GeneralOptionsTab() OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; type |= REDRAW_PARENT; - addConditional("mobile", false); - addConditional("desktop", true); #ifdef VCMI_MOBILE addConditional("mobile", true); addConditional("desktop", false); +#else + addConditional("mobile", false); + addConditional("desktop", true); #endif const JsonNode config(ResourceID("config/widgets/settings/generalOptionsTab.json")); diff --git a/config/widgets/settings/battleOptionsTab.json b/config/widgets/settings/battleOptionsTab.json index 8c2ab8df5..644ca5841 100644 --- a/config/widgets/settings/battleOptionsTab.json +++ b/config/widgets/settings/battleOptionsTab.json @@ -114,6 +114,7 @@ "text": "vcmi.battleOptions.skipBattleIntroMusic.hover", }, { + "created" : "touchscreen", "text": "vcmi.battleOptions.touchscreenMode.hover", } ] @@ -152,6 +153,7 @@ { "name": "touchscreenModeCheckbox", "help": "vcmi.battleOptions.touchscreenMode", + "created" : "touchscreen", "callback": "touchscreenModeChanged" }, ]