Skip to content

Commit

Permalink
autofield
Browse files Browse the repository at this point in the history
  • Loading branch information
xorus committed Jan 2, 2024
1 parent 0da3a7c commit 70b30a0
Show file tree
Hide file tree
Showing 25 changed files with 785 additions and 570 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v2.3.0.0 - unreleased

- Big code rewrite and a bit of optimization
- Fix save errors when spinning color sliders like a maniac in configuration
- Reorganized configuration file to preserve my sanity

# v2.2.6.0
Expand Down
74 changes: 74 additions & 0 deletions Plugin/Attributes/AutoField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// This file is part of EngageTimer
// Copyright (C) 2023 Xorus <[email protected]>
//
// 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/>.

#nullable enable

using System;
using EngageTimer.Ui;

namespace EngageTimer.Attributes;

[AttributeUsage(AttributeTargets.Property)]
public class AutoField : Attribute
{
public string? String { get; set; }
public string? Id { get; set; }
public Components.FieldType Mode { get; set; } = Components.FieldType.Auto;
public float? Step { get; set; }
public float? StepFast { get; set; }
public string? Format { get; set; }
public float? Min { get; set; }
public float? Max { get; set; }

public AutoField()
{
}

public AutoField(string str)
{
String = str;
}

public AutoField(string str, Components.FieldType mode)
{
String = str;
Mode = mode;
}

public AutoField(string str, float min, float max)
{
String = str;
Min = min;
Max = max;
}

public AutoField(string str, Components.FieldType mode, float step, float min, float max)
{
String = str;
Mode = mode;
Step = step;
Min = min;
Max = max;
}

public AutoField(string str, Components.FieldType mode, float step, float stepFast, string format)
{
String = str;
Mode = mode;
Step = step;
StepFast = stepFast;
Format = format;
}
}
34 changes: 34 additions & 0 deletions Plugin/Attributes/Help.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file is part of EngageTimer
// Copyright (C) 2023 Xorus <[email protected]>
//
// 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/>.

using System;

namespace EngageTimer.Attributes;

[AttributeUsage(AttributeTargets.Property)]
public class Help: Attribute
{
public string? Str { get; set; }

public Help()
{

}

public Help(string str)
{
Str = str;
}
}
31 changes: 31 additions & 0 deletions Plugin/Attributes/ItemWidth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file is part of EngageTimer
// Copyright (C) 2023 Xorus <[email protected]>
//
// 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/>.

using System;

namespace EngageTimer.Attributes;

#nullable enable

[AttributeUsage(AttributeTargets.Property)]
public class ItemWidth : Attribute
{
public float Width { get; set; }

public ItemWidth(float width)
{
Width = width;
}
}
33 changes: 33 additions & 0 deletions Plugin/Attributes/MinMax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of EngageTimer
// Copyright (C) 2023 Xorus <[email protected]>
//
// 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/>.

using System;

namespace EngageTimer.Attributes;

#nullable enable

[AttributeUsage(AttributeTargets.Property)]
public class MinMax : Attribute
{
public float? Min { get; set; }
public float? Max { get; set; }

public MinMax(float min, float max)
{
Min = min;
Max = max;
}
}
2 changes: 1 addition & 1 deletion Plugin/Commands/MainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void OnCommand(string command, string args)
}
}

private void OnLocaleChanged(object sender, EventArgs e)
private void OnLocaleChanged(object? sender, EventArgs e)
{
Unregister();
Register();
Expand Down
27 changes: 25 additions & 2 deletions Plugin/Configuration/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Timers;
using Dalamud.Configuration;
using Dalamud.Plugin;
using EngageTimer.Configuration.Legacy;
Expand All @@ -40,12 +41,34 @@ public enum TextAlign

public int Version { get; set; } = 3;

[NonSerialized] private Timer _saveTimer;

public ConfigurationFile()
{
_saveTimer = new Timer(250);
_saveTimer.AutoReset = false;
_saveTimer.Elapsed += SaveTimerElapsed;
}

public void Save()
{
Plugin.Logger.Debug("Saving configuration");
_pluginInterface.SavePluginConfig(this);
OnSave?.Invoke(this, EventArgs.Empty);
}


private void SaveTimerElapsed(object? sender, ElapsedEventArgs e)
{
Save();
}

public void DebouncedSave()
{
_saveTimer.Stop();
_saveTimer.Start();
}

public object GetWebConfig()
{
return new
Expand All @@ -55,7 +78,7 @@ public object GetWebConfig()
};
}

public event EventHandler OnSave;
public event EventHandler? OnSave;

