Implement 40250 classic client port
This commit is contained in:
+135
-6
@@ -1,4 +1,4 @@
|
||||
# GuildUI (P8/M4) —— 公会窗(G 键):成员 / 技能 / 公会战 三页。
|
||||
# GuildUI (P8/M4) —— 公会窗(G 键):成员 / 技能 / 公会战 / 公告 四页。
|
||||
#
|
||||
# var gu := preload("res://ui/guild_ui.gd").new()
|
||||
# add_child(gu)
|
||||
@@ -9,12 +9,13 @@
|
||||
# 到时刷会徽图。⬜ 等级页、日志页。
|
||||
extends Node
|
||||
|
||||
const TABS := ["成员", "技能", "公会战"]
|
||||
const TABS := ["成员", "技能", "公会战", "公告"]
|
||||
# EGuildWarState (wire.h)
|
||||
const WAR_STATE_NAMES := ["无", "已宣战", "被拒", "收到宣战", "待开始", "取消", "交战中", "结束"]
|
||||
|
||||
var client: Node
|
||||
var skill_table: RefCounted # SkillTable
|
||||
var skill_table: Object # SkillTable (tests may provide a Node stub)
|
||||
var _ui_parent: Node
|
||||
# 返回一张 Image(16×12,或任意会被转换/缩放)用作会徽上传源;null = 不显示上传按钮。
|
||||
var mark_image_provider: Callable
|
||||
var _root: Control
|
||||
@@ -25,14 +26,20 @@ var _tab_btns: Array[Button] = []
|
||||
var _pages: Array[VBoxContainer] = []
|
||||
var _war_name_edit: LineEdit
|
||||
var _upload_status: Label
|
||||
var _create_dialog: ConfirmationDialog
|
||||
var _create_name_edit: LineEdit
|
||||
var _create_status: Label
|
||||
|
||||
func setup(m2client: Node, parent: Node, table: RefCounted = null) -> void:
|
||||
func setup(m2client: Node, parent: Node, table: Object = null) -> void:
|
||||
client = m2client
|
||||
skill_table = table
|
||||
_ui_parent = parent
|
||||
_build(parent)
|
||||
for sig in ["guild_changed", "guild_skill_changed", "guild_war_changed"]:
|
||||
for sig in ["guild_changed", "guild_skill_changed", "guild_war_changed", "guild_comments_changed"]:
|
||||
if client.has_signal(sig):
|
||||
client.connect(sig, refresh)
|
||||
if client.has_signal("guild_make_requested"):
|
||||
client.guild_make_requested.connect(_on_guild_make_requested)
|
||||
if client.has_signal("guild_marks_ready"):
|
||||
client.guild_marks_ready.connect(func(_n): refresh())
|
||||
if client.has_signal("guild_mark_uploaded"):
|
||||
@@ -73,6 +80,7 @@ func refresh() -> void:
|
||||
0: _fill_members()
|
||||
1: _fill_skills()
|
||||
2: _fill_war(int(g.get("id", 0)))
|
||||
3: _fill_comments()
|
||||
|
||||
func _fill_members() -> void:
|
||||
var page := _pages[0]
|
||||
@@ -109,9 +117,63 @@ func _fill_members() -> void:
|
||||
String(m.get("name", "?")), int(m.get("level", 0)),
|
||||
gname if gname != "" else str(gi),
|
||||
int(m.get("offer", 0)),
|
||||
" ★" if m.get("general", false) else ""]
|
||||
(" 在线" if m.get("online", false) else " 离线") + (" ★" if m.get("general", false) else "")]
|
||||
page.add_child(row)
|
||||
|
||||
func _fill_comments() -> void:
|
||||
var page := _pages[3]
|
||||
for c in page.get_children():
|
||||
c.queue_free()
|
||||
if not client.has_method("get_guild_comments"):
|
||||
var missing := Label.new()
|
||||
missing.text = "(当前协议没有公告接口)"
|
||||
page.add_child(missing)
|
||||
return
|
||||
var actions := HBoxContainer.new()
|
||||
actions.add_theme_constant_override("separation", 5)
|
||||
page.add_child(actions)
|
||||
var edit := LineEdit.new()
|
||||
edit.placeholder_text = "公告内容(最多 50 字)"
|
||||
edit.custom_minimum_size = Vector2(245, 26)
|
||||
actions.add_child(edit)
|
||||
var post := Button.new()
|
||||
post.text = "发布"
|
||||
post.custom_minimum_size = Vector2(52, 26)
|
||||
post.pressed.connect(func():
|
||||
var text := edit.text.strip_edges()
|
||||
if text != "" and client.has_method("guild_post_comment"):
|
||||
client.guild_post_comment(text))
|
||||
actions.add_child(post)
|
||||
var refresh_btn := Button.new()
|
||||
refresh_btn.text = "刷新"
|
||||
refresh_btn.custom_minimum_size = Vector2(52, 26)
|
||||
refresh_btn.pressed.connect(func():
|
||||
if client.has_method("guild_refresh_comments"):
|
||||
client.guild_refresh_comments())
|
||||
actions.add_child(refresh_btn)
|
||||
var comments: Array = client.get_guild_comments()
|
||||
if comments.is_empty():
|
||||
var none := Label.new()
|
||||
none.text = "(暂无公告)"
|
||||
page.add_child(none)
|
||||
return
|
||||
for item in comments:
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 6)
|
||||
page.add_child(row)
|
||||
var label := Label.new()
|
||||
label.custom_minimum_size = Vector2(286, 0)
|
||||
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
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.pressed.connect(func():
|
||||
if client.has_method("guild_delete_comment"):
|
||||
client.guild_delete_comment(int(item.get("id", 0))))
|
||||
row.add_child(delete)
|
||||
|
||||
func _guild_skill_rows() -> Array:
|
||||
# skill_table 的 GUILD 分类给 id(升序);按顺序配 levels[i]。返回 [{id, name}]。
|
||||
var out := []
|
||||
@@ -236,6 +298,73 @@ func _on_mark_uploaded(ok: bool) -> void:
|
||||
if _upload_status:
|
||||
_upload_status.text = "✔ 已上传(等服务器刷新)" if ok else "✘ 上传失败"
|
||||
|
||||
# 40250 原版在收到 GC_REQUEST_MAKE_GUILD 后弹 InputDialog,再由玩家回送
|
||||
# CG_ANSWER_MAKE_GUILD。这里保留同样的“服务端请求 -> 输入 -> 应答”边界,
|
||||
# 让名称校验发生在发包前,同时把最终权限 / 敏感词判断留给服务端。
|
||||
func _on_guild_make_requested() -> void:
|
||||
if is_instance_valid(_create_dialog):
|
||||
_create_dialog.popup_centered()
|
||||
_create_name_edit.grab_focus()
|
||||
return
|
||||
if _ui_parent == null or client == null:
|
||||
return
|
||||
_create_dialog = ConfirmationDialog.new()
|
||||
_create_dialog.name = "GuildCreateDialog"
|
||||
_create_dialog.title = "创建公会"
|
||||
_create_dialog.dialog_text = "请输入公会名称(最多 12 字)"
|
||||
_create_dialog.ok_button_text = "创建"
|
||||
_create_dialog.cancel_button_text = "取消"
|
||||
_create_name_edit = LineEdit.new()
|
||||
_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_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.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()
|
||||
_create_name_edit.grab_focus()
|
||||
|
||||
func _on_guild_create_confirmed() -> void:
|
||||
if not is_instance_valid(_create_dialog) or _create_name_edit == null:
|
||||
return
|
||||
var name := _create_name_edit.text.strip_edges()
|
||||
var error := ""
|
||||
if name.is_empty():
|
||||
error = "公会名称不能为空"
|
||||
elif name.length() > 12:
|
||||
error = "公会名称最多 12 字"
|
||||
else:
|
||||
for ch in name:
|
||||
if ch.unicode_at(0) < 32:
|
||||
error = "公会名称包含非法字符"
|
||||
break
|
||||
if error != "":
|
||||
_create_status.text = error
|
||||
_create_dialog.call_deferred("popup_centered")
|
||||
_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_name_edit.call_deferred("grab_focus")
|
||||
return
|
||||
_close_guild_create_dialog()
|
||||
|
||||
func _close_guild_create_dialog() -> void:
|
||||
var dialog := _create_dialog
|
||||
_create_dialog = null
|
||||
_create_name_edit = null
|
||||
_create_status = null
|
||||
if is_instance_valid(dialog):
|
||||
dialog.queue_free()
|
||||
|
||||
# 公会 id 变了就重新取会徽图(16x12,放大 3x 显示)。
|
||||
func _refresh_mark(guild_id: int) -> void:
|
||||
if _mark == null:
|
||||
|
||||
Reference in New Issue
Block a user