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
+120 -9
View File
@@ -35,6 +35,11 @@ var help_ui: Node # HelpUI(§8.3)—— 未注入时 _ensur
var toast: Callable = Callable() # 可选:func(msg: String) 显示提示
var _win: Dictionary = {}
var _mobile_mode := false
var _mobile_root: Control
var _mobile_buttons: Dictionary = {}
const MOBILE_SIZE := Vector2(700, 330)
func setup(ui_manager: CanvasLayer, m2client: Node, assets := "",
sys_opt: Node = null, game_opt: Node = null, help_win: Node = null) -> void:
@@ -51,18 +56,37 @@ func setup(ui_manager: CanvasLayer, m2client: Node, assets := "",
uiscript_dir = assets_root.path_join("uiscript")
func is_open() -> bool:
if _mobile_mode:
return _mobile_root != null and is_instance_valid(_mobile_root)
return not _win.is_empty() and is_instance_valid(_win.get("root"))
func set_mobile_mode(enabled: bool) -> void:
if enabled != _mobile_mode and is_open():
close()
_mobile_mode = enabled
if is_instance_valid(help_ui) and help_ui.has_method("set_mobile_mode"):
help_ui.set_mobile_mode(enabled)
func toggle() -> void:
if is_open(): close()
else: open()
func close() -> void:
if _mobile_mode:
var root := _mobile_root
_mobile_root = null
_mobile_buttons.clear()
if root and is_instance_valid(root) and ui:
ui.close(root)
return
if is_open():
ui.close(_win["root"])
_win = {}
func open() -> void:
if _mobile_mode:
_open_mobile()
return
if is_open():
return
var path := uiscript_dir.path_join("systemdialog.py")
@@ -75,6 +99,97 @@ func open() -> void:
_relabel()
_wire()
func _open_mobile() -> void:
if is_open():
return
_mobile_root = Control.new()
_mobile_root.name = "MobileSystemMenuWindow"
_mobile_root.size = MOBILE_SIZE
_mobile_root.set_meta("mobile_title", "系统菜单")
_mobile_root.mouse_filter = Control.MOUSE_FILTER_STOP
var panel := Panel.new()
panel.set_anchors_preset(Control.PRESET_FULL_RECT)
panel.add_theme_stylebox_override("panel", _mobile_panel_style())
_mobile_root.add_child(panel)
var hint := Label.new()
hint.text = "账户、设置和帮助"
hint.position = Vector2(22, 52)
hint.size = Vector2(640, 24)
hint.add_theme_font_size_override("font_size", 13)
hint.add_theme_color_override("font_color", Color(0.68, 0.78, 0.92))
_mobile_root.add_child(hint)
var grid := GridContainer.new()
grid.name = "MobileSystemActions"
grid.columns = 2
grid.position = Vector2(22, 82)
grid.size = Vector2(656, 174)
grid.add_theme_constant_override("h_separation", 12)
grid.add_theme_constant_override("v_separation", 8)
_mobile_root.add_child(grid)
for action in ["帮助", "商城", "系统设置", "游戏设置", "选择角色", "登出"]:
var button := Button.new()
button.name = "MobileAction_%s" % action
button.text = String(action)
button.custom_minimum_size = Vector2(322, 48)
button.add_theme_font_size_override("font_size", 14)
var selected := String(action)
button.pressed.connect(func(): _mobile_action(selected))
_mobile_buttons[selected] = button
grid.add_child(button)
var exit := Button.new()
exit.name = "MobileExitButton"
exit.text = "退出游戏"
exit.position = Vector2(22, 272)
exit.size = Vector2(154, 42)
exit.add_theme_font_size_override("font_size", 13)
exit.pressed.connect(func(): _mobile_action("退出游戏"))
_mobile_buttons["退出游戏"] = exit
_mobile_root.add_child(exit)
var cancel := Button.new()
cancel.name = "MobileCancelButton"
cancel.text = "取消"
cancel.position = Vector2(524, 272)
cancel.size = Vector2(154, 42)
cancel.add_theme_font_size_override("font_size", 13)
cancel.pressed.connect(close)
_mobile_buttons["取消"] = cancel
_mobile_root.add_child(cancel)
ui.open(_mobile_root, true)
func _mobile_action(action: String) -> void:
match action:
"帮助":
close()
open_help()
"商城":
_send_and_close("/in_game_mall")
"系统设置":
close()
if system_option_ui and system_option_ui.has_method("open"):
system_option_ui.open()
"游戏设置":
close()
if game_option_ui and game_option_ui.has_method("open"):
game_option_ui.open()
"选择角色": _send_and_close("/phase_select")
"登出": _send_and_close("/logout")
"退出游戏": get_tree().quit()
func _send_and_close(command: String) -> void:
if client and client.has_method("say"):
client.say(0, command)
close()
func _mobile_panel_style() -> StyleBoxFlat:
var style := StyleBoxFlat.new()
style.bg_color = Color(0.04, 0.065, 0.1, 0.98)
style.border_color = Color(0.52, 0.68, 0.9, 0.86)
style.set_border_width_all(1)
style.set_corner_radius_all(10)
style.shadow_color = Color(0, 0, 0, 0.45)
style.shadow_size = 12
return style
func _node(nm: String) -> Control:
if _win.is_empty():
return null
@@ -99,6 +214,8 @@ func _ensure_help() -> Node:
help_ui = HelpUI.new()
add_child(help_ui)
help_ui.setup(ui, client, assets_root)
if help_ui.has_method("set_mobile_mode"):
help_ui.set_mobile_mode(_mobile_mode)
return help_ui
func open_help() -> void:
@@ -112,9 +229,7 @@ func _wire() -> void:
close()
open_help())
_btn("mall_button", func():
if client and client.has_method("say"):
client.say(0, "/in_game_mall") # net.SendChatPacket("/in_game_mall")
close())
_send_and_close("/in_game_mall"))
_btn("system_option_button", func():
close()
if system_option_ui and system_option_ui.has_method("open"):
@@ -124,13 +239,9 @@ func _wire() -> void:
if game_option_ui and game_option_ui.has_method("open"):
game_option_ui.open())
_btn("change_button", func():
if client and client.has_method("say"):
client.say(0, "/phase_select") # net.ExitGame()
close())
_send_and_close("/phase_select"))
_btn("logout_button", func():
if client and client.has_method("say"):
client.say(0, "/logout") # net.LogOutGame()
close())
_send_and_close("/logout"))
_btn("exit_button", func(): get_tree().quit())
_btn("cancel_button", close)
var board := _node("board")