Snapshot for release 2026.10.11.1 (internal 4eca83a)

This commit is contained in:
Tom Bohar 2026-10-11 15:00:53 -04:00
commit 08b80eed86
94 changed files with 11103 additions and 567 deletions

View file

@ -8,11 +8,17 @@
// an unknown panel shows its first letter), reload (RL) and pop out.
// Dragging the grip moves the bar; the position is the shared bar= row in
// panel_state.txt. Right-click a panel button (or the grip for the bar
// itself) to choose which face shows it docked. Pop out moves the ImGui bar
// itself) to choose which face shows it docked; the grip's menu also has the
// bar's size and "Report a problem". Pop out moves the ImGui bar
// into its own window (ImGuiPopOuts, sized to its content; dock back
// returns it); a bar whose face is Avalonia/Both still pops out as the
// Avalonia bar.
//
// The bar's size is its own text size step (PanelTextScale chrome row): the bar's
// fonts come from that baked set and its metrics scale by the step's factor. Set it
// from the grip's right-click menu, Ctrl+wheel over the bar, Settings > Display or
// /rc ui barsize.
//
// Face key "__bar" in panel_faces.txt; code default Avalonia. While the ImGui
// bar shows, the docked Avalonia bar is hidden and takes no clicks
// (AvaloniaOverlay.DockedBarSuppressed). AC thread except where noted.
@ -23,6 +29,7 @@ using System.Collections.Generic;
using System.Numerics;
using System.Threading;
using ImGuiNET;
using RynthCore.Engine.Compatibility;
using RynthCore.Engine.UI;
using RynthCore.Engine.UI.ScriptWindows;
@ -48,6 +55,11 @@ internal static class ImGuiBar
private static readonly string[] ImGuiOnlyBarPanels =
{ Panels.InventoryFace.Title, Panels.SkillsFace.Title, Panels.SenseFace.Title, Panels.ItemCountFace.Title, Panels.MiniRemoteFace.Title };
// The ILT section: the RynthILT plugin's ImGui-only panels. They never get buttons of their
// own; one ILT button stands for them, shown only on Infinite Leaftide (IltInfo.IsIlt) and
// only for the ones registered (EntryPoint registers them when RynthILT is installed).
private static readonly string[] IltPanels = { Panels.BountiesFace.Title };
// Known panels' icons (DrakBot's where the same window exists); others show their first letter.
private static readonly Dictionary<string, string> PanelIcons = new(StringComparer.OrdinalIgnoreCase)
{
@ -87,10 +99,26 @@ internal static class ImGuiBar
// Square buttons, logical px (x the DPI scale).
private const float ButtonSize = 20f, ButtonGap = 3f;
/// <summary>
/// The bar's text size step (the nearest one already baked) and its scale factor. The one
/// place either is worked out, so the bar's fonts and its metrics always agree.
/// </summary>
private static int ChromeStep(out float factor)
{
int step = ImGuiFonts.BakedStepNear(PanelTextScale.GetChrome());
factor = PanelTextScale.Factor(step);
return step;
}
private static ButtonInfo[]? _buttons;
private static string _tooltip = "";
private static bool _placed;
private static Vector2 _pos, _persistedPos;
// What may write a new position to the bar= row: the user dragging the grip, or the bar being
// pulled back on screen by a size change (a few frames: the window grows a frame late). A clamp
// from a smaller AC window leaves the saved position alone.
private static bool _userMoved;
private static int _lastStep, _sizeWatch;
private const string PopOutTitle = "__bar";
// Popped out (the ImGui bar in its own window). Read from panel_state once,
@ -173,12 +201,15 @@ internal static class ImGuiBar
private static void DrawPopped(float s, Vector2 display)
{
EnsureButtons();
int step = ChromeStep(out float factor);
s *= factor;
float place = AvaloniaOverlay.InputScale > 0 ? AvaloniaOverlay.InputScale : 1f;
ImGuiNET.ImGui.SetNextWindowPos(ImGuiPopOuts.PanelOrigin, ImGuiCond.Always);
PushBarWindowStyle(s);
ImGuiNET.ImGui.Begin("##rc_bar", BarFlags);
try
{
ImGuiFonts.CurrentStep = step;
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui11));
DrawContent(s, place, popped: true);
ImGuiNET.ImGui.PopFont();
@ -189,6 +220,7 @@ internal static class ImGuiBar
}
finally
{
ImGuiFonts.CurrentStep = 0;
ImGuiNET.ImGui.End();
PopBarWindowStyle();
}
@ -218,6 +250,8 @@ internal static class ImGuiBar
public static void Draw(float s)
{
EnsureButtons();
int step = ChromeStep(out float factor);
s *= factor;
float place = AvaloniaOverlay.InputScale > 0 ? AvaloniaOverlay.InputScale : 1f;
bool both = ResolveFace() == PanelFace.Both;
@ -229,18 +263,23 @@ internal static class ImGuiBar
_pos = _persistedPos = logical * place;
ImGuiNET.ImGui.SetNextWindowPos(_pos, ImGuiCond.Always);
_placed = true;
_lastStep = step; // the size the bar loads at is the baseline, not a change
}
if (step != _lastStep) { _lastStep = step; _sizeWatch = 4; }
PushBarWindowStyle(s);
ImGuiNET.ImGui.Begin("##rc_bar", BarFlags);
try
{
ImGuiFonts.CurrentStep = step;
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui11));
DrawContent(s, place, popped: false);
ImGuiNET.ImGui.PopFont();
KeepOnScreen();
}
finally
{
ImGuiFonts.CurrentStep = 0;
_pos = ImGuiNET.ImGui.GetWindowPos();
ImGuiNET.ImGui.End();
PopBarWindowStyle();
@ -249,15 +288,35 @@ internal static class ImGuiBar
if (!ImGuiNET.ImGui.IsMouseDown(ImGuiMouseButton.Left) && _pos != _persistedPos)
{
_persistedPos = _pos;
Vector2 logical = _pos / place - (both ? new Vector2(24, 24) : Vector2.Zero);
double left = logical.X, top = logical.Y;
UiBackgroundWriter.Enqueue("persist bar", () => PanelStateStore.SetBarPosition(left, top));
if (!both) AvaloniaOverlay.SyncDockedBarPosition(left, top);
if (_userMoved || _sizeWatch > 0)
{
Vector2 logical = _pos / place - (both ? new Vector2(24, 24) : Vector2.Zero);
double left = logical.X, top = logical.Y;
UiBackgroundWriter.Enqueue("persist bar", () => PanelStateStore.SetBarPosition(left, top));
if (!both) AvaloniaOverlay.SyncDockedBarPosition(left, top);
}
_userMoved = false;
}
if (_sizeWatch > 0) _sizeWatch--;
}
/// <summary>A bigger size can push the bar's right end off the screen: pull it back (not while it is being dragged).</summary>
private static void KeepOnScreen()
{
Vector2 display = ImGuiNET.ImGui.GetIO().DisplaySize;
if (display.X <= 1 || ImGuiNET.ImGui.IsMouseDown(ImGuiMouseButton.Left)) return;
Vector2 pos = ImGuiNET.ImGui.GetWindowPos();
Vector2 next = Vector2.Clamp(pos, Vector2.Zero, Vector2.Max(Vector2.Zero, display - ImGuiNET.ImGui.GetWindowSize()));
if (next != pos) ImGuiNET.ImGui.SetWindowPos(next);
}
private static void DrawContent(float s, float place, bool popped)
{
// Ctrl+wheel over the bar steps its size (the panels' title bars do the same).
ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();
if (io.KeyCtrl && io.MouseWheel != 0f && ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenBlockedByActiveItem))
PanelTextScale.SetChrome(PanelTextScale.GetChrome() + (io.MouseWheel > 0f ? 1 : -1));
var square = new Vector2(ButtonSize, ButtonSize) * s;
var dl = ImGuiNET.ImGui.GetWindowDrawList();
ImFontPtr iconFont = ImGuiFonts.Get(UiFont.Ui14);
@ -280,12 +339,13 @@ internal static class ImGuiBar
if (display.X > 1)
next = Vector2.Clamp(next, Vector2.Zero, Vector2.Max(Vector2.Zero, display - size));
ImGuiNET.ImGui.SetWindowPos(next);
_userMoved = true;
}
ImGuiNET.ImGui.SetItemTooltip(_tooltip);
if (ImGuiNET.ImGui.IsItemClicked(ImGuiMouseButton.Right))
ImGuiNET.ImGui.OpenPopup("##face_bar");
PhosphorIcons.DrawCentered(dl, iconFont, PhosphorIcons.DotsSixVertical, rcPos, new Vector2(square.X * 0.8f, square.Y), RynthTheme.RcLabel);
FacePopup("##face_bar", FaceKey, hasImGuiFace: true);
FacePopup("##face_bar", FaceKey, hasImGuiFace: true, s);
// Collapse: the bar folds to its grip and this caret.
bool collapsed = RynthAiDashboardState.BarCollapsed;
@ -314,6 +374,21 @@ internal static class ImGuiBar
FacePopup(b.PopupId, b.Title, ImGuiPanelHost.HasFace(b.Title));
}
// The ILT section: one button, only on Infinite Leaftide with RynthILT's panels
// registered. With one panel it toggles that panel; with more it opens a menu.
int iltCount = IltPanelCount();
if (iltCount > 0)
{
ImGuiNET.ImGui.SameLine();
string? only = iltCount == 1 ? FirstIltPanel() : null;
if (IconButton("##ilt", iconFont, PhosphorIcons.Leaf, square, RynthTheme.BarText))
{
if (only != null) PanelRouter.Toggle(only);
else ImGuiNET.ImGui.OpenPopup("##ilt_menu");
}
ImGuiNET.ImGui.SetItemTooltip(only != null ? "Infinite Leaftide: " + only : "Infinite Leaftide");
}
// Script windows (decision 2): one button with a menu, only while a ShowInBar
// script window exists. They never get buttons of their own (EnsureButtons
// lists OverlayHost's engine panels only; script windows are dynamic entries).
@ -352,6 +427,44 @@ internal static class ImGuiBar
// Drawn after the bar buttons' style is popped, so the menu has the normal look.
ScriptsMenu(scripts);
IltMenu();
}
/// <summary>The ILT panels the bar offers now: 0 off Infinite Leaftide or without RynthILT. AC thread.</summary>
private static int IltPanelCount()
{
int n = 0;
foreach (string title in IltPanels)
if (ImGuiPanelHost.HasFace(title)) n++;
return n > 0 && IltInfo.IsIlt ? n : 0;
}
private static string? FirstIltPanel()
{
foreach (string title in IltPanels)
if (ImGuiPanelHost.HasFace(title)) return title;
return null;
}
/// <summary>The ILT button's menu (two or more ILT panels): a checkbox item each for open.</summary>
private static void IltMenu()
{
if (!ImGuiNET.ImGui.BeginPopup("##ilt_menu")) return;
try
{
ImGuiNET.ImGui.TextDisabled("Infinite Leaftide");
foreach (string title in IltPanels)
{
if (!ImGuiPanelHost.HasFace(title)) continue;
bool open = ImGuiPanelHost.IsOpen(title);
if (ImGuiNET.ImGui.MenuItem(title, "", open))
PanelRouter.Toggle(title);
}
}
finally
{
ImGuiNET.ImGui.EndPopup();
}
}
/// <summary>
@ -394,7 +507,7 @@ internal static class ImGuiBar
return clicked;
}
private static void FacePopup(string popupId, string title, bool hasImGuiFace)
private static void FacePopup(string popupId, string title, bool hasImGuiFace, float s = 1f)
{
if (!ImGuiNET.ImGui.BeginPopup(popupId)) return;
ImGuiNET.ImGui.TextDisabled(title == FaceKey ? "Bar, docked, shows as" : "Docked, shows as");
@ -407,9 +520,59 @@ internal static class ImGuiBar
}
if (!hasImGuiFace)
ImGuiNET.ImGui.TextDisabled("(no ImGui version yet)");
if (title == FaceKey)
{
BarSizeRows(s);
ReportRow();
}
ImGuiNET.ImGui.EndPopup();
}
/// <summary>The bar's own popup: smaller / bigger, the current size, reset (the panels' text size popup, for the bar).</summary>
private static void BarSizeRows(float s)
{
int step = PanelTextScale.GetChrome();
int max = PanelTextScale.SizeNames.Length - 1;
float btn = ButtonSize * s;
ImFontPtr iconFont = ImGuiFonts.Get(UiFont.Ui14);
uint text = ImGuiNET.ImGui.GetColorU32(ImGuiCol.Text);
ImGuiNET.ImGui.Separator();
ImGuiNET.ImGui.TextUnformatted("Bar size");
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
ImGuiNET.ImGui.BeginDisabled(step <= 0);
if (IconButton("##bs_smaller", iconFont, PhosphorIcons.Minus, new Vector2(btn, btn), text))
PanelTextScale.SetChrome(step - 1);
ImGuiNET.ImGui.EndDisabled();
ImGuiNET.ImGui.SetItemTooltip("Smaller");
ImGuiNET.ImGui.SameLine(0, 4 * s);
ImGuiNET.ImGui.BeginDisabled(step >= max);
if (IconButton("##bs_bigger", iconFont, PhosphorIcons.Plus, new Vector2(btn, btn), text))
PanelTextScale.SetChrome(step + 1);
ImGuiNET.ImGui.EndDisabled();
ImGuiNET.ImGui.SetItemTooltip("Bigger");
ImGuiNET.ImGui.PopStyleVar();
ImGuiNET.ImGui.SameLine(0, 8 * s);
ImGuiNET.ImGui.AlignTextToFramePadding();
ImGuiNET.ImGui.TextUnformatted(PanelTextScale.Describe(step));
ImGuiNET.ImGui.BeginDisabled(step == 0);
if (ImGuiNET.ImGui.Button(PhosphorIcons.ArrowCounterClockwise + " Reset"))
PanelTextScale.SetChrome(0);
ImGuiNET.ImGui.EndDisabled();
ImGuiNET.ImGui.SetItemTooltip("Back to normal size");
}
/// <summary>The grip menu's "Report a problem" entry (Report/ProblemReport.cs).</summary>
private static void ReportRow()
{
if (!ImGuiPanelHost.HasFace(Panels.ReportFace.Title)) return;
ImGuiNET.ImGui.Separator();
if (ImGuiNET.ImGui.MenuItem(PhosphorIcons.Warning + " Report a problem..."))
Report.ProblemReport.OpenPanel();
ImGuiNET.ImGui.SetItemTooltip("Tell the staff what went wrong (also /rc report).");
}
private static void PushBarButtonStyle(float s)
{
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
@ -446,6 +609,6 @@ internal static class ImGuiBar
list.Add(new ButtonInfo(title, "##bar_" + title, "##face_" + title, icon, letter, title, ImGuiOnly: true));
}
_buttons = list.ToArray();
_tooltip = $"RynthCore {EntryPoint.BuildStamp}\nDrag here to move the bar. Right-click: bar face.";
_tooltip = $"RynthCore {EntryPoint.BuildStamp}\nDrag here to move the bar. Right-click: bar face and size. Ctrl+wheel over the bar: size.";
}
}

