- battle manual actions now share one skill bar backing with accent rules and dividers; button rects, mouse_filter and callbacks unchanged - victory/dialog panel is opaque with a darker dim so battle chrome no longer shows through; action labels and 44px hit areas unchanged - idle underline and tab baselines brightened/thickened for 360px readability - UiText.node_name() falls back to localized chapter theme + node number, so full-game nodes no longer render [content.node.*] raw keys; locale keys intact Evidence: 9ba98ef-polish before/after runtime captures, strict import and focused touch/UI regressions all PASS. No merge, push or release.
546 lines
23 KiB
GDScript
546 lines
23 KiB
GDScript
class_name UiTheme
|
|
extends RefCounted
|
|
|
|
## Shared UI theme factory.
|
|
##
|
|
## Every panel, button, tab and bar is built from the same pixel frames in
|
|
## `assets/ui/`, so the HUD stays consistent and every edge stays on the pixel
|
|
## grid. Frames carry a 6px border and 6px transparent cut corners; the
|
|
## NinePatch margins must match that or the corners smear when a panel grows.
|
|
|
|
const FRAME_PATCH_MARGIN := 6
|
|
|
|
const FRAME_PANEL := "res://assets/ui/ui_frame_panel.png"
|
|
const FRAME_BUTTON := "res://assets/ui/ui_frame_button.png"
|
|
const FRAME_BUTTON_PRESSED := "res://assets/ui/ui_frame_button_pressed.png"
|
|
const FRAME_TAB := "res://assets/ui/ui_frame_tab.png"
|
|
const FRAME_TAB_SELECTED := "res://assets/ui/ui_frame_tab_selected.png"
|
|
const FRAME_TILE := "res://assets/ui/ui_frame_tile.png"
|
|
const FRAME_STAGE := "res://assets/ui/ui_frame_stage.png"
|
|
|
|
## Selected skin name ("" = default built-in frames). Set via build_theme(skin).
|
|
## All frame lookups go through skin_path() so make_panel() defaults follow too.
|
|
static var current_skin: String = ""
|
|
const SKINS := ["default", "parchment"]
|
|
|
|
|
|
## Resolve a frame path to the active skin. A path under assets/ui/ is remapped
|
|
## to assets/skins/<skin>/ when a non-default skin is selected.
|
|
static func skin_path(path: String) -> String:
|
|
if current_skin.is_empty() or current_skin == "default":
|
|
return path
|
|
if path.begins_with("res://assets/ui/"):
|
|
return path.replace("res://assets/ui/", "res://assets/skins/%s/" % current_skin)
|
|
return path
|
|
|
|
const ICON_SWORD := "res://assets/ui/ui_icon_sword.png"
|
|
const ICON_BOLT := "res://assets/ui/ui_icon_bolt.png"
|
|
const ICON_STAR := "res://assets/ui/ui_icon_star.png"
|
|
|
|
const COLOR_BG := Color("#0f192a")
|
|
const COLOR_PANEL := Color("#1c2d44")
|
|
const COLOR_BORDER := Color("#e8c978")
|
|
const COLOR_TEXT := Color("#fff4cd")
|
|
const COLOR_TEXT_DIM := Color("#c2a878")
|
|
const COLOR_MUTED := Color("#9a8464")
|
|
const COLOR_MINT := Color("#6fdab2")
|
|
const COLOR_ORANGE := Color("#e17448")
|
|
const COLOR_PURPLE := Color("#7e5d9a")
|
|
const COLOR_DANGER := Color("#d35a5a")
|
|
|
|
|
|
static func frame_style(path: String, content_margin: int = 0) -> StyleBoxTexture:
|
|
var style := StyleBoxTexture.new()
|
|
var resolved := skin_path(path)
|
|
var texture := load(resolved) as Texture2D
|
|
if texture == null and resolved != path:
|
|
texture = load(path) as Texture2D # fallback to default if skin missing a frame
|
|
if texture == null:
|
|
push_warning("UI frame texture missing: %s" % resolved)
|
|
return style
|
|
style.texture = texture
|
|
style.set_texture_margin_all(FRAME_PATCH_MARGIN)
|
|
# The 6px frame band must not add layout padding on its own: the HUD
|
|
# sizes each region from the layout contract, so the content inset is
|
|
# controlled explicitly by the caller.
|
|
style.content_margin_left = content_margin
|
|
style.content_margin_top = content_margin
|
|
style.content_margin_right = content_margin
|
|
style.content_margin_bottom = content_margin
|
|
style.axis_stretch_horizontal = StyleBoxTexture.AXIS_STRETCH_MODE_STRETCH
|
|
style.axis_stretch_vertical = StyleBoxTexture.AXIS_STRETCH_MODE_STRETCH
|
|
return style
|
|
|
|
|
|
## Tab chrome, not a card: selected gets a short brass underline and a faint
|
|
## tint; idle tabs are transparent with only a dim baseline. No closed border.
|
|
static func tab_style(selected: bool) -> StyleBoxFlat:
|
|
var s := flat_style(Color(0.10, 0.16, 0.25, 0.72) if selected else Color(0, 0, 0, 0))
|
|
s.border_color = COLOR_BORDER if selected else Color("#6d86a8")
|
|
s.set_border_width(SIDE_BOTTOM, 3 if selected else 2)
|
|
s.content_margin_left = 10
|
|
s.content_margin_right = 10
|
|
s.content_margin_top = 5
|
|
s.content_margin_bottom = 5
|
|
return s
|
|
|
|
|
|
static func flat_style(
|
|
color: Color, border_color: Color = Color(0, 0, 0, 0), border_width: int = 0
|
|
) -> StyleBoxFlat:
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = color
|
|
if border_width > 0:
|
|
style.border_color = border_color
|
|
style.set_border_width_all(border_width)
|
|
return style
|
|
|
|
|
|
## Quiet underline affordance for secondary actions. The 48px hit area stays
|
|
## untouched; what disappears is the filled rectangle that made every row look
|
|
## like an identical card. Only one hairline is visible until hover/press.
|
|
static func underline_style(active: bool, accent: Color = COLOR_BORDER) -> StyleBoxFlat:
|
|
var style := flat_style(Color(0, 0, 0, 0))
|
|
style.border_color = accent if active else Color("#8ba3c4")
|
|
style.set_border_width(SIDE_BOTTOM, 3 if active else 2)
|
|
style.content_margin_left = 12
|
|
style.content_margin_right = 12
|
|
style.content_margin_top = 6
|
|
style.content_margin_bottom = 6
|
|
return style
|
|
|
|
|
|
## A recessed skill slot: a single accent edge instead of a closed card frame.
|
|
## Used by the three battle manual actions so they read as abilities, not rows.
|
|
static func slot_style(accent: Color, tint: Color = Color(0.03, 0.07, 0.12, 0.72)) -> StyleBoxFlat:
|
|
var style := flat_style(tint)
|
|
style.border_color = accent
|
|
style.set_border_width(SIDE_LEFT, 3)
|
|
style.set_border_width(SIDE_BOTTOM, 1)
|
|
style.content_margin_left = 10
|
|
style.content_margin_right = 10
|
|
style.content_margin_top = 5
|
|
style.content_margin_bottom = 5
|
|
return style
|
|
|
|
|
|
## One station on the shared battle skill bar. No filled card: the bar's own
|
|
## backing is the surface, and a short accent rule marks the action tier.
|
|
## Callers keep their own rect and mouse_filter; this only paints the chrome.
|
|
static func skill_bar_slot_style(accent: Color) -> StyleBoxFlat:
|
|
var style := flat_style(Color(0, 0, 0, 0))
|
|
style.border_color = accent
|
|
style.set_border_width(SIDE_BOTTOM, 3)
|
|
style.content_margin_left = 10
|
|
style.content_margin_right = 10
|
|
style.content_margin_top = 6
|
|
style.content_margin_bottom = 6
|
|
return style
|
|
|
|
|
|
## Single backing strip for the three manual actions, so they read as one
|
|
## skill bar with hairlines instead of three adjacent filled boxes.
|
|
static func make_skill_bar_panel() -> PanelContainer:
|
|
var panel := PanelContainer.new()
|
|
var box := flat_style(Color(0.03, 0.07, 0.12, 0.94))
|
|
box.border_color = Color(0.55, 0.42, 0.24, 0.62)
|
|
box.set_border_width(SIDE_TOP, 2)
|
|
box.set_border_width(SIDE_BOTTOM, 1)
|
|
box.content_margin_left = 8
|
|
box.content_margin_right = 8
|
|
box.content_margin_top = 6
|
|
box.content_margin_bottom = 6
|
|
panel.add_theme_stylebox_override("panel", box)
|
|
panel.mouse_filter = Control.MOUSE_FILTER_PASS # don't block slot taps
|
|
return panel
|
|
|
|
|
|
static func build_font() -> Font:
|
|
# iOS has NO CJK system font matching the macOS names, so SystemFont rendered
|
|
# every label blank on device. Ship a real CJK font (verified on iPhone in the
|
|
# autoknights project) so text works on both macOS and iOS. preload is required
|
|
# -- a runtime load() path is not known to the export's resource scanner.
|
|
var bundled := preload("res://assets/fonts/NotoSansSC-Bold.fontdata")
|
|
return bundled as Font
|
|
|
|
|
|
static func build_theme(skin: String = "") -> Theme:
|
|
# Empty argument = keep the currently selected skin (set by a previous call
|
|
# or by set_skin). This lets the battle HUD inherit the shell's selection.
|
|
if not skin.is_empty():
|
|
current_skin = skin
|
|
var theme := Theme.new()
|
|
var font := build_font()
|
|
if font != null:
|
|
theme.default_font = font
|
|
theme.default_font_size = 13
|
|
|
|
# Visual language: panels are translucent glass with a single top hairline;
|
|
# generic buttons are quiet underline affordances. The only solid gold
|
|
# surface in the game remains the one docked primary CTA per page.
|
|
var panel_box := flat_style(Color(0.04, 0.08, 0.14, 0.90))
|
|
panel_box.border_color = Color(0.55, 0.42, 0.24, 0.55)
|
|
panel_box.set_border_width(SIDE_TOP, 2)
|
|
panel_box.content_margin_left = 10
|
|
panel_box.content_margin_right = 10
|
|
panel_box.content_margin_top = 8
|
|
panel_box.content_margin_bottom = 8
|
|
theme.set_stylebox("panel", "PanelContainer", panel_box)
|
|
theme.set_stylebox("panel", "Panel", panel_box)
|
|
|
|
var button_normal := underline_style(false)
|
|
var button_pressed := underline_style(true, COLOR_MINT)
|
|
var button_hover := underline_style(true, COLOR_MINT)
|
|
var button_disabled := underline_style(false, Color("#4b4030"))
|
|
theme.set_stylebox("normal", "Button", button_normal)
|
|
theme.set_stylebox("pressed", "Button", button_pressed)
|
|
theme.set_stylebox("hover", "Button", button_hover)
|
|
theme.set_stylebox("focus", "Button", flat_style(Color(0, 0, 0, 0)))
|
|
theme.set_stylebox("disabled", "Button", button_disabled)
|
|
theme.set_color("font_color", "Button", COLOR_TEXT)
|
|
theme.set_color("font_pressed_color", "Button", COLOR_TEXT)
|
|
theme.set_color("font_hover_color", "Button", COLOR_MINT)
|
|
theme.set_color("font_disabled_color", "Button", COLOR_TEXT_DIM)
|
|
theme.set_font_size("font_size", "Button", 13)
|
|
|
|
theme.set_stylebox("panel", "ProgressBar", flat_style(Color("#080f1b")))
|
|
theme.set_stylebox("fill", "ProgressBar", flat_style(COLOR_MINT))
|
|
theme.set_color("font_color", "ProgressBar", COLOR_TEXT)
|
|
|
|
theme.set_color("font_color", "Label", COLOR_TEXT)
|
|
return theme
|
|
|
|
|
|
## A translucent "glass" panel that lets the full-screen scene show through.
|
|
## Used for HUD regions so the artwork is not chopped into gold boxes.
|
|
static func glass_panel(alpha: float = 0.88) -> PanelContainer:
|
|
var panel := PanelContainer.new()
|
|
var box := flat_style(Color(0.04, 0.09, 0.15, alpha))
|
|
box.border_color = Color(0.55, 0.42, 0.24, 0.6)
|
|
box.set_border_width(SIDE_TOP, 2)
|
|
panel.add_theme_stylebox_override("panel", box)
|
|
panel.mouse_filter = Control.MOUSE_FILTER_PASS # don't block list scrolling
|
|
return panel
|
|
|
|
|
|
static func make_panel(_frame_path: String = FRAME_PANEL) -> PanelContainer:
|
|
var panel := PanelContainer.new()
|
|
# Translucent glass card: one hairline on top, no closed box edge. The
|
|
# frame_path argument is kept for call compatibility only.
|
|
var box := flat_style(Color(0.04, 0.08, 0.14, 0.90))
|
|
box.border_color = Color(0.55, 0.42, 0.24, 0.55)
|
|
box.set_border_width(SIDE_TOP, 2)
|
|
box.content_margin_left = 10
|
|
box.content_margin_right = 10
|
|
box.content_margin_top = 8
|
|
box.content_margin_bottom = 8
|
|
panel.add_theme_stylebox_override("panel", box)
|
|
panel.mouse_filter = Control.MOUSE_FILTER_PASS # don't block list scrolling
|
|
return panel
|
|
|
|
|
|
static func make_label(text: String, font_size: int = 13, color: Color = COLOR_TEXT) -> Label:
|
|
var label := Label.new()
|
|
label.text = text
|
|
label.add_theme_font_size_override("font_size", font_size)
|
|
label.add_theme_color_override("font_color", color)
|
|
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
return label
|
|
|
|
|
|
static func make_button(text: String, font_size: int = 13) -> Button:
|
|
var button := Button.new()
|
|
button.text = text
|
|
button.add_theme_font_size_override("font_size", font_size)
|
|
button.focus_mode = Control.FOCUS_NONE
|
|
button.custom_minimum_size = Vector2(48, 48)
|
|
# PASS lets a drag bubble to the parent ScrollContainer so lists scroll even
|
|
# when the finger starts on a button. The button still receives its own tap.
|
|
button.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
return button
|
|
|
|
|
|
## Menu actions in three visual tiers so the player can tell primary from
|
|
## secondary at a glance. `kind`: "primary" | "secondary" | "quiet".
|
|
## Uses flat, sharp-edged styles (no antialiasing) so it stays pixel-grid
|
|
## compatible, and keeps `text` set so accessibility and text-based lookups work.
|
|
static func make_menu_button(icon_path: String, text: String, kind: String = "secondary", font_size: int = 14, compact: bool = false, tight: bool = false) -> Button:
|
|
var button := Button.new()
|
|
button.text = text
|
|
button.focus_mode = Control.FOCUS_NONE
|
|
# PASS keeps taps working while letting drags bubble to a ScrollContainer.
|
|
button.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
button.add_theme_font_size_override("font_size", font_size)
|
|
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
if not icon_path.is_empty():
|
|
var tex := load(icon_path) as Texture2D
|
|
if tex != null:
|
|
button.icon = tex
|
|
button.icon_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
button.expand_icon = false
|
|
button.add_theme_constant_override("h_separation", 4 if tight else 12)
|
|
|
|
var normal: StyleBoxFlat
|
|
var pressed: StyleBoxFlat
|
|
var hover: StyleBoxFlat
|
|
var fg := COLOR_TEXT
|
|
var pad := 12
|
|
var height := 48
|
|
match kind:
|
|
"primary":
|
|
# Skill slot, not a solid card: one brass edge marks the loud action.
|
|
normal = slot_style(COLOR_BORDER, Color(0.10, 0.08, 0.03, 0.80))
|
|
pressed = slot_style(Color("#fff0b8"), Color(0.16, 0.12, 0.05, 0.86))
|
|
hover = slot_style(Color("#fff0b8"), Color(0.12, 0.10, 0.04, 0.84))
|
|
fg = Color("#fff8dc")
|
|
pad = 14
|
|
height = 58
|
|
button.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
"special":
|
|
normal = slot_style(COLOR_PURPLE, Color(0.08, 0.05, 0.13, 0.80))
|
|
pressed = slot_style(Color("#c9a6ff"), Color(0.13, 0.08, 0.20, 0.86))
|
|
hover = slot_style(Color("#c9a6ff"), Color(0.10, 0.06, 0.16, 0.84))
|
|
fg = Color("#fff3ff")
|
|
height = 58
|
|
button.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
"skill":
|
|
normal = slot_style(COLOR_MINT, Color(0.05, 0.10, 0.14, 0.80))
|
|
pressed = slot_style(Color("#b6ffe4"), Color(0.08, 0.16, 0.20, 0.86))
|
|
hover = slot_style(Color("#b6ffe4"), Color(0.06, 0.13, 0.17, 0.84))
|
|
fg = Color("#e6fff5")
|
|
height = 48
|
|
button.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
"quiet":
|
|
normal = flat_style(Color(0, 0, 0, 0))
|
|
pressed = flat_style(Color(0, 0, 0, 0))
|
|
hover = flat_style(Color(0, 0, 0, 0))
|
|
fg = COLOR_TEXT_DIM
|
|
height = 36
|
|
_: # secondary: icon + text with a single underline, no filled box
|
|
normal = underline_style(false)
|
|
pressed = underline_style(true, COLOR_MINT)
|
|
hover = underline_style(true, COLOR_MINT)
|
|
if compact:
|
|
pad = 8
|
|
height = 36
|
|
if tight:
|
|
# Icon + dynamic state text must fit three buttons in one 358px row.
|
|
pad = 4
|
|
for s in [normal, pressed, hover]:
|
|
s.content_margin_left = pad
|
|
s.content_margin_right = pad
|
|
s.content_margin_top = 5 if compact else 6
|
|
s.content_margin_bottom = 5 if compact else 6
|
|
button.add_theme_stylebox_override("normal", normal)
|
|
button.add_theme_stylebox_override("pressed", pressed)
|
|
button.add_theme_stylebox_override("hover", hover)
|
|
# Keep a disabled action legible without promoting it to a loud surface.
|
|
button.add_theme_stylebox_override("disabled", normal)
|
|
button.add_theme_stylebox_override("focus", flat_style(Color(0, 0, 0, 0)))
|
|
button.add_theme_color_override("font_color", fg)
|
|
button.add_theme_color_override("font_pressed_color", fg)
|
|
button.add_theme_color_override("font_hover_color", Color("#fff8dc"))
|
|
# Disabled actions keep a readable warm label instead of fading to mud.
|
|
button.add_theme_color_override("font_disabled_color", Color("#d8c49a"))
|
|
button.custom_minimum_size = Vector2(0, height)
|
|
return button
|
|
|
|
|
|
## Quiet, semi-transparent strip for the status header (no bright gold box).
|
|
static func make_status_strip(alpha: float = 0.72) -> PanelContainer:
|
|
var panel := PanelContainer.new()
|
|
var box := flat_style(Color(0.06, 0.11, 0.18, alpha), Color("#3b5070"), 1)
|
|
box.content_margin_left = 12
|
|
box.content_margin_right = 12
|
|
box.content_margin_top = 6
|
|
box.content_margin_bottom = 6
|
|
panel.add_theme_stylebox_override("panel", box)
|
|
panel.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
return panel
|
|
|
|
|
|
static func make_bar(color: Color, height: int = 10) -> ProgressBar:
|
|
var bar := ProgressBar.new()
|
|
bar.min_value = 0.0
|
|
bar.max_value = 1.0
|
|
bar.value = 1.0
|
|
bar.show_percentage = false
|
|
bar.custom_minimum_size = Vector2(0, height)
|
|
bar.add_theme_stylebox_override("background", flat_style(Color("#080f1b")))
|
|
bar.add_theme_stylebox_override("fill", flat_style(color))
|
|
return bar
|
|
|
|
|
|
## ---------------------------------------------------------------------------
|
|
## U1 UI rebuild additions (additive: existing callers keep their behaviour).
|
|
|
|
## The single material primary action. One per page, always docked, never in a
|
|
## ScrollContainer. It reuses the existing gold nine-slice frame so the only
|
|
## textured surface in the game is also the only loud action. 56px tall and
|
|
## >=48x48 so the thumb target holds.
|
|
static func make_primary_cta(text: String, icon_path: String = "") -> Button:
|
|
var button := Button.new()
|
|
button.text = text
|
|
button.focus_mode = Control.FOCUS_NONE
|
|
button.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
button.custom_minimum_size = Vector2(0, 56)
|
|
button.add_theme_font_size_override("font_size", 16)
|
|
if not icon_path.is_empty():
|
|
var tex := load(icon_path) as Texture2D
|
|
if tex != null:
|
|
button.icon = tex
|
|
button.expand_icon = false
|
|
button.add_theme_constant_override("h_separation", 8)
|
|
var normal := frame_style(FRAME_BUTTON, 12)
|
|
var pressed := frame_style(FRAME_BUTTON_PRESSED, 12)
|
|
var hover := frame_style(FRAME_BUTTON, 12)
|
|
var disabled := frame_style(FRAME_BUTTON, 12)
|
|
# Keep the nine-slice's STRETCH axis mode: tiling its 6px margins repeats
|
|
# the gold band across the dock and draws a grid instead of one border.
|
|
hover.modulate_color = Color("#fff0cc")
|
|
disabled.modulate_color = Color(0.62, 0.58, 0.48, 1.0)
|
|
button.add_theme_stylebox_override("normal", normal)
|
|
button.add_theme_stylebox_override("pressed", pressed)
|
|
button.add_theme_stylebox_override("hover", hover)
|
|
button.add_theme_stylebox_override("disabled", disabled)
|
|
button.add_theme_stylebox_override("focus", flat_style(Color(0, 0, 0, 0)))
|
|
button.add_theme_color_override("font_color", Color("#fff8dc"))
|
|
button.add_theme_color_override("font_pressed_color", Color("#ffffff"))
|
|
button.add_theme_color_override("font_hover_color", Color("#ffffff"))
|
|
# Disabled stays legible: the frame is dimmed, the label is not lost.
|
|
button.add_theme_color_override("font_disabled_color", Color("#e0cf9e"))
|
|
return button
|
|
|
|
|
|
## Bottom-nav / side-tab chrome. Text and hit area are unchanged; the visible
|
|
## affordance is a baseline that turns brass on the active tab.
|
|
static func make_nav_button(text: String, icon_path: String, selected: bool) -> Button:
|
|
var button := Button.new()
|
|
button.text = text
|
|
button.focus_mode = Control.FOCUS_NONE
|
|
button.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
button.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
button.add_theme_font_size_override("font_size", 12)
|
|
if not icon_path.is_empty():
|
|
var tex := load(icon_path) as Texture2D
|
|
if tex != null:
|
|
button.icon = tex
|
|
button.icon_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
button.expand_icon = false
|
|
button.add_theme_constant_override("h_separation", 6)
|
|
button.add_theme_constant_override("icon_max_width", 16)
|
|
button.add_theme_stylebox_override("normal", tab_style(selected))
|
|
button.add_theme_stylebox_override("pressed", tab_style(true))
|
|
button.add_theme_stylebox_override("hover", tab_style(true))
|
|
button.add_theme_stylebox_override("disabled", tab_style(selected))
|
|
button.add_theme_stylebox_override("focus", flat_style(Color(0, 0, 0, 0)))
|
|
button.add_theme_color_override("font_color", COLOR_TEXT if selected else COLOR_TEXT_DIM)
|
|
button.add_theme_color_override("font_pressed_color", COLOR_TEXT)
|
|
button.add_theme_color_override("font_hover_color", COLOR_TEXT)
|
|
button.add_theme_color_override("font_disabled_color", COLOR_TEXT_DIM)
|
|
button.custom_minimum_size = Vector2(0, 48)
|
|
return button
|
|
|
|
|
|
## Dialog / victory actions: only the single main action gets a warm underline;
|
|
## every other action is quiet. Text and 44px hit area are unchanged.
|
|
static func make_dialog_action(text: String, emphasized: bool) -> Button:
|
|
var button := Button.new()
|
|
button.text = text
|
|
button.focus_mode = Control.FOCUS_NONE
|
|
button.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
button.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
button.add_theme_font_size_override("font_size", 13)
|
|
var normal: StyleBoxFlat
|
|
if emphasized:
|
|
normal = flat_style(Color(0.11, 0.08, 0.03, 0.62), Color("#f0cf80"), 1)
|
|
normal.set_border_width_all(0)
|
|
normal.set_border_width(SIDE_BOTTOM, 3)
|
|
else:
|
|
normal = underline_style(false, Color("#8a6f43"))
|
|
button.add_theme_stylebox_override("normal", normal)
|
|
button.add_theme_stylebox_override("pressed", underline_style(true, COLOR_MINT))
|
|
button.add_theme_stylebox_override("hover", underline_style(true, COLOR_BORDER))
|
|
button.add_theme_stylebox_override("disabled", normal)
|
|
button.add_theme_stylebox_override("focus", flat_style(Color(0, 0, 0, 0)))
|
|
button.add_theme_color_override("font_color", Color("#ffe9ad") if emphasized else COLOR_TEXT_DIM)
|
|
button.add_theme_color_override("font_pressed_color", COLOR_TEXT)
|
|
button.add_theme_color_override("font_hover_color", COLOR_TEXT)
|
|
button.add_theme_color_override("font_disabled_color", Color("#d8c49a"))
|
|
button.custom_minimum_size = Vector2(0, 44)
|
|
return button
|
|
|
|
|
|
## A 32px pixel icon with nearest filtering, used by tokens and tiles.
|
|
static func make_icon(icon_path: String, size_px: int = 32) -> TextureRect:
|
|
var icon := TextureRect.new()
|
|
var tex := load(icon_path) as Texture2D
|
|
if tex != null:
|
|
icon.texture = tex
|
|
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
icon.custom_minimum_size = Vector2(size_px, size_px)
|
|
icon.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
|
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
return icon
|
|
|
|
|
|
## Glass chip with runtime text (state, cost, level, count). Never baked into art.
|
|
static func make_chip(text: String, color: Color = COLOR_TEXT_DIM, size_px: int = 11) -> PanelContainer:
|
|
var panel := PanelContainer.new()
|
|
var box := flat_style(Color(0.04, 0.09, 0.15, 0.88), Color("#3b5070"), 1)
|
|
box.content_margin_left = 6
|
|
box.content_margin_right = 6
|
|
box.content_margin_top = 3
|
|
box.content_margin_bottom = 3
|
|
panel.add_theme_stylebox_override("panel", box)
|
|
panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
panel.add_child(make_label(text, size_px, color))
|
|
return panel
|
|
|
|
|
|
## World node token: icon + type tint + state glyph. Hit area >=48x48.
|
|
static func make_entity_token(icon_path: String, tint: Color, state_glyph: String) -> Button:
|
|
var token := Button.new()
|
|
token.focus_mode = Control.FOCUS_NONE
|
|
token.mouse_filter = Control.MOUSE_FILTER_STOP # must receive real ScreenTouch
|
|
token.custom_minimum_size = Vector2(52, 52)
|
|
token.flat = true
|
|
token.modulate = tint
|
|
var box := flat_style(Color("#15243a"), tint, 2)
|
|
box.content_margin_left = 8
|
|
box.content_margin_right = 8
|
|
box.content_margin_top = 8
|
|
box.content_margin_bottom = 8
|
|
token.add_theme_stylebox_override("normal", box)
|
|
token.add_theme_stylebox_override("pressed", flat_style(Color("#223856"), COLOR_MINT, 2))
|
|
token.add_theme_stylebox_override("hover", box)
|
|
token.add_theme_stylebox_override("focus", flat_style(Color(0, 0, 0, 0)))
|
|
var inner := VBoxContainer.new()
|
|
inner.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
inner.add_theme_constant_override("separation", 0)
|
|
inner.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
inner.add_child(make_icon(icon_path, 28))
|
|
var glyph := make_label(state_glyph, 10, COLOR_TEXT)
|
|
glyph.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
inner.add_child(glyph)
|
|
token.add_child(inner)
|
|
return token
|
|
|
|
|
|
## Dashed pixel route segment, drawn from whole ColorRects on the logical grid.
|
|
static func make_route_segment(length_px: int) -> Control:
|
|
var host := Control.new()
|
|
host.custom_minimum_size = Vector2(8, length_px)
|
|
host.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
var y := 0
|
|
while y < length_px:
|
|
var dash := ColorRect.new()
|
|
dash.color = Color("#6d5a34")
|
|
dash.position = Vector2(2, y)
|
|
dash.size = Vector2(3, mini(6, length_px - y))
|
|
dash.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
host.add_child(dash)
|
|
y += 10
|
|
return host
|