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

57 lines
2.2 KiB
GDScript

class_name ABGM52TraitModule
extends Control
const MarketChrome = preload("res://ui/shared/market_chrome.gd")
const UIFactory = preload("res://ui/shared/ui_factory.gd")
const TRAIT_BADGE = preload("res://assets/ui_m52_components/v2_trimmed/frames/trait_badge.png")
var value := ""
var compact_mode := false
var text_scale := 1.0
func configure(next_value: String, next_text_scale := 1.0) -> ABGM52TraitModule:
value = next_value
text_scale = next_text_scale
return self
func set_compact(compact: bool) -> void:
compact_mode = compact
var badge := get_node_or_null("TraitBadge") as CanvasItem
if badge != null:
badge.visible = not compact
if compact and get_node_or_null("CompactChrome") == null:
var chrome := MarketChrome.new().configure("compact_label")
chrome.name = "CompactChrome"
chrome.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
chrome.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(chrome)
move_child(chrome, 0)
func _ready() -> void:
clip_contents = true
# The ribbon has a measured center strip and decorative end caps. A
# NinePatch keeps those caps readable when the text slot changes width.
# Proportional chip chrome: the caps scale with the module, so the text
# strip is a fixed fraction and no cap can cover a glyph at any type size.
var badge := MarketChrome.new().configure("trait_chip")
badge.name = "TraitBadge"
badge.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
badge.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(badge)
var label := UIFactory.label(value, "micro", text_scale, MarketChrome.INK)
label.name = "TraitLabel"
label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
# Keep the label inside the badge's measured centre strip: the ribbon's end
# caps occupy the patch margins, so the text must not run under them.
label.anchor_left = 0.15
label.anchor_right = 0.85
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
label.clip_text = true
label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
label.offset_top = 3.0
label.offset_bottom = -3.0
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(label)