mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
TouchControls: touch_use_crosshair, dig/place simulation refactoring (#15800)
- get rid of simulated mouse events for digging/placing, use keyboard events instead - consistent with other simulated events, less code, no need for a pointer position - more correct: touch controls no longer break if you have custom dig/place keybindings set - move reading of "touch_use_crosshair" setting from Game to TouchControls
This commit is contained in:
parent
abcd2e0b81
commit
5e89371ecd
5 changed files with 53 additions and 63 deletions
|
@ -93,6 +93,8 @@ public:
|
|||
return res;
|
||||
}
|
||||
|
||||
bool isShootlineAvailable() { return !m_use_crosshair; }
|
||||
|
||||
/**
|
||||
* Returns a line which describes what the player is pointing at.
|
||||
* The starting point and looking direction are significant,
|
||||
|
@ -100,6 +102,9 @@ public:
|
|||
* the player can reach.
|
||||
* The line starts at the camera and ends on the camera's far plane.
|
||||
* The coordinates do not contain the camera offset.
|
||||
*
|
||||
* This may only be used if isShootlineAvailable returns true.
|
||||
* Otherwise, the normal crosshair must be used.
|
||||
*/
|
||||
line3d<f32> getShootline() { return m_shootline; }
|
||||
|
||||
|
@ -107,7 +112,6 @@ public:
|
|||
float getJoystickSpeed() { return m_joystick_speed; }
|
||||
|
||||
void step(float dtime);
|
||||
inline void setUseCrosshair(bool use_crosshair) { m_draw_crosshair = use_crosshair; }
|
||||
|
||||
void setVisible(bool visible);
|
||||
void hide();
|
||||
|
@ -132,6 +136,7 @@ private:
|
|||
s32 m_button_size;
|
||||
|
||||
// cached settings
|
||||
bool m_use_crosshair;
|
||||
double m_touchscreen_threshold;
|
||||
u16 m_long_tap_delay;
|
||||
bool m_fixed_joystick;
|
||||
|
@ -143,9 +148,6 @@ private:
|
|||
ButtonLayout m_layout;
|
||||
void applyLayout(const ButtonLayout &layout);
|
||||
|
||||
// not read from a setting, but set by Game via setUseCrosshair
|
||||
bool m_draw_crosshair = false;
|
||||
|
||||
std::unordered_map<u16, recti> m_hotbar_rects;
|
||||
std::optional<u16> m_hotbar_selection = std::nullopt;
|
||||
|
||||
|
@ -157,6 +159,8 @@ private:
|
|||
* A line starting at the camera and pointing towards the selected object.
|
||||
* The line ends on the camera's far plane.
|
||||
* The coordinates do not contain the camera offset.
|
||||
*
|
||||
* Only valid if !m_use_crosshair
|
||||
*/
|
||||
line3d<f32> m_shootline;
|
||||
|
||||
|
@ -164,7 +168,9 @@ private:
|
|||
size_t m_move_id;
|
||||
bool m_move_has_really_moved = false;
|
||||
u64 m_move_downtime = 0;
|
||||
// m_move_pos stays valid even after m_move_id has been released.
|
||||
// m_move_pos stays valid even after the m_move_id pointer has been
|
||||
// released and m_pointer_pos[m_move_id] has been erased
|
||||
// (or even overwritten by a new pointer reusing the same id).
|
||||
v2s32 m_move_pos;
|
||||
// This is needed so that we don't miss if m_has_move_id is true for less
|
||||
// than one client step, i.e. press and release happen in the same step.
|
||||
|
@ -236,8 +242,6 @@ private:
|
|||
// map to store the IDs and positions of currently pressed pointers
|
||||
std::unordered_map<size_t, v2s32> m_pointer_pos;
|
||||
|
||||
v2s32 getPointerPos();
|
||||
void emitMouseEvent(EMOUSE_INPUT_EVENT type);
|
||||
TouchInteractionMode m_last_mode = TouchInteractionMode_END;
|
||||
TapState m_tap_state = TapState::None;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue