Play shows that Build mode exists

A greyed + Card in Play's top bar explains that cards are added in Build,
offers Switch to Build and pulses the Build switch. The ☰ menu shows New
card greyed with a tip. The toast's button can now run any action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-15 12:42:29 -06:00
parent 4a1b365985
commit 48b57e284c
7 changed files with 91 additions and 2 deletions

View file

@ -27,7 +27,9 @@ func _test_lists() -> void:
var play := _texts(Actions.card(main, t))
_check(play.has("Roll") and not play.has("Delete table"), "Play: a card can be rolled, not deleted: %s" % str(play))
var bg := _texts(Actions.background(main, Vector2.ZERO))
_check(bg.has("Search… Ctrl+F") and bg.has("Shuffle all decks") and not bg.has("New card"), "Play spread menu: %s" % str(bg))
_check(bg.has("Search… Ctrl+F") and bg.has("Shuffle all decks") and not bg.has("New card from template…"), "Play spread menu: %s" % str(bg))
var new_card: Dictionary = Actions.background(main, Vector2.ZERO)[bg.find("New card")]
_check(new_card.get("disabled", false), "Play: New card shows greyed, pointing to Build mode")
main.set_mode(Main.Mode.BUILD)
await _frames()
var build := _texts(Actions.card(main, t))

View file

@ -16,6 +16,7 @@ func _init() -> void:
await _test_stripes()
await _test_card_menu()
await _test_help()
await _test_build_hint()
finish()
@ -136,3 +137,23 @@ func _test_help() -> void:
_check(d.text.get_parsed_text().contains("Luck"), "and shows its text")
d.close()
await _frames()
## Play shows that Build mode exists: a greyed "+ Card" that explains and
## offers to switch, and a greyed "New card" in the ☰ menu.
func _test_build_hint() -> void:
main.set_mode(Main.Mode.PLAY)
var bar := main.top_bar
_check(bar.play_add_button.visible and not bar._build_tools.visible, "Play shows the greyed + Card, not the Build tools")
var names := Actions.background(main, Vector2.ZERO).map(func(a: Dictionary) -> String: return str(a.get("text", "")))
var item: Dictionary = Actions.background(main, Vector2.ZERO)[names.find("New card")] if names.has("New card") else {}
_check(item.get("disabled", false), "the ☰ menu shows New card greyed in Play")
bar.play_add_button.pressed.emit()
_eq(bar._toast_label.text, BuildModeHint.MESSAGE, "clicking it explains Build mode")
_check(bar._toast_undo.visible and bar._toast_undo.text == "Switch to Build", "the toast offers Switch to Build")
bar._toast_undo.pressed.emit()
await _frames()
_eq(main.mode, Main.Mode.BUILD, "Switch to Build switches")
_check(not bar.play_add_button.visible, "Build hides the greyed button")
main.toast("Saved")
_eq(bar._toast_undo.text, "Undo", "a later toast's button is Undo again")

View file

@ -176,6 +176,9 @@ static func background(m: Main, at: Vector2) -> Array:
list.append({"text": "Group the selection Ctrl+G", "do": m.grouping.group_selection, "disabled": picked == 0 and m.selecting.groups.is_empty(),
"tip": "Select cards first: drag a box around them"})
list.append({"sep": ""})
else:
list.append(BuildModeHint.menu_item())
list.append({"sep": ""})
list.append({"text": "Search… Ctrl+F", "do": m.nav.open_search})
list.append({"text": "Shuffle all decks", "do": m.local_state.reshuffle_all, "disabled": not has_decks(m),
"tip": "Put every Deck-mode card's results back"})

38
ui/build_mode_hint.gd Normal file
View file

