- Ranged roll tables take a modifier (dice_mod, e.g. @luck). Ranges may run past the dice (-3 to 24 on a d20); totals past the ends use the end result. - Range and chance code moved from RollTable into RollRange; chances follow the modifier's current value; plain wording and Why lines name it. - ModifierEditor builds modifiers in plain words for roll and check cards; the inspector's roll section is now InspectorRoll. - The Earlier tab scrolls; the tray and inspector resize with drag handles (PanelSplitter), sizes kept in local settings. - Demo Room check uses 2d6 + Luck with a luck-only vault; new test_modifier suite; docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
3.5 KiB
GDScript
114 lines
3.5 KiB
GDScript
class_name PanelSplitter
|
|
extends Control
|
|
## A drag handle between the board and a docked panel: above the result tray
|
|
## (dragged up and down) or left of the inspector (dragged left and right).
|
|
## Dragging toward the board makes the panel bigger. A double-click puts back
|
|
## the default size. The panel's size is kept in local settings under
|
|
## `setting` when the drag ends.
|
|
|
|
signal size_changed(px: float)
|
|
|
|
const THICK := 7.0
|
|
const GRIP := 36.0
|
|
|
|
var main: Main
|
|
## True for a handle dragged up and down (it sizes a panel's height).
|
|
var vertical := true
|
|
var setting := ""
|
|
var size_px := 0.0
|
|
var default_px := 0.0
|
|
var min_px := 0.0
|
|
## The panel never takes more than this share of the window.
|
|
var max_share := 0.7
|
|
|
|
var _dragging := false
|
|
var _hover := false
|
|
var _from := 0.0
|
|
var _start := 0.0
|
|
|
|
|
|
func _init(p_main: Main, p_vertical: bool, p_setting: String, p_default: float, p_min: float) -> void:
|
|
main = p_main
|
|
vertical = p_vertical
|
|
setting = p_setting
|
|
default_px = p_default
|
|
min_px = p_min
|
|
size_px = p_default
|
|
if main and main.state:
|
|
size_px = float(main.state.get_setting(setting, p_default))
|
|
custom_minimum_size = Vector2(0, THICK) if vertical else Vector2(THICK, 0)
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
mouse_default_cursor_shape = Control.CURSOR_VSIZE if vertical else Control.CURSOR_HSIZE
|
|
tooltip_text = "Drag to resize · double-click for the default size"
|
|
mouse_entered.connect(func() -> void:
|
|
_hover = true
|
|
queue_redraw()
|
|
)
|
|
mouse_exited.connect(func() -> void:
|
|
_hover = false
|
|
queue_redraw()
|
|
)
|
|
|
|
|
|
func _ready() -> void:
|
|
# A smaller window shrinks a panel that no longer fits.
|
|
get_viewport().size_changed.connect(func() -> void:
|
|
if size_px > max_px():
|
|
set_size_px(size_px)
|
|
)
|
|
if size_px > max_px():
|
|
set_size_px.call_deferred(size_px)
|
|
|
|
|
|
## The largest size allowed now: a share of the area the handle divides
|
|
## (its parent container), or of the window.
|
|
func max_px() -> float:
|
|
var area := Vector2(1600, 1000)
|
|
if get_parent() is Control and (get_parent() as Control).size != Vector2.ZERO:
|
|
area = (get_parent() as Control).size
|
|
elif is_inside_tree():
|
|
area = get_viewport_rect().size
|
|
return maxf(min_px, (area.y if vertical else area.x) * max_share)
|
|
|
|
|
|
## Sets the panel's size (clamped) and tells the panel. `save` stores it.
|
|
func set_size_px(px: float, save: bool = false) -> void:
|
|
size_px = clampf(px, min_px, max_px())
|
|
size_changed.emit(size_px)
|
|
if save and main and main.state:
|
|
main.state.set_setting(setting, roundi(size_px))
|
|
|
|
|
|
func _gui_input(ev: InputEvent) -> void:
|
|
if ev is InputEventMouseButton and (ev as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT:
|
|
var mb := ev as InputEventMouseButton
|
|
if mb.double_click:
|
|
_dragging = false
|
|
set_size_px(default_px, true)
|
|
elif mb.pressed:
|
|
_dragging = true
|
|
_from = _axis(mb.global_position)
|
|
_start = size_px
|
|
elif _dragging:
|
|
_dragging = false
|
|
set_size_px(size_px, true)
|
|
accept_event()
|
|
queue_redraw()
|
|
elif ev is InputEventMouseMotion and _dragging:
|
|
# The panel sits after the handle, so moving toward the board grows it.
|
|
set_size_px(_start - (_axis((ev as InputEventMouseMotion).global_position) - _from))
|
|
accept_event()
|
|
|
|
|
|
func _axis(p: Vector2) -> float:
|
|
return p.y if vertical else p.x
|
|
|
|
|
|
func _draw() -> void:
|
|
draw_rect(Rect2(Vector2.ZERO, size), Style.FELT_DEEP)
|
|
var lit := _hover or _dragging
|
|
var c := Style.BRASS if lit else Color(1, 1, 1, 0.18)
|
|
var mid := size / 2.0
|
|
var r := Rect2(mid - Vector2(GRIP / 2.0, 1.5), Vector2(GRIP, 3)) if vertical \
|
|
else Rect2(mid - Vector2(1.5, GRIP / 2.0), Vector2(3, GRIP))
|
|
draw_rect(r, c)
|