1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

TouchControls: Implement an option for dig/place buttons (#15845)

This commit is contained in:
grorp 2025-03-21 07:06:44 -04:00 committed by GitHub
parent 1f14b7cb1b
commit ead44a27ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 540 additions and 88 deletions

View file

@ -7,6 +7,7 @@
#include "irr_ptr.h"
#include "irrlichttypes_bloated.h"
#include "rect.h"
#include "util/enum_string.h"
#include <iostream>
#include <unordered_map>
@ -20,9 +21,16 @@ namespace irr::video
class ITexture;
}
enum TouchInteractionStyle : u8
{
TAP,
TAP_CROSSHAIR,
BUTTONS_CROSSHAIR,
};
extern const struct EnumString es_TouchInteractionStyle[];
enum touch_gui_button_id : u8
{
// these two are no actual buttons ... yet
dig_id = 0,
place_id,
@ -75,15 +83,34 @@ struct ButtonMeta {
};
struct ButtonLayout {
using ButtonMap = std::unordered_map<touch_gui_button_id, ButtonMeta>;
static bool isButtonValid(touch_gui_button_id id);
static bool isButtonAllowed(touch_gui_button_id id);
static bool isButtonRequired(touch_gui_button_id id);
static s32 getButtonSize(v2u32 screensize);
// Returns the default layout.
// Note: Indirectly depends on settings.
static ButtonLayout loadDefault();
// Reads the layout from the "touch_layout" setting. Falls back to loadDefault
// if the setting is absent or invalid.
// Note: Indirectly depends on additional settings.
static ButtonLayout loadFromSettings();
static video::ITexture *getTexture(touch_gui_button_id btn, ISimpleTextureSource *tsrc);
static void clearTextureCache();
std::unordered_map<touch_gui_button_id, ButtonMeta> layout;
ButtonMap layout;
// Contains disallowed buttons that have been loaded.
// These are only preserved to be saved again later.
// This exists to prevent data loss: If you edit the layout while some button
// is temporarily disallowed, this prevents that button's custom position
// from being lost. See isButtonAllowed.
// This may result in overlapping buttons when the buttons are allowed again
// (could be fixed by resolving collisions in postProcessLoaded).
ButtonMap preserved_disallowed;
core::recti getRect(touch_gui_button_id btn,
v2u32 screensize, s32 button_size, ISimpleTextureSource *tsrc);
@ -91,11 +118,12 @@ struct ButtonLayout {
std::vector<touch_gui_button_id> getMissingButtons();
void serializeJson(std::ostream &os) const;
void deserializeJson(std::istream &is);
static const ButtonLayout predefined;
private:
static const ButtonMap default_data;
static ButtonMap deserializeJson(std::istream &is);
static ButtonLayout postProcessLoaded(const ButtonMap &map);
static std::unordered_map<touch_gui_button_id, irr_ptr<video::ITexture>> texture_cache;
};