Skip to content

Commit

Permalink
add an option to ignore the original countdown when drawing the custo…
Browse files Browse the repository at this point in the history
…m one #56
  • Loading branch information
xorus committed Feb 4, 2024
1 parent 6b0d046 commit bac46f4
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 88 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# v2.3.1.0 - unreleased
# v2.3.2.0

- Adds

# v2.3.1.0

- You can set alarms to play a game sound effect, change stopwatch color or display text at specified combat durations
- Big code rewrite and a bit of optimization
Expand Down
6 changes: 3 additions & 3 deletions Plugin/Commands/MainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

using System;
using Dalamud.Game.Command;
using EngageTimer.Ui;
using EngageTimer.Localization;

namespace EngageTimer.Commands;

Expand All @@ -27,12 +27,12 @@ public sealed class MainCommand : IDisposable
public MainCommand()
{
Register();
Plugin.Translator.LocaleChanged += OnLocaleChanged;
Translator.LocaleChanged += OnLocaleChanged;
}

public void Dispose()
{
Plugin.Translator.LocaleChanged -= OnLocaleChanged;
Translator.LocaleChanged -= OnLocaleChanged;
Unregister();
}

Expand Down
1 change: 1 addition & 0 deletions Plugin/Commands/SettingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System;
using Dalamud.Game.Command;
using EngageTimer.Localization;
using EngageTimer.Ui;

