RynthSuite/Plugins/RynthCore.Plugin.RynthAi/UiPlacement.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

54 lines
2.4 KiB
C#

// UiPlacement.cs - Shared first-use placement and off-screen rescue for RynthAi's floating
// ImGui windows (render thread only).
//
// Windows with no imgui.ini entry open near the middle of the game view instead of ImGui's
// default (60,60), where a popped-out panel above the game frame would hide them. A window
// whose saved position leaves it (almost) off the game view is moved back to the middle.
using System.Numerics;
using ImGuiNET;
namespace RynthCore.Plugin.RynthAi;
internal static class UiPlacement
{
/// <summary>Pixels of a window that must stay inside the game view to count as on-screen.</summary>
private const float MinVisible = 40f;
private static readonly Vector2 CenterPivot = new(0.5f, 0.5f);
/// <summary>
/// Before Begin: if the window has no saved position, centre it in the game view, shifted by
/// <paramref name="offset"/> so windows opened together don't stack exactly.
/// </summary>
public static void CenterFirstUse(Vector2 offset = default)
{
Vector2 display = ImGui.GetIO().DisplaySize;
if (display.X <= 1 || display.Y <= 1) return; // no display size yet: ImGui's default spot
ImGui.SetNextWindowPos(display * 0.5f + offset, ImGuiCond.FirstUseEver, CenterPivot);
}
/// <summary>
/// Between Begin and End, once per show (<paramref name="checkedThisShow"/> is cleared by the
/// caller while the window is hidden): moves the window to the middle of the game view if
/// less than 40 px of it is on screen. Returns true when it moved the window.
/// </summary>
public static bool RescueOncePerShow(ref bool checkedThisShow)
{
if (checkedThisShow) return false;
checkedThisShow = true;
Vector2 pos = ImGui.GetWindowPos();
Vector2 size = ImGui.GetWindowSize();
Vector2 display = ImGui.GetIO().DisplaySize;
if (display.X <= MinVisible * 2 || display.Y <= MinVisible * 2) return false;
if (IsOnScreen(pos, size, display)) return false;
ImGui.SetWindowPos(Vector2.Max(Vector2.Zero, (display - size) * 0.5f));
return true;
}
/// <summary>True when at least 40 px of the window overlaps the game view on each axis.</summary>
public static bool IsOnScreen(Vector2 pos, Vector2 size, Vector2 display) =>
pos.X + size.X >= MinVisible && pos.Y + size.Y >= MinVisible
&& pos.X <= display.X - MinVisible && pos.Y <= display.Y - MinVisible;
}