1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Only show touchscreen options on systems that have one

This commit is contained in:
Ivan Savenko
2023-05-30 20:08:27 +03:00
parent 2c7b94d17f
commit 70155b48e1
7 changed files with 24 additions and 3 deletions

View File

@@ -238,6 +238,11 @@ void InputHandler::stopTextInput()
textHandler->stopTextInput(); textHandler->stopTextInput();
} }
bool InputHandler::hasTouchInputDevice() const
{
return fingerHandler->hasTouchInputDevice();
}
bool InputHandler::isMouseButtonPressed(MouseButton button) const bool InputHandler::isMouseButtonPressed(MouseButton button) const
{ {
return mouseHandler->isMouseButtonPressed(button) || fingerHandler->isMouseButtonPressed(button); return mouseHandler->isMouseButtonPressed(button) || fingerHandler->isMouseButtonPressed(button);

View File

@@ -63,6 +63,9 @@ public:
/// Ends any existing text input state /// Ends any existing text input state
void stopTextInput(); void stopTextInput();
/// returns true if system has active touchscreen
bool hasTouchInputDevice() const;
/// Returns true if selected mouse button is pressed at the moment /// Returns true if selected mouse button is pressed at the moment
bool isMouseButtonPressed(MouseButton button) const; bool isMouseButtonPressed(MouseButton button) const;

View File

@@ -209,6 +209,11 @@ Point InputSourceTouch::convertTouchToMouse(const SDL_TouchFingerEvent & tfinger
return Point(tfinger.x * GH.screenDimensions().x, tfinger.y * GH.screenDimensions().y); 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 bool InputSourceTouch::isMouseButtonPressed(MouseButton button) const
{ {
if (state == TouchState::TAP_DOWN_LONG) if (state == TouchState::TAP_DOWN_LONG)

View File

@@ -108,5 +108,6 @@ public:
void handleUpdate(); void handleUpdate();
bool hasTouchInputDevice() const;
bool isMouseButtonPressed(MouseButton button) const; bool isMouseButtonPressed(MouseButton button) const;
}; };

View File

@@ -15,6 +15,7 @@
#include "../../battle/BattleInterface.h" #include "../../battle/BattleInterface.h"
#include "../../battle/BattleActionsController.h" #include "../../battle/BattleActionsController.h"
#include "../../gui/CGuiHandler.h" #include "../../gui/CGuiHandler.h"
#include "../../eventsSDL/InputHandler.h"
#include "../../../lib/filesystem/ResourceID.h" #include "../../../lib/filesystem/ResourceID.h"
#include "../../../lib/CGeneralTextHandler.h" #include "../../../lib/CGeneralTextHandler.h"
#include "../../widgets/Buttons.h" #include "../../widgets/Buttons.h"
@@ -25,6 +26,8 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
type |= REDRAW_PARENT; type |= REDRAW_PARENT;
addConditional("touchscreen", GH.input().hasTouchInputDevice());
const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json")); const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json"));
addCallback("viewGridChanged", [this, owner](bool value) addCallback("viewGridChanged", [this, owner](bool value)
{ {
@@ -83,6 +86,7 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
mouseShadowCheckbox->setSelected(settings["battle"]["mouseShadow"].Bool()); mouseShadowCheckbox->setSelected(settings["battle"]["mouseShadow"].Bool());
std::shared_ptr<CToggleButton> touchscreenModeCheckbox = widget<CToggleButton>("touchscreenModeCheckbox"); std::shared_ptr<CToggleButton> touchscreenModeCheckbox = widget<CToggleButton>("touchscreenModeCheckbox");
if (touchscreenModeCheckbox)
touchscreenModeCheckbox->setSelected(settings["battle"]["touchscreenMode"].Bool()); touchscreenModeCheckbox->setSelected(settings["battle"]["touchscreenMode"].Bool());
std::shared_ptr<CToggleButton> skipBattleIntroMusicCheckbox = widget<CToggleButton>("skipBattleIntroMusicCheckbox"); std::shared_ptr<CToggleButton> skipBattleIntroMusicCheckbox = widget<CToggleButton>("skipBattleIntroMusicCheckbox");

View File

@@ -79,11 +79,12 @@ GeneralOptionsTab::GeneralOptionsTab()
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
type |= REDRAW_PARENT; type |= REDRAW_PARENT;
addConditional("mobile", false);
addConditional("desktop", true);
#ifdef VCMI_MOBILE #ifdef VCMI_MOBILE
addConditional("mobile", true); addConditional("mobile", true);
addConditional("desktop", false); addConditional("desktop", false);
#else
addConditional("mobile", false);
addConditional("desktop", true);
#endif #endif
const JsonNode config(ResourceID("config/widgets/settings/generalOptionsTab.json")); const JsonNode config(ResourceID("config/widgets/settings/generalOptionsTab.json"));

View File

@@ -114,6 +114,7 @@
"text": "vcmi.battleOptions.skipBattleIntroMusic.hover", "text": "vcmi.battleOptions.skipBattleIntroMusic.hover",
}, },
{ {
"created" : "touchscreen",
"text": "vcmi.battleOptions.touchscreenMode.hover", "text": "vcmi.battleOptions.touchscreenMode.hover",
} }
] ]
@@ -152,6 +153,7 @@
{ {
"name": "touchscreenModeCheckbox", "name": "touchscreenModeCheckbox",
"help": "vcmi.battleOptions.touchscreenMode", "help": "vcmi.battleOptions.touchscreenMode",
"created" : "touchscreen",
"callback": "touchscreenModeChanged" "callback": "touchscreenModeChanged"
}, },
] ]