TableTower/ui/group_mark.gd
RobinFiredrake 16ad73adfb Group marks: member cards' top-right corner in the group's colour
Groups get an optional colour (Colour menu on the group); uncoloured
groups use the theme token GROUP. The group frame's border matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 08:36:13 -06:00

57 lines
2.1 KiB
GDScript

class_name GroupMark
extends Control
## The top-right corner of a card in a group, in the group's colour (its own,
## else Style.GROUP), so members are easy to tell from cards that only lie
## inside the group's frame. On the beaded frame it recolours that corner
## piece; on a plain card it draws a bracket over the corner.
##
## Like CardFrame it draws around the host card's whole rectangle, whatever box
## the container gives it.
## Plain cards: how far the bracket runs along each edge, and its width.
const ARM := 26.0
const WIDTH := 4.0
const RADIUS := 10.0
var _color := Color(0, 0, 0, 0)
func _init() -> void:
mouse_filter = MOUSE_FILTER_IGNORE
texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
visible = false
## The colour of a group's mark and border.
static func color_of(g: TableGroup) -> Color:
return Color.from_string(g.color, Style.GROUP) if g.color != "" else Style.GROUP
## Shows the mark for the card's group, or hides it (null).
func show_for(g: TableGroup) -> void:
var c := color_of(g) if g else Color(0, 0, 0, 0)
if c == _color and visible == (g != null):
return
_color = c
visible = g != null
material = CardFrame.material_for(c) if g and Style.CARD_FRAME == "ornate" else null
queue_redraw()
func _draw() -> void:
var host := get_parent() as Control
if host == null:
return
if Style.CARD_FRAME == "ornate":
var r := Rect2(-position, host.size).grow(CardFrame.OUTSET)
draw_set_transform(Vector2(r.end.x, r.position.y), 0.0, Vector2(-1, 1))
draw_texture_rect(CardFrame.CORNER, Rect2(Vector2.ZERO, Vector2(CardFrame.CORNER_W, CardFrame.CORNER_H) * CardFrame.S), false)
draw_set_transform(Vector2.ZERO)
return
# Plain: an L along the top and right edges, round where the card is.
var r := Rect2(-position, host.size)
var c := Vector2(r.end.x - RADIUS, r.position.y + RADIUS)
var inset := WIDTH / 2.0
draw_arc(c, RADIUS - inset, -PI / 2.0, 0.0, 12, _color, WIDTH, true)
draw_line(Vector2(r.end.x - ARM, r.position.y + inset), Vector2(c.x, r.position.y + inset), _color, WIDTH, true)
draw_line(Vector2(r.end.x - inset, c.y), Vector2(r.end.x - inset, r.position.y + ARM), _color, WIDTH, true)