public ConfigurationFile Import(OldConfig old)
{
Expand Down Expand Up @@ -105,7 +128,7 @@ public ConfigurationFile Import(OldConfig old)
Countdown.Align = (TextAlign)old.CountdownAlign;
FloatingWindow.FontSize = old.FontSize;
WebServer.Enable = old.EnableWebServer;
WebServer.WebServer = old.WebServerPort;
WebServer.Port = old.WebServerPort;
WebServer.EnableStopwatchTimeout = old.EnableWebStopwatchTimeout;
WebServer.StopwatchTimeout = old.WebStopwatchTimeout;
Dtr.CombatTimeEnabled = old.DtrCombatTimeEnabled;
Expand Down
7 changes: 3 additions & 4 deletions Plugin/Configuration/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ public static ConfigurationFile Load()
// config files before 3 needs some BIG MIGRATION WORK
try
{
return new ConfigurationFile().Import(
JsonConvert.DeserializeObject<OldConfig>(
File.ReadAllText(Plugin.PluginInterface.ConfigFile.FullName)
).Migrate()
var oldConfig = JsonConvert.DeserializeObject<OldConfig>(
File.ReadAllText(Plugin.PluginInterface.ConfigFile.FullName)
);
return oldConfig == null ? new ConfigurationFile() : new ConfigurationFile().Import(oldConfig.Migrate());
}
catch (Exception exception)
{
Expand Down
39 changes: 38 additions & 1 deletion Plugin/Configuration/CountdownConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using System;
using System.Numerics;
using EngageTimer.Attributes;
using EngageTimer.Ui;

namespace EngageTimer.Configuration;

Expand All @@ -25,34 +27,69 @@ public class CountdownConfiguration
{ "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;

[AutoField("Settings_CountdownTab_Audio_Enable")]
public bool EnableTickingSound { get; set; } = false;

[AutoField("Settings_CountdownTab_Audio_UseAlternativeSound")]
public bool UseAlternativeSound { get; set; } = false;

[AutoField("Settings_CountdownTab_TickFrom"), MinMax(5, 30),
Help("Settings_CountdownTab_TickFrom_Help")]
public int StartTickingFrom { get; set; } = 30;

[AutoField("Settings_CountdownTab_CountdownDecimals_Left")]
public bool EnableDecimals { get; set; } = false;

[AutoField("Settings_CountdownTab_CountdownDecimals_Right"), ItemWidth(70f), MinMax(1, 3)]
public int DecimalPrecision { get; set; } = 1;

[AutoField("Settings_CountdownTab_CountdownDisplayThreshold")]
public bool EnableDisplayThreshold { get; set; } = false;

[AutoField(Id = "Settings_CountdownTab_CountdownDisplayThreshold_Value"), MinMax(0, 30),
Help("Settings_CountdownTab_CountdownDisplayThreshold_Help")]
public int DisplayThreshold { get; set; } = 5;

// Countdown style
public string TexturePreset { get; set; } = "default";
public string TextureDirectory { get; set; } = null;
public string? TextureDirectory { get; set; } = null;

[AutoField("Settings_CountdownTab_CountdownScale"), MinMax(.05f, 15f), ItemWidth(100f)]
public float Scale { get; set; } = 1f;

[AutoField("Settings_CountdownTab_Monospaced")]
public bool Monospaced { get; set; }

public float? CustomNegativeMargin { get; set; } = null;

[AutoField("Settings_CountdownTab_NumberStyle_LeadingZero")]
public bool LeadingZero { get; set; }

// Countdown color
public int Hue { get; set; }
public float Saturation { get; set; }
public float Luminance { get; set; }
public bool NumberRecolorMode { get; set; }

[AutoField("Settings_CountdownTab_Animate")]
public bool Animate { get; set; }

[AutoField("Settings_CountdownTab_AnimateScale")]
public bool AnimateScale { get; set; } = true;

[AutoField("Settings_CountdownTab_AnimateOpacity")]
public bool AnimateOpacity { get; set; } = true;

public Vector2 WindowOffset { get; set; } = Vector2.Zero;

[AutoField("Settings_CountdownTab_AccurateMode")]
public bool AccurateMode { get; set; } = false;

public ConfigurationFile.TextAlign Align { get; set; } = ConfigurationFile.TextAlign.Center;
}
16 changes: 14 additions & 2 deletions Plugin/Configuration/DtrConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using EngageTimer.Attributes;
using EngageTimer.Ui;

namespace EngageTimer.Configuration;

Expand All @@ -36,12 +38,22 @@ public bool CombatTimeEnabled
}
}

[AutoField("Settings_DtrCombatTimer_Prefix"), MinMax(0, 50)]
public string CombatTimePrefix { get; set; } = DefaultCombatTimePrefix;

[AutoField("Settings_DtrCombatTimer_Suffix"), MinMax(0, 50)]
public string CombatTimeSuffix { get; set; } = DefaultCombatTimeSuffix;

[AutoField("Settings_DtrCombatTimer_DecimalPrecision"), MinMax(0, 3)]
public int CombatTimeDecimalPrecision { get; set; } = 0;

[AutoField("Settings_DtrCombatTimer_AlwaysDisableOutsideDuty")]
public bool CombatTimeAlwaysDisableOutsideDuty { get; set; }

[AutoField("Settings_DtrCombatTimer_HideAfter")]
public bool CombatTimeEnableHideAfter { get; set; } = false;
public float CombatTimeHideAfter { get; set; } = 20f;

public event EventHandler BarCombatTimerEnableChange;
[AutoField("Settings_DtrCombatTimer_HideAfterRight", Components.FieldType.InputFloat, 0.1f, 1f, "%.1f%")]
public float CombatTimeHideAfter { get; set; } = 20f;
public event EventHandler? BarCombatTimerEnableChange;
}
Loading

0 comments on commit 70b30a0

Please sign in to comment.