RynthSuite/Plugins/RynthCore.Plugin.RynthAi/Huds/HudState.cs
BlankenshipG 09b14d4ed1 feat(rynthai): ILT Hub, HUDs, item info, chat translation, ground loot and nav editing
- ILT Hub (overlay window, /ra hub): character progression, pets, quests,
  gear, banking, guardian, buff keepers, session rates, USD import.
- Floating HUDs: combat tracker, item count HUD, Mini Remote (/ra remote,
  /ra huds).
- Item info (Mag-style describer) on select, with its own settings window.
- Chat translation (/ra translate) for chosen channels.
- Ground loot: loose items matching the loot profile are picked up when no
  corpse is in range (CorpseOpenController).
- Nav: breadcrumb recorder, route overlay, and the route editor commands
  the engine Nav panel sends (multi-select move/duplicate/delete, reverse,
  snap to path, pauses, portals, simplify, trail -> route).
- Pets: refill-loop guard for essences the server just confirmed full;
  optional ILT Hub hooks (summon on empty, hold, yield a cosmetic pet).
- QuestTracker: quiet refreshes, Disabled / LastStatus for the hub.
- WorldObjectCache: typed items (keys, gems, comps, food) are placed in
  inventory or landscape by ownership instead of staying Unknown.
- Install-aware data folders (RynthInstallPaths) and a per-category
  diagnostics log (Diagnostics/RynthLog, diagnostics.json).
- Monster Editor: VirindiTank USD import and "Import UB damage insights"
  (ub-mob-seed.json); RynthAi loads the seed (UbMobSeedStore).

Kept as on rynth/main: combat (ammo, off-hand/shield rules), AutoStack in
InventoryManager, LegacyAdvancedSettingsUi and the version stamping. No
host API slots are used; new engine data comes from optional exports
(RynthPluginRenderOverlay, RynthPluginGetProgressionJson,
RynthPluginGetCharmsJson).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-05 16:52:13 -04:00

119 lines
4.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// HudState.cs — Persisted per-character settings for the floating HUD windows
// (<charFolder>\huds.json). Fields, not properties, so the source-generated
// RynthAiJsonContext (IncludeFields) round-trips them under NativeAOT.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace RynthCore.Plugin.RynthAi.Huds;
public sealed class HudState
{
/// <summary>Mini Remote gem grid size (UB layout: 5 columns × 6 rows).</summary>
public const int MiniRemoteColumns = 5;
public const int MiniRemoteSlotCount = 30;
/// <summary>The "Inventory HUDs" setup window is open.</summary>
public bool ShowSetup;
// ── Pack item count HUD ──
public bool ShowItemHud;
public bool ItemHudShowNames;
public bool ItemHudLocked;
public float ItemHudIconSize = 20f;
/// <summary>Items shown on the HUD, in display order (matched by name).</summary>
public List<HudItemEntry> ItemHudItems = new();
// ── Mini Remote ──
public bool ShowMiniRemote;
public bool MiniRemoteLocked;
/// <summary>Sections laid out side by side in columns (the V/H button) instead of stacked.</summary>
public bool MiniRemoteHorizontal;
public bool MiniShowStats = true;
/// <summary>Attack target row: name, health bar, distance.</summary>
public bool MiniShowTarget = true;
/// <summary>Pet row: the summon that is out (health, time left), else the next combat essence.</summary>
public bool MiniShowPet = true;
public bool MiniShowGems = true;
public bool MiniShowToggles = true;
public bool MiniShowBank = true;
public bool MiniShowRebuff = true;
/// <summary>Chat translator row: on/off, receive / send language swap.</summary>
public bool MiniShowTranslate = true;
/// <summary>Temple guardian row: the last riddle answer with a Give button (only while one is recent).</summary>
public bool MiniShowGuardian = true;
/// <summary>Gem grid slots, row-major from the top-left (empty Name = unassigned).</summary>
public List<HudItemEntry> MiniRemoteSlots = new();
}
/// <summary>An item pinned to a HUD. Matched by name; Wcid / IconDid are remembered so the
/// entry still shows its icon while none are carried.</summary>
public sealed class HudItemEntry
{
public string Name = string.Empty;
public uint Wcid;
public uint IconDid;
[JsonIgnore] public bool IsEmpty => string.IsNullOrWhiteSpace(Name);
}
/// <summary>Loads / dirty-checked saves of <see cref="HudState"/>.</summary>
internal sealed class HudStore
{
private readonly string _charFolder;
private string _lastJson = string.Empty;
public HudStore(string charFolder) => _charFolder = charFolder ?? string.Empty;
private string StatePath => Path.Combine(_charFolder, "huds.json");
public HudState Load()
{
HudState? s = null;
try
{
if (_charFolder.Length > 0 && File.Exists(StatePath))
{
string json = File.ReadAllText(StatePath);
s = JsonSerializer.Deserialize(json, RynthAiJsonContext.Default.HudState);
if (s != null) _lastJson = json;
}
}
catch (Exception ex) { RynthLog.Exception(LogCat.Huds, ex, $"load {StatePath}"); }
s ??= new HudState();
Normalize(s);
return s;
}
/// <summary>Writes the state only when its JSON differs from the last write.</summary>
public void SaveIfDirty(HudState state)
{
if (_charFolder.Length == 0) return;
try
{
string json = JsonSerializer.Serialize(state, RynthAiJsonContext.Default.HudState);
if (json == _lastJson) return;
Directory.CreateDirectory(_charFolder);
string tmp = StatePath + ".tmp";
File.WriteAllText(tmp, json);
File.Move(tmp, StatePath, overwrite: true);
_lastJson = json;
}
catch (Exception ex) { RynthLog.Exception(LogCat.Huds, ex, $"save {StatePath}"); }
}
/// <summary>Repairs null lists / out-of-range values after deserialization.</summary>
private static void Normalize(HudState s)
{
s.ItemHudItems ??= new();
s.ItemHudItems.RemoveAll(e => e == null || e.IsEmpty);
s.ItemHudIconSize = Math.Clamp(s.ItemHudIconSize, 12f, 48f);
s.MiniRemoteSlots ??= new();
for (int i = 0; i < s.MiniRemoteSlots.Count; i++) s.MiniRemoteSlots[i] ??= new HudItemEntry();
while (s.MiniRemoteSlots.Count < HudState.MiniRemoteSlotCount) s.MiniRemoteSlots.Add(new HudItemEntry());
if (s.MiniRemoteSlots.Count > HudState.MiniRemoteSlotCount)
s.MiniRemoteSlots.RemoveRange(HudState.MiniRemoteSlotCount, s.MiniRemoteSlots.Count - HudState.MiniRemoteSlotCount);
}
}