Files
mtgodot-poc/project/ui/love_ui.gd
T

68 lines
1.9 KiB
GDScript

# LoveUI — GC_LOVER_INFO / GC_LOVE_POINT_UPDATE 的常驻情侣状态。
extends Node
var client: Node
var _root: Panel
var _name: Label
var _bar: ProgressBar
var _mobile_mode := false
func setup(m2client: Node, parent: Node) -> void:
client = m2client
_build(parent)
if client.has_signal("lover_changed"):
client.lover_changed.connect(func(_lover: Dictionary): refresh())
refresh()
func refresh() -> void:
if client == null or not client.has_method("get_lover"):
return
var lover: Dictionary = client.get_lover()
var valid := bool(lover.get("valid", false))
_root.visible = valid and not _mobile_mode
if not valid:
return
_name.text = "♥ " + String(lover.get("name", ""))
_bar.value = clampi(int(lover.get("love_point", 0)), 0, 100)
_bar.tooltip_text = "爱意值:%d%%" % int(_bar.value)
func get_mobile_window() -> Control:
return _root
func set_mobile_mode(enabled: bool) -> void:
_mobile_mode = enabled
if enabled and _root:
_root.visible = false
func toggle() -> void:
if _root:
var valid := false
if client and client.has_method("get_lover"):
valid = bool(client.get_lover().get("valid", false))
_root.visible = valid and not _root.visible
func _build(parent: Node) -> void:
_root = Panel.new()
_root.name = "LoveStatus"
_root.set_anchors_preset(Control.PRESET_TOP_RIGHT)
_root.position = Vector2(-238, 28)
_root.size = Vector2(220, 48)
var bg := StyleBoxFlat.new()
bg.bg_color = Color(0.14, 0.05, 0.10, 0.88)
bg.border_color = Color(0.95, 0.35, 0.55, 0.9)
bg.set_border_width_all(1)
bg.set_corner_radius_all(5)
_root.add_theme_stylebox_override("panel", bg)
parent.add_child(_root)
_name = Label.new()
_name.position = Vector2(9, 5)
_name.add_theme_font_size_override("font_size", 13)
_name.modulate = Color(1.0, 0.72, 0.82)
_root.add_child(_name)
_bar = ProgressBar.new()
_bar.position = Vector2(9, 27)
_bar.size = Vector2(202, 13)
_bar.max_value = 100
_bar.show_percentage = false
_root.add_child(_bar)