feat(inventory): filter by item attributes; move Charms to the ILT Mini Remote

See Changelog/2026-10-11-inventory-attribute-filter-charms.md.
This commit is contained in:
BlankenshipG 2026-10-12 00:33:11 -04:00
commit 46f8975295
11 changed files with 1225 additions and 239 deletions

View file

@ -0,0 +1,72 @@
# Inventory: filter by item attributes; Charms moved to the ILT Mini Remote
## Inventory attribute filter
- **New button in the tools row:** a list-check icon between the search box and the sort picker.
- In the Modern look it is always visible.
- In the Classic look, open the tools row first (the funnel in the title bar).
- **The popup editor:**
- Filter on/off;
- "Keep items matching all rules / any rule";
- up to 12 rules, each made of an attribute, an operator and a value;
- Add rule, Clear rules, Close.
- **Attributes known without an identify:** Name, Value, Burden, Workmanship, Stack size, Material,
Fits slot (Head ... Aetheria), Equipped, Casts a spell.
- **Attributes that need an identify (marked \*):**
- Armor level, Max damage, Speed;
- Attack bonus %, Melee / Missile / Magic defense %, Elemental damage %, Mana conversion %;
- Damage, Damage resist, Crit, Crit resist, Crit damage, Crit damage resist, Healing boost and
Vitality ratings;
- Level to wield, Arcane lore, Spellcraft, Max mana, Times tinkered, Max item level;
- Armor set (name text), Spells (any spell's name contains the text);
- Imbued, Bonded, Attuned, Retained.
- **Operators:**
- numbers: >=, <=, =, !=;
- yes / no flags: yes, no;
- text: contains, doesn't contain (case-insensitive);
- slot: is, is not.
- **Missing values:** an attribute the item doesn't have counts as 0, no, or empty text. For
example, "Level to wield <= 150" keeps items with no level requirement.
- **Items the server hasn't identified yet:** a rule that needs an identify can't judge them, so
they are hidden and counted.
- The count appears in the header ("N not ID'd"), the button's tooltip and the popup.
- "Identify N" in the popup asks the server about them, 4 a second while the panel is open.
"Stop" empties the queue.
- Items already identified, or asked about in the last minute, are skipped.
- While such a rule is on, the list refreshes once a second so new answers show up.
- **Saving and Clear:**
- The rules are saved in `%LOCALAPPDATA%\RynthCore\inventory_settings.txt`, on the
`attrfilter=` line, when the popup closes.
- Clear (closing the Classic tools row) turns the filter off but keeps its rules.
- In Classic, the filter only applies while the tools row is open, so nothing is ever hidden
without a visible control.
- **Behaves like the search and category filters:**
- Classic lists matches from all packs;
- grid cells stop acting as slots, and drops refuse to reorder;
- "Nothing matches." shows when no item matches.
## Charms
- Settings > Charms Tracking is removed. It is now the Charms tab in RynthAi's Mini Remote
(the matching RynthSuite change). Its poller (`UI/Data/CharmsData.cs`) and its `UiSources` registration are
removed.
- The ILT server menu (right-click the Mini Remote) gains Charms after Gear. It opens with
`/rc miniremote tab charms`.
## Files
- `Compatibility/InventoryAttributeFilter.cs` (new): the attributes, operators, matching (Match /
NoMatch / Unknown), material and set names, and the saved line. It has no dependencies, so the
RynthSuite host tests link it.
- `Compatibility/InventoryFilterFacts.cs` (new): an item's values from the panel's item and the
appraisal cache (render thread, no AC reads).
- `Compatibility/InventoryModel.cs`: the identify queue (`QueueIdentify`, `IdentifyQueueCount`,
`ClearIdentifyQueue`), sent on AC's main thread and cleared on a character change.
- `ImGui/Panels/InventoryFace.AttrFilter.cs` (new): the button, the popup and the per-item check.
- `ImGui/Panels/InventoryFace.cs`, `InventoryFace.Classic.cs`: wiring, `FiltersOn`, and the
`attrfilter` setting.
- `ImGui/Panels/SettingsFace.cs`, `UI/Data/UiSources.cs`, `UI/Data/CharmsData.cs` (deleted),
`EntryPoint.cs`: the Charms move.
The engine builds in Release. The filter has 5 new host tests in RynthSuite
(`InventoryAttributeFilterTests`), and all of them pass. Not yet tested in game.

View file

@ -0,0 +1,527 @@
// ============================================================================
// RynthCore.Engine - Compatibility/InventoryAttributeFilter.cs
// The Inventory panel's attribute filter: rules on an item's attributes
// ("Armor Level >= 300", "Spells contain Legendary", "Fits slot Neck"),
// matched all or any. Pure: no AC reads. The panel supplies each item's
// values through IInventoryFilterFacts (InventoryFilterFacts.cs), so the host
// tests link this file alone.
//
// Two kinds of attribute:
// public what every item sends (value, burden, material, slots...)
// appraised what only an identify returns (armor level, ratings, spells...).
// An item never identified can't be judged on these: Unknown,
// which the panel hides and counts ("N not identified").
// An appraised attribute the item doesn't have counts as 0 / no / "" (a
// weapon's armor level is 0), so "Level to wield <= 150" keeps items with no
// requirement.
//
// Threads: the panel's (render) thread only; the rules are edited and read
// there. Saved as one line in inventory_settings.txt (Serialize / Parse).
// ============================================================================
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace RynthCore.Engine.Compatibility;
/// <summary>How a rule compares the attribute.</summary>
internal enum FilterAttrKind : byte { Number, Flag, Text, Choice }
/// <summary>Where the value comes from and how it is turned into what the rule shows.</summary>
internal enum FilterSource : byte
{
/// <summary>From the item's public description (the panel's InventoryItem).</summary>
Public,
/// <summary>An appraised int property (0 when absent).</summary>
Int,
/// <summary>An appraised float property, shown as is.</summary>
Float,
/// <summary>An appraised float multiplier shown as a bonus percent: 1.15 -> 15.</summary>
FloatModPercent,
/// <summary>An appraised float fraction shown as a percent: 0.05 -> 5.</summary>
FloatPercent,
/// <summary>An appraised int that counts as "yes" when not 0.</summary>
IntNonZero,
/// <summary>An appraised bool property.</summary>
Bool,
/// <summary>Worked out by the facts provider (level to wield, set name, spells).</summary>
Special,
}
/// <summary>Every attribute a rule can test. The persisted key is <see cref="FilterAttrInfo.Key"/>, not the number.</summary>
internal enum FilterAttr : byte
{
// Public
Name, Value, Burden, Workmanship, Stack, Material, Slot, Equipped, CastsSpell,
// Appraised
ArmorLevel, MaxDamage, Speed, AttackBonus, MeleeDefense, MissileDefense, MagicDefense,
ElementalDamage, ManaConversion, DamageRating, DamageResistRating, CritRating, CritResistRating,
CritDamageRating, CritDamageResistRating, HealingBoostRating, VitalityRating, WieldLevel,
ArcaneLore, Spellcraft, MaxMana, Tinkers, MaxItemLevel, SetName, Spells, Imbued, Bonded,
Attuned, Retained,
}
/// <summary>One attribute's description: its key, label, kind and where its value lives.</summary>
internal sealed class FilterAttrInfo
{
public FilterAttr Id;
public string Key = string.Empty;
public string Label = string.Empty;
public FilterAttrKind Kind;
public FilterSource Source;
/// <summary>The appraisal property id (STypeInt / STypeFloat / STypeBool); 0 for public and special.</summary>
public uint Stype;
public string Tip = string.Empty;
/// <summary>Needs an identify (any source but Public).</summary>
public bool NeedsId => Source != FilterSource.Public;
}
/// <summary>How a rule tests its attribute. The persisted key is in <see cref="InventoryAttributeFilter.OpKey"/>.</summary>
internal enum FilterOp : byte { AtLeast, AtMost, Equal, NotEqual, Yes, No, Contains, NotContains, Is, IsNot }
/// <summary>What one rule (or the whole filter) says about an item.</summary>
internal enum FilterVerdict : byte { Match, NoMatch, Unknown }
/// <summary>One item's values as a rule sees them. Absent values are 0 / false / "".</summary>
internal interface IInventoryFilterFacts
{
/// <summary>The server's identify answer is cached for this item.</summary>
bool Identified { get; }
double Number(FilterAttrInfo attr);
bool Flag(FilterAttrInfo attr);
string Text(FilterAttrInfo attr);
/// <summary>The item's ValidLocations (EquipMask) bits, for the Slot choice.</summary>
uint SlotMask { get; }
}
/// <summary>One rule. Mutable: the panel's editor changes it in place and bumps the filter's version.</summary>
internal sealed class InventoryFilterRule
{
public FilterAttr Attr;
public FilterOp Op;
public double Number;
public string Text = string.Empty;
/// <summary>The choice's index (Slot: into <see cref="InventoryAttributeFilter.SlotNames"/>).</summary>
public int Choice;
public InventoryFilterRule Clone() => new() { Attr = Attr, Op = Op, Number = Number, Text = Text, Choice = Choice };
}
/// <summary>The rule list, its match mode and on/off; evaluation, description and persistence.</summary>
internal sealed class InventoryAttributeFilter
{
public const int MaxRules = 12;
/// <summary>Off keeps the rules but shows every item.</summary>
public bool Enabled;
/// <summary>True: any rule matching keeps the item. False: every rule must.</summary>
public bool MatchAny;
public readonly List<InventoryFilterRule> Rules = new();
/// <summary>Bumped on every edit, so the panel knows to rebuild its list.</summary>
public int Version { get; private set; }
/// <summary>On, with at least one rule.</summary>
public bool Active => Enabled && Rules.Count > 0;
/// <summary>Some rule needs an identify (so unknown items can exist and appraisals change matches).</summary>
public bool NeedsIdentify
{
get
{
foreach (InventoryFilterRule r in Rules)
if (Info(r.Attr).NeedsId) return true;
return false;
}
}
public void Touch() => Version++;
// ── Attributes ──────────────────────────────────────────────────────
public static readonly FilterAttrInfo[] Attributes = BuildAttributes();
private static FilterAttrInfo[] BuildAttributes()
{
var list = new FilterAttrInfo[(int)FilterAttr.Retained + 1];
void Add(FilterAttr id, string key, string label, FilterAttrKind kind, FilterSource src, uint stype, string tip) =>
list[(int)id] = new FilterAttrInfo { Id = id, Key = key, Label = label, Kind = kind, Source = src, Stype = stype, Tip = tip };
Add(FilterAttr.Name, "name", "Name", FilterAttrKind.Text, FilterSource.Public, 0, "The item's name.");
Add(FilterAttr.Value, "value", "Value", FilterAttrKind.Number, FilterSource.Public, 0, "Pyreal value.");
Add(FilterAttr.Burden, "burden", "Burden", FilterAttrKind.Number, FilterSource.Public, 0, "Burden units (a stack's total).");
Add(FilterAttr.Workmanship, "work", "Workmanship", FilterAttrKind.Number, FilterSource.Public, 0, "1 to 10; 0 for items without one.");
Add(FilterAttr.Stack, "stack", "Stack size", FilterAttrKind.Number, FilterSource.Public, 0, "1 for a single item.");
Add(FilterAttr.Material, "material", "Material", FilterAttrKind.Text, FilterSource.Public, 0, "Steel, Silk, Ruby...");
Add(FilterAttr.Slot, "slot", "Fits slot", FilterAttrKind.Choice, FilterSource.Public, 0, "Where the item can be worn or wielded.");
Add(FilterAttr.Equipped, "equipped", "Equipped", FilterAttrKind.Flag, FilterSource.Public, 0, "Worn or wielded now.");
Add(FilterAttr.CastsSpell, "casts", "Casts a spell", FilterAttrKind.Flag, FilterSource.Public, 0, "Has a use spell (scrolls, gems, wands).");
Add(FilterAttr.ArmorLevel, "al", "Armor level", FilterAttrKind.Number, FilterSource.Int, 28, "Base armor level.");
Add(FilterAttr.MaxDamage, "dmg", "Max damage", FilterAttrKind.Number, FilterSource.Int, 44, "A weapon's maximum damage.");
Add(FilterAttr.Speed, "speed", "Speed", FilterAttrKind.Number, FilterSource.Int, 49, "Weapon speed (lower is faster).");
Add(FilterAttr.AttackBonus, "attack", "Attack bonus %", FilterAttrKind.Number, FilterSource.FloatModPercent, 62, "A weapon's attack skill bonus.");
Add(FilterAttr.MeleeDefense, "meleed", "Melee defense %", FilterAttrKind.Number, FilterSource.FloatModPercent, 29, "Melee defense bonus.");
Add(FilterAttr.MissileDefense, "missiled", "Missile defense %", FilterAttrKind.Number, FilterSource.FloatModPercent, 149, "Missile defense bonus.");
Add(FilterAttr.MagicDefense, "magicd", "Magic defense %", FilterAttrKind.Number, FilterSource.FloatModPercent, 150, "Magic defense bonus.");
Add(FilterAttr.ElementalDamage, "elem", "Elemental damage %", FilterAttrKind.Number, FilterSource.FloatModPercent, 152, "A caster's elemental damage bonus.");
Add(FilterAttr.ManaConversion, "manac", "Mana conversion %", FilterAttrKind.Number, FilterSource.FloatPercent, 144, "A caster's mana conversion bonus.");
Add(FilterAttr.DamageRating, "dr", "Damage rating", FilterAttrKind.Number, FilterSource.Int, 370, "Gear damage rating.");
Add(FilterAttr.DamageResistRating, "drr", "Damage resist rating", FilterAttrKind.Number, FilterSource.Int, 371, "Gear damage resistance rating.");
Add(FilterAttr.CritRating, "cr", "Crit rating", FilterAttrKind.Number, FilterSource.Int, 372, "Gear critical rating.");
Add(FilterAttr.CritResistRating, "crr", "Crit resist rating", FilterAttrKind.Number, FilterSource.Int, 373, "Gear critical resistance rating.");
Add(FilterAttr.CritDamageRating, "cdr", "Crit damage rating", FilterAttrKind.Number, FilterSource.Int, 374, "Gear critical damage rating.");
Add(FilterAttr.CritDamageResistRating, "cdrr", "Crit damage resist rating", FilterAttrKind.Number, FilterSource.Int, 375, "Gear critical damage resistance rating.");
Add(FilterAttr.HealingBoostRating, "heal", "Healing boost rating", FilterAttrKind.Number, FilterSource.Int, 376, "Gear healing boost rating.");
Add(FilterAttr.VitalityRating, "vit", "Vitality rating", FilterAttrKind.Number, FilterSource.Int, 379, "Gear max health (vitality) rating.");
Add(FilterAttr.WieldLevel, "wieldlvl", "Level to wield", FilterAttrKind.Number, FilterSource.Special, 0, "Character level needed; 0 when none.");
Add(FilterAttr.ArcaneLore, "lore", "Arcane lore", FilterAttrKind.Number, FilterSource.Int, 109, "Arcane lore needed to use it.");
Add(FilterAttr.Spellcraft, "spellcraft", "Spellcraft", FilterAttrKind.Number, FilterSource.Int, 106, "The item's spellcraft.");
Add(FilterAttr.MaxMana, "mana", "Max mana", FilterAttrKind.Number, FilterSource.Int, 108, "The item's mana pool.");
Add(FilterAttr.Tinkers, "tinks", "Times tinkered", FilterAttrKind.Number, FilterSource.Int, 171, "Tinkers applied so far.");
Add(FilterAttr.MaxItemLevel, "maxlvl", "Max item level", FilterAttrKind.Number, FilterSource.Int, 319, "Aetheria / cloak / leveling items.");
Add(FilterAttr.SetName, "set", "Armor set", FilterAttrKind.Text, FilterSource.Special, 265, "Soldier's, Adept's, Cloak War Magic...");
Add(FilterAttr.Spells, "spells", "Spells", FilterAttrKind.Text, FilterSource.Special, 0, "Any of the item's spells contains the text.");
Add(FilterAttr.Imbued, "imbued", "Imbued", FilterAttrKind.Flag, FilterSource.IntNonZero, 179, "Has an imbue (crushing blow, armor rend...).");
Add(FilterAttr.Bonded, "bonded", "Bonded", FilterAttrKind.Flag, FilterSource.IntNonZero, 33, "Bonded, sticky or destroyed on drop.");
Add(FilterAttr.Attuned, "attuned", "Attuned", FilterAttrKind.Flag, FilterSource.IntNonZero, 114, "Can't be given away.");
Add(FilterAttr.Retained, "retained", "Retained", FilterAttrKind.Flag, FilterSource.Bool, 91, "Won't be sold or salvaged by accident.");
return list;
}
public static FilterAttrInfo Info(FilterAttr a) => Attributes[(int)a];
public static FilterAttrInfo? InfoByKey(string key)
{
foreach (FilterAttrInfo i in Attributes)
if (string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)) return i;
return null;
}
// ── Operators ───────────────────────────────────────────────────────
private static readonly FilterOp[] NumberOps = { FilterOp.AtLeast, FilterOp.AtMost, FilterOp.Equal, FilterOp.NotEqual };
private static readonly FilterOp[] FlagOps = { FilterOp.Yes, FilterOp.No };
private static readonly FilterOp[] TextOps = { FilterOp.Contains, FilterOp.NotContains };
private static readonly FilterOp[] ChoiceOps = { FilterOp.Is, FilterOp.IsNot };
/// <summary>The operators that make sense for an attribute kind; the first is the default.</summary>
public static FilterOp[] OpsFor(FilterAttrKind kind) => kind switch
{
FilterAttrKind.Number => NumberOps,
FilterAttrKind.Flag => FlagOps,
FilterAttrKind.Text => TextOps,
_ => ChoiceOps,
};
public static string OpLabel(FilterOp op) => op switch
{
FilterOp.AtLeast => ">=",
FilterOp.AtMost => "<=",
FilterOp.Equal => "=",
FilterOp.NotEqual => "!=",
FilterOp.Yes => "yes",
FilterOp.No => "no",
FilterOp.Contains => "contains",
FilterOp.NotContains => "doesn't contain",
FilterOp.Is => "is",
_ => "is not",
};
public static string OpKey(FilterOp op) => op switch
{
FilterOp.AtLeast => "ge",
FilterOp.AtMost => "le",
FilterOp.Equal => "eq",
FilterOp.NotEqual => "ne",
FilterOp.Yes => "yes",
FilterOp.No => "no",
FilterOp.Contains => "has",
FilterOp.NotContains => "nothas",
FilterOp.Is => "is",
_ => "isnot",
};
private static bool TryOpFromKey(string key, out FilterOp op)
{
for (FilterOp o = FilterOp.AtLeast; o <= FilterOp.IsNot; o++)
if (OpKey(o) == key) { op = o; return true; }
op = default;
return false;
}
/// <summary>A new rule on <paramref name="attr"/> with that attribute's default operator.</summary>
public static InventoryFilterRule NewRule(FilterAttr attr) => new() { Attr = attr, Op = OpsFor(Info(attr).Kind)[0] };
/// <summary>Points <paramref name="rule"/> at another attribute, keeping its operator when it still fits.</summary>
public static void SetAttr(InventoryFilterRule rule, FilterAttr attr)
{
rule.Attr = attr;
if (Array.IndexOf(OpsFor(Info(attr).Kind), rule.Op) < 0) rule.Op = OpsFor(Info(attr).Kind)[0];
if (Info(attr).Kind == FilterAttrKind.Choice) rule.Choice = Math.Clamp(rule.Choice, 0, SlotNames.Length - 1);
}
// ── Evaluation ──────────────────────────────────────────────────────
/// <summary>
/// The whole filter on one item. All: any NoMatch wins, then any Unknown. Any: any Match
/// wins, then any Unknown. Off or empty: Match.
/// </summary>
public FilterVerdict Evaluate(IInventoryFilterFacts facts)
{
if (!Active) return FilterVerdict.Match;
bool unknown = false;
foreach (InventoryFilterRule r in Rules)
{
FilterVerdict v = EvaluateRule(r, facts);
if (v == FilterVerdict.Unknown) unknown = true;
else if (MatchAny && v == FilterVerdict.Match) return FilterVerdict.Match;
else if (!MatchAny && v == FilterVerdict.NoMatch) return FilterVerdict.NoMatch;
}
if (unknown) return FilterVerdict.Unknown;
return MatchAny ? FilterVerdict.NoMatch : FilterVerdict.Match;
}
/// <summary>One rule on one item. Unknown when it needs an identify the item doesn't have.</summary>
public static FilterVerdict EvaluateRule(InventoryFilterRule rule, IInventoryFilterFacts facts)
{
FilterAttrInfo info = Info(rule.Attr);
// A text rule with no text tests nothing: it never hides an item.
if (info.Kind == FilterAttrKind.Text && rule.Text.Length == 0) return FilterVerdict.Match;
if (info.NeedsId && !facts.Identified) return FilterVerdict.Unknown;
bool ok = info.Kind switch
{
FilterAttrKind.Number => CompareNumber(facts.Number(info), rule.Op, rule.Number),
FilterAttrKind.Flag => facts.Flag(info) == (rule.Op == FilterOp.Yes),
FilterAttrKind.Text => facts.Text(info).Contains(rule.Text, StringComparison.OrdinalIgnoreCase) == (rule.Op == FilterOp.Contains),
_ => FitsSlot(facts.SlotMask, rule.Choice) == (rule.Op == FilterOp.Is),
};
return ok ? FilterVerdict.Match : FilterVerdict.NoMatch;
}
/// <summary>
/// Number comparison. Equal allows half a hundredth either way: percents come from floats
/// (1.15 -> 14.999...) and are typed to two places at most.
/// </summary>
public static bool CompareNumber(double value, FilterOp op, double target)
{
const double Eps = 1e-6, EqTol = 0.005;
return op switch
{
FilterOp.AtLeast => value >= target - Eps,
FilterOp.AtMost => value <= target + Eps,
FilterOp.Equal => Math.Abs(value - target) < EqTol,
FilterOp.NotEqual => Math.Abs(value - target) >= EqTol,
_ => false,
};
}
/// <summary>A raw appraised float as the rule shows it.</summary>
public static double Scale(FilterSource source, double raw) => source switch
{
FilterSource.FloatModPercent => raw == 0 ? 0 : (raw - 1.0) * 100.0,
FilterSource.FloatPercent => raw * 100.0,
_ => raw,
};
/// <summary>
/// The level needed to wield: WieldRequirements (158) or WieldRequirements2 (270) = 7
/// (Level) gives WieldDifficulty (160) or WieldDifficulty2 (271). 0 when neither is a level.
/// </summary>
public static int WieldLevel(int req1, int diff1, int req2, int diff2) =>
req1 == WieldRequirementLevel ? diff1 : req2 == WieldRequirementLevel ? diff2 : 0;
public const int WieldRequirementLevel = 7;
public const uint StypeWieldRequirements = 158, StypeWieldDifficulty = 160,
StypeWieldRequirements2 = 270, StypeWieldDifficulty2 = 271;
// ── Slots ───────────────────────────────────────────────────────────
public static readonly string[] SlotNames =
{
"Head", "Chest", "Abdomen", "Upper arms", "Lower arms", "Hands", "Upper legs", "Lower legs", "Feet",
"Neck", "Wrist", "Finger", "Melee weapon", "Shield", "Missile weapon", "Ammunition", "Held (wand, orb)",
"Two-handed weapon", "Trinket", "Cloak", "Aetheria",
};
/// <summary>EquipMask bits per <see cref="SlotNames"/> entry (armor and underclothes share a body part).</summary>
public static readonly uint[] SlotMasks =
{
0x00000001, 0x00000002 | 0x00000200, 0x00000004 | 0x00000400, 0x00000008 | 0x00000800,
0x00000010 | 0x00001000, 0x00000020, 0x00000040 | 0x00002000, 0x00000080 | 0x00004000, 0x00000100,
0x00008000, 0x00030000, 0x000C0000, 0x00100000, 0x00200000, 0x00400000, 0x00800000, 0x01000000,
0x02000000, 0x04000000, 0x08000000, 0x70000000,
};
public static bool FitsSlot(uint validLocations, int choice) =>
choice >= 0 && choice < SlotMasks.Length && (validLocations & SlotMasks[choice]) != 0;
// ── Names (material, armor set) ─────────────────────────────────────
// MaterialType 1..77 (ACE.Entity.Enum.MaterialType), in id order.
private const string MaterialIds =
"Ceramic,Porcelain,Cloth,Linen,Satin,Silk,Velvet,Wool,Gem,Agate,Amber,Amethyst,Aquamarine,Azurite,"
+ "BlackGarnet,BlackOpal,Bloodstone,Carnelian,Citrine,Diamond,Emerald,FireOpal,GreenGarnet,GreenJade,"
+ "Hematite,ImperialTopaz,Jet,LapisLazuli,LavenderJade,Malachite,Moonstone,Onyx,Opal,Peridot,RedGarnet,"
+ "RedJade,RoseQuartz,Ruby,Sapphire,SmokeyQuartz,Sunstone,TigerEye,Tourmaline,Turquoise,WhiteJade,"
+ "WhiteQuartz,WhiteSapphire,YellowGarnet,YellowTopaz,Zircon,Ivory,Leather,ArmoredilloHide,GromnieHide,"
+ "ReedSharkHide,Metal,Brass,Bronze,Copper,Gold,Iron,Pyreal,Silver,Steel,Stone,Alabaster,Granite,Marble,"
+ "Obsidian,Sandstone,Serpentine,Wood,Ebony,Mahogany,Oak,Pine,Teak";
// EquipmentSet 0..140 (ACECustom ACE.Entity.Enum.EquipmentSet), in id order.
private const string SetIds =
"Invalid,Test,Test2,Unknown3,CarraidasBenediction,NobleRelic,AncientRelic,AlduressaRelic,Ninja,EmpyreanRings,"
+ "ArmMindHeart,ArmorPerfectLight,ArmorPerfectLight2,Soldiers,Adepts,Archers,Defenders,Tinkers,Crafters,Hearty,"
+ "Dexterous,Wise,Swift,Hardened,Reinforced,Interlocking,Flameproof,Acidproof,Coldproof,Lightningproof,"
+ "SocietyArmor,ColosseumClothing,GraveyardClothing,OlthoiClothing,NoobieArmor,AetheriaDefense,"
+ "AetheriaDestruction,AetheriaFury,AetheriaGrowth,AetheriaVigor,RareDamageResistance,RareDamageBoost,"
+ "OlthoiArmorDRed,OlthoiArmorCRat,OlthoiArmorCRed,OlthoiArmorDRat,AlduressaRelicUpgrade,AncientRelicUpgrade,"
+ "NobleRelicUpgrade,CloakAlchemy,CloakArcaneLore,CloakArmorTinkering,CloakAssessPerson,CloakLightWeapons,"
+ "CloakMissileWeapons,CloakCooking,CloakCreatureEnchantment,CloakCrossbow,CloakFinesseWeapons,CloakDeception,"
+ "CloakFletching,CloakHealing,CloakItemEnchantment,CloakItemTinkering,CloakLeadership,CloakLifeMagic,"
+ "CloakLoyalty,CloakMace,CloakMagicDefense,CloakMagicItemTinkering,CloakManaConversion,CloakMeleeDefense,"
+ "CloakMissileDefense,CloakSalvaging,CloakSpear,CloakStaff,CloakHeavyWeapons,CloakThrownWeapon,"
+ "CloakTwoHandedCombat,CloakUnarmedCombat,CloakVoidMagic,CloakWarMagic,CloakWeaponTinkering,"
+ "CloakAssessCreature,CloakDirtyFighting,CloakDualWield,CloakRecklessness,CloakShield,CloakSneakAttack,"
+ "Ninja_New,CloakSummoning,ShroudedSoul,DarkenedMind,CloudedSpirit,MinorStingingShroudedSoul,"
+ "MinorSparkingShroudedSoul,MinorSmolderingShroudedSoul,MinorShiveringShroudedSoul,MinorStingingDarkenedMind,"
+ "MinorSparkingDarkenedMind,MinorSmolderingDarkenedMind,MinorShiveringDarkenedMind,MinorStingingCloudedSpirit,"
+ "MinorSparkingCloudedSpirit,MinorSmolderingCloudedSpirit,MinorShiveringCloudedSpirit,"
+ "MajorStingingShroudedSoul,MajorSparkingShroudedSoul,MajorSmolderingShroudedSoul,MajorShiveringShroudedSoul,"
+ "MajorStingingDarkenedMind,MajorSparkingDarkenedMind,MajorSmolderingDarkenedMind,MajorShiveringDarkenedMind,"
+ "MajorStingingCloudedSpirit,MajorSparkingCloudedSpirit,MajorSmolderingCloudedSpirit,"
+ "MajorShiveringCloudedSpirit,BlackfireStingingShroudedSoul,BlackfireSparkingShroudedSoul,"
+ "BlackfireSmolderingShroudedSoul,BlackfireShiveringShroudedSoul,BlackfireStingingDarkenedMind,"
+ "BlackfireSparkingDarkenedMind,BlackfireSmolderingDarkenedMind,BlackfireShiveringDarkenedMind,"
+ "BlackfireStingingCloudedSpirit,BlackfireSparkingCloudedSpirit,BlackfireSmolderingCloudedSpirit,"
+ "BlackfireShiveringCloudedSpirit,ShimmeringShadowsSet,BrownSocietyLocket,YellowSocietyLocket,"
+ "RedSocietyBand,GreenSocietyBand,PurpleSocietyBand,BlueSocietyBand,GauntletGarb,ParagonMissile,"
+ "ParagonCaster,ParagonMelee";
private static readonly string[] Materials = SplitNames(MaterialIds);
private static readonly string[] Sets = SplitNames(SetIds);
/// <summary>"Black Garnet" for MaterialType 15; "" for 0 and ids past the list.</summary>
public static string MaterialName(int materialType) =>
materialType >= 1 && materialType <= Materials.Length ? Materials[materialType - 1] : string.Empty;
/// <summary>"Cloak War Magic" for EquipmentSet 81; "Set 200" for an id past the list; "" for none.</summary>
public static string SetName(int setId) =>
setId <= 0 ? string.Empty
: setId < Sets.Length ? Sets[setId]
: "Set " + setId.ToString(CultureInfo.InvariantCulture);
private static string[] SplitNames(string ids)
{
string[] parts = ids.Split(',');
for (int i = 0; i < parts.Length; i++) parts[i] = Words(parts[i]);
return parts;
}
/// <summary>"CloakWarMagic" -> "Cloak War Magic"; underscores become spaces.</summary>
public static string Words(string id)
{
var sb = new StringBuilder(id.Length + 6);
for (int i = 0; i < id.Length; i++)
{
char c = id[i];
if (c == '_') { sb.Append(' '); continue; }
// A capital starts a word after a lower-case letter or digit, or ends a run of
// capitals when a lower-case letter follows ("ArmorDRed" -> "Armor D Red").
if (i > 0 && char.IsUpper(c))
{
char prev = id[i - 1];
bool nextLower = i + 1 < id.Length && char.IsLower(id[i + 1]);
if (char.IsLower(prev) || char.IsDigit(prev) || (char.IsUpper(prev) && nextLower)) sb.Append(' ');
}
sb.Append(c);
}
return sb.ToString();
}
// ── Description ─────────────────────────────────────────────────────
/// <summary>"Armor level >= 300", "Spells contains Legendary", "Fits slot is Neck".</summary>
public static string Describe(InventoryFilterRule rule)
{
FilterAttrInfo info = Info(rule.Attr);
string what = info.Kind switch
{
FilterAttrKind.Number => " " + rule.Number.ToString("0.##", CultureInfo.InvariantCulture),
FilterAttrKind.Text => " \"" + rule.Text + "\"",
FilterAttrKind.Choice => " " + (rule.Choice >= 0 && rule.Choice < SlotNames.Length ? SlotNames[rule.Choice] : "?"),
_ => string.Empty,
};
return info.Label + " " + OpLabel(rule.Op) + what;
}
/// <summary>The rules joined with " and " / " or ", for the panel's tooltip.</summary>
public string Summary()
{
if (Rules.Count == 0) return "No rules.";
var sb = new StringBuilder();
for (int i = 0; i < Rules.Count; i++)
{
if (i > 0) sb.Append(MatchAny ? " or " : " and ");
sb.Append(Describe(Rules[i]));
}
return sb.ToString();
}
// ── Persistence ─────────────────────────────────────────────────────
/// <summary>
/// One line: "v1;on|off;all|any;" then rules split by ';', each "key,op,number,choice,text"
/// (text URL-escaped so ',' and ';' can't break it).
/// </summary>
public string Serialize()
{
var sb = new StringBuilder("v1;");
sb.Append(Enabled ? "on" : "off").Append(';').Append(MatchAny ? "any" : "all");
foreach (InventoryFilterRule r in Rules)
{
sb.Append(';').Append(Info(r.Attr).Key).Append(',').Append(OpKey(r.Op)).Append(',')
.Append(r.Number.ToString("R", CultureInfo.InvariantCulture)).Append(',')
.Append(r.Choice.ToString(CultureInfo.InvariantCulture)).Append(',')
.Append(Uri.EscapeDataString(r.Text));
}
return sb.ToString();
}
/// <summary>
/// Reads <see cref="Serialize"/>'s line. Unknown attributes and broken rules are skipped,
/// so an older engine's or a hand-edited line still loads what it can.
/// </summary>
public static InventoryAttributeFilter Parse(string? line)
{
var f = new InventoryAttributeFilter();
if (string.IsNullOrWhiteSpace(line)) return f;
string[] parts = line.Trim().Split(';');
if (parts.Length < 3 || parts[0] != "v1") return f;
f.Enabled = parts[1] == "on";
f.MatchAny = parts[2] == "any";
for (int i = 3; i < parts.Length && f.Rules.Count < MaxRules; i++)
{
string[] r = parts[i].Split(',');
if (r.Length < 5) continue;
FilterAttrInfo? info = InfoByKey(r[0]);
if (info == null || !TryOpFromKey(r[1], out FilterOp op)) continue;
if (Array.IndexOf(OpsFor(info.Kind), op) < 0) continue;
if (!double.TryParse(r[2], NumberStyles.Float, CultureInfo.InvariantCulture, out double num) || !double.IsFinite(num)) num = 0;
if (!int.TryParse(r[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out int choice)) choice = 0;
string text;
try { text = Uri.UnescapeDataString(r[4]); }
catch (UriFormatException) { text = string.Empty; }
f.Rules.Add(new InventoryFilterRule
{
Attr = info.Id,
Op = op,
Number = num,
Choice = info.Kind == FilterAttrKind.Choice ? Math.Clamp(choice, 0, SlotNames.Length - 1) : choice,
Text = text,
});
}
return f;
}
}

View file

@ -0,0 +1,112 @@
// ============================================================================
// RynthCore.Engine - Compatibility/InventoryFilterFacts.cs
// One item's values for the Inventory panel's attribute filter
// (InventoryAttributeFilter): public ones from the panel's InventoryItem,
// appraised ones from AppraisalHooks' cache (filled by an identify).
//
// Threads: the panel's (render) thread. AppraisalHooks' getters lock their
// cache and PortalSpellTable's lookups read an immutable table, so neither
// touches AC. One instance is re-bound per item (no allocation per item
// except a spells string, built only when a rule asks for it).
// ============================================================================
using System;
using System.Text;
using RynthCore.Engine.ImGuiBackend.Hud;
namespace RynthCore.Engine.Compatibility;
internal sealed class InventoryFilterFacts : IInventoryFilterFacts
{
private InventoryItem _item = null!;
private bool _identified;
private string? _spells;
private readonly uint[] _spellBuf = new uint[64];
private readonly StringBuilder _sb = new(256);
/// <summary>Points the facts at <paramref name="item"/>; cheap.</summary>
public void Bind(InventoryItem item)
{
_item = item;
_identified = AppraisalHooks.HasAppraisalData(item.Id);
_spells = null;
}
public bool Identified => _identified;
public uint SlotMask => _item.ValidLocations;
public double Number(FilterAttrInfo attr)
{
uint id = _item.Id;
switch (attr.Source)
{
case FilterSource.Public:
return attr.Id switch
{
FilterAttr.Value => _item.Value,
FilterAttr.Burden => _item.Burden,
FilterAttr.Workmanship => _item.Workmanship,
FilterAttr.Stack => Math.Max(1, _item.Stack),
_ => 0,
};
case FilterSource.Int:
return AppraisalHooks.TryGetCachedIntProperty(id, attr.Stype, out int i) ? i : 0;
case FilterSource.Float:
case FilterSource.FloatModPercent:
case FilterSource.FloatPercent:
return AppraisalHooks.TryGetCachedDoubleProperty(id, attr.Stype, out double d)
? InventoryAttributeFilter.Scale(attr.Source, d) : 0;
case FilterSource.Special when attr.Id == FilterAttr.WieldLevel:
return InventoryAttributeFilter.WieldLevel(
IntOr0(id, InventoryAttributeFilter.StypeWieldRequirements),
IntOr0(id, InventoryAttributeFilter.StypeWieldDifficulty),
IntOr0(id, InventoryAttributeFilter.StypeWieldRequirements2),
IntOr0(id, InventoryAttributeFilter.StypeWieldDifficulty2));
default:
return 0;
}
}
public bool Flag(FilterAttrInfo attr) => attr.Source switch
{
FilterSource.Public => attr.Id switch
{
FilterAttr.Equipped => _item.Wielder != 0,
FilterAttr.CastsSpell => _item.SpellId != 0,
_ => false,
},
FilterSource.IntNonZero => IntOr0(_item.Id, attr.Stype) != 0,
FilterSource.Bool => AppraisalHooks.TryGetCachedBoolProperty(_item.Id, attr.Stype, out bool b) && b,
_ => false,
};
public string Text(FilterAttrInfo attr) => attr.Id switch
{
FilterAttr.Name => _item.Name,
FilterAttr.Material => InventoryAttributeFilter.MaterialName(_item.MaterialType),
FilterAttr.SetName => InventoryAttributeFilter.SetName(IntOr0(_item.Id, attr.Stype)),
FilterAttr.Spells => _spells ??= SpellNames(),
_ => string.Empty,
};
private static int IntOr0(uint id, uint stype) =>
AppraisalHooks.TryGetCachedIntProperty(id, stype, out int v) ? v : 0;
/// <summary>The appraised spells' names, newline-separated (a rule's text can't span two).</summary>
private string SpellNames()
{
int n = AppraisalHooks.GetObjectSpellIds(_item.Id, _spellBuf, _spellBuf.Length);
if (n <= 0) return string.Empty;
if (!PortalSpellTable.Ready) PortalSpellTable.EnsureLoadQueued();
_sb.Clear();
int shown = Math.Min(n, _spellBuf.Length);
for (int k = 0; k < shown; k++)
{
// Spell ids in an appraisal can carry the layer in the high word.
uint sid = _spellBuf[k] & 0xFFFF;
if (k > 0) _sb.Append('\n');
_sb.Append(PortalSpellTable.TryGetName(sid, out string name) ? name : "spell " + sid);
}
return _sb.ToString();
}
}

View file

@ -403,6 +403,7 @@ internal static partial class InventoryModel
SampleTarget();
}
HoverTick(now);
IdentifyQueueTick(now);
}
catch (Exception ex)
{
@ -431,6 +432,7 @@ internal static partial class InventoryModel
{
_items.Clear(); // another character: nothing carries over
_identified.Clear();
ClearIdentifyQueue();
_lastPlayer = player;
_lastSignature = 0;
_playerName = string.Empty;
@ -1138,6 +1140,70 @@ internal static partial class InventoryModel
Volatile.Write(ref _tooltip, BuildTooltip(id, appraised, !appraised && sentRecently));
}
// ── Identify queue (the attribute filter's "Identify N") ────────────
private static readonly long QueuedIdentifyGapTicks = Freq / 4; // 4 a second
private const int MaxQueuedIdentifies = 1024;
private static readonly object IdQueueSync = new();
private static readonly Queue<uint> _idQueue = new(); // guarded by IdQueueSync
private static readonly HashSet<uint> _idQueued = new(); // guarded by IdQueueSync
private static long _lastQueuedIdentify;
/// <summary>Items still waiting in the identify queue. Any thread.</summary>
public static int IdentifyQueueCount
{
get { lock (IdQueueSync) return _idQueue.Count; }
}
/// <summary>
/// Asks the server to identify <paramref name="ids"/>, a few a second on AC's main thread
/// while the panel is open. Items already appraised, sent in the last minute, already
/// queued or no longer carried are skipped. Any thread.
/// </summary>
public static void QueueIdentify(IReadOnlyList<uint> ids)
{
lock (IdQueueSync)
{
foreach (uint id in ids)
{
if (id == 0 || _idQueue.Count >= MaxQueuedIdentifies) continue;
if (_idQueued.Add(id)) _idQueue.Enqueue(id);
}
}
}
/// <summary>Drops every queued identify. Any thread.</summary>
public static void ClearIdentifyQueue()
{
lock (IdQueueSync)
{
_idQueue.Clear();
_idQueued.Clear();
}
}
/// <summary>Main thread: sends the next queued identify that still needs sending.</summary>
private static void IdentifyQueueTick(long now)
{
if (now - _lastQueuedIdentify < QueuedIdentifyGapTicks) return;
while (true)
{
uint id;
lock (IdQueueSync)
{
if (!_idQueue.TryDequeue(out id)) return;
_idQueued.Remove(id);
}
if (AppraisalHooks.HasAppraisalData(id) || !_items.ContainsKey(id)) continue;
if (_identified.TryGetValue(id, out long sentAt) && now - sentAt < IdentifyRepeatTicks) continue;
if (_identified.Count > 2048) _identified.Clear();
_identified[id] = now;
_lastQueuedIdentify = now;
ClientActionHooks.RequestId(id); // main thread: the 0xC8 is sent now
return;
}
}
private static InventoryTooltip BuildTooltip(uint id, bool appraised, bool identifying)
{
var lines = new List<string>(8);

View file

@ -586,7 +586,7 @@ public static class EntryPoint
// on). Its Quests and Pets tabs are universal: the Character half of the menus.
foreach ((string label, string tab) in new[]
{
("Character", "character"), ("Banking", "banking"), ("Gear", "gear"), ("Games", "games"),
("Character", "character"), ("Banking", "banking"), ("Gear", "gear"), ("Charms", "charms"), ("Games", "games"),
})
{
UI.ServerMenus.AddItem("ilt", new UI.ServerMenuItem(label, "/rc miniremote tab " + tab,

View file

@ -0,0 +1,403 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/InventoryFace.AttrFilter.cs
// The Inventory panel's attribute filter: the funnel-list button in the tools
// row, its rule editor popup, and the per-item check in the filtered list.
// Rules and matching: Compatibility/InventoryAttributeFilter.cs; values:
// Compatibility/InventoryFilterFacts.cs.
//
// Rules on appraised attributes (armor level, ratings, spells...) can't judge
// an item the server hasn't identified yet: those items are hidden and
// counted, and "Identify N" queues them (InventoryModel.QueueIdentify, a few a
// second on AC's main thread). While such a rule is on, the list is rebuilt
// once a second so new identifies show up.
//
// Classic: the filter applies only while the tools row is open (closing the
// row turns it off, like the search), so nothing hides items unseen.
// Threads: the panel's (render) thread only.
// ============================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
using System.Text;
using ImGuiNET;
using RynthCore.Engine.Compatibility;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
namespace RynthCore.Engine.ImGuiBackend.Panels;
internal sealed partial class InventoryFace
{
private const string AttrPopupId = "##inv_attrfilter";
private static readonly long AttrRefreshTicks = Stopwatch.Frequency; // rebuild while appraisal rules are on
private InventoryAttributeFilter _attr = new();
private bool _attrLoaded;
private readonly InventoryFilterFacts _facts = new();
// Items the last rebuild hid because they need an identify.
private readonly List<uint> _unidentified = new();
private int _builtAttrKey = int.MinValue;
private long _attrRefreshAt;
private bool _attrPass;
private bool _openAttr, _attrPopupOpen, _attrSavePending;
private string _attrSummary = string.Empty;
private int _attrSummaryVersion = -1;
// The text rules' edit buffers, by rule.
private readonly Dictionary<InventoryFilterRule, byte[]> _attrText = new();
/// <summary>The attribute filter hides items now (on, has rules and, in Classic, the tools row is open).</summary>
private bool AttrOn => _attr.Active && (!InventorySettingsStore.Classic || InventorySettingsStore.ShowTools);
private void LoadAttrFilter()
{
if (_attrLoaded) return;
_attrLoaded = true;
_attr = InventoryAttributeFilter.Parse(InventorySettingsStore.AttrFilter);
}
/// <summary>An appraisal rule is on and a second has passed: rebuild to pick up new identifies.</summary>
private bool AttrRefreshDue(bool attrOn) =>
attrOn && _attr.NeedsIdentify && Stopwatch.GetTimestamp() >= _attrRefreshAt;
/// <summary>Start of a list rebuild.</summary>
private void BeginAttrPass(bool attrOn)
{
_attrPass = attrOn;
_unidentified.Clear();
_attrRefreshAt = Stopwatch.GetTimestamp() + AttrRefreshTicks;
}
/// <summary>Does the attribute filter keep <paramref name="item"/>? An unknown one is hidden and counted.</summary>
private bool AttrKeeps(InventoryItem item)
{
_facts.Bind(item);
switch (_attr.Evaluate(_facts))
{
case FilterVerdict.Match:
return true;
case FilterVerdict.Unknown:
_unidentified.Add(item.Id);
return false;
default:
return false;
}
}
/// <summary>Records an edit: the list rebuilds now; the rules are saved when the editor closes.</summary>
private void AttrChanged()
{
_attr.Touch();
_attrSavePending = true;
}
private void SetAttrEnabled(bool on)
{
if (_attr.Enabled == on) return;
_attr.Enabled = on;
_attr.Touch();
InventorySettingsStore.SetAttrFilter(_attr.Serialize());
}
private void SaveAttrIfPending()
{
if (!_attrSavePending) return;
_attrSavePending = false;
InventorySettingsStore.SetAttrFilter(_attr.Serialize());
}
// ── The tools-row button ────────────────────────────────────────────
private void AttrFilterButton(Vector2 pos)
{
bool on = AttrOn;
if (IconButton("##inv_attr", PhosphorIcons.ListChecks, pos, new Vector2(22, 22), on ? Teal : Mute,
on ? Selected : BtnFill, border: on ? Teal : 0u, font: UiFont.Ui11))
_openAttr = true;
if (!ImGuiNET.ImGui.IsItemHovered()) return;
if (_attrSummaryVersion != _attr.Version)
{
_attrSummaryVersion = _attr.Version;
_attrSummary = _attr.Rules.Count == 0 ? string.Empty : _attr.Summary();
}
string tip = on ? "Attribute filter on: " + _attrSummary
: _attr.Rules.Count > 0 ? "Attribute filter off (" + _attrSummary + ")"
: "Filter by item attributes (armor level, ratings, spells, slot...)";
if (on && _unidentified.Count > 0)
tip += "\n" + _unidentified.Count.ToString(CultureInfo.InvariantCulture) + " hidden until identified.";
ImGuiNET.ImGui.SetTooltip(tip);
}
// ── The editor popup ────────────────────────────────────────────────
/// <summary>Once per frame, outside any child.</summary>
private void AttrFilterDialog()
{
if (_openAttr)
{
_openAttr = false;
_attrPopupOpen = true;
ImGuiNET.ImGui.SetNextWindowPos(ImGuiNET.ImGui.GetMousePos(), ImGuiCond.Always);
ImGuiNET.ImGui.OpenPopup(AttrPopupId);
}
if (!_attrPopupOpen) return;
PushAttrStyle();
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(10, 8));
bool visible = ImGuiNET.ImGui.BeginPopup(AttrPopupId, ImGuiWindowFlags.AlwaysAutoResize);
ImGuiNET.ImGui.PopStyleVar();
if (!visible)
{
PopAttrStyle();
_attrPopupOpen = false; // clicked outside, or Esc
SaveAttrIfPending();
return;
}
try
{
if (AttrBody())
{
ImGuiNET.ImGui.CloseCurrentPopup();
_attrPopupOpen = false;
SaveAttrIfPending();
}
}
finally
{
ImGuiNET.ImGui.EndPopup();
PopAttrStyle();
}
}
/// <summary>The popup's contents; true when it should close.</summary>
private bool AttrBody()
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Amber);
ImGuiNET.ImGui.TextUnformatted(PhosphorIcons.ListChecks + " Filter by attributes");
ImGuiNET.ImGui.PopStyleColor();
bool on = _attr.Enabled;
if (ImGuiNET.ImGui.Checkbox("Filter on", ref on))
{
_attr.Enabled = on;
AttrChanged();
}
ImGuiNET.ImGui.SameLine(0, 16);
ImGuiNET.ImGui.TextUnformatted("Keep items matching");
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.RadioButton("all rules", !_attr.MatchAny)) { _attr.MatchAny = false; AttrChanged(); }
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.RadioButton("any rule", _attr.MatchAny)) { _attr.MatchAny = true; AttrChanged(); }
ImGuiNET.ImGui.Separator();
int remove = -1;
for (int i = 0; i < _attr.Rules.Count; i++)
{
ImGuiNET.ImGui.PushID(i);
if (RuleRow(_attr.Rules[i])) remove = i;
ImGuiNET.ImGui.PopID();
}
if (remove >= 0)
{
_attrText.Remove(_attr.Rules[remove]);
_attr.Rules.RemoveAt(remove);
AttrChanged();
}
if (_attr.Rules.Count == 0)
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Mute);
ImGuiNET.ImGui.TextUnformatted("No rules yet. Add one, e.g. Armor level >= 300.");
ImGuiNET.ImGui.PopStyleColor();
}
if (_attr.Rules.Count < InventoryAttributeFilter.MaxRules
&& ImGuiNET.ImGui.Button(PhosphorIcons.Plus + " Add rule"))
{
_attr.Rules.Add(InventoryAttributeFilter.NewRule(FilterAttr.ArmorLevel));
if (_attr.Rules.Count == 1) _attr.Enabled = true; // the first rule turns the filter on
AttrChanged();
}
IdentifySection();
ImGuiNET.ImGui.Separator();
bool close = false;
if (ImGuiNET.ImGui.Button("Clear rules") && _attr.Rules.Count > 0)
{
_attr.Rules.Clear();
_attrText.Clear();
AttrChanged();
}
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.Button("Close")) close = true;
return close;
}
/// <summary>One rule: attribute, operator, value, remove. True when its remove button was pressed.</summary>
private bool RuleRow(InventoryFilterRule rule)
{
FilterAttrInfo info = InventoryAttributeFilter.Info(rule.Attr);
ImGuiNET.ImGui.SetNextItemWidth(180);
if (ImGuiNET.ImGui.BeginCombo("##attr", AttrLabel(info)))
{
bool first = true;
foreach (FilterAttrInfo a in InventoryAttributeFilter.Attributes)
{
if (a.NeedsId && first)
{
first = false;
ImGuiNET.ImGui.Separator();
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Mute);
ImGuiNET.ImGui.TextUnformatted("Needs an identify (*)");
ImGuiNET.ImGui.PopStyleColor();
}
if (ImGuiNET.ImGui.Selectable(AttrLabel(a), a.Id == rule.Attr) && a.Id != rule.Attr)
{
InventoryAttributeFilter.SetAttr(rule, a.Id);
AttrChanged();
}
ImGuiNET.ImGui.SetItemTooltip(a.Tip);
}
ImGuiNET.ImGui.EndCombo();
}
ImGuiNET.ImGui.SetItemTooltip(info.Tip);
info = InventoryAttributeFilter.Info(rule.Attr);
ImGuiNET.ImGui.SameLine();
ImGuiNET.ImGui.SetNextItemWidth(info.Kind == FilterAttrKind.Text ? 120 : 60);
if (ImGuiNET.ImGui.BeginCombo("##op", InventoryAttributeFilter.OpLabel(rule.Op)))
{
foreach (FilterOp op in InventoryAttributeFilter.OpsFor(info.Kind))
{
if (ImGuiNET.ImGui.Selectable(InventoryAttributeFilter.OpLabel(op), op == rule.Op) && op != rule.Op)
{
rule.Op = op;
AttrChanged();
}
}
ImGuiNET.ImGui.EndCombo();
}
ImGuiNET.ImGui.SameLine();
switch (info.Kind)
{
case FilterAttrKind.Number:
{
ImGuiNET.ImGui.SetNextItemWidth(90);
double v = rule.Number;
if (ImGuiNET.ImGui.InputDouble("##num", ref v, 0, 0, "%g") && double.IsFinite(v) && v != rule.Number)
{
rule.Number = v;
AttrChanged();
}
break;
}
case FilterAttrKind.Text:
{
if (!_attrText.TryGetValue(rule, out byte[]? buf))
{
buf = new byte[64];
byte[] src = Encoding.UTF8.GetBytes(rule.Text);
Array.Copy(src, buf, Math.Min(src.Length, buf.Length - 1)); // the last byte stays the terminator
_attrText[rule] = buf;
}
ImGuiNET.ImGui.SetNextItemWidth(150);
if (ImGuiNET.ImGui.InputText("##text", buf, (uint)buf.Length))
{
rule.Text = Utf8(buf).Trim();
AttrChanged();
}
break;
}
case FilterAttrKind.Choice:
{
ImGuiNET.ImGui.SetNextItemWidth(150);
int c = Math.Clamp(rule.Choice, 0, InventoryAttributeFilter.SlotNames.Length - 1);
if (ImGuiNET.ImGui.BeginCombo("##choice", InventoryAttributeFilter.SlotNames[c]))
{
for (int k = 0; k < InventoryAttributeFilter.SlotNames.Length; k++)
{
if (ImGuiNET.ImGui.Selectable(InventoryAttributeFilter.SlotNames[k], k == c) && k != rule.Choice)
{
rule.Choice = k;
AttrChanged();
}
}
ImGuiNET.ImGui.EndCombo();
}
break;
}
default:
ImGuiNET.ImGui.Dummy(new Vector2(150, 0)); // a flag has no value; keeps the remove buttons lined up
break;
}
ImGuiNET.ImGui.SameLine();
bool removeIt = ImGuiNET.ImGui.SmallButton(PhosphorIcons.X);
ImGuiNET.ImGui.SetItemTooltip("Remove this rule");
return removeIt;
}
private static string AttrLabel(FilterAttrInfo a) => a.NeedsId ? a.Label + " *" : a.Label;
/// <summary>How many items wait for an identify, and the button that asks for them.</summary>
private void IdentifySection()
{
if (!_attr.NeedsIdentify) return;
ImGuiNET.ImGui.Separator();
int queued = InventoryModel.IdentifyQueueCount;
if (!AttrOn)
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Mute);
ImGuiNET.ImGui.TextUnformatted(InventorySettingsStore.Classic && !InventorySettingsStore.ShowTools
? "Open the tools row to use the filter." : "Turn the filter on to see which items need an identify.");
ImGuiNET.ImGui.PopStyleColor();
}
else if (_unidentified.Count == 0)
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Green);
ImGuiNET.ImGui.TextUnformatted("Every item the rules need is identified.");
ImGuiNET.ImGui.PopStyleColor();
}
else
{
string n = _unidentified.Count.ToString(CultureInfo.InvariantCulture);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Amber);
ImGuiNET.ImGui.TextUnformatted(n + (_unidentified.Count == 1 ? " item is" : " items are") + " hidden until identified.");
ImGuiNET.ImGui.PopStyleColor();
if (ImGuiNET.ImGui.Button("Identify " + n)) InventoryModel.QueueIdentify(_unidentified);
ImGuiNET.ImGui.SetItemTooltip("Asks the server about them, 4 a second while this panel is open.");
}
if (queued > 0)
{
if (AttrOn && _unidentified.Count > 0) ImGuiNET.ImGui.SameLine();
ImGuiNET.ImGui.TextUnformatted(queued.ToString(CultureInfo.InvariantCulture) + " waiting");
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.SmallButton("Stop")) InventoryModel.ClearIdentifyQueue();
}
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Mute);
ImGuiNET.ImGui.TextUnformatted("* needs an identify. Hovering an item also identifies it.");
ImGuiNET.ImGui.PopStyleColor();
}
private static void PushAttrStyle()
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.PopupBg, ShellBg);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Border, Teal);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Text);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.FrameBg, BtnFill);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, Lighten(BtnFill));
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.CheckMark, Teal);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Separator, BtnBord);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Button, BtnFill);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Lighten(BtnFill));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.PopupRounding, 4f);
}
private static void PopAttrStyle()
{
ImGuiNET.ImGui.PopStyleVar();
ImGuiNET.ImGui.PopStyleColor(9);
}
}

