Skip to content

Commit

Permalink
Further update priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
Limiana committed Dec 30, 2024
1 parent 25bd5ef commit b39ebfe
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 21 deletions.
47 changes: 47 additions & 0 deletions Splatoon/Gui/CGuiGeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -162,6 +164,51 @@ void DisplayGeneralSettings()
ImGui.PopID();
}
});
ImGuiEx.TreeNodeCollapsingHeader("Edit saved priority lists", () =>
{
Dictionary<uint, List<RolePlayerAssignment>> 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)
Expand Down
101 changes: 88 additions & 13 deletions Splatoon/Gui/Priority/PriorityPopupWindow.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<TerritoryType>().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())))
{
Expand Down Expand Up @@ -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.");
});
Expand Down Expand Up @@ -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 _));
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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<IActiveNotification>.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)
Expand Down
1 change: 1 addition & 0 deletions Splatoon/Serializables/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ internal class Configuration : IEzConfig
public List<string> FileWatcherPathes = [];
public bool UseServerBar = true;
public Dictionary<Job, RolePosition> PreferredPositions = [];
public PriorityInfoOption ScriptPriorityNotification = PriorityInfoOption.Display_notification;

public uint ClampFillColorAlpha(uint fillColor)
{
Expand Down
11 changes: 11 additions & 0 deletions Splatoon/Serializables/PriorityInfoOption.cs
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions Splatoon/Services/ScriptFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions SplatoonScripts/Tests/PriorityTest.cs
Original file line number Diff line number Diff line change
@@ -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<uint>? ValidTerritories { get; } = null;

public override HashSet<uint>? ValidTerritories { get; } = [Dungeons.Sastasha];
Config C => this.Controller.GetConfig<Config>();

public override void OnSettingsDraw()
Expand Down Expand Up @@ -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;
}
}

0 comments on commit b39ebfe

Please sign in to comment.