View file

@ -0,0 +1,30 @@
// ============================================================================
// RynthCore.Engine - ImGui/MonsterHud/CreatureSizes.cs
// How tall each kind of creature is, for the plates that hang above its head.
//
// The table (CreatureSizes.g.cs) is generated by tools/CreatureSizes from the ACE world database and
// client_portal.dat: weenie class id -> model height x default scale, in centimetres. A creature that is
// not in it (a custom weenie that was not exported, a model with no height) is unknown, and the HUD
// falls back to its estimate by creature type and name. Pure code; tools/CreatureSizesTests compiles it in.
// ============================================================================
using System;
namespace RynthCore.Engine.ImGuiBackend.Hud;
internal static partial class CreatureSizes
{
/// <summary>Creatures in the table.</summary>
public static int Count => Wcids.Length;
/// <summary>Metres from the creature's feet to the top of its model, for a weenie class id; false when the table has none.</summary>
public static bool TryGetTop(uint wcid, out float metres)
{
metres = 0f;
if (wcid > int.MaxValue) return false;
int i = Array.BinarySearch(Wcids, (int)wcid);
if (i < 0) return false;
metres = TopCm[i] / 100f;
return true;
}
}

File diff suppressed because it is too large Load diff

View file

@ -126,6 +126,10 @@ internal static class MonsterHud
/// <summary>RadarKind.Monster: a full monster plate. Npc / Vendor / Player: a name-only label.</summary>
public byte Kind = RadarKind.Monster;
public bool IsLabel => Kind != RadarKind.Monster;
/// <summary>A name label with a thin health bar under it (players, when "Player health bars" is on).</summary>
public bool WithBar;
public bool HpFresh; // the last health observation is recent enough to draw a bar from
public bool HasBar => WithBar && HpKnown && HpFresh;
public int Level; // 0 = unknown
public string LevelText = "";
public float HeadHeight = DefaultHeadHeight;
@ -177,6 +181,10 @@ internal static class MonsterHud
private sealed record WeakTag(string Label, uint Color, string Icon);
private const float DefaultHeadHeight = 2.0f;
// A player's health is only known from what the game happened to tell us; a reading older than this is not drawn.
private const long PlayerBarMemorySec = 90;
// A size from the table is the top of the model: a hand's width above it for the plate, within sane bounds.
private const float HeadMargin = 0.12f, MinKnownHeadHeight = 0.3f, MaxKnownHeadHeight = 120f;
private static readonly Dictionary<uint, Plate> Plates = new(64);
private static readonly List<Plate> DrawOrder = new(64);
private static readonly List<Plate> Placed = new(64);
@ -277,7 +285,7 @@ internal static class MonsterHud
bool monsters = MonsterHudSettings.Enabled;
bool trackMonsters = monsters || MonsterHudSettings.Numbers;
// Name-only labels over NPCs (and, if asked, players): their own switches and cap.
bool track = trackMonsters || MonsterHudSettings.NpcNames || MonsterHudSettings.PlayerNames;
bool track = trackMonsters || MonsterHudSettings.NpcNames || MonsterHudSettings.PlayerNames || MonsterHudSettings.PlayerBars;
if (!track) ClearPlates();
SetDamageSubscription(monsters && MonsterHudSettings.ShowWeakness);
if (monsters && MonsterHudSettings.ShowDebuffs) PortalSpellTable.EnsureLoadQueued();
@ -373,7 +381,8 @@ internal static class MonsterHud
float maxD2 = maxD * maxD;
float targetD2 = MathF.Max(maxD2, 100f * 100f); // the target keeps its plate a bit further out
bool engagedOnly = MonsterHudSettings.Filter == PlateFilter.Engaged && MonsterHudSettings.Enabled;
bool npcNames = MonsterHudSettings.NpcNames, playerNames = MonsterHudSettings.PlayerNames;
bool npcNames = MonsterHudSettings.NpcNames, playerBars = MonsterHudSettings.PlayerBars,
playerNames = MonsterHudSettings.PlayerNames || playerBars; // a bar comes with the name
float npcD = MonsterHudSettings.NpcMaxDistance;
float npcD2 = npcD * npcD;
float npcTargetD2 = MathF.Max(npcD2, 100f * 100f); // a selected NPC keeps its name further out too
@ -491,6 +500,7 @@ internal static class MonsterHud
byte cls = Classes.TryGetValue(id, out ObjClass oc) ? oc.Cls : ClsCreature;
byte kind = cls == ClsPlayer ? RadarKind.Player : cls == ClsVendor ? RadarKind.Vendor : RadarKind.Npc;
Plate plate = GetPlate(id, kind);
plate.WithBar = playerBars && kind == RadarKind.Player;
// Head height once per name; again while selected (selecting appraises: CreatureType may arrive).
if (name != plate.Name || isTarget)
{
@ -586,11 +596,16 @@ internal static class MonsterHud
/// <summary>
/// Metres from the feet to just above the head. The client's own model
/// height isn't read (its CPartArray/CSetup layout isn't mapped here), so
/// this goes by CreatureType from the appraisal cache, then by name, then
/// a humanoid default; "Height lift" in the settings corrects the rest.
/// this goes by the creature's weenie class id against the generated size
/// table (CreatureSizes: model height x scale), then CreatureType from the
/// appraisal cache, then by name, then a humanoid default; "Height lift"
/// in the settings corrects the rest.
/// </summary>
internal static float EstimateHeadHeight(uint id, string name)
{
if (ClientObjectHooks.TryGetObjectWcid(id, out uint wcid) && CreatureSizes.TryGetTop(wcid, out float top))
return Math.Clamp(top, MinKnownHeadHeight, MaxKnownHeadHeight) + HeadMargin;
if (AppraisalHooks.TryGetCachedIntProperty(id, 2, out int ct) && ct > 0 && ct < CreatureTypeHeights.Length &&
CreatureTypeHeights[ct] > 0)
return CreatureTypeHeights[ct];
@ -925,8 +940,8 @@ internal static class MonsterHud
// Appearing: start at the right size; visible: ease (target pop, distance).
p.Scale = wasVisible ? p.Scale + (scaleTarget - p.Scale) * kScale : scaleTarget;
// ── Health (monster plates only) ──
if (!label) UpdateHealth(p, f.Now, kBar, dt);
// ── Health (monster plates, and player labels with a bar) ──
if (!label || p.WithBar) UpdateHealth(p, f.Now, kBar, dt);
if (!show && p.Alpha < 0.01f)
{
@ -979,6 +994,7 @@ internal static class MonsterHud
if (MonsterHudData.TryGetHealth(p.Id, out HealthObservation h))
{
p.HpKnown = true;
p.HpFresh = (now - h.Ticks) < PlayerBarMemorySec * Stopwatch.Frequency;
p.Ratio = h.Ratio;
uint max = h.Max;
if (ObjectQualityCache.TryGetCreatureVitals(p.Id, out CreatureVitals v) && v.MaxHealth > 0)
@ -990,6 +1006,7 @@ internal static class MonsterHud
{
// Never observed: an untouched monster is at full health in practice.
p.HpKnown = false;
p.HpFresh = false;
p.Ratio = 1f;
p.HpMax = ObjectQualityCache.TryGetCreatureVitals(p.Id, out CreatureVitals v) ? v.MaxHealth : 0;
p.HpCur = p.HpMax;
@ -1043,10 +1060,20 @@ internal static class MonsterHud
p.NameFont = ImGuiFonts.Sharp(p.NameSize, bold: true);
p.NameW = TextWidth(p.NameFont, p.NameSize, p.Name);
p.BadgeW = 0f;
p.BarW = p.BarH = 0f;
p.IconSize = 0f;
p.BelowBar = p.IsTarget ? 9f * k : 3f * k; // the target pointer hangs under the name
p.Width = p.NameW + 8f * k;
if (p.HasBar)
{
// A thin bar under the name, at least the name's width.
p.BarW = MathF.Round(MathF.Max(p.NameW, 64f * k));
p.BarH = MathF.Max(3f, MathF.Round(4f * k));
}
else
{
p.BarW = p.BarH = 0f;
}
float barRow = p.BarH > 0f ? p.BarH + MathF.Round(2f * k) : 0f;
p.BelowBar = (p.IsTarget ? 9f * k : 3f * k) + barRow; // the target pointer hangs under the name (and bar)
p.Width = MathF.Max(p.NameW, p.BarW) + 8f * k;
p.Height = p.NameSize + 2f * k + p.BelowBar;
return;
}
@ -1329,6 +1356,16 @@ internal static class MonsterHud
float x = MathF.Round(cx - p.NameW * 0.5f);
float pointerTop = baseY + 2f * k;
if (p.BarH > 0f)
{
// The player's health under the name.
float barTop = MathF.Round(baseY + 2f * k);
float barL = MathF.Round(cx - p.BarW * 0.5f);
PaintBar(dl, new Vector2(barL, barTop), new Vector2(barL + p.BarW, barTop + p.BarH), MathF.Max(1f, 1.5f * k), a,
p.ShownRatio, p.TrailRatio, HealthColor(p.Ratio), ticks: false);
pointerTop = barTop + p.BarH + 2f * k;
}
if (p.Nudge > 10f * uiScale)
dl.AddLine(new Vector2(cx, pointerTop - 1), new Vector2(cx, p.Anchor.Y - 2f * k), Mul(Leader, a), 1f);

View file

@ -56,6 +56,8 @@ internal static class MonsterHudSettings
public static float NpcMaxDistance = 30f; // yards; short so a town isn't a wall of text
public static int MaxNpcLabels = 15;
public static bool PlayerNames = false;
/// <summary>A health bar under other players' names, for those whose health the client has been told (selected, fellowship).</summary>
public static bool PlayerBars = false;
// Debuff icons on the monster plates (PlateDebuffs).
public static bool ShowDebuffs = true;
@ -196,6 +198,7 @@ internal static class MonsterHudSettings
MaxNpcLabels = Math.Clamp(nm, MinNpcLabels, MaxNpcLabelsLimit);
break;
case "playerNames": PlayerNames = val == "1"; break;
case "playerBars": PlayerBars = val == "1"; break;
case "showDebuffs": ShowDebuffs = val == "1"; break;
case "showOthersDebuff": ShowOthersDebuff = val == "1"; break;
case "selfPlate": SelfPlate = val == "1"; break;
@ -277,6 +280,7 @@ internal static class MonsterHudSettings
sw.WriteLine(FormattableString.Invariant($"npcDistance={NpcMaxDistance:0.#}"));
sw.WriteLine(FormattableString.Invariant($"npcMax={MaxNpcLabels}"));
sw.WriteLine($"playerNames={B(PlayerNames)}");
sw.WriteLine($"playerBars={B(PlayerBars)}");
sw.WriteLine($"showDebuffs={B(ShowDebuffs)}");
sw.WriteLine($"showOthersDebuff={B(ShowOthersDebuff)}");
sw.WriteLine($"selfPlate={B(SelfPlate)}");
@ -322,7 +326,7 @@ internal static class MonsterHudSettings
ShowNames = true; ShowHpNumbers = true; ShowDistance = false; ShowLevel = true; ShowWeakness = true;
FadeWithDistance = true; Scale = 1.0f; Opacity = 0.9f; HeightLift = 0f; ClickToSelect = true;
ShowDebuffs = true; ShowOthersDebuff = true;
NpcNames = true; NpcMaxDistance = 30f; MaxNpcLabels = 15; PlayerNames = false;
NpcNames = true; NpcMaxDistance = 30f; MaxNpcLabels = 15; PlayerNames = false; PlayerBars = false;
SelfPlate = true; SelfNumbers = false; SelfName = false; SelfHideFirstPerson = true;
SelfPlacement = SelfPlacement.Fixed; SelfLocked = true; SelfFixedX = DefaultSelfFixedX; SelfFixedY = DefaultSelfFixedY;
Numbers = true; NumDealt = true; NumTaken = true; NumHeals = true; NumKills = true;
@ -359,7 +363,7 @@ internal static class MonsterHudSettings
public static void SetAll(bool on)
{
Enabled = on; ShowDebuffs = on; SelfPlate = on; Numbers = on; Gains = on; NpcNames = on;
if (!on) PlayerNames = false; // "all on" leaves player names as chosen (off by default)
if (!on) { PlayerNames = false; PlayerBars = false; } // "all on" leaves player names and bars as chosen (off by default)
}
/// <summary>One line for chat: the current state.</summary>
@ -368,7 +372,7 @@ internal static class MonsterHudSettings
$"{MaxDistance:0}yd, max {MaxPlates}, scale {Scale:0.##}, opacity {Opacity:0.##}, lift {HeightLift:0.#}m; " +
$"names {OnOff(ShowNames)}, hp {OnOff(ShowHpNumbers)}, level {OnOff(ShowLevel)}, weak {OnOff(ShowWeakness)}, " +
$"distance {OnOff(ShowDistance)}, fade {OnOff(FadeWithDistance)}, click to select {OnOff(ClickToSelect)}), debuffs {OnOff(ShowDebuffs)} (others {OnOff(ShowOthersDebuff)}); " +
$"NPC names {OnOff(NpcNames)} ({NpcMaxDistance:0}yd, max {MaxNpcLabels}), player names {OnOff(PlayerNames)}; " +
$"NPC names {OnOff(NpcNames)} ({NpcMaxDistance:0}yd, max {MaxNpcLabels}), player names {OnOff(PlayerNames)} (bars {OnOff(PlayerBars)}); " +
$"self {OnOff(SelfPlate)} ({(SelfPlacement == SelfPlacement.Fixed ? "fixed on screen, " + (SelfLocked ? "locked" : "unlocked") : "follows you, " + SelfPosition.ToString().ToLowerInvariant())}, " +
$"numbers {OnOff(SelfNumbers)}, name {OnOff(SelfName)}, hide in first person {OnOff(SelfHideFirstPerson)}); " +
$"combat text {OnOff(Numbers)} (dealt {OnOff(NumDealt)}, taken {OnOff(NumTaken)}, heals {OnOff(NumHeals)}, kills {OnOff(NumKills)}); " +

View file

@ -87,6 +87,9 @@ internal static class MonsterHudSettingsUi
"Text size of the names over NPCs and vendors (1.00x = the default). Names have no bar.");
changed |= Toggle("Player names", ref MonsterHudSettings.PlayerNames,
"The name over other players too (blue), within the same distance and count. Chat: /rv plates players.");
changed |= Toggle("Player health bars", ref MonsterHudSettings.PlayerBars,
"A health bar under other players' names (and their name, even with Player names off). The game only tells you a player's health " +
"once you select them or they share it (fellowship), so a bar shows from then on; others keep just the name. Chat: /rv plates playerbars.");
changed |= SizeSlider("Player name size", ref MonsterHudSettings.PlayerTextSize, MonsterHudSettings.MinTextSize, MonsterHudSettings.MaxTextSize, w,
"Text size of the names over other players (1.00x = the default). Names have no bar.");
Note("Names count apart from the monster plates, so they never push one out; the nearest win.", w);

View file

@ -0,0 +1,312 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/BountiesFace.cs
// ACECustom bounties: every active bounty on the server and this character's
// progress on each (kills, cooldown or QB requirement), from the RynthILT
// plugin's tracker (UI/Data/BountiesData.cs). Part of the ILT section: only
// registered when RynthILT is installed, opened from the bar's ILT button or
// "/rc bounties" on Infinite Leaftide only. ImGui-only. Ported from
// SilentKelpie's rynth/RynthCore PR #5.
//
// The plugin reads /bounty list (quietly) only while this face is shown on
// ILT: on open, a moment after each kill, after bounty chat events and every
// few minutes, never more than once per MinRefreshSeconds. Options, Hide
// QB-locked and Closest first live in the plugin (per character); the text
// filter is this face's own.
// ============================================================================
using System;
using System.Globalization;
using System.Numerics;
using ImGuiNET;
using RynthCore.Engine.UI.Data;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
namespace RynthCore.Engine.ImGuiBackend.Panels;
internal sealed class BountiesFace : IImGuiPanel
{
public const string Title = "Bounties";
public static void Register() => ImGuiPanelHost.Register(Title,
new PanelSpec(new Vector2(560, 420), new Vector2(360, 220), EdgeToEdge: true),
() => new BountiesFace());
private const float RowH = 24, ProgressW = 160, FooterH = 18;
private const int MinRefreshFloor = 5, MinRefreshCeiling = 300, PeriodicCeiling = 60;
private static readonly uint OnBg = RynthTheme.Argb(0xFF104010), OnText = RynthTheme.Argb(0xFF33FF33);
private static readonly uint BarFill = RynthTheme.Argb(0xFF2E8C4A), BarChanged = RynthTheme.Argb(0xFF26C8D9),
BarTrack = RynthTheme.Argb(0xFF0E1A24);
private readonly byte[] _filter = new byte[64];
private bool _showOptions;
public void OnShown()
{
UiSources.Bounties.Subscribe();
UiSources.Bounties.RequestRefresh();
}
public void OnHidden() => UiSources.Bounties.Unsubscribe();
public void Draw()
{
// Off Infinite Leaftide the source stops polling; never show its last list there.
BountiesSnapshot? data = UiSources.Bounties.NotIlt ? null : UiSources.Bounties.Current?.Value;
float w = Begin(out Vector2 origin, out Vector2 size);
DrawToolbar(data, w);
if (data != null)
{
if (_showOptions) DrawOptions(data, w);
DrawFilterRow(data, w);
if (data.LastEvent.Length > 0)
{
Label(data.LastEvent + (data.LastEventAgoSec >= 0 ? " (" + Ago(data.LastEventAgoSec) + " ago)" : ""), Amber);
}
}
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ChildBg, PanelBg);
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
ImGuiNET.ImGui.BeginChild("##bounties_body", new Vector2(w, Math.Max(60, Remaining(origin, size) - FooterH - GripOverlap())));
float bw = ImGuiNET.ImGui.GetContentRegionAvail().X;
DrawBody(data, bw);
ImGuiNET.ImGui.EndChild();
ImGuiNET.ImGui.PopStyleVar();
ImGuiNET.ImGui.PopStyleColor();
ImFontPtr f9 = ImGuiFonts.Get(UiFont.Ui9);
Vector2 fp = ImGuiNET.ImGui.GetCursorScreenPos();
ImGuiNET.ImGui.GetWindowDrawList().AddText(f9, f9.FontSize, fp + new Vector2(2, 3), Mute,
"Kills count in the bounty's own area only (XP/lum mobs you did the most damage to).");
End(origin, size);
}
// ── Header ───────────────────────────────────────────────────────────
private void DrawToolbar(BountiesSnapshot? data, float w)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
bool ready = data != null;
if (Button("##bounty_refresh", PhosphorIcons.ArrowsClockwise + " Refresh", p, new Vector2(90, 22), Teal, BtnFill, ready))
BountiesCommands.Refresh();
string state = !ready
? (UiSources.Bounties.NotIlt ? "not Infinite Leaftide"
: UiSources.Bounties.ExportMissing ? "this RynthILT build has no bounty tracker" : "waiting for RynthILT (log in)")
: data!.Reading ? "reading /bounty list..."
: data.Status.Length > 0 ? data.Status
: data.ListedAgoSec < 0 ? "not read yet"
: "updated " + Ago(data.ListedAgoSec) + " ago";
ImGuiNET.ImGui.GetWindowDrawList().AddText(new Vector2(p.X + 98, p.Y + (22 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Mute, state);
Vector2 op = new(p.X + w - 26, p.Y);
if (IconButton("##bounty_opts", PhosphorIcons.Gear, op, new Vector2(24, 22), _showOptions ? Teal : Mute, _showOptions ? Selected : BtnFill, ready))
_showOptions = !_showOptions;
ImGuiNET.ImGui.SetItemTooltip("Options");
NextLine(p, 26);
}
private static void DrawOptions(BountiesSnapshot d, float w)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
dl.AddRectFilled(p, p + new Vector2(w, 82), PanelBg, 3);
float ty = (22 - ImGuiNET.ImGui.GetFontSize()) * 0.5f;
float x = p.X + 6, y = p.Y + 4;
dl.AddText(new Vector2(x, y + ty), Text, "Update after my kills");
float bx = x + ImGuiNET.ImGui.CalcTextSize("Update after my kills").X + 8;
if (Button("##bounty_onkills", d.RefreshOnKills ? "ON" : "OFF", new Vector2(bx, y), new Vector2(50, 22),
d.RefreshOnKills ? OnText : Mute, d.RefreshOnKills ? OnBg : BtnFill))
BountiesCommands.Set("refreshonkills", !d.RefreshOnKills);
y += 26;
dl.AddText(new Vector2(x, y + ty), Text, "At most every (sec)");
int min = Spinner("##bounty_min", d.MinRefreshSeconds, MinRefreshFloor, MinRefreshCeiling, 5,
new Vector2(x + 150, y));
if (min != d.MinRefreshSeconds) BountiesCommands.Set("minrefreshseconds", min.ToString(CultureInfo.InvariantCulture));
y += 26;
dl.AddText(new Vector2(x, y + ty), Text, "Re-read every (min, 0 = off)");
int per = Spinner("##bounty_per", d.PeriodicRefreshMinutes, 0, PeriodicCeiling, 1,
new Vector2(x + 190, y));
if (per != d.PeriodicRefreshMinutes) BountiesCommands.Set("periodicminutes", per.ToString(CultureInfo.InvariantCulture));
ImFontPtr f9 = ImGuiFonts.Get(UiFont.Ui9);
dl.AddText(f9, f9.FontSize, new Vector2(x + 310, p.Y + 8), Mute, "Reads run only while this\nwindow is open; the reply\nis hidden from chat.");
NextLine(p, 86);
}
private void DrawFilterRow(BountiesSnapshot d, float w)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
float filterW = Math.Clamp(w - 250, 120, 260);
TextBox("##bounty_filter", _filter, p, filterW, "filter by area or reward", out _);
float x = p.X + filterW + 6;
const string hideLabel = "Hide QB-locked";
float hw = ButtonWidth(hideLabel);
if (Button("##bounty_hideqb", hideLabel, new Vector2(x, p.Y), new Vector2(hw, 22),
d.HideQbLocked ? OnText : Mute, d.HideQbLocked ? OnBg : BtnFill))
BountiesCommands.Set("hideqblocked", !d.HideQbLocked);
if (d.HiddenCount > 0) ImGuiNET.ImGui.SetItemTooltip($"{d.HiddenCount} hidden");
x += hw + 4;
const string sortLabel = "Closest first";
if (Button("##bounty_sort", sortLabel, new Vector2(x, p.Y), new Vector2(ButtonWidth(sortLabel), 22),
d.SortByProgress ? OnText : Mute, d.SortByProgress ? OnBg : BtnFill))
BountiesCommands.Set("sortbyprogress", !d.SortByProgress);
ImGuiNET.ImGui.SetItemTooltip("Nearest to a reward first, then cooldowns, then QB-locked");
NextLine(p, 26);
}
// ── Rows ─────────────────────────────────────────────────────────────
private void DrawBody(BountiesSnapshot? d, float w)
{
if (d == null)
{
Empty(UiSources.Bounties.NotIlt ? "Bounties are an Infinite Leaftide feature (/rc ilt for why)."
: "Log in with RynthILT loaded to track bounties.", w);
return;
}
if (d.Unsupported) { Empty("This server has no /bounty command. Press Refresh to check again.", w); return; }
if (d.Rows.Count == 0)
{
Empty(d.NoneAnywhere ? "No bounties are active anywhere right now."
: d.HiddenCount > 0 ? "Every bounty is QB-locked (Hide QB-locked is on)."
: d.Reading ? "Reading the server's bounties..."
: "No bounties read yet. Press Refresh.", w);
return;
}
float areaW = (w - ProgressW) * 0.42f, rewardW = w - ProgressW - areaW;
TableHeader(areaW, rewardW, w);
string filter = Utf8(_filter).Trim();
int shown = 0;
for (int i = 0; i < d.Rows.Count; i++)
{
BountyRowJson r = d.Rows[i];
if (filter.Length > 0 && !r.Where.Contains(filter, StringComparison.OrdinalIgnoreCase)
&& !r.Item.Contains(filter, StringComparison.OrdinalIgnoreCase)) continue;
ImGuiNET.ImGui.PushID(i);
DrawRow(r, shown++, areaW, rewardW, w);
ImGuiNET.ImGui.PopID();
}
if (shown == 0) Empty("No bounty matches the filter.", w);
}
private static void TableHeader(float areaW, float rewardW, float w)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
dl.AddRectFilled(p, p + new Vector2(w, 22), Selected);
ImFontPtr bold = ImGuiFonts.Get(UiFont.UiBold11);
float ty = p.Y + (22 - bold.FontSize) * 0.5f;
dl.AddText(bold, bold.FontSize, new Vector2(p.X + 6, ty), Text, "Area");
dl.AddText(bold, bold.FontSize, new Vector2(p.X + areaW + 6, ty), Text, "Reward");
dl.AddText(bold, bold.FontSize, new Vector2(p.X + areaW + rewardW + 6, ty), Text, "Progress");
ImGuiNET.ImGui.Dummy(new Vector2(w, 22));
}
private static void DrawRow(BountyRowJson r, int index, float areaW, float rewardW, float w)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
dl.AddRectFilled(p, p + new Vector2(w, RowH), index % 2 == 0 ? RowAlt : PanelBg);
float ty = p.Y + (RowH - ImGuiNET.ImGui.GetFontSize()) * 0.5f;
dl.PushClipRect(p, p + new Vector2(areaW - 4, RowH), true);
dl.AddText(new Vector2(p.X + 6, ty), Text, r.Where);
dl.PopClipRect();
float rx = p.X + areaW;
dl.PushClipRect(new Vector2(rx, p.Y), new Vector2(rx + rewardW - 4, p.Y + RowH), true);
dl.AddText(new Vector2(rx + 6, ty), Text, N0(r.Amount) + " " + r.Item);
dl.PopClipRect();
float px = rx + rewardW;
var status = (BountyRowStatus)r.Status;
switch (status)
{
case BountyRowStatus.Counting:
{
Vector2 b0 = new(px + 4, p.Y + 4), b1 = new(p.X + w - 6, p.Y + RowH - 4);
float frac = r.KillsRequired > 0 ? Math.Clamp(r.Kills / (float)r.KillsRequired, 0f, 1f) : 0f;
dl.AddRectFilled(b0, b1, BarTrack, 3);
if (frac > 0) dl.AddRectFilled(b0, new Vector2(b0.X + (b1.X - b0.X) * frac, b1.Y), r.Changed ? BarChanged : BarFill, 3);
dl.AddRect(b0, b1, BtnBord, 3);
string text = N0(r.Kills) + " / " + N0(r.KillsRequired);
Vector2 ts = ImGuiNET.ImGui.CalcTextSize(text);
dl.AddText(new Vector2((b0.X + b1.X - ts.X) * 0.5f, ty), Text, text);
break;
}
case BountyRowStatus.Cooldown:
dl.AddText(new Vector2(px + 6, ty), Amber, "unlocks in " + Ago(r.UnlockInSec));
break;
default:
dl.AddText(new Vector2(px + 6, ty), Mute, "needs " + Compact(r.QbRequired) + " QB");
break;
}
ImGuiNET.ImGui.SetCursorScreenPos(p);
ImGuiNET.ImGui.InvisibleButton("##row", new Vector2(w, RowH));
if (ImGuiNET.ImGui.IsItemHovered())
{
string every = $"Every {N0(r.KillsRequired)} kill(s)"
+ (r.CooldownSeconds > 0 ? ", at most every " + Ago(r.CooldownSeconds) : "");
string detail = status switch
{
BountyRowStatus.Cooldown => $"\nKills don't count for {Ago(r.UnlockInSec)}; after that {N0(r.KillsRequired)} kill(s).",
BountyRowStatus.NeedsQb => $"\nNeeds {N0(r.QbRequired)} QB; you have {N0(r.QbHave)}.",
_ => string.Empty,
};
ImGuiNET.ImGui.SetTooltip($"{r.Where}: {N0(r.Amount)} {r.Item}\n{every}{detail}");
}
NextLine(p, RowH);
}
private static void Empty(string message, float w)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
ImGuiNET.ImGui.GetWindowDrawList().AddRectFilled(p, p + new Vector2(w, 22), RowAlt);
ImGuiNET.ImGui.GetWindowDrawList().AddText(p + new Vector2(8, (22 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Mute, message);
ImGuiNET.ImGui.Dummy(new Vector2(w, 22));
}
/// <summary>[-] value [+]; returns the new value (same when nothing was clicked).</summary>
private static int Spinner(string id, int value, int min, int max, int step, Vector2 pos)
{
int v = value;
ImGuiNET.ImGui.PushID(id);
if (IconButton("##dec", PhosphorIcons.Minus, pos, new Vector2(22, 22), Teal, BtnFill)) v = Math.Max(min, v - step);
string text = v.ToString(CultureInfo.InvariantCulture);
float tw = ImGuiNET.ImGui.CalcTextSize(text).X;
ImGuiNET.ImGui.GetWindowDrawList().AddText(new Vector2(pos.X + 24 + (40 - tw) * 0.5f, pos.Y + (22 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Text, text);
if (IconButton("##inc", PhosphorIcons.Plus, new Vector2(pos.X + 66, pos.Y), new Vector2(22, 22), Teal, BtnFill)) v = Math.Min(max, v + step);
ImGuiNET.ImGui.PopID();
return v;
}
// ── Formatting ───────────────────────────────────────────────────────
private static string N0(long v) => v.ToString("N0", CultureInfo.InvariantCulture);
/// <summary>1.2M, 350k, 900.</summary>
private static string Compact(long v) =>
v >= 1_000_000 ? (v / 1_000_000d).ToString("0.#", CultureInfo.InvariantCulture) + "M"
: v >= 10_000 ? (v / 1_000d).ToString("0.#", CultureInfo.InvariantCulture) + "k"
: N0(v);
/// <summary>"45 sec", "2 min 30 sec", "1 hr 5 min", "2 days 3 hr".</summary>
private static string Ago(int seconds)
{
long s = Math.Max(0, seconds);
if (s >= 86400) return $"{s / 86400} day{(s / 86400 == 1 ? "" : "s")}" + (s % 86400 >= 3600 ? $" {s % 86400 / 3600} hr" : "");
if (s >= 3600) return $"{s / 3600} hr" + (s % 3600 >= 60 ? $" {s % 3600 / 60} min" : "");
if (s >= 60) return $"{s / 60} min" + (s % 60 > 0 ? $" {s % 60} sec" : "");
return $"{s} sec";
}
}

View file

@ -0,0 +1,485 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/ChatDiscordFace.cs
// The Discord panel: everything about copying chat to Discord
// (UI/Data/Discord/ChatDiscord.cs). Opened from the Chat panel's gear menu
// (Discord settings...) or /rc discord window.
//
// Routes one tab per destination: webhook URL, or bot token + channel ID;
// which speech channels and which chat tabs it gets, keywords,
// and optionally its own pacing; Send test / Resume
// Settings who relays (the characters it's on for, your own lines, hidden lines),
// the message format, and the default pacing and limits
// Log messages sent, rate limits and errors
//
// Settings fields are edited in place (single-value writes the pump
// tolerates); adding or removing a route replaces the Routes array, and a
// route's tab list is replaced too. Each change saves (ChatDiscord.Save, on
// the background writer). Secrets go to ChatDiscord, which encrypts them off
// this thread; the box is cleared at once and the text is never shown again.
// AC's render thread only.
// ============================================================================
using System;
using System.Collections.Generic;
using System.Numerics;
using ImGuiNET;
using RynthCore.Engine.UI.Data;
using RynthCore.Engine.UI.Data.Discord;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
namespace RynthCore.Engine.ImGuiBackend.Panels;
internal sealed class ChatDiscordFace : IImGuiPanel
{
public const string Title = "Discord";
public static void Register() => ImGuiPanelHost.Register(Title,
new PanelSpec(new Vector2(560, 520), new Vector2(420, 300)),
() => new ChatDiscordFace());
private string _secretInput = string.Empty;
private string _secretMessage = string.Empty;
private bool _secretMessageIsError;
private DiscordRoute? _secretFor;
private DiscordRoute? _confirmRemove;
private int _lastLogCount;
public void OnShown()
{
ChatModel.EnsureSettingsLoaded();
ChatDiscord.EnsureLoaded();
ChatDiscord.PanelShown(true);
}
public void OnHidden()
{
_confirmRemove = null;
ChatDiscord.PanelShown(false);
}
public void Draw()
{
var s = ChatDiscord.Settings;
DrawSwitch();
ImGuiNET.ImGui.SameLine();
Label("| " + ChatDiscord.StatusLine(), Mute);
ImGuiNET.ImGui.Separator();
if (ImGuiNET.ImGui.BeginTabBar("##dc_tabs"))
{
if (ImGuiNET.ImGui.BeginTabItem("Routes")) { DrawRoutes(s); ImGuiNET.ImGui.EndTabItem(); }
if (ImGuiNET.ImGui.BeginTabItem("Settings")) { DrawSettings(s); ImGuiNET.ImGui.EndTabItem(); }
if (ImGuiNET.ImGui.BeginTabItem("Log")) { DrawLog(); ImGuiNET.ImGui.EndTabItem(); }
ImGuiNET.ImGui.EndTabBar();
}
}
/// <summary>
/// This character's switch (the relay is off for every character until each is switched on).
/// Shared by the Chat panel's gear menu.
/// </summary>
internal static void DrawSwitch()
{
DiscordCharacter? me = ChatDiscord.CurrentCharacter();
bool on = ChatDiscord.IsOn(me);
ImGuiNET.ImGui.BeginDisabled(me == null);
if (ImGuiNET.ImGui.Checkbox("Copy this character's chat to Discord##dc_on", ref on)) ChatDiscord.SetEnabled(on);
ImGuiNET.ImGui.EndDisabled();
if (me == null)
ImGuiNET.ImGui.SetItemTooltip("Log in first: the relay is switched on for one character at a time.");
else
ImGuiNET.ImGui.SetItemTooltip("On for this character only; every other character stays off until it's switched on too.\n" +
"Off: nothing from this character is queued or sent (Send test still works).");
}
// ── Routes ───────────────────────────────────────────────────────────
private void DrawRoutes(ChatDiscordSettings s)
{
if (ImGuiNET.ImGui.SmallButton("Add route"))
{
var r = new DiscordRoute { Name = $"Route {s.Routes.Length + 1}" };
ChatDiscordStore.NormalizeRoute(r);
s.Routes = new List<DiscordRoute>(s.Routes) { r }.ToArray();
ChatDiscord.Save();
}
ImGuiNET.ImGui.SetItemTooltip("A route is one Discord channel and the chat it receives.");
if (s.Routes.Length == 0)
{
ImGuiNET.ImGui.Spacing();
Wrapped("No routes yet. Add one, then paste a webhook URL from Discord: Server Settings > Integrations > "
+ "Webhooks > New Webhook > pick the channel > Copy Webhook URL.", Text);
return;
}
if (!ImGuiNET.ImGui.BeginTabBar("##dc_routes", ImGuiTabBarFlags.FittingPolicyScroll)) return;
DiscordRoute? remove = null;
for (int i = 0; i < s.Routes.Length; i++)
{
DiscordRoute r = s.Routes[i];
string label = (r.Status?.Paused == true ? "! " : r.Enabled ? "" : "(off) ") + r.Name + "###dc_route" + i;
if (!ImGuiNET.ImGui.BeginTabItem(label)) continue;
ImGuiNET.ImGui.PushID(i);
if (DrawRoute(s, r)) remove = r;
ImGuiNET.ImGui.PopID();
ImGuiNET.ImGui.EndTabItem();
}
ImGuiNET.ImGui.EndTabBar();
if (remove != null)
{
var list = new List<DiscordRoute>(s.Routes);
list.Remove(remove);
s.Routes = list.ToArray();
if (ReferenceEquals(_secretFor, remove)) ClearSecretBox(null);
ChatDiscord.Save();
}
}
/// <summary>One route's editor; true when the player asked to remove it.</summary>
private bool DrawRoute(ChatDiscordSettings s, DiscordRoute r)
{
if (!ReferenceEquals(_secretFor, r)) ClearSecretBox(r);
DiscordRouteStatus? st = r.Status;
if (st != null)
{
if (st.Paused) Wrapped("Paused: " + st.LastError, Red);
else if (st.LastError.Length > 0) Wrapped("Last problem: " + st.LastError, Amber);
Label($"{st.MessagesSent} message(s), {st.LinesSent} line(s) sent, {st.Queued} queued, {st.Dropped} dropped"
+ (st.LastSent != default ? $", last {st.LastSent:HH:mm:ss}" : string.Empty), Mute);
}
if (ImGuiNET.ImGui.Checkbox("Enabled##r_on", ref r.Enabled)) ChatDiscord.Save();
ImGuiNET.ImGui.SameLine();
ImGuiNET.ImGui.SetNextItemWidth(200f);
string name = r.Name;
if (Input("Name##r_name", "route name", ref name, 40)) r.Name = name;
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit())
{
if (string.IsNullOrWhiteSpace(r.Name)) r.Name = "Discord";
ChatDiscord.Save();
}
// Connection
Heading("Connection");
int mode = Math.Max(0, Array.IndexOf(DiscordRoute.Modes, r.Mode));
ImGuiNET.ImGui.SetNextItemWidth(220f);
if (ImGuiNET.ImGui.Combo("Send with##r_mode", ref mode, DiscordRoute.ModeNames, DiscordRoute.ModeNames.Length))
{
r.Mode = DiscordRoute.Modes[mode];
ClearSecretBox(r);
ChatDiscord.Resume(r);
ChatDiscord.Save();
}
ImGuiNET.ImGui.SetItemTooltip("Webhook: simplest, one URL per channel, posts under any name.\n"
+ "Bot: your own Discord bot posts it (it must be in the server with Send Messages there).");
bool bot = r.Mode == DiscordRoute.ModeBot;
bool saved = bot ? r.BotTokenProtected.Length > 0 : r.WebhookProtected.Length > 0;
ImGuiNET.ImGui.SetNextItemWidth(330f);
Input((bot ? "Bot token" : "Webhook URL") + "##r_secret",
saved ? "saved (paste a new one to replace it)" : bot ? "paste the bot token" : "https://discord.com/api/webhooks/...",
ref _secretInput, 512, ImGuiInputTextFlags.Password);
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.Button("Save##r_secret_save") && _secretInput.Trim().Length > 0)
{
string err = bot ? ChatDiscord.SetBotToken(r, _secretInput) : ChatDiscord.SetWebhook(r, _secretInput);
_secretInput = string.Empty;
_secretMessageIsError = err.Length > 0;
_secretMessage = err.Length > 0 ? err : "Saved, encrypted for this Windows user. Use Send test to check it.";
}
if (saved)
{
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.Button("Clear##r_secret_clear"))
{
if (bot) r.BotTokenProtected = string.Empty; else r.WebhookProtected = string.Empty;
_secretMessage = "Cleared.";
_secretMessageIsError = false;
ChatDiscord.Save();
}
}
if (_secretMessage.Length > 0) Wrapped(_secretMessage, _secretMessageIsError ? Red : Green);
if (bot)
{
ImGuiNET.ImGui.SetNextItemWidth(200f);
string chId = r.ChannelId;
if (Input("Channel ID##r_chid", "e.g. 123456789012345678", ref chId, 24, ImGuiInputTextFlags.CharsDecimal))
{
r.ChannelId = chId.Trim();
ChatDiscord.Resume(r);
}
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Discord: User Settings > Advanced > Developer Mode on, then right-click the channel > Copy Channel ID.");
if (r.ChannelId.Length > 0 && !DiscordFormat.IsSnowflake(r.ChannelId))
Label("A channel ID is 15-22 digits.", Red);
}
else
{
ImGuiNET.ImGui.SetNextItemWidth(200f);
Input("Post as##r_name_as", "character name", ref r.DisplayName, 80);
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Name shown on the webhook's messages. Blank uses the character's name.\n"
+ "Discord refuses names containing \"discord\" or \"clyde\"; those fall back to the webhook's own name.");
}
if (ImGuiNET.ImGui.Button("Send test##r_test")) ChatDiscord.SendTest(r);
ImGuiNET.ImGui.SetItemTooltip("Posts one test line to this route now (also clears a pause).");
if (st?.Paused == true)
{
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.Button("Resume##r_resume")) ChatDiscord.Resume(r);
}
DrawSpeech(r);
DrawTabs(r);
Heading("Filter");
ImGuiNET.ImGui.SetNextItemWidth(330f);
Input("Keywords##r_kw", "blank = every line; e.g. rare, Asheron", ref r.Keywords, 300);
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Comma-separated. When set, only lines containing one of these words (any case) are relayed.");
Heading("How often");
if (ImGuiNET.ImGui.Checkbox("Own pacing for this route##r_pace", ref r.CustomPace)) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Off: the route uses the pacing on the Settings tab.");
if (r.CustomPace)
DrawPacing(ref r.BatchMs, ref r.MinIntervalMs, "##r");
else
Label($"Using the default: batch {s.BatchMs / 1000.0:0.#} s, at most one message every {s.MinIntervalMs / 1000.0:0.#} s.", Mute);
ImGuiNET.ImGui.Spacing();
ImGuiNET.ImGui.Separator();
bool remove = false;
if (ReferenceEquals(_confirmRemove, r))
{
// The saved webhook URL / bot token goes with the route; there's no undo.
Label("Delete this route and its saved credential?", Amber);
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.SmallButton("Delete##r_remove_yes"))
{
remove = true;
_confirmRemove = null;
}
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.SmallButton("Cancel##r_remove_no")) _confirmRemove = null;
}
else
{
if (ImGuiNET.ImGui.SmallButton("Remove route##r_remove")) _confirmRemove = r;
ImGuiNET.ImGui.SetItemTooltip("Deletes this route and its saved credential (asks first).");
}
return remove;
}
private static void DrawSpeech(DiscordRoute r)
{
Heading("Speech channels");
if (ImGuiNET.ImGui.SmallButton("All##sp_all")) SetSpeech(r, DiscordRoute.AllSpeechMask());
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.SmallButton("None##sp_none")) SetSpeech(r, 0);
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.SmallButton("Defaults##sp_def")) SetSpeech(r, DiscordRoute.DefaultSpeechMask());
ImGuiNET.ImGui.SameLine();
Label("what players say, by channel", Mute);
if (!ImGuiNET.ImGui.BeginTable("##sp_grid", 4, ImGuiTableFlags.SizingStretchSame)) return;
foreach (SpeechChannel ch in ChatSpeech.All)
{
ImGuiNET.ImGui.TableNextColumn();
uint bit = ChatSpeech.Bit(ch);
bool ticked = (r.SpeechMask & bit) != 0;
if (ImGuiNET.ImGui.Checkbox(ChatSpeech.Name(ch) + "##sp" + (int)ch, ref ticked))
SetSpeech(r, ticked ? r.SpeechMask | bit : r.SpeechMask & ~bit);
if (ch == SpeechChannel.Local) ImGuiNET.ImGui.SetItemTooltip("Local speech includes every NPC and player near you; it can be busy.");
}
ImGuiNET.ImGui.EndTable();
}
private static void SetSpeech(DiscordRoute r, uint mask)
{
r.SpeechMask = mask;
ChatDiscord.Save();
}
/// <summary>Chat tabs: every line that shows in a ticked tab goes, whatever it is.</summary>
private static void DrawTabs(DiscordRoute r)
{
Heading("Chat tabs");
Label("every line that shows in the tab (System, Combat, or tabs your chat rules fill)", Mute);
string[] all = ChatModel.AllTabs();
var shown = new List<string>(all);
foreach (string t in r.Tabs)
if (!shown.Exists(x => string.Equals(x, t, StringComparison.OrdinalIgnoreCase))) shown.Add(t);
if (!ImGuiNET.ImGui.BeginTable("##tab_grid", 4, ImGuiTableFlags.SizingStretchSame)) return;
for (int i = 0; i < shown.Count; i++)
{
string tab = shown[i];
ImGuiNET.ImGui.TableNextColumn();
bool ticked = Array.Exists(r.Tabs, t => string.Equals(t, tab, StringComparison.OrdinalIgnoreCase));
bool missing = Array.IndexOf(all, tab) < 0;
if (ImGuiNET.ImGui.Checkbox((missing ? tab + " (gone)" : tab) + "##tab" + i, ref ticked))
{
var list = new List<string>(r.Tabs);
list.RemoveAll(t => string.Equals(t, tab, StringComparison.OrdinalIgnoreCase));
if (ticked) list.Add(tab);
r.Tabs = list.ToArray();
ChatDiscord.Save();
}
if (tab == "All") ImGuiNET.ImGui.SetItemTooltip("Every line in the All tab: very busy. Pair it with keywords.");
else if (missing) ImGuiNET.ImGui.SetItemTooltip("This tab no longer exists; untick it to drop it.");
}
ImGuiNET.ImGui.EndTable();
}
private void ClearSecretBox(DiscordRoute? forRoute)
{
_secretFor = forRoute;
_secretInput = string.Empty;
_secretMessage = string.Empty;
_secretMessageIsError = false;
}
// ── Settings ─────────────────────────────────────────────────────────
private static void DrawSettings(ChatDiscordSettings s)
{
Heading("Who relays");
Label(ChatDiscord.SwitchLine(), Text);
DiscordCharacter[] on = s.Characters;
if (on.Length == 0)
Label("Off for every character.", Mute);
else
{
Label("On for:", Mute);
DiscordCharacter? me = ChatDiscord.CurrentCharacter();
for (int i = 0; i < on.Length; i++)
{
DiscordCharacter c = on[i];
ImGuiNET.ImGui.PushID(i);
if (ImGuiNET.ImGui.SmallButton("Turn off##s_char_off")) ChatDiscord.TurnOffFor(c);
ImGuiNET.ImGui.SameLine();
Label(c.ToString() + (c.Same(me) ? " (this client)" : string.Empty), c.Same(me) ? Green : Text);
ImGuiNET.ImGui.PopID();
}
}
Wrapped("Each character is switched on by itself (the checkbox at the top while you play it, or /rc discord on). "
+ "With several clients in one allegiance or fellowship, switch on just one of them so each line is posted once.", Mute);
if (ImGuiNET.ImGui.Checkbox("Skip lines I type##s_own", ref s.SkipOwn)) ChatDiscord.Save();
if (ImGuiNET.ImGui.Checkbox("Skip lines my chat rules hide##s_hidden", ref s.SkipHidden)) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Lines a Hide rule or standard filter hides in the chat aren't sent either.");
Heading("Message format");
if (ImGuiNET.ImGui.Checkbox("Timestamp (HH:mm:ss)##s_ts", ref s.IncludeTimestamp)) ChatDiscord.Save();
if (ImGuiNET.ImGui.Checkbox("Start lines with [Character]##s_tag", ref s.TagCharacter)) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Useful when several characters post into the same Discord channel.");
Heading("How often (default for every route)");
DrawPacing(ref s.BatchMs, ref s.MinIntervalMs, "##s");
Heading("Limits");
ImGuiNET.ImGui.SetNextItemWidth(200f);
if (ImGuiNET.ImGui.SliderInt("Queue limit (lines)##s_queue", ref s.MaxQueue, ChatDiscordSettings.QueueMin, ChatDiscordSettings.QueueMax))
s.MaxQueue = Math.Clamp(s.MaxQueue, ChatDiscordSettings.QueueMin, ChatDiscordSettings.QueueMax);
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Lines waiting per route; past this the oldest are dropped.");
ImGuiNET.ImGui.SetNextItemWidth(200f);
if (ImGuiNET.ImGui.SliderInt("Log size##s_log", ref s.MaxLog, ChatDiscordSettings.LogMin, ChatDiscordSettings.LogMax))
s.MaxLog = Math.Clamp(s.MaxLog, ChatDiscordSettings.LogMin, ChatDiscordSettings.LogMax);
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.Spacing();
Wrapped("Routes and settings are shared by every client and character (%AppData%\\RynthCore\\rynthchat_discord.json); "
+ "the on / off switch is per character. Webhook URLs and bot tokens "
+ "are encrypted for this Windows user; on another PC or user they must be pasted again.", Mute);
Wrapped("Relayed text never pings: @everyone, @here and user mentions are sent as plain text, and links don't unfurl.", Mute);
}
/// <summary>Batch window and message spacing sliders (seconds on screen, ms stored).</summary>
private static void DrawPacing(ref int batchMs, ref int intervalMs, string id)
{
float batch = batchMs / 1000f;
ImGuiNET.ImGui.SetNextItemWidth(200f);
if (ImGuiNET.ImGui.SliderFloat("Batch window" + id + "_batch", ref batch, ChatDiscordSettings.BatchMinMs / 1000f,
ChatDiscordSettings.BatchMaxMs / 1000f, "%.1f s", ImGuiSliderFlags.Logarithmic))
batchMs = Math.Clamp((int)MathF.Round(batch * 1000f), ChatDiscordSettings.BatchMinMs, ChatDiscordSettings.BatchMaxMs);
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Lines arriving this close together go out as one Discord message.\n"
+ "Longer = fewer, bigger messages (a digest); 0 = each line as soon as allowed.");
float interval = intervalMs / 1000f;
ImGuiNET.ImGui.SetNextItemWidth(200f);
if (ImGuiNET.ImGui.SliderFloat("At most one message every" + id + "_interval", ref interval, ChatDiscordSettings.IntervalMinMs / 1000f,
ChatDiscordSettings.IntervalMaxMs / 1000f, "%.1f s", ImGuiSliderFlags.Logarithmic))
intervalMs = Math.Clamp((int)MathF.Round(interval * 1000f), ChatDiscordSettings.IntervalMinMs, ChatDiscordSettings.IntervalMaxMs);
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatDiscord.Save();
ImGuiNET.ImGui.SetItemTooltip("Spacing between messages to one route. Discord allows about 30 a minute per channel;\n"
+ "2 s stays under it. Lines that arrive meanwhile wait and go in the next message.");
Label($"Up to {60000.0 / Math.Max(1, intervalMs):0.#} messages a minute per route.", Mute);
}
// ── Log ──────────────────────────────────────────────────────────────
private void DrawLog()
{
DiscordLogEntry[] log = ChatDiscord.LogSnapshot();
if (ImGuiNET.ImGui.SmallButton("Clear##log_clear")) ChatDiscord.ClearLog();
ImGuiNET.ImGui.SameLine();
Label($"{log.Length} entries", Mute);
if (!ImGuiNET.ImGui.BeginChild("##dc_log", new Vector2(0, 0), ImGuiChildFlags.Borders)) { ImGuiNET.ImGui.EndChild(); return; }
foreach (DiscordLogEntry e in log)
{
uint col = e.Kind switch { DiscordLogKind.Sent => Green, DiscordLogKind.Error => Red, _ => Amber };
Label(e.Time.ToString("HH:mm:ss"), Mute);
ImGuiNET.ImGui.SameLine();
Label(e.Route, col);
ImGuiNET.ImGui.SameLine();
// Relayed chat and Discord's replies: never a format string (see Wrapped).
WrappedUnformatted(e.Text);
}
// Follow new lines unless the player scrolled up.
if (log.Length != _lastLogCount && ImGuiNET.ImGui.GetScrollY() >= ImGuiNET.ImGui.GetScrollMaxY() - 20f)
ImGuiNET.ImGui.SetScrollHereY(1f);
_lastLogCount = log.Length;
ImGuiNET.ImGui.EndChild();
}
// ── Helpers ──────────────────────────────────────────────────────────
private static void Heading(string text)
{
ImGuiNET.ImGui.Spacing();
Label(text, Teal);
}
/// <summary>
/// Wrapped text in <paramref name="color"/>. ImGui.NET's TextWrapped / Text / TextColored pass
/// their string to ImGui as a printf format, so chat or an error Discord sent back holding
/// "%s" would crash the client. Everything here goes through TextUnformatted.
/// </summary>
private static void Wrapped(string text, uint color)
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, color);
WrappedUnformatted(text);
ImGuiNET.ImGui.PopStyleColor();
}
private static void WrappedUnformatted(string text)
{
ImGuiNET.ImGui.PushTextWrapPos(0f);
ImGuiNET.ImGui.TextUnformatted(text);
ImGuiNET.ImGui.PopTextWrapPos();
}
/// <summary>A text box that keeps the keyboard from AC while it's being typed in.</summary>
private static bool Input(string label, string hint, ref string value, uint maxLength,
ImGuiInputTextFlags flags = ImGuiInputTextFlags.None)
{
bool changed = ImGuiNET.ImGui.InputTextWithHint(label, hint, ref value, maxLength, flags);
if (ImGuiNET.ImGui.IsItemActive()) ImGuiTextFocus.NoteActive(label);
return changed;
}
}

