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

63 lines
2.3 KiB
GDScript

class_name ABGM52IdentityModule
extends Control
const UIFactory = preload("res://ui/shared/ui_factory.gd")
const MarketChrome = preload("res://ui/shared/market_chrome.gd")
const NAME_PLATE = preload("res://assets/ui_m52_components/v2_trimmed/frames/name_plate.png")
var value := ""
var compact_mode := false
func configure(next_value: String) -> ABGM52IdentityModule:
value = next_value
return self
func set_compact(compact: bool) -> void:
compact_mode = compact
var plate := get_node_or_null("NamePlate") as CanvasItem
if plate != null:
plate.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
# Name plates are horizontal surfaces with fixed end ornaments. Keep the
# ornament width while stretching the center to the measured text slot.
var plate := NinePatchRect.new()
plate.name = "NamePlate"
plate.texture = NAME_PLATE
plate.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
plate.patch_margin_left = 20
plate.patch_margin_top = 8
plate.patch_margin_right = 20
plate.patch_margin_bottom = 8
plate.axis_stretch_horizontal = NinePatchRect.AXIS_STRETCH_MODE_STRETCH
plate.axis_stretch_vertical = NinePatchRect.AXIS_STRETCH_MODE_STRETCH
plate.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
plate.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(plate)
var label := UIFactory.label(value, "label", 1.0, MarketChrome.INK)
label.name = "NameLabel"
# The plate carries brass end ornaments on both sides. Anchor the text to
# the parchment opening between them so no glyph can sit under a cap.
label.anchor_left = 0.14
label.anchor_right = 0.86
label.anchor_top = 0.0
label.anchor_bottom = 1.0
label.offset_left = 0.0
label.offset_right = 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.offset_top = 3.0
label.offset_bottom = -3.0
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(label)