Standard (Inter, Source Sans 3, Lora, Rokkitt), easy to read (Atkinson Hyperlegible, Lexend, Andika, OpenDyslexic) and themed title faces (Cinzel, IM Fell English, Uncial Antiqua, Orbitron, Special Elite). All OFL except Special Elite (Apache 2.0); licence files sit beside the fonts. FontCatalog builds faces, synthesising missing bold/italic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
177 lines
6.2 KiB
GDScript
177 lines
6.2 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(_font_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)
|
|
|
|
|
|
## Text and title font pickers, with a line drawn in each choice.
|
|
func _font_row() -> Control:
|
|
var box := VBoxContainer.new()
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 24)
|
|
box.add_child(row)
|
|
var sample := HBoxContainer.new()
|
|
sample.add_theme_constant_override("separation", 16)
|
|
box.add_child(sample)
|
|
var show := func() -> void:
|
|
for c in sample.get_children():
|
|
c.queue_free()
|
|
var b := FontCatalog.resolve(str(_work.get("font_body", "")), "body")
|
|
var d := FontCatalog.resolve(str(_work.get("font_display", "")), "display")
|
|
sample.add_child(Style.make_label("The Fortune Teller", FontCatalog.face(d, 700, false, false), 20, Style.INK))
|
|
sample.add_child(Style.make_label("rolls 2d6 for 7: a quiet night.", FontCatalog.face(b, 400, false, false), 15, Style.INK))
|
|
for spec: Array in [["Text font", "font_body", "body"], ["Title font", "font_display", "display"]]:
|
|
var key: String = spec[1]
|
|
var ob := _choice(FontCatalog.options(spec[2]), key, FontCatalog.resolve(str(_work.get(key, "")), spec[2]))
|
|
ob.item_selected.connect(func(_i: int) -> void: show.call())
|
|
row.add_child(ModalCard.field(spec[0], ob))
|
|
show.call()
|
|
return box
|
|
|
|
|
|
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)
|