Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toggling touchscreen mode at runtime #14075

Merged
merged 33 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2520e96
minetest: allow configurable touchscreen
okias Dec 6, 2023
6a31b87
fixup! minetest: allow configurable touchscreen
okias Jan 7, 2024
054ca39
fixup! minetest: allow configurable touchscreen
okias Jan 14, 2024
494cfc5
buttonbar: convert SCROLL_BTN_WIDTH into function
okias Dec 30, 2023
94db07d
check for enable_touch directly, g_touchscreengui is always null in m…
okias Dec 30, 2023
2ac4ffb
move code into correct block
okias Dec 30, 2023
d90e5a8
query for enable_touch in clientdynamicinfo.h
okias Dec 30, 2023
c550b4b
implement size_tag function instead of variable
okias Dec 30, 2023
4cafcc1
fixup! implement size_tag function instead of variable
okias Jan 14, 2024
2af9607
rename TS entry in the menu
okias Dec 30, 2023
ff120f5
unhack password change scalling
okias Dec 30, 2023
2050b75
fix typo
okias Dec 30, 2023
b37476f
rename m_cache_hold_aux to m_touch_simulate_aux1 to better describe it
okias Dec 30, 2023
5d63fb8
rename isNoCrosshairAllowed to isTouchCrosshairDisabled
okias Dec 30, 2023
da101a9
fix original shorted named, in next commit it gets normalized anyway
okias Jan 1, 2024
dda0ff3
UPDATED: partial solution for possible crash when key is deassigned
okias Dec 30, 2023
30cc841
fixup! UPDATED: partial solution for possible crash when key is deass…
okias Jan 14, 2024
390d351
fixup! UPDATED: partial solution for possible crash when key is deass…
okias Jan 14, 2024
d4e1ce1
Fix stale page list after changing "enable_touch"
grorp Jan 2, 2024
8fb9a4f
fixup! Fix stale page list after changing "enable_touch"
okias Jan 14, 2024
e1fbc13
Do not let Android users disable accidentally touchscreen
okias Jan 14, 2024
9c2835b
Hide control settings when the touchscreen is enabled.
okias Jan 14, 2024
24eb773
Revert "Hide control settings when the touchscreen is enabled."
grorp Jan 15, 2024
8e6214b
Fixes
grorp Jan 15, 2024
d4d7dd2
remove recently added #ifdef
okias Feb 7, 2024
a4da16e
initialize m_touch_simulate_aux1 early
okias Feb 18, 2024
3974e48
check for control_text instead of touchscreen GUI
okias Feb 18, 2024
909e9b9
drop touchscreengui include from main.cpp
okias Feb 18, 2024
ae53781
make buttons list const
okias Feb 18, 2024
13fb14d
use KEY_UNKNOWN
okias Feb 18, 2024
eaf73a0
drop TOUCHSCREEN_GUI from .luacheckrc
okias Feb 18, 2024
f0bd5e2
drop unused renderingengine.h include
okias Feb 18, 2024
5b58981
Update builtin/mainmenu/settings/dlg_settings.lua
okias Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ files["builtin/mainmenu"] = {

read_globals = {
"PLATFORM",
"TOUCHSCREEN_GUI",
},
}

Expand All @@ -82,9 +81,3 @@ files["builtin/common/tests"] = {
"assert",
},
}

files["builtin/fstk"] = {
read_globals = {
"TOUCHSCREEN_GUI",
},
}
14 changes: 8 additions & 6 deletions builtin/fstk/buttonbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@


local BASE_SPACING = 0.1
local SCROLL_BTN_WIDTH = TOUCHSCREEN_GUI and 0.8 or 0.5
local function get_scroll_btn_width()
return core.settings:get_bool("enable_touch") and 0.8 or 0.5
end

local function buttonbar_formspec(self)
if self.hidden then
Expand All @@ -39,7 +41,7 @@ local function buttonbar_formspec(self)

-- The number of buttons per page is always calculated as if the scroll
-- buttons were visible.
local avail_space = self.size.x - 2*BASE_SPACING - 2*SCROLL_BTN_WIDTH
local avail_space = self.size.x - 2*BASE_SPACING - 2*get_scroll_btn_width()
local btns_per_page = math.floor((avail_space - BASE_SPACING) / (btn_size + BASE_SPACING))

self.num_pages = math.ceil(#self.buttons / btns_per_page)
Expand All @@ -55,7 +57,7 @@ local function buttonbar_formspec(self)

local btn_start_x = self.pos.x + btn_spacing
if show_scroll_btns then
btn_start_x = btn_start_x + BASE_SPACING + SCROLL_BTN_WIDTH
btn_start_x = btn_start_x + BASE_SPACING + get_scroll_btn_width()
end

for i = first_btn, first_btn + btns_per_page - 1 do
Expand All @@ -80,19 +82,19 @@ local function buttonbar_formspec(self)
y = self.pos.y + BASE_SPACING,
}
local btn_next_pos = {
x = self.pos.x + self.size.x - BASE_SPACING - SCROLL_BTN_WIDTH,
x = self.pos.x + self.size.x - BASE_SPACING - get_scroll_btn_width(),
y = self.pos.y + BASE_SPACING,
}

table.insert(formspec, string.format("style[%s,%s;noclip=true]",
self.btn_prev_name, self.btn_next_name))

table.insert(formspec, string.format("button[%f,%f;%f,%f;%s;<]",
btn_prev_pos.x, btn_prev_pos.y, SCROLL_BTN_WIDTH, btn_size,
btn_prev_pos.x, btn_prev_pos.y, get_scroll_btn_width(), btn_size,
self.btn_prev_name))

table.insert(formspec, string.format("button[%f,%f;%f,%f;%s;>]",
btn_next_pos.x, btn_next_pos.y, SCROLL_BTN_WIDTH, btn_size,
btn_next_pos.x, btn_next_pos.y, get_scroll_btn_width(), btn_size,
self.btn_next_name))
end

