51 lines
1.9 KiB
GDScript3
51 lines
1.9 KiB
GDScript3
|
|
class_name InspectorThreads
|
||
|
|
extends RefCounted
|
||
|
|
## The card inspector's "Threads in" and "Threads out" lists: every thread
|
||
|
|
## leading into the card (from which card and result) and out of it (from
|
||
|
|
## which result, to which card). Clicking one selects that thread.
|
||
|
|
|
||
|
|
|
||
|
|
static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
|
||
|
|
var board := insp.main.data
|
||
|
|
var ins := VBoxContainer.new()
|
||
|
|
for src in board.tables:
|
||
|
|
for e in src.entries:
|
||
|
|
if e.pipes.has(t.id):
|
||
|
|
ins.add_child(_link(insp, src, e, t.id, "%s · %s" % [_name(src.name), _result(e)]))
|
||
|
|
var outs := VBoxContainer.new()
|
||
|
|
for e in t.entries:
|
||
|
|
for to in e.pipes:
|
||
|
|
var target := board.get_table(to)
|
||
|
|
outs.add_child(_link(insp, t, e, to, "%s → %s" % [_result(e), _name(target.name) if target else to + " (missing)"]))
|
||
|
|
if ins.get_child_count() == 0:
|
||
|
|
ins.add_child(InspectorKit.note("Nothing leads here yet."))
|
||
|
|
if outs.get_child_count() == 0:
|
||
|
|
outs.add_child(InspectorKit.note("No threads leave this card."))
|
||
|
|
box.add_child(InspectorKit.field("Threads in (%d)" % _count(ins), ins))
|
||
|
|
box.add_child(InspectorKit.field("Threads out (%d)" % _count(outs), outs))
|
||
|
|
|
||
|
|
|
||
|
|
static func _link(insp: Inspector, from: RollTable, e: TableEntry, to: String, text: String) -> Button:
|
||
|
|
var key := Roller.pipe_key(from.id, e.id, to)
|
||
|
|
var b := InspectorKit.link(text, "Select this thread")
|
||
|
|
b.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||
|
|
b.clip_text = true
|
||
|
|
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
|
|
var own := str(e.pipe_color.get(to, ""))
|
||
|
|
if own != "":
|
||
|
|
b.add_theme_color_override("font_color", Color(own))
|
||
|
|
b.pressed.connect(func() -> void: insp.main.inspecting.select_pipe(key))
|
||
|
|
return b
|
||
|
|
|
||
|
|
|
||
|
|
static func _count(v: VBoxContainer) -> int:
|
||
|
|
return v.get_children().filter(func(c: Node) -> bool: return c is Button).size()
|
||
|
|
|
||
|
|
|
||
|
|
static func _name(s: String) -> String:
|
||
|
|
return Inspector._title_of(s, "(no name)")
|
||
|
|
|
||
|
|
|
||
|
|
static func _result(e: TableEntry) -> String:
|
||
|
|
return Inspector._title_of(e.text, "(no text)")
|