From b7edb5b4a1ae7d4f8c5f2d1c0712d01cd5a475c5 Mon Sep 17 00:00:00 2001 From: r00telement <47005506+r00telement@users.noreply.github.com> Date: Wed, 8 Dec 2021 17:58:51 +0000 Subject: [PATCH] Revamp tag ui again; this time using a proper tree --- PlayerTags/DefaultPluginData.cs | 17 +- PlayerTags/PluginConfigurationUI.cs | 840 ++++++++++++++--------- PlayerTags/Resources/Strings.Designer.cs | 45 +- PlayerTags/Resources/Strings.resx | 13 +- PlayerTags/Tag.cs | 21 +- 5 files changed, 594 insertions(+), 342 deletions(-) diff --git a/PlayerTags/DefaultPluginData.cs b/PlayerTags/DefaultPluginData.cs index 802979c..576e404 100644 --- a/PlayerTags/DefaultPluginData.cs +++ b/PlayerTags/DefaultPluginData.cs @@ -29,6 +29,7 @@ namespace PlayerTags { AllTagsChanges = new Tag(new LiteralPluginString("")) { + IsSelected = true, IsExpanded = true, TagPositionInChat = TagPosition.Before, TagPositionInNameplates = TagPosition.Replace, @@ -38,6 +39,7 @@ namespace PlayerTags AllRoleTagsChanges = new Tag(new LiteralPluginString("")) { + IsSelected = false, IsExpanded = true, IsIconVisibleInChat = true, IsTextVisibleInNameplates = true, @@ -45,28 +47,32 @@ namespace PlayerTags RoleTagsChanges[Role.LandHand] = new Tag(new LiteralPluginString("")) { - IsExpanded = true, + IsSelected = false, + IsExpanded = false, Icon = BitmapFontIcon.Crafter, TextColor = 3, }.GetChanges(); RoleTagsChanges[Role.Tank] = new Tag(new LiteralPluginString("")) { - IsExpanded = true, + IsSelected = false, + IsExpanded = false, Icon = BitmapFontIcon.Tank, TextColor = 546, }.GetChanges(); RoleTagsChanges[Role.Healer] = new Tag(new LiteralPluginString("")) { - IsExpanded = true, + IsSelected = false, + IsExpanded = false, Icon = BitmapFontIcon.Healer, TextColor = 43, }.GetChanges(); RoleTagsChanges[Role.DPS] = new Tag(new LiteralPluginString("")) { - IsExpanded = true, + IsSelected = false, + IsExpanded = false, Icon = BitmapFontIcon.DPS, TextColor = 508, }.GetChanges(); @@ -87,6 +93,8 @@ namespace PlayerTags { JobTagsChanges[classJob.Abbreviation.RawString] = new Tag(new LiteralPluginString("")) { + IsSelected = false, + IsExpanded = false, Text = classJob.Abbreviation.RawString, }.GetChanges(); } @@ -95,6 +103,7 @@ namespace PlayerTags AllCustomTagsChanges = new Tag(new LiteralPluginString("")) { + IsSelected = false, IsExpanded = true, IsTextVisibleInChat = true, IsTextVisibleInNameplates = true, diff --git a/PlayerTags/PluginConfigurationUI.cs b/PlayerTags/PluginConfigurationUI.cs index 43e15d4..adcaebd 100644 --- a/PlayerTags/PluginConfigurationUI.cs +++ b/PlayerTags/PluginConfigurationUI.cs @@ -2,6 +2,7 @@ using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Party; +using Dalamud.Interface; using FFXIVClientStructs.FFXIV.Client.Game.Character; using ImGuiNET; using Lumina.Excel.GeneratedSheets; @@ -76,8 +77,25 @@ namespace PlayerTags ImGui.Spacing(); DrawHeading(Strings.Loc_Static_Tags); ImGui.TreePush(); - Draw(m_PluginData.AllTags); + ImGui.BeginGroup(); + ImGui.Columns(2); + + ImGui.BeginGroup(); + DrawTree(m_PluginData.AllTags); + ImGui.EndGroup(); + + ImGui.NextColumn(); + ImGui.BeginGroup(); + var selectedTag = m_PluginData.AllTags.Descendents.SingleOrDefault(descendent => descendent.IsSelected.Value); + if (selectedTag != null) + { + DrawControls(selectedTag); + } + ImGui.EndGroup(); + + ImGui.EndGroup(); ImGui.TreePop(); + ImGui.Columns(1); ImGui.Spacing(); @@ -174,226 +192,153 @@ namespace PlayerTags } } - public void Draw(Tag tag) + public string GetTreeItemName(Tag tag) { - ImGui.PushID(tag.GetHashCode().ToString()); - - string collapsingHeaderName = tag.Name.Value; + string itemName = tag.Name.Value; if (m_PluginData.CustomTags.Contains(tag)) { if (tag.Text.InheritedValue != null) { - collapsingHeaderName = tag.Text.InheritedValue; + itemName = tag.Text.InheritedValue; } else { - collapsingHeaderName = ""; + itemName = ""; } } - if (ImGui.CollapsingHeader($"{collapsingHeaderName}###{tag.GetHashCode()}", tag.IsExpanded.Value ? ImGuiTreeNodeFlags.DefaultOpen : ImGuiTreeNodeFlags.None)) + return itemName; + } + + public void Select(Tag tag) + { + foreach (var descendent in m_PluginData.AllTags.Descendents) { - if (!tag.IsExpanded.Value) + descendent.IsSelected.Value = false; + } + + tag.IsSelected.Value = true; + m_PluginConfiguration.Save(m_PluginData); + } + + public void DrawTree(Tag tag) + { + ImGui.PushID(tag.GetHashCode().ToString()); + + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.NoTreePushOnOpen | ImGuiTreeNodeFlags.SpanFullWidth | ImGuiTreeNodeFlags.AllowItemOverlap | ImGuiTreeNodeFlags.FramePadding; + + if (!tag.Children.Any()) + { + flags |= ImGuiTreeNodeFlags.Leaf; + } + + if (tag.IsSelected.Value) + { + flags |= ImGuiTreeNodeFlags.Selected; + } + + if (tag.IsExpanded.Value) + { + flags |= ImGuiTreeNodeFlags.DefaultOpen; + } + + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(0, 3)); + ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0)); + bool isOpened = ImGui.TreeNodeEx($"{GetTreeItemName(tag)}###{tag.GetHashCode()}", flags); + ImGui.PopStyleVar(); + ImGui.PopStyleVar(); + + if (ImGui.IsItemClicked()) + { + Select(tag); + } + + // Add custom tag button + if (tag == m_PluginData.AllCustomTags) + { + ImGui.SameLine(); + + ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.1f, 0.3f, 0.1f, 1)); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.2f, 0.6f, 0.2f, 1)); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.2f, 0.6f, 0.2f, 1)); + ImGui.PushFont(UiBuilder.IconFont); + + ImGui.GetCursorPos(); + ImGui.GetContentRegionAvail(); + + ImGui.SetCursorPosX(ImGui.GetCursorPos().X + ImGui.GetContentRegionAvail().X - 23); + if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString())) + { + var newTag = new Tag(new LocalizedPluginString(nameof(PluginData.CustomTags))) + { + IsExpanded = true, + Text = Strings.Loc_Static_NewTag, + GameObjectNamesToApplyTo = "" + }; + + m_PluginData.CustomTags.Add(newTag); + newTag.Parent = m_PluginData.AllCustomTags; + + Select(newTag); + } + + ImGui.PopFont(); + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip(Strings.Loc_Static_AddCustomTag_Description); + } + } + + + // Remove custom tag button + if (m_PluginData.CustomTags.Contains(tag)) + { + ImGui.SameLine(); + + ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.3f, 0.1f, 0.1f, 1)); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.6f, 0.2f, 0.2f, 1)); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.6f, 0.2f, 0.2f, 1)); + ImGui.PushFont(UiBuilder.IconFont); + + ImGui.SetCursorPosX(ImGui.GetCursorPos().X + ImGui.GetContentRegionAvail().X - 23); + if (ImGui.Button(FontAwesomeIcon.TrashAlt.ToIconString())) + { + m_PluginData.AllCustomTags.Children.Remove(tag); + m_PluginData.CustomTags.Remove(tag); + m_PluginConfiguration.Save(m_PluginData); + + Select(m_PluginData.AllCustomTags); + } + + ImGui.PopFont(); + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip(Strings.Loc_Static_RemoveCustomTag_Description); + } + } + + + if (isOpened) + { + if (tag.Children.Any() && !tag.IsExpanded.Value) { tag.IsExpanded.Value = true; m_PluginConfiguration.Save(m_PluginData); } ImGui.TreePush(); - ImGui.BeginGroup(); - - ImGui.BeginGroup(); - var addButtonSize = new Vector2(23, 23); - if (ImGui.IsPopupOpen("AddPopup")) + foreach (var childTag in tag.Children.OrderBy(child => GetTreeItemName(child)).ToArray()) { - ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.2f, 0.6f, 0.2f, 1)); + DrawTree(childTag); } - else - { - ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.1f, 0.3f, 0.1f, 1)); - } - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.2f, 0.6f, 0.2f, 1)); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.2f, 0.6f, 0.2f, 1)); - - ImGui.Text(""); - - // Add custom tag button - if (tag == m_PluginData.AllCustomTags) - { - ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.1f, 0.3f, 0.1f, 1)); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.2f, 0.6f, 0.2f, 1)); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.2f, 0.6f, 0.2f, 1)); - if (ImGui.Button(Strings.Loc_Static_AddCustomTag)) - { - var newTag = new Tag(new LocalizedPluginString(nameof(PluginData.CustomTags))) - { - IsExpanded = true, - Text = "", - GameObjectNamesToApplyTo = "" - }; - - m_PluginData.CustomTags.Add(newTag); - newTag.Parent = m_PluginData.AllCustomTags; - m_PluginConfiguration.Save(m_PluginData); - } - if (ImGui.IsItemHovered()) - { - ImGui.SetTooltip(Strings.Loc_Static_AddCustomTag_Description); - } - ImGui.PopStyleColor(); - ImGui.PopStyleColor(); - ImGui.PopStyleColor(); - - ImGui.SameLine(); - } - - // Remove custom tag button - if (m_PluginData.CustomTags.Contains(tag)) - { - ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.3f, 0.1f, 0.1f, 1)); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.6f, 0.2f, 0.2f, 1)); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.6f, 0.2f, 0.2f, 1)); - if (ImGui.Button(Strings.Loc_Static_RemoveCustomTag)) - { - m_PluginData.AllCustomTags.Children.Remove(tag); - m_PluginData.CustomTags.Remove(tag); - m_PluginConfiguration.Save(m_PluginData); - } - if (ImGui.IsItemHovered()) - { - ImGui.SetTooltip(Strings.Loc_Static_RemoveCustomTag_Description); - } - ImGui.PopStyleColor(); - ImGui.PopStyleColor(); - ImGui.PopStyleColor(); - - ImGui.SameLine(); - } - - if (ImGui.Button("+", addButtonSize)) - { - ImGui.OpenPopup("AddPopup"); - } - ImGui.PopStyleColor(); - ImGui.PopStyleColor(); - ImGui.PopStyleColor(); - - bool wasPaddingConsumed = false; - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 5)); - ImGui.SetNextWindowPos(ImGui.GetCursorScreenPos() - new Vector2(0, 4)); - if (ImGui.BeginPopup("AddPopup")) - { - wasPaddingConsumed = true; - ImGui.PopStyleVar(); - - ImGui.PushStyleColor(ImGuiCol.FrameBg, new Vector4(0f, 0f, 0f, 0)); - if (ImGui.BeginListBox("###SelectableInheritables")) - { - var selectableInheritables = tag.Inheritables.Where(inheritable => inheritable.Value.Behavior == InheritableBehavior.Inherit).ToDictionary(item => item.Key, item => item.Value); - var selectableInheritablesWithLocalizedNames = selectableInheritables - .Select(inheritable => new { Name = inheritable.Key, LocalizedName = Localizer.GetString(inheritable.Key, false) }) - .OrderBy(item => item.LocalizedName); - - foreach (var inheritableLocalizedName in selectableInheritablesWithLocalizedNames) - { - bool isSelected = false; - if (ImGui.Selectable(inheritableLocalizedName.LocalizedName, isSelected)) - { - selectableInheritables[inheritableLocalizedName.Name].Behavior = InheritableBehavior.Enabled; - - if (selectableInheritables[inheritableLocalizedName.Name] is InheritableValue inheritableBool) - { - inheritableBool.Value = true; - } - - m_PluginConfiguration.Save(m_PluginData); - ImGui.CloseCurrentPopup(); - } - - if (isSelected) - { - ImGui.SetItemDefaultFocus(); - } - - if (ImGui.IsItemHovered()) - { - ImGui.SetTooltip(Localizer.GetString(inheritableLocalizedName.Name, true)); - } - } - - ImGui.EndListBox(); - } - ImGui.PopStyleColor(); - ImGui.EndPopup(); - } - if (!wasPaddingConsumed) - { - ImGui.PopStyleVar(); - } - - if (ImGui.IsItemHovered()) - { - ImGui.SetTooltip(Strings.Loc_Static_AddPropertyOverride_Description); - } - - ImGui.EndGroup(); - - var selectedInheritables = tag.Inheritables.Where(inheritable => inheritable.Value.Behavior != InheritableBehavior.Inherit).ToDictionary(item => item.Key, item => item.Value); - var selectedInheritablesWithLocalizedNames = selectedInheritables - .Select(inheritable => new { Name = inheritable.Key, LocalizedName = Localizer.GetString(inheritable.Key, false) }) - .OrderBy(item => item.LocalizedName); - - foreach (var selectedInheritablesWithLocalizedName in selectedInheritablesWithLocalizedNames) - { - switch (selectedInheritablesWithLocalizedName.Name) - { - case nameof(tag.Icon): - DrawInheritable(nameof(tag.Icon), false, true, tag.Icon); - break; - case nameof(tag.IsIconVisibleInChat): - DrawInheritable(nameof(tag.IsIconVisibleInChat), tag.IsIconVisibleInChat); - break; - case nameof(tag.IsIconVisibleInNameplates): - DrawInheritable(nameof(tag.IsIconVisibleInNameplates), tag.IsIconVisibleInNameplates); - break; - case nameof(tag.Text): - DrawInheritable(nameof(tag.Text), tag.Text); - break; - case nameof(tag.TextColor): - DrawInheritable(nameof(tag.TextColor), tag.TextColor); - break; - case nameof(tag.IsTextItalic): - DrawInheritable(nameof(tag.IsTextItalic), tag.IsTextItalic); - break; - case nameof(tag.IsTextVisibleInChat): - DrawInheritable(nameof(tag.IsTextVisibleInChat), tag.IsTextVisibleInChat); - break; - case nameof(tag.IsTextVisibleInNameplates): - DrawInheritable(nameof(tag.IsTextVisibleInNameplates), tag.IsTextVisibleInNameplates); - break; - case nameof(tag.TagPositionInChat): - DrawInheritable(nameof(tag.TagPositionInChat), true, false, tag.TagPositionInChat); - break; - case nameof(tag.TagPositionInNameplates): - DrawInheritable(nameof(tag.TagPositionInNameplates), true, false, tag.TagPositionInNameplates); - break; - case nameof(tag.TagTargetInNameplates): - DrawInheritable(nameof(tag.TagTargetInNameplates), true, false, tag.TagTargetInNameplates); - break; - case nameof(tag.GameObjectNamesToApplyTo): - DrawInheritable(nameof(tag.GameObjectNamesToApplyTo), tag.GameObjectNamesToApplyTo); - break; - default: - break; - } - } - - foreach (var childTag in tag.Children.ToArray()) - { - Draw(childTag); - } - - ImGui.EndGroup(); ImGui.TreePop(); } else if (tag.IsExpanded.Value) @@ -405,17 +350,168 @@ namespace PlayerTags ImGui.PopID(); } + public void DrawControls(Tag tag) + { + ImGui.PushID(tag.GetHashCode().ToString()); + + ImGui.TreePush(); + ImGui.BeginGroup(); + + + + ImGui.BeginGroup(); + var addButtonSize = new Vector2(23, 23); + if (ImGui.IsPopupOpen("AddPopup")) + { + ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.2f, 0.6f, 0.2f, 1)); + } + else + { + ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.1f, 0.3f, 0.1f, 1)); + } + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.2f, 0.6f, 0.2f, 1)); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.2f, 0.6f, 0.2f, 1)); + + ImGui.Text(""); + + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString(), addButtonSize)) + { + ImGui.OpenPopup("AddPopup"); + } + ImGui.PopFont(); + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + + bool wasPaddingConsumed = false; + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 5)); + ImGui.SetNextWindowPos(ImGui.GetCursorScreenPos() - new Vector2(0, 4)); + if (ImGui.BeginPopup("AddPopup")) + { + wasPaddingConsumed = true; + ImGui.PopStyleVar(); + + ImGui.PushStyleColor(ImGuiCol.FrameBg, new Vector4(0f, 0f, 0f, 0)); + if (ImGui.BeginListBox("###SelectableInheritables")) + { + var selectableInheritables = tag.Inheritables.Where(inheritable => inheritable.Value.Behavior == InheritableBehavior.Inherit).ToDictionary(item => item.Key, item => item.Value); + var selectableInheritablesWithLocalizedNames = selectableInheritables + .Select(inheritable => new { Name = inheritable.Key, LocalizedName = Localizer.GetString(inheritable.Key, false) }) + .OrderBy(item => item.LocalizedName); + + foreach (var inheritableLocalizedName in selectableInheritablesWithLocalizedNames) + { + bool isSelected = false; + if (ImGui.Selectable(inheritableLocalizedName.LocalizedName, isSelected)) + { + selectableInheritables[inheritableLocalizedName.Name].Behavior = InheritableBehavior.Enabled; + + if (selectableInheritables[inheritableLocalizedName.Name] is InheritableValue inheritableBool) + { + inheritableBool.Value = true; + } + + m_PluginConfiguration.Save(m_PluginData); + ImGui.CloseCurrentPopup(); + } + + if (isSelected) + { + ImGui.SetItemDefaultFocus(); + } + + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip(Localizer.GetString(inheritableLocalizedName.Name, true)); + } + } + + ImGui.EndListBox(); + } + ImGui.PopStyleColor(); + ImGui.EndPopup(); + } + if (!wasPaddingConsumed) + { + ImGui.PopStyleVar(); + } + + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip(Strings.Loc_Static_AddPropertyOverride_Description); + } + ImGui.EndGroup(); + + + + + var selectedInheritables = tag.Inheritables/*.Where(inheritable => inheritable.Value.Behavior != InheritableBehavior.Inherit)*/.ToDictionary(item => item.Key, item => item.Value); + var selectedInheritablesWithLocalizedNames = selectedInheritables + .Select(inheritable => new { Name = inheritable.Key, LocalizedName = Localizer.GetString(inheritable.Key, false) }) + .OrderBy(item => item.LocalizedName); + + foreach (var selectedInheritablesWithLocalizedName in selectedInheritablesWithLocalizedNames) + { + switch (selectedInheritablesWithLocalizedName.Name) + { + case nameof(tag.Icon): + DrawInheritable(nameof(tag.Icon), false, true, tag.Icon); + break; + case nameof(tag.IsIconVisibleInChat): + DrawInheritable(nameof(tag.IsIconVisibleInChat), tag.IsIconVisibleInChat); + break; + case nameof(tag.IsIconVisibleInNameplates): + DrawInheritable(nameof(tag.IsIconVisibleInNameplates), tag.IsIconVisibleInNameplates); + break; + case nameof(tag.Text): + DrawInheritable(nameof(tag.Text), tag.Text); + break; + case nameof(tag.TextColor): + DrawInheritable(nameof(tag.TextColor), tag.TextColor); + break; + case nameof(tag.IsTextItalic): + DrawInheritable(nameof(tag.IsTextItalic), tag.IsTextItalic); + break; + case nameof(tag.IsTextVisibleInChat): + DrawInheritable(nameof(tag.IsTextVisibleInChat), tag.IsTextVisibleInChat); + break; + case nameof(tag.IsTextVisibleInNameplates): + DrawInheritable(nameof(tag.IsTextVisibleInNameplates), tag.IsTextVisibleInNameplates); + break; + case nameof(tag.TagPositionInChat): + DrawInheritable(nameof(tag.TagPositionInChat), true, false, tag.TagPositionInChat); + break; + case nameof(tag.TagPositionInNameplates): + DrawInheritable(nameof(tag.TagPositionInNameplates), true, false, tag.TagPositionInNameplates); + break; + case nameof(tag.TagTargetInNameplates): + DrawInheritable(nameof(tag.TagTargetInNameplates), true, false, tag.TagTargetInNameplates); + break; + case nameof(tag.GameObjectNamesToApplyTo): + DrawInheritable(nameof(tag.GameObjectNamesToApplyTo), tag.GameObjectNamesToApplyTo); + break; + default: + break; + } + } + + ImGui.PopID(); + } + private void DrawRemoveButton(IInheritable inheritable) { ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(0, 0)); ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.3f, 0.1f, 0.1f, 1)); ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.6f, 0.2f, 0.2f, 1)); ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.6f, 0.2f, 0.2f, 1)); - if (ImGui.Button($"x", new Vector2(23, 23))) + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.Button(FontAwesomeIcon.TrashAlt.ToIconString(), new Vector2(23, 23))) { inheritable.Behavior = InheritableBehavior.Inherit; m_PluginConfiguration.Save(m_PluginData); } + ImGui.PopFont(); ImGui.PopStyleColor(); ImGui.PopStyleColor(); ImGui.PopStyleColor(); @@ -428,166 +524,288 @@ namespace PlayerTags private void DrawInheritable(string localizedStringName, InheritableValue inheritable) { - ImGui.SameLine(); + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.25f); + } + ImGui.BeginGroup(); - ImGui.Indent(); - ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(180, 50)); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(0 , 50)); ImGui.Text(Localizer.GetString(localizedStringName, false)); - DrawCheckbox("IsEnabled", false, ref inheritable.Value, () => + if (inheritable.Behavior == InheritableBehavior.Inherit) { - m_PluginConfiguration.Save(m_PluginData); - }); + ImGui.SameLine(); + ImGui.TextColored(new Vector4(0.66f, 0.5f, 0.5f, 1), Strings.Loc_Static_Inherited); + } - ImGui.SameLine(); - DrawRemoveButton(inheritable); + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + bool value = inheritable.InheritedValue != null ? inheritable.InheritedValue.Value : false; + DrawCheckbox("IsEnabled", false, ref value, () => + { + }); + } + else + { + DrawCheckbox("IsEnabled", false, ref inheritable.Value, () => + { + m_PluginConfiguration.Save(m_PluginData); + }); + + ImGui.SameLine(); + DrawRemoveButton(inheritable); + } ImGui.EndChild(); ImGui.EndGroup(); + + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.PopStyleVar(); + } } private void DrawInheritable(string localizedStringName, bool shouldLocalizeNames, bool shouldOrderNames, InheritableValue inheritable) where TEnum : struct, Enum { - ImGui.SameLine(); - ImGui.BeginGroup(); - ImGui.Indent(); - ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(180, 50)); - - ImGui.Text(Localizer.GetString(localizedStringName, false)); - - bool isEnabled = inheritable.Behavior == InheritableBehavior.Enabled; - DrawCheckbox("IsEnabled", false, ref isEnabled, () => + if (inheritable.Behavior == InheritableBehavior.Inherit) { - if (isEnabled) - { - inheritable.Behavior = InheritableBehavior.Enabled; - } - else - { - inheritable.Behavior = InheritableBehavior.Disabled; - } - m_PluginConfiguration.Save(m_PluginData); - }); - - if (isEnabled) - { - ImGui.SameLine(); - DrawComboBox(false, shouldLocalizeNames, shouldOrderNames, ref inheritable.Value, () => { m_PluginConfiguration.Save(m_PluginData); }); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.25f); } - ImGui.SameLine(); - DrawRemoveButton(inheritable); + ImGui.BeginGroup(); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(0, 50)); + + ImGui.Text(Localizer.GetString(localizedStringName, false)); + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.SameLine(); + ImGui.TextColored(new Vector4(0.66f, 0.5f, 0.5f, 1), Strings.Loc_Static_Inherited); + } + + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + bool isEnabled = inheritable.InheritedValue != null; + DrawCheckbox("IsEnabled", false, ref isEnabled, () => { }); + + if (isEnabled) + { + ImGui.SameLine(); + ImGui.SetNextItemWidth(200); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(200, 0)); + TEnum value = inheritable.InheritedValue != null ? inheritable.InheritedValue.Value : default(TEnum); + DrawComboBox(false, shouldLocalizeNames, shouldOrderNames, ref value, () => { }); + ImGui.EndChild(); + } + } + else + { + bool isEnabled = inheritable.Behavior == InheritableBehavior.Enabled; + DrawCheckbox("IsEnabled", false, ref isEnabled, () => + { + if (isEnabled) + { + inheritable.Behavior = InheritableBehavior.Enabled; + } + else + { + inheritable.Behavior = InheritableBehavior.Disabled; + } + m_PluginConfiguration.Save(m_PluginData); + }); + + if (isEnabled) + { + ImGui.SameLine(); + ImGui.SetNextItemWidth(200); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(200, 0)); + DrawComboBox(false, shouldLocalizeNames, shouldOrderNames, ref inheritable.Value, () => { m_PluginConfiguration.Save(m_PluginData); }); + ImGui.EndChild(); + } + + ImGui.SameLine(); + DrawRemoveButton(inheritable); + } ImGui.EndChild(); ImGui.EndGroup(); + + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.PopStyleVar(); + } } private void DrawInheritable(string localizedStringName, InheritableValue inheritable) { - ImGui.SameLine(); + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.25f); + } + ImGui.BeginGroup(); - ImGui.Indent(); ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(180, 50)); ImGui.Text(Localizer.GetString(localizedStringName, false)); - - bool isEnabled = inheritable.Behavior == InheritableBehavior.Enabled; - DrawCheckbox("IsEnabled", false, ref isEnabled, () => - { - if (isEnabled) - { - inheritable.Behavior = InheritableBehavior.Enabled; - } - else - { - inheritable.Behavior = InheritableBehavior.Disabled; - } - m_PluginConfiguration.Save(m_PluginData); - }); - - if (isEnabled) + if (inheritable.Behavior == InheritableBehavior.Inherit) { ImGui.SameLine(); - DrawColorButton( - inheritable.Value.ToString(), - UIColorHelper.ToColor(inheritable.Value), - () => - { - m_ColorPickerPopupDataContext = inheritable; - ImGui.OpenPopup("ColorPickerPopup"); - }); + ImGui.TextColored(new Vector4(0.66f, 0.5f, 0.5f, 1), Strings.Loc_Static_Inherited); } - bool wasStyleConsumed = false; - ImGui.SetNextWindowPos(ImGui.GetCursorScreenPos() + new Vector2(31, 0)); - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0)); - if (ImGui.BeginPopup("ColorPickerPopup")) + if (inheritable.Behavior == InheritableBehavior.Inherit) { - wasStyleConsumed = true; - ImGui.PopStyleVar(); + bool isEnabled = inheritable.InheritedValue != null; + DrawCheckbox("IsEnabled", false, ref isEnabled, () => { }); - DrawUIColorPicker( - (UIColor value) => + if (isEnabled) + { + ImGui.SameLine(); + ushort value = inheritable.InheritedValue != null ? inheritable.InheritedValue.Value : default(ushort); + DrawColorButton(value.ToString(), UIColorHelper.ToColor(value), () => { }); + } + } + else + { + bool isEnabled = inheritable.Behavior == InheritableBehavior.Enabled; + DrawCheckbox("IsEnabled", false, ref isEnabled, () => + { + if (isEnabled) { - if (m_ColorPickerPopupDataContext != null) + inheritable.Behavior = InheritableBehavior.Enabled; + } + else + { + inheritable.Behavior = InheritableBehavior.Disabled; + } + m_PluginConfiguration.Save(m_PluginData); + }); + + if (isEnabled) + { + ImGui.SameLine(); + DrawColorButton( + inheritable.Value.ToString(), + UIColorHelper.ToColor(inheritable.Value), + () => { - m_ColorPickerPopupDataContext.Value = (ushort)value.RowId; - m_ColorPickerPopupDataContext = null; - m_PluginConfiguration.Save(m_PluginData); - } + m_ColorPickerPopupDataContext = inheritable; + ImGui.OpenPopup("ColorPickerPopup"); + }); + } - ImGui.CloseCurrentPopup(); - }); + bool wasStyleConsumed = false; + ImGui.SetNextWindowPos(ImGui.GetCursorScreenPos() + new Vector2(31, 0)); + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0)); + if (ImGui.BeginPopup("ColorPickerPopup")) + { + wasStyleConsumed = true; + ImGui.PopStyleVar(); - ImGui.EndPopup(); + DrawUIColorPicker( + (UIColor value) => + { + if (m_ColorPickerPopupDataContext != null) + { + m_ColorPickerPopupDataContext.Value = (ushort)value.RowId; + m_ColorPickerPopupDataContext = null; + m_PluginConfiguration.Save(m_PluginData); + } + + ImGui.CloseCurrentPopup(); + }); + + ImGui.EndPopup(); + } + if (!wasStyleConsumed) + { + ImGui.PopStyleVar(); + } + + ImGui.SameLine(); + DrawRemoveButton(inheritable); } - if (!wasStyleConsumed) - { - ImGui.PopStyleVar(); - } - - ImGui.SameLine(); - DrawRemoveButton(inheritable); ImGui.EndChild(); ImGui.EndGroup(); + + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.PopStyleVar(); + } } private void DrawInheritable(string localizedStringName, InheritableReference inheritable) { - ImGui.SameLine(); - ImGui.BeginGroup(); - ImGui.Indent(); - ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(180, 50)); - - ImGui.Text(Localizer.GetString(localizedStringName, false)); - - bool isEnabled = inheritable.Behavior == InheritableBehavior.Enabled; - DrawCheckbox("IsEnabled", false, ref isEnabled, () => + if (inheritable.Behavior == InheritableBehavior.Inherit) { - if (isEnabled) - { - inheritable.Behavior = InheritableBehavior.Enabled; - } - else - { - inheritable.Behavior = InheritableBehavior.Disabled; - } - m_PluginConfiguration.Save(m_PluginData); - }); - - if (isEnabled) - { - ImGui.SameLine(); - DrawTextBox(localizedStringName, ref inheritable.Value, () => { m_PluginConfiguration.Save(m_PluginData); }); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.25f); } - ImGui.SameLine(); - DrawRemoveButton(inheritable); + ImGui.BeginGroup(); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(0, 50)); + + ImGui.Text(Localizer.GetString(localizedStringName, false)); + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.SameLine(); + ImGui.TextColored(new Vector4(0.66f, 0.5f, 0.5f, 1), Strings.Loc_Static_Inherited); + } + + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + bool isEnabled = inheritable.InheritedValue != null; + DrawCheckbox("IsEnabled", false, ref isEnabled, () => + { + }); + + if (isEnabled) + { + ImGui.SameLine(); + ImGui.SetNextItemWidth(200); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(200, 0)); + string value = inheritable.Value; + DrawTextBox(localizedStringName, ref value, () => { }); + ImGui.EndChild(); + } + } + else + { + bool isEnabled = inheritable.Behavior == InheritableBehavior.Enabled; + DrawCheckbox("IsEnabled", false, ref isEnabled, () => + { + if (isEnabled) + { + inheritable.Behavior = InheritableBehavior.Enabled; + } + else + { + inheritable.Behavior = InheritableBehavior.Disabled; + } + m_PluginConfiguration.Save(m_PluginData); + }); + + if (isEnabled) + { + ImGui.SameLine(); + ImGui.SetNextItemWidth(200); + ImGui.BeginChild(inheritable.GetHashCode().ToString(), new Vector2(200, 0)); + DrawTextBox(localizedStringName, ref inheritable.Value, () => { m_PluginConfiguration.Save(m_PluginData); }); + ImGui.EndChild(); + } + + ImGui.SameLine(); + DrawRemoveButton(inheritable); + } ImGui.EndChild(); ImGui.EndGroup(); + + if (inheritable.Behavior == InheritableBehavior.Inherit) + { + ImGui.PopStyleVar(); + } } private void DrawHeading(string label) diff --git a/PlayerTags/Resources/Strings.Designer.cs b/PlayerTags/Resources/Strings.Designer.cs index 88b9738..8c26f25 100644 --- a/PlayerTags/Resources/Strings.Designer.cs +++ b/PlayerTags/Resources/Strings.Designer.cs @@ -231,6 +231,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Selected. + /// + public static string Loc_IsSelected { + get { + return ResourceManager.GetString("Loc_IsSelected", resourceCulture); + } + } + /// /// Looks up a localized string similar to Text italic. /// @@ -564,15 +573,6 @@ namespace PlayerTags.Resources { } } - /// - /// Looks up a localized string similar to Add. - /// - public static string Loc_Static_AddCustomTag { - get { - return ResourceManager.GetString("Loc_Static_AddCustomTag", resourceCulture); - } - } - /// /// Looks up a localized string similar to Add a new custom tag.. /// @@ -636,6 +636,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to <Inherited>. + /// + public static string Loc_Static_Inherited { + get { + return ResourceManager.GetString("Loc_Static_Inherited", resourceCulture); + } + } + /// /// Looks up a localized string similar to Nameplates. /// @@ -645,6 +654,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to New tag. + /// + public static string Loc_Static_NewTag { + get { + return ResourceManager.GetString("Loc_Static_NewTag", resourceCulture); + } + } + /// /// Looks up a localized string similar to Add custom tags to party members. /// @@ -672,15 +690,6 @@ namespace PlayerTags.Resources { } } - /// - /// Looks up a localized string similar to Remove. - /// - public static string Loc_Static_RemoveCustomTag { - get { - return ResourceManager.GetString("Loc_Static_RemoveCustomTag", resourceCulture); - } - } - /// /// Looks up a localized string similar to Remove this custom tag.. /// diff --git a/PlayerTags/Resources/Strings.resx b/PlayerTags/Resources/Strings.resx index 7d8af61..c541cef 100644 --- a/PlayerTags/Resources/Strings.resx +++ b/PlayerTags/Resources/Strings.resx @@ -144,6 +144,12 @@ Add '{0}' to {1}. + + <Inherited> + + + Selected + Expanded @@ -279,15 +285,12 @@ Remove this override. The value will be inherited. - - Add + + New tag Add a new custom tag. - - Remove - Remove this custom tag. diff --git a/PlayerTags/Tag.cs b/PlayerTags/Tag.cs index f71d596..2b1f445 100644 --- a/PlayerTags/Tag.cs +++ b/PlayerTags/Tag.cs @@ -40,6 +40,21 @@ namespace PlayerTags public List Children { get; } = new List(); + public IEnumerable Descendents + { + get + { + IEnumerable descendents = Children.Prepend(this); + + foreach (var child in Children) + { + descendents = descendents.Union(child.Descendents); + } + + return descendents.Distinct(); + } + } + private Dictionary? m_Inheritables = null; public Dictionary Inheritables { @@ -64,10 +79,8 @@ namespace PlayerTags } } - public InheritableValue IsExpanded = new InheritableValue(false) - { - Behavior = InheritableBehavior.Enabled - }; + public InheritableValue IsSelected = new InheritableValue(false); + public InheritableValue IsExpanded = new InheritableValue(false); public InheritableValue Icon = new InheritableValue(BitmapFontIcon.Aethernet); public InheritableValue IsIconVisibleInChat = new InheritableValue(false);