feat: complete mobile UI implementation

This commit is contained in:
shenlei
2026-09-04 19:54:33 +09:00
parent 9a4a044da5
commit b19d5b5dd3
132 changed files with 6643 additions and 180 deletions
+24 -2
View File
@@ -14,6 +14,8 @@ var _icon: TextureRect
var _label: Label
var _attached: Dictionary = {}
var _targets: Array[Dictionary] = []
var _touch_index := -1
var _touch_position := Vector2.ZERO
func setup(parent: Node, cursor_manager: Node = null, audio_node: Node = null) -> void:
cursor = cursor_manager
@@ -41,11 +43,15 @@ func setup(parent: Node, cursor_manager: Node = null, audio_node: Node = null) -
set_process_input(true)
func attach_item(window: int, cell: int, vnum: int, count: int,
texture: Texture2D = null, source := "inventory", metadata: Dictionary = {}) -> bool:
texture: Texture2D = null, source := "inventory", metadata: Dictionary = {},
touch_index := -1, touch_position := Vector2(-1, -1)) -> bool:
if vnum <= 0 or window < 0 or cell < 0:
return false
_attached = {"window": window, "cell": cell, "vnum": vnum,
"count": maxi(1, count), "source": source}
_touch_index = touch_index
if touch_position.x >= 0.0 and touch_position.y >= 0.0:
_touch_position = touch_position
# Keep the instance fields that the reference mouse module exposes to the
# receiving window (anti flags, sockets, attributes, ...), while retaining
# the canonical source coordinates supplied by the caller.
@@ -70,6 +76,8 @@ func attach_money(amount: int, source := "inventory") -> bool:
return false
_attached = {"window": -1, "cell": -1, "vnum": -1, "count": amount,
"source": source, "money": true}
_touch_index = -1
_touch_position = Vector2.ZERO
if _icon:
_icon.texture = null
_icon.visible = false
@@ -85,6 +93,8 @@ func attach_money(amount: int, source := "inventory") -> bool:
func cancel() -> void:
_attached.clear()
_touch_index = -1
_touch_position = Vector2.ZERO
if _overlay:
_overlay.visible = false
if cursor and cursor.has_method("reset"):
@@ -108,7 +118,10 @@ func unregister_owner(owner: Node) -> void:
func _process(_dt: float) -> void:
if _overlay and _overlay.visible:
_overlay.global_position = get_viewport().get_mouse_position() + Vector2(12, 12)
var position := get_viewport().get_mouse_position()
if _touch_index >= 0:
position = _touch_position
_overlay.global_position = position + Vector2(12, 12)
# 清理已被窗口销毁的目标,防止拖放回调落到旧 UI。
for i in range(_targets.size() - 1, -1, -1):
var c: Control = _targets[i].get("control", null)
@@ -129,6 +142,15 @@ func _input(event: InputEvent) -> void:
if event is InputEventMouseButton and not event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
_drop_at(event.position)
get_viewport().set_input_as_handled()
return
if event is InputEventScreenDrag and event.index == _touch_index:
_touch_position = event.position
get_viewport().set_input_as_handled()
return
if event is InputEventScreenTouch and not event.pressed and event.index == _touch_index:
_touch_position = event.position
_drop_at(event.position)
get_viewport().set_input_as_handled()
func _drop_at(position: Vector2) -> void:
var payload := attached()