Zoomed-out cards: names as tooltips, drag, right-click, and click to roll in Play
Below 45% zoom a CardShield covers each card and collapsed group: the name shows as a tooltip, dragging moves it, right-click opens its menu, and in Play a click rolls it. Zoom back in and the card's own controls return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
748ffad21a
commit
608641df66
6 changed files with 117 additions and 5 deletions
|
|
@ -16,6 +16,7 @@ func _init() -> void:
|
|||
root.add_child(main)
|
||||
await _frames(5)
|
||||
await _test_resize()
|
||||
await _test_compact()
|
||||
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
|
||||
quit(1 if _failures else 0)
|
||||
|
||||
|
|
@ -24,14 +25,14 @@ func _test_resize() -> void:
|
|||
var t := main.data.get_table("road")
|
||||
var card := main.card_for("road")
|
||||
var grip := card.grip
|
||||
_check(grip != null and grip.get_index() == card.get_child_count() - 1, "the grip is the card's last child")
|
||||
_check(grip != null and grip.get_index() == card.get_child_count() - 2 and card.shield.get_index() == card.get_child_count() - 1, "the grip, then the shield, are the card's last children")
|
||||
_check(grip._has_point(grip.size - Vector2(4, 4)) and not grip._has_point(Vector2(4, 4)), "only the corner takes the mouse")
|
||||
var auto_w := card.size.x
|
||||
card.set_user_size(380.0, 120.0)
|
||||
await _frames()
|
||||
_check(is_equal_approx(card.size.x, 380.0 + card.extra_width()), "the card takes the dragged width")
|
||||
_check(card.list_scroll != null and is_equal_approx(card.list_scroll.size.y, 120.0), "a set height makes the results scroll")
|
||||
_check(card.grip.get_index() == card.get_child_count() - 1, "the grip stays on top after a rebuild")
|
||||
_check(card.grip.get_index() == card.get_child_count() - 2, "the grip stays on top after a rebuild")
|
||||
var d := t.to_dict()
|
||||
_check(d.get("w") == 380 and d.get("list_h") == 120, "the size is saved")
|
||||
var back := RollTable.from_dict(d)
|
||||
|
|
@ -41,6 +42,28 @@ func _test_resize() -> void:
|
|||
_check(is_equal_approx(card.size.x, auto_w) and card.list_scroll == null, "back to automatic")
|
||||
|
||||
|
||||
## Zoomed out, cards take only drag, right-click and (in Play) a click to roll.
|
||||
func _test_compact() -> void:
|
||||
main.board.set_zoom(0.3)
|
||||
await _frames()
|
||||
var card := main.card_for("road")
|
||||
_check(main.board.compact and card.shield.visible, "zoomed out, the shield covers the card")
|
||||
_check(card.shield.tooltip_text.begins_with("Road Encounter") and card.shield.tooltip_text.contains("Click to roll"), "its name is a tooltip: " + card.shield.tooltip_text)
|
||||
var click := InputEventMouseButton.new()
|
||||
click.button_index = MOUSE_BUTTON_LEFT
|
||||
click.pressed = true
|
||||
click.global_position = Vector2(10, 10)
|
||||
card.shield._gui_input(click)
|
||||
var up := click.duplicate() as InputEventMouseButton
|
||||
up.pressed = false
|
||||
card.shield._gui_input(up)
|
||||
await _frames(3)
|
||||
_check(main.current.get("table_id", "") == "road" or str(main.current).contains("road"), "a click rolls it in Play")
|
||||
main.board.set_zoom(1.0)
|
||||
await _frames()
|
||||
_check(not main.board.compact and not card.shield.visible, "zoomed in, the shield is gone")
|
||||
|
||||
|
||||
func _frames(n: int = 2) -> void:
|
||||
for i in n:
|
||||
await process_frame
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ const MAX_ZOOM := 1.5
|
|||
## Below this zoom text can't be read, so cards draw as plain cards (their
|
||||
## contents aren't rendered) and group names show large (CardLayer).
|
||||
const FAR_ZOOM := 0.22
|
||||
## Below this, cards and collapsed groups only drag, right-click and (in Play)
|
||||
## roll on a click; their names show as tooltips (CardShield).
|
||||
const COMPACT_ZOOM := 0.45
|
||||
const WORLD_SIZE := 40000.0
|
||||
|
||||
var main: Main
|
||||
|
|
@ -36,6 +39,8 @@ var _culled_rev := -1
|
|||
|
||||
var _panning := false
|
||||
var _banding := false
|
||||
## Zoomed out past COMPACT_ZOOM (see set_compact).
|
||||
var compact := false
|
||||
## The selection box adds to the selection (Ctrl or Shift held).
|
||||
var _band_adds := false
|
||||
var _band_from := Vector2.ZERO
|
||||
|
|
@ -94,6 +99,8 @@ func _process(_delta: float) -> void:
|
|||
if far != cards.far or (far and (_view_sig.is_empty() or v[2] != _view_sig[2])):
|
||||
cards.far = far
|
||||
cards.overlay.queue_redraw()
|
||||
if (zoom < COMPACT_ZOOM) != compact:
|
||||
set_compact(zoom < COMPACT_ZOOM)
|
||||
_view_sig = v
|
||||
_cull()
|
||||
minimap.refresh()
|
||||
|
|
@ -201,6 +208,16 @@ static func pattern_texture(kind: String) -> ImageTexture:
|
|||
return null
|
||||
|
||||
|
||||
## Shows or hides every card's and collapsed group's CardShield.
|
||||
func set_compact(on: bool) -> void:
|
||||
compact = on
|
||||
for layer: Control in [cards, groups]:
|
||||
for c in layer.get_children():
|
||||
var sh: Variant = c.get("shield")
|
||||
if sh is CardShield:
|
||||
(sh as CardShield).visible = on
|
||||
|
||||
|
||||
func world_mouse() -> Vector2:
|
||||
return world.get_local_mouse_position()
|
||||
|
||||
|
|
|
|||
49
ui/card_shield.gd
Normal file
49
ui/card_shield.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
class_name CardShield
|
||||
extends Control
|
||||
## Zoomed out (below BoardView.COMPACT_ZOOM) a card's buttons are too small to
|
||||
## hit, so this cover takes the mouse instead: the name shows as a tooltip,
|
||||
## dragging moves the card (or group), right-click opens its menu, and in Play
|
||||
## a click rolls it. The host's container lays it over the whole host; it's
|
||||
## kept as the host's last child and hidden while zoomed in.
|
||||
|
||||
var main: Main
|
||||
## Gets every left-button event (the host's own drag handling).
|
||||
var on_left: Callable
|
||||
## Gets right-button presses; returns true when it opened a menu.
|
||||
var on_right: Callable
|
||||
## Rolls the host (Play click); empty for hosts that don't roll.
|
||||
var on_roll: Callable
|
||||
var _press := Vector2(-1, -1)
|
||||
|
||||
|
||||
func _init(p_main: Main, left: Callable, right: Callable, roll: Callable = Callable()) -> void:
|
||||
main = p_main
|
||||
on_left = left
|
||||
on_right = right
|
||||
on_roll = roll
|
||||
mouse_filter = MOUSE_FILTER_STOP
|
||||
visible = main.board != null and main.board.compact
|
||||
|
||||
|
||||
func set_name_tip(text: String) -> void:
|
||||
tooltip_text = text + ("\nClick to roll" if on_roll.is_valid() and main.mode == Main.Mode.PLAY else "")
|
||||
|
||||
|
||||
func _gui_input(ev: InputEvent) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.button_index == MOUSE_BUTTON_RIGHT:
|
||||
on_right.call(mb)
|
||||
accept_event()
|
||||
return
|
||||
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
if mb.pressed:
|
||||
_press = mb.global_position
|
||||
elif _press.x >= 0.0 and mb.global_position.distance_to(_press) < 4.0 and main.mode == Main.Mode.PLAY and on_roll.is_valid():
|
||||
on_left.call(ev, self)
|
||||
_press = Vector2(-1, -1)
|
||||
on_roll.call()
|
||||
accept_event()
|
||||
return
|
||||
if mb or ev is InputEventMouseMotion:
|
||||
on_left.call(ev, self)
|
||||
accept_event()
|
||||
1
ui/card_shield.gd.uid
Normal file
1
ui/card_shield.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dk8bu8s48dblw
|
||||
|
|
@ -40,6 +40,8 @@ var _card_rolling: StyleBoxFlat
|
|||
var _card_selected: StyleBoxFlat
|
||||
## In the Build selection (MainSelection).
|
||||
var _selected := false
|
||||
## The zoomed-out cover of a collapsed group (CardShield); null when expanded.
|
||||
var shield: CardShield
|
||||
|
||||
|
||||
func setup(p_main: Main, p_group: TableGroup) -> void:
|
||||
|
|
@ -78,6 +80,7 @@ func rebuild() -> void:
|
|||
c.queue_free()
|
||||
lit_rows.clear()
|
||||
menu_button = null
|
||||
shield = null
|
||||
_card = null
|
||||
_header = null
|
||||
position = group.position
|
||||
|
|
@ -247,6 +250,10 @@ func _build_compact() -> void:
|
|||
if build:
|
||||
row.add_child(_menu_button(false))
|
||||
|
||||
shield = CardShield.new(main, _on_title_input, _open_menu_on)
|
||||
shield.set_name_tip(Formatter.strip_tags(group.name))
|
||||
_card.add_child.call_deferred(shield)
|
||||
|
||||
var pad := MarginContainer.new()
|
||||
pad.mouse_filter = MOUSE_FILTER_PASS
|
||||
pad.add_theme_constant_override("margin_top", 6)
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ var value_ui: TableCardValue
|
|||
var frame: CardFrame
|
||||
## The resize handle (CardGrip), kept as the last child.
|
||||
var grip: CardGrip
|
||||
## Takes the mouse while zoomed out (CardShield).
|
||||
var shield: CardShield
|
||||
## Rules in plain words (read from RulesView at each rebuild).
|
||||
var plain := true
|
||||
|
||||
|
|
@ -113,6 +115,8 @@ func setup(p_main: Main, p_table: RollTable) -> void:
|
|||
add_child(frame)
|
||||
grip = CardGrip.new(self)
|
||||
add_child(grip)
|
||||
shield = CardShield.new(main, _on_header_input, open_menu_on, func() -> void: main.rolling.start_roll(table.id))
|
||||
add_child(shield)
|
||||
header_ui = TableCardHeader.new(self)
|
||||
rows_ui = TableCardRows.new(self)
|
||||
edit_ui = TableCardEditing.new(self)
|
||||
|
|
@ -139,7 +143,7 @@ func _on_rules_view_changed(_v: Variant = null) -> void:
|
|||
|
||||
func rebuild() -> void:
|
||||
for c in get_children():
|
||||
if c == frame or c == grip:
|
||||
if c == frame or c == grip or c == shield:
|
||||
continue
|
||||
remove_child(c)
|
||||
c.queue_free()
|
||||
|
|
@ -181,7 +185,7 @@ func rebuild() -> void:
|
|||
col.add_child(edit_ui.make_footer(ranged))
|
||||
_apply_style()
|
||||
refresh_live()
|
||||
move_child(grip, -1)
|
||||
_raise_covers()
|
||||
return
|
||||
|
||||
var pad := MarginContainer.new()
|
||||
|
|
@ -228,7 +232,7 @@ func rebuild() -> void:
|
|||
col.add_child(edit_ui.make_footer(ranged))
|
||||
_apply_style()
|
||||
refresh_live()
|
||||
move_child(grip, -1)
|
||||
_raise_covers()
|
||||
if list_scroll != null:
|
||||
for eid in rows:
|
||||
if main.is_entry_lit(table.id, eid):
|
||||
|
|
@ -547,8 +551,19 @@ func _gui_input(ev: InputEvent) -> void:
|
|||
accept_event()
|
||||
|
||||
|
||||
## The grip, then the zoomed-out shield, stay on top of the rebuilt content.
|
||||
func _raise_covers() -> void:
|
||||
move_child(grip, -1)
|
||||
move_child(shield, -1)
|
||||
shield.set_name_tip(Formatter.strip_tags(table.name))
|
||||
if table.kind == RollTable.KIND_VARIABLE:
|
||||
shield.on_roll = Callable()
|
||||
|
||||
|
||||
## Right-click: the card's actions menu (Actions.card). True when it opened.
|
||||
func open_menu_on(mb: InputEventMouseButton) -> bool:
|
||||
if mb == null:
|
||||
return false
|
||||
if mb == null or mb.button_index != MOUSE_BUTTON_RIGHT or not mb.pressed:
|
||||
return false
|
||||
main.details().hide_for()
|
||||
|
|
|
|||
Loading…
Reference in a new issue