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
+46 -3
View File
@@ -35,6 +35,10 @@ var _map_origin := Vector2.ZERO
var _map_px := Vector2.ZERO
var _world_size_m := Vector2(1, 1)
var _center_position_adjust := Vector2.ZERO
var _touches: Dictionary = {}
var _touch_dragging := false
var _touch_drag_origin := Vector2.ZERO
var _touch_map_origin := Vector2.ZERO
func setup(metin_world: Node, ui_manager: CanvasLayer, get_player: Callable,
name := "", m2client: Node = null) -> void:
@@ -64,6 +68,8 @@ func close() -> void:
if is_open() and ui:
ui.close(_win)
_win = null
_touches.clear()
_touch_dragging = false
# CPythonMiniMap::SetAtlasCenterPosition ultimately calls the atlas window's
# SetCenterPositionAdjust. Keep the same screen-space adjustment instead of
@@ -119,6 +125,7 @@ func _build_window() -> void:
_map_view.position = Vector2(14, 42)
_map_view.size = Vector2(VIEW_SIZE.x - 28, VIEW_SIZE.y - 80)
_map_view.clip_contents = true
_map_view.mouse_filter = Control.MOUSE_FILTER_STOP
_map_view.gui_input.connect(_on_map_input)
_win.add_child(_map_view)
_overlay = AtlasOverlay.new()
@@ -176,6 +183,39 @@ func _build_map() -> void:
_coord.text = "坐标:--(缺 minimap.dds,仍可查询)"
func _on_map_input(event: InputEvent) -> void:
if event is InputEventScreenTouch:
var touch := event as InputEventScreenTouch
if touch.pressed:
_touches[touch.index] = touch.position
if _touches.size() == 1:
_touch_dragging = true
_touch_drag_origin = touch.position
_touch_map_origin = _map.position
else:
# A second finger is a gesture boundary. Do not continue the
# first finger's drag while pinch/scroll state is ambiguous.
_touch_dragging = false
else:
_touches.erase(touch.index)
if _touches.is_empty():
_touch_dragging = false
elif _touches.size() == 1:
# Re-arm panning for the remaining finger without jumping the map.
var remaining := int(_touches.keys()[0])
_touch_dragging = true
_touch_drag_origin = _touches[remaining]
_touch_map_origin = _map.position
_map_view.accept_event()
return
if event is InputEventScreenDrag:
var drag := event as InputEventScreenDrag
if _touches.has(drag.index):
_touches[drag.index] = drag.position
if _touches.size() == 1 and _touch_dragging and _touches.has(drag.index):
_map.position = _touch_map_origin + drag.position - _touch_drag_origin
_overlay.position = _map.position
_map_view.accept_event()
return
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
_dragging = event.pressed
if _dragging:
@@ -187,11 +227,14 @@ func _on_map_input(event: InputEvent) -> void:
_overlay.position = _map.position
_map_view.accept_event()
elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
_map_origin = (_map_view.size - _map.size) * 0.5
_map.position = _map_origin
_overlay.position = _map.position
_recenter_map()
_map_view.accept_event()
func _recenter_map() -> void:
_map_origin = (_map_view.size - _map.size) * 0.5 + _center_position_adjust
_map.position = _map_origin
_overlay.position = _map.position
func _process(_dt: float) -> void:
if is_open():
_update_player_marker()