CardFrame draws the user's frame_corner/frame_border art around each card, tiling the bead strip so it fits any size; a small shader recolours the art to the theme's trim (or the card's own colour). Themes choose the border (Tarot: beaded, Felt: plain). Cards (RollTable.color) and threads (TableEntry.pipe_color, JSON "color") can have their own colour from the inspector's Colour row (presets, Theme, or any colour). tools/run_tests.sh imports first and prints at most 8 lines per failing suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
151 lines
5 KiB
GDScript
151 lines
5 KiB
GDScript
class_name ThemeDialog
|
|
extends ModalCard
|
|
## View ▾ → Theme…: pick a theme set, edit its colours, background and panel
|
|
## fills, pattern and logo, and save it as your own. "Use theme" restyles the
|
|
## app (Main reloads its UI; the open spread is kept).
|
|
|
|
var m: Main
|
|
var _sets: Array[Dictionary] = []
|
|
## The set being edited: a deep copy with every colour filled in.
|
|
var _work: Dictionary = {}
|
|
var _dirty := false
|
|
var _picker: OptionButton
|
|
var _content: VBoxContainer
|
|
var _more := false
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
super._init("Theme", 640.0)
|
|
m = p_main
|
|
var top := HBoxContainer.new()
|
|
top.add_theme_constant_override("separation", 10)
|
|
body.add_child(top)
|
|
_picker = OptionButton.new()
|
|
_picker.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
_picker.item_selected.connect(func(i: int) -> void: _load(_sets[i]))
|
|
ModalCard.style_popup(_picker.get_popup())
|
|
top.add_child(_picker)
|
|
_content = VBoxContainer.new()
|
|
_content.add_theme_constant_override("separation", 14)
|
|
body.add_child(_content)
|
|
add_button("Delete", "plain", _delete)
|
|
add_button("Save as new…", "plain", _save_as_new)
|
|
add_button("Close", "plain", close)
|
|
add_button("Use theme", "primary", _use)
|
|
_refresh_sets(str(ThemeStore.current.get("id", ThemeStore.DEFAULT_ID)))
|
|
|
|
|
|
func _refresh_sets(select_id: String) -> void:
|
|
_sets = ThemeStore.all()
|
|
_picker.clear()
|
|
var at := 0
|
|
for i in _sets.size():
|
|
var t := _sets[i]
|
|
_picker.add_item(str(t.get("name", "?")) + (" (built in)" if t.get("builtin", false) else ""))
|
|
if str(t.get("id", "")) == select_id:
|
|
at = i
|
|
_picker.select(at)
|
|
_load(_sets[at])
|
|
|
|
|
|
func _load(t: Dictionary) -> void:
|
|
_work = t.duplicate(true)
|
|
_work["colors"] = ThemeStore.resolved_colors(t)
|
|
_dirty = false
|
|
_rebuild()
|
|
|
|
|
|
func _rebuild() -> void:
|
|
for c in _content.get_children():
|
|
c.queue_free()
|
|
if bool(_work.get("builtin", false)):
|
|
_content.add_child(ModalCard.note("This theme is built in. Changes to it are saved as a new theme of your own."))
|
|
var bg := FillEditor.new(_work.get("background", {}), _color("BG"))
|
|
bg.changed.connect(func() -> void: _put("background", bg.fill))
|
|
_content.add_child(ModalCard.field("Background", bg))
|
|
var panel := FillEditor.new(_work.get("panel", {}), _color("PANEL"))
|
|
panel.changed.connect(func() -> void: _put("panel", panel.fill))
|
|
_content.add_child(ModalCard.field("Panels (top bar and tray)", panel))
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 24)
|
|
row.add_child(ModalCard.field("Background pattern", _choice(ThemeStore.PATTERNS, "pattern", "dots")))
|
|
row.add_child(ModalCard.field("Card border", _choice(ThemeStore.CARD_FRAMES, "card_frame", "plain")))
|
|
row.add_child(ModalCard.field("Logo", _choice(ThemeStore.LOGOS, "logo", "none")))
|
|
_content.add_child(row)
|
|
_content.add_child(ModalCard.section("Colours"))
|
|
var grid := GridContainer.new()
|
|
grid.columns = 2
|
|
grid.add_theme_constant_override("h_separation", 14)
|
|
grid.add_theme_constant_override("v_separation", 6)
|
|
_content.add_child(grid)
|
|
for r: Array in ThemeStore.TOKENS:
|
|
if bool(r[2]) or _more:
|
|
var tok: String = r[0]
|
|
grid.add_child(FillEditor.swatch(_color(tok), func(c: Color) -> void:
|
|
(_work["colors"] as Dictionary)[tok] = "#" + c.to_html(true)
|
|
_dirty = true))
|
|
grid.add_child(ModalCard.note(str(r[1]), Style.INK))
|
|
var more := ModalCard.make_button("Fewer colours" if _more else "More colours…")
|
|
more.size_flags_horizontal = SIZE_SHRINK_BEGIN
|
|
more.pressed.connect(func() -> void:
|
|
_more = not _more
|
|
_rebuild.call_deferred())
|
|
_content.add_child(more)
|
|
|
|
|
|
func _color(tok: String) -> Color:
|
|
return Color.from_string(str((_work["colors"] as Dictionary).get(tok, "#000")), Color.BLACK)
|
|
|
|
|
|
func _put(key: String, value: Variant) -> void:
|
|
_work[key] = value
|
|
_dirty = true
|
|
|
|
|
|
func _choice(options: Array, key: String, fallback: String) -> OptionButton:
|
|
var ob := OptionButton.new()
|
|
ModalCard.style_popup(ob.get_popup())
|
|
for i in options.size():
|
|
ob.add_item(str(options[i][1]), i)
|
|
if options[i][0] == str(_work.get(key, fallback)):
|
|
ob.select(i)
|
|
ob.item_selected.connect(func(i: int) -> void: _put(key, options[i][0]))
|
|
return ob
|
|
|
|
|
|
## Saves (a built-in becomes a new set) and restyles the app with it.
|
|
func _use() -> void:
|
|
if not _dirty:
|
|
_apply(_work)
|
|
return
|
|
if bool(_work.get("builtin", false)):
|
|
_save_as_new()
|
|
return
|
|
_work["id"] = ThemeStore.save(_work)
|
|
_apply(_work)
|
|
|
|
|
|
func _save_as_new() -> void:
|
|
var start := str(_work.get("name", "Theme")) + " (mine)"
|
|
add_child(ModalCard.ask_text("Save theme", "Name", start, "Save", func(name: String) -> void:
|
|
var t := _work.duplicate(true)
|
|
t["name"] = name
|
|
t.erase("id")
|
|
t.erase("builtin")
|
|
t["id"] = ThemeStore.save(t)
|
|
_apply(t)))
|
|
|
|
|
|
func _delete() -> void:
|
|
if bool(_work.get("builtin", false)):
|
|
m.toast("Built-in themes can't be deleted.")
|
|
return
|
|
var id := str(_work.get("id", ""))
|
|
add_child(ModalCard.confirm("Delete theme", "Delete “%s”? This can't be undone." % _work.get("name", ""), "Delete", func() -> void:
|
|
ThemeStore.delete(id)
|
|
_refresh_sets(ThemeStore.DEFAULT_ID), true))
|
|
|
|
|
|
func _apply(t: Dictionary) -> void:
|
|
close()
|
|
ThemeStore.use(m, t)
|