44 lines
1.7 KiB
GDScript
44 lines
1.7 KiB
GDScript
class_name TrayWhy
|
|
extends RefCounted
|
|
## Opens the result tray's "Why this?" pop-over (WhyPopover): from a chip's
|
|
## button, or once after a roll when the app was started with --why
|
|
## (for screenshots). ResultTray.open_why() calls open().
|
|
|
|
|
|
## Opens (or, from the same button, closes) the Why pop-over for steps[index].
|
|
static func open(tray: ResultTray, index: int, from: Control = null) -> void:
|
|
var popover := tray._why
|
|
if popover.visible and from != null and popover.opener == from:
|
|
popover.close()
|
|
return
|
|
var steps: Array = tray.main.current.get("steps", [])
|
|
if index < 0 or index >= steps.size():
|
|
return
|
|
tray.main.details().hide_for()
|
|
var at := Rect2(tray.global_position + Vector2(20, 20), Vector2.ZERO)
|
|
var chip: Control = null
|
|
if from != null:
|
|
# Above the whole chip, so it never hides the step it explains.
|
|
chip = from.get_parent().get_parent() as Control
|
|
at = chip.get_global_rect() if chip != null else from.get_global_rect()
|
|
popover.open(steps, index, tray.main.data, RulesView.plain(tray.main), at, from, chip)
|
|
|
|
|
|
## --why[=<step index>]: opens the Why pop-over once after a roll (screenshots).
|
|
static func open_from_flag(tray: ResultTray) -> void:
|
|
for arg in OS.get_cmdline_user_args():
|
|
if arg == "--why" or arg.begins_with("--why="):
|
|
tray._why_flag_done = true
|
|
await tray.get_tree().create_timer(0.4).timeout
|
|
if not tray.main.current.get("done", false):
|
|
tray._why_flag_done = false # a new roll began; wait for it to end
|
|
return
|
|
var at := -1
|
|
if arg == "--why":
|
|
for step_index: int in tray.why_buttons:
|
|
at = maxi(at, step_index)
|
|
else:
|
|
at = arg.get_slice("=", 1).to_int()
|
|
if tray.why_buttons.has(at):
|
|
(tray.why_buttons[at] as Button).emit_signal("pressed")
|
|
return
|