Deck rows show copies left; Reroll this on tray steps
- A deck row with no copies left is greyed out; one partly drawn gets an accent tint (Play and Build) and, in Play, shows <left> / <weight>. - Each step of the current result has a Reroll this button: that card and the cards after it roll again in place. Earlier keeps no copy; the old branch's deck draws go back. - Tests in test_small_ui and test_fast_roll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
577922d15d
commit
7d7b181b71
14 changed files with 277 additions and 15 deletions
|
|
@ -62,6 +62,15 @@ func take(e: TableEntry) -> void:
|
||||||
drawn[e.id] = int(drawn.get(e.id, 0)) + 1
|
drawn[e.id] = int(drawn.get(e.id, 0)) + 1
|
||||||
|
|
||||||
|
|
||||||
|
## Puts one drawn copy of this result back (its roll was replaced).
|
||||||
|
func put_back(entry_id: String) -> void:
|
||||||
|
var count := int(drawn.get(entry_id, 0)) - 1
|
||||||
|
if count > 0:
|
||||||
|
drawn[entry_id] = count
|
||||||
|
else:
|
||||||
|
drawn.erase(entry_id)
|
||||||
|
|
||||||
|
|
||||||
## Forgets draws for entries that no longer exist.
|
## Forgets draws for entries that no longer exist.
|
||||||
func _prune(table: RollTable) -> void:
|
func _prune(table: RollTable) -> void:
|
||||||
for k: Variant in drawn.keys():
|
for k: Variant in drawn.keys():
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,20 @@ func add_history(record: Dictionary) -> void:
|
||||||
_dirty = true
|
_dirty = true
|
||||||
|
|
||||||
|
|
||||||
|
## Swaps the record with the same collection and time for this one (a
|
||||||
|
## rerolled step changes the current roll in place). Adds it if none matches.
|
||||||
|
func replace_history(record: Dictionary) -> void:
|
||||||
|
var list: Array = _section_list("history")
|
||||||
|
for i in list.size():
|
||||||
|
var old: Variant = list[i]
|
||||||
|
if old is Dictionary and str(old.get("collection", "")) == str(record.get("collection", "")) \
|
||||||
|
and float(old.get("time", -1.0)) == float(record.get("time", -2.0)):
|
||||||
|
list[i] = record.duplicate(true)
|
||||||
|
_dirty = true
|
||||||
|
return
|
||||||
|
add_history(record)
|
||||||
|
|
||||||
|
|
||||||
## All records, or only those whose "collection" is cid when cid isn't empty.
|
## All records, or only those whose "collection" is cid when cid isn't empty.
|
||||||
func get_history(cid: String = "") -> Array[Dictionary]:
|
func get_history(cid: String = "") -> Array[Dictionary]:
|
||||||
var out: Array[Dictionary] = []
|
var out: Array[Dictionary] = []
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,8 @@ Each original file keeps one-line delegators, so callers are unchanged.
|
||||||
- **Ledger:** `core/ledger_members.gd` (entries on the card: clean, adopt older spreads, sync with
|
- **Ledger:** `core/ledger_members.gd` (entries on the card: clean, adopt older spreads, sync with
|
||||||
saved values), `ui/ledger_edits.gd` (add/rename/start/remove with undo), `ui/ledger_card_rows.gd`
|
saved values), `ui/ledger_edits.gd` (add/rename/start/remove with undo), `ui/ledger_card_rows.gd`
|
||||||
(Build-mode fields on the card).
|
(Build-mode fields on the card).
|
||||||
- **Rolling:** `ui/main_rolling_show.gd` (show a roll at once), `RollCosts.card_gate` (card costs),
|
- **Rolling:** `ui/main_rolling_show.gd` (show a roll at once), `ui/main_rolling_reroll.gd`
|
||||||
|
("Reroll this" on a tray step: that card and its branch roll again in place; 2026-12-01), `RollCosts.card_gate` (card costs),
|
||||||
`RollPauses` pop-up, `SpreadLinks` (`core/spread_links.gd`, [[Spread::Card]]) with
|
`RollPauses` pop-up, `SpreadLinks` (`core/spread_links.gd`, [[Spread::Card]]) with
|
||||||
`ui/spread_loader.gd` and `ui/spread_link_dialog.gd`.
|
`ui/spread_loader.gd` and `ui/spread_link_dialog.gd`.
|
||||||
- **Interface:** `ui/delete_key.gd`, `ui/sound_panel.gd`, `ui/format_menu.gd` (right-click Format),
|
- **Interface:** `ui/delete_key.gd`, `ui/sound_panel.gd`, `ui/format_menu.gd` (right-click Format),
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@ undo 200 steps, formula depth 8) and the review list at the end of `docs/SHEETS.
|
||||||
- Drag handles reorder a card's results in Build (ranged cards keep ranges in place). Hand-tested.
|
- Drag handles reorder a card's results in Build (ranged cards keep ranges in place). Hand-tested.
|
||||||
- Thread nodes under a card stacked above theirs are hidden. Hand-tested.
|
- Thread nodes under a card stacked above theirs are hidden. Hand-tested.
|
||||||
- Deck mode: a drawn result fades only after the roll animation reveals it (fast rolls: at once).
|
- Deck mode: a drawn result fades only after the roll animation reveals it (fast rolls: at once).
|
||||||
|
- Deck mode rows (2026-12-01): none left = greyed out; some drawn = accent tint, and in Play
|
||||||
|
mode "<left> / <weight>" in place of the number. Tray steps have "↻ Reroll this".
|
||||||
- Group marks (the user's pick, "option C"): a member card's top-right corner, and the group's
|
- Group marks (the user's pick, "option C"): a member card's top-right corner, and the group's
|
||||||
border, take the group's colour (Colour ▸ on the group menu); uncoloured groups use the theme
|
border, take the group's colour (Colour ▸ on the group menu); uncoloured groups use the theme
|
||||||
token GROUP (default gold, same as the highlight; watch for confusion).
|
token GROUP (default gold, same as the highlight; watch for confusion).
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,42 @@ func run() -> void:
|
||||||
await _test_deck_waits()
|
await _test_deck_waits()
|
||||||
await _test_batch_history()
|
await _test_batch_history()
|
||||||
_test_reroll_mark()
|
_test_reroll_mark()
|
||||||
|
await _test_reroll_this()
|
||||||
finish()
|
finish()
|
||||||
|
|
||||||
|
|
||||||
|
## Reroll this: a step rolls again with its branch, in place. The steps
|
||||||
|
## before it stay, Earlier keeps no copy, and a deck's old draw goes back.
|
||||||
|
func _test_reroll_this() -> void:
|
||||||
|
main.start_roll("wilderness", true)
|
||||||
|
var before: Array = main.current["all"]
|
||||||
|
var history := main.history.size()
|
||||||
|
var last := before.size() - 1
|
||||||
|
_check(main.tray.reroll_buttons.has(last), "a step of the current result has Reroll this")
|
||||||
|
await main.rolling.reroll.reroll(last)
|
||||||
|
var after: Array = main.current["all"]
|
||||||
|
for i in last:
|
||||||
|
_check(is_same(after[i], before[i]), "the steps before it are kept (step %d)" % i)
|
||||||
|
_eq(str(after[last]["table_id"]), str(before[last]["table_id"]), "the same card rolls again")
|
||||||
|
_eq(main.history.size(), history, "Earlier keeps no copy of the old result")
|
||||||
|
_check(main.current.get("done", false), "the rerolled result is finished")
|
||||||
|
before = after
|
||||||
|
await main.rolling.reroll.reroll(0)
|
||||||
|
_check(not is_same(main.current["all"][0], before[0]), "the first step and the cards after it roll again")
|
||||||
|
_eq(str(main.current["root"]), "wilderness", "it is still the same roll")
|
||||||
|
|
||||||
|
var t := main.data.get_table("wilderness")
|
||||||
|
t.card_mode = true
|
||||||
|
main.reshuffle_table(t.id)
|
||||||
|
main.start_roll(t.id, true)
|
||||||
|
var total := main.cards_left(t.id).y
|
||||||
|
_eq(main.cards_left(t.id).x, total - 1, "the roll draws one card")
|
||||||
|
await main.rolling.reroll.reroll(0)
|
||||||
|
_eq(main.cards_left(t.id).x, total - 1, "the old card goes back; only the new one is drawn")
|
||||||
|
t.card_mode = false
|
||||||
|
main.reshuffle_table(t.id)
|
||||||
|
|
||||||
|
|
||||||
## "Roll again" shows: the skipped result flickers with a floating note.
|
## "Roll again" shows: the skipped result flickers with a floating note.
|
||||||
func _test_reroll_mark() -> void:
|
func _test_reroll_mark() -> void:
|
||||||
var card := main.card_for("names")
|
var card := main.card_for("names")
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,48 @@ func _test_chip_and_export() -> void:
|
||||||
_check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "diagram formats sit under Export as a diagram")
|
_check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "diagram formats sit under Export as a diagram")
|
||||||
|
|
||||||
|
|
||||||
|
## Deck mode: a row with some copies drawn is tinted (Play and Build) and, in
|
||||||
|
## Play, shows "<left> / <weight>"; with none left it is greyed out.
|
||||||
|
func _test_partly_drawn(t: RollTable) -> void:
|
||||||
|
var first := t.entries[0]
|
||||||
|
var weight := first.weight
|
||||||
|
first.weight = 2
|
||||||
|
main.reshuffle_table(t.id)
|
||||||
|
var card := main.card_for(t.id)
|
||||||
|
card.rebuild()
|
||||||
|
await _frames()
|
||||||
|
var number: Label = card.rows_ui.parts[first.id]["num"]
|
||||||
|
var plain := number.text
|
||||||
|
(main.decks.get_or_add(t.id, DeckState.new()) as DeckState).take(first)
|
||||||
|
card.update_deck()
|
||||||
|
var row: Control = card.rows[first.id]
|
||||||
|
_check(row.self_modulate == TableCardSkin.partly_drawn_tint() and row.modulate == Color.WHITE, "a partly drawn row is tinted")
|
||||||
|
_eq(number.text, "1 / 2", "a partly drawn row shows its copies left")
|
||||||
|
main.set_mode(Main.Mode.BUILD)
|
||||||
|
await _frames()
|
||||||
|
card = main.card_for(t.id)
|
||||||
|
_check(card.rows[first.id].self_modulate == TableCardSkin.partly_drawn_tint(), "it is tinted in Build mode too")
|
||||||
|
main.set_mode(Main.Mode.PLAY)
|
||||||
|
await _frames()
|
||||||
|
card = main.card_for(t.id)
|
||||||
|
(main.decks[t.id] as DeckState).take(first)
|
||||||
|
card.update_deck()
|
||||||
|
row = card.rows[first.id]
|
||||||
|
number = card.rows_ui.parts[first.id]["num"]
|
||||||
|
_check(row.modulate == TableCardSkin.DRAWN_LOOK and row.self_modulate == Color.WHITE, "with no copies left the row is greyed out")
|
||||||
|
_eq(number.text, plain, "it shows its own number again")
|
||||||
|
first.weight = weight
|
||||||
|
main.reshuffle_table(t.id)
|
||||||
|
card.rebuild()
|
||||||
|
await _frames()
|
||||||
|
|
||||||
|
|
||||||
## Deck mode: drawn results fade, an empty deck that waits for Shuffle gives
|
## Deck mode: drawn results fade, an empty deck that waits for Shuffle gives
|
||||||
## its Empty result, and Shuffle all puts everything back.
|
## its Empty result, and Shuffle all puts everything back.
|
||||||
func _test_deck_mode() -> void:
|
func _test_deck_mode() -> void:
|
||||||
var t := main.data.get_table("party_roles")
|
var t := main.data.get_table("party_roles")
|
||||||
_check(t != null and t.card_mode, "the sample's Party Roles is a deck")
|
_check(t != null and t.card_mode, "the sample's Party Roles is a deck")
|
||||||
|
await _test_partly_drawn(t)
|
||||||
t.deck_empty = "stop"
|
t.deck_empty = "stop"
|
||||||
t.deck_empty_text = "No roles left"
|
t.deck_empty_text = "No roles left"
|
||||||
for i in t.entries.size():
|
for i in t.entries.size():
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ var deck_reveal: DeckReveal
|
||||||
var _seed: MainRollingSeed
|
var _seed: MainRollingSeed
|
||||||
var _copy: MainRollingCopy
|
var _copy: MainRollingCopy
|
||||||
var _show: MainRollingShow
|
var _show: MainRollingShow
|
||||||
|
## "Reroll this" on a step in the result tray.
|
||||||
|
var reroll: MainRollingReroll
|
||||||
|
|
||||||
|
|
||||||
func _init(p_main: Main) -> void:
|
func _init(p_main: Main) -> void:
|
||||||
|
|
@ -31,6 +33,7 @@ func _init(p_main: Main) -> void:
|
||||||
_seed = MainRollingSeed.new(p_main)
|
_seed = MainRollingSeed.new(p_main)
|
||||||
_copy = MainRollingCopy.new(p_main)
|
_copy = MainRollingCopy.new(p_main)
|
||||||
_show = MainRollingShow.new(p_main)
|
_show = MainRollingShow.new(p_main)
|
||||||
|
reroll = MainRollingReroll.new(p_main)
|
||||||
|
|
||||||
|
|
||||||
## Rolls a table and plays the result down its pipes. A fast roll (Shift held
|
## Rolls a table and plays the result down its pipes. A fast roll (Shift held
|
||||||
|
|
|
||||||
107
ui/main_rolling_reroll.gd
Normal file
107
ui/main_rolling_reroll.gd
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
class_name MainRollingReroll
|
||||||
|
extends RefCounted
|
||||||
|
## "Reroll this" in the result tray: one step's card rolls again, and so do
|
||||||
|
## the cards after it along its threads. The new steps take the old ones'
|
||||||
|
## place in the current result; Earlier keeps no copy. Deck draws the old
|
||||||
|
## steps made go back into their decks first. The reroll shows at once.
|
||||||
|
|
||||||
|
## Steps that can't be rerolled on their own: text rolls inside a result,
|
||||||
|
## runs dropped from or added into a total, a choice's answer, and the
|
||||||
|
## "Cancelled" / "Stopped after …" ends.
|
||||||
|
const FIXED_KEYS := ["inline", "dropped", "combined", "answer", "spread", "cancelled", "limit"]
|
||||||
|
## How the old step was reached; the new step keeps it, so its thread lights.
|
||||||
|
const LINK_KEYS := ["pass", "after", "card_thread"]
|
||||||
|
|
||||||
|
var m: Main
|
||||||
|
|
||||||
|
|
||||||
|
func _init(p_main: Main) -> void:
|
||||||
|
m = p_main
|
||||||
|
|
||||||
|
|
||||||
|
## True when step `index` of the finished current result can be rerolled.
|
||||||
|
func can_reroll(index: int) -> bool:
|
||||||
|
if m.current.is_empty() or not m.current.get("done", false):
|
||||||
|
return false
|
||||||
|
var steps: Array = m.current.get("all", [])
|
||||||
|
if index < 0 or index >= steps.size():
|
||||||
|
return false
|
||||||
|
var step: Dictionary = steps[index]
|
||||||
|
for key: String in FIXED_KEYS:
|
||||||
|
var value: Variant = step.get(key)
|
||||||
|
if value != null and not (value is bool and value == false):
|
||||||
|
return false
|
||||||
|
var table := m.data.get_table(str(step.get("table_id", "")))
|
||||||
|
return table != null and table.kind != RollTable.KIND_VARIABLE
|
||||||
|
|
||||||
|
|
||||||
|
## Index just past the last step under steps[index] (its whole branch).
|
||||||
|
static func branch_end(steps: Array, index: int) -> int:
|
||||||
|
var depth := int((steps[index] as Dictionary).get("depth", 0))
|
||||||
|
var end := index + 1
|
||||||
|
while end < steps.size() and int((steps[end] as Dictionary).get("depth", 0)) > depth:
|
||||||
|
end += 1
|
||||||
|
return end
|
||||||
|
|
||||||
|
|
||||||
|
## Rolls step `index` of the current result again, with its branch.
|
||||||
|
func reroll(index: int) -> void:
|
||||||
|
if not can_reroll(index):
|
||||||
|
return
|
||||||
|
var current := m.current
|
||||||
|
var steps: Array = current["all"]
|
||||||
|
var step: Dictionary = steps[index]
|
||||||
|
var end := branch_end(steps, index)
|
||||||
|
_put_back_draws(steps.slice(index, end))
|
||||||
|
if m.sound:
|
||||||
|
m.sound.play("roll")
|
||||||
|
var ctx := Roller.new_context(m.data, m.rng, m.persistent_vars, m.decks)
|
||||||
|
ctx.chain_vars = (current.get("chain_vars", {}) as Dictionary).duplicate(true)
|
||||||
|
ctx.prompt = _ask
|
||||||
|
m.sheet_links.before_roll(Formatter.strip_tags(str(current.get("root_name", ""))))
|
||||||
|
var depth := int(step.get("depth", 0))
|
||||||
|
var tree: Dictionary = await Roller.roll_async(m.data, str(step["table_id"]), ctx, depth)
|
||||||
|
if not is_same(current, m.current):
|
||||||
|
return # another roll started while this one asked a question
|
||||||
|
var fresh := Roller.flatten(tree, [], depth)
|
||||||
|
if not fresh.is_empty():
|
||||||
|
for key: String in LINK_KEYS:
|
||||||
|
if step.has(key):
|
||||||
|
(fresh[0] as Dictionary)[key] = step[key]
|
||||||
|
var all: Array = steps.slice(0, index) + fresh + steps.slice(end)
|
||||||
|
current["all"] = all
|
||||||
|
current["steps"] = all
|
||||||
|
current["chain_vars"] = ctx.chain_vars.duplicate()
|
||||||
|
current["fast"] = true
|
||||||
|
_show(all)
|
||||||
|
m.local_state.replace_current_roll(ctx)
|
||||||
|
|
||||||
|
|
||||||
|
## Deck mode: every card the old branch drew goes back into its deck.
|
||||||
|
func _put_back_draws(old_steps: Array) -> void:
|
||||||
|
for st: Dictionary in old_steps:
|
||||||
|
if st.get("stop", false) or not st.has("entry_id"):
|
||||||
|
continue
|
||||||
|
var deck: DeckState = m.decks.get(str(st.get("table_id", "")))
|
||||||
|
if deck:
|
||||||
|
deck.put_back(str(st["entry_id"]))
|
||||||
|
|
||||||
|
|
||||||
|
## Questions in the rerolled branch ask as usual; a paused thread goes on,
|
||||||
|
## since you asked for this branch.
|
||||||
|
func _ask(req: Dictionary) -> Variant:
|
||||||
|
if str(req.get("kind", "")) == "pause":
|
||||||
|
return true
|
||||||
|
return await m.prompt_hook.call(req)
|
||||||
|
|
||||||
|
|
||||||
|
func _show(all: Array) -> void:
|
||||||
|
m.lit_entries.clear()
|
||||||
|
m.lit_pipes.clear()
|
||||||
|
m.lit_texts.clear()
|
||||||
|
m.lit_columns.clear()
|
||||||
|
m.rolling._light_steps(all)
|
||||||
|
m._refresh_lit()
|
||||||
|
m.rolling._reveal_steps(all)
|
||||||
|
m.refresh_live()
|
||||||
|
m.tray.render()
|
||||||
1
ui/main_rolling_reroll.gd.uid
Normal file
1
ui/main_rolling_reroll.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dgy1y1xvj0vpm
|
||||||
|
|
@ -53,7 +53,7 @@ func load_local_state() -> void:
|
||||||
|
|
||||||
## After a roll: saves the decks, any changed persistent variables and the
|
## After a roll: saves the decks, any changed persistent variables and the
|
||||||
## history record.
|
## history record.
|
||||||
func _store_roll(ctx: RollContext) -> void:
|
func _store_roll(ctx: RollContext, replace: bool = false) -> void:
|
||||||
# Values the roll changed go back into the sheets on the spread first.
|
# Values the roll changed go back into the sheets on the spread first.
|
||||||
m.sheet_links.after_roll()
|
m.sheet_links.after_roll()
|
||||||
if m.state == null:
|
if m.state == null:
|
||||||
|
|
@ -61,11 +61,21 @@ func _store_roll(ctx: RollContext) -> void:
|
||||||
_store_decks()
|
_store_decks()
|
||||||
if ctx.persistent_changed:
|
if ctx.persistent_changed:
|
||||||
_store_variables()
|
_store_variables()
|
||||||
m.state.add_history({"collection": m.data.id, "root": m.current["root"], "root_name": m.current["root_name"],
|
var record := {"collection": m.data.id, "root": m.current["root"], "root_name": m.current["root_name"],
|
||||||
"time": m.current["time"], "steps": m.current["all"], "chain_vars": m.current.get("chain_vars", {})})
|
"time": m.current["time"], "steps": m.current["all"], "chain_vars": m.current.get("chain_vars", {})}
|
||||||
|
if replace:
|
||||||
|
m.state.replace_history(record)
|
||||||
|
else:
|
||||||
|
m.state.add_history(record)
|
||||||
m.state.save()
|
m.state.save()
|
||||||
|
|
||||||
|
|
||||||
|
## After "Reroll this": saves like _store_roll, but the current roll's history
|
||||||
|
## record is changed in place, not added again.
|
||||||
|
func replace_current_roll(ctx: RollContext) -> void:
|
||||||
|
_store_roll(ctx, true)
|
||||||
|
|
||||||
|
|
||||||
func _store_decks() -> void:
|
func _store_decks() -> void:
|
||||||
if m.state == null:
|
if m.state == null:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ var _scroll_to_end := false
|
||||||
var _why: WhyPopover
|
var _why: WhyPopover
|
||||||
## The "Why this?" buttons of the chips shown, by step index (tests).
|
## The "Why this?" buttons of the chips shown, by step index (tests).
|
||||||
var why_buttons: Dictionary = {}
|
var why_buttons: Dictionary = {}
|
||||||
|
## The "Reroll this" buttons of the chips shown, by step index (tests).
|
||||||
|
var reroll_buttons: Dictionary = {}
|
||||||
var _why_flag_done := false
|
var _why_flag_done := false
|
||||||
|
|
||||||
## A long chain shows only its last steps; the rest sit behind a toggle.
|
## A long chain shows only its last steps; the rest sit behind a toggle.
|
||||||
|
|
@ -197,6 +199,7 @@ func render() -> void:
|
||||||
_flow.remove_child(c)
|
_flow.remove_child(c)
|
||||||
c.queue_free()
|
c.queue_free()
|
||||||
why_buttons.clear()
|
why_buttons.clear()
|
||||||
|
reroll_buttons.clear()
|
||||||
if _why != null:
|
if _why != null:
|
||||||
_why.close()
|
_why.close()
|
||||||
_empty.visible = current.is_empty()
|
_empty.visible = current.is_empty()
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,8 @@ func _num_width(build: bool, ranged: bool) -> float:
|
||||||
return 100.0 if RangeWeights.uses_weights(table) else 90.0
|
return 100.0 if RangeWeights.uses_weights(table) else 90.0
|
||||||
if ranged:
|
if ranged:
|
||||||
return 52.0 if wide else 40.0
|
return 52.0 if wide else 40.0
|
||||||
|
if table.card_mode and not build:
|
||||||
|
return 50.0 # room for a partly drawn deck row's "<left> / <weight>"
|
||||||
return 24.0 if wide else 22.0
|
return 24.0 if wide else 22.0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ class_name TableCardSkin
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
## The card shell look: frame colour, drop/warning panels and scrollbars.
|
## The card shell look: frame colour, drop/warning panels and scrollbars.
|
||||||
|
|
||||||
|
## A deck row with no copies left: greyed out.
|
||||||
|
const DRAWN_LOOK := Color(0.7, 0.7, 0.7, 0.45)
|
||||||
|
|
||||||
var card: TableCard
|
var card: TableCard
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,8 +84,9 @@ func skin_scrollbar(bar: VScrollBar) -> void:
|
||||||
bar.add_theme_stylebox_override("grabber_pressed", grab_hi)
|
bar.add_theme_stylebox_override("grabber_pressed", grab_hi)
|
||||||
|
|
||||||
|
|
||||||
## Deck mode: results already drawn (none left in the deck) show faded until
|
## Deck mode: a result with no copies left is greyed out until the deck is
|
||||||
## the deck is shuffled.
|
## shuffled; one with some copies drawn is tinted in the accent colour and, in
|
||||||
|
## Play mode, shows "<left> / <weight>" in place of its number.
|
||||||
func dim_drawn() -> void:
|
func dim_drawn() -> void:
|
||||||
if not card.table.card_mode:
|
if not card.table.card_mode:
|
||||||
return
|
return
|
||||||
|
|
@ -91,10 +95,35 @@ func dim_drawn() -> void:
|
||||||
var row: Control = card.rows.get(e.id)
|
var row: Control = card.rows.get(e.id)
|
||||||
if row == null or not is_instance_valid(row):
|
if row == null or not is_instance_valid(row):
|
||||||
continue
|
continue
|
||||||
var held := card.main.rolling.deck_reveal.held(card.table.id, e.id)
|
var copies := DeckState.copies_of(card.table, e)
|
||||||
var gone := deck != null and deck.remaining(card.table, e) + held <= 0
|
var left := copies
|
||||||
row.modulate.a = 0.38 if gone else 1.0
|
if deck != null:
|
||||||
|
var held := card.main.rolling.deck_reveal.held(card.table.id, e.id)
|
||||||
|
left = mini(copies, deck.remaining(card.table, e) + held)
|
||||||
|
var gone := left <= 0
|
||||||
|
var partly := not gone and left < copies
|
||||||
|
row.modulate = DRAWN_LOOK if gone else Color.WHITE
|
||||||
|
row.self_modulate = partly_drawn_tint() if partly else Color.WHITE
|
||||||
row.tooltip_text = "Already drawn: Shuffle the deck to put it back" if gone else ""
|
row.tooltip_text = "Already drawn: Shuffle the deck to put it back" if gone else ""
|
||||||
|
_show_copies_left(e, left, copies, partly)
|
||||||
|
|
||||||
|
|
||||||
|
## The tint on a row with some of its copies drawn.
|
||||||
|
static func partly_drawn_tint() -> Color:
|
||||||
|
return Color.WHITE.lerp(Style.ACCENT, 0.55)
|
||||||
|
|
||||||
|
|
||||||
|
## Play mode: a partly drawn row's number becomes "<left> / <weight>".
|
||||||
|
func _show_copies_left(e: TableEntry, left: int, copies: int, partly: bool) -> void:
|
||||||
|
var part: Dictionary = card.rows_ui.parts.get(e.id, {})
|
||||||
|
var num: Label = part.get("num")
|
||||||
|
if num == null or not is_instance_valid(num):
|
||||||
|
return
|
||||||
|
if not num.has_meta("row_number"):
|
||||||
|
num.set_meta("row_number", [num.text, num.tooltip_text])
|
||||||
|
var own: Array = num.get_meta("row_number")
|
||||||
|
num.text = "%d / %d" % [left, copies] if partly else str(own[0])
|
||||||
|
num.tooltip_text = "%d of %d copies left in the deck" % [left, copies] if partly else str(own[1])
|
||||||
|
|
||||||
|
|
||||||
func build_styles() -> void:
|
func build_styles() -> void:
|
||||||
|
|
|
||||||
|
|
@ -66,11 +66,22 @@ static func chip(tray: ResultTray, step: Dictionary, last: bool, steps: Array =
|
||||||
var fx: Array = step.get("effects", [])
|
var fx: Array = step.get("effects", [])
|
||||||
if not fx.is_empty():
|
if not fx.is_empty():
|
||||||
v.add_child(_effect_lines(TrayText.effect_lines_for(step, main.data, plain)))
|
v.add_child(_effect_lines(TrayText.effect_lines_for(step, main.data, plain)))
|
||||||
|
var pills := HBoxContainer.new()
|
||||||
|
pills.add_theme_constant_override("separation", 6)
|
||||||
if has_why:
|
if has_why:
|
||||||
var wb := _why_button()
|
var wb := _pill_button("Why this?", "What decided this step")
|
||||||
wb.pressed.connect(func() -> void: tray.open_why(index, wb))
|
wb.pressed.connect(func() -> void: tray.open_why(index, wb))
|
||||||
tray.why_buttons[index] = wb
|
tray.why_buttons[index] = wb
|
||||||
v.add_child(wb)
|
pills.add_child(wb)
|
||||||
|
if index >= 0 and main.rolling.reroll.can_reroll(index):
|
||||||
|
var rb := _pill_button("↻ Reroll this", "Roll this card again, and the cards after it")
|
||||||
|
rb.pressed.connect(func() -> void: main.rolling.reroll.reroll(index))
|
||||||
|
tray.reroll_buttons[index] = rb
|
||||||
|
pills.add_child(rb)
|
||||||
|
if pills.get_child_count() > 0:
|
||||||
|
v.add_child(pills)
|
||||||
|
else:
|
||||||
|
pills.free()
|
||||||
if has_details or has_why:
|
if has_details or has_why:
|
||||||
p.mouse_entered.connect(func() -> void:
|
p.mouse_entered.connect(func() -> void:
|
||||||
if not tray.why_popover().visible:
|
if not tray.why_popover().visible:
|
||||||
|
|
@ -78,11 +89,11 @@ static func chip(tray: ResultTray, step: Dictionary, last: bool, steps: Array =
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
## The small "Why this?" pill under a chip.
|
## A small pill button under a chip ("Why this?", "Reroll this").
|
||||||
static func _why_button() -> Button:
|
static func _pill_button(text: String, tip: String) -> Button:
|
||||||
var b := Button.new()
|
var b := Button.new()
|
||||||
b.text = "Why this?"
|
b.text = text
|
||||||
b.tooltip_text = "What decided this step"
|
b.tooltip_text = tip
|
||||||
b.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
b.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
||||||
b.focus_mode = Control.FOCUS_NONE
|
b.focus_mode = Control.FOCUS_NONE
|
||||||
var n := Style.bordered(Style.box(Color.WHITE, 10, [9, 1, 9, 2]), 1, Style.RULE)
|
var n := Style.bordered(Style.box(Color.WHITE, 10, [9, 1, 9, 2]), 1, Style.RULE)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue