Skip to content

Commit

Permalink
minetest: allow configurable touchscreen
Browse files Browse the repository at this point in the history
Signed-off-by: David Heidelberg <[email protected]>
  • Loading branch information
okias committed Dec 23, 2023
1 parent e0d4a9d commit 7ab4e11
Show file tree
Hide file tree
Showing 24 changed files with 180 additions and 261 deletions.
2 changes: 1 addition & 1 deletion builtin/fstk/buttonbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


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

local function buttonbar_formspec(self)
if self.hidden then
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
14 changes: 7 additions & 7 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
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 the touch screen.
# If disabled, touchscreen wouldn't be usable in-game
# Changing this setting requires a restart.
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 @@ -37,7 +37,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)
if(ENABLE_TOUCH)
add_definitions(-DHAVE_TOUCHSCREENGUI)
message(STATUS "Touchscreen support enabled by default.")
add_definitions(-DENABLE_TOUCH)
endif()

if(BUILD_CLIENT)
Expand Down
4 changes: 0 additions & 4 deletions src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,8 @@ 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

the_game(
kill,
Expand All @@ -286,11 +284,9 @@ 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 no main menu, show error and exit
if (skip_main_menu) {
Expand Down
Loading

0 comments on commit 7ab4e11

Please sign in to comment.