Snapshot for release 2026.10.23.1 (internal 7581cff)
This commit is contained in:
parent
893973d0dd
commit
92f28bd243
73 changed files with 12203 additions and 308 deletions
195
Plugins/RynthCore.Plugin.RynthDefective/Views/BarView.cs
Normal file
195
Plugins/RynthCore.Plugin.RynthDefective/Views/BarView.cs
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthDefective.Items;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.Plugin.RynthDefective.Ui;
|
||||
using RynthCore.Plugin.RynthDefective.Use;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Views;
|
||||
|
||||
/// <summary>
|
||||
/// The item bar window: a grid of slot buttons (the item's picture, its count or uses left, its key
|
||||
/// under it), a row with Edit, Settings and Weapons, and the status line. Edit opens the slot editor
|
||||
/// below (set a slot from the item selected in the game, pick one from the pack, how it is used,
|
||||
/// its key); Settings the sizes and switches. Recorded on the pump thread, replayed by the engine.
|
||||
/// </summary>
|
||||
internal sealed class BarView
|
||||
{
|
||||
/// <summary>Logical units a button needs besides its picture: the frame padding and the gap to the next.</summary>
|
||||
public const float CellExtra = 16f;
|
||||
|
||||
private readonly DefSession _s;
|
||||
private readonly SlotEditor _editor;
|
||||
private readonly SettingsPanel _settings;
|
||||
|
||||
public bool EditOpen, SettingsOpen;
|
||||
|
||||
/// <summary>The window should be sized to its content (a setting changed, a section opened).</summary>
|
||||
public Action RequestFit = () => { };
|
||||
/// <summary>Show the weapon picker window.</summary>
|
||||
public Action ShowPicker = () => { };
|
||||
|
||||
public BarView(DefSession session)
|
||||
{
|
||||
_s = session;
|
||||
_editor = new SlotEditor(session);
|
||||
_settings = new SettingsPanel(session, () => RequestFit());
|
||||
}
|
||||
|
||||
public SlotEditor Editor => _editor;
|
||||
|
||||
/// <summary>The window size that fits the grid (and the sections that are open), in logical units.</summary>
|
||||
public (float W, float H) WantedSize()
|
||||
{
|
||||
DefSettings st = _s.Settings;
|
||||
int perRow = Math.Min(st.SlotsPerRow, st.SlotCount);
|
||||
int rows = (st.SlotCount + st.SlotsPerRow - 1) / st.SlotsPerRow;
|
||||
float cell = st.ButtonSize + CellExtra;
|
||||
float w = Math.Max(250f, perRow * cell + 28f);
|
||||
float h = rows * (st.ButtonSize + (st.ShowCounts ? 50f : 14f)) + 70f;
|
||||
if (EditOpen) { h += 330f; w = Math.Max(w, 330f); }
|
||||
if (SettingsOpen) h += 230f;
|
||||
return (w, h);
|
||||
}
|
||||
|
||||
public void Draw(UiWindow w)
|
||||
{
|
||||
if (!_s.LoggedIn)
|
||||
{
|
||||
w.TextDisabled("Log in to use the item bar.");
|
||||
return;
|
||||
}
|
||||
IReadOnlyList<CarriedItem> items = _s.Items();
|
||||
DrawGrid(w, items);
|
||||
DrawToolbar(w);
|
||||
DrawStatus(w);
|
||||
if (EditOpen)
|
||||
{
|
||||
w.Separator();
|
||||
_editor.Draw(w, items);
|
||||
}
|
||||
if (SettingsOpen)
|
||||
{
|
||||
w.Separator();
|
||||
_settings.Draw(w);
|
||||
}
|
||||
}
|
||||
|
||||
// ── The grid ────────────────────────────────────────────────────────────
|
||||
|
||||
private void DrawGrid(UiWindow w, IReadOnlyList<CarriedItem> items)
|
||||
{
|
||||
DefSettings st = _s.Settings;
|
||||
float size = st.ButtonSize;
|
||||
float pitch = size + CellExtra;
|
||||
var labels = new List<(string Text, uint Color)>();
|
||||
var keys = new List<string>();
|
||||
for (int rowStart = 0; rowStart < st.SlotCount; rowStart += st.SlotsPerRow)
|
||||
{
|
||||
int end = Math.Min(st.SlotCount, rowStart + st.SlotsPerRow);
|
||||
labels.Clear();
|
||||
keys.Clear();
|
||||
for (int i = rowStart; i < end; i++)
|
||||
{
|
||||
if (i > rowStart) w.SameLine();
|
||||
DrawSlotButton(w, i + 1, items, size, out string text, out uint color, out string key);
|
||||
labels.Add((text, color));
|
||||
keys.Add(key);
|
||||
}
|
||||
if (!st.ShowCounts) continue;
|
||||
for (int j = 0; j < labels.Count; j++)
|
||||
{
|
||||
if (j > 0) w.SameLine(j * pitch);
|
||||
w.TextColored(labels[j].Color, labels[j].Text.Length > 0 ? labels[j].Text : " ");
|
||||
}
|
||||
for (int j = 0; j < keys.Count; j++)
|
||||
{
|
||||
if (j > 0) w.SameLine(j * pitch);
|
||||
w.TextColored(SlotText.KeyColor, keys[j].Length > 0 ? keys[j] : " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSlotButton(UiWindow w, int number, IReadOnlyList<CarriedItem> items, float size,
|
||||
out string text, out uint color, out string key)
|
||||
{
|
||||
DefSlot slot = _s.Data.Slots[number - 1];
|
||||
string id = "slot" + number;
|
||||
string? keyFull = _s.KeyOfSlot(number);
|
||||
key = SlotText.ShortKey(keyFull);
|
||||
text = string.Empty;
|
||||
color = SlotText.Plain;
|
||||
bool icons = _s.Settings.ShowIcons && _s.IconsAvailable;
|
||||
|
||||
if (slot.Item == null)
|
||||
{
|
||||
w.Button("+", id, () => Choose(number), size + 8f, size + 8f);
|
||||
w.Tooltip(SlotText.Tooltip(number, null, default, slot.Mode, keyFull));
|
||||
return;
|
||||
}
|
||||
|
||||
SlotStatus s = ItemMatcher.Status(slot.Item, items);
|
||||
text = SlotText.Count(s, out color);
|
||||
string tip = SlotText.Tooltip(number, slot.Item, s, slot.Mode, keyFull);
|
||||
bool busy = _s.Use.Involves(slot.Item);
|
||||
bool inHand = s.Item is { Wielded: true };
|
||||
uint? fill = busy ? SlotText.Waiting : inHand ? UiFormat.Rgb(40, 110, 40) : null;
|
||||
|
||||
if (icons && s.Item != null)
|
||||
{
|
||||
w.ImageButton(UiFormat.IconKindObject, s.Item.Id, id, () => Press(number), size, size, 0xFFFFFFFFu, fill ?? 0u);
|
||||
}
|
||||
else if (icons && slot.Item.Icon != 0)
|
||||
{
|
||||
// Not carried: the last picture seen, dimmed.
|
||||
w.ImageButton(UiFormat.IconKindIcon, slot.Item.Icon, id, () => Press(number), size, size, UiFormat.Rgb(255, 255, 255, 90));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fill != null) w.PushStyleColor(UiFormat.ColButton, fill.Value);
|
||||
else if (s.Item == null) w.PushStyleColor(UiFormat.ColText, SlotText.Missing);
|
||||
w.Button(SlotText.Abbreviation(slot.Item.FullName), id, () => Press(number), size + 8f, size + 8f);
|
||||
if (fill != null) w.PopStyleColor();
|
||||
else if (s.Item == null) w.PopStyleColor();
|
||||
}
|
||||
w.Tooltip(tip);
|
||||
}
|
||||
|
||||
private void Press(int number)
|
||||
{
|
||||
string? problem = _s.UseSlot(number);
|
||||
if (problem != null) _s.SetStatus(problem, warning: true);
|
||||
}
|
||||
|
||||
/// <summary>An empty slot's button: open the editor on it.</summary>
|
||||
private void Choose(int number)
|
||||
{
|
||||
if (!EditOpen) { EditOpen = true; RequestFit(); }
|
||||
_editor.Select(number);
|
||||
}
|
||||
|
||||
// ── Toolbar and status ──────────────────────────────────────────────────
|
||||
|
||||
private void DrawToolbar(UiWindow w)
|
||||
{
|
||||
w.ToggleButton("Edit slots", "tb.edit", EditOpen, () => { EditOpen = !EditOpen; RequestFit(); }, small: true);
|
||||
w.SameLine();
|
||||
w.ToggleButton("Settings", "tb.settings", SettingsOpen, () => { SettingsOpen = !SettingsOpen; RequestFit(); }, small: true);
|
||||
w.SameLine();
|
||||
w.SmallButton("Weapons", "tb.weapons", () => ShowPicker());
|
||||
w.Tooltip("The weapon picker: every weapon and wand you carry, one click to wield (/rdef weapons)");
|
||||
}
|
||||
|
||||
private void DrawStatus(UiWindow w)
|
||||
{
|
||||
UseRequest? pending = _s.Use.Pending;
|
||||
if (pending != null)
|
||||
{
|
||||
w.TextColored(SlotText.Waiting, $"Waiting to use {pending.Label}...");
|
||||
return;
|
||||
}
|
||||
string status = _s.Status(out bool warning);
|
||||
if (status.Length > 0) w.TextColored(warning ? SlotText.Missing : SlotText.Plain, status);
|
||||
else w.TextDisabled("Click a slot, or press its key.");
|
||||
}
|
||||
}
|
||||
118
Plugins/RynthCore.Plugin.RynthDefective/Views/PickerView.cs
Normal file
118
Plugins/RynthCore.Plugin.RynthDefective/Views/PickerView.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthDefective.Items;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.Plugin.RynthDefective.Ui;
|
||||
using RynthCore.Plugin.RynthDefective.Use;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Views;
|
||||
|
||||
/// <summary>
|
||||
/// The weapon picker window, for picking among dozens of weapons while playing by hand: a search
|
||||
/// box, a row of kind buttons (All, Melee, Missile, War, Void - the kind the player prefers is kept),
|
||||
/// then the carried weapons and wands as big rows with their picture. Favourites and the recently
|
||||
/// wielded come first; below them every kind, A-Z. One click on a row wields it; the weapon in hand
|
||||
/// is highlighted. The "+" / "-" in front of a row adds or takes out a favourite.
|
||||
/// </summary>
|
||||
internal sealed class PickerView
|
||||
{
|
||||
private static readonly uint InHandColor = UiFormat.Rgb(110, 210, 110);
|
||||
private static readonly uint ElementColor = UiFormat.Rgb(150, 185, 235);
|
||||
|
||||
private readonly DefSession _s;
|
||||
|
||||
public string Search = string.Empty;
|
||||
|
||||
public PickerView(DefSession session) => _s = session;
|
||||
|
||||
public void Draw(UiWindow w)
|
||||
{
|
||||
if (!_s.LoggedIn)
|
||||
{
|
||||
w.TextDisabled("Log in to pick a weapon.");
|
||||
return;
|
||||
}
|
||||
DefSettings st = _s.Settings;
|
||||
IReadOnlyList<CarriedItem> items = _s.Items();
|
||||
PickerModel m = WeaponPicker.Build(items, _s.Data.Favourites, _s.Data.Recent, Search, st.PreferredKind);
|
||||
|
||||
w.InputText("Search", "pk.search", Search, 48, v => Search = v);
|
||||
w.Tooltip("Words in the name, the element or the kind: \"fire wand\", \"axe\", \"void\".");
|
||||
foreach (KindFilter f in Enum.GetValues<KindFilter>())
|
||||
{
|
||||
KindFilter kind = f;
|
||||
w.ToggleButton(WeaponPicker.KindLabel(f), "pk.kind" + (int)f, st.PreferredKind == f, () =>
|
||||
{
|
||||
st.PreferredKind = kind;
|
||||
_s.Save();
|
||||
}, small: true);
|
||||
w.SameLine();
|
||||
}
|
||||
w.SmallButton("Clear", "pk.clear", () => Search = string.Empty);
|
||||
w.Tooltip("Clears the search. The kind button you leave pressed is remembered.");
|
||||
|
||||
DrawHand(w, items);
|
||||
if (st.PreferredKind != KindFilter.All || Search.Length > 0)
|
||||
w.TextDisabled($"{m.Shown} of {m.Total} shown");
|
||||
|
||||
w.BeginChild("pk.list", 0f, 0f, true);
|
||||
float icon = st.PickerIconSize;
|
||||
bool icons = st.ShowIcons && _s.IconsAvailable;
|
||||
if (m.Favourites.Count > 0)
|
||||
{
|
||||
w.SeparatorText("Favourites");
|
||||
foreach (PickerRow r in m.Favourites) DrawRow(w, r, "f", icon, icons, showElement: true);
|
||||
}
|
||||
if (m.Recent.Count > 0)
|
||||
{
|
||||
w.SeparatorText("Recent");
|
||||
foreach (PickerRow r in m.Recent) DrawRow(w, r, "r", icon, icons, showElement: true);
|
||||
}
|
||||
foreach (PickerGroup g in m.Groups)
|
||||
{
|
||||
w.SeparatorText($"{ItemKinds.Label(g.Group)} ({g.Rows.Count})");
|
||||
foreach (PickerRow r in g.Rows) DrawRow(w, r, "g", icon, icons, showElement: g.Group is WeaponGroup.WarMagic or WeaponGroup.VoidMagic);
|
||||
}
|
||||
if (m.Groups.Count == 0)
|
||||
w.TextDisabled(m.Total == 0 ? "No weapons or wands in your pack." : "Nothing matches. Clear the search or pick All.");
|
||||
w.EndChild();
|
||||
}
|
||||
|
||||
/// <summary>What is in the hands now, and the item's name for the title line.</summary>
|
||||
private void DrawHand(UiWindow w, IReadOnlyList<CarriedItem> items)
|
||||
{
|
||||
string hand = string.Empty;
|
||||
foreach (CarriedItem it in items)
|
||||
{
|
||||
if (!it.Wielded) continue;
|
||||
ItemKind k = ItemKinds.Classify(it);
|
||||
if (!ItemKinds.IsWeapon(k) && k != ItemKind.Shield) continue;
|
||||
hand += (hand.Length > 0 ? ", " : string.Empty) + it.FullName;
|
||||
}
|
||||
UseRequest? pending = _s.Use.Pending;
|
||||
if (pending != null) w.TextColored(SlotText.Waiting, $"Waiting to wield {pending.Label}...");
|
||||
else w.TextColored(hand.Length > 0 ? InHandColor : SlotText.Plain, "In hand: " + (hand.Length > 0 ? hand : "nothing"));
|
||||
}
|
||||
|
||||
private void DrawRow(UiWindow w, PickerRow r, string section, float icon, bool icons, bool showElement)
|
||||
{
|
||||
CarriedItem it = r.Item;
|
||||
string idKey = section + it.Id;
|
||||
ItemRef reference = ItemRef.From(it);
|
||||
|
||||
w.SmallButton(r.Favourite ? "-" : "+", "fav" + idKey, () => _s.SetStatus(_s.ToggleFavourite(reference)));
|
||||
w.Tooltip(r.Favourite ? "Take out of the favourites" : "Add to the favourites (listed first)");
|
||||
w.SameLine();
|
||||
if (icons)
|
||||
{
|
||||
w.Image(UiFormat.IconKindObject, it.Id, icon, icon);
|
||||
w.SameLine();
|
||||
}
|
||||
string label = it.FullName;
|
||||
if (showElement && r.Element.Length > 0) label += $" ({r.Element})";
|
||||
if (r.InHand) label += " [in hand]";
|
||||
if (r.InHand) w.PushStyleColor(UiFormat.ColText, InHandColor);
|
||||
w.Selectable(label, "pk" + idKey, r.InHand, () => _s.Wield(reference), 0f, icons ? icon : 0f);
|
||||
if (r.InHand) w.PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.Plugin.RynthDefective.Ui;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Views;
|
||||
|
||||
/// <summary>The settings under the bar: how many slots and how big, what is shown, and the credit.</summary>
|
||||
internal sealed class SettingsPanel
|
||||
{
|
||||
/// <summary>The credit line, in the plugin's about text and the README.</summary>
|
||||
public const string Credit =
|
||||
"RynthDefective is an independent implementation of the ideas of Defective, the Decal item-bar plugin written by "
|
||||
+ "Hazridi and modified by Aun (github.com/aunrela/Defective). It contains no code from it.";
|
||||
|
||||
private readonly DefSession _s;
|
||||
private readonly Action _fit;
|
||||
|
||||
public SettingsPanel(DefSession session, Action fit)
|
||||
{
|
||||
_s = session;
|
||||
_fit = fit;
|
||||
}
|
||||
|
||||
public void Draw(UiWindow w)
|
||||
{
|
||||
DefSettings st = _s.Settings;
|
||||
void Changed(bool fit)
|
||||
{
|
||||
st.Clamp();
|
||||
_s.Save();
|
||||
if (fit) _fit();
|
||||
}
|
||||
|
||||
w.SeparatorText("Settings");
|
||||
w.SliderInt("Slots", "set.slots", st.SlotCount, DefSettings.SlotsMin, DefSettings.SlotsMax, v => { st.SlotCount = v; Changed(true); });
|
||||
w.SliderInt("Slots per row", "set.perrow", st.SlotsPerRow, DefSettings.PerRowMin, DefSettings.PerRowMax, v => { st.SlotsPerRow = v; Changed(true); });
|
||||
w.SliderInt("Button size", "set.button", st.ButtonSize, DefSettings.ButtonMin, DefSettings.ButtonMax, v => { st.ButtonSize = v; Changed(true); });
|
||||
w.SliderInt("Picker row icon", "set.picker", st.PickerIconSize, DefSettings.PickerIconMin, DefSettings.PickerIconMax, v => { st.PickerIconSize = v; Changed(false); });
|
||||
w.Checkbox("Show item icons", "set.icons", st.ShowIcons, v => { st.ShowIcons = v; Changed(false); });
|
||||
w.Tooltip(_s.IconsAvailable ? "Off: the slots are text buttons." : "This engine can't draw item pictures (it needs script window op level 2): the slots are text buttons.");
|
||||
w.Checkbox("Show counts and keys under the slots", "set.counts", st.ShowCounts, v => { st.ShowCounts = v; Changed(true); });
|
||||
w.Checkbox("Allow weapon swaps while RynthAi's macro runs", "set.swap", st.SwapWhileBotRuns, v => { st.SwapWhileBotRuns = v; Changed(false); });
|
||||
w.Tooltip("Off (the default): a weapon, wand or shield is not wielded while the RynthAi macro runs - it picks the weapon itself and would swap back. Kits, potions and other items always work.");
|
||||
|
||||
w.SeparatorText("About");
|
||||
w.TextWrapped(Credit);
|
||||
w.TextDisabled("Commands: /rdef (show or hide), /rdef use <slot or name>, /rdef weapons, /rdef help.");
|
||||
}
|
||||
}
|
||||
172
Plugins/RynthCore.Plugin.RynthDefective/Views/SlotEditor.cs
Normal file
172
Plugins/RynthCore.Plugin.RynthDefective/Views/SlotEditor.cs
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthDefective.Items;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.Plugin.RynthDefective.Ui;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Views;
|
||||
|
||||
/// <summary>
|
||||
/// The slot editor under the bar: every slot as a row (picture, name, key), and for the one picked
|
||||
/// its buttons - Set from selected (the item selected in the game goes in the slot), Pick from pack
|
||||
/// (a searchable list of what is carried), Clear, move up and down - how pressing it uses the item,
|
||||
/// and its key (typed here, bound through the engine's hotkeys as "/rdef use N" or by the item's name).
|
||||
/// </summary>
|
||||
internal sealed class SlotEditor
|
||||
{
|
||||
private const float RowIcon = 22f;
|
||||
private const int PackRows = 40;
|
||||
|
||||
private readonly DefSession _s;
|
||||
private int _selected = 1;
|
||||
private bool _picking;
|
||||
private string _packSearch = string.Empty;
|
||||
private string _keyDraft = string.Empty;
|
||||
private string _note = string.Empty;
|
||||
|
||||
public SlotEditor(DefSession session) => _s = session;
|
||||
|
||||
public int SelectedSlot => _selected;
|
||||
public bool Picking => _picking;
|
||||
public string Note => _note;
|
||||
|
||||
public void Select(int number)
|
||||
{
|
||||
_selected = Math.Clamp(number, 1, DefSettings.SlotsMax);
|
||||
_picking = false;
|
||||
_keyDraft = string.Empty;
|
||||
_note = string.Empty;
|
||||
}
|
||||
|
||||
private void Say(string text)
|
||||
{
|
||||
_note = text;
|
||||
_s.SetStatus(text);
|
||||
}
|
||||
|
||||
public void Draw(UiWindow w, IReadOnlyList<CarriedItem> items)
|
||||
{
|
||||
DefSettings st = _s.Settings;
|
||||
if (_selected > st.SlotCount) _selected = st.SlotCount;
|
||||
bool icons = st.ShowIcons && _s.IconsAvailable;
|
||||
|
||||
w.TextDisabled("Pick a slot, then set it from the item selected in the game or from your pack.");
|
||||
w.BeginChild("slotlist", 0f, Math.Min(st.SlotCount, 6) * (RowIcon + 6f) + 8f, true);
|
||||
for (int n = 1; n <= st.SlotCount; n++)
|
||||
{
|
||||
DefSlot slot = _s.Data.Slots[n - 1];
|
||||
int number = n;
|
||||
string? key = _s.KeyOfSlot(n);
|
||||
string name = slot.Item == null ? "(empty)" : slot.Item.FullName;
|
||||
if (icons)
|
||||
{
|
||||
CarriedItem? have = slot.Item == null ? null : ItemMatcher.Find(slot.Item, items, out _);
|
||||
if (have != null) w.Image(UiFormat.IconKindObject, have.Id, RowIcon, RowIcon);
|
||||
else if (slot.Item != null && slot.Item.Icon != 0) w.Image(UiFormat.IconKindIcon, slot.Item.Icon, RowIcon, RowIcon, UiFormat.Rgb(255, 255, 255, 90));
|
||||
else w.Dummy(RowIcon, RowIcon);
|
||||
w.SameLine();
|
||||
}
|
||||
string label = $"{n}. {name}" + (key != null ? $" [{key}]" : string.Empty);
|
||||
w.Selectable(label, "row" + n, _selected == n, () => Select(number), 0f, icons ? RowIcon : 0f);
|
||||
}
|
||||
w.EndChild();
|
||||
|
||||
DrawSlot(w, items);
|
||||
}
|
||||
|
||||
private void DrawSlot(UiWindow w, IReadOnlyList<CarriedItem> items)
|
||||
{
|
||||
int n = _selected;
|
||||
DefSlot slot = _s.Data.Slots[n - 1];
|
||||
w.TextColored(UiColors.Gold, $"Slot {n}: " + (slot.Item == null ? "(empty)" : slot.Item.FullName));
|
||||
|
||||
w.Button("Set from selected", "ed.set", () => Say(_s.SetFromSelected(n)));
|
||||
w.Tooltip("Select an item in the game (click it in your pack), then press this: it goes in this slot.");
|
||||
w.SameLine();
|
||||
w.ToggleButton("Pick from pack", "ed.pick", _picking, () => { _picking = !_picking; _packSearch = string.Empty; });
|
||||
w.Tooltip("Choose from a list of what you carry.");
|
||||
w.SameLine();
|
||||
w.Button("Clear", "ed.clear", () => Say(_s.ClearSlot(n)));
|
||||
|
||||
w.SmallButton("Move up", "ed.up", () => { if (_s.SwapSlots(n, n - 1)) _selected = n - 1; });
|
||||
w.SameLine();
|
||||
w.SmallButton("Move down", "ed.down", () => { if (_s.SwapSlots(n, n + 1)) _selected = n + 1; });
|
||||
|
||||
uint sel = _s.SelectedId();
|
||||
CarriedItem? selItem = sel == 0 ? null : _s.FindById(sel);
|
||||
w.TextDisabled("Selected in the game: " + (sel == 0 ? "nothing" : selItem != null ? selItem.FullName : "(not in your pack)"));
|
||||
if (_note.Length > 0) w.TextWrapped(_note);
|
||||
|
||||
if (_picking) DrawPackPicker(w, items, n);
|
||||
|
||||
if (slot.Item == null) return;
|
||||
|
||||
int mode = (int)slot.Mode;
|
||||
w.Combo("Pressing it", "ed.mode", mode, UseModes.Labels, i => _s.SetSlotMode(n, (UseMode)Math.Clamp(i, 0, (int)UseMode.Equip)));
|
||||
SlotStatus status = ItemMatcher.Status(slot.Item, items);
|
||||
if (status.Item != null)
|
||||
{
|
||||
ItemKind kind = ItemKinds.Classify(status.Item);
|
||||
UseAction action = UseModes.ActionFor(slot.Mode, kind);
|
||||
w.TextDisabled($"It is {Describe(kind)}: pressing the slot has it {UseModes.Describe(action)}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
w.TextColored(SlotText.Missing, "Not in your pack right now. The slot keeps the name and fills itself when you carry another.");
|
||||
}
|
||||
|
||||
DrawKey(w, n, slot);
|
||||
}
|
||||
|
||||
private void DrawKey(UiWindow w, int n, DefSlot slot)
|
||||
{
|
||||
string? key = _s.KeyOfSlot(n);
|
||||
w.Text("Key: " + (key ?? "none"));
|
||||
w.InputText("Key to bind", "ed.key", _keyDraft, 24, v => _keyDraft = v, UiFormat.InputEnterReturnsTrue);
|
||||
w.Tooltip("A key with Ctrl, Alt or Shift if you like: F9, Ctrl+1, Alt+Shift+Num3.");
|
||||
w.Button("Bind to this slot", "ed.bind", () => Say(_s.BindKey(n, _keyDraft, byName: false)));
|
||||
w.Tooltip($"Runs {DefCommandParser.UseCommand(n)}. If you move or re-set the slot, the key follows the slot.");
|
||||
w.SameLine();
|
||||
w.Button("Bind to this item", "ed.bindname", () => Say(_s.BindKey(n, _keyDraft, byName: true)));
|
||||
w.Tooltip("Runs /rdef use <the item's name>, whichever slot (or none) holds it. Works for every character on this PC.");
|
||||
w.SameLine();
|
||||
w.Button("Unbind", "ed.unbind", () => Say(_s.UnbindKey(n)));
|
||||
w.TextDisabled("Any item can be bound by name from Settings > Hotkeys too: /rdef use <name>.");
|
||||
}
|
||||
|
||||
private void DrawPackPicker(UiWindow w, IReadOnlyList<CarriedItem> items, int n)
|
||||
{
|
||||
bool icons = _s.Settings.ShowIcons && _s.IconsAvailable;
|
||||
w.InputText("Search your pack", "ed.packsearch", _packSearch, 48, v => _packSearch = v);
|
||||
List<PackChoice> choices = PackList.Build(items, _packSearch, PackRows, out int total);
|
||||
w.BeginChild("packlist", 0f, 150f, true);
|
||||
foreach (PackChoice c in choices)
|
||||
{
|
||||
CarriedItem it = c.Item;
|
||||
if (icons) { w.Image(UiFormat.IconKindObject, it.Id, RowIcon, RowIcon); w.SameLine(); }
|
||||
string label = it.FullName + (c.Count > 1 ? $" x{c.Count}" : string.Empty);
|
||||
w.Selectable(label, "pk" + it.Id, false, () =>
|
||||
{
|
||||
Say(_s.SetSlot(n, it));
|
||||
_picking = false;
|
||||
}, 0f, icons ? RowIcon : 0f);
|
||||
}
|
||||
if (choices.Count == 0) w.TextDisabled("Nothing matches.");
|
||||
if (total > choices.Count) w.TextDisabled($"{total - choices.Count} more - type to narrow the list.");
|
||||
w.EndChild();
|
||||
}
|
||||
|
||||
private static string Describe(ItemKind k) => k switch
|
||||
{
|
||||
ItemKind.Kit => "a healing or stamina kit",
|
||||
ItemKind.Melee => "a melee weapon",
|
||||
ItemKind.Missile => "a missile weapon",
|
||||
ItemKind.WarWand => "a war magic wand",
|
||||
ItemKind.VoidWand => "a void magic wand",
|
||||
ItemKind.Shield => "a shield",
|
||||
ItemKind.Armor => "armor or clothing",
|
||||
ItemKind.Jewelry => "jewelry",
|
||||
ItemKind.Ammo => "ammunition",
|
||||
_ => "an item",
|
||||
};
|
||||
}
|
||||
80
Plugins/RynthCore.Plugin.RynthDefective/Views/SlotText.cs
Normal file
80
Plugins/RynthCore.Plugin.RynthDefective/Views/SlotText.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using RynthCore.Plugin.RynthDefective.Items;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.Plugin.RynthDefective.Ui;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Views;
|
||||
|
||||
/// <summary>The words a slot shows: the count under its button, its key, and its tooltip. Pure.</summary>
|
||||
internal static class SlotText
|
||||
{
|
||||
public static readonly uint Missing = UiFormat.Rgb(225, 95, 95);
|
||||
public static readonly uint InHand = UiFormat.Rgb(110, 210, 110);
|
||||
public static readonly uint Plain = UiFormat.Rgb(220, 220, 220);
|
||||
public static readonly uint KeyColor = UiFormat.Rgb(150, 185, 235);
|
||||
public static readonly uint Waiting = UiFormat.Rgb(255, 191, 64);
|
||||
|
||||
/// <summary>The line under a slot button: uses left (kits), the count (stacks, several of a kind), "in hand", or "none".</summary>
|
||||
public static string Count(SlotStatus s, out uint color)
|
||||
{
|
||||
color = Plain;
|
||||
if (s.Item == null)
|
||||
{
|
||||
color = Missing;
|
||||
return "none";
|
||||
}
|
||||
CarriedItem it = s.Item;
|
||||
if (it.Wielded)
|
||||
{
|
||||
color = InHand;
|
||||
return ItemKinds.IsWeapon(ItemKinds.Classify(it)) ? "in hand" : "worn";
|
||||
}
|
||||
if (it.MaxUses > 0) return s.Uses.ToString();
|
||||
if (it.MaxStack > 1 || s.Count > 1) return "x" + s.Count;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>A key as the cell under a slot has room for: "Ctrl+F9" is "C+F9".</summary>
|
||||
public static string ShortKey(string? key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key)) return string.Empty;
|
||||
string k = key.EndsWith(" (off)", StringComparison.Ordinal) ? key[..^6] : key;
|
||||
return k.Replace("Ctrl+", "C+").Replace("Alt+", "A+").Replace("Shift+", "S+");
|
||||
}
|
||||
|
||||
/// <summary>Up to <paramref name="max"/> letters for a slot drawn as text (icons off): "Peerless Healing Kit" is "PHK".</summary>
|
||||
public static string Abbreviation(string name, int max = 4)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (string word in (name ?? string.Empty).Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (word.Length == 0 || !char.IsLetterOrDigit(word[0])) continue;
|
||||
sb.Append(char.ToUpperInvariant(word[0]));
|
||||
if (sb.Length >= max) break;
|
||||
}
|
||||
return sb.Length == 0 ? "?" : sb.ToString();
|
||||
}
|
||||
|
||||
public static string Tooltip(int number, ItemRef? item, SlotStatus s, UseMode mode, string? key)
|
||||
{
|
||||
if (item == null) return $"Slot {number}: empty. Click to set it up.";
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("Slot ").Append(number).Append(": ").Append(s.Item?.FullName ?? item.FullName);
|
||||
if (s.Item == null)
|
||||
{
|
||||
sb.Append("\nNot in your pack - nothing to use. It comes back by itself when you carry one of the same name.");
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemKind kind = ItemKinds.Classify(s.Item);
|
||||
UseAction action = UseModes.ActionFor(mode, kind);
|
||||
sb.Append("\nClick or press the key: ").Append(UseModes.Describe(action).Replace("used", "use it").Replace("wielded", "wield it"));
|
||||
if (s.Item.MaxUses > 0) sb.Append("\n").Append(s.Uses).Append(" uses left");
|
||||
if (s.Count > 1 || s.Item.MaxStack > 1) sb.Append(s.Item.MaxUses > 0 ? ", " : "\n").Append(s.Count).Append(" carried");
|
||||
if (s.Item.Wielded) sb.Append("\nIn your hands now.");
|
||||
}
|
||||
sb.Append(key != null ? "\nKey: " + key : "\nNo key yet (Edit slots).");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue