Skip to content

Commit

Permalink
fix countdown in floating window not appearing when "hide after X" op…
Browse files Browse the repository at this point in the history
…tion is set
  • Loading branch information
xorus committed Oct 13, 2021
1 parent 77a6d1a commit b153980
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class Configuration : IPluginConfiguration
public float AutoHideTimeout { get; set; } = 20f;
public bool EnableTickingSound { get; set; } = false;
public float TickingSoundVolume { get; set; } = 0.05f;
public bool StopwatchCountdown { get; set; } = false;
public bool EnableCountdownDecimal { get; set; } = false;
public int CountdownDecimalPrecision { get; set; } = 1;

Expand Down
2 changes: 1 addition & 1 deletion EngageTimer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<Version>1.0.0</Version>
<AssemblyVersion>2.0.2.0</AssemblyVersion>
<AssemblyVersion>2.0.2.1</AssemblyVersion>
<Deterministic>false</Deterministic>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
39 changes: 24 additions & 15 deletions Ui/FloatingWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,42 @@ public void Draw()
return;
}

var autoHide = _configuration.AutoHideStopwatch &&
(DateTime.Now - _state.CombatEnd).TotalSeconds > _configuration.AutoHideTimeout;
var countdownMode = _configuration.StopwatchCountdown && _state.CountingDown;
if (autoHide && !countdownMode)
return;
var stopwatchActive = StopwatchActive();
var countdownActive = CountdownActive();
if (!stopwatchActive && !countdownActive) return;

if (_font.IsLoaded()) ImGui.PushFont(_font);

this.DrawWindow();
this.DrawWindow(stopwatchActive, countdownActive);

if (_font.IsLoaded()) ImGui.PopFont();
}

private void DrawWindow()
private bool StopwatchActive()
{
var displayStopwatch = _configuration.FloatingWindowStopwatch;
if (!displayStopwatch) return false;

if (_configuration.AutoHideStopwatch &&
(DateTime.Now - _state.CombatEnd).TotalSeconds > _configuration.AutoHideTimeout)
return false;

return !_configuration.FloatingWindowDisplayStopwatchOnlyInDuty || _state.InInstance;
}

private bool CountdownActive()
{
return _configuration.FloatingWindowCountdown && _state.CountingDown && _state.CountDownValue > 0;
}

private void DrawWindow(bool stopwatchActive, bool countdownActive)
{
// ImGui.SetNextWindowBgAlpha(_configuration.FloatingWindowBackgroundColor.Z);
ImGui.PushStyleColor(ImGuiCol.WindowBg, _configuration.FloatingWindowBackgroundColor);

var flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoScrollbar;
if (_configuration.FloatingWindowLock) flags |= ImGuiWindowFlags.NoMouseInputs;

var displayStopwatch = _configuration.FloatingWindowStopwatch;
if (displayStopwatch && _configuration.FloatingWindowDisplayStopwatchOnlyInDuty)
displayStopwatch = _state.InInstance;
var displayCountdown = _configuration.FloatingWindowCountdown && _state.CountingDown &&
_state.CountDownValue > 0;

if (ImGui.Begin("EngageTimer stopwatch", ref _stopwatchVisible, flags))
{
ImGui.PushStyleColor(ImGuiCol.Text, _configuration.FloatingWindowTextColor);
Expand All @@ -84,14 +93,14 @@ private void DrawWindow()
var maxText = "00:00";

var displayed = false;
if (displayCountdown)
if (countdownActive)
{
text = string.Format(
"-{0:0." + new string('0', _configuration.FloatingWindowDecimalCountdownPrecision) + "}",
_state.CountDownValue + (_configuration.FloatingWindowAccurateCountdown ? 0 : 1));
displayed = true;
}
else if (displayStopwatch)
else if (stopwatchActive)
{
if (stopwatchDecimals)
maxText += "." + new string('0', _configuration.FloatingWindowDecimalStopwatchPrecision);
Expand Down

0 comments on commit b153980

Please sign in to comment.