1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Touchscreen: Allow mods to swap the meaning of short and long taps (punch with single tap) (#14087)

This works through a new field "touch_interaction" in item definitions.
The two most important use cases are:
 - Punching players/entities with short tap instead of long tap (enabled by default)
 - Making items usable that require holding the place button (e.g. bows and shields in MC-like games)
This commit is contained in:
grorp 2024-01-21 17:44:08 +01:00 committed by GitHub
parent 8cbd629010
commit 404a063fdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 288 additions and 108 deletions

View file

@ -1,5 +1,7 @@
/*
Copyright (C) 2014 sapier
Copyright (C) 2024 grorp, Gregor Parzefall
<gregor.parzefall@posteo.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@ -29,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <unordered_map>
#include <vector>
#include "itemdef.h"
#include "client/tile.h"
#include "client/game.h"
@ -36,6 +39,13 @@ using namespace irr;
using namespace irr::core;
using namespace irr::gui;
enum class TapState
{
None,
ShortTap,
LongTap,
};
typedef enum
{
jump_id = 0,
@ -75,6 +85,11 @@ typedef enum
#define SETTINGS_BAR_Y_OFFSET 5
#define RARE_CONTROLS_BAR_Y_OFFSET 5
// Our simulated clicks last some milliseconds so that server-side mods have a
// chance to detect them via l_get_player_control.
// If you tap faster than this value, the simulated clicks are of course shorter.
#define SIMULATED_CLICK_DURATION_MS 50
extern const std::string button_image_names[];
extern const std::string joystick_image_names[];
@ -161,6 +176,7 @@ public:
~TouchScreenGUI();
void translateEvent(const SEvent &event);
void applyContextControls(const TouchInteractionMode &mode);
void init(ISimpleTextureSource *tsrc);
@ -230,8 +246,6 @@ private:
size_t m_move_id;
bool m_move_has_really_moved = false;
u64 m_move_downtime = 0;
bool m_move_sent_as_mouse_event = false;
v2s32 m_move_downlocation = v2s32(-10000, -10000); // off-screen
bool m_has_joystick_id = false;
size_t m_joystick_id;
@ -283,9 +297,6 @@ private:
// handle pressing hotbar items
bool isHotbarButton(const SEvent &event);
// do a right-click
bool doRightClick();
// handle release event
void handleReleaseEvent(size_t evt_id);
@ -300,6 +311,16 @@ private:
// rare controls bar
AutoHideButtonBar m_rare_controls_bar;
v2s32 getPointerPos();
void emitMouseEvent(EMOUSE_INPUT_EVENT type);
TapState m_tap_state = TapState::None;
bool m_dig_pressed = false;
u64 m_dig_pressed_until = 0;
bool m_place_pressed = false;
u64 m_place_pressed_until = 0;
};
extern TouchScreenGUI *g_touchscreengui;