@ -0,0 +1,38 @@
class_name BuildModeHint
extends RefCounted
## Play mode tells new players that Build mode exists: a greyed "+ Card"
## button in the top bar and a greyed "New card" in the ☰ menu. Clicking the
## button explains, offers "Switch to Build" and makes the Build switch pulse.
const MESSAGE := "Cards are added and edited in Build mode."
const TIP := "Switch to Build mode (top left) to add and edit cards"
## The greyed "+ Card" shown in Play in place of the real one.
static func make_button(m: Main) -> Button:
var b := Style.bar_button("+ Card")
b.modulate.a = 0.5
b.tooltip_text = TIP
b.focus_mode = Control.FOCUS_NONE
b.pressed.connect(func() -> void: explain(m))
return b
## The ☰ menu's greyed "New card" in Play (Actions.background).
static func menu_item() -> Dictionary:
return {"text": "New card", "disabled": true, "tip": TIP}
static func explain(m: Main) -> void:
m.top_bar.toast_action(MESSAGE, "Switch to Build", func() -> void: m.set_mode(Main.Mode.BUILD))
pulse(m.top_bar._build_button)
## Flashes a button three times to draw the eye.
static func pulse(b: Control) -> void:
if b == null or not b.is_inside_tree():
return
var tween := b.create_tween()
for i in 3:
tween.tween_property(b, "modulate", Color(1.6, 1.4, 0.8), 0.18)
tween.tween_property(b, "modulate", Color.WHITE, 0.22)

View file

@ -0,0 +1 @@
uid://cqbsjhxxuyjys

View file

@ -157,6 +157,7 @@ func set_mode(new_mode: Main.Mode) -> void:
m.top_bar._hint.tooltip_text = Main.HINTS[new_mode]
m.top_bar._hint.custom_minimum_size.x = 60.0 if new_mode == Main.Mode.PLAY else 0.0
m.top_bar._build_tools.visible = new_mode == Main.Mode.BUILD
m.top_bar.play_add_button.visible = new_mode == Main.Mode.PLAY
m.board.pipes.hover_key = ""
m.clear_selection()
m.inspector.visible = new_mode == Main.Mode.BUILD

View file

@ -22,6 +22,10 @@ var zoom: ZoomControl
var _toast: PanelContainer
var _toast_label: Label
var _toast_undo: Button
## The toast button's own action (toast_action), or empty for Undo.
var _toast_do := Callable()
## Play mode's greyed "+ Card" (BuildModeHint).
var play_add_button: Button
var _toast_timer: Timer
## The undo step the toast's Undo button undoes (EditHistory serial), or -1.
var _toast_serial := -1
@ -118,6 +122,8 @@ func _build_top_bar() -> Control:
tools.add_child(_board_menu)
tools.visible = false
h.add_child(tools)
play_add_button = BuildModeHint.make_button(m)
h.add_child(play_add_button)
_endless_chip = _make_endless_chip()
h.add_child(_endless_chip)
@ -212,7 +218,12 @@ func _build_toast() -> void:
var un := Style.box(Style.BG, 7, [12, 5, 12, 5])
var uh := Style.box(Style.BG_HOVER, 7, [12, 5, 12, 5])
Style.skin_button(_toast_undo, un, uh, uh, Style.ACCENT)
_toast_undo.pressed.connect(_undo)
_toast_undo.pressed.connect(func() -> void:
if _toast_do.is_valid():
_toast.hide()
_toast_do.call()
else:
_undo())
_toast_undo.focus_mode = Control.FOCUS_NONE
h.add_child(_toast_undo)
_toast.hide()
@ -231,6 +242,8 @@ func _build_toast() -> void:
## the edit just committed (it goes through the edit history, like Ctrl+Z).
func toast(message: String, undoable: bool = false) -> void:
_toast_serial = m.undo_redo.edits.top_serial() if undoable and m.undo_redo.edits else -1
_toast_do = Callable()
_toast_undo.text = "Undo"
_toast_label.text = message
_toast_undo.visible = _toast_serial >= 0
_toast.show()
@ -239,6 +252,16 @@ func toast(message: String, undoable: bool = false) -> void:
_toast_timer.start()
## A toast whose button runs `on_press` (labelled `label`) instead of Undo.
func toast_action(message: String, label: String, on_press: Callable) -> void:
toast(message)
_toast_do = on_press
_toast_undo.text = label
_toast_undo.show()
_toast.reset_size()
_place_toast()
func _place_toast() -> void:
if _toast and _toast.visible:
_toast.reset_size()