Snapshot for release 2026.10.15.6 (internal 6fd9478)

This commit is contained in:
Tom Bohar 2026-10-15 23:44:38 -04:00
commit a57049d931
44 changed files with 12244 additions and 10674 deletions

View file

@ -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;

View 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;
}
}

View file

@ -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;

View file

@ -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)

View 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();
}
}

View file

@ -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;
}

View file

@ -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)
{

View file

@ -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;

View file

@ -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];

View 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;
}
}

View file

@ -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)