Skip to content

Commit

Permalink
fix sfx and disable font picker
Browse files Browse the repository at this point in the history
  • Loading branch information
xorus committed Jul 5, 2024
1 parent b40650d commit cdcd5e3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 60 deletions.
4 changes: 2 additions & 2 deletions Plugin/Configuration/FloatingWindowConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Plugin/EngageTimer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<AssemblyVersion>2.3.4.0</AssemblyVersion>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<Deterministic>false</Deterministic>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
9 changes: 6 additions & 3 deletions Plugin/EngageTimer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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
7 changes: 4 additions & 3 deletions Plugin/Game/SFXPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint, IntPtr, IntPtr, byte, void> PlaySoundEffect = null;

public GameSound()
Expand All @@ -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
}

Expand Down
24 changes: 17 additions & 7 deletions Plugin/Ui/CountDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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 ||
Expand All @@ -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();
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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(),
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Ui/FloatingWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
21 changes: 13 additions & 8 deletions Plugin/Ui/FloatingWindowFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 =&gt; e.OnPreBuild(
/// tk =&gt; tk.AddDalamudDefaultFont(UiBuilder.DefaultFontSizePx)));
}));

// this.FontHandle = Plugin.PluginInterface.UiBuilder.DefaultFontHandle
}

public void Dispose()
Expand Down
72 changes: 37 additions & 35 deletions Plugin/Ui/SettingsTab/FloatingWindowTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace EngageTimer.Ui.SettingsTab;

public static class FloatingWindowTab
{
private static SingleFontChooserDialog? _fc;
// private static SingleFontChooserDialog? _fc;

public static void Draw()
{
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}

0 comments on commit cdcd5e3

Please sign in to comment.