Expand Down
8 changes: 4 additions & 4 deletions builtin/mainmenu/content/dlg_contentstore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ local function get_info_formspec(text)
return table.concat({
"formspec_version[6]",
"size[15.75,9.5]",
TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "position[0.5,0.55]",
core.settings:get_bool("enable_touch") and "padding[0.01,0.01]" or "position[0.5,0.55]",

"label[4,4.35;", text, "]",
"container[0,", H - 0.8 - 0.375, "]",
Expand Down Expand Up @@ -928,7 +928,7 @@ function store.get_formspec(dlgdata)
local formspec = {
"formspec_version[6]",
"size[15.75,9.5]",
TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "position[0.5,0.55]",
core.settings:get_bool("enable_touch") and "padding[0.01,0.01]" or "position[0.5,0.55]",

"style[status,downloading,queued;border=false]",

Expand Down Expand Up @@ -1175,8 +1175,8 @@ end

function store.handle_events(event)
if event == "DialogShow" then
-- On mobile, don't show the "MINETEST" header behind the dialog.
mm_game_theme.set_engine(TOUCHSCREEN_GUI)
-- On touchscreen, don't show the "MINETEST" header behind the dialog.
mm_game_theme.set_engine(core.settings:get_bool("enable_touch"))

-- If the store is already loaded, auto-install packages here.
do_auto_install()
Expand Down
25 changes: 17 additions & 8 deletions builtin/mainmenu/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ local function check_requirements(name, requires)
local special = {
android = PLATFORM == "Android",
desktop = PLATFORM ~= "Android",
touchscreen_gui = TOUCHSCREEN_GUI,
keyboard_mouse = not TOUCHSCREEN_GUI,
touchscreen_gui = core.settings:get_bool("enable_touch"),
keyboard_mouse = not core.settings:get_bool("enable_touch"),
shaders_support = shaders_support,
shaders = core.settings:get_bool("enable_shaders") and shaders_support,
opengl = video_driver == "opengl",
Expand Down Expand Up @@ -449,13 +449,13 @@ local function get_formspec(dialogdata)

local extra_h = 1 -- not included in tabsize.height
local tabsize = {
width = TOUCHSCREEN_GUI and 16.5 or 15.5,
height = TOUCHSCREEN_GUI and (10 - extra_h) or 12,
width = core.settings:get_bool("enable_touch") and 16.5 or 15.5,
height = core.settings:get_bool("enable_touch") and (10 - extra_h) or 12,
}

local scrollbar_w = TOUCHSCREEN_GUI and 0.6 or 0.4
local scrollbar_w = core.settings:get_bool("enable_touch") and 0.6 or 0.4

local left_pane_width = TOUCHSCREEN_GUI and 4.5 or 4.25
local left_pane_width = core.settings:get_bool("enable_touch") and 4.5 or 4.25
local search_width = left_pane_width + scrollbar_w - (0.75 * 2)

local back_w = 3
Expand All @@ -468,7 +468,7 @@ local function get_formspec(dialogdata)
local fs = {
"formspec_version[6]",
"size[", tostring(tabsize.width), ",", tostring(tabsize.height + extra_h), "]",
TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "",
core.settings:get_bool("enable_touch") and "padding[0.01,0.01]" or "",
"bgcolor[#0000]",

-- HACK: this is needed to allow resubmitting the same formspec
Expand Down Expand Up @@ -641,11 +641,20 @@ local function buttonhandler(this, fields)
local value = core.is_yes(fields.show_advanced)
core.settings:set_bool("show_advanced", value)
write_settings_early()
end

if fields.enable_touch ~= nil then
rubenwardy marked this conversation as resolved.
Show resolved Hide resolved
okias marked this conversation as resolved.
Show resolved Hide resolved
local value = core.is_yes(fields.enable_touch)
core.settings:set_bool("enable_touch", value)
write_settings_early()
end

if fields.show_advanced ~= nil or fields.enable_touch ~= nil then
okias marked this conversation as resolved.
Show resolved Hide resolved
local suggested_page_id = update_filtered_pages(dialogdata.query)

dialogdata.components = nil

if not filtered_page_by_id[dialogdata.page_id] then
dialogdata.components = nil
dialogdata.leftscroll = 0
dialogdata.rightscroll = 0

Expand Down
2 changes: 1 addition & 1 deletion builtin/mainmenu/tab_local.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function singleplayer_refresh_gamebar()

local btnbar = buttonbar_create(
"game_button_bar",
TOUCHSCREEN_GUI and {x = 0, y = 7.25} or {x = 0, y = 7.475},
core.settings:get_bool("enable_touch") and {x = 0, y = 7.25} or {x = 0, y = 7.475},
{x = 15.5, y = 1.25},
"#000000",
game_buttonbar_button_handler)
Expand Down
5 changes: 5 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ invert_hotbar_mouse_wheel (Hotbar: Invert mouse wheel direction) bool false

[*Touchscreen]

# Enables touchscreen mode, allowing you to play the game with a touchscreen.
#
# Requires: !android
enable_touch (Enable touchscreen) bool true

# The length in pixels it takes for touchscreen interaction to start.
#
# Requires: touchscreen_gui
Expand Down
2 changes: 1 addition & 1 deletion doc/compiling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ General options and their default values:
INSTALL_DEVTEST=FALSE - Whether the Development Test game should be installed alongside Minetest
USE_GPROF=FALSE - Enable profiling using GProf
VERSION_EXTRA= - Text to append to version (e.g. VERSION_EXTRA=foobar -> Minetest 0.4.9-foobar)
ENABLE_TOUCH=FALSE - Enable Touchscreen support (requires support by IrrlichtMt)
ENABLE_TOUCH=FALSE - Enable touchscreen support by default (requires support by IrrlichtMt)

Library specific options:

Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ if(BUILD_CLIENT AND ENABLE_SOUND)
endif()
endif()

option(ENABLE_TOUCH "Enable Touchscreen support" FALSE)
option(ENABLE_TOUCH "Enable touchscreen by default" FALSE)
sfan5 marked this conversation as resolved.
Show resolved Hide resolved
if(ENABLE_TOUCH)
add_definitions(-DHAVE_TOUCHSCREENGUI)
message(STATUS "Touchscreen support enabled by default.")
add_definitions(-DENABLE_TOUCH)
endif()

if(BUILD_CLIENT)
Expand Down
18 changes: 9 additions & 9 deletions src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
m_rendering_engine->get_video_driver()->setTextureCreationFlag(
video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));

#ifdef HAVE_TOUCHSCREENGUI
receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver);
g_touchscreengui = receiver->m_touchscreengui;
#endif
if (g_settings->getBool("enable_touch")) {
receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver);
g_touchscreengui = receiver->m_touchscreengui;
}

the_game(
kill,
Expand Down Expand Up @@ -276,11 +276,11 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)

m_rendering_engine->get_scene_manager()->clear();

#ifdef HAVE_TOUCHSCREENGUI
delete g_touchscreengui;
g_touchscreengui = NULL;
receiver->m_touchscreengui = NULL;
#endif
if (g_touchscreengui) {
delete g_touchscreengui;
g_touchscreengui = NULL;
receiver->m_touchscreengui = NULL;
}

/* Save the settings when leaving the game.
* This makes sure that setting changes made in-game are persisted even
Expand Down