Snapshot for release 2026.10.11.1 (internal 4eca83a)
This commit is contained in:
parent
194ea479a0
commit
08b80eed86
94 changed files with 11103 additions and 567 deletions
312
src/RynthCore.Engine/ImGui/Panels/BountiesFace.cs
Normal file
312
src/RynthCore.Engine/ImGui/Panels/BountiesFace.cs
Normal 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";
|
||||
}
|
||||
}
|
||||
485
src/RynthCore.Engine/ImGui/Panels/ChatDiscordFace.cs
Normal file
485
src/RynthCore.Engine/ImGui/Panels/ChatDiscordFace.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
241
src/RynthCore.Engine/ImGui/Panels/ReportFace.cs
Normal file
241
src/RynthCore.Engine/ImGui/Panels/ReportFace.cs
Normal 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);
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue