diff --git a/Plugin/Attributes/ColorPicker.cs b/Plugin/Attributes/ColorPicker.cs new file mode 100644 index 0000000..6962d01 --- /dev/null +++ b/Plugin/Attributes/ColorPicker.cs @@ -0,0 +1,29 @@ +// This file is part of EngageTimer +// Copyright (C) 2024 Xorus +// +// 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 . + +using System; + +namespace EngageTimer.Attributes; + +[AttributeUsage(AttributeTargets.Property)] +public class ColorPicker : Attribute +{ + public readonly int Id; + + public ColorPicker(int id) + { + Id = id; + } +} \ No newline at end of file diff --git a/Plugin/Commands/MainCommand.cs b/Plugin/Commands/MainCommand.cs index c8b1498..22ee831 100644 --- a/Plugin/Commands/MainCommand.cs +++ b/Plugin/Commands/MainCommand.cs @@ -93,20 +93,20 @@ private void OnCommand(string command, string args) case "c": case "countdown": Plugin.Config.Countdown.Display = ToStatus(argument, Plugin.Config.Countdown.Display); - Plugin.Config.Save(); + Plugin.Config.SaveNow(); Plugin.ChatGui.Print(Translator.Tr("MainCommand_Help_Countdown_Success", StatusStr(Plugin.Config.Countdown.Display))); break; case "sw": case "fw": Plugin.Config.FloatingWindow.Display = ToStatus(argument, Plugin.Config.FloatingWindow.Display); - Plugin.Config.Save(); + Plugin.Config.SaveNow(); Plugin.ChatGui.Print(Translator.Tr("MainCommand_Help_FW_Success", StatusStr(Plugin.Config.FloatingWindow.Display))); break; case "dtr": Plugin.Config.Dtr.CombatTimeEnabled = ToStatus(argument, Plugin.Config.Dtr.CombatTimeEnabled); - Plugin.Config.Save(); + Plugin.Config.SaveNow(); Plugin.ChatGui.Print(Translator.Tr("MainCommand_Help_Dtr_Success", StatusStr(Plugin.Config.Dtr.CombatTimeEnabled))); break; diff --git a/Plugin/Configuration/ConfigurationFile.cs b/Plugin/Configuration/ConfigurationFile.cs index be10779..68241cf 100644 --- a/Plugin/Configuration/ConfigurationFile.cs +++ b/Plugin/Configuration/ConfigurationFile.cs @@ -51,7 +51,7 @@ public ConfigurationFile() _saveTimer.Elapsed += SaveTimerElapsed; } - public void Save() + public void SaveNow() { Plugin.Logger.Debug("Saving configuration"); _pluginInterface.SavePluginConfig(this); @@ -61,10 +61,10 @@ public void Save() private void SaveTimerElapsed(object? sender, ElapsedEventArgs e) { - Save(); + SaveNow(); } - public void DebouncedSave() + public void Save() { _saveTimer.Stop(); _saveTimer.Start(); @@ -140,7 +140,7 @@ public ConfigurationFile Import(OldConfig old) Dtr.CombatTimeEnableHideAfter = old.DtrCombatTimeEnableHideAfter; Dtr.CombatTimeHideAfter = old.DtrCombatTimeHideAfter; Version = 3; - Save(); + SaveNow(); return this; } diff --git a/Plugin/Configuration/FloatingWindowConfiguration.cs b/Plugin/Configuration/FloatingWindowConfiguration.cs index 4e630a9..9face6a 100644 --- a/Plugin/Configuration/FloatingWindowConfiguration.cs +++ b/Plugin/Configuration/FloatingWindowConfiguration.cs @@ -65,14 +65,14 @@ public class FloatingWindowConfiguration [AutoField("Settings_FWTab_PrePullOffset", Components.FieldType.InputFloat, 0.1f, 1f, "%.3fs")] public float PrePullOffset { get; set; } = .0f; - [AutoField("Settings_FWTab_TextColor")] + [AutoField("Settings_FWTab_TextColor"), ColorPicker(1)] public Vector4 PrePullColor { get; set; } = ImGuiColors.DalamudRed; // Stopwatch cosmetics - [AutoField("Settings_FWTab_TextColor")] + [AutoField("Settings_FWTab_TextColor"), ColorPicker(2)] public Vector4 TextColor { get; set; } = new(255, 255, 255, 1); - [AutoField("Settings_FWTab_BackgroundColor")] + [AutoField("Settings_FWTab_BackgroundColor"), ColorPicker(3)] public Vector4 BackgroundColor { get; set; } = new(0, 0, 0, 0); public ConfigurationFile.TextAlign Align { get; set; } = ConfigurationFile.TextAlign.Left; diff --git a/Plugin/Configuration/Legacy/CombatAlarmsConfiguration.cs b/Plugin/Configuration/Legacy/CombatAlarmsConfiguration.cs index 7383f70..ea94f13 100644 --- a/Plugin/Configuration/Legacy/CombatAlarmsConfiguration.cs +++ b/Plugin/Configuration/Legacy/CombatAlarmsConfiguration.cs @@ -22,21 +22,21 @@ public class CombatAlarmsConfiguration { public enum TextType { - DalamudNotification = 0, - GameToast = 1, - ChatLogMessage = 2 + ChatLogMessage = 0, + DalamudNotification = 1, + GameToast = 2 } public class Alarm { public bool Enabled = true; - public int StartTime; - public int Duration; + public int StartTime = 270; + public int Duration = 10; public string? Text; - public Vector4? Color; - public int? Sfx; + public Vector4? Color = new Vector4(.8f, .24f, .24f, 1); + public int? Sfx = 9; public TextType TextType = TextType.DalamudNotification; - public bool Blink; + public bool Blink = false; } public readonly List Alarms = new() diff --git a/Plugin/Properties/Resources.Designer.cs b/Plugin/Properties/Resources.Designer.cs index 0bbb08f..8480d16 100644 --- a/Plugin/Properties/Resources.Designer.cs +++ b/Plugin/Properties/Resources.Designer.cs @@ -59,6 +59,195 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to Active. + /// + internal static string AlarmEdit_Active { + get { + return ResourceManager.GetString("AlarmEdit_Active", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enables / disables this alarm. + /// + internal static string AlarmEdit_Active_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_Active_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Blink. + /// + internal static string AlarmEdit_Blink { + get { + return ResourceManager.GetString("AlarmEdit_Blink", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Makes the floating window stopwatch blink during the alarm. + /// + internal static string AlarmEdit_Blink_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_Blink_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Color. + /// + internal static string AlarmEdit_Color { + get { + return ResourceManager.GetString("AlarmEdit_Color", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Applies the color to the floating window stopwatch during the alarm. + /// + internal static string AlarmEdit_Color_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_Color_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Duration. + /// + internal static string AlarmEdit_Duration { + get { + return ResourceManager.GetString("AlarmEdit_Duration", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Stops the color/blink after this amount of time. + /// + internal static string AlarmEdit_Duration_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_Duration_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sound. + /// + internal static string AlarmEdit_Sound { + get { + return ResourceManager.GetString("AlarmEdit_Sound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to None. + /// + internal static string AlarmEdit_Sound_None { + get { + return ResourceManager.GetString("AlarmEdit_Sound_None", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Plays a game sound effect at the alarm time. + /// + internal static string AlarmEdit_Sound_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_Sound_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Start time. + /// + internal static string AlarmEdit_StartTime { + get { + return ResourceManager.GetString("AlarmEdit_StartTime", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The alarm will start at this specified combat time. + /// + internal static string AlarmEdit_StartTime_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_StartTime_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text. + /// + internal static string AlarmEdit_Text { + get { + return ResourceManager.GetString("AlarmEdit_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Clear. + /// + internal static string AlarmEdit_Text_Clear { + get { + return ResourceManager.GetString("AlarmEdit_Text_Clear", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text. + /// + internal static string AlarmEdit_Text_Text { + get { + return ResourceManager.GetString("AlarmEdit_Text_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Allows you to display a text notification at the alarm time. + /// + internal static string AlarmEdit_Text_Tooltip { + get { + return ResourceManager.GetString("AlarmEdit_Text_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Type. + /// + internal static string AlarmEdit_Text_Type { + get { + return ResourceManager.GetString("AlarmEdit_Text_Type", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Chat log. + /// + internal static string AlarmEdit_Type_ChatLog { + get { + return ResourceManager.GetString("AlarmEdit_Type_ChatLog", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dalamud Notification. + /// + internal static string AlarmEdit_Type_DalamudNotification { + get { + return ResourceManager.GetString("AlarmEdit_Type_DalamudNotification", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Game toast. + /// + internal static string AlarmEdit_Type_GameToast { + get { + return ResourceManager.GetString("AlarmEdit_Type_GameToast", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unrecognized argument for {0}: {1}. /// @@ -158,6 +347,33 @@ internal static string MainCommand_Status_On { } } + /// + /// Looks up a localized string similar to This page allows you to set alarms based on elapsed combat time.. + /// + internal static string Settings_AlarmsTab_Line1 { + get { + return ResourceManager.GetString("Settings_AlarmsTab_Line1", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A common use is to notify you of the potion window.. + /// + internal static string Settings_AlarmsTab_Line2 { + get { + return ResourceManager.GetString("Settings_AlarmsTab_Line2", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Alarms. + /// + internal static string Settings_AlarmsTab_Title { + get { + return ResourceManager.GetString("Settings_AlarmsTab_Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Close. /// diff --git a/Plugin/Properties/Resources.resx b/Plugin/Properties/Resources.resx index aef36b3..b3c723c 100644 --- a/Plugin/Properties/Resources.resx +++ b/Plugin/Properties/Resources.resx @@ -494,4 +494,76 @@ help text for the /eg settings command This setting will make it so the sound plays from numbers 5 to the selected value. Note: this plugin cannot remove the tick sound for numbers 1-5. + + Alarms + + + Active + + + Start time + + + Color + + + Blink + + + Duration + + + Sound + + + None + + + Text + + + Dalamud Notification + + + Game toast + + + Chat log + + + Enables / disables this alarm + + + The alarm will start at this specified combat time + + + Applies the color to the floating window stopwatch during the alarm + + + Makes the floating window stopwatch blink during the alarm + + + Stops the color/blink after this amount of time + + + Plays a game sound effect at the alarm time + + + Allows you to display a text notification at the alarm time + + + Type + + + Text + + + Clear + + + This page allows you to set alarms based on elapsed combat time. + + + A common use is to notify you of the potion window. + \ No newline at end of file diff --git a/Plugin/Status/CombatAlarm.cs b/Plugin/Status/CombatAlarm.cs index 8ab013a..dacfea8 100644 --- a/Plugin/Status/CombatAlarm.cs +++ b/Plugin/Status/CombatAlarm.cs @@ -15,8 +15,6 @@ using System; using System.Collections.Generic; -using System.Net.Mime; -using Dalamud.Game.Gui.Toast; using Dalamud.Game.Text; using Dalamud.Interface.Internal.Notifications; using Dalamud.Plugin.Services; @@ -42,7 +40,6 @@ private class AlarmAction private readonly Dictionary _alarms = new(); - // private readonly List _rangAlarms = new(); private int? _lastCheck = null; public CombatAlarm() @@ -56,6 +53,7 @@ public CombatAlarm() private void ConfigurationChanged(object? sender, EventArgs e) { + ClearAlarms(); _alarms.Clear(); for (var index = 0; index < Plugin.Config.CombatAlarms.Alarms.Count; index++) { @@ -75,7 +73,7 @@ private void ConfigurationChanged(object? sender, EventArgs e) } } - private void InCombatChanged(object? sender, EventArgs e) + private static void InCombatChanged(object? sender, EventArgs e) { if (!Plugin.State.InCombat) { @@ -99,59 +97,59 @@ private void FrameworkUpdate(IFramework framework) if (alarm.Type == AlarmActionType.Start) { RunAlarm(alarm.Config); - // _rangAlarms.Add(time); + return; } - if (alarm.Type == AlarmActionType.Stop) - { - ClearAlarms(); - } + if (alarm.Type == AlarmActionType.Stop) ClearAlarms(); } - private void RunAlarm(CombatAlarmsConfiguration.Alarm alarm) + public static void AlarmSfx(CombatAlarmsConfiguration.Alarm alarm) { if (alarm.Sfx != null) { - // Plugin.SfxPlay.SoundEffect(); Plugin.SfxPlay.SoundEffect((uint)(SfxPlay.FirstSeSfx + alarm.Sfx)); } + } + public static void AlarmText(CombatAlarmsConfiguration.Alarm alarm) + { var trimText = alarm.Text?.Trim(); - if (trimText is { Length: > 0 }) + if (trimText is not { Length: > 0 }) return; + switch (alarm.TextType) { - switch (alarm.TextType) - { - case CombatAlarmsConfiguration.TextType.DalamudNotification: - Plugin.PluginInterface.UiBuilder.AddNotification( - trimText, - "EngageTimer", - NotificationType.Info, - 8000 - ); - break; - case CombatAlarmsConfiguration.TextType.GameToast: - Plugin.ToastGui.ShowNormal(trimText); - break; - case CombatAlarmsConfiguration.TextType.ChatLogMessage: - // Plugin.ChatGui.Print(trimText, "EngageTimer"); - Plugin.ChatGui.Print(new XivChatEntry() - { - Type = XivChatType.Echo, - Name = "EngageTimer", - Message = trimText - }); - break; - } + case CombatAlarmsConfiguration.TextType.DalamudNotification: + Plugin.PluginInterface.UiBuilder.AddNotification( + trimText, + "EngageTimer", + NotificationType.Info, + 8000 + ); + break; + case CombatAlarmsConfiguration.TextType.GameToast: + Plugin.ToastGui.ShowNormal(trimText); + break; + case CombatAlarmsConfiguration.TextType.ChatLogMessage: + // Plugin.ChatGui.Print(trimText, "EngageTimer"); + Plugin.ChatGui.Print(new XivChatEntry() + { + Type = XivChatType.Echo, + Name = "EngageTimer", + Message = trimText + }); + break; } + } - if (alarm.Color != null) - { - Plugin.State.OverrideFwColor = alarm.Color; - Plugin.State.BlinkStopwatch = alarm.Blink; - } + private static void RunAlarm(CombatAlarmsConfiguration.Alarm alarm) + { + AlarmSfx(alarm); + AlarmText(alarm); + if (alarm.Color == null) return; + Plugin.State.OverrideFwColor = alarm.Color; + Plugin.State.BlinkStopwatch = alarm.Blink; } - private void ClearAlarms() + private static void ClearAlarms() { Plugin.State.OverrideFwColor = null; Plugin.State.BlinkStopwatch = false; diff --git a/Plugin/Ui/Components.cs b/Plugin/Ui/Components.cs index 4c3e677..30f119d 100644 --- a/Plugin/Ui/Components.cs +++ b/Plugin/Ui/Components.cs @@ -31,7 +31,7 @@ public static void Checkbox(bool original, string title, ApplyCallback sav var state = original; if (!ImGui.Checkbox(title, ref state)) return; save(state); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } public static void InputFloat( @@ -52,17 +52,17 @@ public static void InputFloat( if (value < min) value = (float)min; if (value > max) value = (float)max; apply(value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } ImGui.PopItemWidth(); } - public static void IconButton(FontAwesomeIcon icon, string id, ApplyCallback save) + public static void IconButton(FontAwesomeIcon icon, string id, ApplyCallback apply) { if (!ImGuiComponents.IconButton($"{icon.ToIconString()}###{id}")) return; - save(); - Plugin.Config.DebouncedSave(); + apply(); + Plugin.Config.Save(); } public static void Text(string label, bool sameLine = false) @@ -77,7 +77,7 @@ public static void ResettableDraggable(string id, string label, int original, in IconButton(FontAwesomeIcon.Undo, $"reset_{id}", () => { apply(defaultValue); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); }); ImGui.SameLine(); var value = original; @@ -87,7 +87,7 @@ public static void ResettableDraggable(string id, string label, int original, in if (value > max) value = min; if (value < min) value = max; apply(value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } public static void ResettableSlider(string id, string label, float original, float defaultValue, @@ -96,14 +96,14 @@ public static void ResettableSlider(string id, string label, float original, flo IconButton(FontAwesomeIcon.Undo, $"reset_{id}", () => { apply(defaultValue); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); }); ImGui.SameLine(); var value = original; if (!ImGui.SliderFloat(label, ref value, -1f, 1f)) return; value = Math.Clamp(value, min, max); apply(value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } public delegate void ApplyCallback(); @@ -159,7 +159,7 @@ private static void ShowField(T instance, FieldType? foundType, PropertyInfo var value = (bool)(prop.GetValue(instance) ?? false); if (!ImGui.Checkbox(label, ref value)) return; prop.SetValue(instance, value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } else if (foundType == FieldType.InputInt) { @@ -168,7 +168,7 @@ private static void ShowField(T instance, FieldType? foundType, PropertyInfo if (min != null) value = Math.Max((int)min, value); if (max != null) value = Math.Min((int)max, value); prop.SetValue(instance, value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); customApply?.Invoke(); } else if (foundType == FieldType.InputFloat) @@ -188,7 +188,7 @@ private static void ShowField(T instance, FieldType? foundType, PropertyInfo if (max != null) value = Math.Min((float)max, value); prop.SetValue(instance, value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); customApply?.Invoke(); } else if (foundType == FieldType.DragFloat) @@ -207,17 +207,24 @@ private static void ShowField(T instance, FieldType? foundType, PropertyInfo if (max != null) value = Math.Min((float)max, value); prop.SetValue(instance, value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); customApply?.Invoke(); } else if (foundType == FieldType.ColorPicker) { + var colorPickerAttr = (ColorPicker?)prop.GetCustomAttribute(typeof(ColorPicker)); + if (colorPickerAttr == null) + { + ImGui.Text("!!cannot find ColorPicker attribute!!"); + return; + } + var value = (Vector4)(prop.GetValue(instance) ?? new Vector4()); - var newValue = ImGuiComponents.ColorPickerWithPalette(10, label, value); - if (value == newValue) + var newValue = ImGuiComponents.ColorPickerWithPalette(3112 + colorPickerAttr.Id, label, value); + if (value != newValue) { - prop.SetValue(instance, value); - Plugin.Config.DebouncedSave(); + prop.SetValue(instance, newValue); + Plugin.Config.Save(); customApply?.Invoke(); } @@ -229,7 +236,7 @@ private static void ShowField(T instance, FieldType? foundType, PropertyInfo var value = (string)(prop.GetValue(instance) ?? ""); if (!ImGui.InputText(label, ref value, (uint)(max ?? 100))) return; prop.SetValue(instance, value); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); customApply?.Invoke(); } else @@ -261,4 +268,58 @@ public enum FieldType ColorPicker, InputText } + + public static bool InputTime(string id, ref int seconds) + { + ImGui.PushID(id); + + var changed = false; + var min = (int)Math.Floor(seconds / 60d); + var sec = (int)Math.Floor(seconds % 60d); + ImGui.PushItemWidth(30f); + if (ImGui.DragInt("###min", ref min, 1, 0, 180, "%02d")) + { + seconds = min * 60 + sec; + changed = true; + } + + ImGui.PopItemWidth(); + ImGui.SameLine(); + ImGui.Text(":"); + ImGui.SameLine(); + ImGui.PushItemWidth(30f); + if (ImGui.DragInt("###sec", ref sec, 1, -1, 61, "%02d")) + { + if (min == 0 && sec < 0) sec = 0; + if (sec < 0) + { + min = Math.Max(0, min - 1); + sec = 59; + } + + if (sec > 60) + { + min++; + sec = 0; + } + + seconds = min * 60 + sec; + changed = true; + } + + ImGui.PopItemWidth(); + ImGui.PopID(); + + return changed; + } + + public static void TooltipOnItemHovered(string text) + { + if (!ImGui.IsItemHovered()) return; + ImGui.BeginTooltip(); + ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35f); + ImGui.TextUnformatted(Translator.Tr(text)); + ImGui.PopTextWrapPos(); + ImGui.EndTooltip(); + } } \ No newline at end of file diff --git a/Plugin/Ui/Settings.cs b/Plugin/Ui/Settings.cs index ccbfb33..0781b58 100644 --- a/Plugin/Ui/Settings.cs +++ b/Plugin/Ui/Settings.cs @@ -77,11 +77,11 @@ public override void Draw() ImGui.EndTabItem(); } - // if (ImGui.BeginTabItem(Translator.TrId("Settings_Alarms"))) - // { - // AlarmsTab.Draw(); - // ImGui.EndTabItem(); - // } + if (ImGui.BeginTabItem(Translator.TrId("Settings_AlarmsTab_Title"))) + { + AlarmsTab.Draw(); + ImGui.EndTabItem(); + } if (ImGui.BeginTabItem("About")) { diff --git a/Plugin/Ui/SettingsTab/AlarmsTab.cs b/Plugin/Ui/SettingsTab/AlarmsTab.cs index aec6aec..a28c990 100644 --- a/Plugin/Ui/SettingsTab/AlarmsTab.cs +++ b/Plugin/Ui/SettingsTab/AlarmsTab.cs @@ -13,52 +13,234 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +using System; +using System.Collections.Generic; +using System.Numerics; using Dalamud.Interface; +using Dalamud.Interface.Components; +using Dalamud.Interface.Utility; using EngageTimer.Configuration.Legacy; +using EngageTimer.Game; +using EngageTimer.Status; using ImGuiNET; namespace EngageTimer.Ui.SettingsTab; public static class AlarmsTab { + private static void Header(bool tooltip = false) + { + ImGui.TableNextColumn(); + var str = ImGui.TableGetColumnName(ImGui.TableGetColumnIndex()); + ImGui.TableHeader(Translator.Tr(ImGui.TableGetColumnName(ImGui.TableGetColumnIndex()))); + if (tooltip) Components.TooltipOnItemHovered(Translator.Tr(str + "_Tooltip")); + } + + private static readonly List EditingTexts = new(); + public static void Draw() { - ImGui.Text("Some explanation text here"); + ImGui.Text(Translator.Tr("Settings_AlarmsTab_Line1")); + ImGui.Text(Translator.Tr("Settings_AlarmsTab_Line2")); ImGui.Separator(); - ImGui.Text("Alarm list"); - if (Plugin.Config.CombatAlarms.Alarms.Count == 0) + if (ImGui.BeginTable("alarms", 8, ImGuiTableFlags.Borders)) { - ImGui.Text("No alarms set"); - return; - } + ImGui.TableSetupColumn(" "); + ImGui.TableSetupColumn("AlarmEdit_Active"); + ImGui.TableSetupColumn("AlarmEdit_StartTime"); + ImGui.TableSetupColumn("AlarmEdit_Color"); + ImGui.TableSetupColumn("AlarmEdit_Blink"); + ImGui.TableSetupColumn("AlarmEdit_Duration"); + ImGui.TableSetupColumn("AlarmEdit_Sound"); + ImGui.TableSetupColumn("AlarmEdit_Text"); - for (var index = 0; index < Plugin.Config.CombatAlarms.Alarms.Count; index++) - { - AlarmElement(index, Plugin.Config.CombatAlarms.Alarms[index]); + ImGui.TableNextRow(ImGuiTableRowFlags.Headers); + // trash can + ImGui.TableNextColumn(); + ImGui.Text(""); + Header(true); // active + Header(true); // start time + Header(true); // color + Header(true); // blink + Header(true); // duration + Header(true); // sound + Header(true); // text notification + + for (var index = 0; index < Plugin.Config.CombatAlarms.Alarms.Count; index++) + { + AlarmElement(index, Plugin.Config.CombatAlarms.Alarms[index]); + } + + ImGui.EndTable(); } - if (ImGui.Button("add")) + if (ImGuiComponents.IconButton($"{FontAwesomeIcon.Plus.ToIconString()}###add")) { + Plugin.Config.CombatAlarms.Alarms.Add(new CombatAlarmsConfiguration.Alarm()); + Plugin.Config.Save(); } } private static void AlarmElement(int index, CombatAlarmsConfiguration.Alarm alarm) { - ImGui.PushID("alarm_" + index); - ImGui.BeginGroup(); - Components.IconButton(FontAwesomeIcon.Trash, "delete_" + index, - () => Plugin.Config.CombatAlarms.Alarms.RemoveAt(index)); - ImGui.SameLine(); - ImGui.Text("Alarm " + index); - ImGui.EndGroup(); - - ImGui.Indent(); { - var startTimeFormatted = "00:00"; - ImGui.InputText("start time", ref startTimeFormatted, 10); + ImGui.TableNextRow(); + ImGui.TableNextColumn(); + ImGui.PushID("alarm_" + index); + Components.IconButton(FontAwesomeIcon.Trash, "delete" + index, + () => + { + EditingTexts.Remove(index); + Plugin.Config.CombatAlarms.Alarms.RemoveAt(index); + }); + } + { + ImGui.TableNextColumn(); + ImGui.Checkbox("###enabled" + index, ref alarm.Enabled); + } + { + ImGui.TableNextColumn(); + var startTime = alarm.StartTime; + + if (Components.InputTime("start_time", ref startTime)) + { + alarm.StartTime = startTime; + Plugin.Config.Save(); + } + } + { + ImGui.TableNextColumn(); + var color = alarm.Color ?? Plugin.Config.FloatingWindow.TextColor; + var newValue = + ImGuiComponents.ColorPickerWithPalette(3111, Translator.Tr("AlarmEdit_Color_Tooltip"), color); + if (color != newValue) + { + alarm.Color = newValue; + Plugin.Config.Save(); + } + + ImGui.SameLine(); + if (ImGuiComponents.IconButton($"{FontAwesomeIcon.Undo.ToIconString()}###clearColor")) + { + alarm.Color = null; + Plugin.Config.Save(); + } + } + { + ImGui.TableNextColumn(); + if (ImGui.Checkbox("###blink", ref alarm.Blink)) + { + Plugin.Config.Save(); + } } - ImGui.Unindent(); + { + ImGui.TableNextColumn(); + ImGui.PushItemWidth(50f); + var duration = alarm.Duration; + if (ImGui.DragInt("###duration" + index, ref duration, 1, 0, 1000, "%ds")) + { + duration = Math.Max(duration, 0); + alarm.Duration = duration; + Plugin.Config.Save(); + } + + ImGui.PopItemWidth(); + } + { + ImGui.TableNextColumn(); + ImGui.PushItemWidth(80f); + var choice = alarm.Sfx ?? 0; + if (ImGui.Combo("###sfx", ref choice, Translator.Tr("AlarmEdit_Sound_None") + + "\0\0\0\0\0" + + "\0\0\0\0\0\0\0\0" + + "\0\0\0\0")) + { + alarm.Sfx = choice == 0 ? null : choice; + CombatAlarm.AlarmSfx(alarm); + } + + ImGui.PopItemWidth(); + } + { + ImGui.TableNextColumn(); + if (EditingTexts.Contains(index)) + { + var type = (int)alarm.TextType; + ImGui.PushItemWidth(150f); + if (ImGui.Combo("Type", ref type, Translator.Tr("AlarmEdit_Type_ChatLog") + "\0" + + Translator.Tr("AlarmEdit_Type_DalamudNotification") + "\0" + + Translator.Tr("AlarmEdit_Type_GameToast") + "\0")) + { + alarm.TextType = (CombatAlarmsConfiguration.TextType)type; + Plugin.Config.Save(); + } + + var text = alarm.Text ?? ""; + if (ImGui.InputText(Translator.Tr("AlarmEdit_Text_Text"), ref text, 100)) + { + text = text.Trim(); + alarm.Text = text.Length == 0 ? null : text; + Plugin.Config.Save(); + } + + ImGui.PopItemWidth(); + + if (ImGui.Button(Translator.Tr("AlarmEdit_Text_Type"))) + { + CombatAlarm.AlarmText(alarm); + } + + ImGui.SameLine(); + if (ImGui.Button(Translator.Tr("AlarmEdit_Text_Clear"))) + { + alarm.Text = null; + Plugin.Config.Save(); + EditingTexts.Remove(index); + } + + ImGui.SameLine(); + if (ImGuiComponents.IconButton($"{FontAwesomeIcon.Check.ToIconString()}###doneEditing")) + { + EditingTexts.Remove(index); + Plugin.Config.Save(); + } + } + else + { + if (alarm.Text == null) + { + ImGui.Text("No text"); + } + else + { + ImGui.Text("Type: "); + ImGui.SameLine(); + switch (alarm.TextType) + { + case CombatAlarmsConfiguration.TextType.DalamudNotification: + ImGui.Text("Dalamud notification"); + break; + case CombatAlarmsConfiguration.TextType.GameToast: + ImGui.Text("Toast"); + break; + case CombatAlarmsConfiguration.TextType.ChatLogMessage: + ImGui.Text("Log message"); + break; + } + + ImGui.Text(alarm.Text); + } + + ImGui.SameLine(); + if (ImGuiComponents.IconButton($"{FontAwesomeIcon.Comment.ToIconString()}###editNotification")) + { + // coggers! + EditingTexts.Add(index); + } + } + } + ImGui.PopID(); } } \ No newline at end of file diff --git a/Plugin/Ui/SettingsTab/CountdownTab.cs b/Plugin/Ui/SettingsTab/CountdownTab.cs index 264a500..6176569 100644 --- a/Plugin/Ui/SettingsTab/CountdownTab.cs +++ b/Plugin/Ui/SettingsTab/CountdownTab.cs @@ -151,7 +151,7 @@ private static void CountdownPositionAndSize() { Plugin.Config.Countdown.WindowOffset = new Vector2(countdownOffsetX / 100, Plugin.Config.Countdown.WindowOffset.Y); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } ImGui.SameLine(); @@ -161,7 +161,7 @@ private static void CountdownPositionAndSize() { Plugin.Config.Countdown.WindowOffset = new Vector2(Plugin.Config.Countdown.WindowOffset.X, countdownOffsetY / 100); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } ImGui.SameLine(); @@ -171,7 +171,7 @@ private static void CountdownPositionAndSize() if (ImGuiComponents.IconButton(FontAwesomeIcon.Undo.ToIconString() + "###reset_cd_offset")) { Plugin.Config.Countdown.WindowOffset = Vector2.Zero; - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } var countdownScale = Plugin.Config.Countdown.Scale; @@ -179,7 +179,7 @@ private static void CountdownPositionAndSize() if (ImGui.InputFloat(Translator.TrId("Settings_CountdownTab_CountdownScale"), ref countdownScale, .01f)) { Plugin.Config.Countdown.Scale = Math.Clamp(countdownScale, 0.05f, 15f); - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } ImGui.PopItemWidth(); @@ -191,7 +191,7 @@ private static void CountdownPositionAndSize() Translator.Tr("Settings_FWTab_TextAlign_Right") + "###Right")) { Plugin.Config.Countdown.Align = (ConfigurationFile.TextAlign)align; - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } @@ -231,7 +231,7 @@ private static void CountdownNumberStyle() choiceString)) { configuration.Countdown.TexturePreset = currentTexture < choices.Count() ? choices[currentTexture] : ""; - configuration.DebouncedSave(); + configuration.Save(); Plugin.NumberTextures.Load(); } @@ -247,7 +247,7 @@ private static void CountdownNumberStyle() if (ImGui.Button(Translator.TrId("Settings_CountdownTab_Texture_Custom_Load"))) { configuration.Countdown.TextureDirectory = _tempTexturePath; - configuration.DebouncedSave(); + configuration.Save(); Plugin.NumberTextures.Load(); } } @@ -270,7 +270,7 @@ private static void CountdownNumberStyle() 1f)) { configuration.Countdown.CustomNegativeMargin = nm; - configuration.Save(); + configuration.SaveNow(); } ImGui.PopItemWidth(); diff --git a/Plugin/Ui/SettingsTab/DtrTab.cs b/Plugin/Ui/SettingsTab/DtrTab.cs index 93e683d..a4eb4d5 100644 --- a/Plugin/Ui/SettingsTab/DtrTab.cs +++ b/Plugin/Ui/SettingsTab/DtrTab.cs @@ -31,7 +31,7 @@ public static void Draw() if (ImGui.Checkbox(Translator.TrId("Settings_DtrCombatTimer_Enable"), ref enabled)) { Plugin.Config.Dtr.CombatTimeEnabled = enabled; - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } Components.AutoField(Plugin.Config.Dtr, "CombatTimePrefix"); @@ -43,7 +43,7 @@ public static void Draw() { Plugin.Config.Dtr.CombatTimePrefix = DtrConfiguration.DefaultCombatTimePrefix; Plugin.Config.Dtr.CombatTimeSuffix = DtrConfiguration.DefaultCombatTimeSuffix; - Plugin.Config.DebouncedSave(); + Plugin.Config.Save(); } Components.AutoField(Plugin.Config.Dtr, "CombatTimeAlwaysDisableOutsideDuty"); diff --git a/Plugin/Ui/SettingsTab/FloatingWindowTab.cs b/Plugin/Ui/SettingsTab/FloatingWindowTab.cs index 5bf4b25..020e64f 100644 --- a/Plugin/Ui/SettingsTab/FloatingWindowTab.cs +++ b/Plugin/Ui/SettingsTab/FloatingWindowTab.cs @@ -86,14 +86,14 @@ private static void FwStyling() Translator.Tr("Settings_FWTab_TextAlign_Right") + "###Right")) { configuration.FloatingWindow.Align = (ConfigurationFile.TextAlign)textAlign; - configuration.DebouncedSave(); + configuration.Save(); } var fontSize = configuration.FloatingWindow.FontSize; if (ImGui.InputInt(Translator.TrId("Settings_FWTab_FontSize"), ref fontSize, 4)) { configuration.FloatingWindow.FontSize = Math.Max(0, fontSize); - configuration.DebouncedSave(); + configuration.Save(); if (configuration.FloatingWindow.FontSize >= 8) Plugin.PluginInterface.UiBuilder.RebuildFonts(); }