Snapshot for release 2026.10.28.2 (internal 48c46bd)
This commit is contained in:
parent
b23cabc338
commit
636adfcef2
41 changed files with 3402 additions and 120 deletions
|
|
@ -59,8 +59,9 @@ internal static class BarMapping
|
|||
/// Copies AC's 18 slots (<paramref name="ids"/>, <paramref name="spells"/>, slot 1 first) into the own
|
||||
/// slots 1-18, so an independent bar looks as the usual one did: the own slots that were after AC's
|
||||
/// (own N at bar 18+N) move to own 18+N, where an independent bar shows them. <see cref="BarCopyResult.Moved"/>
|
||||
/// lists the moves of the slots that held something (their "/rdef use N" keys go with them). A spell, or
|
||||
/// an item <paramref name="resolve"/> can't name, can't go in an own slot: that slot stays empty (Skipped).
|
||||
/// lists the moves of the slots that held something (their "/rdef use N" keys go with them). A spell goes
|
||||
/// in as a spell slot (2026-10-28); an item <paramref name="resolve"/> can't name can't go in an own slot:
|
||||
/// that slot stays empty (Skipped).
|
||||
/// Refused (nothing changed) when an own slot past 24 holds something: there is no room to move it.
|
||||
/// </summary>
|
||||
public static BarCopyResult CopyRetail(List<DefSlot> own, ReadOnlySpan<uint> ids, ReadOnlySpan<uint> spells, Func<uint, ItemRef?> resolve)
|
||||
|
|
@ -68,7 +69,7 @@ internal static class BarMapping
|
|||
const int retail = DefSettings.RetailSlots, room = DefSettings.SlotsMax - DefSettings.RetailSlots;
|
||||
for (int n = room + 1; n <= own.Count; n++)
|
||||
if (!own[n - 1].Empty)
|
||||
return new BarCopyResult(0, 0, Array.Empty<(int, int)>(), $"Your slot {n} holds {own[n - 1].Item!.FullName}: there is no room to move "
|
||||
return new BarCopyResult(0, 0, Array.Empty<(int, int)>(), $"Your slot {n} holds {own[n - 1].Label}: there is no room to move "
|
||||
+ $"slots {room + 1}-{DefSettings.SlotsMax} after the game's {retail}. Empty them (or copy by hand) first.");
|
||||
|
||||
var next = DefData.NewSlots();
|
||||
|
|
@ -85,7 +86,11 @@ internal static class BarMapping
|
|||
uint id = i < ids.Length ? ids[i] : 0, spell = i < spells.Length ? spells[i] : 0;
|
||||
if (id == 0)
|
||||
{
|
||||
if (spell != 0) skipped++;
|
||||
if (spell != 0)
|
||||
{
|
||||
next[i] = new DefSlot { SpellId = spell, SpellName = SpellTable.Name(spell) };
|
||||
copied++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ItemRef? r = resolve(id);
|
||||
|
|
@ -97,11 +102,12 @@ internal static class BarMapping
|
|||
return new BarCopyResult(copied, skipped, moved, null);
|
||||
}
|
||||
|
||||
/// <summary>How many of AC's slots hold an item (spells can't be copied, so they don't count).</summary>
|
||||
public static int RetailItems(ReadOnlySpan<uint> ids)
|
||||
/// <summary>How many of AC's slots hold an item or a spell (what a copy would bring over).</summary>
|
||||
public static int RetailShortcuts(ReadOnlySpan<uint> ids, ReadOnlySpan<uint> spells)
|
||||
{
|
||||
int n = 0;
|
||||
foreach (uint id in ids) if (id != 0) n++;
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
if (ids[i] != 0 || (i < spells.Length && spells[i] != 0)) n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
// the bar shows (DefSettings.BarSlots).
|
||||
// An independent bar (DefSettings.IndependentBar) has no AC slots: every slot
|
||||
// N is own slot N (BarMapping), and AC's toolbar isn't read at all.
|
||||
// An own slot can hold a spell (2026-10-28): its picture is the spell's, and
|
||||
// the snapshot carries the character's spells for the slot menu's search.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
|
|
@ -43,10 +45,17 @@ internal sealed record BarSlot(
|
|||
public bool Empty => ObjectId == 0 && SpellId == 0 && Name.Length == 0;
|
||||
}
|
||||
|
||||
/// <summary>The bar as drawn. Independent: every slot is RynthDefective's own (DefSettings.IndependentBar).</summary>
|
||||
internal sealed record BarSnapshot(BarSlot[] Slots, bool Ready, int IconSize, bool Independent = false)
|
||||
/// <summary>
|
||||
/// The bar as drawn. Independent: every slot is RynthDefective's own (DefSettings.IndependentBar).
|
||||
/// Spells: the character's spells, A-Z, for "Put a spell here..." (empty when they can't be read);
|
||||
/// CanCast: the engine casts for plugins.
|
||||
/// </summary>
|
||||
internal sealed record BarSnapshot(BarSlot[] Slots, bool Ready, int IconSize, bool Independent = false,
|
||||
IReadOnlyList<SpellInfo>? Spells = null, bool CanCast = false)
|
||||
{
|
||||
public static readonly BarSnapshot NotReady = new(Array.Empty<BarSlot>(), false, 36);
|
||||
|
||||
public IReadOnlyList<SpellInfo> KnownSpells => Spells ?? Array.Empty<SpellInfo>();
|
||||
}
|
||||
|
||||
/// <summary>Builds the snapshot on the plugin tick (reads the host and the carried items).</summary>
|
||||
|
|
@ -82,12 +91,14 @@ internal sealed class BarSnapshotBuilder
|
|||
{
|
||||
if (!_host.HasShortcuts) return BarSnapshot.NotReady;
|
||||
DefSettings st = session.Settings;
|
||||
IReadOnlyList<SpellInfo> spells = session.KnownSpells();
|
||||
bool canCast = _host.HasCastSpell;
|
||||
if (st.IndependentBar)
|
||||
{
|
||||
// Every slot is RynthDefective's own: AC's toolbar isn't read or shown (BarMapping).
|
||||
var own = new BarSlot[st.BarSlots];
|
||||
for (int n = 1; n <= st.BarSlots; n++) own[n - 1] = Own(n, BarMapping.OwnSlot(n, true), true, session, items, _host);
|
||||
return new BarSnapshot(own, true, st.ButtonSize, true);
|
||||
for (int n = 1; n <= st.BarSlots; n++) own[n - 1] = Own(n, BarMapping.OwnSlot(n, true), true, session, items, spells, _host);
|
||||
return new BarSnapshot(own, true, st.ButtonSize, true, spells, canCast);
|
||||
}
|
||||
if (_host.GetShortcuts(_ids, _spells) == 0) return BarSnapshot.NotReady;
|
||||
RefreshKeys(now);
|
||||
|
|
@ -96,8 +107,8 @@ internal sealed class BarSnapshotBuilder
|
|||
|
||||
var slots = new BarSlot[st.BarSlots];
|
||||
for (int n = 1; n <= st.BarSlots; n++)
|
||||
slots[n - 1] = BarMapping.IsRetail(n, false) ? Retail(n, byId) : Own(n, BarMapping.OwnSlot(n, false), false, session, items, _host);
|
||||
return new BarSnapshot(slots, true, st.ButtonSize);
|
||||
slots[n - 1] = BarMapping.IsRetail(n, false) ? Retail(n, byId) : Own(n, BarMapping.OwnSlot(n, false), false, session, items, spells, _host);
|
||||
return new BarSnapshot(slots, true, st.ButtonSize, false, spells, canCast);
|
||||
}
|
||||
|
||||
private BarSlot Retail(int n, Dictionary<uint, CarriedItem> byId)
|
||||
|
|
@ -123,13 +134,14 @@ internal sealed class BarSnapshotBuilder
|
|||
count = "none";
|
||||
tone = CountTone.Missing;
|
||||
}
|
||||
else name = $"Spell {spell}";
|
||||
else name = SpellTable.Name(spell);
|
||||
string tip = $"Slot {n} (the game's own): {name}{(count.Length > 0 ? " - " + count : "")}.{KeysLine(allKeys)}\n" +
|
||||
"Click: use it, as its key does. Right-click: change the slot or its keys.";
|
||||
return new BarSlot(n, true, 0, id, id == 0 ? spell : 0, name, count, tone, key, allKeys, tip);
|
||||
}
|
||||
|
||||
private static BarSlot Own(int n, int own, bool independent, DefSession session, IReadOnlyList<CarriedItem> items, RynthCoreHost host)
|
||||
private static BarSlot Own(int n, int own, bool independent, DefSession session, IReadOnlyList<CarriedItem> items,
|
||||
IReadOnlyList<SpellInfo> spells, RynthCoreHost host)
|
||||
{
|
||||
DefSlot slot = own >= 1 && own <= session.Data.Slots.Count ? session.Data.Slots[own - 1] : new DefSlot();
|
||||
// Every key of "/rdef use N" (the engine's hotkeys), else the one bound to the item by name.
|
||||
|
|
@ -137,9 +149,10 @@ internal sealed class BarSnapshotBuilder
|
|||
string key = all.Length > 0 ? FirstKey(all) : session.KeyOfSlot(own) ?? string.Empty;
|
||||
if (all.Length == 0) all = key;
|
||||
string whose = independent ? "RynthCore's: this bar is independent of the game's toolbar" : "RynthCore's: the game holds 18";
|
||||
if (slot.IsSpell) return OwnSpell(n, own, slot, whose, key, all, spells);
|
||||
if (slot.Item == null)
|
||||
return new BarSlot(n, false, own, 0, 0, string.Empty, string.Empty, CountTone.Plain, SlotText.ShortKey(key), all,
|
||||
$"Slot {n} ({whose}): empty.{KeysLine(all)}\nRight-click: put the selected item here, or change its keys.");
|
||||
$"Slot {n} ({whose}): empty.{KeysLine(all)}\nRight-click: put the selected item or one of your spells here, or change its keys.");
|
||||
SlotStatus s = ItemMatcher.Status(slot.Item, items);
|
||||
string count = SlotText.Count(s, out uint color);
|
||||
CountTone tone = color == SlotText.InHand ? CountTone.InHand : color == SlotText.Missing ? CountTone.Missing : CountTone.Plain;
|
||||
|
|
@ -149,6 +162,24 @@ internal sealed class BarSnapshotBuilder
|
|||
SlotText.ShortKey(key), all, tip);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A spell slot: the spell's picture and name. A spell the character doesn't know (another
|
||||
/// character's file, a spell lost) shows dimmed with "?" (when the spellbook can be read at all).
|
||||
/// </summary>
|
||||
private static BarSlot OwnSpell(int n, int own, DefSlot slot, string whose, string key, string all, IReadOnlyList<SpellInfo> spells)
|
||||
{
|
||||
string name = slot.SpellLabel;
|
||||
SpellInfo? info = SpellTable.TryGet(slot.SpellId, out SpellInfo si) ? si : null;
|
||||
bool known = spells.Count == 0;
|
||||
foreach (SpellInfo s in spells)
|
||||
if (s.Id == slot.SpellId) { known = true; break; }
|
||||
string tip = $"Slot {n}: {name}, a spell.\nClick or press the key: {SpellTargeting.Describe(info)} (Magic mode first)."
|
||||
+ (known ? "" : "\nYou don't know this spell: pressing it does nothing.")
|
||||
+ (key.Length > 0 ? "\nKey: " + key : "\nNo key yet.") + $"\n({whose}.)\nRight-click: change the slot or its keys.";
|
||||
return new BarSlot(n, false, own, 0, slot.SpellId, name, known ? string.Empty : "?", known ? CountTone.Plain : CountTone.Missing,
|
||||
SlotText.ShortKey(key), all, tip);
|
||||
}
|
||||
|
||||
/// <summary>The first of "1, Ctrl+1": what fits on the slot.</summary>
|
||||
private static string FirstKey(string keys)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,12 +25,16 @@
|
|||
// /rdef use N. A key comes off whatever had it, after the player says so.
|
||||
// An independent bar (DefSettings.IndependentBar) has only RynthDefective's
|
||||
// own slots: every key is an engine hotkey (BarMapping, BarSlot.Own).
|
||||
// Spells (2026-10-28): an own slot's menu has "Put a spell here...", a search
|
||||
// over the character's spells (the engine can't read the spell selected in
|
||||
// the game's spellbook); the slot then casts it (UseController).
|
||||
//
|
||||
// AC's render thread. Reads the snapshot the tick built; every click is
|
||||
// queued for the tick (IBarActions).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
|
|
@ -48,6 +52,8 @@ internal interface IBarActions
|
|||
void SetFromSelected(int number);
|
||||
void Clear(int number);
|
||||
void ChangeSlotCount(int delta);
|
||||
/// <summary>Puts spell <paramref name="spellId"/> in bar slot <paramref name="number"/> (one of RynthDefective's own).</summary>
|
||||
void SetSpell(int number, uint spellId);
|
||||
/// <summary>An item dragged out of AC's UI was let go over slot <paramref name="number"/>.</summary>
|
||||
void DropItem(int number, uint objectId);
|
||||
/// <summary>A key was bound or removed: the bar asks for its keys again.</summary>
|
||||
|
|
@ -155,6 +161,12 @@ internal sealed class ShortcutBarWindow
|
|||
ImGui.OpenPopup(KeyPopupId);
|
||||
}
|
||||
KeyPopup();
|
||||
if (_openSpellPopup)
|
||||
{
|
||||
_openSpellPopup = false;
|
||||
ImGui.OpenPopup(SpellPopupId);
|
||||
}
|
||||
SpellPopup(view);
|
||||
return height;
|
||||
}
|
||||
|
||||
|
|
@ -367,6 +379,15 @@ internal sealed class ShortcutBarWindow
|
|||
ImGui.Separator();
|
||||
bool hasSelection = _host.HasGetSelectedItemId && _host.GetSelectedItemId() != 0;
|
||||
if (ImGui.MenuItem("Put the selected item here", null, false, hasSelection)) _act.SetFromSelected(s.Number);
|
||||
if (!s.Retail)
|
||||
{
|
||||
if (ImGui.MenuItem("Put a spell here...", null, false, view.CanCast)) StartSpellPick(s);
|
||||
SafeImGui.SetItemTooltip(view.CanCast
|
||||
? "One of your spells, found by name: the slot casts it, in Magic mode, on the selection\n"
|
||||
+ "(on you for your own spells, or with nothing selected for a helpful one).\n"
|
||||
+ "The game doesn't tell RynthCore which spell is selected in its spellbook, so you find it here."
|
||||
: "This RynthCore can't cast spells for a plugin.");
|
||||
}
|
||||
if (ImGui.MenuItem("Empty this slot", null, false, !s.Empty)) _act.Clear(s.Number);
|
||||
ImGui.Separator();
|
||||
if (!_host.HasKeyBinding)
|
||||
|
|
@ -441,6 +462,95 @@ internal sealed class ShortcutBarWindow
|
|||
SafeImGui.SetItemTooltip(tip);
|
||||
}
|
||||
|
||||
// ── Spells: "Put a spell here..." ─────────────────────────────────────
|
||||
|
||||
private const string SpellPopupId = "##sb_spell_popup";
|
||||
private const int SpellRows = 40;
|
||||
private bool _openSpellPopup, _spellFocus;
|
||||
private BarSlot? _spellSlot;
|
||||
private string _spellSearch = string.Empty, _spellQuery = "\0";
|
||||
private IReadOnlyList<SpellInfo>? _spellSource;
|
||||
private List<SpellInfo> _spellMatches = new();
|
||||
private int _spellTotal;
|
||||
|
||||
private void StartSpellPick(BarSlot slot)
|
||||
{
|
||||
_spellSlot = slot;
|
||||
_spellSearch = string.Empty;
|
||||
_spellSource = null;
|
||||
_spellFocus = true;
|
||||
_openSpellPopup = true;
|
||||
}
|
||||
|
||||
private void SpellPopup(BarSnapshot view)
|
||||
{
|
||||
if (!ImGui.IsPopupOpen(SpellPopupId)) return;
|
||||
ImGui.PushStyleColor(ImGuiCol.PopupBg, WithAlpha(_bg, 0xFA));
|
||||
ImGui.PushStyleColor(ImGuiCol.Border, _line);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.PopupRounding, Px(4));
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(Px(8), Px(7)));
|
||||
bool open = ImGui.BeginPopup(SpellPopupId);
|
||||
ImGui.PopStyleVar(2);
|
||||
ImGui.PopStyleColor(2);
|
||||
if (!open) return;
|
||||
try
|
||||
{
|
||||
BarSlot? ss = _spellSlot;
|
||||
if (ss == null) { ImGui.CloseCurrentPopup(); return; }
|
||||
float w = Px(250), row = Px(20);
|
||||
ImGui.TextDisabled($"Slot {ss.Number}: a spell to cast");
|
||||
IReadOnlyList<SpellInfo> known = view.KnownSpells;
|
||||
if (_spellFocus)
|
||||
{
|
||||
ImGui.SetKeyboardFocusHere();
|
||||
_spellFocus = false;
|
||||
}
|
||||
ImGui.SetNextItemWidth(w);
|
||||
ImGui.InputTextWithHint("##sb_spell_search", "type a spell's name", ref _spellSearch, 64u);
|
||||
if (!ReferenceEquals(known, _spellSource) || _spellSearch != _spellQuery)
|
||||
{
|
||||
_spellSource = known;
|
||||
_spellQuery = _spellSearch;
|
||||
_spellMatches = SpellTable.Search(known, _spellSearch, SpellRows, out _spellTotal);
|
||||
}
|
||||
if (known.Count == 0) ImGui.TextDisabled("Your spells can't be read right now.");
|
||||
else
|
||||
{
|
||||
int shown = Math.Clamp(_spellMatches.Count, 1, 10);
|
||||
if (ImGui.BeginChild("##sb_spell_list", new Vector2(w, shown * (row + Px(2)) + Px(8)), ImGuiChildFlags.Borders))
|
||||
{
|
||||
foreach (SpellInfo sp in _spellMatches)
|
||||
{
|
||||
ImGui.PushID(unchecked((int)sp.Id));
|
||||
Vector2 start = ImGui.GetCursorPos();
|
||||
bool clicked = ImGui.Selectable("##sp", false, ImGuiSelectableFlags.AllowOverlap, new Vector2(0, row));
|
||||
SafeImGui.SetItemTooltip($"{sp.Name}: {SpellTargeting.Describe(sp)}.");
|
||||
ImGui.SetCursorPos(start);
|
||||
IntPtr tex = _host.GetIconTexture(RynthIconKind.Spell, sp.Id);
|
||||
if (tex != IntPtr.Zero) ImGui.Image(tex, new Vector2(row, row));
|
||||
else ImGui.Dummy(new Vector2(row, row));
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosY(start.Y + (row - ImGui.GetTextLineHeight()) * 0.5f);
|
||||
ImGui.TextUnformatted(sp.Name);
|
||||
ImGui.PopID();
|
||||
if (clicked)
|
||||
{
|
||||
_act.SetSpell(ss.Number, sp.Id);
|
||||
_spellSlot = null;
|
||||
ImGui.CloseCurrentPopup();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui.EndChild();
|
||||
if (_spellMatches.Count == 0) ImGui.TextDisabled("You know no spell by that name.");
|
||||
else if (_spellTotal > _spellMatches.Count) SafeImGui.TextDisabled($"{_spellTotal - _spellMatches.Count} more: type more of the name.");
|
||||
}
|
||||
if (ImGui.Button("Cancel")) { _spellSlot = null; ImGui.CloseCurrentPopup(); }
|
||||
}
|
||||
finally { ImGui.EndPopup(); }
|
||||
}
|
||||
|
||||
// ── Keys: "press a key" ───────────────────────────────────────────────
|
||||
|
||||
private enum KeyStep { Waiting, Confirm, Message }
|
||||
|
|
|
|||
Loading…
Reference in a new issue