Skip to content

Commit

Permalink
add fixed width, leading zero and user customizable negative margin
Browse files Browse the repository at this point in the history
  • Loading branch information
xorus committed Oct 17, 2021
1 parent 4b49e34 commit 6d6954c
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 35 deletions.
3 changes: 3 additions & 0 deletions Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class Configuration : IPluginConfiguration
public string CountdownTextureDirectory { get; set; } = null;
public static readonly string[] BundledTextures = { "default", "yellow", "wow" };
public float CountdownScale { get; set; } = 1f;
public bool CountdownMonospaced { get; set; }
public float? CountdownCustomNegativeMargin { get; set; } = null;
public bool CountdownLeadingZero { get; set; }

// Countdown color
public int CountdownNumberHue { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions Data/numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ Example JSON contents with default values:
```json
{
"NumberNegativeMargin": 10,
"NumberNegativeMarginMono": 10,
"NumberBottomMargin": 0
}
```

- NumberNegativeMargin: margin to remove when positioning the next number
- NumberNegativeMarginMono: same but for monospaced mode
- NumberBottomMargin: margin to the number baseline in pixels (to align decimal numbers)

**Example:**
Expand Down
1 change: 1 addition & 0 deletions Data/numbers/default/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"NumberNegativeMargin": 22,
"NumberNegativeMarginMono": 32,
"NumberBottomMargin": 20
}
1 change: 1 addition & 0 deletions Data/numbers/wow/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"NumberNegativeMargin": 5,
"NumberNegativeMarginMono": 10,
"NumberBottomMargin": 7
}
1 change: 1 addition & 0 deletions Data/numbers/yellow/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"NumberNegativeMargin": 13,
"NumberNegativeMarginMono": 18,
"NumberBottomMargin": 16
}
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.1.0.0</AssemblyVersion>
<AssemblyVersion>2.1.1.0</AssemblyVersion>
<Deterministic>false</Deterministic>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 2 additions & 0 deletions EngageTimer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ image_urls:
- https://github.com/goatcorp/DalamudPlugins/blob/api4/plugins/EngageTimer/images/image1.png
- https://github.com/goatcorp/DalamudPlugins/blob/api4/plugins/EngageTimer/images/image2.png
- https://github.com/goatcorp/DalamudPlugins/blob/api4/plugins/EngageTimer/images/image3.png
category_tags:
- jobs
45 changes: 45 additions & 0 deletions 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 Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,16 @@ Ce paramètre ne fonctionne que si le compte à rebours original est caché.</va
<data name="Settings_CountdownTab_FloatingWindowScale" xml:space="preserve">
<value>Échelle</value>
</data>
<data name="Settings_CountdownTab_Monospaced" xml:space="preserve">
<value>Taille fixe</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_Advanced" xml:space="preserve">
<value>Options avancées</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_LeadingZero" xml:space="preserve">
<value>Préfixer par 0</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_EnableCustomNegativeMargin" xml:space="preserve">
<value>Utiliser une marge négative personnalisée</value>
</data>
</root>
15 changes: 15 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,19 @@ This setting only works when the original countdown is hidden.</value>
<data name="Settings_CountdownTab_FloatingWindowScale" xml:space="preserve">
<value>Scale</value>
</data>
<data name="Settings_CountdownTab_Monospaced" xml:space="preserve">
<value>Fixed width</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_Advanced" xml:space="preserve">
<value>More options</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_LeadingZero" xml:space="preserve">
<value>Add a leading 0</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_EnableCustomNegativeMargin" xml:space="preserve">
<value>Enable custom negative margin</value>
</data>
<data name="Settings_CountdownTab_NumberStyle_CustomNegativeMargin" xml:space="preserve">
<value>pixels</value>
</data>
</root>
94 changes: 65 additions & 29 deletions Ui/CountDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CountDown
private readonly GameGui _gui;
private readonly NumberTextures _numberTextures;
private readonly string _path;
private bool _accurateMode = false;
private bool _accurateMode;

public CountDown(Configuration configuration, State state, GameGui gui, NumberTextures numberTextures,
string path)
Expand All @@ -50,7 +50,7 @@ private void UpdateFromConfig()
}

private const byte VisibleFlag = 0x20;
private bool _originalAddonHidden = false;
private bool _originalAddonHidden;

// finds the original CountDown addon and toggles its visibility flag
private unsafe void ToggleOriginalAddon()
Expand Down Expand Up @@ -80,11 +80,7 @@ private unsafe void ToggleOriginalAddon()
1, -0.02, .71, 1
);

// private readonly Easing _easingOpacity = new InCubic(
// new TimeSpan(0, 0, 0, 0, 1000)
// );

private int _lastSecond = 0;
private int _lastSecond;

public void Draw()
{
Expand Down Expand Up @@ -131,7 +127,12 @@ public void Draw()
}
}

var negativeMargin = _numberTextures.NumberNegativeMargin * numberScale;
var negativeMargin = _configuration.CountdownCustomNegativeMargin ?? (
_configuration.CountdownMonospaced
? _numberTextures.NumberNegativeMarginMono
: _numberTextures.NumberNegativeMargin
) * numberScale;

var io = ImGui.GetIO();
ImGui.SetNextWindowPos(
new Vector2(0, io.DisplaySize.Y * 0.5f + _configuration.CountdownWindowOffset.Y),
Expand Down Expand Up @@ -164,7 +165,7 @@ public void Draw()
ImGui.End();
}

private void DrawCountdown(ImGuiIOPtr io, bool showMainCountdown, float numberScale, float negativeMargin,
private void DrawCountdown(ImGuiIOPtr io, bool showMainCountdown, float numberScale, float negativeMarginScaled,
bool alternateMode)
{
ImGui.SetCursorPosY(0f);
Expand All @@ -174,29 +175,35 @@ private void DrawCountdown(ImGuiIOPtr io, bool showMainCountdown, float numberSc
? Math.Floor(_state.CountDownValue).ToString(CultureInfo.InvariantCulture)
: Math.Ceiling(_state.CountDownValue).ToString(CultureInfo.InvariantCulture);

if (_configuration.CountdownLeadingZero && number.Length == 1) number = "0" + number;

var integers = NumberList(number);
// First loop to compute total width
var totalWidth = 0f;
foreach (var i in integers)
if (_configuration.CountdownMonospaced)
{
totalWidth = (_numberTextures.MaxTextureWidth * numberScale - negativeMarginScaled) * integers.Count;
}
else
{
var texture = _numberTextures.GetAltTexture(i);
totalWidth += (texture.Width * numberScale) - negativeMargin;
foreach (var i in integers)
{
var texture = _numberTextures.GetAltTexture(i);
totalWidth += texture.Width * numberScale - negativeMarginScaled;
}
}

totalWidth += negativeMargin;
totalWidth += negativeMarginScaled;

// Center the cursor
ImGui.SetCursorPosX(io.DisplaySize.X / 2f - totalWidth / 2f + _configuration.CountdownWindowOffset.X);

// Draw the images \o/
foreach (var i in integers)
{
var texture = alternateMode ? _numberTextures.GetAltTexture(i) : _numberTextures.GetTexture(i);
var cursorX = ImGui.GetCursorPosX();
ImGui.Image(texture.ImGuiHandle,
new Vector2(texture.Width * numberScale, texture.Height * numberScale));
ImGui.SameLine();
ImGui.SetCursorPosX(cursorX + (texture.Width * numberScale) - negativeMargin);
DrawNumber(alternateMode, i,
numberScale, negativeMarginScaled,
_numberTextures.MaxTextureWidth * numberScale, _configuration.CountdownMonospaced);
}
}
else if (_configuration.EnableCountdownDecimal)
Expand All @@ -217,22 +224,51 @@ private void DrawCountdown(ImGuiIOPtr io, bool showMainCountdown, float numberSc
- _numberTextures.MaxTextureHeight * smolNumberScale
- _numberTextures.NumberBottomMargin * smolNumberScale;

var cursorY = ImGui.GetCursorPosY();
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + _numberTextures.NumberNegativeMargin);
var cursorY = ImGui.GetCursorPosY() + offsetY;
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + negativeMarginScaled);
foreach (var i in NumberList(decimalPart))
{
var texture = alternateMode ? _numberTextures.GetAltTexture(i) : _numberTextures.GetTexture(i);
var cursorX = ImGui.GetCursorPosX();
var height = texture.Height * smolNumberScale;
ImGui.SetCursorPosY(cursorY + offsetY);
ImGui.Image(texture.ImGuiHandle, new Vector2(texture.Width * smolNumberScale, height));
ImGui.SameLine();
ImGui.SetCursorPosX(cursorX + smolMaxWidthScaled -
_numberTextures.NumberNegativeMargin * smolNumberScale);
ImGui.SetCursorPosY(cursorY);
// small numbers are always fixed width
DrawNumber(alternateMode, i, smolNumberScale,
negativeMarginScaled * smolNumberScale, smolMaxWidthScaled, true);

// var texture = alternateMode ? _numberTextures.GetAltTexture(i) : _numberTextures.GetTexture(i);
// var cursorX = ImGui.GetCursorPosX();
// var height = texture.Height * smolNumberScale;
// ImGui.Image(texture.ImGuiHandle, new Vector2(texture.Width * smolNumberScale, height));
// ImGui.SameLine();
// ImGui.SetCursorPosX(cursorX + smolMaxWidthScaled - negativeMargin * smolNumberScale);
}
}
}

