A left-docked panel (View ▾ → List view, ☰ or right-click the spread) lists every card, with groups as folders. Rows show threads in and out (hover for where they lead) and a Roll cell; click selects in Build, double-click shows the card on the spread, right-click opens its menu. Drag to reorder (the spread's own order, saved and undoable), onto a folder to move in, folder into folder to nest. Own search, + Folder, resizable edge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
208 lines
6.7 KiB
GDScript
208 lines
6.7 KiB
GDScript
class_name ListTree
|
|
extends Tree
|
|
## List view's tree: groups as folders (nested), cards as rows with their
|
|
## threads and a Roll cell. Drag a row to reorder it or drop it on a folder to
|
|
## move it in; the order is the spread's own (TowerBoard.tables and .groups).
|
|
|
|
const COL_NAME := 0
|
|
const COL_THREADS := 1
|
|
const COL_ROLL := 2
|
|
|
|
var m: Main
|
|
var filter := ""
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
m = p_main
|
|
columns = 3
|
|
hide_root = true
|
|
column_titles_visible = false
|
|
select_mode = Tree.SELECT_ROW
|
|
allow_reselect = true
|
|
set_column_expand(COL_NAME, true)
|
|
set_column_expand(COL_THREADS, false)
|
|
set_column_custom_minimum_width(COL_THREADS, 64)
|
|
set_column_expand(COL_ROLL, false)
|
|
set_column_custom_minimum_width(COL_ROLL, 54)
|
|
add_theme_font_override("font", Style.body())
|
|
add_theme_font_size_override("font_size", 15)
|
|
add_theme_color_override("font_color", Style.INK)
|
|
add_theme_color_override("font_selected_color", Style.INK)
|
|
add_theme_constant_override("v_separation", 6)
|
|
add_theme_stylebox_override("panel", Style.box(Style.CARD, 0, [4, 4, 4, 4]))
|
|
add_theme_stylebox_override("selected", Style.box(Style.LIT, 4))
|
|
add_theme_stylebox_override("selected_focus", Style.box(Style.LIT, 4))
|
|
add_theme_stylebox_override("focus", StyleBoxEmpty.new())
|
|
item_mouse_selected.connect(_on_click)
|
|
item_activated.connect(_on_activated)
|
|
item_collapsed.connect(_on_folder_toggled)
|
|
|
|
|
|
## Rebuilds every row from the spread, keeping the open folders and selection.
|
|
func rebuild() -> void:
|
|
var sel := _meta(get_selected())
|
|
clear()
|
|
var root := create_item()
|
|
_fill(root, "")
|
|
if not sel.is_empty():
|
|
_select_meta(root, sel)
|
|
|
|
|
|
func _fill(parent: TreeItem, gid: String) -> void:
|
|
for g in m.data.groups:
|
|
if g.parent == gid:
|
|
var it := create_item(parent)
|
|
it.set_text(COL_NAME, Formatter.strip_tags(g.name))
|
|
it.set_custom_font(COL_NAME, Style.body_bold())
|
|
it.set_custom_color(COL_NAME, Style.TRIM_DARK)
|
|
it.set_metadata(COL_NAME, {"kind": "group", "id": g.id})
|
|
it.set_tooltip_text(COL_NAME, "Folder (a group on the spread): %s" % MainSelection.describe_counts(m.data.tables_in(g.id).size(), m.data.groups_in(g.id).size() - 1))
|
|
_fill(it, g.id)
|
|
it.collapsed = g.collapsed and filter == ""
|
|
if filter != "" and it.get_first_child() == null:
|
|
it.free()
|
|
var members := {}
|
|
var g0 := m.data.get_group(gid)
|
|
if g0:
|
|
for tid in g0.members:
|
|
members[tid] = true
|
|
for t in m.data.tables:
|
|
if (gid == "" and m.data.group_of(t.id) == null) or members.has(t.id):
|
|
if filter != "" and not _matches(t):
|
|
continue
|
|
_card_row(parent, t)
|
|
|
|
|
|
func _card_row(parent: TreeItem, t: RollTable) -> void:
|
|
var it := create_item(parent)
|
|
it.set_text(COL_NAME, Formatter.strip_tags(t.name))
|
|
it.set_tooltip_text(COL_NAME, Describe.kind_label(t))
|
|
if t.color != "":
|
|
it.set_custom_color(COL_NAME, Color(t.color).darkened(0.2))
|
|
it.set_metadata(COL_NAME, {"kind": "card", "id": t.id})
|
|
var ins := _threads_in(t.id)
|
|
var outs := _threads_out(t)
|
|
var counts := PackedStringArray()
|
|
if not ins.is_empty():
|
|
counts.append("←%d" % ins.size())
|
|
if not outs.is_empty():
|
|
counts.append("→%d" % outs.size())
|
|
it.set_text(COL_THREADS, " ".join(counts))
|
|
it.set_custom_color(COL_THREADS, Style.MUTED)
|
|
var tip := PackedStringArray()
|
|
if not ins.is_empty():
|
|
tip.append("Threads in:\n " + "\n ".join(ins))
|
|
if not outs.is_empty():
|
|
tip.append("Threads out:\n " + "\n ".join(outs))
|
|
it.set_tooltip_text(COL_THREADS, "\n".join(tip) if not tip.is_empty() else "No threads")
|
|
if t.kind != RollTable.KIND_VARIABLE:
|
|
it.set_text(COL_ROLL, "Roll")
|
|
it.set_custom_color(COL_ROLL, Style.TRIM_DARK)
|
|
it.set_custom_font(COL_ROLL, Style.body_bold())
|
|
it.set_tooltip_text(COL_ROLL, "Roll %s" % Formatter.strip_tags(t.name))
|
|
|
|
|
|
func _threads_in(tid: String) -> PackedStringArray:
|
|
var out := PackedStringArray()
|
|
for src in m.data.tables:
|
|
for e in src.entries:
|
|
if e.pipes.has(tid):
|
|
out.append("from %s · %s" % [Formatter.strip_tags(src.name), Formatter.strip_tags(e.text).left(40)])
|
|
return out
|
|
|
|
|
|
func _threads_out(t: RollTable) -> PackedStringArray:
|
|
var out := PackedStringArray()
|
|
for e in t.entries:
|
|
for to in e.pipes:
|
|
var target := m.data.get_table(to)
|
|
out.append("%s → %s" % [Formatter.strip_tags(e.text).left(40), Formatter.strip_tags(target.name) if target else to])
|
|
return out
|
|
|
|
|
|
func _matches(t: RollTable) -> bool:
|
|
if Formatter.strip_tags(t.name).to_lower().contains(filter):
|
|
return true
|
|
for e in t.entries:
|
|
if Formatter.strip_tags(e.text).to_lower().contains(filter):
|
|
return true
|
|
return false
|
|
|
|
|
|
# ---------- Clicks ----------
|
|
|
|
func _on_click(at: Vector2, button: int) -> void:
|
|
var meta := _meta(get_selected())
|
|
if meta.is_empty():
|
|
return
|
|
if button == MOUSE_BUTTON_RIGHT:
|
|
var list := Actions.card(m, m.data.get_table(meta["id"])) if meta["kind"] == "card" else Actions.group(m, m.data.get_group(meta["id"]))
|
|
Actions.popup_at(m, list, get_screen_transform() * at)
|
|
return
|
|
if meta["kind"] == "card":
|
|
if get_column_at_position(at) == COL_ROLL:
|
|
m.rolling.start_roll(str(meta["id"]))
|
|
elif m.mode == Main.Mode.BUILD:
|
|
m.select_card(str(meta["id"]))
|
|
|
|
|
|
## Double-click or Enter: show the card on the spread.
|
|
func _on_activated() -> void:
|
|
var meta := _meta(get_selected())
|
|
if meta.get("kind") == "card":
|
|
m.focus_table(str(meta["id"]))
|
|
|
|
|
|
## Opening or closing a folder opens or closes its group on the spread too.
|
|
func _on_folder_toggled(it: TreeItem) -> void:
|
|
var meta := _meta(it)
|
|
if meta.get("kind") == "group" and filter == "":
|
|
var g := m.data.get_group(meta["id"])
|
|
if g and g.collapsed != it.collapsed:
|
|
m.grouping.set_group_collapsed(g.id, it.collapsed)
|
|
|
|
|
|
static func _meta(it: TreeItem) -> Dictionary:
|
|
if it == null:
|
|
return {}
|
|
var v: Variant = it.get_metadata(COL_NAME)
|
|
return v if v is Dictionary else {}
|
|
|
|
|
|
func _select_meta(it: TreeItem, want: Dictionary) -> bool:
|
|
var c := it.get_first_child()
|
|
while c:
|
|
if _meta(c) == want:
|
|
c.select(COL_NAME)
|
|
return true
|
|
if _select_meta(c, want):
|
|
return true
|
|
c = c.get_next()
|
|
return false
|
|
|
|
|
|
# ---------- Drag and drop ----------
|
|
|
|
func _get_drag_data(at: Vector2) -> Variant:
|
|
var it := get_item_at_position(at)
|
|
var meta := _meta(it)
|
|
if meta.is_empty() or filter != "":
|
|
return null
|
|
var l := Label.new()
|
|
l.text = it.get_text(COL_NAME)
|
|
set_drag_preview(l)
|
|
drop_mode_flags = DROP_MODE_ON_ITEM | DROP_MODE_INBETWEEN
|
|
return {"list_item": meta}
|
|
|
|
|
|
func _can_drop_data(at: Vector2, data: Variant) -> bool:
|
|
if not (data is Dictionary and (data as Dictionary).has("list_item")):
|
|
return false
|
|
var target := _meta(get_item_at_position(at))
|
|
return target.is_empty() or target != data["list_item"]
|
|
|
|
|
|
func _drop_data(at: Vector2, data: Variant) -> void:
|
|
drop_mode_flags = DROP_MODE_DISABLED
|
|
var it := get_item_at_position(at)
|
|
ListOrder.move(m, data["list_item"], _meta(it), get_drop_section_at_position(at))
|