Snapshot for release 2026.10.15.6 (internal 6fd9478)
This commit is contained in:
parent
aba17a9834
commit
a57049d931
44 changed files with 12244 additions and 10674 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
@ -8,6 +7,12 @@ using RynthCore.Engine.Hooking;
|
|||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
// 2026-10-15: back on the kernel32 exports. SilentKelpie's 2026-10-14 change hooked only the
|
||||
// acclient.exe and MSVCR70 CreateFile import slots, but AC opens its data files with
|
||||
// CreateFileW by another route: no .dat open reached the hook, the first client on that
|
||||
// engine held a data file without sharing it, and every client started after it stopped
|
||||
// with "Can't open the data files" (2026.10.15.2 / .3). Only .dat paths are changed; every
|
||||
// other CreateFile (Direct3D, drivers) passes through untouched with its last-error kept.
|
||||
/// <summary>
|
||||
/// IAT-hooks acclient.exe's <c>kernel32!CreateFileW</c> and <c>CreateFileA</c>
|
||||
/// imports to force maximally-permissive share semantics on AC's data files.
|
||||
|
|
@ -28,19 +33,12 @@ namespace RynthCore.Engine.Compatibility;
|
|||
/// Other paths pass through untouched.
|
||||
///
|
||||
/// Why IAT-hook instead of MinHook on the kernel32 export:
|
||||
/// Only the modules that open AC's data files are hooked: acclient.exe
|
||||
/// (imports CreateFileA) and its CRT MSVCR70.dll (CreateFileA/W, behind
|
||||
/// fopen/_wfopen). A kernel32 export hook also caught every other module,
|
||||
/// including d3d9.dll and the GPU driver while AC created its device: their
|
||||
/// CreateFile calls went through managed code, could wait on the runtime
|
||||
/// while plugins loaded, and on some PCs AC then failed with "Could not
|
||||
/// initialize Direct3D" (2026-10-14). The detour preserves the Win32 last
|
||||
/// error, because callers read it after a successful CreateFile too
|
||||
/// (ERROR_ALREADY_EXISTS).
|
||||
/// Decal coexistence: our detour calls the pointer the IAT slot held, so any
|
||||
/// Decal detour on the kernel32 export still runs. Both hooks fire in order.
|
||||
/// The slots are restored at engine shutdown (<see cref="Uninstall"/>): the
|
||||
/// detours live in this engine generation, which hot reload unloads.
|
||||
/// Decal coexistence. Decal almost certainly already detours kernel32!CreateFile
|
||||
/// (that's how Decal-injected Thwargle clients can multibox without a
|
||||
/// second AC install). IAT-hooking acclient.exe's import slot intercepts only
|
||||
/// acclient.exe's own calls; our detour's call into the saved IAT pointer
|
||||
/// still routes through any Decal MinHook trampoline on the kernel32 export.
|
||||
/// No collision; both hooks fire in order.
|
||||
/// </summary>
|
||||
internal static class DatFileShareHooks
|
||||
{
|
||||
|
|
@ -85,16 +83,23 @@ internal static class DatFileShareHooks
|
|||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);
|
||||
|
||||
/// <summary>
|
||||
/// One patched import slot. <see cref="Slot"/> is the address inside the IAT array (not a
|
||||
/// function address); <see cref="Original"/> is what it held (the real kernel32!CreateFile,
|
||||
/// or another hooker's detour), written back by <see cref="Uninstall"/>. <see cref="Detour"/>
|
||||
/// keeps the delegate reachable: the function pointer handed to native code is only valid
|
||||
/// while it is.
|
||||
/// </summary>
|
||||
private sealed record IatHook(string Module, string Function, IntPtr Slot, IntPtr Original, Delegate Detour);
|
||||
// Pinned via static field — Marshal.GetFunctionPointerForDelegate keeps a
|
||||
// weak handle, so the delegate must be reachable for the process lifetime.
|
||||
private static CreateFileWDelegate? _wDetour;
|
||||
private static CreateFileADelegate? _aDetour;
|
||||
|
||||
private static readonly List<IatHook> _iatHooks = [];
|
||||
// The IAT slot pointer (the address inside the IAT array, NOT the original
|
||||
// function address) — needed for the unhook path.
|
||||
private static IntPtr _wIatSlot;
|
||||
private static IntPtr _aIatSlot;
|
||||
|
||||
// What was in the IAT slot when we patched it. Could be the real
|
||||
// kernel32!CreateFile, or another hooker's detour if they got there first.
|
||||
private static IntPtr _wOriginalPtr;
|
||||
private static IntPtr _aOriginalPtr;
|
||||
|
||||
private static CreateFileWDelegate? _wOriginal;
|
||||
private static CreateFileADelegate? _aOriginal;
|
||||
|
||||
private static string _statusMessage = "Not probed yet.";
|
||||
|
||||
|
|
@ -138,23 +143,80 @@ internal static class DatFileShareHooks
|
|||
return;
|
||||
}
|
||||
|
||||
// acclient.exe opens DATs with its own CreateFileA import; its CRT
|
||||
// (MSVCR70.dll, statically imported, so loaded by now) does fopen/_wfopen
|
||||
// opens through its CreateFileA/W imports. Nothing else is hooked.
|
||||
HookModuleImports("acclient.exe", moduleBase);
|
||||
HookModuleImports("MSVCR70.dll", GetModuleHandleW("MSVCR70.dll"));
|
||||
|
||||
if (_iatHooks.Count == 0)
|
||||
// Hook the kernel32 exports directly with MinHook so we catch ALL
|
||||
// callers in the process — acclient.exe itself, the CRT layer
|
||||
// (msvcrt.dll, which is how AC's fopen-style DAT loads route), and
|
||||
// any plugin or runtime DLL. IAT-hooking acclient.exe alone misses
|
||||
// CRT-mediated calls because they go through msvcrt's own IAT slot.
|
||||
IntPtr hKernel32 = GetModuleHandleW("kernel32.dll");
|
||||
if (hKernel32 == IntPtr.Zero)
|
||||
{
|
||||
_statusMessage = "no CreateFile import slots found in acclient.exe or MSVCR70.dll.";
|
||||
_statusMessage = "kernel32.dll module handle not found.";
|
||||
RynthLog.Compat($"Compat: DAT share hook failed - {_statusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Two-phase install. Phase 1: create both hooks (inactive),
|
||||
// assign typed trampolines into _aOriginal/_wOriginal. Phase 2:
|
||||
// memory barrier then Enable. Critical ordering: the detour can
|
||||
// fire from ANY caller in the process the moment Enable returns,
|
||||
// and the detour calls _aOriginal/_wOriginal — those fields MUST
|
||||
// be set first or the first invocation null-derefs and kills the
|
||||
// engine init thread.
|
||||
IntPtr aTarget = GetProcAddress(hKernel32, "CreateFileA");
|
||||
IntPtr wTarget = GetProcAddress(hKernel32, "CreateFileW");
|
||||
|
||||
int patched = 0;
|
||||
if (aTarget != IntPtr.Zero)
|
||||
{
|
||||
_aDetour = CreateFileADetour;
|
||||
IntPtr aDetourPtr = Marshal.GetFunctionPointerForDelegate(_aDetour);
|
||||
_aOriginalPtr = MinHook.HookCreate(aTarget, aDetourPtr);
|
||||
_aOriginal = Marshal.GetDelegateForFunctionPointer<CreateFileADelegate>(_aOriginalPtr);
|
||||
patched++;
|
||||
}
|
||||
|
||||
if (wTarget != IntPtr.Zero)
|
||||
{
|
||||
_wDetour = CreateFileWDetour;
|
||||
IntPtr wDetourPtr = Marshal.GetFunctionPointerForDelegate(_wDetour);
|
||||
_wOriginalPtr = MinHook.HookCreate(wTarget, wDetourPtr);
|
||||
_wOriginal = Marshal.GetDelegateForFunctionPointer<CreateFileWDelegate>(_wOriginalPtr);
|
||||
patched++;
|
||||
}
|
||||
|
||||
// Publish trampolines to other cores before enabling.
|
||||
Thread.MemoryBarrier();
|
||||
|
||||
if (aTarget != IntPtr.Zero)
|
||||
{
|
||||
MinHook.Enable(aTarget);
|
||||
RynthLog.Info($"Compat: DAT share - hooked kernel32!CreateFileA @ 0x{aTarget.ToInt32():X8} (trampoline 0x{_aOriginalPtr.ToInt32():X8}).");
|
||||
}
|
||||
else
|
||||
{
|
||||
RynthLog.Compat("Compat: DAT share - kernel32!CreateFileA export not found.");
|
||||
}
|
||||
|
||||
if (wTarget != IntPtr.Zero)
|
||||
{
|
||||
MinHook.Enable(wTarget);
|
||||
RynthLog.Info($"Compat: DAT share - hooked kernel32!CreateFileW @ 0x{wTarget.ToInt32():X8} (trampoline 0x{_wOriginalPtr.ToInt32():X8}).");
|
||||
}
|
||||
else
|
||||
{
|
||||
RynthLog.Compat("Compat: DAT share - kernel32!CreateFileW export not found.");
|
||||
}
|
||||
|
||||
if (patched == 0)
|
||||
{
|
||||
_statusMessage = "MinHook on kernel32 CreateFile exports failed.";
|
||||
RynthLog.Compat($"Compat: DAT share hook failed - {_statusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
IsInstalled = true;
|
||||
_statusMessage = $"DAT share hook installed ({_iatHooks.Count} import slot(s): " +
|
||||
string.Join(", ", _iatHooks.Select(h => $"{h.Module}!{h.Function}")) +
|
||||
"); Direct3D and drivers call CreateFile unhooked.";
|
||||
_statusMessage = $"DAT share hook installed ({patched} kernel32 export(s) detoured).";
|
||||
RynthLog.Info($"Compat: {_statusMessage}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -164,84 +226,9 @@ internal static class DatFileShareHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Points <paramref name="moduleName"/>'s kernel32 CreateFileA/W import slots at detours that
|
||||
/// call whatever each slot held. A module that isn't loaded, or doesn't import one of them,
|
||||
/// is skipped (logged).
|
||||
/// </summary>
|
||||
private static void HookModuleImports(string moduleName, IntPtr moduleBase)
|
||||
{
|
||||
if (moduleBase == IntPtr.Zero)
|
||||
{
|
||||
RynthLog.Compat($"Compat: DAT share - {moduleName} is not loaded; its CreateFile imports are not hooked.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryPatchIatSlot(moduleBase, "CreateFileW", out IntPtr wSlot, out IntPtr wCurrent))
|
||||
{
|
||||
CreateFileWDelegate original = Marshal.GetDelegateForFunctionPointer<CreateFileWDelegate>(wCurrent);
|
||||
CreateFileWDelegate detour = (name, access, share, security, disposition, flags, template) =>
|
||||
CreateFileWDetour(original, name, access, share, security, disposition, flags, template);
|
||||
InstallSlot(moduleName, "CreateFileW", wSlot, wCurrent, detour, Marshal.GetFunctionPointerForDelegate(detour));
|
||||
}
|
||||
|
||||
if (TryPatchIatSlot(moduleBase, "CreateFileA", out IntPtr aSlot, out IntPtr aCurrent))
|
||||
{
|
||||
CreateFileADelegate original = Marshal.GetDelegateForFunctionPointer<CreateFileADelegate>(aCurrent);
|
||||
CreateFileADelegate detour = (name, access, share, security, disposition, flags, template) =>
|
||||
CreateFileADetour(original, name, access, share, security, disposition, flags, template);
|
||||
InstallSlot(moduleName, "CreateFileA", aSlot, aCurrent, detour, Marshal.GetFunctionPointerForDelegate(detour));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records the hook (so the delegate stays reachable) before the slot is written: the
|
||||
/// detour can run on any thread the moment the pointer lands.
|
||||
/// </summary>
|
||||
private static void InstallSlot(string moduleName, string function, IntPtr slot, IntPtr original, Delegate detour, IntPtr detourPtr)
|
||||
{
|
||||
var hook = new IatHook(moduleName, function, slot, original, detour);
|
||||
_iatHooks.Add(hook);
|
||||
Thread.MemoryBarrier();
|
||||
|
||||
if (WriteIatPointer(slot, detourPtr))
|
||||
{
|
||||
RynthLog.Info($"Compat: DAT share - hooked {moduleName}!{function} import (slot 0x{slot.ToInt32():X8}, was 0x{original.ToInt32():X8}).");
|
||||
return;
|
||||
}
|
||||
|
||||
_iatHooks.Remove(hook);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes every patched slot back to what it held, at engine shutdown. The detours are in
|
||||
/// this engine generation, which hot reload unloads; a slot left pointing at them would
|
||||
/// crash the next CreateFile.
|
||||
/// </summary>
|
||||
public static void Uninstall()
|
||||
{
|
||||
if (_iatHooks.Count == 0)
|
||||
return;
|
||||
|
||||
int restored = 0;
|
||||
foreach (IatHook hook in _iatHooks)
|
||||
{
|
||||
if (WriteIatPointer(hook.Slot, hook.Original))
|
||||
restored++;
|
||||
}
|
||||
|
||||
RynthLog.Info($"Compat: DAT share - restored {restored}/{_iatHooks.Count} CreateFile import slot(s).");
|
||||
_iatHooks.Clear();
|
||||
IsInstalled = false;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern IntPtr GetModuleHandleW(string? lpModuleName);
|
||||
|
||||
// Plain import (no SetLastError marshalling): it must leave the value it sets.
|
||||
[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
|
||||
private static extern void SetWin32LastError(uint dwErrCode);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
|
||||
|
||||
|
|
@ -421,8 +408,12 @@ internal static class DatFileShareHooks
|
|||
&& path.EndsWith(DatExtension, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// Puts back the Win32 last-error the real CreateFile set, so the caller reads its own answer
|
||||
// (the detour's managed work in between may change it; SilentKelpie's 2026-10-14 fix).
|
||||
[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
|
||||
private static extern void SetWin32LastError(uint dwErrCode);
|
||||
|
||||
private static IntPtr CreateFileWDetour(
|
||||
CreateFileWDelegate original,
|
||||
IntPtr lpFileName,
|
||||
uint dwDesiredAccess,
|
||||
uint dwShareMode,
|
||||
|
|
@ -452,14 +443,14 @@ internal static class DatFileShareHooks
|
|||
{
|
||||
}
|
||||
|
||||
IntPtr result = original(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
|
||||
IntPtr result = _wOriginal!(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
||||
// Captured by the SetLastError=true delegate; the caller may read it even on success.
|
||||
int lastError = Marshal.GetLastPInvokeError();
|
||||
|
||||
if (isAnyDatExt)
|
||||
{
|
||||
int err = result == new IntPtr(-1) ? lastError : 0;
|
||||
uint err = result == new IntPtr(-1) ? (uint)lastError : 0;
|
||||
string fname = Path.GetFileName(path!);
|
||||
string note = isDat ? "filtered" : "passthrough";
|
||||
RynthLog.Info($"Compat: DAT share - W [{note}]: {fname} access=0x{origAccess:X8}->0x{dwDesiredAccess:X8} share=0x{origShare:X}->0x{dwShareMode:X} result=0x{result.ToInt32():X8}{(err != 0 ? $" GetLastError={err}" : "")}");
|
||||
|
|
@ -470,7 +461,6 @@ internal static class DatFileShareHooks
|
|||
}
|
||||
|
||||
private static IntPtr CreateFileADetour(
|
||||
CreateFileADelegate original,
|
||||
IntPtr lpFileName,
|
||||
uint dwDesiredAccess,
|
||||
uint dwShareMode,
|
||||
|
|
@ -500,13 +490,14 @@ internal static class DatFileShareHooks
|
|||
{
|
||||
}
|
||||
|
||||
IntPtr result = original(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
|
||||
IntPtr result = _aOriginal!(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
||||
// Captured by the SetLastError=true delegate; the caller may read it even on success.
|
||||
int lastError = Marshal.GetLastPInvokeError();
|
||||
|
||||
if (isAnyDatExt)
|
||||
{
|
||||
int err = result == new IntPtr(-1) ? lastError : 0;
|
||||
uint err = result == new IntPtr(-1) ? (uint)lastError : 0;
|
||||
string fname = Path.GetFileName(path!);
|
||||
string note = isDat ? "filtered" : "passthrough";
|
||||
RynthLog.Info($"Compat: DAT share - A [{note}]: {fname} access=0x{origAccess:X8}->0x{dwDesiredAccess:X8} share=0x{origShare:X}->0x{dwShareMode:X} result=0x{result.ToInt32():X8}{(err != 0 ? $" GetLastError={err}" : "")}");
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ namespace RynthCore.Engine.Compatibility;
|
|||
/// <item><c>/rc hooks [on|off <name>]</c> (alias <c>/rc uihooks</c>) — the UI hooks
|
||||
/// (screen mode, client cleanup, tooltip, drag/drop; <see cref="UiHookRegistry"/>):
|
||||
/// status, or switch one off/on (now and in engine.json).</item>
|
||||
/// <item><c>/rc video [status|off|world|unfocused|all|fps <n>]</c> (alias
|
||||
/// <c>/rc videopatch</c>; "on" = world) — the video patch
|
||||
/// <item><c>/rc video [status|enable|disable|off|world|unfocused|all|fps <n>]</c> (alias
|
||||
/// <c>/rc videopatch</c>; "on" / "enable" = world, "disable" = off; RynthAi forwards /ra and /ub videopatch) — the video patch
|
||||
/// (<see cref="D3D9.VideoPatch"/>): stop drawing AC's 3D world (world), only while
|
||||
/// the client is in the background (unfocused), or AC's UI too (all, session only).
|
||||
/// Saved per character (also Settings > Misc); fps = the frame cap while patched.</item>
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ internal static unsafe class VideoPatch
|
|||
replies.Add(SetMode(mode, save: true, "/rc video"));
|
||||
return replies;
|
||||
}
|
||||
replies.Add("Usage: /rc video [status|off|world|unfocused|all|fps <n>]");
|
||||
replies.Add("Usage: /rc video [status|enable|disable|off|world|unfocused|all|fps <n>] (enable = world, disable = off; also /ra videopatch and /ub videopatch)");
|
||||
return replies;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ internal static class VideoPatchPolicy
|
|||
mode = VideoPatchMode.Off;
|
||||
switch (text?.Trim().ToLowerInvariant())
|
||||
{
|
||||
case "off": case "0": case "false": case "none": mode = VideoPatchMode.Off; return true;
|
||||
case "on": case "1": case "true": case "world": case "3d": mode = VideoPatchMode.World; return true;
|
||||
case "off": case "0": case "false": case "none": case "disable": case "disabled": mode = VideoPatchMode.Off; return true;
|
||||
case "on": case "1": case "true": case "world": case "3d": case "enable": case "enabled": mode = VideoPatchMode.World; return true;
|
||||
case "unfocused": case "focus": case "background": case "bg": mode = VideoPatchMode.Unfocused; return true;
|
||||
case "all": case "full": case "everything": mode = VideoPatchMode.All; return true;
|
||||
default: return false;
|
||||
|
|
|
|||
|
|
@ -207,9 +207,6 @@ internal static class EngineLifecycle
|
|||
// Process-wide events: under CoreCLR they would hold this generation.
|
||||
Step("EntryPoint.UninstallManagedExceptionHandlers", EntryPoint.UninstallManagedExceptionHandlers);
|
||||
|
||||
// IAT slots aren't MinHook hooks: write them back before this generation unloads.
|
||||
Step("DatFileShareHooks.Uninstall", Compatibility.DatFileShareHooks.Uninstall);
|
||||
|
||||
Step("MH_DisableHook(ALL)", () =>
|
||||
{
|
||||
// DisableHook restores the original code at every hooked function — that's
|
||||
|
|
|
|||
|
|
@ -83,17 +83,18 @@ public static class EntryPoint
|
|||
/// </summary>
|
||||
/// <summary>
|
||||
/// The loader refused a hot-reload because this client is short of address
|
||||
/// space (each reload keeps the old engine and plugins mapped). Says so in
|
||||
/// chat. Loader thread.
|
||||
/// space: too little free in all, or (CoreCLR engine, 2026-10-15) no free block
|
||||
/// big enough. <paramref name="freeMb"/> is the figure that fell short (the loader
|
||||
/// log says which). Says so in chat. Loader thread.
|
||||
/// </summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthCoreReloadRefused")]
|
||||
public static uint ReloadRefused(int freeMb)
|
||||
{
|
||||
try
|
||||
{
|
||||
RynthLog.Warn($"Hot-reload refused by the loader: {freeMb} MB of address space free.");
|
||||
RynthLog.Warn($"Hot-reload refused by the loader: short of address space ({freeMb} MB free in all, or in the largest free block; see the loader line).");
|
||||
Compatibility.AcMainThreadQueue.EnqueueWriteToChat(
|
||||
$"[RynthCore] A new RynthCore build is ready but wasn't loaded: this client has only {freeMb} MB of memory address space left, and reloading could crash it. Restart the client to use the new build.", 2);
|
||||
$"[RynthCore] A new RynthCore build is ready but wasn't loaded: this client is low on memory address space ({freeMb} MB usable), and reloading could crash it. Restart the client to use the new build.", 2);
|
||||
}
|
||||
catch { }
|
||||
return 0;
|
||||
|
|
@ -102,7 +103,7 @@ public static class EntryPoint
|
|||
/// <summary>
|
||||
/// The reload cap (ReloadCapNotice): the loader asks this before every hot reload, and
|
||||
/// refuses the reload once this client has done that many. engine.json MaxHotReloads,
|
||||
/// default 3; negative = no cap. Loader thread.
|
||||
/// default 20; negative = no cap. Loader thread.
|
||||
/// </summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthCoreMaxHotReloads")]
|
||||
public static int MaxHotReloads()
|
||||
|
|
|
|||
|
|
@ -339,6 +339,9 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
/// <summary>The channels drawer on the chat window's left edge (DashboardDrawers' mechanics).</summary>
|
||||
private sealed class ChannelsDrawer : DashboardDrawer
|
||||
{
|
||||
// The chat window often sits against the screen's left edge: the channels then open on its right.
|
||||
public override bool FlipsWhenNoRoom => true;
|
||||
|
||||
private const float RowH = 20;
|
||||
private static bool s_open; // this session only
|
||||
private readonly ChatFace _face;
|
||||
|
|
|
|||
124
src/RynthCore.Engine/ImGui/Panels/CircleClip.cs
Normal file
124
src/RynthCore.Engine/ImGui/Panels/CircleClip.cs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - ImGui/Panels/CircleClip.cs
|
||||
// The round Radar's geometry, with no ImGui in it (tools\RadarSettingsTests links this file):
|
||||
// ImGui only clips to rectangles, so everything the radar draws that could cross the circle's
|
||||
// edge is cut to it by hand - line segments exactly, convex polygons (floor strips, map
|
||||
// tiles, with their texture coordinates carried along) against a 48-sided polygon inscribed
|
||||
// in the circle (Sutherland-Hodgman; the circle's edge is within 0.2% of true).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace RynthCore.Engine.ImGuiBackend.Panels;
|
||||
|
||||
/// <summary>A circle on the screen: where the round radar's picture shows.</summary>
|
||||
internal readonly struct RoundMask
|
||||
{
|
||||
public readonly Vector2 Centre;
|
||||
public readonly float Radius;
|
||||
|
||||
public RoundMask(Vector2 centre, float radius) { Centre = centre; Radius = radius; }
|
||||
|
||||
public bool Contains(Vector2 p) => (p - Centre).LengthSquared() <= Radius * Radius;
|
||||
|
||||
/// <summary>The whole box is inside the circle.</summary>
|
||||
public bool ContainsBox(Vector2 min, Vector2 max) =>
|
||||
Contains(min) && Contains(max) && Contains(new Vector2(min.X, max.Y)) && Contains(new Vector2(max.X, min.Y));
|
||||
|
||||
/// <summary>Part of the box may be inside the circle (false: none of it is).</summary>
|
||||
public bool OverlapsBox(Vector2 min, Vector2 max)
|
||||
{
|
||||
Vector2 nearest = Vector2.Clamp(Centre, min, max);
|
||||
return (nearest - Centre).LengthSquared() <= Radius * Radius;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class CircleClip
|
||||
{
|
||||
private const int Sides = 48;
|
||||
private static readonly Vector2[] Normals = BuildNormals();
|
||||
private static readonly float PlaneDist = MathF.Cos(MathF.PI / Sides); // x radius: an edge's distance from the centre
|
||||
|
||||
private static Vector2[] BuildNormals()
|
||||
{
|
||||
var n = new Vector2[Sides];
|
||||
for (int k = 0; k < Sides; k++)
|
||||
{
|
||||
float a = (k + 0.5f) * (2f * MathF.PI / Sides);
|
||||
n[k] = new Vector2(MathF.Cos(a), MathF.Sin(a));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// <summary>The most vertices a clipped polygon can have: its own plus one per edge of the 48-gon.</summary>
|
||||
public const int MaxPoints = 8 + Sides;
|
||||
|
||||
/// <summary>
|
||||
/// Cuts the segment a-b to the circle. False when no part of it is inside (a and b are then undefined).
|
||||
/// </summary>
|
||||
public static bool Segment(in RoundMask m, ref Vector2 a, ref Vector2 b)
|
||||
{
|
||||
Vector2 d = b - a, f = a - m.Centre;
|
||||
float A = Vector2.Dot(d, d);
|
||||
float C = Vector2.Dot(f, f) - m.Radius * m.Radius;
|
||||
if (A < 1e-9f) return C <= 0;
|
||||
float B = 2f * Vector2.Dot(f, d);
|
||||
float disc = B * B - 4f * A * C;
|
||||
if (disc <= 0) return false;
|
||||
float root = MathF.Sqrt(disc);
|
||||
float t0 = (-B - root) / (2f * A), t1 = (-B + root) / (2f * A);
|
||||
if (t1 < 0f || t0 > 1f) return false;
|
||||
t0 = MathF.Max(t0, 0f); t1 = MathF.Min(t1, 1f);
|
||||
Vector2 na = a + d * t0, nb = a + d * t1;
|
||||
a = na; b = nb;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cuts the convex polygon <paramref name="pts"/> (with a texture coordinate per point in
|
||||
/// <paramref name="uvs"/>, or empty for none) to the circle. Returns the number of points left
|
||||
/// in <paramref name="outPts"/> / <paramref name="outUvs"/> (each at least <see cref="MaxPoints"/> long;
|
||||
/// outUvs is untouched without uvs): 0 when nothing is inside.
|
||||
/// </summary>
|
||||
public static int Polygon(in RoundMask m, ReadOnlySpan<Vector2> pts, ReadOnlySpan<Vector2> uvs, Span<Vector2> outPts, Span<Vector2> outUvs)
|
||||
{
|
||||
bool hasUv = uvs.Length >= pts.Length;
|
||||
Span<Vector2> aP = stackalloc Vector2[MaxPoints], aU = stackalloc Vector2[MaxPoints];
|
||||
Span<Vector2> bP = stackalloc Vector2[MaxPoints], bU = stackalloc Vector2[MaxPoints];
|
||||
int n = pts.Length;
|
||||
if (n < 3 || n > 8) return 0;
|
||||
pts.CopyTo(aP);
|
||||
if (hasUv) uvs[..n].CopyTo(aU);
|
||||
|
||||
float dist = m.Radius * PlaneDist;
|
||||
Span<Vector2> curP = aP, curU = aU, nxtP = bP, nxtU = bU;
|
||||
for (int k = 0; k < Sides && n >= 3; k++)
|
||||
{
|
||||
Vector2 nk = Normals[k];
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Vector2 p = curP[i], q = curP[(i + 1) % n];
|
||||
float sp = Vector2.Dot(p - m.Centre, nk) - dist, sq = Vector2.Dot(q - m.Centre, nk) - dist;
|
||||
bool pin = sp <= 0, qin = sq <= 0;
|
||||
if (pin) { nxtP[cnt] = p; if (hasUv) nxtU[cnt] = curU[i]; cnt++; }
|
||||
if (pin != qin)
|
||||
{
|
||||
float t = sp / (sp - sq);
|
||||
nxtP[cnt] = p + (q - p) * t;
|
||||
if (hasUv) nxtU[cnt] = curU[i] + (curU[(i + 1) % n] - curU[i]) * t;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
n = cnt;
|
||||
Span<Vector2> tp = curP, tu = curU;
|
||||
curP = nxtP; curU = nxtU;
|
||||
nxtP = tp; nxtU = tu;
|
||||
}
|
||||
if (n < 3) return 0;
|
||||
curP[..n].CopyTo(outPts);
|
||||
if (hasUv) curU[..n].CopyTo(outUvs);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,9 @@
|
|||
// dashboard drawer can be moved to the other one from its tab's right-click
|
||||
// (saved with the dashboard's state). The tabs never switch sides on their
|
||||
// own any more; a panel with no room on its side stays on the screen over
|
||||
// the dashboard instead.
|
||||
// the dashboard instead. A drawer can opt in to flipping (FlipsWhenNoRoom,
|
||||
// 2026-10-15: RynthChat's Channels): with no room on its own side for its
|
||||
// panel and room on the other, it draws there until its side has room again.
|
||||
//
|
||||
// The look: a closed tab is a button with its drawer's icon that peeks out a
|
||||
// little on hover; the open tab joins its panel (same background, a teal
|
||||
|
|
@ -79,8 +81,16 @@ internal abstract class DashboardDrawer
|
|||
public virtual bool Moved => false;
|
||||
public virtual void SaveMoved(bool moved) { }
|
||||
|
||||
/// <summary>
|
||||
/// With no room on its side for the panel (the window against the screen's edge) and room
|
||||
/// on the other, the drawer draws on the other side until its own has room again. Not saved.
|
||||
/// </summary>
|
||||
public virtual bool FlipsWhenNoRoom => false;
|
||||
/// <summary>Set by the host while a <see cref="FlipsWhenNoRoom"/> drawer is on its other side.</summary>
|
||||
internal bool Flipped;
|
||||
|
||||
/// <summary>The side it is on now.</summary>
|
||||
public bool OnRight => StartsRight != Moved;
|
||||
public bool OnRight => (StartsRight != Moved) != Flipped;
|
||||
|
||||
private string? _tabId, _hideTip, _sideMenuId;
|
||||
/// <summary>The tab's ImGui id and open tooltip (built once).</summary>
|
||||
|
|
@ -267,10 +277,51 @@ internal sealed class DashboardDrawers
|
|||
|
||||
Vector2 dashPos = ImGuiNET.ImGui.GetWindowPos(), dashSize = ImGuiNET.ImGui.GetWindowSize();
|
||||
float k = MathF.Max(1f, ImGuiFonts.Get(UiFont.Dash11).FontSize / 11f);
|
||||
UpdateFlips(dashPos, dashSize, k);
|
||||
DrawSide(0, dashPos, dashSize, k);
|
||||
DrawSide(1, dashPos, dashSize, k);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts each <see cref="DashboardDrawer.FlipsWhenNoRoom"/> drawer on the side its whole panel
|
||||
/// fits: its own side when it fits there, else the other side when that fits, else its own.
|
||||
/// </summary>
|
||||
private void UpdateFlips(Vector2 dashPos, Vector2 dashSize, float k)
|
||||
{
|
||||
float displayW = ImGuiNET.ImGui.GetIO().DisplaySize.X;
|
||||
if (displayW <= 1) return;
|
||||
float tabW = 17 * k;
|
||||
foreach (DashboardDrawer d in _drawers)
|
||||
{
|
||||
if (!d.FlipsWhenNoRoom) continue;
|
||||
bool homeRight = d.StartsRight != d.Moved;
|
||||
float need = tabW + d.Width(k);
|
||||
bool fitsLeft = dashPos.X - need >= 0;
|
||||
bool fitsRight = dashPos.X + dashSize.X + need <= displayW;
|
||||
bool fitsHome = homeRight ? fitsRight : fitsLeft;
|
||||
bool fitsOther = homeRight ? fitsLeft : fitsRight;
|
||||
SetFlipped(d, !fitsHome && fitsOther);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Moves a drawer to its flipped side or back; an open drawer stays open (no slide).</summary>
|
||||
private void SetFlipped(DashboardDrawer d, bool flipped)
|
||||
{
|
||||
if (d.Flipped == flipped) return;
|
||||
int i = Array.IndexOf(_drawers, d);
|
||||
Side from = SideOf(d);
|
||||
bool wasOpen = from.Open == i;
|
||||
if (wasOpen) from.Open = -1;
|
||||
if (from.Shown == i) { from.Shown = -1; from.T = 0f; }
|
||||
d.Flipped = flipped;
|
||||
if (!wasOpen) return;
|
||||
Side to = SideOf(d);
|
||||
if (to.Open >= 0 && to.Open != i) _drawers[to.Open].SaveOpen(false); // one open per side
|
||||
to.Open = i;
|
||||
to.Shown = i;
|
||||
to.T = 1f;
|
||||
}
|
||||
|
||||
private void DrawSide(int sideIdx, Vector2 dashPos, Vector2 dashSize, float k)
|
||||
{
|
||||
bool right = sideIdx == 1;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
// - portals always shown with their destination; doors and creatures optional;
|
||||
// - hidden while you're outdoors or in portal space, back in the next dungeon
|
||||
// (the panel stays open; ImGuiPanelHost skips drawing it docked).
|
||||
// Every marker has a size, an optional name label and a name size of its own
|
||||
// (DungeonMapSettingsStore.Markers, edited in the toolbar's Markers window; the
|
||||
// radar keeps its own set).
|
||||
// Settings are the engine's (dungeon_map_settings.txt beside radar_settings.txt),
|
||||
// not RynthAi's per-character Map* fields. Zoom, pan and floor picks last for the
|
||||
// session, as they did.
|
||||
|
|
@ -32,7 +35,10 @@
|
|||
// on floors the map isn't showing are hidden, on shown other floors dimmed, like the
|
||||
// walls. Points outside this dungeon's floor area aren't drawn.
|
||||
//
|
||||
// "Edit route" (off by default; needs RynthAi with MapEdit >= 1):
|
||||
// "Edit route" (off by default; needs RynthAi with MapEdit >= 1): the map holds still while it
|
||||
// is on - fixed on the spot it was showing (not following you), north up, and on the floors it
|
||||
// was showing - so a point can be placed or dragged while you walk; turning it off puts Follow
|
||||
// back as it was.
|
||||
// - click (no drag) on a floor: add a point there (after the selected point, else
|
||||
// at the end; Z from that floor: the player's floor first, then the other shown
|
||||
// floors nearest it). Off every shown floor: refused with a status line;
|
||||
|
|
@ -55,6 +61,7 @@ using System.Numerics;
|
|||
using ImGuiNET;
|
||||
using RynthCore.Engine.UI;
|
||||
using RynthCore.Engine.UI.Data;
|
||||
using MarkerStyleSettings = RynthCore.Engine.UI.Panels.MarkerStyleSettings;
|
||||
|
||||
namespace RynthCore.Engine.ImGuiBackend.Panels;
|
||||
|
||||
|
|
@ -109,6 +116,10 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
private const long StatusMs = 4000;
|
||||
private bool _navSubscribed;
|
||||
private bool _editRoute;
|
||||
private bool _followBeforeEdit; // Follow as it was when editing began
|
||||
private bool _anchorSet; // the world spot the frozen map is centred on (Edit route)
|
||||
private Vector2 _anchorWorld;
|
||||
private bool _markersOpen; // the Markers (sizes and names) window
|
||||
private int _selected = -1; // route index the next added point goes after
|
||||
private int _hoverPt = -1;
|
||||
private readonly List<(int Idx, Vector2 At)> _drawn = new(); // this frame's drawn points, for picking
|
||||
|
|
@ -221,14 +232,18 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
ImDrawListFlags saved = dl.Flags;
|
||||
dl.Flags = saved & ~(ImDrawListFlags.AntiAliasedLines | ImDrawListFlags.AntiAliasedLinesUseTex | ImDrawListFlags.AntiAliasedFill);
|
||||
dl.PushClipRect(canvasMin, canvasMax, true);
|
||||
var p = new DungeonMapProjection(centre, live.Player.WorldX, live.Player.WorldY, live.Player.Heading,
|
||||
DungeonMapSettingsStore.RotateWithPlayer, _zoom);
|
||||
// Editing: centred on a fixed spot, north up, so the map doesn't move under the mouse.
|
||||
if (_editRoute && !_anchorSet) { _anchorWorld = new Vector2(live.Player.WorldX, live.Player.WorldY); _anchorSet = true; }
|
||||
bool frozen = _editRoute && _anchorSet;
|
||||
var p = new DungeonMapProjection(centre,
|
||||
frozen ? _anchorWorld.X : live.Player.WorldX, frozen ? _anchorWorld.Y : live.Player.WorldY, live.Player.Heading,
|
||||
DungeonMapSettingsStore.RotateWithPlayer && !frozen, _zoom);
|
||||
proj = p;
|
||||
DrawFloors(dl, view, p, canvasMin, canvasMax);
|
||||
dl.Flags = saved;
|
||||
if (nav != null) routeDrawn = DrawRoute(dl, view, nav, p, canvasMin, canvasMax);
|
||||
DrawMarkers(dl, live, p, canvasMin, canvasMax);
|
||||
DrawPlayer(dl, centre, p);
|
||||
DrawPlayer(dl, frozen ? p.P(live.Player.WorldX, live.Player.WorldY) : centre, p, DungeonMapSettingsStore.Markers.SelfSize);
|
||||
DrawRouteStatus(dl, canvasMin, canvasMax, nav, routeDrawn);
|
||||
dl.PopClipRect();
|
||||
}
|
||||
|
|
@ -246,6 +261,7 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
|
||||
CanvasInput(canvasMin, canvasMax, view, nav, proj);
|
||||
DrawPointMenu(nav);
|
||||
MarkersWindow();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -264,7 +280,9 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
_pan = Vector2.Zero;
|
||||
_autoLayer = -1;
|
||||
_visible.Clear();
|
||||
if (_editRoute) { StopEditing(); SetStatus("Edit route turned off: you went to another dungeon."); }
|
||||
}
|
||||
if (_editRoute) return; // the floors shown stay as they were
|
||||
int best = view.CurrentLayer;
|
||||
if (best < 0 || best == _autoLayer) return;
|
||||
_autoLayer = best;
|
||||
|
|
@ -364,45 +382,64 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
const float Margin = 20f;
|
||||
bool doors = DungeonMapSettingsStore.ShowDoors, creatures = DungeonMapSettingsStore.ShowCreatures,
|
||||
corpses = DungeonMapSettingsStore.ShowCorpses;
|
||||
MarkerStyleSettings markers = DungeonMapSettingsStore.Markers;
|
||||
RadarMarkerStyle.FillColors(KindCols);
|
||||
bool anyName = false;
|
||||
foreach (RadarMarker m in live.Markers)
|
||||
{
|
||||
if (!ShowOnMap(m.Kind, doors, creatures, corpses)) continue;
|
||||
anyName |= markers.NameShown(m.Kind);
|
||||
Vector2 p = proj.P(m.X, m.Y);
|
||||
if (p.X < clipMin.X - Margin || p.X > clipMax.X + Margin || p.Y < clipMin.Y - Margin || p.Y > clipMax.Y + Margin) continue;
|
||||
float s = markers.SizeOf(m.Kind);
|
||||
switch (m.Kind)
|
||||
{
|
||||
case 0:
|
||||
dl.AddCircleFilled(p, 4f, Monster, 10);
|
||||
dl.AddCircle(p, 6f, MonsterRing, 10, 1f);
|
||||
Label(dl, p + new Vector2(7, -7), CreatureLabel, m.Label, 20);
|
||||
dl.AddCircleFilled(p, 4f * s, Monster, 10);
|
||||
dl.AddCircle(p, 6f * s, MonsterRing, 10, 1f);
|
||||
break;
|
||||
case 1:
|
||||
dl.AddCircleFilled(p, 4f, Npc, 10);
|
||||
dl.AddCircle(p, 6f, NpcRing, 10, 1.2f);
|
||||
Label(dl, p + new Vector2(7, -7), CreatureLabel, m.Label, 20);
|
||||
dl.AddCircleFilled(p, 4f * s, Npc, 10);
|
||||
dl.AddCircle(p, 6f * s, NpcRing, 10, 1.2f);
|
||||
break;
|
||||
case 2:
|
||||
dl.AddCircleFilled(p, 5f, Portal, 12);
|
||||
dl.AddCircle(p, 7f, PortalRing, 12, 1.5f);
|
||||
Label(dl, p + new Vector2(9, -7), PortalLabel, m.Label, 22);
|
||||
dl.AddCircleFilled(p, 5f * s, Portal, 12);
|
||||
dl.AddCircle(p, 7f * s, PortalRing, 12, 1.5f);
|
||||
break;
|
||||
case 3:
|
||||
const float r = 5f, o = r + 1.5f;
|
||||
float r = 5f * s, o = r + 1.5f;
|
||||
dl.AddQuadFilled(p + new Vector2(0, -r), p + new Vector2(r, 0), p + new Vector2(0, r), p + new Vector2(-r, 0), Door);
|
||||
dl.AddQuad(p + new Vector2(0, -o), p + new Vector2(o, 0), p + new Vector2(0, o), p + new Vector2(-o, 0), DoorRing, 1.2f);
|
||||
Label(dl, p + new Vector2(8, -7), DoorLabel, m.Label, 20);
|
||||
break;
|
||||
default:
|
||||
// The kinds added 2026-10-04: the radar's shape and (user-pickable) colour, a size up.
|
||||
RadarMarkerStyle.Draw(dl, m.Kind, p, KindCols[m.Kind], 1.35f);
|
||||
if (m.Kind is not RadarKind.GroundItem)
|
||||
Label(dl, p + new Vector2(8, -7), CreatureLabel, m.Label, 20);
|
||||
RadarMarkerStyle.Draw(dl, m.Kind, p, KindCols[m.Kind], 1.35f * s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Names last, over every marker.
|
||||
if (!anyName) return;
|
||||
ImFontPtr nameFont = ImGuiFonts.Get(UiFont.Ui11);
|
||||
foreach (RadarMarker m in live.Markers)
|
||||
{
|
||||
if (!markers.NameShown(m.Kind) || !ShowOnMap(m.Kind, doors, creatures, corpses)) continue;
|
||||
Vector2 p = proj.P(m.X, m.Y);
|
||||
if (p.X < clipMin.X - Margin || p.X > clipMax.X + Margin || p.Y < clipMin.Y - Margin || p.Y > clipMax.Y + Margin) continue;
|
||||
// Half the marker's width as drawn above (kinds 0-3: their outer ring).
|
||||
float reach = m.Kind switch { 0 or 1 => 6f, 2 => 7f, 3 => 6.5f, _ => RadarMarkerStyle.Radius(m.Kind) * 1.35f };
|
||||
RadarMarkerStyle.DrawName(dl, nameFont, p, reach * markers.SizeOf(m.Kind), NameColor(m.Kind), m.Label, markers.NameSizeOf(m.Kind));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The map's label colours: warm white for creatures, tinted for portals and doors.</summary>
|
||||
private static uint NameColor(byte kind) => kind switch
|
||||
{
|
||||
RadarKind.Portal => PortalLabel,
|
||||
RadarKind.Door => DoorLabel,
|
||||
_ => CreatureLabel,
|
||||
};
|
||||
|
||||
private static readonly uint[] KindCols = new uint[RadarKind.Count];
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -423,18 +460,11 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
_ => UI.Panels.RadarSettingsStore.ShowKind(kind),
|
||||
};
|
||||
|
||||
private static void Label(ImDrawListPtr dl, Vector2 pos, uint col, string? text, int max)
|
||||
private static void DrawPlayer(ImDrawListPtr dl, Vector2 at, in DungeonMapProjection proj, float s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return;
|
||||
if (text.Length > max) text = text[..max] + "…";
|
||||
dl.AddText(pos, col, text);
|
||||
}
|
||||
|
||||
private static void DrawPlayer(ImDrawListPtr dl, Vector2 at, in DungeonMapProjection proj)
|
||||
{
|
||||
dl.AddCircleFilled(at, 4f, PlayerCol, 10);
|
||||
dl.AddCircleFilled(at, 4f * s, PlayerCol, 10);
|
||||
// Rotating: facing is always up. North-up: AC heading 0 = east, 90 = north.
|
||||
Vector2 tip = proj.Rotated ? at + new Vector2(0, -10) : at + new Vector2(proj.Cos * 10, -proj.Sin * 10);
|
||||
Vector2 tip = proj.Rotated ? at + new Vector2(0, -10 * s) : at + new Vector2(proj.Cos * 10 * s, -proj.Sin * 10 * s);
|
||||
dl.AddLine(at, tip, PlayerCol, 1.5f);
|
||||
}
|
||||
|
||||
|
|
@ -672,12 +702,16 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
SetStatus("Editing the route on the map needs a newer RynthAi.");
|
||||
return false;
|
||||
}
|
||||
_followBeforeEdit = _follow;
|
||||
_follow = false;
|
||||
_anchorSet = false;
|
||||
_editRoute = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void StopEditing()
|
||||
{
|
||||
if (_editRoute) { _follow = _followBeforeEdit; _anchorSet = false; }
|
||||
_editRoute = false;
|
||||
_selected = -1;
|
||||
CancelPress();
|
||||
|
|
@ -907,6 +941,64 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
}
|
||||
}
|
||||
|
||||
// ── Markers window ────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Per-kind name box, marker size and name size (DungeonMapSettingsStore.Markers), your own marker's
|
||||
/// size, and a reset. Show boxes and colours are the toolbar's and the Radar's.
|
||||
/// </summary>
|
||||
private void MarkersWindow()
|
||||
{
|
||||
if (!_markersOpen) return;
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.WindowBg, RynthTheme.BoxBg);
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Border, ButtonBorder);
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 4f);
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(10, 10));
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(6, 4));
|
||||
const ImGuiWindowFlags flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize
|
||||
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoCollapse;
|
||||
bool visible = ImGuiNET.ImGui.Begin("##dmap_markers_window", ref _markersOpen, flags);
|
||||
ImGuiNET.ImGui.PopStyleVar(3);
|
||||
ImGuiNET.ImGui.PopStyleColor(2);
|
||||
if (visible)
|
||||
{
|
||||
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.UiBold11));
|
||||
ImGuiNET.ImGui.TextUnformatted("Map markers");
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
ImGuiNET.ImGui.SameLine(258 * MathF.Max(1f, EngineFrameController.FontScale) + MarkerStyleEditor.SizeSliderWidth - 14);
|
||||
if (FaceKit.IconButton("##dmap_markers_close", PhosphorIcons.X, ImGuiNET.ImGui.GetCursorScreenPos(), new Vector2(14, 14),
|
||||
FaceKit.Faded(FaceKit.Mute), RynthTheme.WithAlpha(RynthTheme.Background, 0xDC), font: UiFont.Ui9))
|
||||
_markersOpen = false;
|
||||
ImGuiNET.ImGui.SetItemTooltip("Close");
|
||||
ImGuiNET.ImGui.TextDisabled("Which kinds show, and their colours: the toolbar and the Radar's settings.");
|
||||
ImGuiNET.ImGui.Separator();
|
||||
|
||||
float scale = MathF.Max(1f, EngineFrameController.FontScale);
|
||||
float xName = 140 * scale, xSize = 176 * scale, xText = 258 * scale;
|
||||
MarkerStyleSettings markers = DungeonMapSettingsStore.Markers;
|
||||
bool changed = false;
|
||||
MarkerStyleEditor.HeaderRow(xName, xSize, xText);
|
||||
foreach (var (kind, label) in RadarFace.KindRowsOrder)
|
||||
{
|
||||
ImGuiNET.ImGui.PushID(kind);
|
||||
ImGuiNET.ImGui.AlignTextToFramePadding();
|
||||
ImGuiNET.ImGui.TextUnformatted(label);
|
||||
changed |= MarkerStyleEditor.KindCells(markers, kind, xName, xSize, xText);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
}
|
||||
ImGuiNET.ImGui.Separator();
|
||||
changed |= MarkerStyleEditor.SliderRow("You (dot and arrow)", ref markers.SelfSize,
|
||||
MarkerStyleSettings.MinSize, MarkerStyleSettings.MaxSize, "%.1fx", xSize);
|
||||
if (ImGuiNET.ImGui.SmallButton("Reset sizes and names"))
|
||||
{
|
||||
markers.Reset();
|
||||
changed = true;
|
||||
}
|
||||
if (changed) DungeonMapSettingsStore.Save();
|
||||
}
|
||||
ImGuiNET.ImGui.End();
|
||||
}
|
||||
|
||||
// ── Toolbar ───────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Draws the settings rows (they wrap to the width). Returns their height.</summary>
|
||||
|
|
@ -980,17 +1072,24 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
|
||||
// Follow / Rotate / Reset.
|
||||
SameLineIfFits(190, limit, 12);
|
||||
ImGuiNET.ImGui.BeginDisabled(_editRoute);
|
||||
ImGuiNET.ImGui.Checkbox("Follow##dmap_follow", ref _follow);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Keep the map centred on you (dragging the map turns this off)");
|
||||
ImGuiNET.ImGui.EndDisabled();
|
||||
SafeImGui.SetItemTooltip(_editRoute ? "The map holds still while Edit route is on"
|
||||
: "Keep the map centred on you (dragging the map turns this off)");
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
ImGuiNET.ImGui.BeginDisabled(_editRoute);
|
||||
changed |= ImGuiNET.ImGui.Checkbox("Rotate##dmap_rotate", ref DungeonMapSettingsStore.RotateWithPlayer);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Turn the map so the way you face is up");
|
||||
ImGuiNET.ImGui.EndDisabled();
|
||||
SafeImGui.SetItemTooltip(_editRoute ? "The map stays north-up while Edit route is on"
|
||||
: "Turn the map so the way you face is up");
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
if (ImGuiNET.ImGui.SmallButton("Reset##dmap_reset"))
|
||||
{
|
||||
_pan = Vector2.Zero;
|
||||
_zoom = DefaultZoom;
|
||||
_follow = true;
|
||||
_follow = !_editRoute; // editing: the map stays put, re-centred on you where you are now
|
||||
_anchorSet = false;
|
||||
_oneUpOneDown = true;
|
||||
SetOneUpOneDown(layers);
|
||||
}
|
||||
|
|
@ -1004,6 +1103,14 @@ internal sealed class DungeonMapFace : IImGuiPanel
|
|||
ImGuiNET.ImGui.SameLine();
|
||||
changed |= ImGuiNET.ImGui.Checkbox("Corpses##dmap_corpses", ref DungeonMapSettingsStore.ShowCorpses);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Corpses on the map. Off hides them here whatever the Radar shows; on, they also follow the Radar's corpse boxes.");
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
if (ImGuiNET.ImGui.SmallButton("Markers...##dmap_markers"))
|
||||
{
|
||||
_markersOpen = !_markersOpen;
|
||||
if (_markersOpen)
|
||||
ImGuiNET.ImGui.SetNextWindowPos(ImGuiNET.ImGui.GetItemRectMin() + new Vector2(0, ImGuiNET.ImGui.GetItemRectSize().Y + 4), ImGuiCond.Always);
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip("Marker sizes, and which names to draw beside the markers and how big.");
|
||||
|
||||
// Route / Edit route.
|
||||
SameLineIfFits(160, limit, 12);
|
||||
|
|
@ -1117,6 +1224,16 @@ internal static class DungeonMapSettingsStore
|
|||
public static float BgOpacity = 1.0f;
|
||||
public static bool RotateWithPlayer;
|
||||
|
||||
/// <summary>
|
||||
/// Per-kind marker size and name label (added 2026-10-15). The map has always named everything
|
||||
/// but items on the ground, so names start on for every other kind.
|
||||
/// </summary>
|
||||
public static readonly MarkerStyleSettings Markers = new(new[]
|
||||
{
|
||||
true, true, true, true, true, true, true, true, true, true, true,
|
||||
false, // item on the ground
|
||||
});
|
||||
|
||||
private static string FilePath
|
||||
{
|
||||
get
|
||||
|
|
@ -1156,6 +1273,7 @@ internal static class DungeonMapSettingsStore
|
|||
if (float.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out float o))
|
||||
BgOpacity = Math.Clamp(o, 0f, 1f);
|
||||
break;
|
||||
default: Markers.TryLoad(key, val); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1175,6 +1293,9 @@ internal static class DungeonMapSettingsStore
|
|||
+ $"showToolbar={(ShowToolbar ? "1" : "0")}\n"
|
||||
+ $"rotate={(RotateWithPlayer ? "1" : "0")}\n"
|
||||
+ FormattableString.Invariant($"opacity={BgOpacity:0.##}\n");
|
||||
var styleLines = new List<string>();
|
||||
Markers.AppendLines(styleLines);
|
||||
foreach (string line in styleLines) text += line + "\n";
|
||||
UiBackgroundWriter.Enqueue("dungeon map settings", () =>
|
||||
{
|
||||
lock (_sync)
|
||||
|
|
|
|||
74
src/RynthCore.Engine/ImGui/Panels/MarkerStyleEditor.cs
Normal file
74
src/RynthCore.Engine/ImGui/Panels/MarkerStyleEditor.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - ImGui/Panels/MarkerStyleEditor.cs
|
||||
// The per-kind "Name / Size / Text" controls of MarkerStyleSettings, shared by the
|
||||
// Radar's settings window (one row per kind, after its show box and colour) and
|
||||
// the Dungeon Map's Markers window. Sliders report a change once the drag ends
|
||||
// (so the settings file is written once, not per step); the name box at once.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Engine.UI.Panels;
|
||||
|
||||
namespace RynthCore.Engine.ImGuiBackend.Panels;
|
||||
|
||||
internal static class MarkerStyleEditor
|
||||
{
|
||||
public const float SizeSliderWidth = 74f;
|
||||
|
||||
/// <summary>"Name Size Text" column titles, at the given offsets from the window's left edge.</summary>
|
||||
public static void HeaderRow(float xName, float xSize, float xText)
|
||||
{
|
||||
ImGuiNET.ImGui.SetCursorPosX(xName);
|
||||
ImGuiNET.ImGui.TextDisabled("Name");
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("Draw the object's name beside its marker.");
|
||||
ImGuiNET.ImGui.SameLine(xSize);
|
||||
ImGuiNET.ImGui.TextDisabled("Size");
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("How big the marker is drawn. Ctrl+click a slider to type a value.");
|
||||
ImGuiNET.ImGui.SameLine(xText);
|
||||
ImGuiNET.ImGui.TextDisabled("Text");
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("How big its name is drawn, in pixels.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One kind's name box, marker size and name size on the current row (the caller has pushed an id
|
||||
/// for the kind). True when something was changed and should be saved.
|
||||
/// </summary>
|
||||
public static bool KindCells(MarkerStyleSettings st, byte kind, float xName, float xSize, float xText)
|
||||
{
|
||||
bool changed = false;
|
||||
ImGuiNET.ImGui.SameLine(xName);
|
||||
changed |= ImGuiNET.ImGui.Checkbox("##name", ref st.ShowName[kind]);
|
||||
ImGuiNET.ImGui.SameLine(xSize);
|
||||
changed |= Slider("##size", ref st.Size[kind], MarkerStyleSettings.MinSize, MarkerStyleSettings.MaxSize, "%.1fx", SizeSliderWidth);
|
||||
ImGuiNET.ImGui.SameLine(xText);
|
||||
// Never greyed out: set the name's size first, switch the name on after (or the other way round).
|
||||
changed |= Slider("##text", ref st.NameSize[kind], MarkerStyleSettings.MinName, MarkerStyleSettings.MaxName, "%.0f px", SizeSliderWidth);
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <summary>A labelled slider on its own row: the label, then the slider at <paramref name="x"/>.</summary>
|
||||
public static bool SliderRow(string label, ref float value, float min, float max, string fmt, float x)
|
||||
{
|
||||
ImGuiNET.ImGui.AlignTextToFramePadding();
|
||||
ImGuiNET.ImGui.TextUnformatted(label);
|
||||
ImGuiNET.ImGui.SameLine(x);
|
||||
ImGuiNET.ImGui.PushID(label);
|
||||
bool changed = Slider("##v", ref value, min, max, fmt, SizeSliderWidth);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static bool Slider(string id, ref float value, float min, float max, string fmt, float width)
|
||||
{
|
||||
ImGuiNET.ImGui.SetNextItemWidth(width);
|
||||
bool moved = ImGuiNET.ImGui.SliderFloat(id, ref value, min, max, fmt, ImGuiSliderFlags.AlwaysClamp);
|
||||
if (!float.IsFinite(value)) value = min;
|
||||
// Save once the drag ends, not on every step (a typed value commits when it is accepted).
|
||||
return moved && !ImGuiNET.ImGui.IsItemActive() || ImGuiNET.ImGui.IsItemDeactivatedAfterEdit();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,8 +8,12 @@
|
|||
// pop-out and settings (gear) buttons, wheel zoom, left-drag moves, left-click on a dot
|
||||
// selects it in game by object id (hover: name, distance, health), right-click menu, settings
|
||||
// popup. Settings are shared with the Avalonia face (RadarSettingsStore).
|
||||
// Marker kinds (RadarKind) each have a shape (RadarMarkerStyle), a show box
|
||||
// and a colour the user can pick; the settings popup doubles as the legend.
|
||||
// Marker kinds (RadarKind) each have a shape (RadarMarkerStyle), a show box,
|
||||
// a colour the user can pick, a size and an optional name label with its own
|
||||
// text size (RadarSettingsStore.Markers); the settings popup doubles as the
|
||||
// legend. Your own arrow, the compass letters and the coordinates have sizes too.
|
||||
// Outdoors the World Map's picture can be drawn behind it (RadarSettingsStore.ShowWorldMap; the
|
||||
// tiles come from WorldMapTiles through WorldMapTileDrawer, the same code as the World Map).
|
||||
//
|
||||
// Data: UiSources.Radar (RadarView, lookups precomputed). World geometry is
|
||||
// drawn without anti-aliasing (crisp tiling like the Avalonia face's aliased
|
||||
|
|
@ -61,12 +65,25 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
{ ("N", 0, 1), ("E", 1, 0), ("S", 0, -1), ("W", -1, 0) };
|
||||
|
||||
private bool _settingsOpen;
|
||||
private bool _settingsSub; // subscribed to RynthAi's settings (the retail radar switch) while the window is open
|
||||
private bool? _hidePending; // the retail-radar switch as just set, until RynthAi's answer shows it
|
||||
private long _hidePendingAt;
|
||||
|
||||
// The round radar (RadarSettingsStore.RoundRadar): this frame's circle, read by the drawing helpers.
|
||||
private static bool _round;
|
||||
private static RoundMask _mask;
|
||||
|
||||
/// <summary>Markers move: popped out, redraw smoothly even when idle.</summary>
|
||||
public int PopOutIdleHz => 20;
|
||||
|
||||
// Docked click-through: the panel takes no input (the game gets the clicks) unless Ctrl is held or
|
||||
// the mouse is over a dot or one of the buttons (_hot, worked out by the last frame's Draw), so a
|
||||
// dot can always be hovered and clicked. A press that began on a dot keeps the panel interactive
|
||||
// until the button is released.
|
||||
private bool _hot, _pressHot, _downPrev;
|
||||
|
||||
public bool ClickThrough =>
|
||||
RadarSettingsStore.CtrlGatedClickThrough && !ImGuiNET.ImGui.GetIO().KeyCtrl;
|
||||
RadarSettingsStore.CtrlGatedClickThrough && !ImGuiNET.ImGui.GetIO().KeyCtrl && !_hot;
|
||||
|
||||
public void OnShown()
|
||||
{
|
||||
|
|
@ -75,7 +92,11 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
UiSources.Radar.RequestRefresh();
|
||||
}
|
||||
|
||||
public void OnHidden() => UiSources.Radar.Unsubscribe();
|
||||
public void OnHidden()
|
||||
{
|
||||
UiSources.Radar.Unsubscribe();
|
||||
if (_settingsSub) { UiSources.Settings.Unsubscribe(); _settingsSub = false; }
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
|
|
@ -87,27 +108,57 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
|
||||
bool rim = RadarSettingsStore.ShowGoldRim;
|
||||
float canvasInset = rim ? 5 : 0;
|
||||
const float coordStrip = 14;
|
||||
float opacity = Math.Clamp(RadarSettingsStore.Opacity, 0f, 1f);
|
||||
Vector2 frameMax = origin + size;
|
||||
// The coordinates sit in a strip of their own under the radar, clear of its frame: the text's height
|
||||
// (its size at the UI scale) and a gap above it. The radar - frame, canvas, dial - is everything above.
|
||||
float coordH = ImGuiFonts.Get(UiFont.UiBold11).FontSize * RadarSettingsStore.CoordSize / 11f;
|
||||
float coordStrip = coordH + 5f;
|
||||
Vector2 panelMax = origin + size;
|
||||
Vector2 frameMax = new Vector2(panelMax.X, MathF.Max(origin.Y + 16f, panelMax.Y - coordStrip));
|
||||
|
||||
// ── Frame: outer black (fades) + gold inner border + accent ──
|
||||
if (rim)
|
||||
{
|
||||
dl.AddRectFilled(origin, frameMax, MulAlpha(FrameOuterArgb, opacity));
|
||||
dl.AddRect(origin + new Vector2(1, 1), frameMax - new Vector2(1, 1), FrameInner, 0, ImDrawFlags.None, 2);
|
||||
dl.AddRect(origin + new Vector2(3, 3), frameMax - new Vector2(3, 3), FrameAccent, 0, ImDrawFlags.None, 1);
|
||||
}
|
||||
|
||||
// ── Canvas and world playfield (canvas minus the coord strip) ──
|
||||
// ── Canvas and world playfield ──
|
||||
Vector2 canvasMin = origin + new Vector2(canvasInset, canvasInset);
|
||||
Vector2 canvasMax = frameMax - new Vector2(canvasInset, canvasInset);
|
||||
dl.AddRectFilled(canvasMin, canvasMax, MulAlpha(CanvasBgArgb, opacity));
|
||||
var worldMin = canvasMin;
|
||||
var worldMax = new Vector2(canvasMax.X, canvasMax.Y - coordStrip);
|
||||
var worldMax = canvasMax;
|
||||
Vector2 centre = (worldMin + worldMax) * 0.5f;
|
||||
dl.AddLine(new Vector2(centre.X, worldMin.Y), new Vector2(centre.X, worldMax.Y), Crosshair);
|
||||
dl.AddLine(new Vector2(worldMin.X, centre.Y), new Vector2(worldMax.X, centre.Y), Crosshair);
|
||||
// Round: the circle (frame included) is as wide as the radar is tall or wide, whichever is less.
|
||||
_round = RadarSettingsStore.RoundRadar;
|
||||
float frameR = MathF.Max(10f, MathF.Min(frameMax.X - origin.X, frameMax.Y - origin.Y) * 0.5f);
|
||||
float dial = MathF.Max(8f, frameR - canvasInset);
|
||||
if (_round)
|
||||
{
|
||||
centre = (origin + frameMax) * 0.5f;
|
||||
worldMin = centre - new Vector2(dial, dial);
|
||||
worldMax = centre + new Vector2(dial, dial);
|
||||
}
|
||||
_mask = new RoundMask(centre, dial);
|
||||
|
||||
if (_round)
|
||||
{
|
||||
if (rim)
|
||||
{
|
||||
dl.AddCircleFilled(centre, frameR, MulAlpha(FrameOuterArgb, opacity), 72);
|
||||
dl.AddCircle(centre, frameR - 1, FrameInner, 72, 2);
|
||||
dl.AddCircle(centre, frameR - 3, FrameAccent, 72, 1);
|
||||
}
|
||||
dl.AddCircleFilled(centre, dial, MulAlpha(CanvasBgArgb, opacity), 72);
|
||||
dl.AddLine(new Vector2(centre.X, centre.Y - dial), new Vector2(centre.X, centre.Y + dial), Crosshair);
|
||||
dl.AddLine(new Vector2(centre.X - dial, centre.Y), new Vector2(centre.X + dial, centre.Y), Crosshair);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ── Frame: outer black (fades) + gold inner border + accent ──
|
||||
if (rim)
|
||||
{
|
||||
dl.AddRectFilled(origin, frameMax, MulAlpha(FrameOuterArgb, opacity));
|
||||
dl.AddRect(origin + new Vector2(1, 1), frameMax - new Vector2(1, 1), FrameInner, 0, ImDrawFlags.None, 2);
|
||||
dl.AddRect(origin + new Vector2(3, 3), frameMax - new Vector2(3, 3), FrameAccent, 0, ImDrawFlags.None, 1);
|
||||
}
|
||||
dl.AddRectFilled(canvasMin, canvasMax, MulAlpha(CanvasBgArgb, opacity));
|
||||
dl.AddLine(new Vector2(centre.X, worldMin.Y), new Vector2(centre.X, worldMax.Y), Crosshair);
|
||||
dl.AddLine(new Vector2(worldMin.X, centre.Y), new Vector2(worldMax.X, centre.Y), Crosshair);
|
||||
}
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
|
|
@ -119,36 +170,36 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
dl.Flags = saved;
|
||||
|
||||
DrawOutlinedText(dl, ImGuiFonts.Get(UiFont.UiBold11), view.CoordText,
|
||||
new Vector2((canvasMin.X + canvasMax.X) * 0.5f, canvasMax.Y), CoordText, alignBottom: true);
|
||||
new Vector2((origin.X + panelMax.X) * 0.5f, panelMax.Y), CoordText, alignBottom: true,
|
||||
scale: RadarSettingsStore.CoordSize / 11f);
|
||||
DrawCardinals(dl, view, centre, (worldMax.X - worldMin.X) * 0.5f, (worldMax.Y - worldMin.Y) * 0.5f);
|
||||
}
|
||||
|
||||
// ── Buttons (submitted before the surface so they win the hover) ──
|
||||
const float btn = 22, gap = 4, inset = 6;
|
||||
var gearPos = new Vector2(frameMax.X - inset - btn, origin.Y + inset);
|
||||
var popPos = gearPos - new Vector2(btn + gap, 0);
|
||||
// Small and flat, like the Arrow's corner buttons: settings, pop out, close.
|
||||
const float btn = 14, gap = 2, inset = 3;
|
||||
uint btnFg = FaceKit.Faded(FaceKit.Mute), btnBg = RynthTheme.WithAlpha(RynthTheme.Background, 0xDC);
|
||||
var closePos = new Vector2(frameMax.X - inset - btn, origin.Y + inset);
|
||||
var popPos = closePos - new Vector2(btn + gap, 0);
|
||||
var gearPos = (PanelRouter.CanPopOut ? popPos : closePos) - new Vector2(btn + gap, 0);
|
||||
if (FaceKit.IconButton("##radar_close", PhosphorIcons.X, closePos, new Vector2(btn, btn), btnFg, btnBg, font: UiFont.Ui9))
|
||||
ImGuiPanelHost.Close(Title);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Close the radar");
|
||||
if (PanelRouter.CanPopOut)
|
||||
{
|
||||
if (IconButton("##radar_pop", popPos, ImGuiPanelHost.PopOutGlyph))
|
||||
if (FaceKit.IconButton("##radar_pop", ImGuiPanelHost.PopOutGlyph, popPos, new Vector2(btn, btn), btnFg, btnBg, font: UiFont.Ui9))
|
||||
ImGuiPanelHost.TogglePopOut(Title);
|
||||
SafeImGui.SetItemTooltip(ImGuiPanelHost.PopOutTooltip);
|
||||
}
|
||||
bool gear = IconButton("##radar_gear", gearPos, PhosphorIcons.Gear);
|
||||
bool gear = FaceKit.IconButton("##radar_gear", PhosphorIcons.Gear, gearPos, new Vector2(btn, btn), btnFg, btnBg, font: UiFont.Ui9);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Radar settings");
|
||||
if (gear)
|
||||
{
|
||||
if (_settingsOpen) _settingsOpen = false;
|
||||
else
|
||||
{
|
||||
_settingsOpen = true;
|
||||
ImGuiNET.ImGui.SetNextWindowPos(new Vector2(gearPos.X + btn, gearPos.Y + btn + 4), ImGuiCond.Always, new Vector2(1, 0));
|
||||
}
|
||||
}
|
||||
if (gear) ToggleSettings(new Vector2(closePos.X + btn, closePos.Y + btn + 4));
|
||||
|
||||
// ── Surface: drag moves the panel, a click on a dot selects, wheel zooms, right-click menu ──
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(origin);
|
||||
bool surfaceClicked = ImGuiNET.ImGui.InvisibleButton("##radar_surface", size);
|
||||
ImGuiPanelHost.DragWindowWithLastItem();
|
||||
UpdateHot(view, centre, worldMin, worldMax, gearPos, new Vector2(closePos.X + btn, closePos.Y + btn));
|
||||
if (view != null && RadarSettingsStore.ClickToSelect)
|
||||
MarkerInput(dl, view, centre, worldMin, worldMax, surfaceClicked);
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
|
|
@ -164,6 +215,7 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
{
|
||||
if (PanelRouter.CanPopOut && ImGuiNET.ImGui.MenuItem(ImGuiPopOuts.InPopOutFrame ? "Dock back" : "Pop out"))
|
||||
ImGuiPanelHost.TogglePopOut(Title);
|
||||
if (ImGuiNET.ImGui.MenuItem("Radar settings...")) ToggleSettings(ImGuiNET.ImGui.GetMousePos());
|
||||
ImGuiNET.ImGui.Separator();
|
||||
if (ImGuiNET.ImGui.MenuItem("Rotate with player", "", RadarSettingsStore.RotateWithPlayer))
|
||||
{
|
||||
|
|
@ -180,6 +232,14 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
SettingsWindow();
|
||||
}
|
||||
|
||||
/// <summary>Opens the settings window with its top-right corner at <paramref name="corner"/>, or closes it.</summary>
|
||||
private void ToggleSettings(Vector2 corner)
|
||||
{
|
||||
if (_settingsOpen) { _settingsOpen = false; return; }
|
||||
_settingsOpen = true;
|
||||
ImGuiNET.ImGui.SetNextWindowPos(corner, ImGuiCond.Always, new Vector2(1, 0));
|
||||
}
|
||||
|
||||
// ── World ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>World (AC x east, y north) → screen, north-up or rotated so facing is up.</summary>
|
||||
|
|
@ -218,6 +278,9 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
bool rotate = RadarSettingsStore.RotateWithPlayer;
|
||||
var proj = new Projection(centre, live.Player, rotate, MathF.Max(0.5f, RadarSettingsStore.Zoom));
|
||||
|
||||
if (RadarSettingsStore.ShowWorldMap && !live.IsIndoor)
|
||||
DrawWorldMapBackdrop(dl, live, centre, clipMin, clipMax, rotate);
|
||||
|
||||
int cur = view.CurrentLayer, count = live.LayerZs.Count;
|
||||
// Same order as the Avalonia/ImGui-era radar: below, above (dimmed), current.
|
||||
if (cur - 1 >= 0) DrawLayer(dl, view, cur - 1, 0.30f, false, proj, rotate, clipMin, clipMax);
|
||||
|
|
@ -226,6 +289,7 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
|
||||
// Markers (shapes: RadarMarkerStyle). Corpses and items first, creatures on top.
|
||||
RadarMarkerStyle.FillColors(KindCols);
|
||||
MarkerStyleSettings markers = RadarSettingsStore.Markers;
|
||||
for (int pass = 0; pass < 2; pass++)
|
||||
{
|
||||
foreach (RadarMarker m in live.Markers)
|
||||
|
|
@ -233,17 +297,66 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
if (!RadarSettingsStore.ShowKind(m.Kind)) continue;
|
||||
if ((pass == 1) != (RadarKind.IsCreature(m.Kind) || m.Kind is RadarKind.Portal or RadarKind.Door)) continue;
|
||||
Vector2 pp = proj.P(m.X, m.Y);
|
||||
if (pp.X < clipMin.X || pp.X > clipMax.X || pp.Y < clipMin.Y || pp.Y > clipMax.Y) continue;
|
||||
RadarMarkerStyle.Draw(dl, m.Kind, pp, KindCols[m.Kind]);
|
||||
if (_round ? !_mask.Contains(pp) : (pp.X < clipMin.X || pp.X > clipMax.X || pp.Y < clipMin.Y || pp.Y > clipMax.Y)) continue;
|
||||
RadarMarkerStyle.Draw(dl, m.Kind, pp, KindCols[m.Kind], markers.SizeOf(m.Kind));
|
||||
}
|
||||
}
|
||||
|
||||
// Names last, over every marker.
|
||||
bool anyName = false;
|
||||
for (byte k = 0; k < RadarKind.Count; k++) anyName |= markers.ShowName[k] && RadarSettingsStore.ShowKind(k);
|
||||
if (anyName)
|
||||
{
|
||||
ImFontPtr nameFont = ImGuiFonts.Get(UiFont.UiBold11);
|
||||
foreach (RadarMarker m in live.Markers)
|
||||
{
|
||||
if (!markers.NameShown(m.Kind) || !RadarSettingsStore.ShowKind(m.Kind)) continue;
|
||||
Vector2 pp = proj.P(m.X, m.Y);
|
||||
if (pp.X < clipMin.X - 8 || pp.X > clipMax.X || pp.Y < clipMin.Y - 8 || pp.Y > clipMax.Y + 8) continue;
|
||||
if (_round && !_mask.Contains(pp)) continue;
|
||||
RadarMarkerStyle.DrawName(dl, nameFont, pp, RadarMarkerStyle.Radius(m.Kind) * markers.SizeOf(m.Kind),
|
||||
RadarMarkerStyle.NameColor(KindCols[m.Kind]), m.Label, markers.NameSizeOf(m.Kind), _round ? _mask : null);
|
||||
}
|
||||
}
|
||||
|
||||
// Player dot + 10 px heading arrow (always up when rotating).
|
||||
dl.AddCircleFilled(centre, 3.5f, PlayerCol, 10);
|
||||
Vector2 tip = rotate ? centre + new Vector2(0, -10) : centre + new Vector2(proj.Cos * 10, -proj.Sin * 10);
|
||||
float me = markers.SelfSize;
|
||||
dl.AddCircleFilled(centre, 3.5f * me, PlayerCol, 10);
|
||||
Vector2 tip = rotate ? centre + new Vector2(0, -10 * me) : centre + new Vector2(proj.Cos * 10 * me, -proj.Sin * 10 * me);
|
||||
dl.AddLine(centre, tip, PlayerCol, 2);
|
||||
}
|
||||
|
||||
// ── World map backdrop ─────────────────────────────────────────────────
|
||||
// The radar's world coordinates are yards from the world's south-west corner; the World Map's cells
|
||||
// are 24 yards, so cell = yards / 24 on both axes, and the radar's zoom (px per yard) is 24x that
|
||||
// in px per cell. The rotation is the Mini Map's (the way you face is up).
|
||||
|
||||
private static readonly WorldMapTileDrawer Backdrop = new();
|
||||
private static long _mapsAskedAtMs;
|
||||
|
||||
private static void DrawWorldMapBackdrop(ImDrawListPtr dl, RadarSnapshot live, Vector2 centre, Vector2 clipMin, Vector2 clipMax,
|
||||
bool rotate)
|
||||
{
|
||||
if (!WorldMapTiles.IsOpen)
|
||||
{
|
||||
// Find and open the picture (a pool thread does the file work); asked again every few seconds
|
||||
// while it isn't open, which also covers the switch being turned on later.
|
||||
long now = Environment.TickCount64;
|
||||
if (now - _mapsAskedAtMs > 5000)
|
||||
{
|
||||
_mapsAskedAtMs = now;
|
||||
WorldMapSettings.Load();
|
||||
WorldMapMaps.Refresh();
|
||||
}
|
||||
return;
|
||||
}
|
||||
float alpha = Math.Clamp(RadarSettingsStore.WorldMapOpacity, 0.1f, 1f) * Math.Clamp(RadarSettingsStore.Opacity, 0f, 1f);
|
||||
uint tint = ((uint)(alpha * 255f + 0.5f) << 24) | 0x00FFFFFFu;
|
||||
float phi = rotate ? MapProjection.PhiForHeading(live.Player.Heading) : 0f;
|
||||
Backdrop.Draw(dl, clipMin, clipMax, centre, live.Player.WorldX / 24.0, live.Player.WorldY / 24.0,
|
||||
MathF.Max(0.5f, RadarSettingsStore.Zoom) * 24f, phi, tint, _round ? _mask : null);
|
||||
}
|
||||
|
||||
private static void DrawLayer(ImDrawListPtr dl, RadarView view, int layer, float a, bool current,
|
||||
in Projection proj, bool rotate, Vector2 clipMin, Vector2 clipMax)
|
||||
{
|
||||
|
|
@ -269,7 +382,11 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
{
|
||||
Vector2 pa = proj.P(segs[i], segs[i + 1]);
|
||||
Vector2 pb = proj.P(segs[i + 2], segs[i + 3]);
|
||||
if (MathF.Max(pa.X, pb.X) < clipMin.X || MathF.Min(pa.X, pb.X) > clipMax.X ||
|
||||
if (_round)
|
||||
{
|
||||
if (!CircleClip.Segment(_mask, ref pa, ref pb)) continue;
|
||||
}
|
||||
else if (MathF.Max(pa.X, pb.X) < clipMin.X || MathF.Min(pa.X, pb.X) > clipMax.X ||
|
||||
MathF.Max(pa.Y, pb.Y) < clipMin.Y || MathF.Min(pa.Y, pb.Y) > clipMax.Y) continue;
|
||||
bool v = flags != null && w < flags.Length && flags[w];
|
||||
dl.AddLine(pa, pb, v ? visited : unseen, thick);
|
||||
|
|
@ -289,6 +406,11 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
uint col, Vector2 clipMin, Vector2 clipMax)
|
||||
{
|
||||
Vector2 p00 = proj.P(x0, y0), p11 = proj.P(x1, y1);
|
||||
if (_round)
|
||||
{
|
||||
FillRound(dl, p00, proj.P(x1, y0), p11, proj.P(x0, y1), col);
|
||||
return;
|
||||
}
|
||||
if (rotate)
|
||||
{
|
||||
Vector2 p10 = proj.P(x1, y0), p01 = proj.P(x0, y1);
|
||||
|
|
@ -308,6 +430,19 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>A floor strip (four corners, in order round it) on the round radar: whole, skipped or cut to the circle.</summary>
|
||||
private static void FillRound(ImDrawListPtr dl, Vector2 a, Vector2 b, Vector2 c, Vector2 d, uint col)
|
||||
{
|
||||
Vector2 min = Vector2.Min(Vector2.Min(a, b), Vector2.Min(c, d)), max = Vector2.Max(Vector2.Max(a, b), Vector2.Max(c, d));
|
||||
if (!_mask.OverlapsBox(min, max)) return;
|
||||
if (_mask.ContainsBox(min, max)) { dl.AddQuadFilled(a, b, c, d, col); return; }
|
||||
Span<Vector2> q = stackalloc Vector2[4];
|
||||
q[0] = a; q[1] = b; q[2] = c; q[3] = d;
|
||||
Span<Vector2> p = stackalloc Vector2[CircleClip.MaxPoints];
|
||||
int n = CircleClip.Polygon(_mask, q, default, p, default);
|
||||
if (n >= 3) dl.AddConvexPolyFilled(ref p[0], n, col);
|
||||
}
|
||||
|
||||
// ── Click-to-select ─────────────────────────────────────────────────────
|
||||
// Left-click a dot: that object is selected in game, as a click on it in the
|
||||
// 3D world would. A press that moves more than a few pixels is a drag (the
|
||||
|
|
@ -355,11 +490,7 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
if (!hovered && !clicked) return;
|
||||
if (mouse.X < clipMin.X || mouse.X > clipMax.X || mouse.Y < clipMin.Y || mouse.Y > clipMax.Y) return;
|
||||
|
||||
float zoom = MathF.Max(0.5f, RadarSettingsStore.Zoom);
|
||||
var proj = new Projection(centre, view.Live.Player, RadarSettingsStore.RotateWithPlayer, zoom);
|
||||
// Hit radius: a little more than the dot, growing with zoom, in UI-scaled pixels.
|
||||
float radius = Math.Clamp(5f + 1.5f * zoom, 6f, 14f) * MathF.Max(1f, EngineFrameController.FontScale);
|
||||
RadarMarker? hit = MarkerAt(view, proj, mouse, radius, clipMin, clipMax, out Vector2 hitPos);
|
||||
RadarMarker? hit = HitTest(view, centre, clipMin, clipMax, mouse, out Vector2 hitPos);
|
||||
if (hit == null) return;
|
||||
|
||||
if (clicked && _pressTravel <= ClickSlop)
|
||||
|
|
@ -379,20 +510,57 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
ImGuiNET.ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
/// <summary>The marker under <paramref name="mouse"/> (a dot's hit radius grows with the zoom and the marker's size), or null.</summary>
|
||||
private static RadarMarker? HitTest(RadarView view, Vector2 centre, Vector2 clipMin, Vector2 clipMax, Vector2 mouse, out Vector2 hitPos)
|
||||
{
|
||||
hitPos = default;
|
||||
if (_round && !_mask.Contains(mouse)) return null;
|
||||
if (mouse.X < clipMin.X || mouse.X > clipMax.X || mouse.Y < clipMin.Y || mouse.Y > clipMax.Y) return null;
|
||||
float zoom = MathF.Max(0.5f, RadarSettingsStore.Zoom);
|
||||
var proj = new Projection(centre, view.Live.Player, RadarSettingsStore.RotateWithPlayer, zoom);
|
||||
// Hit radius: a little more than the dot, growing with zoom, in UI-scaled pixels.
|
||||
float radius = Math.Clamp(5f + 1.5f * zoom, 6f, 14f) * MathF.Max(1f, EngineFrameController.FontScale);
|
||||
return MarkerAt(view, proj, mouse, radius, clipMin, clipMax, out hitPos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the mouse is over a selectable dot or one of the two buttons: the next frame's
|
||||
/// <see cref="ClickThrough"/> answer. Once a press has begun, it holds until the button is up.
|
||||
/// </summary>
|
||||
private void UpdateHot(RadarView? view, Vector2 centre, Vector2 clipMin, Vector2 clipMax, Vector2 buttonsMin, Vector2 buttonsMax)
|
||||
{
|
||||
var io = ImGuiNET.ImGui.GetIO();
|
||||
Vector2 m = io.MousePos;
|
||||
bool over = m.X >= buttonsMin.X && m.X <= buttonsMax.X && m.Y >= buttonsMin.Y && m.Y <= buttonsMax.Y;
|
||||
if (!over && view != null && RadarSettingsStore.ClickToSelect)
|
||||
over = HitTest(view, centre, clipMin, clipMax, m, out _) != null;
|
||||
bool down = io.MouseDown[0];
|
||||
if (down)
|
||||
{
|
||||
if (!_downPrev) _pressHot = over;
|
||||
_hot = _pressHot;
|
||||
}
|
||||
else _hot = over;
|
||||
_downPrev = down;
|
||||
}
|
||||
|
||||
/// <summary>The shown marker nearest <paramref name="mouse"/> within <paramref name="radius"/> px, or null.</summary>
|
||||
private static RadarMarker? MarkerAt(RadarView view, in Projection proj, Vector2 mouse, float radius,
|
||||
Vector2 clipMin, Vector2 clipMax, out Vector2 at)
|
||||
{
|
||||
RadarMarker? best = null;
|
||||
float bestD2 = radius * radius;
|
||||
float bestD2 = float.MaxValue;
|
||||
at = default;
|
||||
float uiScale = MathF.Max(1f, EngineFrameController.FontScale);
|
||||
foreach (RadarMarker m in view.Live.Markers)
|
||||
{
|
||||
if (!RadarSettingsStore.ShowKind(m.Kind)) continue;
|
||||
Vector2 pp = proj.P(m.X, m.Y);
|
||||
if (pp.X < clipMin.X || pp.X > clipMax.X || pp.Y < clipMin.Y || pp.Y > clipMax.Y) continue;
|
||||
// A big marker is grabbed anywhere on it, not only near its centre.
|
||||
float reach = MathF.Max(radius, (RadarMarkerStyle.Radius(m.Kind) * RadarSettingsStore.Markers.SizeOf(m.Kind) + 2f) * uiScale);
|
||||
float d2 = Vector2.DistanceSquared(pp, mouse);
|
||||
if (d2 > bestD2) continue;
|
||||
if (d2 > reach * reach || d2 >= bestD2) continue;
|
||||
bestD2 = d2;
|
||||
best = m;
|
||||
at = pp;
|
||||
|
|
@ -475,7 +643,7 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
|
||||
private static void DrawCardinals(ImDrawListPtr dl, RadarView view, Vector2 centre, float halfW, float halfH)
|
||||
{
|
||||
const float sz = 14;
|
||||
float sz = RadarSettingsStore.CompassSize;
|
||||
bool rotate = RadarSettingsStore.RotateWithPlayer;
|
||||
float h = view.Live.Player.Heading * MathF.PI / 180f;
|
||||
float sinH = MathF.Sin(h), cosH = MathF.Cos(h);
|
||||
|
|
@ -498,19 +666,24 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
// Onto the rectangular perimeter: max(|dx t|/effW, |dy t|/effH) = 1.
|
||||
float m = MathF.Max(MathF.Abs(dirX) / effW, MathF.Abs(dirY) / effH);
|
||||
if (m < 1e-4f) continue;
|
||||
float t = 1 / m;
|
||||
DrawOutlinedText(dl, font, c.Label, new Vector2(centre.X + dirX * t, centre.Y + dirY * t), Cardinal, alignBottom: false);
|
||||
float t = _round ? MathF.Max(1f, _mask.Radius - sz * 0.6f) / MathF.Sqrt(dirX * dirX + dirY * dirY) : 1 / m;
|
||||
DrawOutlinedText(dl, font, c.Label, new Vector2(centre.X + dirX * t, centre.Y + dirY * t), Cardinal, alignBottom: false,
|
||||
scale: sz / 14f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Text with a 1 px 4-way black outline, centred on x; centred or bottom-aligned on y.</summary>
|
||||
private static void DrawOutlinedText(ImDrawListPtr dl, ImFontPtr font, string text, Vector2 anchor, uint col, bool alignBottom)
|
||||
/// <summary>
|
||||
/// Text with a 1 px 4-way black outline, centred on x; centred or bottom-aligned on y.
|
||||
/// <paramref name="scale"/> stretches the font's baked size (1 = as baked).
|
||||
/// </summary>
|
||||
private static void DrawOutlinedText(ImDrawListPtr dl, ImFontPtr font, string text, Vector2 anchor, uint col, bool alignBottom,
|
||||
float scale = 1f)
|
||||
{
|
||||
ImGuiNET.ImGui.PushFont(font);
|
||||
Vector2 ts = ImGuiNET.ImGui.CalcTextSize(text);
|
||||
Vector2 ts = ImGuiNET.ImGui.CalcTextSize(text) * scale;
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
var pos = new Vector2(anchor.X - ts.X * 0.5f, alignBottom ? anchor.Y - ts.Y - 1 : anchor.Y - ts.Y * 0.5f);
|
||||
float fs = font.FontSize;
|
||||
float fs = font.FontSize * scale;
|
||||
dl.AddText(font, fs, pos + new Vector2(-1, 0), Outline, text);
|
||||
dl.AddText(font, fs, pos + new Vector2(1, 0), Outline, text);
|
||||
dl.AddText(font, fs, pos + new Vector2(0, -1), Outline, text);
|
||||
|
|
@ -518,24 +691,21 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
dl.AddText(font, fs, pos, col, text);
|
||||
}
|
||||
|
||||
private static bool IconButton(string id, Vector2 pos, string glyph)
|
||||
{
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
var size = new Vector2(22, 22);
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(pos);
|
||||
bool clicked = ImGuiNET.ImGui.InvisibleButton(id, size);
|
||||
uint bg = ImGuiNET.ImGui.IsItemActive() ? C(0xE0101820) : ImGuiNET.ImGui.IsItemHovered() ? C(0xE0243444) : ButtonBg;
|
||||
dl.AddRectFilled(pos, pos + size, bg, 3);
|
||||
dl.AddRect(pos, pos + size, ButtonBorder, 3);
|
||||
PhosphorIcons.DrawCentered(dl, ImGuiFonts.Get(UiFont.Ui14), glyph, pos, size, CoordText);
|
||||
return clicked;
|
||||
}
|
||||
|
||||
// ── Settings (gear) ─────────────────────────────────────────────────────
|
||||
|
||||
private void SettingsWindow()
|
||||
{
|
||||
if (!_settingsOpen) return;
|
||||
if (!_settingsOpen)
|
||||
{
|
||||
if (_settingsSub) { UiSources.Settings.Unsubscribe(); _settingsSub = false; }
|
||||
return;
|
||||
}
|
||||
if (!_settingsSub)
|
||||
{
|
||||
UiSources.Settings.Subscribe();
|
||||
UiSources.Settings.RequestRefresh();
|
||||
_settingsSub = true;
|
||||
}
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.WindowBg, RynthTheme.BoxBg);
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Border, ButtonBorder);
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 4f);
|
||||
|
|
@ -552,19 +722,39 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.UiBold11));
|
||||
ImGuiNET.ImGui.TextUnformatted("Radar Settings");
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
// The small close X, in the top-right corner of the content (the width of the kind rows' last column).
|
||||
float uiScale = MathF.Max(1f, EngineFrameController.FontScale);
|
||||
ImGuiNET.ImGui.SameLine(350 * uiScale + MarkerStyleEditor.SizeSliderWidth - 14);
|
||||
if (FaceKit.IconButton("##radar_settings_close", PhosphorIcons.X, ImGuiNET.ImGui.GetCursorScreenPos(), new Vector2(14, 14),
|
||||
FaceKit.Faded(FaceKit.Mute), RynthTheme.WithAlpha(RynthTheme.Background, 0xDC), font: UiFont.Ui9))
|
||||
_settingsOpen = false;
|
||||
ImGuiNET.ImGui.SetItemTooltip("Close");
|
||||
ImGuiNET.ImGui.Separator();
|
||||
|
||||
bool changed = false;
|
||||
changed |= Check("Rotate with player", ref RadarSettingsStore.RotateWithPlayer);
|
||||
changed |= Check("Show gold rim", ref RadarSettingsStore.ShowGoldRim);
|
||||
changed |= Check("Docked click-through (hold Ctrl to interact)", ref RadarSettingsStore.CtrlGatedClickThrough);
|
||||
changed |= Check("Round radar", ref RadarSettingsStore.RoundRadar);
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("On: docked clicks pass through to the game; hold Ctrl to drag, open the gear, or resize.");
|
||||
ImGuiNET.ImGui.SetTooltip("A circle instead of a square: the picture, the dots and the world map are all cut to it.");
|
||||
changed |= Check("Docked click-through (dots still work; Ctrl for the rest)", ref RadarSettingsStore.CtrlGatedClickThrough);
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("On: docked clicks pass through to the game, except on a dot (hover it, click to select) and the two buttons; hold Ctrl to drag or resize.");
|
||||
changed |= Check("Click a dot to select it", ref RadarSettingsStore.ClickToSelect);
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("Left-click a dot to select that object in game. Hover a dot for its name and distance.");
|
||||
changed |= Slider("Opacity", ref RadarSettingsStore.Opacity, 0.05f, 1.0f, "%.2f");
|
||||
changed |= Slider("Zoom", ref RadarSettingsStore.Zoom, 0.5f, 6.0f, "%.1f");
|
||||
changed |= Check("World map behind the radar (outdoors)", ref RadarSettingsStore.ShowWorldMap);
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("Draws the World Map's picture of the ground behind the dots while you're outdoors.\nIts sharpness follows the World Map's Detail setting (the bigger map packs look best zoomed in).");
|
||||
if (RadarSettingsStore.ShowWorldMap)
|
||||
{
|
||||
changed |= Slider("Map", ref RadarSettingsStore.WorldMapOpacity, 0.1f, 1.0f, "%.2f");
|
||||
if (!WorldMapTiles.IsOpen && WorldMapTiles.Status.Length > 0)
|
||||
SafeImGui.TextDisabled(WorldMapTiles.Status);
|
||||
}
|
||||
RetailRadarRow();
|
||||
ImGuiNET.ImGui.Separator();
|
||||
changed |= KindRows();
|
||||
if (changed)
|
||||
|
|
@ -572,9 +762,6 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
AvaloniaOverlay.RadarCtrlGatedClickThrough = RadarSettingsStore.CtrlGatedClickThrough;
|
||||
RadarSettingsStore.Save();
|
||||
}
|
||||
// The gear toggles this window too; Close is the obvious way out (changes are already saved).
|
||||
ImGuiNET.ImGui.Separator();
|
||||
if (ImGuiNET.ImGui.Button("Close")) _settingsOpen = false;
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
}
|
||||
ImGuiNET.ImGui.End();
|
||||
|
|
@ -582,8 +769,41 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
|
||||
private static bool Check(string label, ref bool value) => ImGuiNET.ImGui.Checkbox(label, ref value);
|
||||
|
||||
/// <summary>
|
||||
/// "Hide the retail radar": RynthAi's own SuppressRetailRadar setting (RynthAi pushes it to the engine every
|
||||
/// tick), the same switch as Settings > UI > Hide retail radar. This reads it from RynthAi's settings payload
|
||||
/// and saves it back through the same command, so the two always agree whichever is changed; saved with the
|
||||
/// character's RynthAi settings. Greyed out until RynthAi has answered. The box shows the new value at once,
|
||||
/// until RynthAi's answer catches up.
|
||||
/// </summary>
|
||||
private void RetailRadarRow()
|
||||
{
|
||||
RynthAiSettings? ra = UiSources.Settings.Current?.Value;
|
||||
bool actual = ra?.SuppressRetailRadar ?? false;
|
||||
if (_hidePending is bool pending && (pending == actual || Environment.TickCount64 - _hidePendingAt > 3000))
|
||||
_hidePending = null;
|
||||
bool hide = _hidePending ?? actual;
|
||||
ImGuiNET.ImGui.BeginDisabled(ra == null);
|
||||
if (ImGuiNET.ImGui.Checkbox("Hide the retail radar", ref hide) && ra != null)
|
||||
{
|
||||
RynthAiSettings copy = ra.Clone();
|
||||
copy.SuppressRetailRadar = hide;
|
||||
SettingsCommands.Save(copy);
|
||||
_hidePending = hide;
|
||||
_hidePendingAt = Environment.TickCount64;
|
||||
}
|
||||
ImGuiNET.ImGui.EndDisabled();
|
||||
if (ImGuiNET.ImGui.IsItemHovered())
|
||||
ImGuiNET.ImGui.SetTooltip("Hides the game's built-in radar (bezel, compass, coordinates, blips).\nThe same switch as RynthAi's Settings > UI > Hide retail radar: change it in either place.");
|
||||
if (ra == null)
|
||||
{
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
ImGuiNET.ImGui.TextDisabled("(waiting for RynthAi)");
|
||||
}
|
||||
}
|
||||
|
||||
// Legend order: creatures, then corpses, then places, then items.
|
||||
private static readonly (byte Kind, string Label)[] KindRowsOrder =
|
||||
internal static readonly (byte Kind, string Label)[] KindRowsOrder =
|
||||
{
|
||||
(RadarKind.Monster, "Monsters"), (RadarKind.Player, "Players"), (RadarKind.Fellow, "Fellows"),
|
||||
(RadarKind.Npc, "NPCs"), (RadarKind.Vendor, "Vendors"), (RadarKind.Pet, "Your pets"),
|
||||
|
|
@ -608,8 +828,9 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
};
|
||||
|
||||
/// <summary>
|
||||
/// The legend and per-kind settings: show box, the marker as drawn, its name and a colour
|
||||
/// swatch (click to pick). One row per kind, then "Reset colours". True when something changed.
|
||||
/// The legend and per-kind settings: show box, the marker as drawn, its name, a colour swatch
|
||||
/// (click to pick), then the name box and the marker and name sizes (MarkerStyleEditor). One row
|
||||
/// per kind, then your own arrow's size, the reset buttons. True when something changed.
|
||||
/// </summary>
|
||||
private static bool KindRows()
|
||||
{
|
||||
|
|
@ -620,6 +841,10 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
RadarMarkerStyle.FillColors(KindCols);
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
float scale = MathF.Max(1f, EngineFrameController.FontScale);
|
||||
// Columns after the colour swatch (at 190): name box, marker size, name text size.
|
||||
float xName = 232 * scale, xSize = 268 * scale, xText = 350 * scale;
|
||||
MarkerStyleSettings markers = RadarSettingsStore.Markers;
|
||||
MarkerStyleEditor.HeaderRow(xName, xSize, xText);
|
||||
const ImGuiColorEditFlags pickFlags = ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel
|
||||
| ImGuiColorEditFlags.AlphaBar | ImGuiColorEditFlags.AlphaPreviewHalf;
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(6, 3));
|
||||
|
|
@ -630,6 +855,7 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
bool sub = kind == RadarKind.OwnCorpse;
|
||||
if (sub) { ImGuiNET.ImGui.Indent(14 * scale); ImGuiNET.ImGui.BeginDisabled(!RadarSettingsStore.ShowCorpses); }
|
||||
changed |= ImGuiNET.ImGui.Checkbox("##show", ref RadarSettingsStore.ShowFlag(kind));
|
||||
if (sub) ImGuiNET.ImGui.EndDisabled(); // the sizes below stay adjustable
|
||||
if (ImGuiNET.ImGui.IsItemHovered()) SafeImGui.SetTooltip(KindTips[kind]);
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
// The marker exactly as the radar draws it; faded while the kind is hidden, so the
|
||||
|
|
@ -652,10 +878,19 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
RadarSettingsStore.KindColors[kind] = ToArgb(v);
|
||||
_colorDirty = true;
|
||||
}
|
||||
if (sub) { ImGuiNET.ImGui.EndDisabled(); ImGuiNET.ImGui.Unindent(14 * scale); }
|
||||
changed |= MarkerStyleEditor.KindCells(markers, kind, xName, xSize, xText);
|
||||
if (sub) ImGuiNET.ImGui.Unindent(14 * scale);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
}
|
||||
ImGuiNET.ImGui.PopStyleVar();
|
||||
// Everything else drawn on the radar that has a size.
|
||||
ImGuiNET.ImGui.Separator();
|
||||
changed |= MarkerStyleEditor.SliderRow("You (heading arrow)", ref markers.SelfSize,
|
||||
MarkerStyleSettings.MinSize, MarkerStyleSettings.MaxSize, "%.1fx", xSize);
|
||||
changed |= MarkerStyleEditor.SliderRow("Compass letters", ref RadarSettingsStore.CompassSize,
|
||||
RadarSettingsStore.MinText, RadarSettingsStore.MaxText, "%.0f px", xText);
|
||||
changed |= MarkerStyleEditor.SliderRow("Coordinates", ref RadarSettingsStore.CoordSize,
|
||||
RadarSettingsStore.MinText, RadarSettingsStore.MaxText, "%.0f px", xText);
|
||||
// The picker reports every drag step: save once no colour edit is in progress.
|
||||
if (_colorDirty && !ImGuiNET.ImGui.IsAnyItemActive())
|
||||
{
|
||||
|
|
@ -668,6 +903,13 @@ internal sealed class RadarFace : IImGuiPanel
|
|||
changed = true;
|
||||
}
|
||||
if (ImGuiNET.ImGui.IsItemHovered()) ImGuiNET.ImGui.SetTooltip("Every kind back to its default colour (show boxes stay as they are).");
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
if (ImGuiNET.ImGui.SmallButton("Reset sizes and names"))
|
||||
{
|
||||
RadarSettingsStore.ResetSizes();
|
||||
changed = true;
|
||||
}
|
||||
if (ImGuiNET.ImGui.IsItemHovered()) ImGuiNET.ImGui.SetTooltip("Every marker, name, arrow, compass and coordinate size, and the name boxes, back to their defaults.");
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
// Colours come in as ImGui colours (RynthTheme.Argb of the ARGB setting).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Engine.UI.Data;
|
||||
|
|
@ -101,6 +103,79 @@ internal static class RadarMarkerStyle
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Half the marker's width at <c>s</c> = 1, in pixels (where a name label starts, how big a hit is).</summary>
|
||||
public static float Radius(byte kind) => kind switch
|
||||
{
|
||||
RadarKind.Monster or RadarKind.Npc => 3f,
|
||||
RadarKind.Portal => 4f,
|
||||
RadarKind.Door => 3.5f,
|
||||
RadarKind.Player => 4.5f,
|
||||
RadarKind.Fellow => 4.8f,
|
||||
RadarKind.Pet => 2.8f,
|
||||
RadarKind.Vendor => 4f,
|
||||
RadarKind.Corpse => 3f,
|
||||
RadarKind.OwnCorpse => 3.6f,
|
||||
RadarKind.Lifestone => 3.8f,
|
||||
_ => 3f,
|
||||
};
|
||||
|
||||
private const int MaxNameChars = 24;
|
||||
// Clipped names, so a long one costs no string per frame. Cleared when it grows large.
|
||||
private static readonly Dictionary<string, string> Clipped = new();
|
||||
private static readonly uint NameOutline = RynthTheme.Argb(0xE6000000);
|
||||
|
||||
/// <summary>
|
||||
/// Draws <paramref name="name"/> to the right of a marker centred on <paramref name="p"/>
|
||||
/// (<paramref name="radius"/> = its drawn half-width), in <paramref name="col"/> with a dark outline so it
|
||||
/// reads on floors and walls alike. <paramref name="sizePx"/> is the text size at 100% UI scale:
|
||||
/// <paramref name="font"/> (baked at the UI scale) is stretched to it, so it follows the UI scale too.
|
||||
/// Names longer than 24 characters are cut with an ellipsis. On the round radar (<paramref name="mask"/>) a name that
|
||||
/// runs past the circle is cut off at its edge.
|
||||
/// </summary>
|
||||
public static void DrawName(ImDrawListPtr dl, ImFontPtr font, Vector2 p, float radius, uint col, string? name, float sizePx,
|
||||
RoundMask? mask = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return;
|
||||
if (name.Length > MaxNameChars)
|
||||
{
|
||||
if (!Clipped.TryGetValue(name, out string? cut))
|
||||
{
|
||||
if (Clipped.Count > 512) Clipped.Clear();
|
||||
cut = name[..MaxNameChars] + "…";
|
||||
Clipped[name] = cut;
|
||||
}
|
||||
name = cut;
|
||||
}
|
||||
// The font is baked for 11 px text at the UI scale: its FontSize / 11 is that scale.
|
||||
float fs = sizePx * (font.FontSize / 11f);
|
||||
ImGuiNET.ImGui.PushFont(font);
|
||||
Vector2 ts = ImGuiNET.ImGui.CalcTextSize(name) * (fs / font.FontSize);
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
var at = new Vector2(p.X + radius + 3f, p.Y - ts.Y * 0.5f);
|
||||
// Round radar, and the name runs past the circle: it is cut off at the circle's edge. ImGui clips to
|
||||
// rectangles, so the cut is a vertical edge at the circle's width on the text's farthest row from the
|
||||
// centre (the text is a line high, so the edge is within a pixel or two of the circle).
|
||||
bool clipped = false;
|
||||
if (mask is RoundMask round && !round.ContainsBox(at, at + ts))
|
||||
{
|
||||
float dy = MathF.Max(MathF.Abs(at.Y - round.Centre.Y), MathF.Abs(at.Y + ts.Y - round.Centre.Y));
|
||||
float half = round.Radius * round.Radius - dy * dy;
|
||||
if (half <= 0f) return;
|
||||
half = MathF.Sqrt(half);
|
||||
dl.PushClipRect(new Vector2(round.Centre.X - half, at.Y - 2f), new Vector2(round.Centre.X + half, at.Y + ts.Y + 2f), true);
|
||||
clipped = true;
|
||||
}
|
||||
dl.AddText(font, fs, at + new Vector2(-1, 0), NameOutline, name);
|
||||
dl.AddText(font, fs, at + new Vector2(1, 0), NameOutline, name);
|
||||
dl.AddText(font, fs, at + new Vector2(0, -1), NameOutline, name);
|
||||
dl.AddText(font, fs, at + new Vector2(0, 1), NameOutline, name);
|
||||
dl.AddText(font, fs, at, col, name);
|
||||
if (clipped) dl.PopClipRect();
|
||||
}
|
||||
|
||||
/// <summary>A kind's colour for its name: the marker's colour, fully opaque.</summary>
|
||||
public static uint NameColor(uint markerCol) => markerCol | 0xFF000000u;
|
||||
|
||||
/// <summary>An ImGui colour (ABGR) with its RGB scaled by <paramref name="k"/>, alpha kept.</summary>
|
||||
public static uint Darken(uint col, float k)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -712,7 +712,9 @@ internal sealed partial class RynthAiFace : IImGuiPanel
|
|||
float y = ImGuiNET.ImGui.GetCursorScreenPos().Y;
|
||||
// Nav and Meta left the row (2026-10-14): right-click the Navigation and Meta toggles.
|
||||
// Hub left it 2026-10-15 (the Mini Remote: the bar button, Char's menu, its drawer tab).
|
||||
const int buttons = 7;
|
||||
// World joins them when the engine has the world map (WorldMapFace; its tiles may not be installed).
|
||||
bool worldMap = ImGuiPanelHost.HasFace(WorldMapFace.Title);
|
||||
int buttons = worldMap ? 8 : 7;
|
||||
float gap = Px(LauncherGap);
|
||||
float bw = MathF.Floor((width - buttons * gap) / buttons);
|
||||
// Short labels only when every button has room for its icon and label.
|
||||
|
|
@ -733,6 +735,12 @@ internal sealed partial class RynthAiFace : IImGuiPanel
|
|||
Launcher("##l_map", PhosphorIcons.MapPin, "Map", "Dungeon Map (shows while you're in a dungeon)", x, y, bw, labels,
|
||||
() => PanelRouter.Toggle(DungeonMapFace.Title), ImGuiPanelHost.IsOpen(DungeonMapFace.Title));
|
||||
x += bw + gap;
|
||||
if (worldMap)
|
||||
{
|
||||
Launcher("##l_world", PhosphorIcons.GlobeHemisphereWest, "World", "World Map: Dereth, with your position, the route and places (also in the RynthNav panel)", x, y, bw, labels,
|
||||
() => PanelRouter.Toggle(WorldMapFace.Title), ImGuiPanelHost.IsOpen(WorldMapFace.Title));
|
||||
x += bw + gap;
|
||||
}
|
||||
Launcher("##l_items", PhosphorIcons.Backpack, "Items", "Items", x, y, bw, labels, () => PanelRouter.Toggle("Items"),
|
||||
ImGuiPanelHost.IsOpen("Items"));
|
||||
x += bw + gap;
|
||||
|
|
|
|||
|
|
@ -341,6 +341,7 @@ internal sealed class RynthNavFace : IImGuiPanel
|
|||
NextLine(p, 28);
|
||||
if (st.HasAvoid) AvoidRows(st, w);
|
||||
if (st.HasMarkers) MarkerRow(st, w);
|
||||
if (st.HasMesh) MeshRows(st, w);
|
||||
}
|
||||
Line(w);
|
||||
|
||||
|
|
@ -708,6 +709,46 @@ internal sealed class RynthNavFace : IImGuiPanel
|
|||
NextLine(p, 26);
|
||||
}
|
||||
|
||||
// The navmesh drawn in the world (RynthNav 0.6.7+): green where nav can walk, red walls where
|
||||
// the mesh ends. Each click sends /rnav mesh ... (saved in rynthnav.json by RynthNav).
|
||||
private static void MeshRows(RynthNavStatus st, float w)
|
||||
{
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
float w1 = (w - 8) * 0.44f, w2 = (w - 8) * 0.26f, w3 = w - 8 - w1 - w2;
|
||||
if (Toggle("##ms_on", "Show navmesh", st.MeshOn, p, w1))
|
||||
RynthNavCommands.Command(st.MeshOn ? "mesh off" : "mesh on");
|
||||
SafeImGui.SetItemTooltip("Draw the navigation mesh in the world: green where nav can walk, red walls where the mesh ends\n"
|
||||
+ "(buildings, trees, rocks, cliffs, steep ground and the margin round them). Not drawn in dungeons."
|
||||
+ (st.MeshOn ? $"\n\nNow: {st.MeshDrawn} triangles drawn." : ""));
|
||||
if (Toggle("##ms_floor", "Green", st.MeshFloor, new Vector2(p.X + w1 + 4, p.Y), w2))
|
||||
RynthNavCommands.Command(st.MeshFloor ? "mesh floor off" : "mesh floor on");
|
||||
ImGuiNET.ImGui.SetItemTooltip("The walkable ground, in green.");
|
||||
if (Toggle("##ms_walls", "Red walls", st.MeshWalls, new Vector2(p.X + w1 + w2 + 8, p.Y), w3))
|
||||
RynthNavCommands.Command(st.MeshWalls ? "mesh walls off" : "mesh walls on");
|
||||
ImGuiNET.ImGui.SetItemTooltip("Upright red strips along every edge nav will not cross.");
|
||||
NextLine(p, 26);
|
||||
MeshStepRow("radius", "Mesh radius", st.MeshRadius, 10, 10, 150, " m", st.MeshOn, w,
|
||||
"How far around you the mesh is drawn.");
|
||||
MeshStepRow("triangles", "Mesh detail", st.MeshTriangles, 500, 200, 7000, "", st.MeshOn, w,
|
||||
"The most triangles the mesh may use. The game's 3D buffer holds 8192 for every plugin, so keep this under about 5000\n"
|
||||
+ "when RynthVision's slope overlay is on. The nearest ground and walls are kept first.");
|
||||
}
|
||||
|
||||
private static void MeshStepRow(string key, string label, int value, int step, int min, int max, string unit, bool active, float w, string tip)
|
||||
{
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
float bw = 22, vw = 54, lw = w - 2 * bw - vw - 12;
|
||||
Button("##ms_" + key, label, p, new Vector2(lw, 22), active ? Text : Faded(Mute), BtnFill, enabled: false, leftAlign: true);
|
||||
SafeImGui.SetItemTooltip(tip);
|
||||
float x = p.X + lw + 4;
|
||||
if (Button("##ms_" + key + "_dn", "-", new Vector2(x, p.Y), new Vector2(bw, 22), Text, BtnFill, enabled: value > min))
|
||||
RynthNavCommands.Command($"mesh {key} {Math.Max(min, value - step)}");
|
||||
Button("##ms_" + key + "_v", value + unit, new Vector2(x + bw + 4, p.Y), new Vector2(vw, 22), active ? Text : Faded(Mute), PanelBg, enabled: false);
|
||||
if (Button("##ms_" + key + "_up", "+", new Vector2(x + bw + vw + 8, p.Y), new Vector2(bw, 22), Text, BtnFill, enabled: value < max))
|
||||
RynthNavCommands.Command($"mesh {key} {Math.Min(max, value + step)}");
|
||||
NextLine(p, 26);
|
||||
}
|
||||
|
||||
// ── Save as nav route (RynthNav 0.6.6+) ──────────────────────────────
|
||||
|
||||
private readonly byte[] _saveName = new byte[96];
|
||||
|
|
|
|||
152
src/RynthCore.Engine/ImGui/Panels/WorldMapTileDrawer.cs
Normal file
152
src/RynthCore.Engine/ImGui/Panels/WorldMapTileDrawer.cs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - ImGui/Panels/WorldMapTileDrawer.cs
|
||||
// Draws the World Map picture (WorldMapTiles' pyramid of tiles) into a rectangle, for any view that
|
||||
// can say where the picture sits: the World Map and Mini Map (WorldMapView) and the Radar's
|
||||
// "world map behind the radar" option. The view gives the cell at its centre, the zoom (screen px
|
||||
// per cell) and the rotation; this picks the sharpest tile level the screen can use, draws the
|
||||
// coarser levels under it (so whatever hasn't arrived shows blurry, not blank) and asks for the
|
||||
// tiles under the view, centre first. One drawer per view (it keeps a scratch list).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace RynthCore.Engine.ImGuiBackend.Panels;
|
||||
|
||||
internal sealed class WorldMapTileDrawer
|
||||
{
|
||||
private readonly List<(int Dist, int Col, int Row)> _tileOrder = new(128);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the tiles under the canvas. <paramref name="centre"/> is the screen point of map cell
|
||||
/// (<paramref name="ccx"/>, <paramref name="ccy"/>); <paramref name="scale"/> is pixels per cell; <paramref name="phi"/>
|
||||
/// the map's rotation in radians (0: north up). <paramref name="tint"/> is an ImGui colour
|
||||
/// (white = as is; its alpha fades the picture). <paramref name="mask"/>: only the part inside that circle is drawn
|
||||
/// (the round Radar); tiles across its edge are cut to it, texture coordinates and all. AC's render thread, inside a Draw.
|
||||
/// </summary>
|
||||
public void Draw(ImDrawListPtr dl, Vector2 canvasMin, Vector2 canvasMax, Vector2 centre,
|
||||
double ccx, double ccy, float scale, float phi, uint tint = 0xFFFFFFFF, RoundMask? mask = null)
|
||||
{
|
||||
var levels = WorldMapTiles.Levels;
|
||||
if (!WorldMapTiles.IsOpen || levels.Count == 0) return;
|
||||
int ppc0 = WorldMapTiles.PixelsPerCell, top = levels.Count - 1;
|
||||
double cellsHigh = WorldMapTiles.CellsHigh;
|
||||
// The map area in view: the canvas as it is, or (turned) the circle around it.
|
||||
double halfW = (canvasMax.X - canvasMin.X) * 0.5, halfH = (canvasMax.Y - canvasMin.Y) * 0.5;
|
||||
if (phi != 0f) { halfW = halfH = Math.Sqrt(halfW * halfW + halfH * halfH); }
|
||||
double cxMin = ccx - halfW / scale, cxMax = ccx + halfW / scale;
|
||||
double cyMin = ccy - halfH / scale, cyMax = ccy + halfH / scale;
|
||||
|
||||
// The sharpest level whose pixels are at least as dense as the screen's; a coarser one if that is too many tiles.
|
||||
int L = Math.Clamp((int)Math.Floor(Math.Log2(ppc0 / (double)scale)), 0, top);
|
||||
while (L < top && VisibleTiles(L, ppc0, cellsHigh, cxMin, cxMax, cyMin, cyMax) > 80) L++;
|
||||
|
||||
var proj = new MapProjection(centre, ccx, ccy, scale, phi);
|
||||
// Coarse to fine: the top level (always loaded) first, so whatever hasn't arrived shows blurry, not blank.
|
||||
for (int lv = top; lv >= L; lv--)
|
||||
DrawLevel(dl, lv, ppc0, cellsHigh, cxMin, cxMax, cyMin, cyMax, request: lv <= Math.Min(top, L + 1),
|
||||
centre, ccx, ccy, scale, phi != 0f, proj, tint, mask);
|
||||
}
|
||||
|
||||
private static int VisibleTiles(int lv, int ppc0, double cellsHigh, double cxMin, double cxMax, double cyMin, double cyMax)
|
||||
{
|
||||
double cpt = WorldMapTiles.TileSize * (double)(1 << lv) / ppc0;
|
||||
int cols = (int)Math.Floor(Math.Min(cxMax, WorldMapTiles.CellsWide) / cpt) - (int)Math.Floor(Math.Max(cxMin, 0) / cpt) + 1;
|
||||
int rows = (int)Math.Floor((cellsHigh - Math.Max(cyMin, 0)) / cpt) - (int)Math.Floor((cellsHigh - Math.Min(cyMax, cellsHigh)) / cpt) + 1;
|
||||
return Math.Max(cols, 0) * Math.Max(rows, 0);
|
||||
}
|
||||
|
||||
private void DrawLevel(ImDrawListPtr dl, int lv, int ppc0, double cellsHigh, double cxMin, double cxMax, double cyMin, double cyMax,
|
||||
bool request, Vector2 centre, double ccx, double ccy, float scale, bool turned, in MapProjection proj, uint tint, RoundMask? mask)
|
||||
{
|
||||
var lvl = WorldMapTiles.Levels[lv];
|
||||
double cpt = WorldMapTiles.TileSize * (double)(1 << lv) / ppc0;
|
||||
int c0 = Math.Max(0, (int)Math.Floor(cxMin / cpt)), c1 = Math.Min(lvl.Cols - 1, (int)Math.Floor(cxMax / cpt));
|
||||
int r0 = Math.Max(0, (int)Math.Floor((cellsHigh - cyMax) / cpt)), r1 = Math.Min(lvl.Rows - 1, (int)Math.Floor((cellsHigh - cyMin) / cpt));
|
||||
if (c1 < c0 || r1 < r0) return;
|
||||
|
||||
// Centre-out, so the tiles you're looking at load first.
|
||||
_tileOrder.Clear();
|
||||
double ccol = ccx / cpt, crow = (cellsHigh - ccy) / cpt;
|
||||
for (int r = r0; r <= r1; r++)
|
||||
for (int c = c0; c <= c1; c++)
|
||||
{
|
||||
double dx = c + 0.5 - ccol, dy = r + 0.5 - crow;
|
||||
_tileOrder.Add(((int)((dx * dx + dy * dy) * 1000), c, r));
|
||||
}
|
||||
_tileOrder.Sort(static (a, b) => a.Dist.CompareTo(b.Dist));
|
||||
|
||||
for (int i = _tileOrder.Count - 1; i >= 0; i--) // draw far to near; nothing overlaps within a level
|
||||
{
|
||||
var (_, c, r) = _tileOrder[i];
|
||||
IntPtr tex;
|
||||
if (!(request ? WorldMapTiles.TryGet(lv, c, r, out tex) : WorldMapTiles.Peek(lv, c, r, out tex))) continue;
|
||||
double left = c * cpt, right = (c + 1) * cpt, topCell = cellsHigh - r * cpt, bottomCell = cellsHigh - (r + 1) * cpt;
|
||||
if (mask is RoundMask round)
|
||||
{
|
||||
DrawRound(dl, tex, round, proj, left, right, topCell, bottomCell, tint);
|
||||
continue;
|
||||
}
|
||||
if (!turned)
|
||||
{
|
||||
// Edges from the same formula for both neighbours, rounded to whole pixels: no seams, no gaps.
|
||||
float x0 = MathF.Round(centre.X + (float)((left - ccx) * scale)), x1 = MathF.Round(centre.X + (float)((right - ccx) * scale));
|
||||
float y0 = MathF.Round(centre.Y - (float)((topCell - ccy) * scale)), y1 = MathF.Round(centre.Y - (float)((bottomCell - ccy) * scale));
|
||||
dl.AddImage(tex, new Vector2(x0, y0), new Vector2(x1, y1), Vector2.Zero, Vector2.One, tint);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Turned: a quad, grown by a pixel so neighbours overlap instead of showing a hairline.
|
||||
Vector2 tl = proj.Project(left, topCell), tr = proj.Project(right, topCell), br = proj.Project(right, bottomCell), bl = proj.Project(left, bottomCell);
|
||||
Vector2 mid = (tl + br) * 0.5f;
|
||||
tl = Grow(tl, mid); tr = Grow(tr, mid); br = Grow(br, mid); bl = Grow(bl, mid);
|
||||
dl.AddImageQuad(tex, tl, tr, br, bl, new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One tile inside a circle: whole when it is, skipped when none of it is, else cut to the circle.</summary>
|
||||
private static unsafe void DrawRound(ImDrawListPtr dl, IntPtr tex, in RoundMask mask, in MapProjection proj,
|
||||
double left, double right, double topCell, double bottomCell, uint tint)
|
||||
{
|
||||
Span<Vector2> q = stackalloc Vector2[4];
|
||||
q[0] = proj.Project(left, topCell); q[1] = proj.Project(right, topCell);
|
||||
q[2] = proj.Project(right, bottomCell); q[3] = proj.Project(left, bottomCell);
|
||||
Vector2 mid = (q[0] + q[2]) * 0.5f;
|
||||
for (int i = 0; i < 4; i++) q[i] = Grow(q[i], mid); // a pixel of overlap, as the other path
|
||||
Vector2 min = Vector2.Min(Vector2.Min(q[0], q[1]), Vector2.Min(q[2], q[3]));
|
||||
Vector2 max = Vector2.Max(Vector2.Max(q[0], q[1]), Vector2.Max(q[2], q[3]));
|
||||
if (!mask.OverlapsBox(min, max)) return;
|
||||
Span<Vector2> uv = stackalloc Vector2[4];
|
||||
uv[0] = new Vector2(0, 0); uv[1] = new Vector2(1, 0); uv[2] = new Vector2(1, 1); uv[3] = new Vector2(0, 1);
|
||||
if (mask.ContainsBox(min, max))
|
||||
{
|
||||
dl.AddImageQuad(tex, q[0], q[1], q[2], q[3], uv[0], uv[1], uv[2], uv[3], tint);
|
||||
return;
|
||||
}
|
||||
Span<Vector2> p = stackalloc Vector2[CircleClip.MaxPoints], t = stackalloc Vector2[CircleClip.MaxPoints];
|
||||
int n = CircleClip.Polygon(mask, q, uv, p, t);
|
||||
if (n < 3) return;
|
||||
// A textured fan, written by hand (ImGui has no textured polygon call).
|
||||
dl.PushTextureID(tex);
|
||||
dl.PrimReserve((n - 2) * 3, n);
|
||||
uint first = dl.NativePtr->_VtxCurrentIdx;
|
||||
for (int i = 0; i < n; i++) dl.PrimWriteVtx(p[i], t[i], tint);
|
||||
for (int i = 1; i < n - 1; i++)
|
||||
{
|
||||
dl.PrimWriteIdx((ushort)first);
|
||||
dl.PrimWriteIdx((ushort)(first + (uint)i));
|
||||
dl.PrimWriteIdx((ushort)(first + (uint)i + 1));
|
||||
}
|
||||
dl.PopTextureID();
|
||||
}
|
||||
|
||||
private static Vector2 Grow(Vector2 p, Vector2 mid)
|
||||
{
|
||||
Vector2 d = p - mid;
|
||||
float len = d.Length();
|
||||
return len < 1f ? p : p + d / len * 0.8f;
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +125,6 @@ internal sealed class WorldMapView
|
|||
private readonly List<(Vector2 Min, Vector2 Max)> _labelRects = new(128);
|
||||
private readonly List<(Vector2 Pos, int Index)> _drawn = new(256);
|
||||
private readonly List<(Vector2 Pos, int Index)> _drawnChars = new(16);
|
||||
private readonly List<(int Dist, int Col, int Row)> _tileOrder = new(128);
|
||||
private CharacterRow[] _chars = Array.Empty<CharacterRow>();
|
||||
|
||||
public WorldMapView(bool mini)
|
||||
|
|
@ -239,86 +238,11 @@ internal sealed class WorldMapView
|
|||
DrawContextMenu();
|
||||
}
|
||||
|
||||
// ── Tiles ────────────────────────────────────────────────────────────
|
||||
private void DrawTiles(ImDrawListPtr dl, Vector2 canvasMin, Vector2 canvasMax)
|
||||
{
|
||||
var levels = WorldMapTiles.Levels;
|
||||
if (!WorldMapTiles.IsOpen || levels.Count == 0) return;
|
||||
int ppc0 = WorldMapTiles.PixelsPerCell, top = levels.Count - 1;
|
||||
double cellsHigh = WorldMapTiles.CellsHigh;
|
||||
// The map area in view: the canvas as it is, or (turned) the circle around it.
|
||||
double halfW = (canvasMax.X - canvasMin.X) * 0.5, halfH = (canvasMax.Y - canvasMin.Y) * 0.5;
|
||||
if (_phi != 0f) { halfW = halfH = Math.Sqrt(halfW * halfW + halfH * halfH); }
|
||||
double cxMin = _ccx - halfW / _scale, cxMax = _ccx + halfW / _scale;
|
||||
double cyMin = _ccy - halfH / _scale, cyMax = _ccy + halfH / _scale;
|
||||
// ── Tiles (WorldMapTileDrawer, shared with the Radar's world map backdrop) ──
|
||||
private readonly WorldMapTileDrawer _tiles = new();
|
||||
|
||||
// The sharpest level whose pixels are at least as dense as the screen's; a coarser one if that is too many tiles.
|
||||
int L = Math.Clamp((int)Math.Floor(Math.Log2(ppc0 / (double)_scale)), 0, top);
|
||||
while (L < top && VisibleTiles(L, ppc0, cellsHigh, cxMin, cxMax, cyMin, cyMax) > 80) L++;
|
||||
|
||||
// Coarse to fine: the top level (always loaded) first, so whatever hasn't arrived shows blurry, not blank.
|
||||
for (int lv = top; lv >= L; lv--)
|
||||
DrawLevel(dl, lv, ppc0, cellsHigh, cxMin, cxMax, cyMin, cyMax, request: lv <= Math.Min(top, L + 1));
|
||||
}
|
||||
|
||||
private static int VisibleTiles(int lv, int ppc0, double cellsHigh, double cxMin, double cxMax, double cyMin, double cyMax)
|
||||
{
|
||||
double cpt = WorldMapTiles.TileSize * (double)(1 << lv) / ppc0;
|
||||
int cols = (int)Math.Floor(Math.Min(cxMax, WorldMapTiles.CellsWide) / cpt) - (int)Math.Floor(Math.Max(cxMin, 0) / cpt) + 1;
|
||||
int rows = (int)Math.Floor((cellsHigh - Math.Max(cyMin, 0)) / cpt) - (int)Math.Floor((cellsHigh - Math.Min(cyMax, cellsHigh)) / cpt) + 1;
|
||||
return Math.Max(cols, 0) * Math.Max(rows, 0);
|
||||
}
|
||||
|
||||
private void DrawLevel(ImDrawListPtr dl, int lv, int ppc0, double cellsHigh, double cxMin, double cxMax, double cyMin, double cyMax, bool request)
|
||||
{
|
||||
var lvl = WorldMapTiles.Levels[lv];
|
||||
double cpt = WorldMapTiles.TileSize * (double)(1 << lv) / ppc0;
|
||||
int c0 = Math.Max(0, (int)Math.Floor(cxMin / cpt)), c1 = Math.Min(lvl.Cols - 1, (int)Math.Floor(cxMax / cpt));
|
||||
int r0 = Math.Max(0, (int)Math.Floor((cellsHigh - cyMax) / cpt)), r1 = Math.Min(lvl.Rows - 1, (int)Math.Floor((cellsHigh - cyMin) / cpt));
|
||||
if (c1 < c0 || r1 < r0) return;
|
||||
|
||||
// Centre-out, so the tiles you're looking at load first.
|
||||
_tileOrder.Clear();
|
||||
double ccol = _ccx / cpt, crow = (cellsHigh - _ccy) / cpt;
|
||||
for (int r = r0; r <= r1; r++)
|
||||
for (int c = c0; c <= c1; c++)
|
||||
{
|
||||
double dx = c + 0.5 - ccol, dy = r + 0.5 - crow;
|
||||
_tileOrder.Add(((int)((dx * dx + dy * dy) * 1000), c, r));
|
||||
}
|
||||
_tileOrder.Sort(static (a, b) => a.Dist.CompareTo(b.Dist));
|
||||
|
||||
bool turned = _phi != 0f;
|
||||
for (int i = _tileOrder.Count - 1; i >= 0; i--) // draw far to near; nothing overlaps within a level
|
||||
{
|
||||
var (_, c, r) = _tileOrder[i];
|
||||
IntPtr tex;
|
||||
if (!(request ? WorldMapTiles.TryGet(lv, c, r, out tex) : WorldMapTiles.Peek(lv, c, r, out tex))) continue;
|
||||
double left = c * cpt, right = (c + 1) * cpt, topCell = cellsHigh - r * cpt, bottomCell = cellsHigh - (r + 1) * cpt;
|
||||
if (!turned)
|
||||
{
|
||||
// Edges from the same formula for both neighbours, rounded to whole pixels: no seams, no gaps.
|
||||
float x0 = MathF.Round(_centre.X + (float)((left - _ccx) * _scale)), x1 = MathF.Round(_centre.X + (float)((right - _ccx) * _scale));
|
||||
float y0 = MathF.Round(_centre.Y - (float)((topCell - _ccy) * _scale)), y1 = MathF.Round(_centre.Y - (float)((bottomCell - _ccy) * _scale));
|
||||
dl.AddImage(tex, new Vector2(x0, y0), new Vector2(x1, y1));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Turned: a quad, grown by a pixel so neighbours overlap instead of showing a hairline.
|
||||
Vector2 tl = Project(left, topCell), tr = Project(right, topCell), br = Project(right, bottomCell), bl = Project(left, bottomCell);
|
||||
Vector2 mid = (tl + br) * 0.5f;
|
||||
tl = Grow(tl, mid); tr = Grow(tr, mid); br = Grow(br, mid); bl = Grow(bl, mid);
|
||||
dl.AddImageQuad(tex, tl, tr, br, bl, new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector2 Grow(Vector2 p, Vector2 mid)
|
||||
{
|
||||
Vector2 d = p - mid;
|
||||
float len = d.Length();
|
||||
return len < 1f ? p : p + d / len * 0.8f;
|
||||
}
|
||||
private void DrawTiles(ImDrawListPtr dl, Vector2 canvasMin, Vector2 canvasMax) =>
|
||||
_tiles.Draw(dl, canvasMin, canvasMax, _centre, _ccx, _ccy, _scale, _phi);
|
||||
|
||||
// ── Grid ─────────────────────────────────────────────────────────────
|
||||
private void DrawGrid(ImDrawListPtr dl, Vector2 canvasMin, Vector2 canvasMax, bool turned)
|
||||
|
|
|
|||
|
|
@ -414,11 +414,12 @@ internal static class EngineSettings
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>"MaxHotReloads" in engine.json (default 3, 2026-10-11): how many engine hot reloads
|
||||
/// one client takes; the loader asks before each one (RynthCoreMaxHotReloads) and refuses the
|
||||
/// rest, so a newer engine then needs a client restart. Clients died with CoreCLR fatal error
|
||||
/// 0x80131506 after 4+ reloads in one process. Negative = no cap (test clients soaking
|
||||
/// reloads), 0 = no hot reloads at all. Read at each engine init; edited in the file.</summary>
|
||||
/// <summary>"MaxHotReloads" in engine.json (default 20 since 2026-10-15; 3 from 10-11): how many
|
||||
/// engine hot reloads one client takes; the loader asks before each one (RynthCoreMaxHotReloads)
|
||||
/// and refuses the rest, so a newer engine then needs a client restart. A backstop: the 0x80131506
|
||||
/// deaths after 4+ reloads that set it at 3 were the v1 crash logger (fixed 10-12). Negative = no
|
||||
/// cap (test clients soaking reloads), 0 = no hot reloads at all. Read at each engine init; edited
|
||||
/// in the file.</summary>
|
||||
public static int MaxHotReloads
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -6,14 +6,16 @@ namespace RynthCore.Engine;
|
|||
/// the reload once this client has done that many; the client keeps running on the current engine
|
||||
/// and the loader tells the engine (RynthCoreReloadCapped), which logs it and says so in chat: once
|
||||
/// on its own, and again whenever the player asks for a reload by hand (RL, /rc rl), so a button
|
||||
/// press never goes unanswered. Clients died with CoreCLR fatal error 0x80131506 after 4+ engine
|
||||
/// reloads in one process. No engine state here: tools/ReloadCapTests compiles this file in.
|
||||
/// press never goes unanswered. The cap was 3 after clients died with CoreCLR fatal error
|
||||
/// 0x80131506 after 4+ reloads (2026-10-08..10); those were the v1 SehTrampoline crash logger
|
||||
/// (fixed 10-12), so since 2026-10-15 it is 20, a backstop. No engine state here:
|
||||
/// tools/ReloadCapTests compiles this file in.
|
||||
/// </summary>
|
||||
internal sealed class ReloadCapNotice
|
||||
{
|
||||
/// <summary>engine.json MaxHotReloads when the file doesn't set it (and the loader's own
|
||||
/// default for an engine without the export, DEFAULT_MAX_HOT_RELOADS in Loader.c).</summary>
|
||||
public const int DefaultMaxHotReloads = 3;
|
||||
public const int DefaultMaxHotReloads = 20;
|
||||
|
||||
/// <summary>How recent the engine's own reload signal must be to count as "asked by hand".</summary>
|
||||
public const long ManualWindowMs = 10_000;
|
||||
|
|
|
|||
|
|
@ -111,6 +111,9 @@ internal sealed class RynthNavStatus
|
|||
// Path markers and "save as nav route" (RynthNav 0.6.6+; HasMarkers / HasSave false on older plugins).
|
||||
public bool HasMarkers, MarkersOn, MarkerLabels, MarkerGuide, MarkersShown;
|
||||
public string MarkerStatus = "";
|
||||
// The navmesh drawn in the world (/rnav mesh; RynthNav 0.6.7+ status "mesh"; HasMesh false on older plugins).
|
||||
public bool HasMesh, MeshOn, MeshFloor, MeshWalls;
|
||||
public int MeshRadius = 40, MeshTriangles = 3000, MeshDrawn;
|
||||
public bool HasSave, CanSave, SaveBusy;
|
||||
public string SaveFor = "", SaveName = "", SaveConflict = "", SaveLast = "";
|
||||
public bool HasTies;
|
||||
|
|
@ -307,6 +310,16 @@ internal sealed class RynthNavStatus
|
|||
}
|
||||
s.PathSegments = segs.ToArray();
|
||||
}
|
||||
if (r.TryGetProperty("mesh", out var ms) && ms.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
s.HasMesh = true;
|
||||
s.MeshOn = Int(ms, "on") != 0;
|
||||
s.MeshFloor = Int(ms, "floor", 1) != 0;
|
||||
s.MeshWalls = Int(ms, "walls", 1) != 0;
|
||||
s.MeshRadius = Int(ms, "radius", 40);
|
||||
s.MeshTriangles = Int(ms, "triangles", 3000);
|
||||
s.MeshDrawn = Int(ms, "drawn");
|
||||
}
|
||||
if (r.TryGetProperty("save", out var sv) && sv.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
s.HasSave = true;
|
||||
|
|
|
|||
|
|
@ -170,6 +170,8 @@ internal sealed class RynthAiSettings
|
|||
public float DunPatrolSightYd { get; set; } = 20f; // sweep: how far a monster notices you (lane spacing)
|
||||
public bool OpenDoors { get; set; }
|
||||
public float OpenDoorRange { get; set; } = 5f;
|
||||
// RynthAi OpenDoorsOnPathOnly: Open Doors opens only a closed door on the path of travel. An older plugin ignores it.
|
||||
public bool OpenDoorsOnPathOnly { get; set; }
|
||||
public bool AutoUnlockDoors { get; set; }
|
||||
public int MovementMode { get; set; }
|
||||
public float NavStopTurnAngle { get; set; } = 20f;
|
||||
|
|
@ -941,6 +943,8 @@ internal static class SettingsSchema
|
|||
Bool("Open Doors While Navigating", s => s.OpenDoors, (s, v) => s.OpenDoors = v,
|
||||
"Automatically open doors encountered during navigation.", gates: true),
|
||||
Float("Door Detection Range (yd)", s => s.OpenDoorRange, (s, v) => s.OpenDoorRange = v, 0.1f, 70f, 1f, when: s => s.OpenDoors),
|
||||
Bool("Only Doors On My Path", s => s.OpenDoorsOnPathOnly, (s, v) => s.OpenDoorsOnPathOnly = v,
|
||||
"Open only a closed door that is on the way: within the range along the route's next legs (or straight ahead when not on a route).\nOff: every closed door within the range is opened.", when: s => s.OpenDoors),
|
||||
Bool("Auto-Unlock Doors", s => s.AutoUnlockDoors, (s, v) => s.AutoUnlockDoors = v,
|
||||
"If a door is locked, try to use a lockpick from your Consumable Items list.", when: s => s.OpenDoors),
|
||||
Spacer(),
|
||||
|
|
|
|||
114
src/RynthCore.Engine/UI/Panels/MarkerStyleSettings.cs
Normal file
114
src/RynthCore.Engine/UI/Panels/MarkerStyleSettings.cs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - UI/Panels/MarkerStyleSettings.cs
|
||||
// Per-kind marker size, name label and name size, for one map surface. The Radar
|
||||
// and the Dungeon Map each own one (RadarSettingsStore.Markers /
|
||||
// DungeonMapSettingsStore.Markers), so a name that suits the big map can stay off
|
||||
// the small radar. No ImGui here: tools/RadarSettingsTests compiles this file.
|
||||
//
|
||||
// Size marker scale per RadarKind (1 = the surface's normal size)
|
||||
// ShowName draw the object's name (the marker's label) beside the marker
|
||||
// NameSize that name's text size, in pixels at 100% UI scale
|
||||
// SelfSize your own dot and heading arrow
|
||||
//
|
||||
// Settings-file keys (written only when they differ from the defaults, so a later
|
||||
// default change still lands): size.<kind>, name.<kind>, nameSize.<kind>, size.self,
|
||||
// where <kind> is the kind's key (monster, npc, portal, door, player, ...).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using RynthCore.Engine.UI.Data;
|
||||
|
||||
namespace RynthCore.Engine.UI.Panels;
|
||||
|
||||
internal sealed class MarkerStyleSettings
|
||||
{
|
||||
public const float MinSize = 0.5f, MaxSize = 3.0f, DefaultSize = 1.0f;
|
||||
public const float MinName = 7f, MaxName = 24f, DefaultName = 11f;
|
||||
|
||||
/// <summary>Settings-file key per <see cref="RadarKind"/>.</summary>
|
||||
public static readonly string[] Keys =
|
||||
{
|
||||
"monster", "npc", "portal", "door", "player", "fellow",
|
||||
"pet", "vendor", "corpse", "ownCorpse", "lifestone", "groundItem",
|
||||
};
|
||||
|
||||
/// <summary>Marker scale per kind.</summary>
|
||||
public readonly float[] Size = new float[RadarKind.Count];
|
||||
/// <summary>Whether a kind's name is drawn.</summary>
|
||||
public readonly bool[] ShowName = new bool[RadarKind.Count];
|
||||
/// <summary>Name text size per kind (px at 100% UI scale).</summary>
|
||||
public readonly float[] NameSize = new float[RadarKind.Count];
|
||||
/// <summary>Scale of your own dot and heading arrow.</summary>
|
||||
public float SelfSize = DefaultSize;
|
||||
|
||||
private readonly bool[] _defaultNames;
|
||||
|
||||
/// <param name="defaultNames">Which kinds show their name until the user says otherwise (length RadarKind.Count).</param>
|
||||
public MarkerStyleSettings(bool[] defaultNames)
|
||||
{
|
||||
if (defaultNames.Length != RadarKind.Count) throw new ArgumentException("one flag per RadarKind", nameof(defaultNames));
|
||||
_defaultNames = (bool[])defaultNames.Clone();
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>Every size and name box back to its default.</summary>
|
||||
public void Reset()
|
||||
{
|
||||
for (int k = 0; k < RadarKind.Count; k++)
|
||||
{
|
||||
Size[k] = DefaultSize;
|
||||
ShowName[k] = _defaultNames[k];
|
||||
NameSize[k] = DefaultName;
|
||||
}
|
||||
SelfSize = DefaultSize;
|
||||
}
|
||||
|
||||
public bool NameShown(byte kind) => kind < RadarKind.Count && ShowName[kind];
|
||||
|
||||
/// <summary>Marker scale of a kind; 1 for a kind this engine doesn't know.</summary>
|
||||
public float SizeOf(byte kind) => kind < RadarKind.Count ? Size[kind] : DefaultSize;
|
||||
|
||||
/// <summary>Name size of a kind (px at 100% UI scale).</summary>
|
||||
public float NameSizeOf(byte kind) => kind < RadarKind.Count ? NameSize[kind] : DefaultName;
|
||||
|
||||
/// <summary>Takes a settings-file line if its key is one of ours. True when it was.</summary>
|
||||
public bool TryLoad(string key, string val)
|
||||
{
|
||||
int dot = key.IndexOf('.');
|
||||
if (dot <= 0) return false;
|
||||
string head = key[..dot], tail = key[(dot + 1)..];
|
||||
if (head != "size" && head != "name" && head != "nameSize") return false;
|
||||
|
||||
if (head == "size" && tail == "self")
|
||||
{
|
||||
if (TryFloat(val, out float self)) SelfSize = Math.Clamp(self, MinSize, MaxSize);
|
||||
return true;
|
||||
}
|
||||
int k = Array.IndexOf(Keys, tail);
|
||||
if (k < 0) return false;
|
||||
switch (head)
|
||||
{
|
||||
case "size": if (TryFloat(val, out float s)) Size[k] = Math.Clamp(s, MinSize, MaxSize); break;
|
||||
case "name": ShowName[k] = val == "1"; break;
|
||||
case "nameSize": if (TryFloat(val, out float n)) NameSize[k] = Math.Clamp(n, MinName, MaxName); break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The settings-file lines for everything that differs from the defaults.</summary>
|
||||
public void AppendLines(List<string> lines)
|
||||
{
|
||||
for (int k = 0; k < RadarKind.Count; k++)
|
||||
{
|
||||
if (Size[k] != DefaultSize) lines.Add(FormattableString.Invariant($"size.{Keys[k]}={Size[k]:0.##}"));
|
||||
if (ShowName[k] != _defaultNames[k]) lines.Add($"name.{Keys[k]}={(ShowName[k] ? "1" : "0")}");
|
||||
if (NameSize[k] != DefaultName) lines.Add(FormattableString.Invariant($"nameSize.{Keys[k]}={NameSize[k]:0.##}"));
|
||||
}
|
||||
if (SelfSize != DefaultSize) lines.Add(FormattableString.Invariant($"size.self={SelfSize:0.##}"));
|
||||
}
|
||||
|
||||
private static bool TryFloat(string val, out float f) =>
|
||||
float.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out f) && float.IsFinite(f);
|
||||
}
|
||||
|
|
@ -27,6 +27,8 @@ internal static class RadarSettingsStore
|
|||
public static float Opacity = 1.0f;
|
||||
public static bool RotateWithPlayer;
|
||||
public static bool ShowGoldRim = true;
|
||||
/// <summary>ImGui face: a round radar (everything cut to a circle) instead of the square one.</summary>
|
||||
public static bool RoundRadar;
|
||||
public static bool CtrlGatedClickThrough = false;
|
||||
public static bool ShowMonsters = true;
|
||||
public static bool ShowNpcs = true;
|
||||
|
|
@ -44,6 +46,37 @@ internal static class RadarSettingsStore
|
|||
/// <summary>ImGui face: a left-click on a dot selects that object in game.</summary>
|
||||
public static bool ClickToSelect = true;
|
||||
|
||||
/// <summary>ImGui face: the World Map's picture drawn behind the radar while you're outdoors (off by default).</summary>
|
||||
public static bool ShowWorldMap;
|
||||
/// <summary>How strongly that picture shows (the radar's own Opacity applies on top).</summary>
|
||||
public static float WorldMapOpacity = 0.8f;
|
||||
|
||||
// Text sizes of the compass letters and the coordinate strip (px at 100% UI scale).
|
||||
public const float DefaultCompassSize = 14f, DefaultCoordSize = 11f, MinText = 8f, MaxText = 28f;
|
||||
public static float CompassSize = DefaultCompassSize;
|
||||
public static float CoordSize = DefaultCoordSize;
|
||||
|
||||
/// <summary>
|
||||
/// Per-kind marker size and name label (added 2026-10-15). Names start on for the kinds you
|
||||
/// look for by name - monsters, NPCs, vendors, players, fellows, portals - and off for the
|
||||
/// rest, which would only add clutter.
|
||||
/// </summary>
|
||||
public static readonly MarkerStyleSettings Markers = new(new[]
|
||||
{
|
||||
true, // monster
|
||||
true, // NPC
|
||||
true, // portal
|
||||
false, // door
|
||||
true, // player
|
||||
true, // fellow
|
||||
false, // your pet
|
||||
true, // vendor
|
||||
false, // corpse
|
||||
false, // your corpse
|
||||
false, // lifestone
|
||||
false, // item on the ground
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Default marker colour per <see cref="RadarKind"/> (ARGB). Chosen to stay apart for
|
||||
/// red-green colour blindness as well: the kinds that share a hue family also differ
|
||||
|
|
@ -69,11 +102,7 @@ internal static class RadarSettingsStore
|
|||
public static readonly uint[] KindColors = (uint[])DefaultKindColors.Clone();
|
||||
|
||||
// Settings-file keys per kind (color.<key>=AARRGGBB).
|
||||
private static readonly string[] KindKeys =
|
||||
{
|
||||
"monster", "npc", "portal", "door", "player", "fellow",
|
||||
"pet", "vendor", "corpse", "ownCorpse", "lifestone", "groundItem",
|
||||
};
|
||||
private static readonly string[] KindKeys = MarkerStyleSettings.Keys;
|
||||
|
||||
/// <summary>The show/hide flag of a kind (the radar's per-kind check boxes).</summary>
|
||||
public static ref bool ShowFlag(byte kind)
|
||||
|
|
@ -106,6 +135,14 @@ internal static class RadarSettingsStore
|
|||
|
||||
public static void ResetKindColors() => Array.Copy(DefaultKindColors, KindColors, KindColors.Length);
|
||||
|
||||
/// <summary>Every marker size, name box and text size back to its default (show boxes and colours stay).</summary>
|
||||
public static void ResetSizes()
|
||||
{
|
||||
Markers.Reset();
|
||||
CompassSize = DefaultCompassSize;
|
||||
CoordSize = DefaultCoordSize;
|
||||
}
|
||||
|
||||
// RYNTHCORE_RADAR_SETTINGS points a test at its own file instead of the real one.
|
||||
private static string FilePath
|
||||
{
|
||||
|
|
@ -148,6 +185,7 @@ internal static class RadarSettingsStore
|
|||
break;
|
||||
case "rotate": RotateWithPlayer = val == "1"; break;
|
||||
case "showGoldRim": ShowGoldRim = val == "1"; break;
|
||||
case "round": RoundRadar = val == "1"; break;
|
||||
case "ctrlClickThrough": CtrlGatedClickThrough = val == "1"; break;
|
||||
case "showMonsters": ShowMonsters = val == "1"; break;
|
||||
case "showNpcs": ShowNpcs = val == "1"; break;
|
||||
|
|
@ -162,7 +200,21 @@ internal static class RadarSettingsStore
|
|||
case "showLifestones": ShowLifestones = val == "1"; break;
|
||||
case "showGroundItems": ShowGroundItems = val == "1"; break;
|
||||
case "clickSelect": ClickToSelect = val == "1"; break;
|
||||
case "worldMap": ShowWorldMap = val == "1"; break;
|
||||
case "worldMapOpacity":
|
||||
if (float.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out float wo) && float.IsFinite(wo))
|
||||
WorldMapOpacity = Math.Clamp(wo, 0.1f, 1.0f);
|
||||
break;
|
||||
case "compassSize":
|
||||
if (float.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out float cs) && float.IsFinite(cs))
|
||||
CompassSize = Math.Clamp(cs, MinText, MaxText);
|
||||
break;
|
||||
case "coordSize":
|
||||
if (float.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out float ds) && float.IsFinite(ds))
|
||||
CoordSize = Math.Clamp(ds, MinText, MaxText);
|
||||
break;
|
||||
default:
|
||||
if (Markers.TryLoad(key, val)) break;
|
||||
if (key.StartsWith("color.", StringComparison.Ordinal))
|
||||
{
|
||||
int k = Array.IndexOf(KindKeys, key["color.".Length..]);
|
||||
|
|
@ -195,6 +247,7 @@ internal static class RadarSettingsStore
|
|||
sw.WriteLine(FormattableString.Invariant($"opacity={Opacity:0.##}"));
|
||||
sw.WriteLine($"rotate={(RotateWithPlayer ? "1" : "0")}");
|
||||
sw.WriteLine($"showGoldRim={(ShowGoldRim ? "1" : "0")}");
|
||||
sw.WriteLine($"round={(RoundRadar ? "1" : "0")}");
|
||||
sw.WriteLine($"ctrlClickThrough={(CtrlGatedClickThrough ? "1" : "0")}");
|
||||
sw.WriteLine($"showMonsters={(ShowMonsters ? "1" : "0")}");
|
||||
sw.WriteLine($"showNpcs={(ShowNpcs ? "1" : "0")}");
|
||||
|
|
@ -209,6 +262,13 @@ internal static class RadarSettingsStore
|
|||
sw.WriteLine($"showLifestones={(ShowLifestones ? "1" : "0")}");
|
||||
sw.WriteLine($"showGroundItems={(ShowGroundItems ? "1" : "0")}");
|
||||
sw.WriteLine($"clickSelect={(ClickToSelect ? "1" : "0")}");
|
||||
sw.WriteLine($"worldMap={(ShowWorldMap ? "1" : "0")}");
|
||||
sw.WriteLine(FormattableString.Invariant($"worldMapOpacity={WorldMapOpacity:0.##}"));
|
||||
sw.WriteLine(FormattableString.Invariant($"compassSize={CompassSize:0.##}"));
|
||||
sw.WriteLine(FormattableString.Invariant($"coordSize={CoordSize:0.##}"));
|
||||
var styleLines = new System.Collections.Generic.List<string>();
|
||||
Markers.AppendLines(styleLines);
|
||||
foreach (string line in styleLines) sw.WriteLine(line);
|
||||
// Only colours that differ from the default, so a later default change still lands.
|
||||
for (int k = 0; k < KindColors.Length; k++)
|
||||
if (KindColors[k] != DefaultKindColors[k])
|
||||
|
|
|
|||
Loading…
Reference in a new issue