Style's colours become static vars named by role (BG, PANEL, CARD, THREAD, ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme can replace them. Stray hard-coded colours moved into tokens. ThemeStore applies built-in sets (Tarot, the new default: jewel-purple cloth with a shine; Felt, the old look) and the user's own sets from user://themes/. Fills for the background and panels can be gradients; the background pattern (dots, stars, none) and logo are per set. View ▾ → Theme… edits a set; changes to a built-in save as a new set. Using a theme reloads the UI and keeps the open spread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
164 lines
5.1 KiB
GDScript
164 lines
5.1 KiB
GDScript
class_name Minimap
|
|
extends Control
|
|
## A small overview of the whole board in the bottom-right corner: group
|
|
## frames and collapsed group cards as tinted blocks, cards as card-coloured
|
|
## rectangles (brass when they hold a lit result) and the part of the board
|
|
## in view as a rectangle. Click or drag on it to pan there.
|
|
##
|
|
## It only redraws when BoardView asks (the view moved, or the board's
|
|
## geometry changed), never every frame. The map's scale comes from the
|
|
## board's content, so it holds still while panning.
|
|
|
|
const MAX_SIZE := Vector2(232, 160)
|
|
const MARGIN := 14.0
|
|
const PAD := 8.0
|
|
|
|
var board: BoardView
|
|
var _bg: StyleBoxFlat
|
|
var _dragging := false
|
|
## World rect the map shows, and how it maps onto the map's inner rect.
|
|
var _world := Rect2()
|
|
var _scale := 1.0
|
|
var _offset := Vector2.ZERO
|
|
var _rev := -1
|
|
|
|
|
|
func setup(p_board: BoardView) -> void:
|
|
board = p_board
|
|
mouse_filter = MOUSE_FILTER_STOP
|
|
mouse_default_cursor_shape = CURSOR_POINTING_HAND
|
|
tooltip_text = "Overview: click or drag to move around (M)"
|
|
_bg = Style.bordered(Style.box(Color(Style.BG_DEEP, 0.92), 10), 1, Color(1, 1, 1, 0.16))
|
|
_bg.shadow_color = Color(0, 0, 0, 0.35)
|
|
_bg.shadow_size = 12
|
|
_bg.shadow_offset = Vector2(0, 4)
|
|
visible = false
|
|
size = MAX_SIZE
|
|
board.resized.connect(place)
|
|
|
|
|
|
## Re-places and redraws the map (BoardView calls this when the view or the
|
|
## board's geometry changed). Does nothing while hidden.
|
|
func refresh() -> void:
|
|
if not visible:
|
|
return
|
|
place()
|
|
queue_redraw()
|
|
|
|
|
|
## Keeps the map in the board's bottom-right corner, sized to the content's shape.
|
|
func place() -> void:
|
|
if board == null:
|
|
return
|
|
_refresh_frame()
|
|
position = board.size - size - Vector2(MARGIN, MARGIN)
|
|
|
|
|
|
func _notification(what: int) -> void:
|
|
if what == NOTIFICATION_VISIBILITY_CHANGED and visible:
|
|
_rev = -1
|
|
refresh()
|
|
|
|
|
|
## Recomputes the world rect and scale from the board's content (only when
|
|
## the board's geometry changed).
|
|
func _refresh_frame() -> void:
|
|
if _rev == board.geometry_rev and _world.size != Vector2.ZERO:
|
|
return
|
|
_rev = board.geometry_rev
|
|
var b := board.content_bounds()
|
|
if b.size == Vector2.ZERO:
|
|
b = Rect2(Vector2.ZERO, Vector2(1000, 700))
|
|
b = b.grow(maxf(b.size.x, b.size.y) * 0.03 + 40.0)
|
|
set_world(b)
|
|
|
|
|
|
## Sets the world rect the map covers and resizes the map to its shape.
|
|
func set_world(b: Rect2) -> void:
|
|
_world = b
|
|
var inner := MAX_SIZE - Vector2(PAD, PAD) * 2.0
|
|
_scale = minf(inner.x / b.size.x, inner.y / b.size.y)
|
|
var used := b.size * _scale
|
|
size = Vector2(maxf(used.x, 90.0), maxf(used.y, 60.0)) + Vector2(PAD, PAD) * 2.0
|
|
_offset = (size - used) / 2.0
|
|
|
|
|
|
func world_to_map(p: Vector2) -> Vector2:
|
|
return _offset + (p - _world.position) * _scale
|
|
|
|
|
|
func map_to_world(p: Vector2) -> Vector2:
|
|
return _world.position + (p - _offset) / _scale
|
|
|
|
|
|
## The board's view as a rect on the map (map coordinates).
|
|
func view_rect_on_map() -> Rect2:
|
|
var v := board.view_rect()
|
|
return Rect2(world_to_map(v.position), v.size * _scale)
|
|
|
|
|
|
func _draw() -> void:
|
|
if board == null or board.main == null or board.main.data == null:
|
|
return
|
|
var main := board.main
|
|
draw_style_box(_bg, Rect2(Vector2.ZERO, size))
|
|
var inner := Rect2(Vector2(3, 3), size - Vector2(6, 6))
|
|
# Expanded group frames first, then cards and collapsed groups on top.
|
|
for g in main.data.groups:
|
|
if not g.collapsed:
|
|
_block(g.rect(), Color(0, 0, 0, 0.28), Color(1, 1, 1, 0.18), inner)
|
|
var hidden := main.hidden_groups()
|
|
var lit_tables := {}
|
|
for k: String in main.lit_entries:
|
|
lit_tables[k.substr(0, k.rfind(":"))] = true
|
|
for t in main.data.tables:
|
|
if hidden.has(t.id):
|
|
continue
|
|
var c := main.card_for(t.id)
|
|
var r := Rect2(c.position, c.size) if c else Rect2(t.position, Vector2(TableCard.WIDTH, 120))
|
|
var lit := lit_tables.has(t.id)
|
|
_block(r, Style.ACCENT if lit else Color(Style.CARD, 0.85), Color(0, 0, 0, 0), inner)
|
|
for g in main.data.groups:
|
|
if g.collapsed:
|
|
var n := main.group_node(g.id)
|
|
var r := Rect2(n.position, n.size) if n else Rect2(g.position, Vector2(TableCard.WIDTH, 120))
|
|
var lit := false
|
|
for tid in g.members:
|
|
if lit_tables.has(tid):
|
|
lit = true
|
|
break
|
|
_block(r, Style.ACCENT if lit else Style.CARD_SHADE, Style.TRIM_DARK, inner)
|
|
var v := view_rect_on_map().intersection(inner)
|
|
if v.size.x > 0.0 and v.size.y > 0.0:
|
|
draw_rect(v, Color(Style.ON_BG, 0.08))
|
|
draw_rect(v, Style.ON_BG, false, 1.5)
|
|
|
|
|
|
## One block on the map, at least 2 px so tiny cards still show.
|
|
func _block(r: Rect2, fill: Color, edge: Color, clip: Rect2) -> void:
|
|
var m := Rect2(world_to_map(r.position), (r.size * _scale).max(Vector2(2, 2))).intersection(clip)
|
|
if m.size.x <= 0.0 or m.size.y <= 0.0:
|
|
return
|
|
draw_rect(m, fill)
|
|
if edge.a > 0.0 and m.size.x > 4.0 and m.size.y > 4.0:
|
|
draw_rect(m, edge, false, 1.0)
|
|
|
|
|
|
func _gui_input(ev: InputEvent) -> void:
|
|
var mb := ev as InputEventMouseButton
|
|
if mb:
|
|
if mb.button_index == MOUSE_BUTTON_LEFT:
|
|
_dragging = mb.pressed
|
|
if mb.pressed:
|
|
pan_to_map_point(mb.position)
|
|
accept_event()
|
|
return
|
|
var mm := ev as InputEventMouseMotion
|
|
if mm and _dragging:
|
|
pan_to_map_point(mm.position)
|
|
accept_event()
|
|
|
|
|
|
## Centres the board's view on the world point under a map point.
|
|
func pan_to_map_point(p: Vector2) -> void:
|
|
board.center_on(map_to_world(p))
|