feat: complete mobile UI implementation
This commit is contained in:
+79
-16
@@ -17,6 +17,10 @@ var _list: VBoxContainer
|
||||
var _name_edit: LineEdit
|
||||
var _invite_dialog: ConfirmationDialog
|
||||
var _pending_invite := ""
|
||||
var _mobile_mode := false
|
||||
var _title: Label
|
||||
var _bottom: HBoxContainer
|
||||
var _add_button: Button
|
||||
|
||||
func setup(m2client: Node, parent: Node) -> void:
|
||||
client = m2client
|
||||
@@ -29,6 +33,15 @@ func setup(m2client: Node, parent: Node) -> void:
|
||||
func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
|
||||
func get_mobile_window() -> Control:
|
||||
return _root
|
||||
|
||||
func set_mobile_mode(enabled: bool) -> void:
|
||||
_mobile_mode = enabled
|
||||
_apply_mobile_layout()
|
||||
if _invite_dialog and _invite_dialog.visible:
|
||||
_popup_invite_dialog()
|
||||
|
||||
func close() -> void:
|
||||
if _root:
|
||||
_root.visible = false
|
||||
@@ -57,15 +70,18 @@ func refresh() -> void:
|
||||
|
||||
func _row(f: Dictionary) -> Control:
|
||||
var row := HBoxContainer.new()
|
||||
row.custom_minimum_size = Vector2(260, 0)
|
||||
row.custom_minimum_size = Vector2(640, 46) if _mobile_mode else Vector2(260, 0)
|
||||
var dot := Label.new()
|
||||
dot.text = "●"
|
||||
dot.custom_minimum_size = Vector2(28, 42) if _mobile_mode else Vector2.ZERO
|
||||
dot.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
dot.modulate = Color(0.4, 0.9, 0.4) if f.get("online", false) else Color(0.4, 0.4, 0.4)
|
||||
row.add_child(dot)
|
||||
var nm := Button.new()
|
||||
nm.text = String(f.get("name", "?"))
|
||||
nm.flat = true
|
||||
nm.custom_minimum_size = Vector2(150, 0)
|
||||
nm.custom_minimum_size = Vector2(450, 42) if _mobile_mode else Vector2(150, 0)
|
||||
nm.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
nm.pressed.connect(func() -> void: whisper_to.emit(String(f.get("name", ""))))
|
||||
row.add_child(nm)
|
||||
if f.get("mobile", false):
|
||||
@@ -76,6 +92,7 @@ func _row(f: Dictionary) -> Control:
|
||||
row.add_child(mobile)
|
||||
var del := Button.new()
|
||||
del.text = "×"
|
||||
del.custom_minimum_size = Vector2(64, 42) if _mobile_mode else Vector2.ZERO
|
||||
del.pressed.connect(func() -> void: client.remove_friend(String(f.get("name", ""))))
|
||||
row.add_child(del)
|
||||
return row
|
||||
@@ -91,7 +108,7 @@ func _on_friend_invite(name: String) -> void:
|
||||
return
|
||||
_pending_invite = name
|
||||
_invite_dialog.dialog_text = "接受“%s”的好友请求?" % name
|
||||
_invite_dialog.popup_centered()
|
||||
_popup_invite_dialog()
|
||||
|
||||
func _answer_invite(accept: bool) -> void:
|
||||
var name := _pending_invite
|
||||
@@ -108,6 +125,7 @@ func _build(parent: Node) -> void:
|
||||
_root.size = Vector2(300, 360)
|
||||
_root.visible = false
|
||||
_root.set_meta("is_titlebar", true)
|
||||
_root.set_meta("mobile_title", "好友")
|
||||
parent.add_child(_root)
|
||||
var panel := Panel.new()
|
||||
panel.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
@@ -116,27 +134,29 @@ func _build(parent: Node) -> void:
|
||||
sb.set_corner_radius_all(4)
|
||||
panel.add_theme_stylebox_override("panel", sb)
|
||||
_root.add_child(panel)
|
||||
var title := Label.new()
|
||||
title.text = "好友"
|
||||
title.position = Vector2(12, 8)
|
||||
_root.add_child(title)
|
||||
_title = Label.new()
|
||||
_title.text = "好友"
|
||||
_title.position = Vector2(12, 8)
|
||||
_root.add_child(_title)
|
||||
_list = VBoxContainer.new()
|
||||
_list.position = Vector2(12, 34)
|
||||
_list.size = Vector2(276, 278)
|
||||
_list.add_theme_constant_override("separation", 3)
|
||||
_root.add_child(_list)
|
||||
var bottom := HBoxContainer.new()
|
||||
bottom.position = Vector2(12, 320)
|
||||
bottom.custom_minimum_size = Vector2(276, 0)
|
||||
_root.add_child(bottom)
|
||||
_bottom = HBoxContainer.new()
|
||||
_bottom.position = Vector2(12, 320)
|
||||
_bottom.custom_minimum_size = Vector2(276, 0)
|
||||
_root.add_child(_bottom)
|
||||
_name_edit = LineEdit.new()
|
||||
_name_edit.placeholder_text = "角色名"
|
||||
_name_edit.custom_minimum_size = Vector2(190, 0)
|
||||
bottom.add_child(_name_edit)
|
||||
var add_btn := Button.new()
|
||||
add_btn.text = "添加"
|
||||
add_btn.pressed.connect(_on_add)
|
||||
bottom.add_child(add_btn)
|
||||
_bottom.add_child(_name_edit)
|
||||
_add_button = Button.new()
|
||||
_add_button.text = "添加"
|
||||
_add_button.pressed.connect(_on_add)
|
||||
_bottom.add_child(_add_button)
|
||||
_invite_dialog = ConfirmationDialog.new()
|
||||
_invite_dialog.name = "FriendInviteDialog"
|
||||
_invite_dialog.title = "好友请求"
|
||||
_invite_dialog.ok_button_text = "接受"
|
||||
_invite_dialog.cancel_button_text = "拒绝"
|
||||
@@ -145,3 +165,46 @@ func _build(parent: Node) -> void:
|
||||
# Keep the dialog outside the toggleable friend panel: requests must still
|
||||
# be visible when the friend list window itself is closed.
|
||||
parent.add_child(_invite_dialog)
|
||||
if parent.has_method("track_mobile_modal"):
|
||||
parent.track_mobile_modal(_invite_dialog)
|
||||
_apply_mobile_layout()
|
||||
|
||||
func _popup_invite_dialog() -> void:
|
||||
if not is_instance_valid(_invite_dialog):
|
||||
return
|
||||
if _mobile_mode:
|
||||
# Native Window remains the owner of the confirmation signals, while its
|
||||
# mobile footprint is large enough for landscape touch targets and the
|
||||
# software keyboard-safe input area.
|
||||
_invite_dialog.set_meta("mobile_title", "好友请求")
|
||||
_invite_dialog.min_size = Vector2i(480, 220)
|
||||
_invite_dialog.size = Vector2i(480, 220)
|
||||
_invite_dialog.popup_centered(Vector2i(480, 220))
|
||||
else:
|
||||
_invite_dialog.popup_centered()
|
||||
|
||||
func _apply_mobile_layout() -> void:
|
||||
if _root == null or _title == null or _bottom == null:
|
||||
return
|
||||
if _mobile_mode:
|
||||
_root.size = Vector2(680, 344)
|
||||
_root.position = Vector2(-340, -172)
|
||||
_title.position = Vector2(18, 48)
|
||||
_title.add_theme_font_size_override("font_size", 16)
|
||||
_list.position = Vector2(18, 88)
|
||||
_list.size = Vector2(644, 190)
|
||||
_bottom.position = Vector2(18, 288)
|
||||
_bottom.custom_minimum_size = Vector2(644, 44)
|
||||
_name_edit.custom_minimum_size = Vector2(520, 44)
|
||||
_add_button.custom_minimum_size = Vector2(112, 44)
|
||||
else:
|
||||
_root.size = Vector2(300, 360)
|
||||
_root.position = Vector2(-150, -180)
|
||||
_title.position = Vector2(12, 8)
|
||||
_title.remove_theme_font_size_override("font_size")
|
||||
_list.position = Vector2(12, 34)
|
||||
_list.size = Vector2(276, 278)
|
||||
_bottom.position = Vector2(12, 320)
|
||||
_bottom.custom_minimum_size = Vector2(276, 0)
|
||||
_name_edit.custom_minimum_size = Vector2(190, 0)
|
||||
_add_button.custom_minimum_size = Vector2(0, 0)
|
||||
|
||||
Reference in New Issue
Block a user