4d3db17a89
Per GODOT_PORTING_GUIDE.md §7, the highest-risk piece in the wizard.
Three reusable widgets + the orchestrating step.
Scenes/Widgets/AbilityToken.cs:
Draggable Control with Value + Origin metadata. _GetDragData returns
a Dictionary payload {kind, value, from, ability, idx} per guide
§7.1. MouseFilter = Pass so clicks propagate to the parent slot
for the click-to-return affordance (later removed; see commit body).
Drag preview is a dimmed duplicate.
Scenes/Widgets/AbilitySlot.cs:
PanelContainer drop target per guide §7.2. Accepts any
ability_value payload via _CanDropData / _DropData and emits
Dropped(payload). Each slot owns one ability id (STR/DEX/CON/INT/
WIS/CHA).
Scenes/Widgets/AbilityPool.cs:
HBoxContainer drop target per guide §7.3. Accepts only slot→pool
drops (returning an assigned value to the pool); pool→pool drops
are no-ops.
Scenes/Steps/StepStats.cs:
Direct port of StepStats in steps.jsx per guide §7.4. Standard
array (default) and roll-4d6-drop-lowest method tabs; Reroll
button visible in roll mode; Auto Assign sorts the remaining pool
descending and places the largest values into empty slots ordered
by class.PrimaryAbility. Three drag-drop cases (pool→slot,
slot→slot swap, slot→pool) all delegate to a single Patch call,
then the entire token tree rebuilds from the new draft state on
the Changed signal — handlers don't reparent anything manually.
Issues hit during development and resolved before commit:
- Initial click-to-return on slot pre-empted drag-from-slot every
time (the GuiInput fired on mouse-down, before Godot detected
the drag). Removed click-to-return — drag is the canonical
interaction; that matches the React prototype anyway.
- Token MouseFilter = Stop blocked clicks from reaching the slot
layer; switched to Pass which still works as a drag source.
- Refresh() teardown + rebuild reset the parent ScrollContainer's
scroll to 0 every drop. CallDeferred / SetDeferred / CreateTimer
all raced because layout settles over multiple frames; the fix
that worked was capturing scroll position pre-rebuild and
restoring in _Process the next frame.
Wizard.cs:
StepTypes[5] = typeof(StepStats); the Abilities step is now
reachable. (StepTypes[1..4, 6..7] still null — coming in M6.3+.)
Verified: all three drag scenarios + click handling + auto-assign
+ method switch + reroll work; scroll position holds across drops.
Closes M6.2. Next per guide §12: M6.3 — popover system (TraitChip +
shared PopoverLayer) before adding more easy card-grid steps.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using Godot;
|
|
|
|
namespace Theriapolis.GodotHost.Scenes.Widgets;
|
|
|
|
/// <summary>
|
|
/// Draggable ability-score token. Replaces the React prototype's
|
|
/// <c>.die</c> + filled <c>.slot</c> in <c>steps.jsx</c> per
|
|
/// GODOT_PORTING_GUIDE.md §7.1. Shows the int value as a centered
|
|
/// label; <c>_GetDragData</c> returns a Dictionary payload describing
|
|
/// where the token came from so the step can mutate CharacterDraft
|
|
/// accordingly.
|
|
///
|
|
/// Tokens are owned by either an AbilityPool (Origin == "pool",
|
|
/// OriginPoolIdx set) or an AbilitySlot (Origin == "slot",
|
|
/// OriginAbility set). Dropping a token rebuilds the StepStats UI from
|
|
/// the new draft state — token instances are short-lived.
|
|
/// </summary>
|
|
public partial class AbilityToken : PanelContainer
|
|
{
|
|
[Export] public int Value { get; set; }
|
|
[Export] public string Origin { get; set; } = "pool";
|
|
[Export] public string OriginAbility { get; set; } = "";
|
|
[Export] public int OriginPoolIdx { get; set; } = -1;
|
|
|
|
public override void _Ready()
|
|
{
|
|
CustomMinimumSize = new Vector2(56, 56);
|
|
// PASS so clicks propagate up to the parent AbilitySlot's GuiInput
|
|
// handler (click-to-return). Drag detection still triggers on the
|
|
// deepest non-IGNORE Control under the cursor, so PASS works for
|
|
// _GetDragData too.
|
|
MouseFilter = MouseFilterEnum.Pass;
|
|
|
|
var label = new Label
|
|
{
|
|
Text = Value.ToString(),
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
MouseFilter = MouseFilterEnum.Ignore,
|
|
};
|
|
label.AddThemeFontSizeOverride("font_size", 22);
|
|
AddChild(label);
|
|
}
|
|
|
|
public override Variant _GetDragData(Vector2 atPosition)
|
|
{
|
|
// Drag preview — a dimmed duplicate of the token.
|
|
var preview = new Panel { CustomMinimumSize = new Vector2(56, 56) };
|
|
var lbl = new Label
|
|
{
|
|
Text = Value.ToString(),
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
};
|
|
lbl.AddThemeFontSizeOverride("font_size", 22);
|
|
lbl.AnchorRight = 1f;
|
|
lbl.AnchorBottom = 1f;
|
|
preview.AddChild(lbl);
|
|
preview.Modulate = new Color(1, 1, 1, 0.85f);
|
|
SetDragPreview(preview);
|
|
|
|
return new Godot.Collections.Dictionary
|
|
{
|
|
{ "kind", "ability_value" },
|
|
{ "value", Value },
|
|
{ "from", Origin },
|
|
{ "ability", OriginAbility },
|
|
{ "idx", OriginPoolIdx },
|
|
};
|
|
}
|
|
}
|