namespace EngageTimer.Commands;
Expand Down
4 changes: 2 additions & 2 deletions Plugin/Configuration/CountdownConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ namespace EngageTimer.Configuration;
public class CountdownConfiguration
{
public static readonly string[] BundledTextures =
{ "default", "yellow", "wow", "awk", "tall", "misaligned", "pixel", "moire", "mspaint" };
{"default", "yellow", "wow", "awk", "tall", "misaligned", "pixel", "moire", "mspaint"};

// Countdown
[AutoField("Settings_CountdownTab_Enable")]
public bool Display { get; set; } = true;

[AutoField("Settings_CountdownTab_HideOriginalCountDown"), Help("Settings_CountdownTab_HideOriginalCountDown_Help")]
public bool HideOriginalAddon { get; set; } = false;
public bool IgnoreOriginalAddon { get; set; } = false;

[AutoField("Settings_CountdownTab_Audio_Enable")]
public bool EnableTickingSound { get; set; } = false;
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.1.1</AssemblyVersion>
<AssemblyVersion>2.3.2.0</AssemblyVersion>
<Deterministic>false</Deterministic>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
37 changes: 37 additions & 0 deletions Plugin/Localization/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file is part of EngageTimer
// Copyright (C) 2024 Xorus <xorus@posteo.net>
//
// 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 <https://www.gnu.org/licenses/>.

namespace EngageTimer.Localization;

/**
* For the lazy dogs out there (me)
*/
public static class Extensions
{
public static string Tr(this string id)
{
return Translator.Tr(id);
}

public static string TrId(this string id)
{
return Translator.TrId(id);
}

public static string TrYesNo(this bool yesNo, string yes, string no)
{
return yesNo ? Tr(yes) : Tr(no);
}
}
16 changes: 8 additions & 8 deletions Plugin/Ui/Translator.cs → Plugin/Localization/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
using System.Globalization;
using EngageTimer.Properties;

namespace EngageTimer.Ui;
namespace EngageTimer.Localization;

public sealed class Translator : IDisposable
public static class Translator
{
public Translator()
public static event EventHandler? LocaleChanged;

public static void Register()
{
Plugin.PluginInterface.LanguageChanged += ConfigureLanguage;
ConfigureLanguage();
}

public void Dispose()
public static void Unregister()
{
Plugin.PluginInterface.LanguageChanged -= ConfigureLanguage;
}

public event EventHandler? LocaleChanged;

public static string TrId(string id)
{
return $"{Resources.ResourceManager.GetString(id, Resources.Culture) ?? id}###EngageTimer_{id}";
Expand Down Expand Up @@ -61,7 +61,7 @@ public static string Tr(string id, params string[] replacements)
return str;
}

private void ConfigureLanguage(string? langCode = null)
private static void ConfigureLanguage(string? langCode = null)
{
var lang = (langCode ?? Plugin.PluginInterface.UiLanguage) switch
{
Expand All @@ -72,6 +72,6 @@ private void ConfigureLanguage(string? langCode = null)
_ => "en"
};
Resources.Culture = new CultureInfo(lang ?? "en");
LocaleChanged?.Invoke(this, EventArgs.Empty);
LocaleChanged?.Invoke(null, EventArgs.Empty);
}
}
6 changes: 3 additions & 3 deletions Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using EngageTimer.Commands;
using EngageTimer.Configuration;
using EngageTimer.Game;
using EngageTimer.Localization;
using EngageTimer.Status;
using EngageTimer.Ui;
using JetBrains.Annotations;
Expand All @@ -43,7 +44,6 @@ public sealed class Plugin : IDalamudPlugin
[PluginService] public static IToastGui ToastGui { get; private set; } = null!;
public static ConfigurationFile Config { get; private set; } = null!;
public static State State { get; private set; } = null!;
public static Translator Translator { get; private set; } = null!;
public static PluginUi PluginUi { get; private set; } = null!;
public static NumberTextures NumberTextures { get; set; } = null!;
public static string PluginPath { get; private set; } = null!;
Expand All @@ -57,9 +57,9 @@ public Plugin(DalamudPluginInterface pluginInterface)
{
PluginPath = PluginInterface.AssemblyLocation.DirectoryName ??
throw new InvalidOperationException("Cannot find plugin directory");
Translator.Register();
Config = ConfigurationLoader.Load();
State = new State();
Translator = new Translator();
FrameworkThings = new FrameworkThings();
MainCommand = new MainCommand();
SettingsCommand = new SettingsCommand();
Expand All @@ -70,12 +70,12 @@ public Plugin(DalamudPluginInterface pluginInterface)

void IDisposable.Dispose()
{
Translator.Unregister();
PluginInterface.SavePluginConfig(Config);
CombatAlarm.Dispose();
PluginUi.Dispose();
FrameworkThings.Dispose();
MainCommand.Dispose();
SettingsCommand.Dispose();
Translator.Dispose();
}
}
36 changes: 36 additions & 0 deletions Plugin/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Plugin/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -617,4 +617,16 @@ help text for the /eg settings command</comment>
<data name="CombatAlarm_ImportedEmpty" xml:space="preserve">
<value>An empty or invalid alarm list was imported</value>
</data>
<data name="Settings_CountdownTab_IgnoreOriginalCountDown" xml:space="preserve">
<value>Draw even if original countdown is visible</value>
</data>
<data name="Settings_CountdownTab_IgnoreOriginalCountDown_Help" xml:space="preserve">
<value>Allows you to have the vanilla countdown showing on your game but still use the custom one in a corner or overlaping if you like chaos. Useful if you setup your OBS to not capture addons and want to look unmodified.</value>
</data>
<data name="Settings_CountdownTab_DefaultOriginalCountDown" xml:space="preserve">
<value>Don't overlap with game countdown (default)</value>
</data>
<data name="Settings_CountdownTab_DefaultOriginalCountDown_Help" xml:space="preserve">
<value>Hides the custom countdown under 5 to prevent overlapping with the vanilla one.</value>
</data>
</root>
1 change: 1 addition & 0 deletions Plugin/Status/CombatAlarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Dalamud.Plugin.Services;
using EngageTimer.Configuration;
using EngageTimer.Game;
using EngageTimer.Localization;
using EngageTimer.Ui;
using Newtonsoft.Json;

Expand Down
1 change: 1 addition & 0 deletions Plugin/Ui/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using EngageTimer.Attributes;
using EngageTimer.Localization;
using ImGuiNET;

namespace EngageTimer.Ui;
Expand Down
30 changes: 12 additions & 18 deletions Plugin/Ui/CountDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using System.Globalization;
using System.Numerics;
using Dalamud.Interface.Animation;
using Dalamud.Interface.Animation.EasingFunctions;
using EngageTimer.Configuration;
using EngageTimer.Game;
using EngageTimer.Ui.CustomEasing;
Expand All @@ -30,14 +29,9 @@ public sealed class CountDown : IDisposable
{
private const float BaseNumberScale = 1f;
private const int GameCountdownWidth = 60; // just trust in the magic numbers
private const float AnimationSize = .7f;

private readonly Easing _easing = new OutCubic(new TimeSpan(0, 0, 0, 0, 1000));

private readonly Easing _easingOpacity = new OpacityEasing(
new TimeSpan(0, 0, 0, 0, 1000),
1, -0.02, .71, 1
);
private readonly Easing _easing = new NumberEasing();
private readonly Easing _easingOpacity = new OpacityEasing();

private bool _accurateMode;
private const string WindowTitle = "EngageTimer Countdown";
Expand Down Expand Up @@ -76,13 +70,12 @@ private void ConfigurationOnOnSave(object? sender, EventArgs e)
*/
private void UpdateFromConfig()
{
_accurateMode = Plugin.Config.Countdown.HideOriginalAddon && Plugin.Config.Countdown.AccurateMode;
_accurateMode = Plugin.Config.Countdown.AccurateMode &&
(Plugin.Config.Countdown.HideOriginalAddon || Plugin.Config.Countdown.IgnoreOriginalAddon);
}

private void FirstDraw()
{
if (!_firstDraw) return;

var visible = true;
var flags = ImGuiWindowFlags.NoTitleBar
| ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoTitleBar
Expand Down Expand Up @@ -119,10 +112,11 @@ public void Draw()
// ImGui.End();
// #endif

FirstDraw();
if (_firstDraw) FirstDraw();
if (!Plugin.Config.Countdown.Display || !Plugin.State.CountingDown) return;

var showMainCountdown = Plugin.State.CountDownValue > 5 || Plugin.Config.Countdown.HideOriginalAddon;
var showMainCountdown = Plugin.Config.Countdown.HideOriginalAddon ||
Plugin.Config.Countdown.IgnoreOriginalAddon || Plugin.State.CountDownValue > 5;
if (showMainCountdown && Plugin.Config.Countdown.EnableDisplayThreshold &&
Plugin.State.CountDownValue > Plugin.Config.Countdown.DisplayThreshold)
return;
Expand All @@ -136,7 +130,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 @@ -148,8 +142,8 @@ public void Draw()
_easingOpacity.Update();
if (Plugin.Config.Countdown.AnimateScale)
{
maxNumberScale = numberScale + AnimationSize;
numberScale += AnimationSize * (1 - (float)_easing.Value);
maxNumberScale = numberScale + NumberEasing.StartSize;
numberScale += NumberEasing.StartSize * (1 - (float) _easing.Value);
}
}
}
Expand Down Expand Up @@ -196,7 +190,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 @@ -208,7 +202,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
Loading

0 comments on commit bac46f4

Please sign in to comment.