From 6cbddf414b501cd1765c8242101bab4c15d0edd5 Mon Sep 17 00:00:00 2001 From: xorus Date: Sun, 30 Jun 2024 12:06:47 +0200 Subject: [PATCH 1/4] update for api 10 changes and font stuff, comment out texture stuff for now, addon visibility flag might not work --- Plugin/Configuration/ConfigurationFile.cs | 2 +- .../FloatingWindowConfiguration.cs | 5 + Plugin/Game/AddonHider.cs | 6 +- Plugin/Plugin.cs | 9 +- Plugin/Status/CombatAlarm.cs | 15 +- Plugin/Status/CombatStopwatch.cs | 3 +- Plugin/Ui/DtrBarUi.cs | 7 +- Plugin/Ui/FloatingWindow.cs | 85 +---------- Plugin/Ui/FloatingWindowFont.cs | 65 ++++++++ Plugin/Ui/NumberTextures.cs | 142 +++++++++--------- Plugin/Ui/PluginUi.cs | 1 - Plugin/Ui/SettingsTab/CountdownTab.cs | 13 +- Plugin/Ui/SettingsTab/FloatingWindowTab.cs | 48 +++++- 13 files changed, 229 insertions(+), 172 deletions(-) create mode 100644 Plugin/Ui/FloatingWindowFont.cs diff --git a/Plugin/Configuration/ConfigurationFile.cs b/Plugin/Configuration/ConfigurationFile.cs index 68241cf..cd32c4e 100644 --- a/Plugin/Configuration/ConfigurationFile.cs +++ b/Plugin/Configuration/ConfigurationFile.cs @@ -32,7 +32,7 @@ public enum TextAlign } // Add any other properties or methods here. - [NonSerialized] private DalamudPluginInterface _pluginInterface = Plugin.PluginInterface; + [NonSerialized] private IDalamudPluginInterface _pluginInterface = Plugin.PluginInterface; public CountdownConfiguration Countdown = new(); public DtrConfiguration Dtr = new(); diff --git a/Plugin/Configuration/FloatingWindowConfiguration.cs b/Plugin/Configuration/FloatingWindowConfiguration.cs index 942d7fd..f741dee 100644 --- a/Plugin/Configuration/FloatingWindowConfiguration.cs +++ b/Plugin/Configuration/FloatingWindowConfiguration.cs @@ -16,7 +16,9 @@ #nullable enable using System; using System.Numerics; +using System.Text.Json.Serialization; using Dalamud.Interface.Colors; +using Dalamud.Interface.FontIdentifier; using EngageTimer.Attributes; using EngageTimer.Ui; @@ -81,6 +83,9 @@ public class FloatingWindowConfiguration public ConfigurationFile.TextAlign Align { get; set; } = ConfigurationFile.TextAlign.Left; public int FontSize { get; set; } = 16; + + [JsonIgnore] public IFontSpec? FontSpec { get; set; } = null; + public IFontId? FontId { get; set; } = null; [AutoField("Settings_FWTab_AutoHide_Left")] public bool AutoHide { get; set; } = true; diff --git a/Plugin/Game/AddonHider.cs b/Plugin/Game/AddonHider.cs index a19dfa1..3074373 100644 --- a/Plugin/Game/AddonHider.cs +++ b/Plugin/Game/AddonHider.cs @@ -46,7 +46,8 @@ private unsafe void ShowAddonNearEnd(object? sender, EventArgs eventArgs) try { var atkUnitBase = (AtkUnitBase*)_lastCountdownAddon; - atkUnitBase->Flags |= VisibleFlag; + atkUnitBase->IsVisible = true; + // atkUnitBase->Flags |= VisibleFlag; // Plugin.Logger.Debug("show addon"); } catch (Exception) @@ -74,7 +75,8 @@ private unsafe void HideAddon(AddonEvent type, AddonArgs args) try { var atkUnitBase = (AtkUnitBase*)addon; - atkUnitBase->Flags = (byte)(atkUnitBase->Flags & ~VisibleFlag); + atkUnitBase->IsVisible = false; + // atkUnitBase->Flags = (byte)(atkUnitBase->Flags & ~VisibleFlag); // Plugin.Logger.Debug("hide addon"); } catch (Exception) diff --git a/Plugin/Plugin.cs b/Plugin/Plugin.cs index ba36161..3287c7e 100644 --- a/Plugin/Plugin.cs +++ b/Plugin/Plugin.cs @@ -30,7 +30,7 @@ namespace EngageTimer; [PublicAPI] public sealed class Plugin : IDalamudPlugin { - [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] public static IDalamudPluginInterface PluginInterface { get; private set; } = null!; [PluginService] public static IGameGui GameGui { get; private set; } = null!; [PluginService] public static ICommandManager Commands { get; private set; } = null!; [PluginService] public static ICondition Condition { get; private set; } = null!; @@ -42,6 +42,8 @@ public sealed class Plugin : IDalamudPlugin [PluginService] public static IPluginLog Logger { get; private set; } = null!; [PluginService] public static IAddonLifecycle AddonLifecycle { get; private set; } = null!; [PluginService] public static IToastGui ToastGui { get; private set; } = null!; + [PluginService] public static INotificationManager NotificationManager { get; private set; } = null!; + [PluginService] public static ITextureProvider TextureProvider { get; private set; } = null!; public static ConfigurationFile Config { get; private set; } = null!; public static State State { get; private set; } = null!; public static PluginUi PluginUi { get; private set; } = null!; @@ -52,8 +54,9 @@ public sealed class Plugin : IDalamudPlugin private static SettingsCommand SettingsCommand { get; set; } = null!; public static CombatAlarm CombatAlarm { get; set; } = null!; public static SfxPlay SfxPlay { get; set; } = null!; + public static FloatingWindowFont FloatingWindowFont { get; set; } = null!; - public Plugin(DalamudPluginInterface pluginInterface) + public Plugin(IDalamudPluginInterface pluginInterface) { PluginPath = PluginInterface.AssemblyLocation.DirectoryName ?? throw new InvalidOperationException("Cannot find plugin directory"); @@ -63,6 +66,7 @@ public Plugin(DalamudPluginInterface pluginInterface) FrameworkThings = new FrameworkThings(); MainCommand = new MainCommand(); SettingsCommand = new SettingsCommand(); + FloatingWindowFont = new FloatingWindowFont(); PluginUi = new PluginUi(); CombatAlarm = new CombatAlarm(); SfxPlay = new SfxPlay(); @@ -77,5 +81,6 @@ void IDisposable.Dispose() FrameworkThings.Dispose(); MainCommand.Dispose(); SettingsCommand.Dispose(); + FloatingWindowFont.Dispose(); } } \ No newline at end of file diff --git a/Plugin/Status/CombatAlarm.cs b/Plugin/Status/CombatAlarm.cs index c3e59b1..173f930 100644 --- a/Plugin/Status/CombatAlarm.cs +++ b/Plugin/Status/CombatAlarm.cs @@ -18,7 +18,7 @@ using System.IO; using System.Linq; using Dalamud.Game.Text; -using Dalamud.Interface.Internal.Notifications; +using Dalamud.Interface.ImGuiNotification; using Dalamud.Plugin.Services; using EngageTimer.Configuration; using EngageTimer.Game; @@ -179,11 +179,14 @@ public static void AlarmText(CombatAlarmsConfiguration.Alarm alarm) switch (alarm.TextType) { case CombatAlarmsConfiguration.TextType.DalamudNotification: - Plugin.PluginInterface.UiBuilder.AddNotification( - trimText, - "EngageTimer", - NotificationType.Info, - 8000 + Plugin.NotificationManager.AddNotification( + new Notification() + { + Content = trimText, + Title ="EngageTimer", + Type = NotificationType.Info, + InitialDuration = TimeSpan.FromSeconds(8.0) + } ); break; case CombatAlarmsConfiguration.TextType.GameToast: diff --git a/Plugin/Status/CombatStopwatch.cs b/Plugin/Status/CombatStopwatch.cs index a4fcf54..e3da2db 100644 --- a/Plugin/Status/CombatStopwatch.cs +++ b/Plugin/Status/CombatStopwatch.cs @@ -19,6 +19,7 @@ using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Plugin.Services; using EngageTimer.Configuration; +using FFXIVClientStructs.FFXIV.Client.Game.Character; namespace EngageTimer.Status; @@ -43,7 +44,7 @@ public void UpdateEncounterTimer() // if anyone in the party is in combat foreach (var actor in Plugin.PartyList) { - if (actor.GameObject is not Character character || + if (actor.GameObject is not ICharacter character || (character.StatusFlags & StatusFlags.InCombat) == 0) continue; inCombat = true; break; diff --git a/Plugin/Ui/DtrBarUi.cs b/Plugin/Ui/DtrBarUi.cs index ae3ecb5..68b8261 100644 --- a/Plugin/Ui/DtrBarUi.cs +++ b/Plugin/Ui/DtrBarUi.cs @@ -21,7 +21,7 @@ namespace EngageTimer.Ui; public sealed class DtrBarUi : IDisposable { - private DtrBarEntry? _entry; + private IDtrBarEntry? _entry; public DtrBarUi() { @@ -31,10 +31,10 @@ public DtrBarUi() public void Dispose() { - _entry?.Dispose(); + _entry?.Remove(); } - private DtrBarEntry? GetEntry() + private IDtrBarEntry? GetEntry() { const string dtrBarTitle = "EngageTimer stopwatch"; var dtrBar = Plugin.DtrBar; @@ -89,6 +89,7 @@ public void Update() if (_entry is { Shown: true }) _entry.Shown = false; return; } + if (!_entry.Shown) _entry.Shown = true; var seString = (SeString)(Plugin.Config.Dtr.CombatTimePrefix + diff --git a/Plugin/Ui/FloatingWindow.cs b/Plugin/Ui/FloatingWindow.cs index f569dce..6103edc 100644 --- a/Plugin/Ui/FloatingWindow.cs +++ b/Plugin/Ui/FloatingWindow.cs @@ -15,34 +15,20 @@ using System; using System.Globalization; -using System.IO; using System.Numerics; -using Dalamud.Interface; using EngageTimer.Configuration; -using EngageTimer.Status; using ImGuiNET; namespace EngageTimer.Ui; -public sealed class FloatingWindow : IDisposable +public sealed class FloatingWindow { private const float WindowPadding = 5f; - private bool _firstLoad = true; - private ImFontPtr _font; - private ImFontGlyphRangesBuilderPtr? _grBuilder; - private float _maxTextWidth; private float _paddingLeft; private float _paddingRight; private bool _stopwatchVisible; - private bool _triggerFontRebuild = true; - private bool _useFont; - - public FloatingWindow() - { - Plugin.PluginInterface.UiBuilder.BuildFonts += BuildFont; - } public bool StopwatchVisible { @@ -50,32 +36,18 @@ public bool StopwatchVisible set => _stopwatchVisible = value; } - public void Dispose() - { - Plugin.PluginInterface.UiBuilder.BuildFonts -= BuildFont; - _grBuilder?.Destroy(); - Plugin.PluginInterface.UiBuilder.RebuildFonts(); - } - public void Draw() { if (!Plugin.Config.FloatingWindow.Display) return; - if (_triggerFontRebuild) - { - Plugin.PluginInterface.UiBuilder.RebuildFonts(); - return; - } - var stopwatchActive = StopwatchActive(); var countdownActive = CountdownActive(); - if (!_firstLoad && !stopwatchActive && !countdownActive) return; + if (!stopwatchActive && !countdownActive) return; - if (_useFont && _font.IsLoaded()) ImGui.PushFont(_font); - DrawWindow(stopwatchActive, countdownActive); - if (_useFont && _font.IsLoaded()) ImGui.PopFont(); - - if (_firstLoad) _firstLoad = false; + using (Plugin.FloatingWindowFont.FontHandle?.Push()) + { + DrawWindow(stopwatchActive, countdownActive); + } } private static bool StopwatchActive() @@ -194,7 +166,6 @@ private void DrawWindow(bool stopwatchActive, bool countdownActive) _paddingRight = 0f; } - var size = ImGui.CalcTextSize(text); ImGui.SetCursorPosY(0f); ImGui.SetCursorPosX(_paddingLeft + WindowPadding); @@ -218,48 +189,4 @@ private void DrawWindow(bool stopwatchActive, bool countdownActive) ImGui.PopStyleColor(); if (pushVar) ImGui.PopStyleVar(); } - - - /** - * UI font code adapted from ping plugin by karashiiro - * https://github.com/karashiiro/PingPlugin/blob/feex/PingPlugin/PingUI.cs - */ - private unsafe void BuildFont() - { - _triggerFontRebuild = false; - - _grBuilder?.Destroy(); - try - { - // attempt to load the correct font (I'm only using numbers anyway) - string[] fonts = { "NotoSansCJKsc-Medium.otf", "NotoSansCJKjp-Medium.otf" }; - string? filePath = null; - foreach (var font in fonts) - { - filePath = Path.Combine(Plugin.PluginInterface.DalamudAssetDirectory.FullName, "UIRes", font); - if (File.Exists(filePath)) break; - filePath = null; - } - - if (filePath == null) throw new FileNotFoundException("Font file not found!"); - - var grBuilder = - new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); - // the "z" at the end of this range is still required because of a dalamud issue that somehow removes the - // ":" from my text range. - grBuilder.AddText("-0123456789:.z"); - grBuilder.BuildRanges(out var ranges); - _font = ImGui.GetIO().Fonts.AddFontFromFileTTF(filePath, - Math.Max(8, Plugin.Config.FloatingWindow.FontSize), - null, ranges.Data); - - _grBuilder = grBuilder; - } - catch (Exception e) - { - Plugin.Logger.Error(e.Message); - } - - _useFont = true; - } } \ No newline at end of file diff --git a/Plugin/Ui/FloatingWindowFont.cs b/Plugin/Ui/FloatingWindowFont.cs new file mode 100644 index 0000000..0c1b41b --- /dev/null +++ b/Plugin/Ui/FloatingWindowFont.cs @@ -0,0 +1,65 @@ +// This file is part of EngageTimer +// Copyright (C) 2024 Xorus +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +using System; +using Dalamud.Interface.ManagedFontAtlas; + +namespace EngageTimer.Ui; + +public sealed class FloatingWindowFont : IDisposable +{ + public IFontHandle? FontHandle { get; private set; } + + public FloatingWindowFont() + { + UpdateFont(); + } + + public void UpdateFont() + { + this.FontHandle?.Dispose(); + this.FontHandle = Plugin.PluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e => e.OnPreBuild(tk => + { + // tk.AddDalamudDefaultFont( + // Math.Max(8, Plugin.Config.FloatingWindow.FontSize), + // FontAtlasBuildToolkitUtilities.ToGlyphRange([ + // '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '.' + // ]) + // ); + // var spec = (SingleFontSpec)(Plugin.Config.FloatingWindow.FontSpec ?? + // Plugin.PluginInterface.UiBuilder.DefaultFontSpec); + // var specWithRanges = new SingleFontSpec() + // { + // FontId = spec.FontId, + // SizePx = spec.SizePx, + // SizePt = spec.SizePt, + // GlyphOffset = spec.GlyphOffset, + // LetterSpacing = spec.LetterSpacing, + // LineHeight = spec.LineHeight, + // GlyphRanges = FontAtlasBuildToolkitUtilities.ToGlyphRange([ + // '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '.' + // ]) + // }; + + var spec = Plugin.Config.FloatingWindow.FontSpec ?? Plugin.PluginInterface.UiBuilder.DefaultFontSpec; + spec.AddToBuildToolkit(tk); + })); + } + + public void Dispose() + { + FontHandle?.Dispose(); + } +} \ No newline at end of file diff --git a/Plugin/Ui/NumberTextures.cs b/Plugin/Ui/NumberTextures.cs index 269f83f..b7ca8fe 100644 --- a/Plugin/Ui/NumberTextures.cs +++ b/Plugin/Ui/NumberTextures.cs @@ -19,6 +19,7 @@ using System.Linq; using Dalamud.Interface; using Dalamud.Interface.Internal; +using Dalamud.Interface.Textures.TextureWraps; using EngageTimer.Configuration; using EngageTimer.Ui.Color; using Newtonsoft.Json; @@ -33,13 +34,15 @@ public sealed class NumberTextures private readonly Dictionary _numberImages = new(); private readonly Dictionary _numberTextures = new(); private readonly Dictionary _numberTexturesAlt = new(); - private readonly UiBuilder _uiBuilder = Plugin.PluginInterface.UiBuilder; + private readonly IUiBuilder _uiBuilder = Plugin.PluginInterface.UiBuilder; public double LastTextureCreationDuration = 0d; public NumberTextures() { - _error = _uiBuilder.LoadImage(Path.Combine(Plugin.PluginPath, "Data", "error.png")); + // _error = Plugin.TextureProvider..LoadImage(Path.Combine(Plugin.PluginPath, "Data", "error.png")); + + // Plugin.TextureProvider.CreateFromImageAsync(Path.Combine(Plugin.PluginPath, "Data", "error.png")) Load(); } @@ -59,6 +62,7 @@ public void Load() private void LoadImages() { + return; _numberImages.Clear(); string texturePath; @@ -99,6 +103,7 @@ private void LoadImages() private void ReadPackSettings(string settingsFile) { + return; try { var json = File.ReadAllText(settingsFile); @@ -140,72 +145,73 @@ private void ReadPackSettings(string settingsFile) public void CreateTextures() { - var watch = System.Diagnostics.Stopwatch.StartNew(); - MaxTextureHeight = 0; - MaxTextureWidth = 0; - - var success = false; - for (var i = 0; i < 10; i++) - { - if (_numberImages.ContainsKey(i)) - try - { - var image = _numberImages[i]; - var bytes = image.Data.ToArray(); - var bytesAlt = new byte[bytes.Length]; - var configuration = Plugin.Config; - if (image.NumChannels == 4) - for (var p = 0; p < bytes.Length; p += 4) - { - var originalRgb = new HslConv.Rgb(bytes[p], bytes[p + 1], bytes[p + 2]); - var hsl = HslConv.RgbToHsl(originalRgb); - if (configuration.Countdown.NumberRecolorMode) - hsl.H = Math.Clamp(configuration.Countdown.Hue, 0, 360); - else - hsl.H += configuration.Countdown.Hue; - hsl.S = Math.Clamp(hsl.S + configuration.Countdown.Saturation, 0f, 1f); - hsl.L = Math.Clamp(hsl.L + configuration.Countdown.Luminance, 0f, 1f); - var modifiedRgb = HslConv.HslToRgb(hsl); - bytes[p] = modifiedRgb.R; - bytes[p + 1] = modifiedRgb.G; - bytes[p + 2] = modifiedRgb.B; - - if (!configuration.Countdown.Animate) continue; - var hslAlt = new HslConv.Hsl(hsl.H, hsl.S, hsl.L); - hslAlt.L = Math.Clamp(hslAlt.L + .3f, 0f, 1f); - var modifiedRgbAlt = HslConv.HslToRgb(hslAlt); - bytesAlt[p] = modifiedRgbAlt.R; - bytesAlt[p + 1] = modifiedRgbAlt.G; - bytesAlt[p + 2] = modifiedRgbAlt.B; - bytesAlt[p + 3] = bytes[p + 3]; - } - - var texture = _uiBuilder.LoadImageRaw(bytes, image.Width, image.Height, image.NumChannels); - var textureAlt = - _uiBuilder.LoadImageRaw(bytesAlt, image.Width, image.Height, image.NumChannels); - - MaxTextureHeight = Math.Max(MaxTextureHeight, texture.Height); - MaxTextureWidth = Math.Max(MaxTextureWidth, texture.Width); - _numberTextures.Remove(i); - _numberTextures.Add(i, texture); - success = true; - - if (!configuration.Countdown.Animate) continue; - _numberTexturesAlt.Remove(i); - _numberTexturesAlt.Add(i, textureAlt); - } - catch (Exception) - { - // a loading error occured - } - - if (success) continue; - MaxTextureWidth = _error.Width; - MaxTextureHeight = _error.Height; - } - - watch.Stop(); - LastTextureCreationDuration = watch.ElapsedMilliseconds / 1000d; + return; + // var watch = System.Diagnostics.Stopwatch.StartNew(); + // MaxTextureHeight = 0; + // MaxTextureWidth = 0; + // + // var success = false; + // for (var i = 0; i < 10; i++) + // { + // if (_numberImages.ContainsKey(i)) + // try + // { + // var image = _numberImages[i]; + // var bytes = image.Data.ToArray(); + // var bytesAlt = new byte[bytes.Length]; + // var configuration = Plugin.Config; + // if (image.NumChannels == 4) + // for (var p = 0; p < bytes.Length; p += 4) + // { + // var originalRgb = new HslConv.Rgb(bytes[p], bytes[p + 1], bytes[p + 2]); + // var hsl = HslConv.RgbToHsl(originalRgb); + // if (configuration.Countdown.NumberRecolorMode) + // hsl.H = Math.Clamp(configuration.Countdown.Hue, 0, 360); + // else + // hsl.H += configuration.Countdown.Hue; + // hsl.S = Math.Clamp(hsl.S + configuration.Countdown.Saturation, 0f, 1f); + // hsl.L = Math.Clamp(hsl.L + configuration.Countdown.Luminance, 0f, 1f); + // var modifiedRgb = HslConv.HslToRgb(hsl); + // bytes[p] = modifiedRgb.R; + // bytes[p + 1] = modifiedRgb.G; + // bytes[p + 2] = modifiedRgb.B; + // + // if (!configuration.Countdown.Animate) continue; + // var hslAlt = new HslConv.Hsl(hsl.H, hsl.S, hsl.L); + // hslAlt.L = Math.Clamp(hslAlt.L + .3f, 0f, 1f); + // var modifiedRgbAlt = HslConv.HslToRgb(hslAlt); + // bytesAlt[p] = modifiedRgbAlt.R; + // bytesAlt[p + 1] = modifiedRgbAlt.G; + // bytesAlt[p + 2] = modifiedRgbAlt.B; + // bytesAlt[p + 3] = bytes[p + 3]; + // } + // + // var texture = _uiBuilder.LoadImageRaw(bytes, image.Width, image.Height, image.NumChannels); + // var textureAlt = + // _uiBuilder.LoadImageRaw(bytesAlt, image.Width, image.Height, image.NumChannels); + // + // MaxTextureHeight = Math.Max(MaxTextureHeight, texture.Height); + // MaxTextureWidth = Math.Max(MaxTextureWidth, texture.Width); + // _numberTextures.Remove(i); + // _numberTextures.Add(i, texture); + // success = true; + // + // if (!configuration.Countdown.Animate) continue; + // _numberTexturesAlt.Remove(i); + // _numberTexturesAlt.Add(i, textureAlt); + // } + // catch (Exception) + // { + // // a loading error occured + // } + // + // if (success) continue; + // MaxTextureWidth = _error.Width; + // MaxTextureHeight = _error.Height; + // } + // + // watch.Stop(); + // LastTextureCreationDuration = watch.ElapsedMilliseconds / 1000d; } public IDalamudTextureWrap GetTexture(int i) diff --git a/Plugin/Ui/PluginUi.cs b/Plugin/Ui/PluginUi.cs index 619531f..4c78dd4 100644 --- a/Plugin/Ui/PluginUi.cs +++ b/Plugin/Ui/PluginUi.cs @@ -37,7 +37,6 @@ public PluginUi() public void Dispose() { - _floatingWindow.Dispose(); _countDown.Dispose(); Plugin.PluginInterface.UiBuilder.Draw -= Draw; Plugin.PluginInterface.UiBuilder.OpenConfigUi -= OpenSettings; diff --git a/Plugin/Ui/SettingsTab/CountdownTab.cs b/Plugin/Ui/SettingsTab/CountdownTab.cs index 0ac122a..0ba793d 100644 --- a/Plugin/Ui/SettingsTab/CountdownTab.cs +++ b/Plugin/Ui/SettingsTab/CountdownTab.cs @@ -42,7 +42,7 @@ public static void DebounceTextureCreation() if (time - _lastTextureCreation < .05d + Plugin.NumberTextures.LastTextureCreationDuration) return; // 50ms + previous time taken _lastTextureCreation = time; - Plugin.NumberTextures.CreateTextures(); + // Plugin.NumberTextures.CreateTextures(); _requestTextureCreation = false; } @@ -57,7 +57,7 @@ public static void UpdateMock() if (_mockTarget == 0 || _mockTarget < ImGui.GetTime()) _mockTarget = ImGui.GetTime() + 30d; Plugin.State.CountingDown = true; - Plugin.State.CountDownValue = (float) (_mockTarget - ImGui.GetTime()); + Plugin.State.CountDownValue = (float)(_mockTarget - ImGui.GetTime()); } public static void OnClose() @@ -202,7 +202,7 @@ private static void CountdownPositionAndSize() if (ImGui.DragFloat("Settings_CountdownTab_OffsetX".TrId(), ref countdownOffsetX, .1f)) { Plugin.Config.Countdown.WindowOffset = - Plugin.Config.Countdown.WindowOffset with {X = countdownOffsetX / 100}; + Plugin.Config.Countdown.WindowOffset with { X = countdownOffsetX / 100 }; Plugin.Config.Save(); } @@ -212,7 +212,7 @@ private static void CountdownPositionAndSize() if (ImGui.DragFloat("Settings_CountdownTab_OffsetY".TrId(), ref countdownOffsetY, .1f)) { Plugin.Config.Countdown.WindowOffset = - Plugin.Config.Countdown.WindowOffset with {Y = countdownOffsetY / 100}; + Plugin.Config.Countdown.WindowOffset with { Y = countdownOffsetY / 100 }; Plugin.Config.Save(); } @@ -236,13 +236,13 @@ private static void CountdownPositionAndSize() ImGui.PopItemWidth(); - var align = (int) Plugin.Config.Countdown.Align; + var align = (int)Plugin.Config.Countdown.Align; if (ImGui.Combo("Settings_CountdownTab_CountdownAlign".TrId(), ref align, "Settings_FWTab_TextAlign_Left".Tr() + "###Left\0" + "Settings_FWTab_TextAlign_Center".Tr() + "###Center\0" + "Settings_FWTab_TextAlign_Right".Tr() + "###Right")) { - Plugin.Config.Countdown.Align = (ConfigurationFile.TextAlign) align; + Plugin.Config.Countdown.Align = (ConfigurationFile.TextAlign)align; Plugin.Config.Save(); } @@ -252,6 +252,7 @@ private static void CountdownPositionAndSize() private static void CountdownNumberStyle() { + return; var texture = Plugin.NumberTextures.GetTexture(_exampleNumber); const float scale = .5f; ImGui.BeginGroup(); diff --git a/Plugin/Ui/SettingsTab/FloatingWindowTab.cs b/Plugin/Ui/SettingsTab/FloatingWindowTab.cs index 0d56eb1..8d73bad 100644 --- a/Plugin/Ui/SettingsTab/FloatingWindowTab.cs +++ b/Plugin/Ui/SettingsTab/FloatingWindowTab.cs @@ -14,7 +14,11 @@ // along with this program. If not, see . using System; +using System.Threading.Tasks; +using Dalamud.Interface; using Dalamud.Interface.Components; +using Dalamud.Interface.FontIdentifier; +using Dalamud.Interface.ImGuiFontChooserDialog; using EngageTimer.Configuration; using EngageTimer.Localization; using EngageTimer.Properties; @@ -24,6 +28,8 @@ namespace EngageTimer.Ui.SettingsTab; public static class FloatingWindowTab { + private static SingleFontChooserDialog? _fc; + public static void Draw() { ImGui.PushTextWrapPos(); @@ -81,13 +87,13 @@ private static void FwStyling() Components.AutoField(Plugin.Config.FloatingWindow, "Scale"); var configuration = Plugin.Config; - var textAlign = (int) configuration.FloatingWindow.Align; + var textAlign = (int)configuration.FloatingWindow.Align; if (ImGui.Combo(Translator.TrId("Settings_FWTab_TextAlign"), ref textAlign, Strings.Settings_FWTab_TextAlign_Left + "###Left\0" + Strings.Settings_FWTab_TextAlign_Center + "###Center\0" + Strings.Settings_FWTab_TextAlign_Right + "###Right")) { - configuration.FloatingWindow.Align = (ConfigurationFile.TextAlign) textAlign; + configuration.FloatingWindow.Align = (ConfigurationFile.TextAlign)textAlign; configuration.Save(); } @@ -97,7 +103,7 @@ private static void FwStyling() configuration.FloatingWindow.FontSize = Math.Max(0, fontSize); configuration.Save(); - if (configuration.FloatingWindow.FontSize >= 8) Plugin.PluginInterface.UiBuilder.RebuildFonts(); + // if (configuration.FloatingWindow.FontSize >= 8) Plugin.PluginInterface.UiBuilder.RebuildFonts(); } ImGui.EndGroup(); @@ -108,6 +114,42 @@ private static void FwStyling() Components.AutoField(Plugin.Config.FloatingWindow, "ForceHideWindowBorder"); ImGui.EndGroup(); + ImGui.Text("Font:"); + ImGui.SameLine(); + using (Plugin.FloatingWindowFont.FontHandle?.Push()) + { + if (configuration.FloatingWindow.FontSpec == null) + ImGui.Text("default"); + else + ImGui.Text(configuration.FloatingWindow.FontSpec.ToString()); + } + + if (ImGui.Button("change font") && !_fcO) + { + _fc = SingleFontChooserDialog.CreateAuto((UiBuilder)Plugin.PluginInterface.UiBuilder); + _fcO = true; + _fc.PreviewText = "-01:23.45 6789"; + _fc.ResultTask.ContinueWith(task => + { + _fcO = false; + if (!task.IsCompleted) return; + configuration.FloatingWindow.FontId = _fc.SelectedFont.FontId; + + configuration.Save(); + Plugin.FloatingWindowFont.UpdateFont(); + }); + } + + ImGui.SameLine(); + if (ImGui.Button("reset font")) + { + configuration.FloatingWindow.FontSpec = null; + configuration.Save(); + Plugin.FloatingWindowFont.UpdateFont(); + } + ImGui.Unindent(); } + + private static bool _fcO = false; } \ No newline at end of file From 053c6129a468461f87f17617581c4cb8b39be87d Mon Sep 17 00:00:00 2001 From: xorus Date: Wed, 3 Jul 2024 12:49:35 +0200 Subject: [PATCH 2/4] fix pointer --- Plugin/EngageTimer.csproj | 2 +- Plugin/Game/CountdownHook.cs | 55 ++++++++---------------------------- Plugin/packages.lock.json | 6 ++-- 3 files changed, 15 insertions(+), 48 deletions(-) diff --git a/Plugin/EngageTimer.csproj b/Plugin/EngageTimer.csproj index 27992e7..c580eb3 100644 --- a/Plugin/EngageTimer.csproj +++ b/Plugin/EngageTimer.csproj @@ -67,7 +67,7 @@ - + diff --git a/Plugin/Game/CountdownHook.cs b/Plugin/Game/CountdownHook.cs index b87e913..f642108 100644 --- a/Plugin/Game/CountdownHook.cs +++ b/Plugin/Game/CountdownHook.cs @@ -23,31 +23,24 @@ /* * Based on the work (for finding the pointer) of https://github.com/Haplo064/Europe + * 7.0 function changes taken from https://github.com/DelvUI/DelvUI/commit/492211c8f43b813d10b2220e6fe768ac508dcede and + * https://discord.com/channels/581875019861328007/653504487352303619/1257920418388639774. Thanks Tischel for that work! */ namespace EngageTimer.Game; public sealed class CountdownHook : IDisposable { - [Signature("48 89 5C 24 ?? 57 48 83 EC 40 8B 41", DetourName = nameof(CountdownTimerFunc))] + [Signature("40 53 48 83 EC 40 80 79 38 00", DetourName = nameof(CountdownTimerFunc))] private readonly Hook? _countdownTimerHook = null; private readonly State _state; - private ulong _countDown; - private bool _countDownRunning; - - /// - /// Ticks since the timer stalled - /// - private int _countDownStallTicks; - - private float _lastCountDownValue; - + private ulong _paramValue; public CountdownHook() { _state = Plugin.State; - _countDown = 0; + _paramValue = 0; Plugin.GameInterop.InitializeFromAttributes(this); _countdownTimerHook?.Enable(); } @@ -61,7 +54,7 @@ public void Dispose() private IntPtr CountdownTimerFunc(ulong value) { - _countDown = value; + _paramValue = value; return _countdownTimerHook!.Original(value); } @@ -74,37 +67,11 @@ public void Update() private void UpdateCountDown() { - var newCountingDown = false; - if (_countDown == 0) - { - _state.CountingDown = newCountingDown; - return; - } - - var countDownPointerValue = Marshal.PtrToStructure((IntPtr)_countDown + 0x2c); - - // is last value close enough (workaround for floating point approx) - if (Math.Abs(countDownPointerValue - _lastCountDownValue) < 0.001f) - { - _countDownStallTicks++; - } - else - { - _countDownStallTicks = 0; - _countDownRunning = true; - } - - if (_countDownStallTicks > 50) _countDownRunning = false; - - if (countDownPointerValue > 0 && _countDownRunning) - { - var newValue = Marshal.PtrToStructure((IntPtr)_countDown + 0x2c); - _state.CountDownValue = newValue; - newCountingDown = true; - } - - _state.CountingDown = newCountingDown; - _lastCountDownValue = countDownPointerValue; + if (_paramValue == 0) return; + var countDownActive = Marshal.PtrToStructure((IntPtr)_paramValue + 0x38) == 1; + var countDownPointerValue = Marshal.PtrToStructure((IntPtr)_paramValue + 0x2c); + _state.CountingDown = countDownActive && countDownPointerValue > 0f; + _state.CountDownValue = countDownPointerValue; } [UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)] diff --git a/Plugin/packages.lock.json b/Plugin/packages.lock.json index 0cac435..d0ffd4f 100644 --- a/Plugin/packages.lock.json +++ b/Plugin/packages.lock.json @@ -4,9 +4,9 @@ "net8.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[2.1.12, )", - "resolved": "2.1.12", - "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + "requested": "[2.1.13, )", + "resolved": "2.1.13", + "contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ==" }, "EmbedIO": { "type": "Direct", From b40650d516ffc85157dd53d4ba85147818d9369c Mon Sep 17 00:00:00 2001 From: xorus Date: Wed, 3 Jul 2024 13:26:44 +0200 Subject: [PATCH 3/4] fix texture stuff --- Plugin/Ui/FloatingWindow.cs | 2 +- Plugin/Ui/NumberTextures.cs | 153 +++++++++++++------------- Plugin/Ui/SettingsTab/CountdownTab.cs | 5 +- 3 files changed, 80 insertions(+), 80 deletions(-) diff --git a/Plugin/Ui/FloatingWindow.cs b/Plugin/Ui/FloatingWindow.cs index 6103edc..2ca567b 100644 --- a/Plugin/Ui/FloatingWindow.cs +++ b/Plugin/Ui/FloatingWindow.cs @@ -94,7 +94,7 @@ private void DrawWindow(bool stopwatchActive, bool countdownActive) ImGui.PushStyleColor(ImGuiCol.Text, color); ImGui.SetWindowFontScale(Plugin.Config.FloatingWindow.Scale); - + var stopwatchDecimals = Plugin.Config.FloatingWindow.DecimalStopwatchPrecision > 0; var text = ""; // text to be displayed diff --git a/Plugin/Ui/NumberTextures.cs b/Plugin/Ui/NumberTextures.cs index b7ca8fe..7fd37f0 100644 --- a/Plugin/Ui/NumberTextures.cs +++ b/Plugin/Ui/NumberTextures.cs @@ -15,10 +15,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using Dalamud.Interface; -using Dalamud.Interface.Internal; +using Dalamud.Interface.Textures; using Dalamud.Interface.Textures.TextureWraps; using EngageTimer.Configuration; using EngageTimer.Ui.Color; @@ -40,9 +41,9 @@ public sealed class NumberTextures public NumberTextures() { - // _error = Plugin.TextureProvider..LoadImage(Path.Combine(Plugin.PluginPath, "Data", "error.png")); - - // Plugin.TextureProvider.CreateFromImageAsync(Path.Combine(Plugin.PluginPath, "Data", "error.png")) + // plugin crash if the default file is not found is expected + _error = Plugin.TextureProvider.CreateFromImageAsync(File.OpenRead(Path.Combine(Plugin.PluginPath, "Data", + "error.png"))).Result; Load(); } @@ -62,7 +63,6 @@ public void Load() private void LoadImages() { - return; _numberImages.Clear(); string texturePath; @@ -103,7 +103,6 @@ private void LoadImages() private void ReadPackSettings(string settingsFile) { - return; try { var json = File.ReadAllText(settingsFile); @@ -128,7 +127,7 @@ private void ReadPackSettings(string settingsFile) catch (Exception exception) { Plugin.Logger.Warning("Invalid json or missing property in " + settingsFile + "\n" + - exception); + exception); } } catch (IOException) @@ -145,82 +144,84 @@ private void ReadPackSettings(string settingsFile) public void CreateTextures() { - return; - // var watch = System.Diagnostics.Stopwatch.StartNew(); - // MaxTextureHeight = 0; - // MaxTextureWidth = 0; - // - // var success = false; - // for (var i = 0; i < 10; i++) - // { - // if (_numberImages.ContainsKey(i)) - // try - // { - // var image = _numberImages[i]; - // var bytes = image.Data.ToArray(); - // var bytesAlt = new byte[bytes.Length]; - // var configuration = Plugin.Config; - // if (image.NumChannels == 4) - // for (var p = 0; p < bytes.Length; p += 4) - // { - // var originalRgb = new HslConv.Rgb(bytes[p], bytes[p + 1], bytes[p + 2]); - // var hsl = HslConv.RgbToHsl(originalRgb); - // if (configuration.Countdown.NumberRecolorMode) - // hsl.H = Math.Clamp(configuration.Countdown.Hue, 0, 360); - // else - // hsl.H += configuration.Countdown.Hue; - // hsl.S = Math.Clamp(hsl.S + configuration.Countdown.Saturation, 0f, 1f); - // hsl.L = Math.Clamp(hsl.L + configuration.Countdown.Luminance, 0f, 1f); - // var modifiedRgb = HslConv.HslToRgb(hsl); - // bytes[p] = modifiedRgb.R; - // bytes[p + 1] = modifiedRgb.G; - // bytes[p + 2] = modifiedRgb.B; - // - // if (!configuration.Countdown.Animate) continue; - // var hslAlt = new HslConv.Hsl(hsl.H, hsl.S, hsl.L); - // hslAlt.L = Math.Clamp(hslAlt.L + .3f, 0f, 1f); - // var modifiedRgbAlt = HslConv.HslToRgb(hslAlt); - // bytesAlt[p] = modifiedRgbAlt.R; - // bytesAlt[p + 1] = modifiedRgbAlt.G; - // bytesAlt[p + 2] = modifiedRgbAlt.B; - // bytesAlt[p + 3] = bytes[p + 3]; - // } - // - // var texture = _uiBuilder.LoadImageRaw(bytes, image.Width, image.Height, image.NumChannels); - // var textureAlt = - // _uiBuilder.LoadImageRaw(bytesAlt, image.Width, image.Height, image.NumChannels); - // - // MaxTextureHeight = Math.Max(MaxTextureHeight, texture.Height); - // MaxTextureWidth = Math.Max(MaxTextureWidth, texture.Width); - // _numberTextures.Remove(i); - // _numberTextures.Add(i, texture); - // success = true; - // - // if (!configuration.Countdown.Animate) continue; - // _numberTexturesAlt.Remove(i); - // _numberTexturesAlt.Add(i, textureAlt); - // } - // catch (Exception) - // { - // // a loading error occured - // } - // - // if (success) continue; - // MaxTextureWidth = _error.Width; - // MaxTextureHeight = _error.Height; - // } - // - // watch.Stop(); - // LastTextureCreationDuration = watch.ElapsedMilliseconds / 1000d; + var watch = Stopwatch.StartNew(); + MaxTextureHeight = 0; + MaxTextureWidth = 0; + + var success = false; + for (var i = 0; i < 10; i++) + { + if (_numberImages.TryGetValue(i, out var image)) + try + { + var bytes = image.Data.ToArray(); + var bytesAlt = new byte[bytes.Length]; + var configuration = Plugin.Config; + if (image.NumChannels == 4) + for (var p = 0; p < bytes.Length; p += 4) + { + var originalRgb = new HslConv.Rgb(bytes[p], bytes[p + 1], bytes[p + 2]); + var hsl = HslConv.RgbToHsl(originalRgb); + if (configuration.Countdown.NumberRecolorMode) + hsl.H = Math.Clamp(configuration.Countdown.Hue, 0, 360); + else + hsl.H += configuration.Countdown.Hue; + hsl.S = Math.Clamp(hsl.S + configuration.Countdown.Saturation, 0f, 1f); + hsl.L = Math.Clamp(hsl.L + configuration.Countdown.Luminance, 0f, 1f); + var modifiedRgb = HslConv.HslToRgb(hsl); + bytes[p] = modifiedRgb.R; + bytes[p + 1] = modifiedRgb.G; + bytes[p + 2] = modifiedRgb.B; + + if (!configuration.Countdown.Animate) continue; + var hslAlt = new HslConv.Hsl(hsl.H, hsl.S, hsl.L); + hslAlt.L = Math.Clamp(hslAlt.L + .3f, 0f, 1f); + var modifiedRgbAlt = HslConv.HslToRgb(hslAlt); + bytesAlt[p] = modifiedRgbAlt.R; + bytesAlt[p + 1] = modifiedRgbAlt.G; + bytesAlt[p + 2] = modifiedRgbAlt.B; + bytesAlt[p + 3] = bytes[p + 3]; + } + + + var texture = Plugin.TextureProvider.CreateFromRaw( + RawImageSpecification.Rgba32(image.Width, image.Height), + bytes); + var textureAlt = Plugin.TextureProvider.CreateFromRaw( + RawImageSpecification.Rgba32(image.Width, image.Height), + bytesAlt); + + MaxTextureHeight = Math.Max(MaxTextureHeight, texture.Height); + MaxTextureWidth = Math.Max(MaxTextureWidth, texture.Width); + _numberTextures.Remove(i); + _numberTextures.Add(i, texture); + success = true; + + if (!configuration.Countdown.Animate) continue; + _numberTexturesAlt.Remove(i); + _numberTexturesAlt.Add(i, textureAlt); + } + catch (Exception) + { + // a loading error occured + } + + if (success) continue; + MaxTextureWidth = _error.Width; + MaxTextureHeight = _error.Height; + } + + watch.Stop(); + LastTextureCreationDuration = watch.ElapsedMilliseconds / 1000d; } public IDalamudTextureWrap GetTexture(int i) { - return _numberTextures.ContainsKey(i) ? _numberTextures[i] : _error; + return _numberTextures.GetValueOrDefault(i, _error); } public IDalamudTextureWrap GetAltTexture(int i) { - return _numberTexturesAlt.ContainsKey(i) ? _numberTexturesAlt[i] : _error; + return _numberTexturesAlt.GetValueOrDefault(i, _error); } } \ No newline at end of file diff --git a/Plugin/Ui/SettingsTab/CountdownTab.cs b/Plugin/Ui/SettingsTab/CountdownTab.cs index 0ba793d..a012a01 100644 --- a/Plugin/Ui/SettingsTab/CountdownTab.cs +++ b/Plugin/Ui/SettingsTab/CountdownTab.cs @@ -42,7 +42,7 @@ public static void DebounceTextureCreation() if (time - _lastTextureCreation < .05d + Plugin.NumberTextures.LastTextureCreationDuration) return; // 50ms + previous time taken _lastTextureCreation = time; - // Plugin.NumberTextures.CreateTextures(); + Plugin.NumberTextures.CreateTextures(); _requestTextureCreation = false; } @@ -146,7 +146,7 @@ public static void Draw() ImGui.Unindent(); } - public static void CountdownHideOptions() + private static void CountdownHideOptions() { var cdStatus = 0; if (Plugin.Config.Countdown.HideOriginalAddon) cdStatus = 1; @@ -252,7 +252,6 @@ private static void CountdownPositionAndSize() private static void CountdownNumberStyle() { - return; var texture = Plugin.NumberTextures.GetTexture(_exampleNumber); const float scale = .5f; ImGui.BeginGroup(); From cdcd5e3476f8f529804c053cfa789882754049f8 Mon Sep 17 00:00:00 2001 From: xorus Date: Fri, 5 Jul 2024 16:58:27 +0200 Subject: [PATCH 4/4] fix sfx and disable font picker --- .../FloatingWindowConfiguration.cs | 4 +- Plugin/EngageTimer.csproj | 2 +- Plugin/EngageTimer.yaml | 9 ++- Plugin/Game/SFXPlay.cs | 7 +- Plugin/Ui/CountDown.cs | 24 +++++-- Plugin/Ui/FloatingWindow.cs | 2 +- Plugin/Ui/FloatingWindowFont.cs | 21 +++--- Plugin/Ui/SettingsTab/FloatingWindowTab.cs | 72 ++++++++++--------- 8 files changed, 81 insertions(+), 60 deletions(-) diff --git a/Plugin/Configuration/FloatingWindowConfiguration.cs b/Plugin/Configuration/FloatingWindowConfiguration.cs index f741dee..c890dc7 100644 --- a/Plugin/Configuration/FloatingWindowConfiguration.cs +++ b/Plugin/Configuration/FloatingWindowConfiguration.cs @@ -84,8 +84,8 @@ public class FloatingWindowConfiguration public int FontSize { get; set; } = 16; - [JsonIgnore] public IFontSpec? FontSpec { get; set; } = null; - public IFontId? FontId { get; set; } = null; + // [JsonIgnore] public IFontSpec? FontSpec { get; set; } = null; + // public IFontSpec? Font { get; set; } = null; [AutoField("Settings_FWTab_AutoHide_Left")] public bool AutoHide { get; set; } = true; diff --git a/Plugin/EngageTimer.csproj b/Plugin/EngageTimer.csproj index c580eb3..f787921 100644 --- a/Plugin/EngageTimer.csproj +++ b/Plugin/EngageTimer.csproj @@ -8,7 +8,7 @@ true false false - 2.3.4.0 + 2.4.0.0 false true true diff --git a/Plugin/EngageTimer.yaml b/Plugin/EngageTimer.yaml index 147cf20..4669dbe 100644 --- a/Plugin/EngageTimer.yaml +++ b/Plugin/EngageTimer.yaml @@ -33,6 +33,9 @@ image_urls: category_tags: - jobs changelog: |- - - Fix not being able to disable alarms - - Missing translation strings in web server config - - Hide floating window border by default (you can re-enable it in Floating Window -> styling) \ No newline at end of file + - DT compatibility + - Update for API10: + - Use new texture loading for countdown + - Migrate to the new font system, the floating window contents might be blurry, this will be fixed soon when I + can implement font customization instead of always using the default dalamud one + \ No newline at end of file diff --git a/Plugin/Game/SFXPlay.cs b/Plugin/Game/SFXPlay.cs index 351a97c..5e25544 100644 --- a/Plugin/Game/SFXPlay.cs +++ b/Plugin/Game/SFXPlay.cs @@ -21,12 +21,13 @@ namespace EngageTimer.Game; /** * thanks aers * sig taken from https://github.com/philpax/plogonscript/blob/main/PlogonScript/Script/Bindings/Sound.cs + * https://github.com/0ceal0t/JobBars/blob/2c9bef8dd4f0bf9ebc91c07e03da6c841ac2bd35/JobBars/Helper/UiHelper.GameFunctions.cs#L61 * --- * https://discord.com/channels/581875019861328007/653504487352303619/988123102116450335 */ internal unsafe class GameSound { - [Signature("E8 ?? ?? ?? ?? 4D 39 BE ?? ?? ?? ??")] + [Signature("E8 ?? ?? ?? ?? 48 63 45 80")] public readonly delegate* unmanaged PlaySoundEffect = null; public GameSound() @@ -45,10 +46,10 @@ public class SfxPlay public SfxPlay() { /* Force a sound to play on load as a workaround for the CLR taking some time to init the pointy method call, - * we dont want a freeze midway through a countdown + * we don't want a freeze midway through a countdown (or midway in combat for alarms) * https://discord.com/channels/581875019861328007/653504487352303619/988123102116450335 * https://i.imgur.com/BrLUr2p.png - * */ + */ SoundEffect(0); // should be cursor sound } diff --git a/Plugin/Ui/CountDown.cs b/Plugin/Ui/CountDown.cs index 70ae630..5ebd78a 100644 --- a/Plugin/Ui/CountDown.cs +++ b/Plugin/Ui/CountDown.cs @@ -43,7 +43,7 @@ public sealed class CountDown : IDisposable * * In my testing, this is about 10 to 20ms. */ - private bool _firstDraw = true; + private int _firstDrawTicks = 5; private int _lastSecond; private bool _wasInMainViewport = true; @@ -88,9 +88,14 @@ private void FirstDraw() if (ImGui.Begin(WindowTitle, ref visible, flags)) { ImGui.Text(""); + for (var i = 0; i <= 9; i++) + { + DrawNumber(false, i, 0.001f, 0f, 1f, false); + DrawNumber(true, i, 0.001f, 0f, 1f, false); + } } - _firstDraw = false; + _firstDrawTicks--; } public void Draw() @@ -112,7 +117,12 @@ public void Draw() // ImGui.End(); // #endif - if (_firstDraw) FirstDraw(); + if (_firstDrawTicks > 0) + { + FirstDraw(); + return; + } + if (!Plugin.Config.Countdown.Display || !Plugin.State.CountingDown) return; var showMainCountdown = Plugin.Config.Countdown.HideOriginalAddon || @@ -130,7 +140,7 @@ public void Draw() if (Plugin.Config.Countdown.Animate) { - var second = (int) Plugin.State.CountDownValue; + var second = (int)Plugin.State.CountDownValue; if (_lastSecond != second) { _easing.Restart(); @@ -143,7 +153,7 @@ public void Draw() if (Plugin.Config.Countdown.AnimateScale) { maxNumberScale = numberScale + NumberEasing.StartSize; - numberScale += NumberEasing.StartSize * (1 - (float) _easing.Value); + numberScale += NumberEasing.StartSize * (1 - (float)_easing.Value); } } } @@ -190,7 +200,7 @@ public void Draw() ImGui.GetWindowPos(), ImGui.GetWindowPos() + ImGui.GetWindowSize(), ImGui.GetColorU32(ImGuiCol.Text), 0f, ImDrawFlags.None, - 7f + (float) Math.Sin(ImGui.GetTime() * 2) * 5f); + 7f + (float)Math.Sin(ImGui.GetTime() * 2) * 5f); d.AddRect( ImGui.GetWindowPos(), ImGui.GetWindowPos() + ImGui.GetWindowSize(), @@ -202,7 +212,7 @@ public void Draw() DrawCountdown(showMainCountdown, numberScale, negativeMargin, false); if (Plugin.Config.Countdown.Animate && Plugin.Config.Countdown.AnimateOpacity) { - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float) _easingOpacity.Value); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)_easingOpacity.Value); DrawCountdown(showMainCountdown, numberScale, negativeMargin, true); ImGui.PopStyleVar(); } diff --git a/Plugin/Ui/FloatingWindow.cs b/Plugin/Ui/FloatingWindow.cs index 2ca567b..745b85d 100644 --- a/Plugin/Ui/FloatingWindow.cs +++ b/Plugin/Ui/FloatingWindow.cs @@ -78,7 +78,7 @@ private void DrawWindow(bool stopwatchActive, bool countdownActive) pushVar = true; ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0); } - + ImGui.PushStyleColor(ImGuiCol.WindowBg, Plugin.Config.FloatingWindow.BackgroundColor); var flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoScrollbar | diff --git a/Plugin/Ui/FloatingWindowFont.cs b/Plugin/Ui/FloatingWindowFont.cs index 0c1b41b..17aeb33 100644 --- a/Plugin/Ui/FloatingWindowFont.cs +++ b/Plugin/Ui/FloatingWindowFont.cs @@ -32,12 +32,12 @@ public void UpdateFont() this.FontHandle?.Dispose(); this.FontHandle = Plugin.PluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e => e.OnPreBuild(tk => { - // tk.AddDalamudDefaultFont( - // Math.Max(8, Plugin.Config.FloatingWindow.FontSize), - // FontAtlasBuildToolkitUtilities.ToGlyphRange([ - // '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '.' - // ]) - // ); + tk.AddDalamudDefaultFont( + Math.Max(8, Plugin.Config.FloatingWindow.FontSize), + FontAtlasBuildToolkitUtilities.ToGlyphRange([ + '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '.' + ]) + ); // var spec = (SingleFontSpec)(Plugin.Config.FloatingWindow.FontSpec ?? // Plugin.PluginInterface.UiBuilder.DefaultFontSpec); // var specWithRanges = new SingleFontSpec() @@ -53,9 +53,14 @@ public void UpdateFont() // ]) // }; - var spec = Plugin.Config.FloatingWindow.FontSpec ?? Plugin.PluginInterface.UiBuilder.DefaultFontSpec; - spec.AddToBuildToolkit(tk); + // var spec = Plugin.PluginInterface.UiBuilder.DefaultFontSpec; + // spec.AddToBuildToolkit(tk, font); + /// fontAtlas.NewDelegateFontHandle( + /// e => e.OnPreBuild( + /// tk => tk.AddDalamudDefaultFont(UiBuilder.DefaultFontSizePx))); })); + + // this.FontHandle = Plugin.PluginInterface.UiBuilder.DefaultFontHandle } public void Dispose() diff --git a/Plugin/Ui/SettingsTab/FloatingWindowTab.cs b/Plugin/Ui/SettingsTab/FloatingWindowTab.cs index 8d73bad..0a577bb 100644 --- a/Plugin/Ui/SettingsTab/FloatingWindowTab.cs +++ b/Plugin/Ui/SettingsTab/FloatingWindowTab.cs @@ -28,7 +28,7 @@ namespace EngageTimer.Ui.SettingsTab; public static class FloatingWindowTab { - private static SingleFontChooserDialog? _fc; + // private static SingleFontChooserDialog? _fc; public static void Draw() { @@ -102,6 +102,7 @@ private static void FwStyling() { configuration.FloatingWindow.FontSize = Math.Max(0, fontSize); configuration.Save(); + Plugin.FloatingWindowFont.UpdateFont(); // if (configuration.FloatingWindow.FontSize >= 8) Plugin.PluginInterface.UiBuilder.RebuildFonts(); } @@ -114,42 +115,43 @@ private static void FwStyling() Components.AutoField(Plugin.Config.FloatingWindow, "ForceHideWindowBorder"); ImGui.EndGroup(); - ImGui.Text("Font:"); - ImGui.SameLine(); - using (Plugin.FloatingWindowFont.FontHandle?.Push()) - { - if (configuration.FloatingWindow.FontSpec == null) - ImGui.Text("default"); - else - ImGui.Text(configuration.FloatingWindow.FontSpec.ToString()); - } - - if (ImGui.Button("change font") && !_fcO) - { - _fc = SingleFontChooserDialog.CreateAuto((UiBuilder)Plugin.PluginInterface.UiBuilder); - _fcO = true; - _fc.PreviewText = "-01:23.45 6789"; - _fc.ResultTask.ContinueWith(task => - { - _fcO = false; - if (!task.IsCompleted) return; - configuration.FloatingWindow.FontId = _fc.SelectedFont.FontId; - - configuration.Save(); - Plugin.FloatingWindowFont.UpdateFont(); - }); - } - - ImGui.SameLine(); - if (ImGui.Button("reset font")) - { - configuration.FloatingWindow.FontSpec = null; - configuration.Save(); - Plugin.FloatingWindowFont.UpdateFont(); - } + // ImGui.Text("Font:"); + // ImGui.SameLine(); + // using (Plugin.FloatingWindowFont.FontHandle?.Push()) + // { + // if (configuration.FloatingWindow.FontSpec == null) + // ImGui.Text("default"); + // else + // ImGui.Text(configuration.FloatingWindow.FontSpec.ToString()); + // } + // + // if (ImGui.Button("change font") && !_fcO) + // { + // _fc = SingleFontChooserDialog.CreateAuto((UiBuilder)Plugin.PluginInterface.UiBuilder); + // _fcO = true; + // _fc.PreviewText = "-01:23.45 6789"; + // _fc.ResultTask.ContinueWith(task => + // { + // _fcO = false; + // if (!task.IsCompleted) return; + // configuration.FloatingWindow.Font = _fc.SelectedFont; + // + // Plugin.Logger.Info("font chosen: " + _fc.SelectedFont); + // + // configuration.Save(); + // Plugin.FloatingWindowFont.UpdateFont(); + // }); + // } + // ImGui.SameLine(); + // if (ImGui.Button("reset font")) + // { + // configuration.FloatingWindow.FontSpec = null; + // configuration.Save(); + // Plugin.FloatingWindowFont.UpdateFont(); + // } ImGui.Unindent(); } - private static bool _fcO = false; + // private static bool _fcO = false; } \ No newline at end of file