RynthSuite as of 2026-12-02 (internal a58302e): hotfix 2026.12.2.1
This commit is contained in:
parent
6b5a9c7e99
commit
ba4ea691fe
18 changed files with 263 additions and 148 deletions
|
|
@ -1,174 +0,0 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - Clock/DayNightWindow.cs
|
||||
// The Day/Night timer (2026-11-04, a request on 2026-11-01: a tiny window with
|
||||
// the real minutes until the next day/night change): a sun or a moon, then
|
||||
// "Night in 23m" / "Day in 4m 10s", and the hour's name when there's room.
|
||||
// "—" until the player is in world (the clock can't be read before).
|
||||
// Plugins/Shared/DerethClock.cs has the math; RynthCore hosts the frameless
|
||||
// window (plugin API v90) and remembers where it is.
|
||||
//
|
||||
// A clear background by default (2026-12-01: no box, the sun or moon and the text shadowed, so it
|
||||
// can sit on the radar or under the arrow without taking room); /rdef daynight box brings the
|
||||
// dark box back (DefSettings.DayNightBox). While hovered a faint box shows where to grab it.
|
||||
//
|
||||
// anywhere drag to move; Ctrl+wheel: bigger or smaller (30-250%);
|
||||
// right-click: hide it (/rdef daynight, the bar button, or
|
||||
// Settings > Interface > In The Retail Toolbar's Place show it again).
|
||||
//
|
||||
// AC's render thread; reads the view the tick built (DayNightView) and counts
|
||||
// the seconds down from when it was read, so the seconds move every frame.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Plugin.RynthDefective.ShortcutBar;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.Plugin.Shared.RynthUi;
|
||||
using RynthCore.PluginSdk;
|
||||
using static RynthCore.Plugin.Shared.RynthUi.RynthUi;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Clock;
|
||||
|
||||
/// <summary>The clock as the tick read it; Ready = in world with a usable reading.</summary>
|
||||
internal sealed record DayNightView(bool Ready, DerethNow Now, long ReadAtMs)
|
||||
{
|
||||
public static readonly DayNightView NotReady = new(false, default, 0);
|
||||
|
||||
/// <summary>The real seconds to the change at <paramref name="nowMs"/> (counted down from the reading).</summary>
|
||||
public double SecondsLeft(long nowMs) => Math.Max(0, Now.SecondsToChange - (nowMs - ReadAtMs) / 1000.0);
|
||||
}
|
||||
|
||||
internal sealed class DayNightWindow
|
||||
{
|
||||
public const string Title = "Day/Night";
|
||||
public const string NotInWorld = "—";
|
||||
|
||||
private readonly RynthCoreHost _host;
|
||||
private float _k = 1f, _r = 1f;
|
||||
|
||||
// The label, made again only when the second it shows changes (no string every frame).
|
||||
private long _shownSecond = -1;
|
||||
private bool _shownDay;
|
||||
private string _label = NotInWorld;
|
||||
|
||||
public DayNightWindow(RynthCoreHost host) => _host = host;
|
||||
|
||||
private float Px(float v) => v * _k;
|
||||
private float Fs(ImFontPtr f) => f.FontSize * _r;
|
||||
|
||||
private void Scale()
|
||||
{
|
||||
float fontK = Math.Max(0.5f, Font(RynthUiFont.Ui10).FontSize / 10f);
|
||||
int pct = _host.PanelScale(Title);
|
||||
_k = pct > 0 ? pct / 100f : fontK;
|
||||
_r = _k / fontK;
|
||||
}
|
||||
|
||||
private const float Pad = 5, RowH = 16, Mark = 14, Gap = 4, Radius = 4;
|
||||
|
||||
private static readonly uint SunColor = Argb(0xFFF2C14E), MoonColor = Argb(0xFFB8C7F0);
|
||||
private static readonly uint ShadowColor = Argb(0xD8000000); // under the text and icon on a clear background
|
||||
private static uint A(uint c, float alpha) => WithAlpha(c, (uint)Math.Clamp(MathF.Round(alpha * 255f), 0f, 255f));
|
||||
|
||||
/// <summary>Draws the timer into the host's window; returns the height it needs (pixels).
|
||||
/// <paramref name="box"/>: the dark box; false = a clear background, the text shadowed. Render thread.</summary>
|
||||
public float Draw(DayNightView v, bool box = false)
|
||||
{
|
||||
Scale();
|
||||
uint bg = Color(RynthUiColor.Background), line = Color(RynthUiColor.Hairline);
|
||||
uint text = Color(RynthUiColor.Text), faint = Color(RynthUiColor.Faint);
|
||||
|
||||
Vector2 origin = ImGui.GetCursorScreenPos();
|
||||
origin = new Vector2(MathF.Round(origin.X), MathF.Round(origin.Y));
|
||||
float width = MathF.Floor(ImGui.GetContentRegionAvail().X);
|
||||
float pad = Px(Pad), rowH = Px(RowH);
|
||||
float height = MathF.Ceiling(2 * pad + rowH);
|
||||
if (width < 30) return height;
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
Vector2 max = origin + new Vector2(width, height);
|
||||
if (box)
|
||||
{
|
||||
dl.AddRectFilled(origin, max, A(bg, 0.94f), Px(Radius));
|
||||
dl.AddRect(origin, max, line, Px(Radius));
|
||||
}
|
||||
|
||||
// The whole window is the drag surface.
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.InvisibleButton("##daynight_drag", new Vector2(width, height));
|
||||
_host.PanelDragWithLastItem();
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) _host.SetPanelOpen(Title, RynthPanelOpen.Close);
|
||||
bool hot = ImGui.IsItemHovered();
|
||||
if (!box && hot) dl.AddRectFilled(origin, max, A(bg, 0.45f), Px(Radius)); // where to grab it
|
||||
Vector2 sh = new(MathF.Max(1f, MathF.Round(Px(1))), MathF.Max(1f, MathF.Round(Px(1)))); // the shadow's offset
|
||||
|
||||
long nowMs = Environment.TickCount64;
|
||||
double left = v.Ready ? v.SecondsLeft(nowMs) : 0;
|
||||
string label = Label(v, left);
|
||||
|
||||
// The sun by day, the moon at night (an engine from before the moon was baked: a star).
|
||||
Vector2 at = origin + new Vector2(pad, pad);
|
||||
string icon = !v.Ready || v.Now.IsDay ? RynthIcons.Sun : HasGlyph(RynthIcons.Moon) ? RynthIcons.Moon : RynthIcons.Star;
|
||||
uint iconColor = !v.Ready ? faint : v.Now.IsDay ? SunColor : MoonColor;
|
||||
if (!box) PanelButtonsWindow.DrawIcon(dl, icon, at + sh, new Vector2(Px(Mark), rowH), Px(13), ShadowColor);
|
||||
PanelButtonsWindow.DrawIcon(dl, icon, at, new Vector2(Px(Mark), rowH), Px(13), iconColor);
|
||||
|
||||
ImFontPtr nf = Font(RynthUiFont.NarrowBold11), sf = Font(RynthUiFont.Narrow9);
|
||||
float tx = at.X + Px(Mark) + Px(Gap), right = origin.X + width - pad;
|
||||
float lw = nf.CalcTextSizeA(Fs(nf), float.MaxValue, 0f, label).X;
|
||||
Vector2 labelAt = new(MathF.Round(tx), MathF.Round(at.Y + (rowH - Fs(nf)) * 0.5f));
|
||||
if (!box) dl.AddText(nf, Fs(nf), labelAt + sh, ShadowColor, label);
|
||||
dl.AddText(nf, Fs(nf), labelAt, v.Ready ? text : faint, label);
|
||||
|
||||
// The hour's name, right-aligned, only when it fits whole.
|
||||
if (v.Ready)
|
||||
{
|
||||
string hour = v.Now.HourName;
|
||||
float hw = sf.CalcTextSizeA(Fs(sf), float.MaxValue, 0f, hour).X;
|
||||
if (tx + lw + Px(8) + hw <= right)
|
||||
{
|
||||
Vector2 hourAt = new(MathF.Round(right - hw), MathF.Round(at.Y + (rowH - Fs(sf)) * 0.5f));
|
||||
if (!box) dl.AddText(sf, Fs(sf), hourAt + sh, ShadowColor, hour);
|
||||
dl.AddText(sf, Fs(sf), hourAt, box ? faint : A(text, 0.8f), hour);
|
||||
}
|
||||
}
|
||||
|
||||
if (hot) SafeImGui.SetItemTooltip(Tip(v, left));
|
||||
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.Dummy(new Vector2(width, height));
|
||||
return height;
|
||||
}
|
||||
|
||||
private string Label(DayNightView v, double left)
|
||||
{
|
||||
if (!v.Ready) { _shownSecond = -1; return _label = NotInWorld; }
|
||||
long second = (long)Math.Ceiling(left);
|
||||
if (second != _shownSecond || v.Now.IsDay != _shownDay)
|
||||
{
|
||||
_shownSecond = second;
|
||||
_shownDay = v.Now.IsDay;
|
||||
_label = DerethClock.Label(v.Now, left);
|
||||
}
|
||||
return _label;
|
||||
}
|
||||
|
||||
/// <summary>The tooltip (built only while hovered).</summary>
|
||||
internal static string Tip(DayNightView v, double left)
|
||||
{
|
||||
const string help = "A Dereth day is 2 h 7 min of real time: 63.5 minutes of day, then 63.5 of night.\n"
|
||||
+ "Drag to move; Ctrl+wheel: bigger or smaller; right-click: hide (/rdef daynight).\n"
|
||||
+ "/rdef daynight box: the dark box; /rdef daynight clear: no background.";
|
||||
if (!v.Ready) return "Day or night in Dereth, and the real minutes until it changes. Shown once you're in the world.\n" + help;
|
||||
TimeSpan t = TimeSpan.FromSeconds(Math.Ceiling(left));
|
||||
string until = t.TotalMinutes >= 1 ? $"{(int)t.TotalMinutes} min {t.Seconds} s" : $"{t.Seconds} s";
|
||||
return $"{(v.Now.IsDay ? "Day" : "Night")} now ({v.Now.HourName}). {v.Now.Next} comes at {v.Now.NextHourName}, in {until} of real time.\n" + help;
|
||||
}
|
||||
|
||||
/// <summary>Whether the engine's atlas has <paramref name="glyph"/> (an icon baked after this engine was built isn't).</summary>
|
||||
private static unsafe bool HasGlyph(string glyph)
|
||||
{
|
||||
ImFontPtr font = Font(RynthUiFont.Ui18);
|
||||
return font.NativePtr != null && ImGuiNative.ImFont_FindGlyphNoFallback(font.NativePtr, glyph[0]) != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -121,7 +121,8 @@ internal sealed class DefSettings
|
|||
/// The Day/Night timer's dark box (2026-12-01: a clear background, so it takes no
|
||||
/// room of its own). Off (the default, and what a file from before reads as): the timer
|
||||
/// is drawn on a clear background, its sun or moon and text shadowed so they read over the radar,
|
||||
/// the arrow or the world. On: the dark box as before. /rdef daynight clear | box.
|
||||
/// the arrow or the world. On: the dark box as before. Unused since 2026-12-02: the timer is RynthAi's
|
||||
/// (its own DayNightBox); kept so a settings file from before still loads.
|
||||
/// </summary>
|
||||
public bool DayNightBox;
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -26,25 +26,8 @@ internal static class DefReplies
|
|||
_ => (false, $"The {title} isn't open: open it first (/rdef appraisal), then pop it out."),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// /rdef daynight [show|hide]: the Day/Night timer after it (<paramref name="state"/> as <see cref="Window"/>),
|
||||
/// then the time now when the clock can be read (null = not in world): "Day/Night timer shown. Night now
|
||||
/// (Evensong); day in 23m of real time."
|
||||
/// </summary>
|
||||
public static (bool Ok, string Text) DayNight(int state, DerethNow? now)
|
||||
{
|
||||
string time = now is { } n
|
||||
? $" {(n.IsDay ? "Day" : "Night")} now ({n.HourName}); {n.Next.ToLowerInvariant()} in {DerethClock.Countdown(n.SecondsToChange)} of real time."
|
||||
: "";
|
||||
return state < 0
|
||||
? (false, "This RynthCore has no Day/Night timer window (it needs plugin API v90)." + time)
|
||||
: (true, CommandReply.Shown("Day/Night timer", state == 1) + time);
|
||||
}
|
||||
|
||||
/// <summary>/rdef daynight clear | box: the timer's background after it.</summary>
|
||||
public static (bool Ok, string Text) DayNightLook(bool box) => (true, box
|
||||
? "Day/Night timer: on its dark box (/rdef daynight clear for no background)."
|
||||
: "Day/Night timer: on a clear background (/rdef daynight box brings the dark box back).");
|
||||
/// <summary>/rdef daynight when RynthAi can't take it: the timer is RynthAi's since 2026-12-02.</summary>
|
||||
public const string DayNightMoved = "The Day/Night timer is part of RynthAi now: load RynthAi, then /ra daynight [show|hide|clear|box].";
|
||||
|
||||
/// <summary>A slot's use started (the result shows on the bar; a problem is said in chat).</summary>
|
||||
public static string UseSlot(DefSlot slot, int number) => slot.IsSpell
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ public static unsafe class PluginExports
|
|||
else if (name == RynthDefectivePlugin.SelectionSurface) result = plugin.RenderSelection(out wantH);
|
||||
else if (name == RynthDefectivePlugin.AppraisalSurface) result = plugin.RenderAppraisal(popped, out wantH);
|
||||
else if (name == RynthDefectivePlugin.CorpsesSurface) result = plugin.RenderCorpses(out wantH);
|
||||
else if (name == RynthDefectivePlugin.DayNightSurface) result = plugin.RenderDayNight(out wantH);
|
||||
else if (RynthDefectivePlugin.TryExtraSurface(name, out int extra)) result = plugin.RenderExtraBar(extra, popped, out wantH);
|
||||
else return 0;
|
||||
if (result != 1) return result;
|
||||
|
|
|
|||
|
|
@ -106,11 +106,7 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Skull[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":290,\"height\":80,\"minWidth\":140,\"minHeight\":30,\"bar\":true,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
// Day or night and the real minutes to the change (a bar button of its own; one row, any width).
|
||||
string dayNight = ",{\"id\":\"daynight\",\"title\":\"" + Clock.DayNightWindow.Title + "\",\"surface\":\"" + DayNightSurface +
|
||||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Sun[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":150,\"height\":26,\"minWidth\":70,\"minHeight\":20,\"bar\":true,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
// (The Day/Night timer was here until 2026-12-02; it is RynthAi's now, RynthAiPlugin.DayNight.cs.)
|
||||
// The extra bars (an engine before v100 hosts at most 8 windows for a plugin: these five and up to three
|
||||
// of them; v100 hosts 12, and the Appraisal window makes nine).
|
||||
string extras = "";
|
||||
|
|
@ -119,7 +115,7 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
+ ExtraBar.SurfaceOf(n) + "\",\"icon\":\"\\u" + ((int)RynthIcons.Lightning[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":300,\"height\":80,\"minWidth\":90,\"minHeight\":40,\"bar\":false,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
return "{\"version\":1,\"windows\":[" + bar + panels + selection + appraisal + corpses + dayNight + extras + "]}";
|
||||
return "{\"version\":1,\"windows\":[" + bar + panels + selection + appraisal + corpses + extras + "]}";
|
||||
}
|
||||
|
||||
/// <summary>"window:bar2" ... "window:bar4": an extra bar's surface, and its number.</summary>
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - RynthDefectivePlugin.DayNight.cs
|
||||
// The Day/Night timer (2026-11-04): day or night in Dereth now and the real
|
||||
// time until the next dawn or dusk (Clock/DayNightWindow.cs draws it,
|
||||
// Plugins/Shared/DerethClock.cs has the math).
|
||||
//
|
||||
// The tick reads the game clock twice a second while the window shows, and
|
||||
// only in world: the clock's address isn't readable before world entry, and
|
||||
// a fault there can't be caught (RynthAi's ReadGameClock has the same guard).
|
||||
// Before that the window shows "—".
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using RynthCore.Plugin.RynthDefective.Clock;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective;
|
||||
|
||||
public sealed partial class RynthDefectivePlugin
|
||||
{
|
||||
internal const string DayNightSurface = "window:daynight";
|
||||
|
||||
private DayNightWindow? _dayNightWindow; // render thread
|
||||
private volatile DayNightView _dayNightView = DayNightView.NotReady; // tick writes, render reads
|
||||
private long _dayNightDrawnMs = long.MinValue / 2, _nextDayNightMs;
|
||||
private int _dayNightFailures;
|
||||
|
||||
/// <summary>RynthPluginRenderEmbed "window:daynight". 1 drawn, 0 not ready, -2 failed (three in a row). Render thread.</summary>
|
||||
internal int RenderDayNight(out float wantHeight)
|
||||
{
|
||||
wantHeight = 0;
|
||||
if (!UsesShortcutBar) return 0;
|
||||
System.Threading.Volatile.Write(ref _dayNightDrawnMs, Environment.TickCount64);
|
||||
try
|
||||
{
|
||||
_dayNightWindow ??= new DayNightWindow(Host);
|
||||
wantHeight = _dayNightWindow.Draw(_dayNightView, _session.Settings.DayNightBox);
|
||||
_dayNightFailures = 0;
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Host.Log($"[RynthDefective] day/night draw failed: {ex.GetType().Name}: {ex.Message}");
|
||||
return ++_dayNightFailures >= 3 ? -2 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Plugin tick: the clock's view while the window shows.</summary>
|
||||
private void TickDayNight(long now)
|
||||
{
|
||||
if (!UsesShortcutBar) return;
|
||||
if (now - System.Threading.Volatile.Read(ref _dayNightDrawnMs) > 2000 || now < _nextDayNightMs) return;
|
||||
_nextDayNightMs = now + 500;
|
||||
try { _dayNightView = ReadDayNight(now); }
|
||||
catch (Exception ex) { Host.Log($"[RynthDefective] day/night read failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
|
||||
/// <summary>The clock now; NotReady out of world (never read then) or before the clock is set.</summary>
|
||||
private DayNightView ReadDayNight(long now)
|
||||
{
|
||||
if (!_inWorld || !_identityKnown || Host.GetPlayerId() == 0) return DayNightView.NotReady;
|
||||
long bits = System.Runtime.InteropServices.Marshal.ReadInt64(new IntPtr(unchecked((int)DerethClock.ClockAddress)));
|
||||
double raw = BitConverter.Int64BitsToDouble(bits);
|
||||
return DerethClock.IsUsable(raw) ? new DayNightView(true, DerethClock.At(raw), now) : DayNightView.NotReady;
|
||||
}
|
||||
}
|
||||
|
|
@ -136,7 +136,6 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
_qty.Reset();
|
||||
_qtyWorld?.Reset();
|
||||
_barView = RynthCore.Plugin.RynthDefective.ShortcutBar.BarSnapshot.NotReady;
|
||||
_dayNightView = Clock.DayNightView.NotReady;
|
||||
foreach (UiWindow? w in new[] { _barWindow, _pickerWindow, _settingsWindow })
|
||||
if (w != null) { w.Visible = false; w.NeedsPass = true; }
|
||||
_session.DeclineCopy();
|
||||
|
|
@ -234,22 +233,10 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
else PrintFail("This RynthCore can't show the corpses window (it needs plugin API v90).");
|
||||
break;
|
||||
case DefVerb.DayNight:
|
||||
{
|
||||
if (c.Text is "clear" or "box")
|
||||
{
|
||||
// The timer's background (2026-12-01): kept with the character's settings.
|
||||
_session.Settings.DayNightBox = c.Text == "box";
|
||||
RequestSave();
|
||||
Answer(DefReplies.DayNightLook(_session.Settings.DayNightBox));
|
||||
break;
|
||||
}
|
||||
// The window shown or hidden, and the time now in the reply (an engine without the window: the time only).
|
||||
RynthPanelOpen mode = c.Text == "show" ? RynthPanelOpen.Open : c.Text == "hide" ? RynthPanelOpen.Close : RynthPanelOpen.Toggle;
|
||||
int state = UsesShortcutBar ? Host.SetPanelOpen(Clock.DayNightWindow.Title, mode) : -1;
|
||||
Clock.DayNightView clock = ReadDayNight(Environment.TickCount64);
|
||||
Answer(DefReplies.DayNight(state, clock.Ready ? clock.Now : null));
|
||||
// The Day/Night timer is RynthAi's since 2026-12-02 (R-20261202-122606-0b16): handed over, RynthAi answers.
|
||||
if (!(Host.HasSendPluginCommand && Host.SendPluginCommand("RynthAi", "daynight", c.Text)))
|
||||
PrintFail(DefReplies.DayNightMoved);
|
||||
break;
|
||||
}
|
||||
case DefVerb.Panels:
|
||||
if (UsesPanelButtons) Answer(DefReplies.Window("Game Panels buttons", Host.SetPanelOpen(RynthCore.Plugin.RynthDefective.ShortcutBar.PanelButtonsWindow.Title, RynthPanelOpen.Toggle)));
|
||||
else PrintFail("This RynthCore can't open the game's panels from buttons (it needs plugin API v90).");
|
||||
|
|
@ -501,7 +488,6 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
TickAppraisal(now);
|
||||
TickQuantity(now);
|
||||
TickCorpses(now);
|
||||
TickDayNight(now);
|
||||
|
||||
// With the shortcut bar the old script-window bar stays shut (the weapon picker is still one), and
|
||||
// has no RynthBar button (one that opened a window shut again at once). Its settings have their
|
||||
|
|
|
|||
Loading…
Reference in a new issue