No more drag walls; drag box selects; middle/Space-drag pans; groups move with the selection

Cards, selections, new cards and inserted templates may sit anywhere,
including left of or above the old edge. In Build a drag on empty space
draws a selection box (Ctrl/Shift adds); middle-drag or Space+drag pans
(a plain drag still pans in Play). The box also picks up collapsed groups
it touches and expanded groups it covers, and dragging any selected card
or group moves the whole selection (MainSelection). Ctrl-click a group's
title to add it to the selection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-10 18:30:13 -06:00
parent 781aaf1be8
commit 9fcaf5c123
13 changed files with 192 additions and 41 deletions

View file

@ -84,7 +84,7 @@ godot --path .
Double-click the edge to go back to the default size.
- **Collapsing:** the arrow beside a table's name collapses it. A collapsed table still shows
its last result. **View ▾ → Collapse all tables / Expand all tables** does every table at once.
- **Groups:** in Build mode, Ctrl- or Shift-click card headers (or Ctrl-drag on the felt) to
- **Groups:** in Build mode, Ctrl- or Shift-click card headers (or drag a box on empty space) to
select cards, then **Group** (Ctrl+G, the selection bar, or **+ Card ▾**). A group is a
frame behind its cards; drag its title bar to move them all, drop a card into a frame to
add it, drag it out to take it out. The chevron collapses the group into one compact

View file

@ -137,7 +137,7 @@ Result text can do more than plain words:
# Groups and templates
## Groups
- Ctrl-click or Shift-click cards to select several, or Ctrl-drag a box around them.
- Drag a box on empty space to select several cards and groups (hold Ctrl or Shift to add to the selection), or Ctrl-click or Shift-click cards. Dragging any selected card or group moves them all.
- Press [b]Ctrl+G[/b] to put them in a group: a frame that moves and collapses as one.
- Drag cards into or out of a group. The group's ⋯ menu renames, saves as a template, ungroups or deletes it.
- [b]Spread ▾ → Pack collapsed groups[/b] moves collapsed groups together to close the gaps.
@ -168,7 +168,7 @@ Click any item in the report to jump to that card. A spread that can loop foreve
# Finding your way
- [b]Search[/b] (the magnifier, or [b]Ctrl+F[/b]) finds cards by name, result, question, value or group, opens closed groups and flashes the card.
- Drag the felt to move around. The mouse wheel scrolls up and down, [b]Shift+wheel[/b] scrolls sideways and [b]Ctrl+wheel[/b] zooms.
- Drag with the middle mouse button, or hold [b]Space[/b] and drag, to move around (in Play a plain drag works too). The mouse wheel scrolls up and down, [b]Shift+wheel[/b] scrolls sideways and [b]Ctrl+wheel[/b] zooms.
- The zoom control at the top right shows the zoom. − and + step it, and the percentage opens [b]Fit spread[/b], [b]Zoom to 100%[/b] and the minimap.
- The [b]minimap[/b] (press [b]M[/b]) shows the whole spread in the corner. Click or drag on it to move there.
@ -187,6 +187,6 @@ Click any item in the report to jump to that card. A spread that can loop foreve
- [b]Ctrl+Z[/b]: undo
- [b]Ctrl+Shift+Z[/b] or [b]Ctrl+Y[/b]: redo
- [b]Ctrl+G[/b]: group the selected cards
- [b]Ctrl-click[/b], [b]Shift-click[/b] or [b]Ctrl-drag[/b]: select several cards
- [b]Ctrl-click[/b], [b]Shift-click[/b] or a drag box on empty space: select several cards and groups
- [b]Esc[/b]: clear the selection, or close a window
- Double-click the tray's or the inspector's edge: reset its size

View file

@ -30,6 +30,7 @@ func _init() -> void:
await _test_collapse()
await _test_lit_and_choice()
await _test_move()
await _test_box_select()
await _test_drop_in_and_out()
await _test_collapse_all_and_fit()
await _test_ungroup_and_delete()
@ -339,6 +340,33 @@ func _test_ungroup_and_delete() -> void:
## True when a table has a card on show (hidden members have no card at all).
## A drag box picks up a collapsed group and a card; dragging the group moves both.
func _test_box_select() -> void:
var g := _group()
var was_collapsed := g.collapsed
if not g.collapsed:
main.toggle_group(g.id)
for i in 3:
await process_frame
main.clear_selection()
var node := main.group_node(g.id)
var loose := main.card_for("loose")
main.select_in_rect(Rect2(node.position, node.size).merge(Rect2(loose.position, loose.size)))
_check(main.selecting.groups.has(g.id) and main.selection.has("loose"), "a drag box selects groups and cards")
_check(main.editing._sel_label.text.ends_with(", 1 group selected"), "the bar counts both: " + main.editing._sel_label.text)
var gp := g.position
var lp := loose.table.position
main.selecting.drag_group(g.id, Vector2(30, 10))
_check(g.position == gp + Vector2(30, 10) and loose.table.position == lp + Vector2(30, 10), "dragging a selected group moves the whole selection")
main.selecting.drag_group(g.id, Vector2(-30, -10))
main.clear_selection()
_check(main.selecting.groups.is_empty(), "clearing the selection drops the groups")
if not was_collapsed:
main.toggle_group(g.id)
for i in 3:
await process_frame
func _shown(tid: String) -> bool:
var c := main.card_for(tid)
return c != null and c.visible

View file

@ -273,7 +273,7 @@ func _test_app() -> void:
_check(chk.entries[0].pipes == ["wounds"], "an outside thread relinks to Wounds on this spread")
var center := main.board.screen_to_world(main.board.size / 2.0)
var ext := TemplateKit.extent(tpl)
_check(chk.position.distance_to((center - ext / 2.0).round().max(Vector2(20, 20 + TableGroup.TITLE_H))) < 2.0, "placed around the view centre")
_check(chk.position.distance_to((center - ext / 2.0).round()) < 2.0, "placed around the view centre")
_check(main.top_bar._toast.visible and main.top_bar._toast_undo.visible, "an undo toast follows")
main.top_bar._undo()
await process_frame

View file

@ -36,6 +36,8 @@ var _culled_rev := -1
var _panning := false
var _banding := false
## The selection box adds to the selection (Ctrl or Shift held).
var _band_adds := false
var _band_from := Vector2.ZERO
var _band_to := Vector2.ZERO
var _press_at := Vector2(-1, -1)
@ -290,20 +292,14 @@ func _gui_input(ev: InputEvent) -> void:
if mb:
match mb.button_index:
MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE:
var build_left := mb.button_index == MOUSE_BUTTON_LEFT and main.mode == Main.Mode.BUILD
# Middle-drag or Space+drag pans anywhere; in Play a left-drag pans too.
var pan_drag := mb.button_index == MOUSE_BUTTON_MIDDLE or Input.is_key_pressed(KEY_SPACE)
var build_left := mb.button_index == MOUSE_BUTTON_LEFT and main.mode == Main.Mode.BUILD and not pan_drag
if mb.pressed:
# Clicking the felt leaves a text field, so Ctrl+Z undoes on the board.
var f := get_viewport().gui_get_focus_owner()
if f is LineEdit or f is TextEdit:
f.release_focus()
if build_left and (mb.ctrl_pressed or mb.meta_pressed):
# Ctrl-drag on the felt: rubber-band selection.
_banding = true
_band_from = mb.position
_band_to = mb.position
overlay.queue_redraw()
accept_event()
return
if build_left:
var key := pipes.pipe_at(world_mouse(), 11.0)
if key != "":
@ -311,7 +307,15 @@ func _gui_input(ev: InputEvent) -> void:
main.open_pipe_options(key, mb.global_position)
accept_event()
return
# A drag on empty space draws a selection box; Ctrl or Shift
# adds to the selection instead of replacing it.
_press_at = mb.position
_band_adds = mb.ctrl_pressed or mb.meta_pressed or mb.shift_pressed
_banding = true
_band_from = mb.position
_band_to = mb.position
accept_event()
return
_panning = true
stop_animation()
mouse_default_cursor_shape = CURSOR_DRAG
@ -319,15 +323,20 @@ func _gui_input(ev: InputEvent) -> void:
if _banding and mb.button_index == MOUSE_BUTTON_LEFT:
_banding = false
overlay.queue_redraw()
var a := screen_to_world(_band_from)
var b := screen_to_world(_band_to)
main.select_in_rect(Rect2(a.min(b), (a - b).abs()))
if mb.position.distance_to(_press_at) < 4.0:
# A plain click on the felt (no drag) clears the selection.
if not _band_adds:
main.clear_selection()
main.clear_inspector()
else:
if not _band_adds:
main.clear_selection()
var a := screen_to_world(_band_from)
var b := screen_to_world(_band_to)
main.select_in_rect(Rect2(a.min(b), (a - b).abs()))
_press_at = Vector2(-1, -1)
accept_event()
return
# A plain click on the felt (no drag) clears the selection.
if build_left and _press_at.x >= 0.0 and mb.position.distance_to(_press_at) < 4.0:
main.clear_selection()
main.clear_inspector()
_press_at = Vector2(-1, -1)
_panning = false
mouse_default_cursor_shape = CURSOR_ARROW

View file

@ -42,6 +42,9 @@ var _band_box: StyleBoxFlat
var _stack_box: StyleBoxFlat
var _card_box: StyleBoxFlat
var _card_rolling: StyleBoxFlat
var _card_selected: StyleBoxFlat
## In the Build selection (MainSelection).
var _selected := false
func setup(p_main: Main, p_group: TableGroup) -> void:
@ -67,6 +70,9 @@ func setup(p_main: Main, p_group: TableGroup) -> void:
_card_rolling.shadow_color = Color(Style.ACCENT, 0.45)
_card_rolling.shadow_size = 26
_card_rolling.shadow_offset = Vector2.ZERO
_card_selected = _card_box.duplicate() as StyleBoxFlat
Style.bordered(_card_selected, 3, Style.TRIM)
_card_selected.set_expand_margin_all(4)
minimum_size_changed.connect(func() -> void: _shrink.call_deferred())
rebuild()
@ -121,7 +127,7 @@ func _draw() -> void:
draw_style_box(_stack_box, Rect2(off, size))
return
var r := Rect2(Vector2.ZERO, size)
draw_style_box(_frame_drop if _drop else _frame_box, r)
draw_style_box(_frame_drop if _drop or _selected else _frame_box, r)
draw_style_box(_band_box, Rect2(0, 0, size.x, TableGroup.TITLE_H))
@ -192,7 +198,7 @@ func _build_compact() -> void:
_shrink.call_deferred()
_card = PanelContainer.new()
_card.mouse_filter = MOUSE_FILTER_STOP
_card.add_theme_stylebox_override("panel", _card_rolling if _rolling else _card_box)
_card.add_theme_stylebox_override("panel", _card_style())
_card.gui_input.connect(func(ev: InputEvent) -> void:
# Clicks on the card body shouldn't pan the board.
var mb := ev as InputEventMouseButton
@ -332,10 +338,21 @@ func refresh_lit(keys: Array) -> void:
rebuild()
func _card_style() -> StyleBox:
return _card_rolling if _rolling else (_card_selected if _selected else _card_box)
func set_selected(on: bool) -> void:
_selected = on
if is_instance_valid(_card):
_card.add_theme_stylebox_override("panel", _card_style())
queue_redraw()
func set_rolling(on: bool) -> void:
_rolling = on
if is_instance_valid(_card):
_card.add_theme_stylebox_override("panel", _card_rolling if on else _card_box)
_card.add_theme_stylebox_override("panel", _card_style())
# ---------- Shared parts ----------
@ -422,6 +439,10 @@ func _on_title_input(ev: InputEvent, owner: Control) -> void:
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
if mb.pressed:
main.details().hide_for()
if main.mode == Main.Mode.BUILD and (mb.ctrl_pressed or mb.meta_pressed):
main.selecting.toggle_group(group.id)
owner.accept_event()
return
_dragging = true
_drag_last = main.board.world_mouse()
if group.collapsed:
@ -435,6 +456,6 @@ func _on_title_input(ev: InputEvent, owner: Control) -> void:
if mm and _dragging:
var delta := (main.board.world_mouse() - _drag_last).round()
if delta != Vector2.ZERO:
main.move_group(group.id, delta)
main.selecting.drag_group(group.id, delta)
_drag_last += delta
owner.accept_event()

View file

@ -39,8 +39,10 @@ var board: BoardView
var tray: ResultTray
## The Build-mode inspector docked right of the board (ui/inspector.gd).
var inspector: Inspector
## Table ids selected in Build mode (Ctrl/Shift-click, Ctrl-drag on the felt).
## Table ids selected in Build mode (Ctrl/Shift-click, or a drag box on empty space).
var selection: Dictionary = {}
## Groups in the Build selection (MainSelection).
var selecting: MainSelection
var _save_timer: Timer
var _saving_enabled := true
@ -85,6 +87,7 @@ func _init() -> void:
undo_redo = MainHistory.new(self)
inspecting = MainInspectorLink.new(self)
cli = MainCli.new(self)
selecting = MainSelection.new(self)
prompt_hook = rolling._ask_player

View file

@ -87,7 +87,7 @@ func add_table(kind: String = RollTable.KIND_ROLL, sub: String = "") -> RollTabl
e.id = TowerBoard.new_id("e")
if kind == RollTable.KIND_VARIABLE:
t.var_name = _free_var_name(t.var_name)
t.position = Vector2(maxf(20.0, roundf(center.x - 128.0)), maxf(20.0, roundf(center.y - 120.0)))
t.position = Vector2(roundf(center.x - 128.0), roundf(center.y - 120.0))
m.data.tables.append(t)
var card := TableCard.new()
m.board.cards.add_child(card)
@ -110,7 +110,7 @@ func add_variable_card(label: String, var_name: String, type: String = "number")
var center := m.board.screen_to_world(m.board.size / 2.0)
var t := RollTable.create(RollTable.KIND_VARIABLE, TowerBoard.new_id("t"), label, type)
t.var_name = _free_var_name(var_name)
t.position = Vector2(maxf(20.0, roundf(center.x - 300.0)), maxf(20.0, roundf(center.y + 40.0)))
t.position = Vector2(roundf(center.x - 300.0), roundf(center.y + 40.0))
m.data.tables.append(t)
var card := TableCard.new()
m.board.cards.add_child(card)
@ -306,6 +306,7 @@ func clear_selection() -> void:
if c:
c.set_selected(false)
m.selection.clear()
m.selecting.clear()
_update_selection_bar()
@ -316,6 +317,7 @@ func select_in_rect(r: Rect2) -> void:
if c.visible and Rect2(c.position, c.size).intersects(r):
m.selection[tid] = true
c.set_selected(true)
m.selecting.select_in_rect(r)
_update_selection_bar()
@ -354,8 +356,8 @@ func _update_selection_bar() -> void:
if _sel_bar == null:
return
var n := m.selection.size()
_sel_bar.visible = n > 0 and m.mode == Main.Mode.BUILD
_sel_label.text = "%d %s selected" % [n, "card" if n == 1 else "cards"]
_sel_bar.visible = n + m.selecting.groups.size() > 0 and m.mode == Main.Mode.BUILD
_sel_label.text = m.selecting.describe(n) + " selected"
_place_selection_bar.call_deferred()

View file

@ -10,6 +10,8 @@ var m: Main
var _group_nodes: Dictionary = {} # group id -> GroupCard
var _hidden_cache: Variant = null # table id -> GroupCard, or null when stale
## Ids of the cards being dragged and the group the pointer is over (Build).
## Dragging moves the whole Build selection (cards and groups).
var _drag_all := false
var _drag_set: Array[String] = []
var _drag_from: Dictionary = {} # table id -> its position when the drag began
var _drag_over: GroupCard
@ -178,7 +180,7 @@ func group_selection() -> TableGroup:
if m.selection.has(t.id):
ids.append(t.id)
if ids.is_empty():
m.toast("Select some cards first: Ctrl- or Shift-click their headers, or Ctrl-drag on the felt")
m.toast("Select some cards first: Ctrl- or Shift-click their headers, or drag a box around them")
return null
m.undo_redo._begin_edit()
var g := m.data.add_group(_free_group_name(), ids)
@ -284,9 +286,11 @@ func begin_card_drag(card: TableCard) -> void:
m.select_card(card.table.id)
m.undo_redo._begin_edit()
_drag_set.clear()
if m.mode == Main.Mode.BUILD and m.selection.has(card.table.id) and m.selection.size() > 1:
_drag_all = m.selecting.moves_together(card.table.id)
if _drag_all:
# Cards in selected groups move with their group.
for tid: String in m.selection:
if m.cards.has(tid):
if m.cards.has(tid) and not m.selecting.covers(tid):
_drag_set.append(tid)
else:
_drag_set.append(card.table.id)
@ -302,16 +306,12 @@ func begin_card_drag(card: TableCard) -> void:
## Moves the dragged card (and the rest of a multi-selection) so `card` lands at `to`.
func drag_card(card: TableCard, to: Vector2) -> void:
var delta := to - card.position
if _drag_set.size() > 1:
# Keep every selected card on the board.
for tid in _drag_set:
var c := m.card_for(tid)
delta.x = maxf(delta.x, 10.0 - c.position.x)
delta.y = maxf(delta.y, 10.0 - c.position.y)
if _drag_all:
for tid in _drag_set:
var c := m.card_for(tid)
c.position += delta
c.table.position = c.position
m.selecting.move_groups(delta)
else:
card.position = to
card.table.position = to

88
ui/main_selection.gd Normal file
View file

@ -0,0 +1,88 @@
class_name MainSelection
extends RefCounted
## Groups in the Build selection, alongside Main.selection's cards. A drag box
## picks up collapsed groups it touches and expanded groups it covers whole;
## dragging any selected card or group then moves everything selected together
## (groups can be moved as one even when they can't be grouped).
var m: Main
## gid -> true
var groups: Dictionary = {}
func _init(p_main: Main) -> void:
m = p_main
func select_in_rect(r: Rect2) -> void:
for n in m.board.groups.get_children() + m.board.cards.get_children():
var gc := n as GroupCard
if gc == null or not gc.visible or gc.group == null:
continue
var gr := Rect2(gc.position, gc.size)
if (gc.group.collapsed and gr.intersects(r)) or (not gc.group.collapsed and r.encloses(gr)):
set_group(gc.group.id, true)
func set_group(gid: String, on: bool) -> void:
if on:
groups[gid] = true
else:
groups.erase(gid)
var n := m.group_node(gid)
if n:
n.set_selected(on)
func toggle_group(gid: String) -> void:
set_group(gid, not groups.has(gid))
m.editing._update_selection_bar()
func clear() -> void:
for gid: String in groups.keys():
set_group(gid, false)
## True when a selected group carries this card (moving the group moves it).
func covers(tid: String) -> bool:
var g := m.data.group_of(tid)
return g != null and groups.has(g.id)
## True when dragging this card should move the whole selection.
func moves_together(tid: String) -> bool:
return m.mode == Main.Mode.BUILD and (m.selection.has(tid) or covers(tid)) \
and m.selection.size() + groups.size() > 1
## Moves every selected group by `delta`.
func move_groups(delta: Vector2) -> void:
for gid: String in groups:
m.move_group(gid, delta)
## A group's title was dragged: moves just it, or the whole selection when it's
## part of one.
func drag_group(gid: String, delta: Vector2) -> void:
if not groups.has(gid) or m.selection.size() + groups.size() < 2:
m.move_group(gid, delta)
return
move_groups(delta)
for tid: String in m.selection:
if not covers(tid):
var c := m.card_for(tid)
if c:
c.position += delta
c.table.position = c.position
m.board.geometry_rev += 1
## "3 cards, 1 group" for the selection bar.
func describe(cards: int) -> String:
var parts := PackedStringArray()
if cards > 0:
parts.append("%d %s" % [cards, "card" if cards == 1 else "cards"])
if not groups.is_empty():
parts.append("%d %s" % [groups.size(), "group" if groups.size() == 1 else "groups"])
return ", ".join(parts)

1
ui/main_selection.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://6iju4ukbl0dd

View file

@ -84,7 +84,6 @@ func insert_template(tpl: Dictionary, values: Dictionary) -> Dictionary:
var ext := TemplateKit.extent(tpl)
var center := m.board.screen_to_world(m.board.size / 2.0)
var origin := (center - ext / 2.0).round()
origin = Vector2(maxf(20.0, origin.x), maxf(20.0 + TableGroup.TITLE_H, origin.y))
var r := TemplateKit.insert(tpl, values, m.data, origin)
for t: RollTable in r["tables"]:
if t.kind == RollTable.KIND_VARIABLE and t.var_name == "":

View file

@ -537,5 +537,5 @@ func _on_header_input(ev: InputEvent, header: Control) -> void:
var mm := ev as InputEventMouseMotion
if mm and _dragging:
var p := main.board.world_mouse() - _drag_offset
main.drag_card(self, Vector2(maxf(10.0, roundf(p.x)), maxf(10.0, roundf(p.y))))
main.drag_card(self, p.round())
header.accept_event()