View file

@ -900,7 +900,7 @@ internal sealed class ChatFace : IImGuiPanel
ChatModel.LogEnabled = log;
ChatModel.SaveSettings();
}
ImGuiNET.ImGui.SetItemTooltip("%AppData%\\RynthCore\\ChatLogs\\<character>.log");
ImGuiNET.ImGui.SetItemTooltip("%%AppData%%\\RynthCore\\ChatLogs\\<character>.log"); // a format string: %% is a literal %
bool through = ChatModel.CtrlGatedClickThrough;
if (ImGuiNET.ImGui.Checkbox("Click-through (hold Ctrl to interact)", ref through))
ChatModel.SetCtrlGatedClickThrough(through);
@ -934,6 +934,8 @@ internal sealed class ChatFace : IImGuiPanel
ChatModel.SaveSettings();
}
}
// Discord above the colours: the colour grid opens downward, so it stays last.
DrawDiscordSettings();
ImGuiNET.ImGui.Separator();
if (ImGuiNET.ImGui.CollapsingHeader("Line colours")) DrawLineColours();
@ -1024,6 +1026,25 @@ internal sealed class ChatFace : IImGuiPanel
ImGuiNET.ImGui.PopID();
}
/// <summary>
/// Settings menu: this character's Discord relay switch, its status and the way into the
/// Discord panel, in two compact rows like the rest of the menu.
/// </summary>
private static void DrawDiscordSettings()
{
ImGuiNET.ImGui.Separator();
ChatDiscordFace.DrawSwitch();
ImGuiNET.ImGui.SameLine();
if (ImGuiNET.ImGui.SmallButton("Discord…##chat_discord"))
{
if (!ImGuiPanelHost.IsOpen(ChatDiscordFace.Title)) PanelRouter.Toggle(ChatDiscordFace.Title);
ImGuiNET.ImGui.CloseCurrentPopup();
}
ImGuiNET.ImGui.SetItemTooltip("Discord panel: connection (webhook or bot), which channels and tabs go where,\n" +
"keywords, how often, and the send log.");
Label(UI.Data.Discord.ChatDiscord.SwitchLine() + " " + UI.Data.Discord.ChatDiscord.StatusLine(), Mute);
}
private void DrawNewTabPopup()
{
if (!ImGuiNET.ImGui.BeginPopup("##chat_newtab"))

View file

@ -269,9 +269,11 @@ internal sealed class LootAddDialog
}
if (ImGuiNET.ImGui.IsItemHovered())
ImGuiNET.ImGui.SetTooltip(
"Also require this item's T11 tier, weapon grade, damage %, every modifier, slot special\n" +
"and Cast on Strike, each at least as good as this one. Works with any match.\n" +
"Not added: Can Wield (depends on your character) and Zone Locked (depends on where it was assessed).");
"Also require this item's T11 tier (the server's stamped tier when it sends one), weapon grade,\n" +
"damage %, gear grade, every modifier, slot special and Cast on Strike, each at least as good\n" +
"as this one. Works with any match.\n" +
"Not added: Can Wield (depends on your character), Zone Locked (depends on where it was assessed),\n" +
"and property slots / Tainted (bag state, not quality).");
if (!d.IsT11)
{
ImGuiNET.ImGui.SameLine();

View file

@ -40,6 +40,9 @@ internal static class P1Faces
// items to use): ImGui only, saved per character in item_huds.txt.
ItemCountFace.Register();
MiniRemoteFace.Register();
// Report a problem (Report/ProblemReport.cs): ImGui only, opened from the bar's grip
// menu, Settings and /rc report (no bar button of its own).
ReportFace.Register();
}
}

