1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement an editor to customize the touchscreen controls (#14933)

- The editor is accessible via the pause menu and the settings menu.
- Buttons can be moved via drag & drop.
- Buttons can be added/removed. The grid menu added by #14918 is used to show
  all buttons not included in the layout.
- Custom layouts are responsive and adapt to changed screen size / DPI /
  hud_scaling.
- The layout is saved as JSON in the "touch_layout" setting.
This commit is contained in:
grorp 2024-11-24 11:33:39 +01:00 committed by GitHub
parent 4faa16fe0d
commit 6a1d22b2c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1122 additions and 195 deletions

View file

@ -26,6 +26,7 @@
#include "client/event_manager.h"
#include "fontengine.h"
#include "gui/touchcontrols.h"
#include "gui/touchscreeneditor.h"
#include "itemdef.h"
#include "log.h"
#include "log_internal.h"
@ -144,6 +145,11 @@ struct LocalFormspecHandler : public TextDest
return;
}
if (fields.find("btn_touchscreen_layout") != fields.end()) {
g_gamecallback->touchscreenLayout();
return;
}
if (fields.find("btn_exit_menu") != fields.end()) {
g_gamecallback->disconnect();
return;
@ -1844,6 +1850,12 @@ inline bool Game::handleCallbacks()
g_gamecallback->keyconfig_requested = false;
}
if (g_gamecallback->touchscreenlayout_requested) {
(new GUITouchscreenLayout(guienv, guiroot, -1,
&g_menumgr, texture_src))->drop();
g_gamecallback->touchscreenlayout_requested = false;
}
if (!g_gamecallback->show_open_url_dialog.empty()) {
(void)make_irr<GUIOpenURLMenu>(guienv, guiroot, -1,
&g_menumgr, texture_src, g_gamecallback->show_open_url_dialog);
@ -4510,9 +4522,14 @@ void Game::showPauseMenu()
<< strgettext("Sound Volume") << "]";
}
#endif
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;"
<< strgettext("Controls") << "]";
#endif
if (g_touchcontrols) {
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_touchscreen_layout;"
<< strgettext("Touchscreen Layout") << "]";
} else {
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;"
<< strgettext("Controls") << "]";
}
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;"
<< strgettext("Exit to Menu") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"