diff --git a/assets/art/fortune_teller.png b/assets/art/fortune_teller.png new file mode 100644 index 0000000..3f1a6ca Binary files /dev/null and b/assets/art/fortune_teller.png differ diff --git a/assets/art/fortune_teller.png.import b/assets/art/fortune_teller.png.import new file mode 100644 index 0000000..0e00d6f --- /dev/null +++ b/assets/art/fortune_teller.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://jank70o552kk" +path="res://.godot/imported/fortune_teller.png-51e43d125e970eb5dc5acd92909929b2.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/art/fortune_teller.png" +dest_files=["res://.godot/imported/fortune_teller.png-51e43d125e970eb5dc5acd92909929b2.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/art/fortune_teller.svg b/assets/art/fortune_teller.svg new file mode 100644 index 0000000..4e4beec --- /dev/null +++ b/assets/art/fortune_teller.svg @@ -0,0 +1,625 @@ + + + + + + + + + diff --git a/assets/art/fortune_teller.svg.import b/assets/art/fortune_teller.svg.import new file mode 100644 index 0000000..5ebe6fa --- /dev/null +++ b/assets/art/fortune_teller.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dkgqjm6y55p6k" +path="res://.godot/imported/fortune_teller.svg-26b2d1470e7041a80e0cff58e1a65231.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/art/fortune_teller.svg" +dest_files=["res://.godot/imported/fortune_teller.svg-26b2d1470e7041a80e0cff58e1a65231.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=0.25 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/assets/ui/frame_border.svg b/assets/ui/frame_border.svg new file mode 100644 index 0000000..31ad209 --- /dev/null +++ b/assets/ui/frame_border.svg @@ -0,0 +1,6 @@ + + + + + diff --git a/assets/ui/frame_border.svg.import b/assets/ui/frame_border.svg.import new file mode 100644 index 0000000..0982d4d --- /dev/null +++ b/assets/ui/frame_border.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d3rhv7shtr7bp" +path="res://.godot/imported/frame_border.svg-528d2c5d86ed50a2330d153461182811.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/frame_border.svg" +dest_files=["res://.godot/imported/frame_border.svg-528d2c5d86ed50a2330d153461182811.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=0.5 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/assets/ui/frame_corner.svg b/assets/ui/frame_corner.svg new file mode 100644 index 0000000..a66b4a4 --- /dev/null +++ b/assets/ui/frame_corner.svg @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/assets/ui/frame_corner.svg.import b/assets/ui/frame_corner.svg.import new file mode 100644 index 0000000..121d869 --- /dev/null +++ b/assets/ui/frame_corner.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cw0ppr3c0q6o2" +path="res://.godot/imported/frame_corner.svg-199c8ced7321cc056b8a09ed1de82e79.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/frame_corner.svg" +dest_files=["res://.godot/imported/frame_corner.svg-199c8ced7321cc056b8a09ed1de82e79.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=0.5 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/core/roll_table.gd b/core/roll_table.gd index 78ef5f9..4924720 100644 --- a/core/roll_table.gd +++ b/core/roll_table.gd @@ -49,6 +49,8 @@ var collapsed: bool = false ## Longer description (may contain BBCode). var details: String = "" var tags: Array[String] = [] +## The card's own colour ("#hex") for its frame and header; "" = the theme's. +var color: String = "" ## Dice expression for ranged tables, e.g. "1d100", "2d6", "1d8+2", or any ## expression such as "2d6 + dm(@end)". var dice: String = DEFAULT_DICE @@ -421,6 +423,8 @@ func to_dict() -> Dictionary: d["details"] = details if not tags.is_empty(): d["tags"] = tags.duplicate() + if color != "": + d["color"] = color if is_ranged(): d["dice"] = dice if has_mod(): @@ -485,6 +489,7 @@ static func from_dict(d: Dictionary) -> RollTable: t.details = str(d.get("details", "")) for tag: Variant in d.get("tags", []): t.tags.append(str(tag)) + t.color = str(d.get("color", "")) if d.has("dice"): t.dice = str(d["dice"]) elif int(d.get("die", 0)) > 1: diff --git a/core/table_entry.gd b/core/table_entry.gd index d0d0a95..d660fb0 100644 --- a/core/table_entry.gd +++ b/core/table_entry.gd @@ -34,6 +34,8 @@ var pipe_otherwise: Dictionary = {} ## card's inputs (docs/PLAIN.md §4.2), worked out in the entry's snapshot. ## Missing = none. var pipe_with: Dictionary = {} +## target table id -> the thread's own colour "#hex" (missing = the theme's). +var pipe_color: Dictionary = {} ## Router cards: this case's condition. "" is the Otherwise case (always ## matches). Ignored on other kinds. var when: String = "" @@ -201,6 +203,7 @@ func remove_pipe(target: String) -> void: pipe_when.erase(target) pipe_otherwise.erase(target) pipe_with.erase(target) + pipe_color.erase(target) func to_dict() -> Dictionary: @@ -224,7 +227,8 @@ func to_dict() -> Dictionary: var w := when_for(p) var other := is_otherwise(p) var wv: Variant = pipe_with.get(p) - if expr == "" and n == 1 and s == "" and w == "" and not other and wv == null: + var col := str(pipe_color.get(p, "")) + if expr == "" and n == 1 and s == "" and w == "" and not other and wv == null and col == "": list.append(p) else: var po := {"table": p} @@ -240,6 +244,8 @@ func to_dict() -> Dictionary: po["otherwise"] = true if wv is Dictionary and not (wv as Dictionary).is_empty(): po["with"] = (wv as Dictionary).duplicate() + if col != "": + po["color"] = col list.append(po) d["pipes"] = list if has_range: @@ -264,6 +270,8 @@ static func from_dict(d: Dictionary) -> TableEntry: e.set_pipe_otherwise(target, bool(p.get("otherwise", false))) if p.get("with") is Dictionary: e.set_pipe_with(target, p["with"]) + if str(p.get("color", "")) != "": + e.pipe_color[target] = str(p["color"]) elif str(p) != "": e.add_pipe(str(p)) var r: Variant = d.get("range") diff --git a/tests/test_theme.gd b/tests/test_theme.gd index 0adeeba..e302a33 100644 --- a/tests/test_theme.gd +++ b/tests/test_theme.gd @@ -19,6 +19,7 @@ func _init() -> void: _test_apply() _test_save_delete() await _test_dialog() + _test_own_colours() print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) quit(1 if _failures else 0) @@ -69,6 +70,26 @@ func _test_dialog() -> void: await _frames() +func _test_own_colours() -> void: + var t := RollTable.new() + t.id = "a" + t.color = "#2f8a4f" + var e := TableEntry.new("e1", "x") + e.add_pipe("b") + e.pipe_color["b"] = "#c04a86" + t.entries.append(e) + var back := RollTable.from_dict(t.to_dict()) + _check(back.color == "#2f8a4f", "a card's colour survives saving") + _check(back.entries[0].pipe_color.get("b") == "#c04a86", "a thread's colour survives saving") + back.entries[0].remove_pipe("b") + _check(back.entries[0].pipe_color.is_empty(), "deleting a thread drops its colour") + var card := main.card_for(main.data.tables[0].id) + if card and card.frame: + main.data.get_table(card.table.id).color = "#b8382c" + card.rebuild() + _check(card.frame.material == CardFrame.material_for(Color("#b8382c")), "the frame takes the card's colour") + + func _frames(n: int = 2) -> void: for i in n: await process_frame diff --git a/tests/test_theme.gd.uid b/tests/test_theme.gd.uid new file mode 100644 index 0000000..0929088 --- /dev/null +++ b/tests/test_theme.gd.uid @@ -0,0 +1 @@ +uid://nfq0rycxflhw diff --git a/tools/run_tests.sh b/tools/run_tests.sh index 3ec987c..8d53aa1 100755 --- a/tools/run_tests.sh +++ b/tools/run_tests.sh @@ -3,13 +3,15 @@ # A suite fails if it doesn't print "PASS: 0 failure(s)" or if its output has # a SCRIPT ERROR (a crashed test function can still print PASS). # Usage: tools/run_tests.sh [name-filter] e.g. tools/run_tests.sh inspector -# Full output of failing suites is printed; passing output is discarded. +# Failing suites print their first 8 error lines; passing output is discarded. set -u cd "$(dirname "$0")/.." GODOT="${GODOT:-$HOME/apps/Godot_v4.7.2-stable_linux.x86_64}" OUT="$(mktemp -d)" trap 'rm -rf "$OUT"' EXIT suites=(tests/test_*${1:-}*.gd) +# Register any new class_name scripts first (cheap when nothing changed). +"$GODOT" --headless --path . --import >/dev/null 2>&1 for t in "${suites[@]}"; do n="$(basename "$t" .gd)" ( timeout 300 "$GODOT" --headless --path . -s "res://$t" -- --sample >"$OUT/$n.log" 2>&1 ) & @@ -24,7 +26,7 @@ for t in "${suites[@]}"; do echo "ok $n" else echo "FAIL $n" - grep -E "FAIL|SCRIPT ERROR|ERROR|at: " "$log" | head -40 + grep -E "FAIL|SCRIPT ERROR|ERROR" "$log" | head -8 fail=1 fi done diff --git a/ui/builtin_themes.gd b/ui/builtin_themes.gd index c19840a..9ef24fe 100644 --- a/ui/builtin_themes.gd +++ b/ui/builtin_themes.gd @@ -6,11 +6,12 @@ extends RefCounted ## ## Set keys: id, name, colors {TOKEN: "#hex"}, background and panel fills ## ({kind: "solid"|"linear"|"radial", colors: [...], angle}), pattern -## ("none"|"dots"|"stars"), logo, font_body, font_display. +## ("none"|"dots"|"stars"), card_frame ("ornate"|"plain"), logo, font_body, +## font_display. const TAROT := { "id": "tarot", "name": "Tarot", "builtin": true, - "pattern": "stars", "logo": "fortune_teller", + "pattern": "stars", "logo": "fortune_teller", "card_frame": "ornate", "font_body": "atkinson", "font_display": "rokkitt", # A jewel-tone spread cloth with a soft shine up and to the left. "background": {"kind": "radial", "colors": ["#4b1470", "#2c0744", "#1f0431"], "center": [0.32, 0.28]}, @@ -33,7 +34,7 @@ const TAROT := { ## The original green felt and copper look, kept as a second set. const FELT := { "id": "felt", "name": "Felt", "builtin": true, - "pattern": "dots", "logo": "none", + "pattern": "dots", "logo": "none", "card_frame": "plain", "font_body": "atkinson", "font_display": "rokkitt", "background": {"kind": "radial", "colors": ["#2a5c47", "#1f4a39"], "center": [0.35, 0.3]}, "panel": {"kind": "solid", "colors": ["#12301f"]}, diff --git a/ui/card_frame.gd b/ui/card_frame.gd new file mode 100644 index 0000000..cc8359f --- /dev/null +++ b/ui/card_frame.gd @@ -0,0 +1,111 @@ +class_name CardFrame +extends Control +## The ornamental border around a card: four corner pieces (frame_corner.svg, +## mirrored) joined by beaded strips (frame_border.svg, tiled along each edge so +## it scales to any card size). A small shader recolours the art: its amber +## becomes the trim colour (the card's own colour, else the theme's TRIM) and +## its near-black strip becomes BG_DEEP. +## +## It's the card's first child and draws around the card's whole rectangle, +## a little outside it (OUTSET), whatever box the container gives it. + +const CORNER: Texture2D = preload("res://assets/ui/frame_corner.svg") +const BORDER: Texture2D = preload("res://assets/ui/frame_border.svg") +## Drawn size relative to the art's source units (corner art is 200 × 194). +const S := 0.28 +## How far the frame reaches outside the card. +const OUTSET := 9.0 +## Extra padding inside a framed card, so the corners clear its contents. +const PAD := 5.0 +# Source-unit geometry (see the comments in the SVGs). +const CORNER_W := 200.0 +const CORNER_H := 194.0 +const TOP_MID := 33.0 ## The top tab's centre line (y) in the corner art. +const SIDE_MID := 29.0 ## The side tab's centre line (x) in the corner art. +const TILE_W := 44.0 +const TILE_H := 50.0 +const TILE_MID := 22.0 + +const SHADER := "shader_type canvas_item; +uniform vec4 dark : source_color; +uniform vec4 trim : source_color; +void fragment() { + vec4 t = texture(TEXTURE, UV); + float l = dot(t.rgb, vec3(0.299, 0.587, 0.114)); + COLOR = vec4(mix(dark.rgb, trim.rgb, smoothstep(0.05, 0.30, l)), t.a * COLOR.a); +}" + +static var _shader: Shader +static var _materials: Dictionary = {} + + +func _init() -> void: + mouse_filter = MOUSE_FILTER_IGNORE + texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS + set_trim(Color(0, 0, 0, 0)) + + +## Recolours the frame; a transparent colour means the theme's TRIM. +func set_trim(c: Color) -> void: + material = material_for(Style.TRIM if c.a == 0.0 else c) + queue_redraw() + + +## Shared materials, one per trim colour. +static func material_for(trim: Color) -> ShaderMaterial: + var key := trim.to_html() + Style.BG_DEEP.to_html() + if not _materials.has(key): + if _shader == null: + _shader = Shader.new() + _shader.code = SHADER + var mat := ShaderMaterial.new() + mat.shader = _shader + mat.set_shader_parameter("dark", Style.BG_DEEP) + mat.set_shader_parameter("trim", trim) + _materials[key] = mat + return _materials[key] + + +func _draw() -> void: + var host := get_parent() as Control + if host == null: + return + # Work in the host card's coordinates, grown by OUTSET. + var r := Rect2(-position, host.size).grow(OUTSET) + var cw := CORNER_W * S + var ch := CORNER_H * S + var corner := Vector2(cw, ch) + # Corners: top-left as drawn, the others mirrored. + for flip: Vector2 in [Vector2(1, 1), Vector2(-1, 1), Vector2(1, -1), Vector2(-1, -1)]: + var at := Vector2(r.position.x if flip.x > 0 else r.end.x, r.position.y if flip.y > 0 else r.end.y) + draw_set_transform(at, 0.0, flip) + draw_texture_rect(CORNER, Rect2(Vector2.ZERO, corner), false) + # Sides: vertical strips between the corners' side tabs. + var side_len := r.size.y - 2.0 * ch + for flip: float in [1.0, -1.0]: + var x := (r.position.x if flip > 0 else r.end.x) + flip * SIDE_MID * S + _strip(Vector2(x, r.position.y + ch), side_len, 0.0) + # Top and bottom: the same strip turned on its side. + var top_len := r.size.x - 2.0 * cw + for flip: float in [1.0, -1.0]: + var y := (r.position.y if flip > 0 else r.end.y) + flip * TOP_MID * S + _strip(Vector2(r.position.x + cw, y), top_len, -PI / 2.0) + draw_set_transform(Vector2.ZERO) + + +## Tiles the bead strip along `length` from `start` (the strip's centre line), +## downwards (angle 0) or rightwards (angle −π/2). Tiles stretch slightly so a +## whole number of beads fits. +func _strip(start: Vector2, length: float, angle: float) -> void: + if length <= 1.0: + return + var n := maxi(1, roundi(length / (TILE_H * S))) + var tile := length / n + var w := TILE_W * S + if angle == 0.0: + draw_set_transform(start - Vector2(TILE_MID * S, 0), 0.0, Vector2.ONE) + else: + # Rotating by −90° maps the tile's +y (its length) onto +x. + draw_set_transform(start + Vector2(0, TILE_MID * S), angle, Vector2.ONE) + for i in n: + draw_texture_rect(BORDER, Rect2(0, i * tile, w, tile), false) diff --git a/ui/card_frame.gd.uid b/ui/card_frame.gd.uid new file mode 100644 index 0000000..455db16 --- /dev/null +++ b/ui/card_frame.gd.uid @@ -0,0 +1 @@ +uid://esygkdvh7s2f diff --git a/ui/color_choice.gd b/ui/color_choice.gd new file mode 100644 index 0000000..af97c22 --- /dev/null +++ b/ui/color_choice.gd @@ -0,0 +1,65 @@ +class_name ColorChoice +extends HFlowContainer +## A card's or thread's own colour: "Theme" (none), a row of presets, or any +## colour from the custom picker. Calls on_change with "#hex", or "" for Theme. +## PRESETS is shared with the right-click menus. + +const PRESETS := [ + ["Red", "#b8382c"], ["Orange", "#c8691e"], ["Gold", "#c99a1c"], ["Green", "#2f8a4f"], + ["Teal", "#13877f"], ["Blue", "#2f5d9a"], ["Violet", "#7a3fa8"], ["Pink", "#c04a86"], + ["Grey", "#6b6670"], +] + +var _on_change: Callable +var _value := "" + + +func _init(value: String, on_change: Callable) -> void: + _value = value + _on_change = on_change + add_theme_constant_override("h_separation", 4) + add_theme_constant_override("v_separation", 4) + _build() + + +func _build() -> void: + for c in get_children(): + c.queue_free() + var theme_b := _swatch(Color(0, 0, 0, 0), "Theme colour", _value == "") + theme_b.text = "Theme" + theme_b.custom_minimum_size.x = 0 + theme_b.pressed.connect(_pick.bind("")) + add_child(theme_b) + var matched := _value == "" + for p: Array in PRESETS: + var on := _value.to_lower() == str(p[1]) + matched = matched or on + var b := _swatch(Color(str(p[1])), str(p[0]), on) + b.pressed.connect(_pick.bind(str(p[1]))) + add_child(b) + var custom := FillEditor.swatch(Color(_value) if _value != "" and not matched else Style.TRIM, func(c: Color) -> void: + _value = "#" + c.to_html(false) + _on_change.call(_value)) + custom.edit_alpha = false + custom.custom_minimum_size = Vector2(30, 24) + custom.tooltip_text = "Any colour…" + add_child(custom) + + +func _pick(hex: String) -> void: + _value = hex + _on_change.call(hex) + _build.call_deferred() + + +static func _swatch(c: Color, tip: String, on: bool) -> Button: + var b := Button.new() + b.tooltip_text = tip + b.custom_minimum_size = Vector2(24, 24) + b.focus_mode = Control.FOCUS_NONE + var fill := c if c.a > 0.0 else Style.CARD_SOFT + var normal := Style.bordered(Style.box(fill, 12, [8, 2, 8, 2]), 3 if on else 1, Style.INK if on else Style.DASH) + var hover := Style.bordered(Style.box(fill.lightened(0.12), 12, [8, 2, 8, 2]), 3 if on else 1, Style.INK) + Style.skin_button(b, normal, hover, hover, Style.INK, Style.INK) + b.add_theme_font_size_override("font_size", 13) + return b diff --git a/ui/color_choice.gd.uid b/ui/color_choice.gd.uid new file mode 100644 index 0000000..2b0a050 --- /dev/null +++ b/ui/color_choice.gd.uid @@ -0,0 +1 @@ +uid://cng60e0d6tuf0 diff --git a/ui/inspector.gd b/ui/inspector.gd index 8a01afd..af47392 100644 --- a/ui/inspector.gd +++ b/ui/inspector.gd @@ -328,6 +328,18 @@ func set_pipe_save(to: String, s: String) -> void: wrote(selected_table()) +func set_pipe_color(hex: String, to: String) -> void: + var e := _pipe_entry() + if e == null: + return + if hex == "": + e.pipe_color.erase(to) + else: + e.pipe_color[to] = hex + wrote(selected_table()) + main.board.geometry_rev += 1 + + func remove_pipe(to: String) -> void: var t := selected_table() var e := selected_entry() @@ -518,6 +530,7 @@ func _pipe_section(t: RollTable, e: TableEntry, to: String) -> void: back.pressed.connect(func() -> void: select({"kind": "result", "tid": t.id, "eid": e.id})) _content.add_child(back) _content.add_child(_pipe_box(t, e, to)) + _content.add_child(InspectorKit.field("Thread colour", ColorChoice.new(str(e.pipe_color.get(to, "")), set_pipe_color.bind(to)))) _lint_lines(t, e) diff --git a/ui/inspector_card.gd b/ui/inspector_card.gd index 4ed6f2a..5034533 100644 --- a/ui/inspector_card.gd +++ b/ui/inspector_card.gd @@ -50,6 +50,9 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void: tags.text_changed.connect(func(s: String) -> void: insp.apply_settings({"tags": s})) insp.fields["tags"] = tags box.add_child(InspectorKit.field("Tags", tags)) + box.add_child(InspectorKit.field("Colour", ColorChoice.new(t.color, func(hex: String) -> void: + t.color = hex + insp.wrote(t)))) if t.kind != RollTable.KIND_VARIABLE: box.add_child(_inputs(insp, t)) diff --git a/ui/pipe_layer.gd b/ui/pipe_layer.gd index c6a00ac..829e113 100644 --- a/ui/pipe_layer.gd +++ b/ui/pipe_layer.gd @@ -105,13 +105,16 @@ func _coarse(rid: RID, pts: PackedVector2Array, color: Color, width: float) -> v ## An unlit pipe (as _draw_pipe draws it), in its own canvas item. -func _batch_pipe(pts: PackedVector2Array, hovered: bool) -> void: +## `own` is the thread's own colour ("" = the theme's THREAD). +func _batch_pipe(pts: PackedVector2Array, hovered: bool, own: String = "") -> void: var rid := _batch_item() + var col := Color.from_string(own, Style.THREAD) if own != "" else Style.THREAD + var dark := col.darkened(0.6) if own != "" else Style.THREAD_DARK if _far: - _coarse(rid, pts, Style.THREAD, 10.0) + _coarse(rid, pts, col, 10.0) return - _line(rid, pts, Style.THREAD_DARK, 11.0) - _line(rid, pts, Style.THREAD.lightened(0.35) if hovered else Style.THREAD, 6.0) + _line(rid, pts, dark, 11.0) + _line(rid, pts, col.lightened(0.35) if hovered else col, 6.0) RenderingServer.canvas_item_add_set_transform(rid, Transform2D(0.0, Vector2(0, -1.5))) _line(rid, pts, Color(1.0, 0.886, 0.745, 0.4), 1.5) RenderingServer.canvas_item_add_set_transform(rid, Transform2D.IDENTITY) @@ -229,7 +232,7 @@ func _draw() -> void: elif rerouted: _batch_bundle(pts) else: - _batch_pipe(pts, build and (key == hover_key or key == select_key)) + _batch_pipe(pts, build and (key == hover_key or key == select_key), str(e.pipe_color.get(to, ""))) if not is_ref and not rerouted: var tag := RulesView.pipe_label(e, to, main.data, plain) if tag != "": diff --git a/ui/style.gd b/ui/style.gd index c37cdb6..da2c5b4 100644 --- a/ui/style.gd +++ b/ui/style.gd @@ -62,6 +62,8 @@ static var PANEL_FILL: Dictionary = {} static var PATTERN := "dots" ## The logo shown in the top bar ("none" for none). static var LOGO := "none" +## Card border art: "ornate" (CardFrame) or "plain". +static var CARD_FRAME := "plain" const FONT_DIR := "res://assets/fonts/" diff --git a/ui/table_card.gd b/ui/table_card.gd index ad53b4a..106af80 100644 --- a/ui/table_card.gd +++ b/ui/table_card.gd @@ -49,6 +49,8 @@ var header_ui: TableCardHeader var rows_ui: TableCardRows var edit_ui: TableCardEditing var value_ui: TableCardValue +## The ornamental border (null when the theme has none). +var frame: CardFrame ## Rules in plain words (read from RulesView at each rebuild). var plain := true @@ -78,6 +80,8 @@ func setup(p_main: Main, p_table: RollTable) -> void: position = table.position _style_normal = Style.box(Style.CARD, 10) + if Style.CARD_FRAME == "ornate": + _style_normal.set_content_margin_all(CardFrame.PAD) _style_normal.shadow_color = Color(0, 0, 0, 0.32) _style_normal.shadow_size = 16 _style_normal.shadow_offset = Vector2(0, 8) @@ -102,6 +106,9 @@ func setup(p_main: Main, p_table: RollTable) -> void: _style_dragging.shadow_size = 26 _style_dragging.shadow_offset = Vector2(0, 16) + if Style.CARD_FRAME == "ornate": + frame = CardFrame.new() + add_child(frame) header_ui = TableCardHeader.new(self) rows_ui = TableCardRows.new(self) edit_ui = TableCardEditing.new(self) @@ -111,14 +118,28 @@ func setup(p_main: Main, p_table: RollTable) -> void: rebuild() +## The frame follows the card's own colour (RollTable.color), else the theme's. +## Without a frame, the card's colour is a border instead. +func _sync_frame() -> void: + var own := Color.from_string(table.color, Color(0, 0, 0, 0)) if table.color != "" else Color(0, 0, 0, 0) + if frame: + frame.set_trim(own) + else: + for sb: StyleBoxFlat in [_style_normal, _style_dragging]: + Style.bordered(sb, 3 if own.a > 0.0 else 0, own) + + func _on_rules_view_changed(_v: Variant = null) -> void: rebuild() func rebuild() -> void: for c in get_children(): + if c == frame: + continue remove_child(c) c.queue_free() + _sync_frame() rows.clear() rows_ui.clear() more_row = null diff --git a/ui/table_card_header.gd b/ui/table_card_header.gd index 3c9dc0d..dccad3c 100644 --- a/ui/table_card_header.gd +++ b/ui/table_card_header.gd @@ -75,7 +75,7 @@ func make(build: bool, ranged: bool) -> Control: titles.size_flags_vertical = Control.SIZE_SHRINK_CENTER titles.mouse_filter = Control.MOUSE_FILTER_IGNORE var title := Style.make_label(Formatter.strip_tags(table.name), Style.display(true), 20, Style.INK) - title.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + title.autowrap_mode = TextServer.AUTOWRAP_WORD if table.details.strip_edges() != "": # A small ⓘ after the name says hovering shows the table's details. var name_row := TableCard.hbox(4) diff --git a/ui/theme_dialog.gd b/ui/theme_dialog.gd index 22c7051..cbdd809 100644 --- a/ui/theme_dialog.gd +++ b/ui/theme_dialog.gd @@ -69,6 +69,7 @@ func _rebuild() -> void: 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")) diff --git a/ui/theme_store.gd b/ui/theme_store.gd index c214ca2..852b69e 100644 --- a/ui/theme_store.gd +++ b/ui/theme_store.gd @@ -56,6 +56,7 @@ const TOKENS := [ ] const PATTERNS := [["none", "None"], ["dots", "Dots"], ["stars", "Stars"]] const LOGOS := [["fortune_teller", "Fortune teller"], ["none", "None"]] +const CARD_FRAMES := [["ornate", "Beaded"], ["plain", "Plain"]] ## The open spread, handed across the scene reload that applies a theme. static var carry_board: TowerBoard = null @@ -124,6 +125,7 @@ static func apply(t: Dictionary) -> void: Style.PANEL_FILL = t.get("panel", {}) Style.PATTERN = str(t.get("pattern", "dots")) Style.LOGO = str(t.get("logo", "none")) + Style.CARD_FRAME = str(t.get("card_frame", "plain")) current = t