feat: DTR toggling & reordering in settings window

This commit is contained in:
goaaats 2022-01-29 04:44:52 +01:00
parent 35d5ca9a19
commit 597b7bb000
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 166 additions and 30 deletions

View file

@ -245,6 +245,11 @@ namespace Dalamud.Configuration.Internal
/// </summary>
public List<string>? DtrOrder { get; set; }
/// <summary>
/// Gets or sets the list of ignored DTR elements, by title.
/// </summary>
public List<string>? DtrIgnore { get; set; }
/// <summary>
/// Load a configuration from the provided path.
/// </summary>

View file

@ -33,6 +33,11 @@ namespace Dalamud.Game.Gui.Dtr
public DtrBar()
{
Service<Framework>.Get().Update += this.Update;
var configuration = Service<DalamudConfiguration>.Get();
configuration.DtrOrder ??= new List<string>();
configuration.DtrIgnore ??= new List<string>();
configuration.Save();
}
/// <summary>
@ -75,6 +80,47 @@ namespace Dalamud.Game.Gui.Dtr
/// <returns>Whether or not an entry with that title is registered.</returns>
internal bool HasEntry(string title) => this.entries.Any(x => x.Title == title);
/// <summary>
/// Dirty the DTR bar entry with the specified title.
/// </summary>
/// <param name="title">Title of the entry to dirty.</param>
/// <returns>Whether the entry was found.</returns>
internal bool MakeDirty(string title)
{
var entry = this.entries.FirstOrDefault(x => x.Title == title);
if (entry == null)
return false;
entry.Dirty = true;
return true;
}
/// <summary>
/// Reapply the DTR entry ordering from <see cref="DalamudConfiguration"/>.
/// </summary>
internal void ApplySort()
{
var configuration = Service<DalamudConfiguration>.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<GameGui>.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<DalamudConfiguration>.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<DalamudConfiguration>.Get();
if (configuration.DtrOrder == null)
{
configuration.DtrOrder = new List<string>();
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;
}
}
}

View file

@ -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<string>? dtrOrder;
private List<string>? dtrIgnore;
private List<ThirdPartyRepoSettings> 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<DalamudConfiguration>.Get();
this.dtrOrder = configuration.DtrOrder;
this.dtrIgnore = configuration.DtrIgnore;
}
/// <inheritdoc/>
@ -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;
}
/// <inheritdoc/>
@ -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<DalamudConfiguration>.Get();
var dtrBar = Service<DtrBar>.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<DalamudConfiguration>.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();