M6.8: Hybrid trait pickers (Phase B)

Per theriapolis-rpg-clades.md "Building a Hybrid": hybrids now pick
two clade traits from the dominant parent + one from the other (2/1
split keyed off DominantParent), and one species trait + one species
detriment from each parent. All clade detriments still inherit fully
from both parents. Universal hybrid detriments unchanged.

CharacterDraft gains six new fields (sire/dam clade-trait arrays,
sire/dam species trait/detriment ids) and a CladeTraitLimit(lineage)
helper. Step 0/1 validators enforce the picks; Aside renders only the
chosen subset for hybrids.

Cascading clears: clade swap clears that lineage's bonus + clade
traits + (if species also invalidated) species pick; species swap
clears that lineage's species trait/detriment; dominant flip trims
overflow from the end (non-destructive when possible); hybrid-off
clears all six new fields.

Toggle buttons in both steps wire MouseEntered/Exited into
PopoverLayer so the player can read each trait's description on
hover (detriment buttons get the red-tinted "DETRIMENT" popover).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Christopher Wiebe
2026-05-04 20:12:56 -07:00
parent e3f0296e6f
commit 8bf9eba2a7
5 changed files with 432 additions and 15 deletions
+177 -5
View File
@@ -32,6 +32,13 @@ public partial class StepClade : VBoxContainer, IStep
private HBoxContainer _sireBonusRow = null!;
private HBoxContainer _damBonusRow = null!;
// Phase B clade-trait pickers: 2 from dominant parent + 1 from non-dominant.
private VBoxContainer _traitSection = null!;
private VBoxContainer _sireTraitCol = null!;
private VBoxContainer _damTraitCol = null!;
private Label _sireTraitHeader = null!;
private Label _damTraitHeader = null!;
private readonly Dictionary<string, PanelContainer> _purebredCards = new();
private readonly Dictionary<string, PanelContainer> _sireCards = new();
private readonly Dictionary<string, PanelContainer> _damCards = new();
@@ -45,6 +52,11 @@ public partial class StepClade : VBoxContainer, IStep
private string _sireBonusBuiltFor = "";
private string _damBonusBuiltFor = "";
private readonly Dictionary<string, Button> _sireTraitButtons = new();
private readonly Dictionary<string, Button> _damTraitButtons = new();
private string _sireTraitsBuiltFor = "";
private string _damTraitsBuiltFor = "";
public void Bind(CharacterDraft draft)
{
_draft = draft;
@@ -134,6 +146,36 @@ public partial class StepClade : VBoxContainer, IStep
_dominantToggle.ItemSelected += OnDominantSelected;
dominantRow.AddChild(_dominantToggle);
// Phase B clade-trait pickers — per doc "2/1 split, player's choice
// of which parent is dominant". DominantParent drives the limit.
_traitSection = new VBoxContainer();
_traitSection.AddThemeConstantOverride("separation", 8);
_hybridSection.AddChild(_traitSection);
_traitSection.AddChild(new Label { Text = "CLADE TRAITS", ThemeTypeVariation = "Eyebrow" });
_traitSection.AddChild(new Label
{
Text = "Pick two clade traits from the dominant parent and one from the other. "
+ "All clade detriments from both parents are inherited automatically.",
AutowrapMode = TextServer.AutowrapMode.WordSmart,
});
var traitGrid = new HBoxContainer();
traitGrid.AddThemeConstantOverride("separation", 16);
traitGrid.SizeFlagsHorizontal = SizeFlags.ExpandFill;
_traitSection.AddChild(traitGrid);
_sireTraitCol = new VBoxContainer { SizeFlagsHorizontal = SizeFlags.ExpandFill };
_sireTraitCol.AddThemeConstantOverride("separation", 4);
traitGrid.AddChild(_sireTraitCol);
_sireTraitHeader = new Label { Text = "SIRE", ThemeTypeVariation = "Eyebrow" };
_sireTraitCol.AddChild(_sireTraitHeader);
_damTraitCol = new VBoxContainer { SizeFlagsHorizontal = SizeFlags.ExpandFill };
_damTraitCol.AddThemeConstantOverride("separation", 4);
traitGrid.AddChild(_damTraitCol);
_damTraitHeader = new Label { Text = "DAM", ThemeTypeVariation = "Eyebrow" };
_damTraitCol.AddChild(_damTraitHeader);
Refresh();
}
@@ -171,6 +213,12 @@ public partial class StepClade : VBoxContainer, IStep
patch["dam_species_id"] = "";
patch["sire_chosen_ability"] = "";
patch["dam_chosen_ability"] = "";
patch["sire_chosen_clade_traits"] = new Godot.Collections.Array<string>();
patch["dam_chosen_clade_traits"] = new Godot.Collections.Array<string>();
patch["sire_chosen_species_trait"] = "";
patch["dam_chosen_species_trait"] = "";
patch["sire_chosen_species_detriment"] = "";
patch["dam_chosen_species_detriment"] = "";
}
ClearBackgroundIfInvalidated(patch);
_draft.Patch(patch);
@@ -178,10 +226,28 @@ public partial class StepClade : VBoxContainer, IStep
private void OnDominantSelected(long index)
{
_draft.Patch(new Godot.Collections.Dictionary
string newDominant = index == 0 ? "sire" : "dam";
var patch = new Godot.Collections.Dictionary
{
{ "dominant_parent", index == 0 ? "sire" : "dam" },
});
{ "dominant_parent", newDominant },
};
// Trim clade-trait picks down to the new limit per side: 2 for the
// dominant lineage, 1 for the other. Only trims, never expands —
// user re-picks the missing slot manually.
TrimToLimit(patch, "sire", _draft.SireChosenCladeTraits, newDominant == "sire" ? 2 : 1);
TrimToLimit(patch, "dam", _draft.DamChosenCladeTraits, newDominant == "dam" ? 2 : 1);
_draft.Patch(patch);
}
private static void TrimToLimit(Godot.Collections.Dictionary patch, string lineage,
Godot.Collections.Array<string> current, int limit)
{
if (current.Count <= limit) return;
var trimmed = new Godot.Collections.Array<string>();
for (int i = 0; i < limit; i++) trimmed.Add(current[i]);
patch[lineage + "_chosen_clade_traits"] = trimmed;
}
private void Refresh()
@@ -200,7 +266,11 @@ public partial class StepClade : VBoxContainer, IStep
int dominantIdx = _draft.DominantParent == "dam" ? 1 : 0;
if (_dominantToggle.Selected != dominantIdx) _dominantToggle.Select(dominantIdx);
if (hybrid) RebuildBonusPickers();
if (hybrid)
{
RebuildBonusPickers();
RebuildTraitPickers();
}
}
/// <summary>
@@ -288,11 +358,17 @@ public partial class StepClade : VBoxContainer, IStep
string currentSpecies = lineage == "sire" ? _draft.SireSpeciesId : _draft.DamSpeciesId;
var sp = CodexContent.SpeciesById(currentSpecies);
if (sp is null || !string.Equals(sp.CladeId, cladeId, System.StringComparison.OrdinalIgnoreCase))
{
patch[lineage + "_species_id"] = "";
patch[lineage + "_chosen_species_trait"] = "";
patch[lineage + "_chosen_species_detriment"] = "";
}
// Clade swap invalidates the previously-picked lineage bonus
// (different clade has different mod options).
// (different clade has different mod options) and the clade
// trait picks.
patch[lineage + "_chosen_ability"] = "";
patch[lineage + "_chosen_clade_traits"] = new Godot.Collections.Array<string>();
ClearBackgroundIfInvalidated(patch);
_draft.Patch(patch);
@@ -306,6 +382,102 @@ public partial class StepClade : VBoxContainer, IStep
});
}
/// <summary>
/// Syncs both clade-trait columns. Header text reflects the current
/// limit (2 for dominant, 1 for other). Mutate-in-place same as
/// SyncLineageBonusRow — Free()-during-Pressed leaves stale buttons.
/// </summary>
private void RebuildTraitPickers()
{
SyncCladeTraitColumn(_sireTraitCol, _sireTraitHeader, _sireTraitButtons,
ref _sireTraitsBuiltFor, "sire", _draft.SireCladeId,
_draft.SireChosenCladeTraits, _draft.CladeTraitLimit("sire"));
SyncCladeTraitColumn(_damTraitCol, _damTraitHeader, _damTraitButtons,
ref _damTraitsBuiltFor, "dam", _draft.DamCladeId,
_draft.DamChosenCladeTraits, _draft.CladeTraitLimit("dam"));
}
private void SyncCladeTraitColumn(VBoxContainer col, Label header,
Dictionary<string, Button> cache,
ref string builtFor, string lineage,
string cladeId,
Godot.Collections.Array<string> chosen,
int limit)
{
string headerLabel = lineage.ToUpperInvariant() + (lineage == _draft.DominantParent ? " ★" : "");
header.Text = $"{headerLabel} ({chosen.Count}/{limit})";
if (cladeId == builtFor)
{
foreach (var (id, btn) in cache)
{
bool want = chosen.Contains(id);
if (btn.ButtonPressed != want) btn.SetPressedNoSignal(want);
bool atCap = chosen.Count >= limit && !want;
btn.Disabled = atCap;
}
return;
}
// Remove old buttons but keep the header (index 0).
for (int i = col.GetChildCount() - 1; i >= 1; i--) col.GetChild(i).Free();
cache.Clear();
builtFor = cladeId;
var clade = CodexContent.Clade(cladeId);
if (clade is null)
{
col.AddChild(new Label { Text = "(pick a clade above)" });
return;
}
foreach (var t in clade.Traits)
{
string captured = t.Id;
string capturedName = t.Name;
string capturedDesc = t.Description;
bool isPicked = chosen.Contains(t.Id);
var btn = new Button
{
Text = t.Name,
ToggleMode = true,
ButtonPressed = isPicked,
FocusMode = Control.FocusModeEnum.None,
Disabled = !isPicked && chosen.Count >= limit,
SizeFlagsHorizontal = SizeFlags.ExpandFill,
};
btn.Toggled += pressed => OnCladeTraitToggled(lineage, captured, pressed);
var btnRef = btn;
btn.MouseEntered += () =>
PopoverLayer.Instance?.ShowFor(btnRef, capturedName, capturedDesc, "trait", false);
btn.MouseExited += () =>
PopoverLayer.Instance?.ScheduleClose();
col.AddChild(btn);
cache[t.Id] = btn;
}
}
private void OnCladeTraitToggled(string lineage, string traitId, bool pressed)
{
var current = lineage == "sire" ? _draft.SireChosenCladeTraits : _draft.DamChosenCladeTraits;
int limit = _draft.CladeTraitLimit(lineage);
var next = new Godot.Collections.Array<string>(current);
if (pressed)
{
if (next.Contains(traitId)) return;
if (next.Count >= limit) return; // cap (UI also disables, defense-in-depth)
next.Add(traitId);
}
else
{
next.Remove(traitId);
}
_draft.Patch(new Godot.Collections.Dictionary
{
{ lineage + "_chosen_clade_traits", next },
});
}
/// <summary>
/// Clade changes can make a previously-valid background unavailable
/// (e.g. picking Felidae while Pack-Raised is selected). Build the