feat: complete mobile UI implementation
This commit is contained in:
+133
-40
@@ -6,7 +6,7 @@
|
||||
# gu.toggle() # G 键
|
||||
#
|
||||
# `guild_changed` / `guild_skill_changed` / `guild_war_changed` 刷新,`guild_marks_ready`
|
||||
# 到时刷会徽图。⬜ 等级页、日志页。
|
||||
# 到时刷会徽图。等级/日志页仍取决于协议是否提供对应数据,不在当前四页入口内伪造。
|
||||
extends Node
|
||||
|
||||
const TABS := ["成员", "技能", "公会战", "公告"]
|
||||
@@ -19,8 +19,12 @@ var _ui_parent: Node
|
||||
# 返回一张 Image(16×12,或任意会被转换/缩放)用作会徽上传源;null = 不显示上传按钮。
|
||||
var mark_image_provider: Callable
|
||||
var _root: Control
|
||||
var _title: Label
|
||||
var _info: Label
|
||||
var _mark: TextureRect
|
||||
var _tabrow: HBoxContainer
|
||||
var _scroll: ScrollContainer
|
||||
var _stack: Control
|
||||
var _tab := 0
|
||||
var _tab_btns: Array[Button] = []
|
||||
var _pages: Array[VBoxContainer] = []
|
||||
@@ -29,6 +33,9 @@ var _upload_status: Label
|
||||
var _create_dialog: ConfirmationDialog
|
||||
var _create_name_edit: LineEdit
|
||||
var _create_status: Label
|
||||
var _mobile_mode := false
|
||||
|
||||
const MOBILE_SIZE := Vector2(700, 340)
|
||||
|
||||
func setup(m2client: Node, parent: Node, table: Object = null) -> void:
|
||||
client = m2client
|
||||
@@ -48,6 +55,19 @@ func setup(m2client: Node, parent: Node, table: Object = null) -> void:
|
||||
func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
|
||||
func set_mobile_mode(enabled: bool) -> void:
|
||||
_mobile_mode = enabled
|
||||
_apply_mobile_layout()
|
||||
if _mobile_mode and is_open() and _ui_parent and _ui_parent.has_method("reflow_mobile_window"):
|
||||
_ui_parent.reflow_mobile_window(_root)
|
||||
|
||||
func close() -> void:
|
||||
if _root:
|
||||
_root.visible = false
|
||||
|
||||
func get_mobile_window() -> Control:
|
||||
return _root
|
||||
|
||||
func toggle() -> void:
|
||||
_root.visible = not _root.visible
|
||||
if _root.visible:
|
||||
@@ -95,7 +115,7 @@ func _fill_members() -> void:
|
||||
page.add_child(row)
|
||||
var ub := Button.new()
|
||||
ub.text = "上传会徽"
|
||||
ub.custom_minimum_size = Vector2(96, 26)
|
||||
ub.custom_minimum_size = Vector2(140, 40) if _mobile_mode else Vector2(96, 26)
|
||||
ub.pressed.connect(_upload_mark)
|
||||
row.add_child(ub)
|
||||
_upload_status = Label.new()
|
||||
@@ -112,7 +132,9 @@ func _fill_members() -> void:
|
||||
if gi >= 1 and gi <= grades.size():
|
||||
gname = String(grades[gi - 1].get("name", ""))
|
||||
var row := Label.new()
|
||||
row.add_theme_font_size_override("font_size", 12)
|
||||
row.custom_minimum_size = Vector2(640, 34) if _mobile_mode else Vector2.ZERO
|
||||
row.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
row.add_theme_font_size_override("font_size", 14 if _mobile_mode else 12)
|
||||
row.text = "%s Lv.%d [%s] 贡献 %d%s" % [
|
||||
String(m.get("name", "?")), int(m.get("level", 0)),
|
||||
gname if gname != "" else str(gi),
|
||||
@@ -134,11 +156,11 @@ func _fill_comments() -> void:
|
||||
page.add_child(actions)
|
||||
var edit := LineEdit.new()
|
||||
edit.placeholder_text = "公告内容(最多 50 字)"
|
||||
edit.custom_minimum_size = Vector2(245, 26)
|
||||
edit.custom_minimum_size = Vector2(440, 40) if _mobile_mode else Vector2(245, 26)
|
||||
actions.add_child(edit)
|
||||
var post := Button.new()
|
||||
post.text = "发布"
|
||||
post.custom_minimum_size = Vector2(52, 26)
|
||||
post.custom_minimum_size = Vector2(92, 40) if _mobile_mode else Vector2(52, 26)
|
||||
post.pressed.connect(func():
|
||||
var text := edit.text.strip_edges()
|
||||
if text != "" and client.has_method("guild_post_comment"):
|
||||
@@ -146,7 +168,7 @@ func _fill_comments() -> void:
|
||||
actions.add_child(post)
|
||||
var refresh_btn := Button.new()
|
||||
refresh_btn.text = "刷新"
|
||||
refresh_btn.custom_minimum_size = Vector2(52, 26)
|
||||
refresh_btn.custom_minimum_size = Vector2(92, 40) if _mobile_mode else Vector2(52, 26)
|
||||
refresh_btn.pressed.connect(func():
|
||||
if client.has_method("guild_refresh_comments"):
|
||||
client.guild_refresh_comments())
|
||||
@@ -162,13 +184,15 @@ func _fill_comments() -> void:
|
||||
row.add_theme_constant_override("separation", 6)
|
||||
page.add_child(row)
|
||||
var label := Label.new()
|
||||
label.custom_minimum_size = Vector2(286, 0)
|
||||
label.custom_minimum_size = Vector2(560, 42) if _mobile_mode else Vector2(286, 0)
|
||||
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
label.add_theme_font_size_override("font_size", 13 if _mobile_mode else 12)
|
||||
label.text = "%s:%s" % [String(item.get("name", "?")), String(item.get("content", ""))]
|
||||
row.add_child(label)
|
||||
var delete := Button.new()
|
||||
delete.text = "删"
|
||||
delete.custom_minimum_size = Vector2(32, 24)
|
||||
delete.custom_minimum_size = Vector2(64, 40) if _mobile_mode else Vector2(32, 24)
|
||||
delete.pressed.connect(func():
|
||||
if client.has_method("guild_delete_comment"):
|
||||
client.guild_delete_comment(int(item.get("id", 0))))
|
||||
@@ -193,7 +217,9 @@ func _fill_skills() -> void:
|
||||
page.add_child(l)
|
||||
return
|
||||
var head := Label.new()
|
||||
head.add_theme_font_size_override("font_size", 12)
|
||||
head.custom_minimum_size = Vector2(640, 34) if _mobile_mode else Vector2.ZERO
|
||||
head.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
head.add_theme_font_size_override("font_size", 14 if _mobile_mode else 12)
|
||||
head.modulate = Color(0.8, 0.9, 1.0)
|
||||
head.text = "技能点 %d 公会点 %d / %d" % [
|
||||
int(sk.get("skill_point", 0)), int(sk.get("guild_point", 0)), int(sk.get("max_guild_point", 0))]
|
||||
@@ -211,14 +237,15 @@ func _fill_skills() -> void:
|
||||
row.add_theme_constant_override("separation", 8)
|
||||
page.add_child(row)
|
||||
var lbl := Label.new()
|
||||
lbl.add_theme_font_size_override("font_size", 12)
|
||||
lbl.custom_minimum_size = Vector2(240, 0)
|
||||
lbl.add_theme_font_size_override("font_size", 14 if _mobile_mode else 12)
|
||||
lbl.custom_minimum_size = Vector2(430, 40) if _mobile_mode else Vector2(240, 0)
|
||||
lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
lbl.text = "%s Lv %d" % [nm, lv]
|
||||
row.add_child(lbl)
|
||||
if sid >= 0 and lv > 0:
|
||||
var btn := Button.new()
|
||||
btn.text = "施放"
|
||||
btn.custom_minimum_size = Vector2(56, 24)
|
||||
btn.custom_minimum_size = Vector2(92, 40) if _mobile_mode else Vector2(56, 24)
|
||||
btn.pressed.connect(func(): client.use_guild_skill(sid, 0))
|
||||
row.add_child(btn)
|
||||
|
||||
@@ -230,7 +257,9 @@ func _fill_war(my_guild_id: int) -> void:
|
||||
var cur: Dictionary = client.get_guild_war()
|
||||
var st := int(cur.get("state", 0))
|
||||
var cur_lbl := Label.new()
|
||||
cur_lbl.add_theme_font_size_override("font_size", 12)
|
||||
cur_lbl.custom_minimum_size = Vector2(640, 36) if _mobile_mode else Vector2.ZERO
|
||||
cur_lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
cur_lbl.add_theme_font_size_override("font_size", 14 if _mobile_mode else 12)
|
||||
cur_lbl.modulate = Color(1.0, 0.8, 0.7)
|
||||
if st == 0:
|
||||
cur_lbl.text = "当前无公会战"
|
||||
@@ -247,11 +276,11 @@ func _fill_war(my_guild_id: int) -> void:
|
||||
page.add_child(decl)
|
||||
_war_name_edit = LineEdit.new()
|
||||
_war_name_edit.placeholder_text = "对方公会名"
|
||||
_war_name_edit.custom_minimum_size = Vector2(200, 26)
|
||||
_war_name_edit.custom_minimum_size = Vector2(440, 40) if _mobile_mode else Vector2(200, 26)
|
||||
decl.add_child(_war_name_edit)
|
||||
var db := Button.new()
|
||||
db.text = "宣战"
|
||||
db.custom_minimum_size = Vector2(60, 26)
|
||||
db.custom_minimum_size = Vector2(92, 40) if _mobile_mode else Vector2(60, 26)
|
||||
db.pressed.connect(func():
|
||||
var nm := _war_name_edit.text.strip_edges()
|
||||
if nm != "":
|
||||
@@ -259,7 +288,9 @@ func _fill_war(my_guild_id: int) -> void:
|
||||
decl.add_child(db)
|
||||
|
||||
var hdr := Label.new()
|
||||
hdr.add_theme_font_size_override("font_size", 12)
|
||||
hdr.custom_minimum_size = Vector2(640, 34) if _mobile_mode else Vector2.ZERO
|
||||
hdr.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
hdr.add_theme_font_size_override("font_size", 14 if _mobile_mode else 12)
|
||||
hdr.text = "— 进行中的公会战 —"
|
||||
page.add_child(hdr)
|
||||
var wars: Array = client.get_guild_wars()
|
||||
@@ -271,7 +302,9 @@ func _fill_war(my_guild_id: int) -> void:
|
||||
var sn := String(wpair.get("src_name", ""))
|
||||
var dn := String(wpair.get("dst_name", ""))
|
||||
var row := Label.new()
|
||||
row.add_theme_font_size_override("font_size", 12)
|
||||
row.custom_minimum_size = Vector2(640, 34) if _mobile_mode else Vector2.ZERO
|
||||
row.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
row.add_theme_font_size_override("font_size", 14 if _mobile_mode else 12)
|
||||
var mark_self := " ◀我方" if int(wpair.get("src", 0)) == my_guild_id or int(wpair.get("dst", 0)) == my_guild_id else ""
|
||||
row.text = "%s vs %s%s" % [
|
||||
sn if sn != "" else "#%d" % int(wpair.get("src", 0)),
|
||||
@@ -303,7 +336,7 @@ func _on_mark_uploaded(ok: bool) -> void:
|
||||
# 让名称校验发生在发包前,同时把最终权限 / 敏感词判断留给服务端。
|
||||
func _on_guild_make_requested() -> void:
|
||||
if is_instance_valid(_create_dialog):
|
||||
_create_dialog.popup_centered()
|
||||
_popup_create_dialog()
|
||||
_create_name_edit.grab_focus()
|
||||
return
|
||||
if _ui_parent == null or client == null:
|
||||
@@ -318,17 +351,19 @@ func _on_guild_make_requested() -> void:
|
||||
_create_name_edit.name = "GuildName"
|
||||
_create_name_edit.max_length = 12
|
||||
_create_name_edit.placeholder_text = "公会名称"
|
||||
_create_name_edit.custom_minimum_size = Vector2(250, 28)
|
||||
_create_name_edit.custom_minimum_size = Vector2(380, 44) if _mobile_mode else Vector2(250, 28)
|
||||
_create_dialog.add_child(_create_name_edit)
|
||||
_create_status = Label.new()
|
||||
_create_status.name = "Status"
|
||||
_create_status.add_theme_font_size_override("font_size", 11)
|
||||
_create_status.add_theme_font_size_override("font_size", 13 if _mobile_mode else 11)
|
||||
_create_status.modulate = Color(1.0, 0.7, 0.6)
|
||||
_create_dialog.add_child(_create_status)
|
||||
_ui_parent.add_child(_create_dialog)
|
||||
_create_dialog.confirmed.connect(_on_guild_create_confirmed)
|
||||
_create_dialog.canceled.connect(_close_guild_create_dialog)
|
||||
_create_dialog.popup_centered()
|
||||
if _ui_parent.has_method("track_mobile_modal"):
|
||||
_ui_parent.track_mobile_modal(_create_dialog)
|
||||
_popup_create_dialog()
|
||||
_create_name_edit.grab_focus()
|
||||
|
||||
func _on_guild_create_confirmed() -> void:
|
||||
@@ -347,12 +382,12 @@ func _on_guild_create_confirmed() -> void:
|
||||
break
|
||||
if error != "":
|
||||
_create_status.text = error
|
||||
_create_dialog.call_deferred("popup_centered")
|
||||
_create_dialog.call_deferred("popup_centered", Vector2i(520, 270) if _mobile_mode else Vector2i(-1, -1))
|
||||
_create_name_edit.call_deferred("grab_focus")
|
||||
return
|
||||
if not client.has_method("guild_answer_make") or not bool(client.call("guild_answer_make", name)):
|
||||
_create_status.text = "创建请求发送失败"
|
||||
_create_dialog.call_deferred("popup_centered")
|
||||
_create_dialog.call_deferred("popup_centered", Vector2i(520, 270) if _mobile_mode else Vector2i(-1, -1))
|
||||
_create_name_edit.call_deferred("grab_focus")
|
||||
return
|
||||
_close_guild_create_dialog()
|
||||
@@ -365,6 +400,17 @@ func _close_guild_create_dialog() -> void:
|
||||
if is_instance_valid(dialog):
|
||||
dialog.queue_free()
|
||||
|
||||
func _popup_create_dialog() -> void:
|
||||
if not is_instance_valid(_create_dialog):
|
||||
return
|
||||
if _mobile_mode:
|
||||
_create_dialog.set_meta("mobile_title", "创建公会")
|
||||
_create_dialog.min_size = Vector2i(520, 270)
|
||||
_create_dialog.size = Vector2i(520, 270)
|
||||
_create_dialog.popup_centered(Vector2i(520, 270))
|
||||
else:
|
||||
_create_dialog.popup_centered()
|
||||
|
||||
# 公会 id 变了就重新取会徽图(16x12,放大 3x 显示)。
|
||||
func _refresh_mark(guild_id: int) -> void:
|
||||
if _mark == null:
|
||||
@@ -396,10 +442,10 @@ 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)
|
||||
_mark = TextureRect.new()
|
||||
_mark.position = Vector2(320, 6)
|
||||
_mark.custom_minimum_size = Vector2(48, 36) # 16x12 放大 3x
|
||||
@@ -414,30 +460,77 @@ func _build(parent: Node) -> void:
|
||||
_info.modulate = Color(0.9, 0.85, 0.6)
|
||||
_root.add_child(_info)
|
||||
|
||||
var tabrow := HBoxContainer.new()
|
||||
tabrow.position = Vector2(12, 54)
|
||||
tabrow.add_theme_constant_override("separation", 4)
|
||||
_root.add_child(tabrow)
|
||||
_tabrow = HBoxContainer.new()
|
||||
_tabrow.position = Vector2(12, 54)
|
||||
_tabrow.add_theme_constant_override("separation", 4)
|
||||
_root.add_child(_tabrow)
|
||||
for i in TABS.size():
|
||||
var b := Button.new()
|
||||
b.text = TABS[i]
|
||||
b.custom_minimum_size = Vector2(84, 26)
|
||||
b.pressed.connect(_set_tab.bind(i))
|
||||
tabrow.add_child(b)
|
||||
_tabrow.add_child(b)
|
||||
_tab_btns.append(b)
|
||||
|
||||
var sc := ScrollContainer.new()
|
||||
sc.position = Vector2(12, 86)
|
||||
sc.custom_minimum_size = Vector2(356, 322)
|
||||
_root.add_child(sc)
|
||||
var stack := Control.new()
|
||||
stack.custom_minimum_size = Vector2(350, 0)
|
||||
sc.add_child(stack)
|
||||
_scroll = ScrollContainer.new()
|
||||
_scroll.position = Vector2(12, 86)
|
||||
_scroll.custom_minimum_size = Vector2(356, 322)
|
||||
_root.add_child(_scroll)
|
||||
_stack = Control.new()
|
||||
_stack.custom_minimum_size = Vector2(350, 0)
|
||||
_scroll.add_child(_stack)
|
||||
for i in TABS.size():
|
||||
var page := VBoxContainer.new()
|
||||
page.custom_minimum_size = Vector2(350, 0)
|
||||
page.add_theme_constant_override("separation", 3)
|
||||
page.visible = (i == 0)
|
||||
stack.add_child(page)
|
||||
_stack.add_child(page)
|
||||
_pages.append(page)
|
||||
_tab_btns[0].disabled = true
|
||||
_apply_mobile_layout()
|
||||
|
||||
func _apply_mobile_layout() -> void:
|
||||
if _root == null or _title == null or _tabrow == null or _scroll == null or _stack == null:
|
||||
return
|
||||
if _mobile_mode:
|
||||
_root.size = MOBILE_SIZE
|
||||
_root.position = Vector2(-MOBILE_SIZE.x * 0.5, -MOBILE_SIZE.y * 0.5)
|
||||
_title.visible = false
|
||||
_info.position = Vector2(18, 46)
|
||||
_info.size = Vector2(580, 26)
|
||||
_info.add_theme_font_size_override("font_size", 14)
|
||||
_mark.position = Vector2(624, 46)
|
||||
_mark.size = Vector2(48, 36)
|
||||
_tabrow.position = Vector2(18, 78)
|
||||
_tabrow.size = Vector2(664, 40)
|
||||
for b in _tab_btns:
|
||||
b.custom_minimum_size = Vector2(160, 38)
|
||||
b.add_theme_font_size_override("font_size", 13)
|
||||
_scroll.custom_minimum_size = Vector2(664, 194)
|
||||
_scroll.position = Vector2(18, 124)
|
||||
_scroll.size = Vector2(664, 194)
|
||||
_stack.custom_minimum_size = Vector2(648, 0)
|
||||
for page in _pages:
|
||||
page.custom_minimum_size = Vector2(648, 0)
|
||||
page.add_theme_constant_override("separation", 6)
|
||||
else:
|
||||
_root.size = Vector2(380, 420)
|
||||
_root.position = Vector2(-190, -210)
|
||||
_title.visible = true
|
||||
_title.position = Vector2(12, 8)
|
||||
_info.position = Vector2(12, 32)
|
||||
_info.remove_theme_font_size_override("font_size")
|
||||
_mark.position = Vector2(320, 6)
|
||||
_mark.size = Vector2(48, 36)
|
||||
_tabrow.position = Vector2(12, 54)
|
||||
_tabrow.size = Vector2(0, 0)
|
||||
for b in _tab_btns:
|
||||
b.custom_minimum_size = Vector2(84, 26)
|
||||
b.remove_theme_font_size_override("font_size")
|
||||
_scroll.custom_minimum_size = Vector2(356, 322)
|
||||
_scroll.position = Vector2(12, 86)
|
||||
_scroll.size = Vector2(356, 322)
|
||||
_stack.custom_minimum_size = Vector2(350, 0)
|
||||
for page in _pages:
|
||||
page.custom_minimum_size = Vector2(350, 0)
|
||||
page.add_theme_constant_override("separation", 3)
|
||||
|
||||
Reference in New Issue
Block a user