From a254814f1175b2f01a35acde2ca77862447f2187 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 11 Nov 2022 22:23:55 +0100 Subject: [PATCH] TouchScreenGUI: use `mouse_sensitivity` setting instead of `mouse_sensity` --- builtin/mainmenu/tab_settings_simple.lua | 4 ++-- builtin/settingtypes.txt | 3 +++ multicraft.conf.example | 4 ++++ src/defaultsettings.cpp | 20 ++++++++++++-------- src/gui/touchscreengui.cpp | 12 ++++++------ src/gui/touchscreengui.h | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/builtin/mainmenu/tab_settings_simple.lua b/builtin/mainmenu/tab_settings_simple.lua index a33c8f23d..6bbb221d9 100644 --- a/builtin/mainmenu/tab_settings_simple.lua +++ b/builtin/mainmenu/tab_settings_simple.lua @@ -81,7 +81,7 @@ local languages, language_dropdown, lang_idx = get_language_list() local function formspec(tabview, name, tabdata) local fps = tonumber(core.settings:get("fps_max")) local range = tonumber(core.settings:get("viewing_range")) - local sensitivity = tonumber(core.settings:get("mouse_sensitivity")) * 2000 + local sensitivity = tonumber(core.settings:get("touch_sensitivity")) * 2000 local touchtarget = core.settings:get_bool("touchtarget") or false local fancy_leaves = core.settings:get("leaves_style") == "fancy" local fast_move = core.settings:get_bool("fast_move") or false @@ -296,7 +296,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) local event = core.explode_scrollbar_event(fields["sb_sensitivity"]) if event.type == "CHG" then - core.settings:set("mouse_sensitivity", event.value / 2000) + core.settings:set("touch_sensitivity", event.value / 2000) -- The formspec cannot be updated or the scrollbar movement will -- break. diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 89727a39d..cc6e40e4d 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -99,6 +99,9 @@ invert_mouse (Invert mouse) bool false # Mouse sensitivity multiplier. mouse_sensitivity (Mouse sensitivity) float 0.2 +# Touch sensitivity multiplier. +touch_sensitivity (Touch sensitivity) float 0.2 + # If enabled, "special" key instead of "sneak" key is used for climbing down and # descending. aux1_descends (Special key for climbing/descending) bool false diff --git a/multicraft.conf.example b/multicraft.conf.example index 62a580226..6804047f1 100644 --- a/multicraft.conf.example +++ b/multicraft.conf.example @@ -61,6 +61,10 @@ # type: float # mouse_sensitivity = 0.2 +# Touch sensitivity multiplier. +# type: float +# touch_sensitivity = 0.2 + # If enabled, "special" key instead of "sneak" key is used for climbing down and # descending. # type: bool diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 4dc61db38..8161e51b6 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -528,6 +528,7 @@ void set_default_settings() #ifdef HAVE_TOUCHSCREENGUI settings->setDefault("touchtarget", "true"); settings->setDefault("touchscreen_threshold", "20"); + settings->setDefault("touch_sensitivity", "0.2"); settings->setDefault("fixed_virtual_joystick", "true"); settings->setDefault("virtual_joystick_triggers_aux", "false"); settings->setDefault("fast_move", "true"); @@ -640,7 +641,7 @@ void set_default_settings() if (x_inches <= 3.7) { // small 4" phones g_settings->setDefault("hud_scaling", "0.55"); - g_settings->setDefault("mouse_sensitivity", "0.3"); + g_settings->setDefault("touch_sensitivity", "0.3"); } else if (x_inches > 3.7 && x_inches <= 4.5) { // medium phones g_settings->setDefault("hud_scaling", "0.6"); @@ -686,33 +687,36 @@ void set_default_settings() if SDVersion4Inch { // 4" iPhone and iPod Touch settings->setDefault("hud_scaling", "0.55"); - settings->setDefault("mouse_sensitivity", "0.33"); + settings->setDefault("touch_sensitivity", "0.33"); } else if SDVersion4and7Inch { // 4.7" iPhone settings->setDefault("hud_scaling", "0.6"); - settings->setDefault("mouse_sensitivity", "0.27"); + settings->setDefault("touch_sensitivity", "0.27"); } else if SDVersion5and5Inch { // 5.5" iPhone Plus settings->setDefault("hud_scaling", "0.65"); - settings->setDefault("mouse_sensitivity", "0.3"); + settings->setDefault("touch_sensitivity", "0.3"); } else if (SDVersion5and8Inch || SDVersion6and1Inch) { // 5.8" and 6.1" iPhones settings->setDefault("hud_scaling", "0.8"); - settings->setDefault("mouse_sensitivity", "0.35"); + settings->setDefault("touch_sensitivity", "0.35"); settings->setDefault("selectionbox_width", "6"); } else if SDVersion6and5Inch { // 6.5" iPhone settings->setDefault("hud_scaling", "0.85"); - settings->setDefault("mouse_sensitivity", "0.35"); + settings->setDefault("touch_sensitivity", "0.35"); settings->setDefault("selectionbox_width", "6"); } else if SDVersion7and9Inch { // iPad mini settings->setDefault("hud_scaling", "0.9"); - settings->setDefault("mouse_sensitivity", "0.25"); + settings->setDefault("touch_sensitivity", "0.25"); + settings->setDefault("selectionbox_width", "6"); + } else if SDVersion8and3Inch { + settings->setDefault("touch_sensitivity", "0.25"); settings->setDefault("selectionbox_width", "6"); } else { // iPad - settings->setDefault("mouse_sensitivity", "0.3"); + settings->setDefault("touch_sensitivity", "0.3"); settings->setDefault("selectionbox_width", "6"); } diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index f2a9c945d..93b59323c 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -437,7 +437,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) } m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold"); - m_mouse_sensitivity = rangelim(g_settings->getFloat("mouse_sensitivity"), 0.1, 1.0); + m_touch_sensitivity = rangelim(g_settings->getFloat("touch_sensitivity"), 0.1, 1.0); m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick"); m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux"); m_screensize = m_device->getVideoDriver()->getScreenSize(); @@ -865,6 +865,9 @@ void TouchScreenGUI::moveJoystick(const SEvent &event, float dx, float dy) { void TouchScreenGUI::translateEvent(const SEvent &event) { + if (!m_buttons_initialized) + return; + if (!m_visible) { infostream << "TouchScreenGUI::translateEvent got event but not visible!" @@ -991,11 +994,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) s32 dx = X - m_pointerpos[event.TouchInput.ID].X; s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y; - // adapt to similar behaviour as pc screen - double d = m_mouse_sensitivity; - - m_camera_yaw_change -= dx * d; - m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180); + m_camera_yaw_change -= dx * m_touch_sensitivity; + m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * m_touch_sensitivity), -180), 180); // update shootline m_shootline = m_device diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 2dee53ea8..d1b8dd0ec 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -224,7 +224,7 @@ private: v2u32 m_screensize; s32 button_size; double m_touchscreen_threshold; - double m_mouse_sensitivity; + double m_touch_sensitivity; std::map> m_hud_rects; std::map m_hud_ids; bool m_visible; // is the gui visible