136 lines
5.8 KiB
GDScript
136 lines
5.8 KiB
GDScript
class_name ABGM52CostModule
|
|
extends Control
|
|
|
|
const MarketChrome = preload("res://ui/shared/market_chrome.gd")
|
|
const UIFactory = preload("res://ui/shared/ui_factory.gd")
|
|
const COST_BADGE = preload("res://assets/ui_m52_components/v2_trimmed/frames/cost_badge.png")
|
|
const COIN_ICON = preload("res://assets/ui_m52_components/v2_trimmed/icons/coin.png")
|
|
|
|
var status := ""
|
|
var cost := ""
|
|
var ledger_mode := false
|
|
|
|
func configure(next_status: String, next_cost: String) -> ABGM52CostModule:
|
|
status = next_status
|
|
cost = next_cost
|
|
return self
|
|
|
|
func set_compact(compact: bool, show_status := false) -> void:
|
|
var status_label := get_node_or_null("AvailabilityLabel") as Label
|
|
var cost_label := get_node_or_null("CostLabel") as Label
|
|
var icon := get_node_or_null("CoinIcon") as Control
|
|
if status_label == null or cost_label == null:
|
|
return
|
|
ledger_mode = compact and show_status
|
|
var card_compact_mode := compact and not show_status
|
|
var plate := get_node_or_null("CostPlate") as CanvasItem
|
|
if plate != null:
|
|
plate.visible = not ledger_mode and not card_compact_mode
|
|
if ledger_mode and get_node_or_null("LedgerCostChrome") == null:
|
|
var chrome := MarketChrome.new().configure("ledger_cost")
|
|
chrome.name = "LedgerCostChrome"
|
|
chrome.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
chrome.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(chrome)
|
|
move_child(chrome, 0)
|
|
if card_compact_mode and get_node_or_null("CompactCostChrome") == null:
|
|
var chrome := MarketChrome.new().configure("compact_cost")
|
|
chrome.name = "CompactCostChrome"
|
|
chrome.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
chrome.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(chrome)
|
|
move_child(chrome, 0)
|
|
var exceptional := status.contains("不足") or status.to_lower().contains("insufficient")
|
|
status_label.visible = not compact or show_status or exceptional
|
|
if compact:
|
|
status_label.anchor_left = 0.46
|
|
status_label.anchor_right = 0.64
|
|
cost_label.anchor_left = 0.67
|
|
cost_label.offset_right = -4.0
|
|
# The compact ledger amount column is intentionally narrow. Keep the
|
|
# project's normal type family, but give this one value its measured
|
|
# inner size so “14 金币” remains a complete runtime string.
|
|
status_label.add_theme_font_size_override("font_size", 11)
|
|
cost_label.add_theme_font_size_override("font_size", 11 if show_status else 13)
|
|
if show_status:
|
|
# Detail-ledger variant: do not use the card's centered coin socket.
|
|
# Give the icon, availability and amount three non-overlapping columns.
|
|
if icon != null:
|
|
icon.anchor_left = 0.05
|
|
icon.anchor_right = 0.24
|
|
status_label.anchor_left = 0.28
|
|
status_label.anchor_right = 0.56
|
|
cost_label.anchor_left = 0.60
|
|
else:
|
|
# Card compact variant: one icon slot and one centered amount slot.
|
|
if icon != null:
|
|
icon.anchor_left = 0.10
|
|
icon.anchor_right = 0.34
|
|
status_label.visible = false
|
|
cost_label.anchor_left = 0.36
|
|
cost_label.anchor_right = 0.92
|
|
cost_label.offset_right = -2.0
|
|
cost_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
|
|
func _ready() -> void:
|
|
clip_contents = true
|
|
# This asset is authored as a left coin socket plus a stretchable paper
|
|
# strip. NinePatch preserves the socket/corners instead of shrinking the
|
|
# whole silhouette into a thin centered thumbnail on phone layouts.
|
|
var plate := NinePatchRect.new()
|
|
plate.name = "CostPlate"
|
|
plate.texture = COST_BADGE
|
|
plate.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
plate.patch_margin_left = 34
|
|
plate.patch_margin_top = 8
|
|
plate.patch_margin_right = 14
|
|
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 icon := TextureRect.new()
|
|
icon.name = "CoinIcon"
|
|
icon.texture = COIN_ICON
|
|
icon.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
# The generated plate's round socket is the coin position; keep the icon
|
|
# centered in that socket instead of adding a detached second ornament.
|
|
icon.anchor_left = 0.24
|
|
icon.anchor_right = 0.46
|
|
icon.offset_left = 0.0
|
|
icon.offset_right = 0.0
|
|
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
icon.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
|
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(icon)
|
|
var status_label := UIFactory.label(status, "micro", 1.0, MarketChrome.INK_SOFT)
|
|
status_label.name = "AvailabilityLabel"
|
|
status_label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
# The generated cost plate has a decorative circular socket in the middle.
|
|
# Keep status left of that ornament and reserve the right column for the
|
|
# amount so neither dynamic label is painted over the socket.
|
|
status_label.anchor_left = 0.48
|
|
status_label.anchor_right = 0.68
|
|
status_label.offset_left = 0.0
|
|
status_label.offset_right = 0.0
|
|
status_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
status_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
|
status_label.clip_text = true
|
|
status_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
|
status_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(status_label)
|
|
var cost_label := UIFactory.label(cost, "label", 1.0, MarketChrome.INK)
|
|
cost_label.name = "CostLabel"
|
|
cost_label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
cost_label.anchor_left = 0.71
|
|
cost_label.offset_left = 0.0
|
|
cost_label.offset_right = -6.0
|
|
cost_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
cost_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
|
cost_label.clip_text = true
|
|
cost_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
|
cost_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(cost_label)
|