View file

@ -0,0 +1,241 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/ReportFace.cs
// The "Report a problem" panel (Report/ProblemReport.cs). ImGui only.
//
// What went wrong? required, 2,500 bytes of UTF-8 at most
// What were you doing? optional, 1,500 bytes
// [x] Attach my recent RynthCore log ticked each time the panel opens
// its size, View (opens exactly what will be sent) and Refresh
// what else is sent, the Send button and the result
//
// Opened from the bar's grip menu, Settings' sidebar and /rc report. Draw reads
// ProblemReport's state and calls Send / RefreshTail / ViewTail, which do their
// work off AC's thread. The log tail is read when the panel opens (and on
// Refresh); Send sends that same tail, so what View showed is what goes.
// ============================================================================
using System;
using System.Globalization;
using System.Numerics;
using System.Text;
using ImGuiNET;
using RynthCore.Engine.Report;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
namespace RynthCore.Engine.ImGuiBackend.Panels;
internal sealed class ReportFace : IImGuiPanel
{
public const string Title = ProblemReport.PanelTitle;
public static void Register() => ImGuiPanelHost.Register(Title,
new PanelSpec(new Vector2(390, 490), new Vector2(300, 440), EdgeToEdge: true, GripInBody: true),
() => new ReportFace());
private const string DescId = "##report_desc", DoingId = "##report_doing";
private static readonly byte[] DescLabel = Encoding.UTF8.GetBytes(DescId + "\0");
private static readonly byte[] DoingLabel = Encoding.UTF8.GetBytes(DoingId + "\0");
private readonly byte[] _desc = new byte[ProblemReportCore.MaxDescriptionBytes + 1];
private readonly byte[] _doing = new byte[ProblemReportCore.MaxDoingBytes + 1];
private bool _attachLog = true;
private long _messageSeqAtOpen;
private long _resultSeqAtSend = -1; // >= 0 while a send this panel started is out
private string _localError = "";
private LogTail? _describedTail; // the tail _tailText describes (built when the tail changes, not per frame)
private string _tailText = "";
private static readonly string LogToggleLabel =
$"Attach my recent RynthCore log (last {ProblemReportCore.TailLines:N0} lines)";
public void OnShown()
{
_attachLog = true; // ticked by default, every time
_localError = "";
_messageSeqAtOpen = ProblemReport.MessageSeq;
ProblemReport.RefreshTail();
}
public void Draw()
{
// A send this panel started finished: clear the form when it was taken.
if (_resultSeqAtSend >= 0 && ProblemReport.ResultSeq != _resultSeqAtSend)
{
if (ProblemReport.State == ReportState.Sent)
{
WriteUtf8(_desc, "");
WriteUtf8(_doing, "");
}
_resultSeqAtSend = -1;
}
float w = Begin(out Vector2 origin, out Vector2 size);
Label("What went wrong? (required)", Text);
MultiLine(DescId, DescLabel, _desc, w, 92, "What happened, and what did you expect?");
Label("What were you doing? (optional)", Mute);
MultiLine(DoingId, DoingLabel, _doing, w, 56, "e.g. hunting in a dungeon with the bot on");
ImGuiNET.ImGui.Dummy(new Vector2(0, 2));
Separator(w);
LogRow(w);
Separator(w);
Note("Also sent: your character, server, RynthCore / RynthAi / plugin versions, where you are (landblock and cell) " +
"and the client's process id. Reports go to the staff only.", w);
ImGuiNET.ImGui.Dummy(new Vector2(0, 2));
SendRow(w);
End(origin, size);
}
// ── The log ─────────────────────────────────────────────────────────
private void LogRow(float w)
{
// Square toggle + label; the whole row toggles (Settings' look).
var dl = ImGuiNET.ImGui.GetWindowDrawList();
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
float labelW = ImGuiNET.ImGui.CalcTextSize(LogToggleLabel).X;
if (ImGuiNET.ImGui.InvisibleButton("##report_attach", new Vector2(Math.Min(w, 18 + labelW), 18)))
_attachLog = !_attachLog;
bool hot = ImGuiNET.ImGui.IsItemHovered();
if (hot) ImGuiNET.ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
ImGuiNET.ImGui.SetItemTooltip("Your RynthCore log helps us see what happened. Untick it to send only what you wrote.");
dl.AddRectFilled(p + new Vector2(0, 3), p + new Vector2(12, 15), _attachLog ? Green : C(0xFF334455), 2);
dl.AddText(p + new Vector2(18, (18 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), hot ? Teal : Text, LogToggleLabel);
LogTail? tail = ProblemReport.Tail;
if (!ReferenceEquals(tail, _describedTail))
{
_describedTail = tail;
_tailText = tail != null ? ProblemReportCore.DescribeTail(tail) : "";
}
string info = ProblemReport.TailLoading ? "Reading the log..."
: tail != null ? _tailText
: ProblemReport.TailError.Length > 0 ? ProblemReport.TailError : "Reading the log...";
Wrapped(info, _attachLog ? Mute : Faded(Mute), w);
Vector2 row = ImGuiNET.ImGui.GetCursorScreenPos();
string view = PhosphorIcons.Eye + " View what will be sent";
string refresh = PhosphorIcons.ArrowsClockwise + " Refresh";
float vw = ButtonWidth(view), rw = ButtonWidth(refresh);
bool canView = tail != null && !ProblemReport.TailLoading;
if (Button("##report_view", view, row, new Vector2(vw, 22), Text, BtnFill, enabled: canView))
ProblemReport.ViewTail(tail!);
ImGuiNET.ImGui.SetItemTooltip("Opens the exact log text that will be sent, in your text editor.");
if (Button("##report_refresh", refresh, new Vector2(row.X + vw + 4, row.Y), new Vector2(rw, 22), Text, BtnFill,
enabled: !ProblemReport.TailLoading))
ProblemReport.RefreshTail();
ImGuiNET.ImGui.SetItemTooltip("Take the log again, up to now.");
NextLine(row, 26);
Note("The log has your character names and some chat in it (your account, Windows user and PC names are hidden). View shows exactly what will be sent.", w);
}
// ── Send ────────────────────────────────────────────────────────────
private void SendRow(float w)
{
ReportState state = ProblemReport.State;
long cooldown = ProblemReport.CooldownLeftMs;
bool sending = state == ReportState.Sending;
bool hasText = _desc[0] != 0;
Vector2 row = ImGuiNET.ImGui.GetCursorScreenPos();
string label = sending ? "Sending..." : "Send report";
float bw = Math.Max(110, ButtonWidth(label));
bool enabled = hasText && !sending && cooldown == 0 && !(_attachLog && ProblemReport.TailLoading);
if (Button("##report_send", label, row, new Vector2(bw, 24), Text, StartBg, enabled: enabled))
StartSend();
if (ImGuiNET.ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled | ImGuiHoveredFlags.ForTooltip))
ImGuiNET.ImGui.SetTooltip(!hasText ? "Write what went wrong first."
: cooldown > 0 ? "One report a minute: " + CooldownText(cooldown)
: "Send this report to the staff.");
NextLine(row, 28);
// The result (only ones from since the panel opened), then the cooldown.
if (_localError.Length > 0)
Wrapped(_localError, Amber, w);
else if (sending || ProblemReport.MessageSeq != _messageSeqAtOpen)
Wrapped(ProblemReport.Message, state switch
{
ReportState.Sent => Green,
ReportState.Failed => Red,
_ => Mute,
}, w);
if (!sending && cooldown > 0)
Wrapped(CooldownText(cooldown), Faded(Mute), w);
}
// "You can send another report in 42 s.", rebuilt once a second rather than every frame.
private long _cooldownShownS = -1;
private string _cooldownText = "";
private string CooldownText(long ms)
{
long sec = (ms + 999) / 1000;
if (sec != _cooldownShownS)
{
_cooldownShownS = sec;
_cooldownText = $"You can send another report in {ProblemReportCore.FormatWait(ms)}.";
}
return _cooldownText;
}
private void StartSend()
{
string description = Utf8(_desc), doing = Utf8(_doing);
LogTail? tail = _attachLog ? ProblemReport.Tail : null;
long seq = ProblemReport.ResultSeq;
if (ProblemReport.Send(description, doing, tail, readTailIfNull: false, announceInChat: false, out string error))
{
_localError = "";
_resultSeqAtSend = seq;
}
else
{
_localError = error;
}
}
// ── Widgets ─────────────────────────────────────────────────────────
/// <summary>A bordered multi-line text box (FaceKit.TextBox's look) with a grey hint while empty.</summary>
private unsafe void MultiLine(string id, byte[] label, byte[] buffer, float width, float height, string hint)
{
Vector2 pos = ImGuiNET.ImGui.GetCursorScreenPos();
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.FrameBg, BtnFill);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, Text);
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Border, BtnBord);
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1f);
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(4, 3));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 3f);
fixed (byte* l = label)
fixed (byte* b = buffer)
{
if (ImGuiNative.igInputTextMultiline(l, b, (uint)buffer.Length, new Vector2(width, height),
ImGuiInputTextFlags.None, null, null) != 0)
_localError = "";
}
bool active = ImGuiNET.ImGui.IsItemActive();
if (active) ImGuiTextFocus.NoteActive(id); // keys stay out of AC
ImGuiNET.ImGui.PopStyleVar(3);
ImGuiNET.ImGui.PopStyleColor(3);
if (buffer[0] == 0 && !active)
ImGuiNET.ImGui.GetWindowDrawList().AddText(pos + new Vector2(5, 3), Faded(Mute), hint);
}
private static void Wrapped(string text, uint color, float w)
{
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, color);
ImGuiNET.ImGui.PushTextWrapPos(ImGuiNET.ImGui.GetCursorPosX() + w);
ImGuiNET.ImGui.TextUnformatted(text);
ImGuiNET.ImGui.PopTextWrapPos();
ImGuiNET.ImGui.PopStyleColor();
}
private static void Note(string text, float w) => Wrapped(text, Faded(Mute), w);
private static uint C(uint argb) => RynthTheme.Argb(argb);
}

