Skip to content

Commit

Permalink
add some floating window options
Browse files Browse the repository at this point in the history
- Add an option to remove the "-" sign (#15)
- Add an option to display combat time as seconds (#13)
- Add a scale slider for people who really like ugly font scaling
  • Loading branch information
xorus committed Oct 16, 2021
1 parent 4f16e20 commit 18080b0
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class Configuration : IPluginConfiguration
public int FloatingWindowDecimalCountdownPrecision { get; set; } = 0;
public int FloatingWindowDecimalStopwatchPrecision { get; set; } = 0;
public bool FloatingWindowDisplayStopwatchOnlyInDuty { get; set; } = false;
public bool FloatingWindowStopwatchAsSeconds { get; set; } = false;
public bool FloatingWindowCountdownNegativeSign { get; set; } = true;
public float FloatingWindowScale { get; set; } = 1f;

// Stopwatch cosmetics

Expand Down
27 changes: 27 additions & 0 deletions Properties/Resources.Designer.cs

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

11 changes: 10 additions & 1 deletion Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Ce paramètre ne fonctionne que si le compte à rebours original est caché.</va
<value>Couleur</value>
</data>
<data name="Settings_CountdownTab_CountdownScale" xml:space="preserve">
<value>Taille</value>
<value>Échelle</value>
</data>
<data name="Settings_CountdownTab_Animate" xml:space="preserve">
<value>Activer l'animation</value>
Expand All @@ -322,4 +322,13 @@ Ce paramètre ne fonctionne que si le compte à rebours original est caché.</va
<data name="Settings_CountdownTab_PositionWarning" xml:space="preserve">
<value>Attention : ces paramètres peuvent se comporter incorrectement si l'option "Cacher le compte à rebours original" n'est pas active.</value>
</data>
<data name="Settings_FWTab_StopwatchAsSeconds" xml:space="preserve">
<value>Afficher le temps de combat en secondes</value>
</data>
<data name="Settings_FWTab_CountdownNegativeSign" xml:space="preserve">
<value>Afficher le signe "-"</value>
</data>
<data name="Settings_CountdownTab_FloatingWindowScale" xml:space="preserve">
<value>Échelle</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,13 @@ This setting only works when the original countdown is hidden.</value>
<data name="Settings_CountdownTab_PositionWarning" xml:space="preserve">
<value>Warning : when not hiding the original countdown, rescaling/offseting might behave wrongly</value>
</data>
<data name="Settings_FWTab_StopwatchAsSeconds" xml:space="preserve">
<value>Display combat time in seconds instead of time format</value>
</data>
<data name="Settings_FWTab_CountdownNegativeSign" xml:space="preserve">
<value>Display the "-" sign</value>
</data>
<data name="Settings_CountdownTab_FloatingWindowScale" xml:space="preserve">
<value>Scale</value>
</data>
</root>
32 changes: 23 additions & 9 deletions Ui/FloatingWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using System.Numerics;
using Dalamud.Logging;
Expand Down Expand Up @@ -83,31 +84,44 @@ private void DrawWindow(bool stopwatchActive, bool countdownActive)
if (ImGui.Begin("EngageTimer stopwatch", ref _stopwatchVisible, flags))
{
ImGui.PushStyleColor(ImGuiCol.Text, _configuration.FloatingWindowTextColor);
ImGui.SetWindowFontScale(_configuration.FloatingWindowScale);

var stopwatchDecimals = _configuration.FloatingWindowDecimalStopwatchPrecision > 0;

var text = ""; // text to be displayed
// the largest possible string, taking advantage that the default font has fixed number width
var maxText = "00:00";
var maxText = (_configuration.FloatingWindowStopwatchAsSeconds ? "0000" : "00") +
(stopwatchDecimals
? new string('0', _configuration.FloatingWindowDecimalStopwatchPrecision)
: "");

var displayed = false;
if (countdownActive)
{
text = string.Format(
"-{0:0." + new string('0', _configuration.FloatingWindowDecimalCountdownPrecision) + "}",
(_configuration.FloatingWindowCountdownNegativeSign ? "-" : "")
+ "{0:0." + new string('0', _configuration.FloatingWindowDecimalCountdownPrecision) + "}",
_state.CountDownValue + (_configuration.FloatingWindowAccurateCountdown ? 0 : 1));
displayed = true;
}
else if (stopwatchActive)
{
if (stopwatchDecimals)
maxText += "." + new string('0', _configuration.FloatingWindowDecimalStopwatchPrecision);
if (stopwatchDecimals)
text = _state.CombatDuration.ToString(
@"mm\:ss\." + new string('f', _configuration.FloatingWindowDecimalStopwatchPrecision)
);
if (_configuration.FloatingWindowStopwatchAsSeconds)
{
text = Math.Floor(_state.CombatDuration.TotalSeconds).ToString(CultureInfo.InvariantCulture);
if (stopwatchDecimals)
text += "." + _state.CombatDuration.ToString(
new string('f', _configuration.FloatingWindowDecimalStopwatchPrecision)
);
}
else
text = _state.CombatDuration.ToString(@"mm\:ss");
{
text = stopwatchDecimals
? _state.CombatDuration.ToString(@"mm\:ss\." + new string('f',
_configuration.FloatingWindowDecimalStopwatchPrecision))
: _state.CombatDuration.ToString(@"mm\:ss");
}

displayed = true;
}

Expand Down
74 changes: 53 additions & 21 deletions Ui/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,58 @@ private void FloatingWindowTabContent()
}

ImGuiComponents.HelpMarker(Trans("Settings_FWTab_StopwatchPrecision_Help"));

ImGui.Separator();
if (ImGui.CollapsingHeader(TransId("Settings_FWTab_Styling"))) FwStyling();
ImGui.Separator();

ImGui.Text(Trans("Settings_FWTab_Styling"));
if (ImGui.Checkbox(TransId("Settings_FWTab_AccurateCountdown"),
ref floatingWindowAccurateCountdown))
{
_configuration.FloatingWindowAccurateCountdown = floatingWindowAccurateCountdown;
_configuration.Save();
}

ImGuiComponents.HelpMarker(Trans("Settings_FWTab_AccurateCountdown_Help"));

var fWDisplayStopwatchOnlyInDuty = _configuration.FloatingWindowDisplayStopwatchOnlyInDuty;
if (ImGui.Checkbox(TransId("Settings_FWTab_DisplayStopwatchOnlyInDuty"),
ref fWDisplayStopwatchOnlyInDuty))
{
_configuration.FloatingWindowDisplayStopwatchOnlyInDuty = fWDisplayStopwatchOnlyInDuty;
_configuration.Save();
}

ImGuiComponents.HelpMarker(Trans("Settings_FWTab_DisplayStopwatchOnlyInDuty_Help"));

var negativeSign = _configuration.FloatingWindowCountdownNegativeSign;
if (ImGui.Checkbox(TransId("Settings_FWTab_CountdownNegativeSign"), ref negativeSign))
{
_configuration.FloatingWindowCountdownNegativeSign = negativeSign;
_configuration.Save();
}

var displaySeconds = _configuration.FloatingWindowStopwatchAsSeconds;
if (ImGui.Checkbox(TransId("Settings_FWTab_StopwatchAsSeconds"), ref displaySeconds))
{
_configuration.FloatingWindowStopwatchAsSeconds = displaySeconds;
_configuration.Save();
}
}

private void FwStyling()
{
ImGui.Indent();

ImGui.BeginGroup();
var fwScale = _configuration.FloatingWindowScale;
ImGui.PushItemWidth(100f);
if (ImGui.DragFloat(TransId("Settings_CountdownTab_FloatingWindowScale"), ref fwScale, .01f))
{
_configuration.FloatingWindowScale = Math.Clamp(fwScale, 0.05f, 15f);
_configuration.Save();
}

var textAlign = (int)_configuration.StopwatchTextAlign;
if (ImGui.Combo(TransId("Settings_FWTab_TextAlign"), ref textAlign,
Trans("Settings_FWTab_TextAlign_Left") + "###Left\0" +
Expand All @@ -438,6 +485,9 @@ private void FloatingWindowTabContent()
}
}

ImGui.EndGroup();
ImGui.SameLine();
ImGui.BeginGroup();
var floatingWindowTextColor = ImGuiComponents.ColorPickerWithPalette(1,
TransId("Settings_FWTab_TextColor"),
_configuration.FloatingWindowTextColor);
Expand All @@ -461,27 +511,9 @@ private void FloatingWindowTabContent()

ImGui.SameLine();
ImGui.Text(Trans("Settings_FWTab_BackgroundColor"));
ImGui.Unindent();
ImGui.Separator();

if (ImGui.Checkbox(TransId("Settings_FWTab_AccurateCountdown"),
ref floatingWindowAccurateCountdown))
{
_configuration.FloatingWindowAccurateCountdown = floatingWindowAccurateCountdown;
_configuration.Save();
}

ImGuiComponents.HelpMarker(Trans("Settings_FWTab_AccurateCountdown_Help"));

var fWDisplayStopwatchOnlyInDuty = _configuration.FloatingWindowDisplayStopwatchOnlyInDuty;
if (ImGui.Checkbox(TransId("Settings_FWTab_DisplayStopwatchOnlyInDuty"),
ref fWDisplayStopwatchOnlyInDuty))
{
_configuration.FloatingWindowDisplayStopwatchOnlyInDuty = fWDisplayStopwatchOnlyInDuty;
_configuration.Save();
}
ImGui.EndGroup();

ImGuiComponents.HelpMarker(Trans("Settings_FWTab_DisplayStopwatchOnlyInDuty_Help"));
ImGui.Unindent();
}

private void WebServerTabContent()
Expand Down

0 comments on commit 18080b0

Please sign in to comment.