View file

@ -160,7 +160,7 @@ internal sealed partial class InventoryFace
// The open pack: a real pack (Classic has no "All" or "Worn" entry; the paperdoll is Worn).
if (_pack == AllPacks || _pack == WornPacks || view.PackOf(_pack) == null)
_pack = view.Packs.Length > 0 ? view.Packs[0].Id : AllPacks;
bool filtered = _category != 0 || _searchText.Length > 0;
bool filtered = FiltersOn;
RebuildIfNeeded(view, filtered ? AllPacks : _pack);
Backdrop(dl, o, w, bottom - o.Y, s);
@ -964,8 +964,9 @@ internal sealed partial class InventoryFace
}
/// <summary>
/// The Inventory panel's remembered choices: Classic or Modern look, and whether the
/// Classic view shows its tools row. %LOCALAPPDATA%\RynthCore\inventory_settings.txt,
/// The Inventory panel's remembered choices: Classic or Modern look, whether the
/// Classic view shows its tools row, its size, and the attribute filter's rules.
/// %LOCALAPPDATA%\RynthCore\inventory_settings.txt,
/// read once when the panel opens, written in the background when a choice changes.
/// </summary>
internal static class InventorySettingsStore
@ -980,6 +981,8 @@ internal static class InventorySettingsStore
/// <summary>The panel's size in percent of the UI scale (50-150, steps of 5); text follows it.</summary>
public static int SizePct { get; private set; } = 80;
public static float SizeFactor => SizePct / 100f;
/// <summary>The attribute filter's rules (InventoryAttributeFilter.Serialize); "" = none.</summary>
public static string AttrFilter { get; private set; } = string.Empty;
private static string FilePath => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RynthCore", "inventory_settings.txt");
@ -1003,6 +1006,7 @@ internal static class InventorySettingsStore
if (key == "classic") Classic = val == "1";
else if (key == "tools") ShowTools = val == "1";
else if (key == "size" && int.TryParse(val, out int pct)) SizePct = Math.Clamp(pct, 50, 150);
else if (key == "attrfilter") AttrFilter = val;
}
}
catch { /* defaults stay */ }
@ -1031,13 +1035,22 @@ internal static class InventorySettingsStore
Save();
}
public static void SetAttrFilter(string line)
{
line ??= string.Empty;
if (AttrFilter == line) return;
AttrFilter = line;
Save();
}
/// <summary>Writes the settings in the background (the caller is AC's render thread).</summary>
private static void Save()
{
string text = "# RynthCore inventory panel settings - auto-generated, hand-edits OK.\n"
+ "classic=" + (Classic ? "1" : "0") + "\n"
+ "tools=" + (ShowTools ? "1" : "0") + "\n"
+ "size=" + SizePct + "\n";
+ "size=" + SizePct + "\n"
+ "attrfilter=" + AttrFilter + "\n";
UiBackgroundWriter.Enqueue("inventory settings", () =>
{
lock (Sync)

View file

@ -7,7 +7,8 @@
// Modern the Phase 1 layout, below
//
// header burden (percent of capacity) and pyreals; item count
// tools search box, sort picker; category chips
// tools search box, attribute filter (InventoryFace.AttrFilter.cs), sort
// picker; category chips
// packs All, Main pack, each side pack (its icon and fill), Worn
// grid the chosen pack's items as icons with stack counts; hover for a
// tooltip (asks the server to identify an unknown item, throttled);
@ -125,6 +126,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
public void OnShown()
{
InventorySettingsStore.Load();
LoadAttrFilter();
InventoryModel.Subscribe();
}
@ -174,6 +176,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
ContextMenu(view);
SplitDialog(view);
ConfirmDialog();
AttrFilterDialog();
_lootAdd.Draw();
_picker.Draw();
}
@ -260,7 +263,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
float sortW = 118;
float boxW = Math.Max(80, w - sortW - 26 - 8);
float boxW = Math.Max(80, w - sortW - 26 - 26 - 8);
if (TextBox("##inv_search", _search, p, boxW, PhosphorIcons.MagnifyingGlass + " Search names", out _))
_searchText = Utf8(_search).Trim().ToLowerInvariant();
if (IconButton("##inv_clear", PhosphorIcons.X, new Vector2(p.X + boxW + 2, p.Y), new Vector2(22, 22), Mute, BtnFill,
@ -270,6 +273,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
_searchText = string.Empty;
}
ImGuiNET.ImGui.SetItemTooltip("Clear the search");
AttrFilterButton(new Vector2(p.X + boxW + 26, p.Y));
Vector2 sp = new(p.X + w - sortW, p.Y);
if (Button("##inv_sortbtn", SortLabels[_sort], sp, new Vector2(sortW, 22), Text, BtnFill,
leftAlign: true))
@ -322,12 +326,16 @@ internal sealed partial class InventoryFace : IImGuiPanel
private void RebuildIfNeeded(InventoryView view, uint pack)
{
bool classic = InventorySettingsStore.Classic;
bool attrOn = AttrOn;
int attrKey = attrOn ? _attr.Version : -1;
if (ReferenceEquals(view, _builtFor) && _builtPack == pack && _builtSort == _sort
&& _builtCategory == _category && ReferenceEquals(_builtSearch, _searchText) && _builtClassic == classic
&& _builtOrderVersion == Net.InventoryOrder.Version)
&& _builtOrderVersion == Net.InventoryOrder.Version && _builtAttrKey == attrKey && !AttrRefreshDue(attrOn))
return;
if (_builtPack != pack || !ReferenceEquals(_builtSearch, _searchText) || _builtCategory != _category)
if (_builtPack != pack || !ReferenceEquals(_builtSearch, _searchText) || _builtCategory != _category || _builtAttrKey != attrKey)
_gridFirstRow = 0; // another pack or filter: back to the top (Classic grid)
_builtAttrKey = attrKey;
BeginAttrPass(attrOn);
if (!ReferenceEquals(view, _builtFor)) PruneSelection(view);
_builtFor = view;
_builtPack = pack;
@ -363,6 +371,8 @@ internal sealed partial class InventoryFace : IImGuiPanel
_countText = _shown.Count == total
? total.ToString(CultureInfo.InvariantCulture) + " items"
: _shown.Count.ToString(CultureInfo.InvariantCulture) + " of " + total.ToString(CultureInfo.InvariantCulture);
if (_unidentified.Count > 0)
_countText += ", " + _unidentified.Count.ToString(CultureInfo.InvariantCulture) + " not ID'd";
_selectAllLabel = "Select all shown (" + _shown.Count.ToString(CultureInfo.InvariantCulture) + ")";
// The Classic grid's caption, retail's "Contents of <pack>".
_captionText = pack == WornPacks ? "Worn"
@ -396,7 +406,10 @@ internal sealed partial class InventoryFace : IImGuiPanel
/// <summary>A grid cell is a slot only while the list is the server's, whole and in pack order, and the item is an ordinary one.</summary>
private bool CellsAreSlots(InventoryItem item) =>
_orderKnown && _sort == 0 && _category == 0 && _searchText.Length == 0 && !item.RequiresPackSlot && !item.IsPack;
_orderKnown && _sort == 0 && !FiltersOn && !item.RequiresPackSlot && !item.IsPack;
/// <summary>Some filter hides items: a category, search text or the attribute filter.</summary>
private bool FiltersOn => _category != 0 || _searchText.Length > 0 || AttrOn;
/// <summary>The slot an item holds now among its pack's ordinary items, or -1 when unknown.</summary>
private static int SlotOf(InventoryItem item)
@ -419,6 +432,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
if (_skipSlotItems && it.RequiresPackSlot) continue;
if (_category != 0 && it.Category != cat) continue;
if (_searchText.Length > 0 && !it.SearchName.Contains(_searchText, StringComparison.Ordinal)) continue;
if (_attrPass && !AttrKeeps(it)) continue;
_shown.Add(it);
}
}
@ -521,7 +535,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
if (_shown.Count == 0)
{
dl.AddText(o + new Vector2(4, 4), Mute, _searchText.Length > 0 || _category != 0 ? "Nothing matches." : "Empty.");
dl.AddText(o + new Vector2(4, 4), Mute, FiltersOn ? "Nothing matches." : "Empty.");
ImGuiNET.ImGui.Dummy(new Vector2(avail, 20));
}
else
@ -758,7 +772,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
case DropKind.Pack:
if (slot == -2)
{
Refuse(_sort != 0 || _category != 0 || _searchText.Length > 0
Refuse(_sort != 0 || FiltersOn
? "To reorder, set Sort to Pack order and clear the search and filter."
: "The pack's order isn't known yet: log in again so the panel can learn it.");
return;
@ -810,12 +824,13 @@ internal sealed partial class InventoryFace : IImGuiPanel
}
}
/// <summary>Back to everything: no search text, no category.</summary>
/// <summary>Back to everything: no search text, no category, the attribute filter off (its rules kept).</summary>
private void ClearFilters()
{
Array.Clear(_search);
_searchText = string.Empty;
_category = 0;
SetAttrEnabled(false);
}
private void Refuse(string why)

View file

@ -56,23 +56,15 @@ internal sealed class SettingsFace : IImGuiPanel
// Text rows being typed in (the saved value shows again once the box loses focus).
private readonly Dictionary<SettingRow, string> _textEdits = new();
/// <summary>Extra sidebar tab after the schema tabs; drawn from UiSources.Charms, not settings rows.</summary>
private const string CharmsTabName = "Charms Tracking";
private static int CharmsTab => SettingsSchema.Tabs.Length;
private const string CharmsHeader = "Advanced Settings > " + CharmsTabName;
public void OnShown()
{
UiSources.Settings.Subscribe();
UiSources.Settings.RequestRefresh();
UiSources.Charms.Subscribe();
UiSources.Charms.RequestRefresh();
}
public void OnHidden()
{
UiSources.Settings.Unsubscribe();
UiSources.Charms.Unsubscribe();
}
public void Draw()
@ -113,9 +105,9 @@ internal sealed class SettingsFace : IImGuiPanel
var dl = ImGuiNET.ImGui.GetWindowDrawList();
float w = ImGuiNET.ImGui.GetContentRegionAvail().X;
SettingsTab[] tabs = SettingsSchema.Tabs;
for (int i = 0; i <= tabs.Length; i++)
for (int i = 0; i < tabs.Length; i++)
{
string tabName = i < tabs.Length ? tabs[i].Name : CharmsTabName;
string tabName = tabs[i].Name;
ImGuiNET.ImGui.Dummy(new Vector2(0, 1));
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
ImGuiNET.ImGui.PushID(i);
@ -167,23 +159,14 @@ internal sealed class SettingsFace : IImGuiPanel
float w = ImGuiNET.ImGui.GetContentRegionAvail().X;
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.UiBold11));
if (_tab > CharmsTab) _tab = 0;
bool charms = _tab == CharmsTab;
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFF26D9E6), charms ? CharmsHeader : Headers[_tab]);
if (_tab >= SettingsSchema.Tabs.Length) _tab = 0;
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFF26D9E6), Headers[_tab]);
ImGuiNET.ImGui.PopFont();
ImGuiNET.ImGui.Dummy(new Vector2(0, 4));
Vector2 lp = ImGuiNET.ImGui.GetCursorScreenPos();
dl.AddLine(lp, lp + new Vector2(w, 0), BtnBord);
ImGuiNET.ImGui.Dummy(new Vector2(0, 6));
if (charms)
{
CharmsTabContent(w);
ImGuiNET.ImGui.PopStyleVar();
ImGuiNET.ImGui.EndChild();
return;
}
SettingRow[] rows = SettingsSchema.Tabs[_tab].Rows;
for (int i = 0; i < rows.Length; i++)
{
@ -548,130 +531,6 @@ internal sealed class SettingsFace : IImGuiPanel
}
}
// ── Charms Tracking tab ───────────────────────────────────────────────
private static readonly uint CharmOn = C(0xFF33FF33), CharmDisabled = C(0xFFFF5555);
/// <summary>Summary line, one table row per ACECustom registry charm, then how each column is known.</summary>
private static void CharmsTabContent(float w)
{
var snap = UiSources.Charms.Current;
if (snap == null)
{
Note("Waiting for RynthAi...", w);
return;
}
CharmsInfo info = snap.Value;
if (!info.Available)
{
Note("Charm tracking is for ILT (Infinite Leaftide / ACECustom) worlds."
+ (info.World.Length > 0 ? " Current world: " + info.World + "." : ""), w);
Note("Use /ra hub force on to treat this world as ILT.", w);
return;
}
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.UiBold11));
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFE8B333),
$"{info.AcquiredCount} of {info.Total} acquired | {info.ActiveCount} active");
ImGuiNET.ImGui.PopFont();
ImGuiNET.ImGui.Dummy(new Vector2(0, 4));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(4, 3));
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.TableRowBg, PanelBg);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.TableRowBgAlt, ShellBg);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.TableHeaderBg, TabActive);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.TableBorderLight, BtnBord);
const ImGuiTableFlags flags = ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersInnerH | ImGuiTableFlags.SizingFixedFit;
if (ImGuiNET.ImGui.BeginTable("##charms", 5, flags, new Vector2(w, 0)))
{
ImGuiNET.ImGui.TableSetupColumn("Charm", ImGuiTableColumnFlags.WidthStretch);
ImGuiNET.ImGui.TableSetupColumn("Acquired", ImGuiTableColumnFlags.WidthFixed, 70);
ImGuiNET.ImGui.TableSetupColumn("Status", ImGuiTableColumnFlags.WidthFixed, 44);
ImGuiNET.ImGui.TableSetupColumn("Tier", ImGuiTableColumnFlags.WidthFixed, 32);
ImGuiNET.ImGui.TableSetupColumn("Server", ImGuiTableColumnFlags.WidthFixed, 56);
ImGuiNET.ImGui.TableHeadersRow();
CharmRow[] rows = info.Charms;
for (int i = 0; i < rows.Length; i++)
{
CharmRow r = rows[i];
ImGuiNET.ImGui.PushID(i);
ImGuiNET.ImGui.TableNextRow();
ImGuiNET.ImGui.TableNextColumn();
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFF2F7FC), r.Name);
if (r.Effect.Length > 0) ImGuiNET.ImGui.SetItemTooltip(r.Effect);
ImGuiNET.ImGui.TableNextColumn();
switch (r.Acquired)
{
case "carried":
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFF26D9E6), r.Count > 1 ? $"Carried x{r.Count}" : "Carried");
ImGuiNET.ImGui.SetItemTooltip("In your pack or equipped.");
break;
case "seen":
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFE8B333), "Stored");
ImGuiNET.ImGui.SetItemTooltip("Owned but not carried"
+ (r.LastSeen.Length > 0 ? " (last carried " + r.LastSeen + ")" : "")
+ ". The client only sees items you carry.");
break;
default:
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFB8C8D8), "Not yet");
break;
}
ImGuiNET.ImGui.TableNextColumn();
if (r.Acquired != "carried")
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFB8C8D8), "-");
else if (r.Active == "on")
ColoredText(CharmOn, "ON");
else if (r.Active == "off")
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFB8C8D8), "OFF");
else
{
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFE8B333), "?");
ImGuiNET.ImGui.SetItemTooltip("Waiting for the charm's appraisal (requested automatically).");
}
ImGuiNET.ImGui.TableNextColumn();
string tier = r.Tier <= 0 ? "-" : r.MaxTier > 0 ? $"{r.Tier}/{r.MaxTier}" : r.Tier.ToString(CultureInfo.InvariantCulture);
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFF2F7FC), tier);
ImGuiNET.ImGui.TableNextColumn();
if (r.Server == "off")
{
ColoredText(CharmDisabled, "Disabled");
ImGuiNET.ImGui.SetItemTooltip("The server refused or reported this charm as disabled.");
}
else if (r.Server == "on")
ColoredText(CharmOn, "Enabled");
else
{
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFB8C8D8), "-");
ImGuiNET.ImGui.SetItemTooltip("Not reported. The server only tells players when a charm is refused.");
}
ImGuiNET.ImGui.PopID();
}
ImGuiNET.ImGui.EndTable();
}
ImGuiNET.ImGui.PopStyleColor(4);
ImGuiNET.ImGui.PopStyleVar();
ImGuiNET.ImGui.Dummy(new Vector2(0, 6));
Note("Double-click a carried charm in your pack to toggle it. Status comes from the charm's appraisal "
+ "(Status: ON/OFF) or your character's ability flag. Charms not carried are inactive.", w);
Note("Stored = carried by this character before; RynthAi remembers it per character.", w);
}
/// <summary>TextUnformatted in a packed ImGui colour.</summary>
private static void ColoredText(uint abgr, string text)
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, abgr);
ImGuiNET.ImGui.TextUnformatted(text);
ImGuiNET.ImGui.PopStyleColor();
}
private static bool StepButton(string id, Vector2 pos, string glyph)
{
var dl = ImGuiNET.ImGui.GetWindowDrawList();
@ -700,7 +559,6 @@ internal sealed class SettingsFace : IImGuiPanel
["Looting"] = PhosphorIcons.Bag,
["Vendoring"] = PhosphorIcons.Storefront,
["Diagnostics"] = PhosphorIcons.Wrench,
[CharmsTabName] = PhosphorIcons.Gift,
};
private static readonly System.Collections.Generic.Dictionary<string, string> TabLabels = new();

View file

@ -1,78 +0,0 @@
// ============================================================================
// RynthCore.Engine - UI/Data/CharmsData.cs
// RynthAi's ACECustom charm tracker for the Settings panel's "Charms
// Tracking" tab. RynthAi owns the charm registry (WCIDs, ability flags) and
// the per-character "seen" memory; this side only shows the snapshot.
// ============================================================================
using System;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using RynthCore.Engine.Plugins;
namespace RynthCore.Engine.UI.Data;
/// <summary>RynthPluginGetCharmsJson's payload.</summary>
internal sealed class CharmsInfo
{
/// <summary>False off ILT-like worlds (or before RynthAi's ILT Hub exists).</summary>
[JsonPropertyName("available")] public bool Available { get; set; }
[JsonPropertyName("world")] public string World { get; set; } = "";
[JsonPropertyName("total")] public int Total { get; set; }
[JsonPropertyName("acquiredCount")] public int AcquiredCount { get; set; }
[JsonPropertyName("activeCount")] public int ActiveCount { get; set; }
[JsonPropertyName("charms")] public CharmRow[] Charms { get; set; } = Array.Empty<CharmRow>();
}
internal sealed class CharmRow
{
[JsonPropertyName("name")] public string Name { get; set; } = "";
[JsonPropertyName("effect")] public string Effect { get; set; } = "";
/// <summary>"carried" (in pack / equipped now), "seen" (carried before, now elsewhere) or "no".</summary>
[JsonPropertyName("acquired")] public string Acquired { get; set; } = "no";
/// <summary>Copies carried right now.</summary>
[JsonPropertyName("count")] public int Count { get; set; }
/// <summary>Best tier carried or last seen; 0 until an appraisal reports it.</summary>
[JsonPropertyName("tier")] public int Tier { get; set; }
[JsonPropertyName("maxTier")] public int MaxTier { get; set; }
/// <summary>Ability toggled on: "on", "off" or "unknown".</summary>
[JsonPropertyName("active")] public string Active { get; set; } = "unknown";
/// <summary>Server-side global switch as far as the client has learned it: "on", "off" or "unknown".</summary>
[JsonPropertyName("server")] public string Server { get; set; } = "unknown";
/// <summary>yyyy-MM-dd the charm was last carried (empty when never).</summary>
[JsonPropertyName("lastSeen")] public string LastSeen { get; set; } = "";
}
[JsonSerializable(typeof(CharmsInfo))]
internal sealed partial class CharmsJsonContext : JsonSerializerContext { }
/// <summary>
/// RynthPluginGetCharmsJson (single static buffer: one caller only) while the Settings panel
/// is open. Every 2 s is plenty: charm state only changes when one is picked up or toggled.
/// </summary>
internal sealed unsafe class CharmsSource : UiSource<CharmsInfo>
{
private delegate* unmanaged[Cdecl]<IntPtr> _getCharmsJson;
public CharmsSource() : base("Charms", periodMs: 2000) { }
protected internal override void Poll()
{
if (_getCharmsJson == null)
_getCharmsJson = (delegate* unmanaged[Cdecl]<IntPtr>)PluginExportBinder.Resolve("RynthAi", "RynthPluginGetCharmsJson");
if (_getCharmsJson == null) return;
IntPtr p = _getCharmsJson();
string json = p == IntPtr.Zero ? "{}" : Marshal.PtrToStringAnsi(p) ?? "{}";
CharmsInfo info;
try { info = JsonSerializer.Deserialize(json, CharmsJsonContext.Default.CharmsInfo) ?? new CharmsInfo(); }
catch (JsonException) { info = new CharmsInfo(); }
Publish(info);
}
protected internal override void Reset()
{
_getCharmsJson = null;
ClearSnapshot();
}
}

View file

@ -17,7 +17,6 @@ internal static class UiSources
public static readonly RynthAiSource RynthAi = new();
public static readonly PatrolSource Patrol = new();
public static readonly ProgressionSource Progression = new();
public static readonly CharmsSource Charms = new();
public static readonly RadarSource Radar = new();
public static readonly SettingsSource Settings = new();
public static readonly MetaSource Meta = new();
@ -57,7 +56,6 @@ internal static class UiSources
UiDataHub.Register(RynthAi);
UiDataHub.Register(Patrol);
UiDataHub.Register(Progression);
UiDataHub.Register(Charms);
UiDataHub.Register(PluginStatus);
UiDataHub.Register(Log);
UiDataHub.Register(Tracker);