private void DrawNumber(bool alternateMode, int i, float numberScale, float negativeMarginScaled,
float maxWidthScaled,
bool fixedWidth)
{
var texture = alternateMode ? _numberTextures.GetAltTexture(i) : _numberTextures.GetTexture(i);
var width = texture.Width * numberScale;
var cursorX = ImGui.GetCursorPosX();
if (fixedWidth)
{
ImGui.SetCursorPosX(cursorX + (maxWidthScaled - width) / 2);
}

ImGui.Image(texture.ImGuiHandle,
new Vector2(texture.Width * numberScale, texture.Height * numberScale));
ImGui.SameLine();

if (fixedWidth)
{
ImGui.SetCursorPosX(cursorX + maxWidthScaled - negativeMarginScaled);
}
else
{
ImGui.SetCursorPosX(cursorX + width - negativeMarginScaled);
}
}

private static List<int> NumberList(string number)
{
var integers = new List<int>();
Expand Down
12 changes: 12 additions & 0 deletions Ui/NumberTextures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class NumberTextures
public int MaxTextureHeight { get; private set; }

public int NumberNegativeMargin { get; private set; }
public int NumberNegativeMarginMono { get; private set; }
public int NumberBottomMargin { get; private set; }

public NumberTextures(Configuration configuration, UiBuilder uiBuilder, string dataPath)
Expand Down Expand Up @@ -65,6 +66,7 @@ private void LoadImages()

// Read pack settings file
NumberNegativeMargin = 10;
NumberNegativeMarginMono = 10;
NumberBottomMargin = 20;
ReadPackSettings(Path.Combine(texturePath, "settings.json"));

Expand Down Expand Up @@ -105,6 +107,16 @@ private void ReadPackSettings(string settingsFile)
NumberNegativeMargin = nnnToken.Value<int>();
}

var nnnmToken = parsed.SelectToken("NumberNegativeMarginMono");
if (nnnmToken != null)
{
NumberNegativeMarginMono = nnnmToken.Value<int>();
}
else
{
NumberNegativeMarginMono = NumberNegativeMargin;
}

var nbmToken = parsed.SelectToken("NumberBottomMargin");
if (nbmToken != null)
{
Expand Down
Loading

0 comments on commit 6d6954c

Please sign in to comment.