From 41bc5601f25174def8a6eea04ce8291ece85d5ba Mon Sep 17 00:00:00 2001 From: xorus Date: Fri, 5 Jul 2024 16:58:27 +0200 Subject: [PATCH] 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