Переглянути джерело

Only show touchscreen options on systems that have one

Ivan Savenko 2 роки тому
батько
коміт
70155b48e1

+ 5 - 0
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);

+ 3 - 0
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;
 

+ 5 - 0
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)

+ 1 - 0
client/eventsSDL/InputSourceTouch.h

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

+ 5 - 1
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<CToggleButton> touchscreenModeCheckbox = widget<CToggleButton>("touchscreenModeCheckbox");
-	touchscreenModeCheckbox->setSelected(settings["battle"]["touchscreenMode"].Bool());
+	if (touchscreenModeCheckbox)
+		touchscreenModeCheckbox->setSelected(settings["battle"]["touchscreenMode"].Bool());
 
 	std::shared_ptr<CToggleButton> skipBattleIntroMusicCheckbox = widget<CToggleButton>("skipBattleIntroMusicCheckbox");
 	skipBattleIntroMusicCheckbox->setSelected(settings["gameTweaks"]["skipBattleIntroMusic"].Bool());

+ 3 - 2
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"));

+ 2 - 0
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"
 				},
 			]