feat: complete mobile UI implementation
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# mobile_window_host_test —— 移动窗口安全区/按钮触摸/模态返回自检。
|
||||
# godot --display-driver headless --rendering-method gl_compatibility --path project --script mobile_window_host_test.gd
|
||||
extends SceneTree
|
||||
|
||||
const UiManager = preload("res://ui/ui_manager.gd")
|
||||
const MobileWindowHost = preload("res://ui/mobile/mobile_window_host.gd")
|
||||
|
||||
var _fail := 0
|
||||
|
||||
func _ck(condition: bool, message: String) -> void:
|
||||
if not condition:
|
||||
_fail += 1
|
||||
printerr("FAIL: " + message)
|
||||
|
||||
func _init() -> void:
|
||||
await _run()
|
||||
if _fail == 0:
|
||||
print("PASS: mobile_window_host_test (safe area + touch bridge + modal back)")
|
||||
quit(0)
|
||||
else:
|
||||
printerr("%d check(s) failed" % _fail)
|
||||
quit(1)
|
||||
|
||||
func _run() -> void:
|
||||
var ui: CanvasLayer = UiManager.new()
|
||||
get_root().add_child(ui)
|
||||
await process_frame
|
||||
ui.set_mobile_mode(true)
|
||||
var win := Panel.new()
|
||||
win.name = "TouchWindow"
|
||||
win.size = Vector2(420, 280)
|
||||
var button := Button.new()
|
||||
button.text = "触摸按钮"
|
||||
button.position = Vector2(20, 60)
|
||||
button.size = Vector2(160, 52)
|
||||
win.add_child(button)
|
||||
var count := [0]
|
||||
button.pressed.connect(func(): count[0] += 1)
|
||||
ui.open(win)
|
||||
MobileWindowHost.wire_buttons(win)
|
||||
var down := InputEventScreenTouch.new()
|
||||
down.index = 11
|
||||
down.pressed = true
|
||||
down.position = Vector2(100, 100)
|
||||
button.gui_input.emit(down)
|
||||
var up := InputEventScreenTouch.new()
|
||||
up.index = 11
|
||||
up.pressed = false
|
||||
up.position = down.position
|
||||
button.gui_input.emit(up)
|
||||
_ck(count[0] == 1, "standard Button screen touch emits one press")
|
||||
|
||||
var modal := Panel.new()
|
||||
modal.name = "MobileModal"
|
||||
modal.size = Vector2(200, 100)
|
||||
modal.set_meta("mobile_modal", true)
|
||||
modal.visible = true
|
||||
win.add_child(modal)
|
||||
_ck(ui.blocks_game_input(down), "mobile modal blocks screen touch from world")
|
||||
_ck(ui.close_top(), "back closes the visible mobile modal first")
|
||||
_ck(not modal.visible and ui.top() == win, "modal closes without closing its parent window")
|
||||
_ck(ui.close_top(), "second back closes hosted feature window")
|
||||
var native_modal := ConfirmationDialog.new()
|
||||
native_modal.name = "NativeModal"
|
||||
var canceled := [0]
|
||||
native_modal.canceled.connect(func(): canceled[0] += 1)
|
||||
ui.add_child(native_modal)
|
||||
ui.track_mobile_modal(native_modal)
|
||||
native_modal.popup_centered()
|
||||
_ck(ui.blocks_game_input(down), "tracked native dialog blocks world input")
|
||||
_ck(ui.close_top(), "back closes tracked native dialog first")
|
||||
_ck(canceled[0] == 1, "tracked native dialog uses cancel action on back")
|
||||
native_modal.queue_free()
|
||||
ui.queue_free()
|
||||
Reference in New Issue
Block a user