From 47918e176a922eb6ca71d7b5d23389a32acbe366 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 16:58:15 +0200 Subject: [PATCH 01/12] Android Permission --- android/vcmi-app/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/vcmi-app/src/main/AndroidManifest.xml b/android/vcmi-app/src/main/AndroidManifest.xml index a0bf14dcf..459d0efbd 100644 --- a/android/vcmi-app/src/main/AndroidManifest.xml +++ b/android/vcmi-app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ package="eu.vcmi.vcmi"> + - \ No newline at end of file + From 1050dee429deab0a2874e89f20779c7271c0cce7 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 16:59:33 +0200 Subject: [PATCH 02/12] Update NativeMethods.java --- .../src/main/java/eu/vcmi/vcmi/NativeMethods.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java b/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java index 90c3786a9..3ed602e20 100644 --- a/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java +++ b/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java @@ -3,11 +3,14 @@ package eu.vcmi.vcmi; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.Environment; import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; +import android.os.VibrationEffect; +import android.os.Vibrator; import org.libsdl.app.SDL; import org.libsdl.app.SDLActivity; @@ -138,6 +141,18 @@ public class NativeMethods { internalProgressDisplay(false); } + + @SuppressWarnings(Const.JNI_METHOD_SUPPRESS) + public static void hapticFeedback() + { + int duration_ms = 30; + final Context ctx = SDL.getContext(); + if (Build.VERSION.SDK_INT >= 26) { + ((Vibrator) ctx.getSystemService(ctx.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration_ms, 5)); + } else { + ((Vibrator) ctx.getSystemService(ctx.VIBRATOR_SERVICE)).vibrate(duration_ms); + } + } private static void internalProgressDisplay(final boolean show) { From a5fe6cc80b2be1ac8ef01a3fa3f775d1f4dcb1af Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 17:02:44 +0200 Subject: [PATCH 03/12] hapticFeedback --- client/eventsSDL/InputSourceTouch.cpp | 13 +++++++++++++ client/eventsSDL/InputSourceTouch.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 40d816e20..3070d1eb2 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -22,6 +22,10 @@ #include "../gui/MouseButton.h" #include "../gui/WindowHandler.h" +#ifdef VCMI_ANDROID +#include "../../lib/CAndroidVMHelper.h" +#endif + #include #include #include @@ -166,6 +170,7 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger) GH.input().setCursorPosition(convertTouchToMouse(tfinger)); GH.events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger)); GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger)); + hapticFeedback(); state = TouchState::IDLE; break; } @@ -215,6 +220,7 @@ void InputSourceTouch::handleUpdate() if (currentTime > lastTapTimeTicks + params.longTouchTimeMilliseconds) { GH.events().dispatchShowPopup(GH.getCursorPosition()); + hapticFeedback(); if (GH.windows().isTopWindowPopup()) state = TouchState::TAP_DOWN_LONG; @@ -287,3 +293,10 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger) if (distanceOld > params.pinchSensitivityThreshold) GH.events().dispatchGesturePinch(lastTapPosition, distanceNew / distanceOld); } + +void InputSourceTouch::hapticFeedback() { +#if defined(VCMI_ANDROID) + CAndroidVMHelper vmHelper; + vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); +#endif +} diff --git a/client/eventsSDL/InputSourceTouch.h b/client/eventsSDL/InputSourceTouch.h index 233f25fc1..85a102b78 100644 --- a/client/eventsSDL/InputSourceTouch.h +++ b/client/eventsSDL/InputSourceTouch.h @@ -94,6 +94,8 @@ class InputSourceTouch void emitPanningEvent(const SDL_TouchFingerEvent & tfinger); void emitPinchEvent(const SDL_TouchFingerEvent & tfinger); + + void hapticFeedback(); public: InputSourceTouch(); From da8bcdd2dd4c0fa591e15dfe802125a8e163c8f6 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:15:36 +0200 Subject: [PATCH 04/12] ios Support --- client/eventsSDL/InputSourceTouch.cpp | 6 ++++++ client/ios/utils.h | 2 ++ client/ios/utils.mm | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 3070d1eb2..6651ea1d4 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -25,6 +25,9 @@ #ifdef VCMI_ANDROID #include "../../lib/CAndroidVMHelper.h" #endif +#ifdef VCMI_IOS +#include "../ios/utils.h" +#endif #include #include @@ -299,4 +302,7 @@ void InputSourceTouch::hapticFeedback() { CAndroidVMHelper vmHelper; vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); #endif +#if defined(VCMI_IOS) + iOS_utils::hapticFeedback(); +#endif } diff --git a/client/ios/utils.h b/client/ios/utils.h index f3a643d83..c921ae23b 100644 --- a/client/ios/utils.h +++ b/client/ios/utils.h @@ -15,4 +15,6 @@ double screenScale(); void showLoadingIndicator(); void hideLoadingIndicator(); + +void hapticFeedback(); } diff --git a/client/ios/utils.mm b/client/ios/utils.mm index 41cb65f4f..643fa8bae 100644 --- a/client/ios/utils.mm +++ b/client/ios/utils.mm @@ -43,4 +43,11 @@ void hideLoadingIndicator() [indicator removeFromSuperview]; indicator = nil; } + +void hapticFeedback() +{ + UIImpactFeedbackGenerator *hapticGen = [[UIImpactFeedbackGenerator alloc] initWithStyle:(UIImpactFeedbackStyleLight)]; + [hapticGen impactOccurred]; + hapticGen = NULL; +} } From c786583ce86002000e2b4cfdcde970eb826a6124 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:16:54 +0200 Subject: [PATCH 05/12] Android Tick Effect --- .../vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java b/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java index 3ed602e20..8470e2d16 100644 --- a/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java +++ b/android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java @@ -145,12 +145,11 @@ public class NativeMethods @SuppressWarnings(Const.JNI_METHOD_SUPPRESS) public static void hapticFeedback() { - int duration_ms = 30; final Context ctx = SDL.getContext(); if (Build.VERSION.SDK_INT >= 26) { - ((Vibrator) ctx.getSystemService(ctx.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration_ms, 5)); + ((Vibrator) ctx.getSystemService(ctx.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK)); } else { - ((Vibrator) ctx.getSystemService(ctx.VIBRATOR_SERVICE)).vibrate(duration_ms); + ((Vibrator) ctx.getSystemService(ctx.VIBRATOR_SERVICE)).vibrate(30); } } From ff51b8f46b7cf059368fe67c93719e104a9cce57 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:47:38 +0200 Subject: [PATCH 06/12] Setting for haptic feedback --- Mods/vcmi/config/vcmi/english.json | 2 ++ Mods/vcmi/config/vcmi/german.json | 2 ++ client/eventsSDL/InputSourceTouch.cpp | 9 ++++++--- client/eventsSDL/InputSourceTouch.h | 2 ++ client/windows/settings/GeneralOptionsTab.cpp | 7 +++++++ config/schemas/settings.json | 7 ++++++- config/widgets/settings/generalOptionsTab.json | 12 +++++++++++- 7 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index c07d25215..d2d264574 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -74,6 +74,8 @@ "vcmi.systemOptions.longTouchMenu.entry" : "%d milliseconds", "vcmi.systemOptions.framerateButton.hover" : "Show FPS", "vcmi.systemOptions.framerateButton.help" : "{Show FPS}\n\nToggle the visibility of the Frames Per Second counter in the corner of the game window", + "vcmi.systemOptions.hapticFeedbackButton.hover" : "Haptic feedback", + "vcmi.systemOptions.hapticFeedbackButton.help" : "{Haptic feedback}\n\nToggle the haptic feedback on touch inputs", "vcmi.adventureOptions.infoBarPick.hover" : "Show Messages in Info Panel", "vcmi.adventureOptions.infoBarPick.help" : "{Show Messages in Info Panel}\n\nWhenever possible, game messages from visiting map objects will be shown in the info panel, instead of popping up in a separate window.", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index b585d28de..aab2710e3 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -74,6 +74,8 @@ "vcmi.systemOptions.longTouchMenu.entry" : "%d Millisekunden", "vcmi.systemOptions.framerateButton.hover" : "FPS anzeigen", "vcmi.systemOptions.framerateButton.help" : "{FPS anzeigen}\n\n Schaltet die Sichtbarkeit des Zählers für die Bilder pro Sekunde in der Ecke des Spielfensters um.", + "vcmi.systemOptions.hapticFeedbackButton.hover" : "Haptisches Feedback", + "vcmi.systemOptions.hapticFeedbackButton.help" : "{Haptisches Feedback}\n\nHaptisches Feedback bei Touch-Eingaben.", "vcmi.adventureOptions.infoBarPick.hover" : "Meldungen im Infobereich anzeigen", "vcmi.adventureOptions.infoBarPick.help" : "{Meldungen im Infobereich anzeigen}\n\nWann immer möglich, werden Spielnachrichten von besuchten Kartenobjekten in der Infoleiste angezeigt, anstatt als Popup-Fenster zu erscheinen", diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 6651ea1d4..3bd4f55b2 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -39,6 +39,7 @@ InputSourceTouch::InputSourceTouch() params.useRelativeMode = settings["general"]["userRelativePointer"].Bool(); params.relativeModeSpeedFactor = settings["general"]["relativePointerSpeedMultiplier"].Float(); params.longTouchTimeMilliseconds = settings["general"]["longTouchTimeMilliseconds"].Float(); + params.hapticFeedback = settings["general"]["hapticFeedback"].Bool(); if (params.useRelativeMode) state = TouchState::RELATIVE_MODE; @@ -298,11 +299,13 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger) } void InputSourceTouch::hapticFeedback() { + if(hapticFeedback) #if defined(VCMI_ANDROID) - CAndroidVMHelper vmHelper; - vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); + CAndroidVMHelper vmHelper; + vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); #endif #if defined(VCMI_IOS) - iOS_utils::hapticFeedback(); + iOS_utils::hapticFeedback(); #endif + } } diff --git a/client/eventsSDL/InputSourceTouch.h b/client/eventsSDL/InputSourceTouch.h index 85a102b78..82980c42e 100644 --- a/client/eventsSDL/InputSourceTouch.h +++ b/client/eventsSDL/InputSourceTouch.h @@ -79,6 +79,8 @@ struct TouchInputParameters uint32_t pinchSensitivityThreshold = 10; bool useRelativeMode = false; + + bool hapticFeedback = false; }; /// Class that handles touchscreen input from SDL events diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index 4710067cc..ae1ce6548 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -153,6 +153,10 @@ GeneralOptionsTab::GeneralOptionsTab() { setBoolSetting("video", "showfps", value); }); + addCallback("hapticFeedbackChanged", [](bool value) + { + setBoolSetting("general", "hapticFeedback", value); + }); //moved from "other" tab that is disabled for now to avoid excessible tabs with barely any content addCallback("availableCreaturesAsDwellingChanged", [=](int value) @@ -190,6 +194,9 @@ GeneralOptionsTab::GeneralOptionsTab() std::shared_ptr framerateCheckbox = widget("framerateCheckbox"); framerateCheckbox->setSelected(settings["video"]["showfps"].Bool()); + std::shared_ptr hapticFeedbackCheckbox = widget("hapticFeedbackCheckbox"); + hapticFeedbackCheckbox->setSelected(settings["general"]["hapticFeedback"].Bool()); + std::shared_ptr musicSlider = widget("musicSlider"); musicSlider->scrollTo(CCS->musich->getVolume()); diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 71832ae99..30cc2808a 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -33,7 +33,8 @@ "extraDump", "userRelativePointer", "relativePointerSpeedMultiplier", - "longTouchTimeMilliseconds" + "longTouchTimeMilliseconds", + "hapticFeedback" ], "properties" : { "playerName" : { @@ -101,6 +102,10 @@ "longTouchTimeMilliseconds" : { "type" : "number", "default" : 1000 + }, + "hapticFeedback" : { + "type" : "boolean", + "default" : false } } }, diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index 78f042adf..27a613039 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -57,6 +57,10 @@ "name": "longTouchLabel", "text": "vcmi.systemOptions.longTouchButton.hover", "created" : "touchscreen" + }, + { + "text": "vcmi.systemOptions.hapticFeedbackButton.hover", + "created" : "touchscreen" } ] }, @@ -76,7 +80,7 @@ "name": "scalingButton", "type": "buttonGear", "help": "vcmi.systemOptions.scalingButton", - "callback": "setGameScaling", + "callback": "setGameScaling" }, { "name": "fullscreenBorderlessCheckbox", @@ -106,6 +110,12 @@ "help": "vcmi.systemOptions.longTouchButton", "callback": "setLongTouchDuration", "created" : "touchscreen" + }, + { + "name": "hapticFeedbackCheckbox", + "help": "vcmi.systemOptions.hapticFeedbackButton", + "callback": "hapticFeedbackChanged", + "created" : "touchscreen" } ] }, From 050a22c257c07fb4e8f95a1dbd4bce08342d450e Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:50:59 +0200 Subject: [PATCH 07/12] only pop up for now --- client/eventsSDL/InputSourceTouch.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 3bd4f55b2..d5325513f 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -174,7 +174,6 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger) GH.input().setCursorPosition(convertTouchToMouse(tfinger)); GH.events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger)); GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger)); - hapticFeedback(); state = TouchState::IDLE; break; } From 06541211d5ac7890b0445e8d7f6a203c8112e3f3 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 19:11:26 +0200 Subject: [PATCH 08/12] Rename var --- client/eventsSDL/InputSourceTouch.cpp | 4 ++-- client/eventsSDL/InputSourceTouch.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index d5325513f..3f7a696c8 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -39,7 +39,7 @@ InputSourceTouch::InputSourceTouch() params.useRelativeMode = settings["general"]["userRelativePointer"].Bool(); params.relativeModeSpeedFactor = settings["general"]["relativePointerSpeedMultiplier"].Float(); params.longTouchTimeMilliseconds = settings["general"]["longTouchTimeMilliseconds"].Float(); - params.hapticFeedback = settings["general"]["hapticFeedback"].Bool(); + params.hapticFeedbackEnabled = settings["general"]["hapticFeedback"].Bool(); if (params.useRelativeMode) state = TouchState::RELATIVE_MODE; @@ -298,7 +298,7 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger) } void InputSourceTouch::hapticFeedback() { - if(hapticFeedback) + if(hapticFeedbackEnabled) #if defined(VCMI_ANDROID) CAndroidVMHelper vmHelper; vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); diff --git a/client/eventsSDL/InputSourceTouch.h b/client/eventsSDL/InputSourceTouch.h index 82980c42e..fb7277046 100644 --- a/client/eventsSDL/InputSourceTouch.h +++ b/client/eventsSDL/InputSourceTouch.h @@ -80,7 +80,7 @@ struct TouchInputParameters bool useRelativeMode = false; - bool hapticFeedback = false; + bool hapticFeedbackEnabled = false; }; /// Class that handles touchscreen input from SDL events From 70b7f992de28e092896ab0ffaee79b59cbf27df2 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 20:34:11 +0200 Subject: [PATCH 09/12] fix --- client/eventsSDL/InputSourceTouch.cpp | 3 ++- config/widgets/settings/generalOptionsTab.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 3f7a696c8..314fff09e 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -108,6 +108,7 @@ void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinge { // FIXME: better place to update potentially changed settings? params.longTouchTimeMilliseconds = settings["general"]["longTouchTimeMilliseconds"].Float(); + params.hapticFeedbackEnabled = settings["general"]["hapticFeedback"].Bool(); lastTapTimeTicks = tfinger.timestamp; @@ -298,7 +299,7 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger) } void InputSourceTouch::hapticFeedback() { - if(hapticFeedbackEnabled) + if(hapticFeedbackEnabled) { #if defined(VCMI_ANDROID) CAndroidVMHelper vmHelper; vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index 27a613039..ae3518c0e 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -60,7 +60,7 @@ }, { "text": "vcmi.systemOptions.hapticFeedbackButton.hover", - "created" : "touchscreen" + "created" : "mobile" } ] }, From d91175682702c639582bc2ed5cef69943060a4c1 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Jul 2023 21:02:03 +0200 Subject: [PATCH 10/12] changes from code review --- client/eventsSDL/InputSourceTouch.cpp | 14 ++++++-------- client/ios/utils.mm | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 314fff09e..8e627ac27 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -22,10 +22,9 @@ #include "../gui/MouseButton.h" #include "../gui/WindowHandler.h" -#ifdef VCMI_ANDROID +#if defined(VCMI_ANDROID) #include "../../lib/CAndroidVMHelper.h" -#endif -#ifdef VCMI_IOS +#elif defined(VCMI_IOS) #include "../ios/utils.h" #endif @@ -299,12 +298,11 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger) } void InputSourceTouch::hapticFeedback() { - if(hapticFeedbackEnabled) { + if(params.hapticFeedbackEnabled) { #if defined(VCMI_ANDROID) - CAndroidVMHelper vmHelper; - vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); -#endif -#if defined(VCMI_IOS) + CAndroidVMHelper vmHelper; + vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback"); +#elif defined(VCMI_IOS) iOS_utils::hapticFeedback(); #endif } diff --git a/client/ios/utils.mm b/client/ios/utils.mm index 643fa8bae..42cca084e 100644 --- a/client/ios/utils.mm +++ b/client/ios/utils.mm @@ -46,8 +46,7 @@ void hideLoadingIndicator() void hapticFeedback() { - UIImpactFeedbackGenerator *hapticGen = [[UIImpactFeedbackGenerator alloc] initWithStyle:(UIImpactFeedbackStyleLight)]; - [hapticGen impactOccurred]; - hapticGen = NULL; + auto hapticGen = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight]; + [hapticGen impactOccurred]; } } From 11bcedc2bf46e589ee4ed14ea1e3e77a4faa5675 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Wed, 12 Jul 2023 22:56:23 +0200 Subject: [PATCH 11/12] Update config/widgets/settings/generalOptionsTab.json Co-authored-by: Ivan Savenko --- config/widgets/settings/generalOptionsTab.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index ae3518c0e..f8a5a4602 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -115,7 +115,7 @@ "name": "hapticFeedbackCheckbox", "help": "vcmi.systemOptions.hapticFeedbackButton", "callback": "hapticFeedbackChanged", - "created" : "touchscreen" + "created" : "mobile" } ] }, From 1abd8bbe9208cda7254497f4419b10a7bbda7fa7 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Wed, 12 Jul 2023 22:56:35 +0200 Subject: [PATCH 12/12] Update client/windows/settings/GeneralOptionsTab.cpp Co-authored-by: Ivan Savenko --- client/windows/settings/GeneralOptionsTab.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index ae1ce6548..0ff66f7e0 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -195,7 +195,8 @@ GeneralOptionsTab::GeneralOptionsTab() framerateCheckbox->setSelected(settings["video"]["showfps"].Bool()); std::shared_ptr hapticFeedbackCheckbox = widget("hapticFeedbackCheckbox"); - hapticFeedbackCheckbox->setSelected(settings["general"]["hapticFeedback"].Bool()); + if (hapticFeedbackCheckbox) + hapticFeedbackCheckbox->setSelected(settings["general"]["hapticFeedback"].Bool()); std::shared_ptr musicSlider = widget("musicSlider"); musicSlider->scrollTo(CCS->musich->getVolume());