Files
aetherbound-guild/runtime/ui/m52/resource_status_group.gd
T

115 lines
4.8 KiB
GDScript

class_name ABGM52ResourceStatusGroup
extends Control
## Shared top-right resource cluster. It owns only presentation and emits the
## settings intent; Market remains the source of company facts and routing.
const UIFactory = preload("res://ui/shared/ui_factory.gd")
const MarketChrome = preload("res://ui/shared/market_chrome.gd")
const PageChrome = preload("res://ui/shared/page_chrome.gd")
const UIIcon = preload("res://ui/shared/ui_icon.gd")
signal settings_requested
var line_caption := "队伍"
var line_value := "0/0"
var coin_caption := "金币"
var coin_value := "0"
var text_scale := 1.0
func configure(next_line_caption: String, next_line_value: String, next_coin_caption: String, next_coin_value: String, next_text_scale := 1.0) -> ABGM52ResourceStatusGroup:
line_caption = next_line_caption
line_value = next_line_value
coin_caption = next_coin_caption
coin_value = next_coin_value
text_scale = next_text_scale
return self
func _ready() -> void:
clip_contents = true
_badge("MarketCompanyStatus", "company", line_caption, line_value, Rect2(0.00, 0.00, 0.42, 1.00))
_badge("MarketCoinStatus", "coin", coin_caption, coin_value, Rect2(0.44, 0.00, 0.40, 1.00))
# The settings control uses the same hand-drawn plate family as Readiness
# instead of a flat square with vector art.
var settings := Button.new()
settings.name = "MarketSettings"
settings.flat = true
settings.focus_mode = Control.FOCUS_ALL
settings.tooltip_text = "打开设置"
settings.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
settings.custom_minimum_size = Vector2(48, 48)
settings.set_meta("ui_factory_control", true)
settings.set_meta("ui_semantic_variant", "utility")
settings.set_meta("ui_shape", "dock_plate")
settings.set_meta("ui_family", "company")
settings.set_meta("ui_icon_kind", "settings")
_place(settings, Rect2(0.84, 0.00, 0.16, 1.00))
for style_name in ["normal", "hover", "pressed", "focus", "disabled", "hover_pressed"]:
settings.add_theme_stylebox_override(style_name, StyleBoxEmpty.new())
var settings_plate := PageChrome.new().configure("utility_plate")
settings_plate.name = "SettingsPlate"
settings_plate.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
settings_plate.mouse_filter = Control.MOUSE_FILTER_IGNORE
settings.add_child(settings_plate)
var settings_icon := UIIcon.new().configure("settings", "light")
settings_icon.name = "SettingsIcon"
settings_icon.anchor_left = 0.22
settings_icon.anchor_right = 0.78
settings_icon.anchor_top = 0.22
settings_icon.anchor_bottom = 0.78
settings_icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
settings.add_child(settings_icon)
settings.pressed.connect(func(): settings_requested.emit(), CONNECT_DEFERRED)
add_child(settings)
func _badge(node_name: String, icon_kind: String, caption: String, value: String, area: Rect2) -> void:
var badge := Control.new()
badge.name = node_name
_place(badge, area)
var chrome := PageChrome.new().configure("card")
chrome.name = "BadgeChrome"
chrome.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
chrome.mouse_filter = Control.MOUSE_FILTER_IGNORE
badge.add_child(chrome)
# Icon and label share the badge without overlapping: the icon owns the
# 0.08-0.24 strip, the label is anchored past it and centred in the rest.
# A fixed pixel inset here previously let the first glyph sit on the icon.
var icon := UIIcon.new().configure(icon_kind, "light")
icon.name = "Icon"
icon.anchor_left = 0.05 if text_scale > 1.15 else 0.08
icon.anchor_right = 0.20 if text_scale > 1.15 else 0.24
icon.anchor_top = 0.30
icon.anchor_bottom = 0.70
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
badge.add_child(icon)
var label := UIFactory.label("%s %s" % [caption, value], "label", text_scale, PageChrome.INK)
# "金币 999" measured 127px against a 107px slot at label size; the badge
# carries a compact value at micro instead.
label.add_theme_font_size_override("font_size", roundi(11.0 * text_scale))
label.name = "StatusLabel"
label.anchor_left = 0.21 if text_scale > 1.15 else 0.26
label.anchor_right = 0.98 if text_scale > 1.15 else 0.96
label.anchor_top = 0.0
label.anchor_bottom = 1.0
label.offset_left = 0.0
label.offset_right = 0.0
label.offset_top = 0.0
label.offset_bottom = 0.0
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
label.clip_text = true
label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
badge.add_child(label)
add_child(badge)
func _place(control: Control, area: Rect2) -> void:
control.anchor_left = area.position.x
control.anchor_top = area.position.y
control.anchor_right = area.end.x
control.anchor_bottom = area.end.y
control.offset_left = 0.0
control.offset_top = 0.0
control.offset_right = 0.0
control.offset_bottom = 0.0