View file

@ -115,9 +115,30 @@ internal sealed class SettingsFace : IImGuiPanel
float ty = p.Y + (26 - ImGuiNET.ImGui.GetFontSize()) * 0.5f;
dl.AddText(new Vector2(p.X + 8, ty), sel ? Teal : Mute, TabLabel(tabName));
}
ReportButton(w);
ImGuiNET.ImGui.EndChild();
}
// At the sidebar's foot (below the tabs when they fill it): opens Report a problem.
private static void ReportButton(float w)
{
if (!ImGuiPanelHost.HasFace(ReportFace.Title)) return;
const float h = 26;
float bottom = ImGuiNET.ImGui.GetWindowHeight() - ImGuiNET.ImGui.GetStyle().WindowPadding.Y - h;
ImGuiNET.ImGui.Dummy(new Vector2(0, 6));
if (ImGuiNET.ImGui.GetCursorPosY() < bottom) ImGuiNET.ImGui.SetCursorPosY(bottom);
var dl = ImGuiNET.ImGui.GetWindowDrawList();
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
if (ImGuiNET.ImGui.InvisibleButton("##report", new Vector2(w, h)))
Report.ProblemReport.OpenPanel();
bool hot = ImGuiNET.ImGui.IsItemHovered();
ImGuiNET.ImGui.SetItemTooltip("Tell the staff what went wrong (also /rc report).");
dl.AddRectFilled(p, p + new Vector2(w, h), hot ? Lighten(BtnFill) : BtnFill);
dl.AddRect(p, p + new Vector2(w, h), BtnBord);
dl.AddText(new Vector2(p.X + 8, p.Y + (h - ImGuiNET.ImGui.GetFontSize()) * 0.5f), hot ? Amber : Mute,
PhosphorIcons.Warning + " Report a problem");
}
// ── Content: header + the tab's rows ───────────────────────────────────
private void Content(Vector2 size)

View file

@ -92,6 +92,7 @@ internal static unsafe class PhosphorIcons
public const string Info = "\uE2CE";
public const string Knife = "\uE636";
public const string Lightning = "\uE2DE";
public const string Leaf = "\uE2DA";
public const string ListChecks = "\uEADC";
public const string Lock = "\uE2FA";
public const string LockOpen = "\uE306";
@ -167,7 +168,7 @@ internal static unsafe class PhosphorIcons
+ ArrowCircleUp + Barbell + Brain + GraduationCap + Hourglass + SortDescending + Package
+ Binoculars + Crown + Sun
+ CastleTurret + ClockCounterClockwise + GlobeHemisphereWest + Path + Star + Target + User
+ TextAa;
+ TextAa + Leaf;
/// <summary>
/// Draws <paramref name="glyph"/> (one icon) centred in the box at