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

89 lines
3.7 KiB
GDScript

class_name ABGM52MarketHeader
extends Control
## Shared Market header module. The page owns placement and intent routing;
## this module owns the title plaque, local text slots and clipping boundary.
const UIFactory = preload("res://ui/shared/ui_factory.gd")
const MarketChrome = preload("res://ui/shared/market_chrome.gd")
const TITLE_PLAQUE = preload("res://assets/ui_m52_market/v2/title_plaque.png")
var title_text := "市场"
var subtitle_text := "准备出发"
var text_scale := 1.0
func configure(next_title: String, next_subtitle: String, next_text_scale := 1.0) -> ABGM52MarketHeader:
title_text = next_title
subtitle_text = next_subtitle
text_scale = next_text_scale
return self
func _ready() -> void:
clip_contents = true
var plaque := Control.new()
plaque.name = "MarketTitlePlaque"
plaque.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
plaque.clip_contents = true
add_child(plaque)
var chrome := NinePatchRect.new()
chrome.name = "TitleChrome"
chrome.texture = TITLE_PLAQUE
# Keep the summed margins below the smallest phone-landscape plaque height
# so the NinePatch center never collapses.
chrome.patch_margin_left = 24
chrome.patch_margin_top = 16
chrome.patch_margin_right = 24
chrome.patch_margin_bottom = 16
chrome.axis_stretch_horizontal = NinePatchRect.AXIS_STRETCH_MODE_STRETCH
chrome.axis_stretch_vertical = NinePatchRect.AXIS_STRETCH_MODE_STRETCH
chrome.draw_center = true
chrome.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
chrome.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
chrome.mouse_filter = Control.MOUSE_FILTER_IGNORE
plaque.add_child(chrome)
# Measured plaque contract: the source art is 984x560 with its parchment
# opening at rows 225-425 / cols 199-830. Through the nine-patch stretch that
# opening lands at x 0.221-0.821, y 0.421-0.706 of this module, so both text
# slots are authored inside that window instead of on the frame rails.
var title := UIFactory.label(title_text, "label", text_scale, MarketChrome.INK)
title.name = "M50MarketTitle"
title.add_theme_font_size_override("font_size", roundi(10.0 * text_scale))
title.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
title.offset_left = 8.0
title.offset_right = -8.0
# The generated plaque has a transparent crest above its parchment opening;
# keep the title below that crest so it never sits on the top rail.
_place(title, Rect2(0.26, 0.378, 0.52, 0.210))
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
title.clip_text = true
title.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
title.add_theme_color_override("font_shadow_color", Color(MarketChrome.PAPER_LIGHT, 0.92))
title.add_theme_constant_override("shadow_offset_x", 1)
title.add_theme_constant_override("shadow_offset_y", 2)
plaque.add_child(title)
var subtitle := UIFactory.label(subtitle_text, "micro", text_scale, MarketChrome.INK)
subtitle.add_theme_font_size_override("font_size", roundi(7.0 * text_scale))
subtitle.name = "M50MarketStage"
subtitle.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
_place(subtitle, Rect2(0.28, 0.557, 0.48, 0.132))
subtitle.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
subtitle.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
subtitle.clip_text = true
subtitle.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
subtitle.mouse_filter = Control.MOUSE_FILTER_IGNORE
plaque.add_child(subtitle)
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