59 lines
2.2 KiB
GDScript
59 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
|
|
|
|
func configure(next_value: String) -> ABGM52TraitModule:
|
|
value = next_value
|
|
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.
|
|
var badge := NinePatchRect.new()
|
|
badge.name = "TraitBadge"
|
|
badge.texture = TRAIT_BADGE
|
|
badge.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
badge.patch_margin_left = 18
|
|
badge.patch_margin_top = 6
|
|
badge.patch_margin_right = 18
|
|
badge.patch_margin_bottom = 6
|
|
badge.axis_stretch_horizontal = NinePatchRect.AXIS_STRETCH_MODE_STRETCH
|
|
badge.axis_stretch_vertical = NinePatchRect.AXIS_STRETCH_MODE_STRETCH
|
|
badge.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
|
badge.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(badge)
|
|
var label := UIFactory.label(value, "micro", 1.0, MarketChrome.INK_SOFT)
|
|
label.name = "TraitLabel"
|
|
label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
label.offset_left = 6.0
|
|
label.offset_right = -6.0
|
|
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)
|