Implement 40250 classic client port
This commit is contained in:
+33
-1
@@ -15,12 +15,16 @@ var client: Node
|
||||
var _root: Control
|
||||
var _list: VBoxContainer
|
||||
var _name_edit: LineEdit
|
||||
var _invite_dialog: ConfirmationDialog
|
||||
var _pending_invite := ""
|
||||
|
||||
func setup(m2client: Node, parent: Node) -> void:
|
||||
client = m2client
|
||||
_build(parent)
|
||||
if client.has_signal("friends_changed"):
|
||||
client.friends_changed.connect(refresh)
|
||||
if client.has_signal("friend_invite_ask"):
|
||||
client.friend_invite_ask.connect(_on_friend_invite)
|
||||
|
||||
func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
@@ -55,9 +59,15 @@ func _row(f: Dictionary) -> Control:
|
||||
var nm := Button.new()
|
||||
nm.text = String(f.get("name", "?"))
|
||||
nm.flat = true
|
||||
nm.custom_minimum_size = Vector2(180, 0)
|
||||
nm.custom_minimum_size = Vector2(150, 0)
|
||||
nm.pressed.connect(func() -> void: whisper_to.emit(String(f.get("name", ""))))
|
||||
row.add_child(nm)
|
||||
if f.get("mobile", false):
|
||||
var mobile := Label.new()
|
||||
mobile.text = "手机"
|
||||
mobile.modulate = Color(0.45, 0.8, 1.0)
|
||||
mobile.add_theme_font_size_override("font_size", 10)
|
||||
row.add_child(mobile)
|
||||
var del := Button.new()
|
||||
del.text = "×"
|
||||
del.pressed.connect(func() -> void: client.remove_friend(String(f.get("name", ""))))
|
||||
@@ -70,6 +80,19 @@ func _on_add() -> void:
|
||||
client.add_friend(nm)
|
||||
_name_edit.clear()
|
||||
|
||||
func _on_friend_invite(name: String) -> void:
|
||||
if client == null or name.strip_edges() == "":
|
||||
return
|
||||
_pending_invite = name
|
||||
_invite_dialog.dialog_text = "接受“%s”的好友请求?" % name
|
||||
_invite_dialog.popup_centered()
|
||||
|
||||
func _answer_invite(accept: bool) -> void:
|
||||
var name := _pending_invite
|
||||
_pending_invite = ""
|
||||
if name != "" and client != null and client.has_method("friend_answer"):
|
||||
client.friend_answer(name, accept)
|
||||
|
||||
func _build(parent: Node) -> void:
|
||||
_root = Control.new()
|
||||
_root.set_anchors_preset(Control.PRESET_CENTER)
|
||||
@@ -105,3 +128,12 @@ func _build(parent: Node) -> void:
|
||||
add_btn.text = "添加"
|
||||
add_btn.pressed.connect(_on_add)
|
||||
bottom.add_child(add_btn)
|
||||
_invite_dialog = ConfirmationDialog.new()
|
||||
_invite_dialog.title = "好友请求"
|
||||
_invite_dialog.ok_button_text = "接受"
|
||||
_invite_dialog.cancel_button_text = "拒绝"
|
||||
_invite_dialog.confirmed.connect(func() -> void: _answer_invite(true))
|
||||
_invite_dialog.canceled.connect(func() -> void: _answer_invite(false))
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user