From 597b7bb00089c6739c40e26f1f08e128c92235c4 Mon Sep 17 00:00:00 2001 From: goaaats Date: Sat, 29 Jan 2022 04:44:52 +0100 Subject: [PATCH] feat: DTR toggling & reordering in settings window --- .../Internal/DalamudConfiguration.cs | 5 + Dalamud/Game/Gui/Dtr/DtrBar.cs | 81 ++++++++----- .../Internal/Windows/SettingsWindow.cs | 110 ++++++++++++++++++ 3 files changed, 166 insertions(+), 30 deletions(-) diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index 9451f1c05..aa9277d3d 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -245,6 +245,11 @@ namespace Dalamud.Configuration.Internal /// public List? DtrOrder { get; set; } + /// + /// Gets or sets the list of ignored DTR elements, by title. + /// + public List? DtrIgnore { get; set; } + /// /// Load a configuration from the provided path. /// diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs index 18b75cfb4..468de495f 100644 --- a/Dalamud/Game/Gui/Dtr/DtrBar.cs +++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs @@ -33,6 +33,11 @@ namespace Dalamud.Game.Gui.Dtr public DtrBar() { Service.Get().Update += this.Update; + var configuration = Service.Get(); + + configuration.DtrOrder ??= new List(); + configuration.DtrIgnore ??= new List(); + configuration.Save(); } /// @@ -75,6 +80,47 @@ namespace Dalamud.Game.Gui.Dtr /// Whether or not an entry with that title is registered. internal bool HasEntry(string title) => this.entries.Any(x => x.Title == title); + /// + /// Dirty the DTR bar entry with the specified title. + /// + /// Title of the entry to dirty. + /// Whether the entry was found. + internal bool MakeDirty(string title) + { + var entry = this.entries.FirstOrDefault(x => x.Title == title); + if (entry == null) + return false; + + entry.Dirty = true; + return true; + } + + /// + /// Reapply the DTR entry ordering from . + /// + internal void ApplySort() + { + var configuration = Service.Get(); + + // Sort the current entry list, based on the order in the configuration. + var ordered = configuration.DtrOrder.Select(entry => this.entries.FirstOrDefault(x => x.Title == entry)).Where(value => value != null).ToList(); + + // Add entries that weren't sorted to the end of the list. + if (ordered.Count != this.entries.Count) + { + ordered.AddRange(this.entries.Where(x => ordered.All(y => y.Title != x.Title))); + } + + // Update the order list for new entries. + configuration.DtrOrder.Clear(); + foreach (var dtrEntry in ordered) + { + configuration.DtrOrder.Add(dtrEntry.Title); + } + + this.entries = ordered; + } + private static AtkUnitBase* GetDtr() => (AtkUnitBase*)Service.Get().GetAddonByName("_DTR", 1).ToPointer(); private void Update(Framework unused) @@ -93,9 +139,12 @@ namespace Dalamud.Game.Gui.Dtr var collisionNode = dtr->UldManager.NodeList[1]; var runningXPos = collisionNode->X; + var configuration = Service.Get(); + for (var i = 0; i < this.entries.Count; i++) { var data = this.entries[i]; + var isHide = configuration.DtrIgnore!.Any(x => x == data.Title) || !data.Shown; if (data.Dirty && data.Added && data.Text != null && data.TextNode != null) { @@ -103,7 +152,7 @@ namespace Dalamud.Game.Gui.Dtr node->SetText(data.Text?.Encode()); ushort w = 0, h = 0; - if (!data.Shown) + if (isHide) { node->AtkResNode.ToggleVisibility(false); } @@ -122,7 +171,7 @@ namespace Dalamud.Game.Gui.Dtr data.Added = this.AddNode(data.TextNode); } - if (data.Shown) + if (!isHide) { runningXPos -= data.TextNode->AtkResNode.Width + ElementPadding; data.TextNode->AtkResNode.SetPositionFloat(runningXPos, 2); @@ -213,33 +262,5 @@ namespace Dalamud.Game.Gui.Dtr return newTextNode; } - - private void ApplySort() - { - var configuration = Service.Get(); - if (configuration.DtrOrder == null) - { - configuration.DtrOrder = new List(); - configuration.Save(); - } - - // Sort the current entry list, based on the order in the configuration. - var ordered = configuration.DtrOrder.Select(entry => this.entries.FirstOrDefault(x => x.Title == entry)).Where(value => value != null).ToList(); - - // Add entries that weren't sorted to the end of the list. - if (ordered.Count != this.entries.Count) - { - ordered.AddRange(this.entries.Where(x => ordered.All(y => y.Title != x.Title))); - } - - // Update the order list for new entries. - configuration.DtrOrder.Clear(); - foreach (var dtrEntry in ordered) - { - configuration.DtrOrder.Add(dtrEntry.Title); - } - - this.entries = ordered; - } } } diff --git a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs index d7dfc0e07..428f25e65 100644 --- a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using CheapLoc; using Dalamud.Configuration; using Dalamud.Configuration.Internal; +using Dalamud.Game.Gui.Dtr; using Dalamud.Game.Text; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; @@ -44,6 +45,9 @@ namespace Dalamud.Interface.Internal.Windows private bool doGamepad; private bool doFocus; + private List? dtrOrder; + private List? dtrIgnore; + private List thirdRepoList; private bool thirdRepoListChanged; private string thirdRepoTempUrl = string.Empty; @@ -152,6 +156,10 @@ namespace Dalamud.Interface.Internal.Windows { this.thirdRepoListChanged = false; this.devPluginLocationsChanged = false; + + var configuration = Service.Get(); + this.dtrOrder = configuration.DtrOrder; + this.dtrIgnore = configuration.DtrIgnore; } /// @@ -162,6 +170,9 @@ namespace Dalamud.Interface.Internal.Windows ImGui.GetIO().FontGlobalScale = configuration.GlobalUiScale; this.thirdRepoList = configuration.ThirdRepoList.Select(x => x.Clone()).ToList(); this.devPluginLocations = configuration.DevPluginLoadLocations.Select(x => x.Clone()).ToList(); + + configuration.DtrOrder = this.dtrOrder; + configuration.DtrIgnore = this.dtrIgnore; } /// @@ -184,6 +195,12 @@ namespace Dalamud.Interface.Internal.Windows ImGui.EndTabItem(); } + if (ImGui.BeginTabItem(Loc.Localize("DalamudSettingsServerInfoBar", "Server Info Bar"))) + { + this.DrawServerInfoBarTab(); + ImGui.EndTabItem(); + } + if (ImGui.BeginTabItem(Loc.Localize("DalamudSettingsExperimental", "Experimental"))) { this.DrawExperimentalTab(); @@ -297,6 +314,96 @@ namespace Dalamud.Interface.Internal.Windows ImGui.TextColored(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingToggleGamepadNavigationHint", "This will allow you to toggle between game and plugin navigation via L1+L3.\nToggle the PluginInstaller window via R3 if ImGui navigation is enabled.")); } + private void DrawServerInfoBarTab() + { + ImGui.Text(Loc.Localize("DalamudSettingServerInfoBar", "Server Info Bar configuration")); + ImGui.TextColored(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingServerInfoBarHint", "Plugins can put additional information into your server information bar(where world & time can be seen).\nYou can reorder and disable these here.")); + + ImGuiHelpers.ScaledDummy(10, 10); + + var configuration = Service.Get(); + var dtrBar = Service.Get(); + + var order = configuration.DtrOrder!; + var ignore = configuration.DtrIgnore!; + + if (order.Count == 0) + { + ImGui.TextColored(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingServerInfoBarDidNone", "You have no plugins that use this feature.")); + } + + var isOrderChange = false; + for (var i = 0; i < order.Count; i++) + { + var title = order[i]; + if (!dtrBar.HasEntry(title)) + continue; + + // TODO: Maybe we can also resort the rest of the bar in the future? + // var isRequired = search is Configuration.SearchSetting.Internal or Configuration.SearchSetting.MacroLinks; + + ImGui.PushFont(UiBuilder.IconFont); + + var arrowUpText = $"{FontAwesomeIcon.ArrowUp.ToIconString()}##{title}"; + if (i == 0) + { + ImGuiComponents.DisabledButton(arrowUpText); + } + else + { + if (ImGui.Button(arrowUpText)) + { + (order[i], order[i - 1]) = (order[i - 1], order[i]); + isOrderChange = true; + } + } + + ImGui.SameLine(); + + var arrowDownText = $"{FontAwesomeIcon.ArrowDown.ToIconString()}##{title}"; + if (i == order.Count - 1) + { + ImGuiComponents.DisabledButton(arrowDownText); + } + else + { + if (ImGui.Button(arrowDownText) && i != order.Count - 1) + { + (order[i], order[i + 1]) = (order[i + 1], order[i]); + isOrderChange = true; + } + } + + ImGui.PopFont(); + + ImGui.SameLine(); + + // if (isRequired) { + // ImGui.TextUnformatted($"Search in {name}"); + // } else { + + var isShown = ignore.All(x => x != title); + var nextIsShow = isShown; + if (ImGui.Checkbox($"{title}###dtrEntry{i}", ref nextIsShow) && nextIsShow != isShown) + { + if (nextIsShow) + ignore.Remove(title); + else + ignore.Add(title); + + dtrBar.MakeDirty(title); + } + + // } + } + + configuration.DtrOrder = order; + configuration.DtrIgnore = ignore; + + if (isOrderChange) + dtrBar.ApplySort(); + } + private void DrawExperimentalTab() { var configuration = Service.Get(); @@ -697,6 +804,9 @@ namespace Dalamud.Interface.Internal.Windows ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.NavEnableSetMousePos; } + this.dtrOrder = configuration.DtrOrder; + this.dtrIgnore = configuration.DtrIgnore; + configuration.DoPluginTest = this.doPluginTest; configuration.ThirdRepoList = this.thirdRepoList.Select(x => x.Clone()).ToList(); configuration.DevPluginLoadLocations = this.devPluginLocations.Select(x => x.Clone()).ToList();