diff --git a/ECommons b/ECommons index 49aeffa3..8bfcea0d 160000 --- a/ECommons +++ b/ECommons @@ -1 +1 @@ -Subproject commit 49aeffa3d7b1c68b1490d9cb5ae832b21d52d0f5 +Subproject commit 8bfcea0db8627cae86c958d162e2447ae3194cef diff --git a/Splatoon/Gui/CGuiGeneralSettings.cs b/Splatoon/Gui/CGuiGeneralSettings.cs index 198553ad..7b63fe99 100644 --- a/Splatoon/Gui/CGuiGeneralSettings.cs +++ b/Splatoon/Gui/CGuiGeneralSettings.cs @@ -132,6 +132,8 @@ void DisplayGeneralSettings() { DalamudReflector.SetDtrEntryState(InfoBar.EntryName, state); } + ImGui.SetNextItemWidth(150f); + ImGuiEx.EnumCombo("Priority assignment auto-loading notification", ref P.Config.ScriptPriorityNotification); ImGuiEx.TreeNodeCollapsingHeader("Preferred Role Assignments", () => { ImGuiEx.Text($"Select role assignments that you would like to assigned to yourself via autofill function"); @@ -162,6 +164,51 @@ void DisplayGeneralSettings() ImGui.PopID(); } }); + ImGuiEx.TreeNodeCollapsingHeader("Edit saved priority lists", () => + { + Dictionary> dict = []; + foreach(var x in P.Config.RolePlayerAssignments) + { + if(!dict.TryGetValue(x.Territory, out var list)) + { + list = new(); + dict[x.Territory] = list; + } + list.Add(x); + } + foreach(var x in dict) + { + ImGui.PushID(x.Key.ToString()); + ImGuiEx.TreeNodeCollapsingHeader($"{ExcelTerritoryHelper.GetName(x.Key)} - {x.Value.Count} assignments###edit{x.Key}", () => + { + if(ImGui.BeginTable($"PrioTable{x.Key}", 2, ImGuiEx.DefaultTableFlags)) + { + ImGui.TableSetupColumn("1", ImGuiTableColumnFlags.WidthStretch); + ImGui.TableSetupColumn("2"); + + foreach(var a in x.Value) + { + ImGui.PushID(a.ToString()); + ImGui.TableNextRow(); + ImGui.TableNextColumn(); + var lst = a.Players.Select(p => $"{PriorityPopupWindow.ConfiguredNames.SafeSelect(PriorityPopupWindow.RolePositions.SafeSelect(a.Players.IndexOf(p)))}: {p.Name}{(p.Jobs.Count > 0 ? $" - {p.Jobs.Print()}" : "")}"); + ImGuiEx.TextV($"{lst.Print()}"); + ImGuiEx.Tooltip(lst.Print("\n")); + ImGui.TableNextColumn(); + if(ImGuiEx.IconButton(FontAwesomeIcon.Trash)) + { + new TickScheduler(() => P.Config.RolePlayerAssignments.Remove(a)); + } + ImGui.PopID(); + } + + ImGui.EndTable(); + } + }); + ImGui.PopID(); + } + + }); }) .Section("Miscellaneous", collapsible: false) diff --git a/Splatoon/Gui/Priority/PriorityPopupWindow.cs b/Splatoon/Gui/Priority/PriorityPopupWindow.cs index f10c660a..7661fe42 100644 --- a/Splatoon/Gui/Priority/PriorityPopupWindow.cs +++ b/Splatoon/Gui/Priority/PriorityPopupWindow.cs @@ -1,11 +1,14 @@ using Dalamud.Game.ClientState.Conditions; using Dalamud.Interface.Colors; +using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.Windowing; using ECommons.ChatMethods; using ECommons.ExcelServices; using ECommons.GameHelpers; +using ECommons.ImGuiMethods.TerritorySelection; using ECommons.LanguageHelpers; using ECommons.PartyFunctions; +using Lumina.Excel.Sheets; using Splatoon.SplatoonScripting; using Splatoon.SplatoonScripting.Priority; using System.Collections.ObjectModel; @@ -71,7 +74,28 @@ public override void Draw() this.Assignments.RemoveAt(this.Assignments.Count - 1); } ImGuiEx.TextWrapped($"You have entered a zone for which you have enabled scripts that use priority lists. If you have any priority lists set to \"Placeholder\" mode, please configure them here."); - ImGuiEx.CollectionCheckbox($"Display this popup in {ExcelTerritoryHelper.GetName(TerritoryType)}", TerritoryType, P.Config.NoPrioPopupTerritories, true); + if(IsZoneSupported(this.TerritoryType)) + { + ImGuiEx.CollectionCheckbox($"Display this popup in {ExcelTerritoryHelper.GetName(TerritoryType)}", TerritoryType, P.Config.NoPrioPopupTerritories, true); + } + else + { + ImGuiEx.TextWrapped(EColor.OrangeBright, $"Currently selected zone {ExcelTerritoryHelper.GetName(TerritoryType)} does not supports priority lists. You may still edit it, but you must select supported zone in order to save it."); + } + if(ImGuiEx.IconButtonWithText(FontAwesomeIcon.List, "Select different zone")) + { + new TerritorySelector(this.TerritoryType, (_, x) => + { + this.TerritoryType = x; + this.LoadMatchingAssignment(); + }) + { + HiddenTerritories = Svc.Data.GetExcelSheet().Select(x => x.RowId).Where(x => !IsZoneSupported(x)).ToArray(), + SelectedCategory = TerritorySelector.Category.All, + ExtraColumns = [TerritorySelector.Column.ID, TerritorySelector.Column.IntendedUse], + Mode = TerritorySelector.DisplayMode.PlaceNameDutyUnion, + }; + } ImGui.Checkbox("Display DPS as D1/D2/D3/D4", ref P.Config.PrioUnifyDps); if(ImGuiEx.IconButtonWithText(FontAwesomeIcon.List, "Fill automatically", enabled:ImGuiEx.Ctrl || this.Assignments.All(x => x.IsPlayerEmpty()))) { @@ -126,11 +150,14 @@ public override void Draw() { this.IsOpen = false; } - ImGui.SameLine(); - if(ImGuiEx.IconButtonWithText(FontAwesomeIcon.Save, "Apply and save".Loc())) + if(IsZoneSupported(this.TerritoryType)) { - this.IsOpen = false; - Save(); + ImGui.SameLine(); + if(ImGuiEx.IconButtonWithText(FontAwesomeIcon.Save, "Apply and save".Loc())) + { + this.IsOpen = false; + Save(); + } } ImGuiEx.Tooltip($"When you will join {ExcelTerritoryHelper.GetName(TerritoryType)} again with same players on same jobs, this priority list will be loaded again."); }); @@ -159,6 +186,26 @@ public void Save() P.Config.Save(); } + public static bool IsZoneSupported(uint zone) + { + return ExcelTerritoryHelper.GetTerritoryIntendedUse(zone).EqualsAny([ + TerritoryIntendedUseEnum.Alliance_Raid, + TerritoryIntendedUseEnum.Dungeon, + TerritoryIntendedUseEnum.Deep_Dungeon, + TerritoryIntendedUseEnum.Variant_Dungeon, + TerritoryIntendedUseEnum.Criterion_Duty, + TerritoryIntendedUseEnum.Criterion_Savage_Duty, + TerritoryIntendedUseEnum.Large_Scale_Savage_Raid, + TerritoryIntendedUseEnum.Eureka, + TerritoryIntendedUseEnum.Bozja, + TerritoryIntendedUseEnum.Raid, + TerritoryIntendedUseEnum.Raid_2, + TerritoryIntendedUseEnum.Trial, + TerritoryIntendedUseEnum.Large_Scale_Raid, + TerritoryIntendedUseEnum.Treasure_Map_Duty, + ]); + } + public bool IsValid() { return UniversalParty.LengthPlayback == this.Assignments.Count(x => x.IsInParty(false, out _)); @@ -264,7 +311,7 @@ internal int GetOrderedRoleIndex(Job job) public bool ShouldAutoOpen() { - return ScriptingProcessor.AnyScriptUsesPriority(this.TerritoryType) && !P.Config.NoPrioPopupTerritories.Contains(this.TerritoryType) && !Svc.Condition[ConditionFlag.DutyRecorderPlayback]; + return IsZoneSupported(this.TerritoryType) && ScriptingProcessor.AnyScriptUsesPriority(this.TerritoryType) && !P.Config.NoPrioPopupTerritories.Contains(this.TerritoryType) && !Svc.Condition[ConditionFlag.DutyRecorderPlayback]; } public void Open(bool force) @@ -282,13 +329,7 @@ public void Open(bool force) { if(Player.Available) { - var ass = GetMatchingAssignment(this.TerritoryType); - if(ass != null) - { - this.Assignments.Clear(); - this.Assignments.AddRange(ass.Players.JSONClone()); - ChatPrinter.Green($"[Splatoon] Priority assignments loaded for {ExcelTerritoryHelper.GetName(this.TerritoryType)}:\n{RolePositions.Select(x => $"{x}: {Assignments.SafeSelect(RolePositions.IndexOf(x)).GetNameAndJob()}").Print("\n")}"); - } + LoadMatchingAssignment(); open(); return true; } @@ -304,6 +345,40 @@ void open() } } + public bool LoadMatchingAssignment() + { + var ass = GetMatchingAssignment(this.TerritoryType); + if(ass != null) + { + this.Assignments.Clear(); + this.Assignments.AddRange(ass.Players.JSONClone()); + var assString = $"{RolePositions.Select(x => $"{x}: {Assignments.SafeSelect(RolePositions.IndexOf(x)).GetNameAndJob()}").Print("\n")}"; + var assTitle = $"Priority assignments loaded for {ExcelTerritoryHelper.GetName(this.TerritoryType)}"; + if(P.Config.ScriptPriorityNotification == Serializables.PriorityInfoOption.Print_in_chat_with_roles) + { + ChatPrinter.Green($"[Splatoon] {assTitle}:\n{assString}"); + } + else if(P.Config.ScriptPriorityNotification == Serializables.PriorityInfoOption.Print_in_chat) + { + ChatPrinter.Green($"[Splatoon] {assTitle}."); + } + else if(P.Config.ScriptPriorityNotification == Serializables.PriorityInfoOption.Display_notification) + { + ref var activeNnotification = ref Ref.Get("PrioNotification"); + activeNnotification?.DismissNow(); + var notification = new Notification() + { + Title = assTitle, + Content = assString, + Minimized = false, + InitialDuration = TimeSpan.FromSeconds(10), + }; + activeNnotification = Svc.NotificationManager.AddNotification(notification); + } + } + return ass != null; + } + public RolePlayerAssignment? GetMatchingAssignment(uint territory) { foreach(var x in P.Config.RolePlayerAssignments) diff --git a/Splatoon/Serializables/Configuration.cs b/Splatoon/Serializables/Configuration.cs index 65e7a6d1..c6291e4a 100644 --- a/Splatoon/Serializables/Configuration.cs +++ b/Splatoon/Serializables/Configuration.cs @@ -89,6 +89,7 @@ internal class Configuration : IEzConfig public List FileWatcherPathes = []; public bool UseServerBar = true; public Dictionary PreferredPositions = []; + public PriorityInfoOption ScriptPriorityNotification = PriorityInfoOption.Display_notification; public uint ClampFillColorAlpha(uint fillColor) { diff --git a/Splatoon/Serializables/PriorityInfoOption.cs b/Splatoon/Serializables/PriorityInfoOption.cs new file mode 100644 index 00000000..163906ab --- /dev/null +++ b/Splatoon/Serializables/PriorityInfoOption.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Splatoon.Serializables; +public enum PriorityInfoOption +{ + Print_in_chat_with_roles, Print_in_chat, Display_notification, Disable +} diff --git a/Splatoon/Services/ScriptFileWatcher.cs b/Splatoon/Services/ScriptFileWatcher.cs index 8d9d5508..09b025f1 100644 --- a/Splatoon/Services/ScriptFileWatcher.cs +++ b/Splatoon/Services/ScriptFileWatcher.cs @@ -42,10 +42,9 @@ internal void StartWatching() NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.FileName | - NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size | - NotifyFilters.Security, + NotifyFilters.Security, EnableRaisingEvents = true }; watcher.Created += Watcher_Created; diff --git a/SplatoonScripts/Tests/PriorityTest.cs b/SplatoonScripts/Tests/PriorityTest.cs index c1bfe415..f10bf8d6 100644 --- a/SplatoonScripts/Tests/PriorityTest.cs +++ b/SplatoonScripts/Tests/PriorityTest.cs @@ -1,21 +1,22 @@ using ECommons; using ECommons.Configuration; +using ECommons.ExcelServices.TerritoryEnumeration; using ECommons.ImGuiMethods; using ECommons.PartyFunctions; using ImGuiNET; -using Splatoon.SplatoonScripting; +using Splatoon.SplatoonScripting; using Splatoon.SplatoonScripting.Priority; using System; using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Text; using System.Threading.Tasks; namespace SplatoonScriptsOfficial.Tests; public class PriorityTest : SplatoonScript { - public override HashSet? ValidTerritories { get; } = null; - + public override HashSet? ValidTerritories { get; } = [Dungeons.Sastasha]; + Config C => this.Controller.GetConfig(); public override void OnSettingsDraw() @@ -46,9 +47,13 @@ public class Config : IEzConfig { public PriorityData4 Priority = new(); } - + public class PriorityData4 : PriorityData { public override int GetNumPlayers() => 4; } + public class PriorityData1 : PriorityData + { + public override int GetNumPlayers() => 1; + } }