104 lines
3.6 KiB
GDScript
104 lines
3.6 KiB
GDScript
class_name ChoiceChrome
|
|
extends RefCounted
|
|
## The extras around a ChoiceDialog: the preview panel, the Minimize button,
|
|
## the "Question waiting" pill and its toast.
|
|
|
|
var d: ChoiceDialog
|
|
|
|
|
|
func _init(dialog: ChoiceDialog) -> void:
|
|
d = dialog
|
|
|
|
|
|
func build() -> void:
|
|
d.preview_panel = PanelContainer.new()
|
|
d.preview_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
d.preview_panel.clip_contents = true
|
|
var sb := Style.box(Style.CARD, 10, [14, 11, 14, 12])
|
|
sb.border_width_top = 3
|
|
sb.border_color = Style.TRIM
|
|
sb.shadow_color = Color(0, 0, 0, 0.4)
|
|
sb.shadow_size = 16
|
|
sb.shadow_offset = Vector2(0, 6)
|
|
d.preview_panel.add_theme_stylebox_override("panel", sb)
|
|
d._preview_box = VBoxContainer.new()
|
|
d._preview_box.add_theme_constant_override("separation", 8)
|
|
d._preview_box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
d.preview_panel.add_child(d._preview_box)
|
|
d.preview_panel.hide()
|
|
d.add_child(d.preview_panel)
|
|
|
|
var min_btn := d.add_button("Minimize", "plain", d.minimize)
|
|
min_btn.tooltip_text = "Hide this question to look at the spread (M or Tab)"
|
|
d.footer.move_child(min_btn, 0)
|
|
var spacer := Control.new()
|
|
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
d.footer.add_child(spacer)
|
|
d.footer.move_child(spacer, 1)
|
|
|
|
d.pill = _bar_panel()
|
|
var row := d.pill.get_child(0) as HBoxContainer
|
|
var lbl := Style.make_label("Question waiting: " + d.title_label.text + " ·", Style.body_bold(), 15, Style.INK)
|
|
lbl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
row.add_child(lbl)
|
|
var show_btn := d.make_button("Show", "primary")
|
|
show_btn.add_theme_font_size_override("font_size", 14)
|
|
show_btn.pressed.connect(d.restore)
|
|
show_btn.tooltip_text = "Bring the question back (M)"
|
|
row.add_child(show_btn)
|
|
var x := d.make_button("Cancel", "plain")
|
|
x.add_theme_font_size_override("font_size", 14)
|
|
x.tooltip_text = "Cancel the question and stop this roll"
|
|
x.pressed.connect(func() -> void: d.answer(null))
|
|
row.add_child(x)
|
|
d.pill.hide()
|
|
d.add_child(d.pill)
|
|
|
|
d.toast_panel = _bar_panel()
|
|
var trow := d.toast_panel.get_child(0) as HBoxContainer
|
|
var tl := Style.make_label("", Style.body(), 15, Style.INK)
|
|
trow.add_child(tl)
|
|
d.toast_panel.set_meta("label", tl)
|
|
var ts := d.make_button("Show", "primary")
|
|
ts.add_theme_font_size_override("font_size", 14)
|
|
ts.pressed.connect(d.restore)
|
|
trow.add_child(ts)
|
|
d.toast_panel.hide()
|
|
d.add_child(d.toast_panel)
|
|
d._toast_timer = Timer.new()
|
|
d._toast_timer.one_shot = true
|
|
d._toast_timer.wait_time = 4.0
|
|
d._toast_timer.timeout.connect(func() -> void: d.toast_panel.hide())
|
|
d.add_child(d._toast_timer)
|
|
|
|
|
|
func _bar_panel() -> PanelContainer:
|
|
var p := PanelContainer.new()
|
|
var sb := Style.bordered(Style.box(Style.CARD, 12, [14, 7, 8, 7]), 1, Style.DASH)
|
|
sb.border_width_top = 3
|
|
sb.border_color = Style.TRIM
|
|
sb.shadow_color = Color(0, 0, 0, 0.4)
|
|
sb.shadow_size = 14
|
|
sb.shadow_offset = Vector2(0, 5)
|
|
p.add_theme_stylebox_override("panel", sb)
|
|
p.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 10)
|
|
p.add_child(row)
|
|
return p
|
|
|
|
|
|
## Bottom centre, above the result tray; the toast sits just above it.
|
|
func place_pill() -> void:
|
|
if not d.minimized:
|
|
return
|
|
d.pill.reset_size()
|
|
var bottom := d.size.y - 14.0
|
|
var m := d.get_parent() as Main
|
|
if m and m.tray and m.tray.is_inside_tree():
|
|
bottom = m.tray.get_global_rect().position.y - d.get_global_rect().position.y - 12.0
|
|
d.pill.position = Vector2(maxf(8.0, (d.size.x - d.pill.size.x) / 2.0), bottom - d.pill.size.y)
|
|
if d.toast_panel.visible:
|
|
d.toast_panel.reset_size()
|
|
d.toast_panel.position = Vector2(maxf(8.0, (d.size.x - d.toast_panel.size.x) / 2.0), d.pill.position.y - d.toast_panel.size.y - 8.0)
|
|
|