Add new configuration options
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using AetherBags.Configuration;
|
||||
using AetherBags.Nodes.Configuration.Category;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
using KamiToolKit;
|
||||
@@ -17,27 +19,32 @@ public class AddonCategoryConfigurationWindow : NativeAddon
|
||||
private CategoryConfigurationNode? _configNode;
|
||||
private TextNode? _nothingSelectedTextNode;
|
||||
|
||||
private List<CategoryWrapper> _categoryWrappers = new();
|
||||
|
||||
protected override unsafe void OnSetup(AtkUnitBase* addon)
|
||||
{
|
||||
List<CategoryWrapper> categoryDefinitionsWrappers = System.Config.Categories.UserCategories
|
||||
.Select(categoryDefinition => new CategoryWrapper(categoryDefinition))
|
||||
.ToList();
|
||||
_categoryWrappers = CreateCategoryWrappers();
|
||||
|
||||
_selectionListNode = new ModifyListNode<CategoryWrapper> {
|
||||
_selectionListNode = new ModifyListNode<CategoryWrapper>
|
||||
{
|
||||
Position = ContentStartPosition,
|
||||
Size = new Vector2(250.0f, ContentSize.Y),
|
||||
SelectionOptions = categoryDefinitionsWrappers,
|
||||
SelectionOptions = _categoryWrappers,
|
||||
OnOptionChanged = OnOptionChanged,
|
||||
AddNewEntry = OnAddNewCategory,
|
||||
RemoveEntry = OnRemoveCategory,
|
||||
};
|
||||
_selectionListNode.AttachNode(this);
|
||||
|
||||
_separatorLine = new VerticalLineNode {
|
||||
_separatorLine = new VerticalLineNode
|
||||
{
|
||||
Position = ContentStartPosition + new Vector2(250.0f + 8.0f, 0.0f),
|
||||
Size = new Vector2(4.0f, ContentSize.Y),
|
||||
};
|
||||
_separatorLine.AttachNode(this);
|
||||
|
||||
_nothingSelectedTextNode = new TextNode {
|
||||
_nothingSelectedTextNode = new TextNode
|
||||
{
|
||||
Position = ContentStartPosition + new Vector2(250.0f + 16.0f, 0.0f),
|
||||
Size = ContentSize - new Vector2(250.0f + 16.0f, 0.0f),
|
||||
AlignmentType = AlignmentType.Center,
|
||||
@@ -50,21 +57,60 @@ public class AddonCategoryConfigurationWindow : NativeAddon
|
||||
};
|
||||
_nothingSelectedTextNode.AttachNode(this);
|
||||
|
||||
_configNode = new CategoryConfigurationNode {
|
||||
_configNode = new CategoryConfigurationNode
|
||||
{
|
||||
Position = ContentStartPosition + new Vector2(250.0f + 16.0f, 0.0f),
|
||||
Size = ContentSize - new Vector2(250.0f + 16.0f, 0.0f),
|
||||
IsVisible = false,
|
||||
OnCategoryChanged = RefreshSelectionList,
|
||||
};
|
||||
|
||||
_configNode.AttachNode(this);
|
||||
}
|
||||
|
||||
private void OnOptionChanged(CategoryWrapper? newOption) {
|
||||
private List<CategoryWrapper> CreateCategoryWrappers()
|
||||
{
|
||||
return System.Config.Categories.UserCategories
|
||||
.Select(categoryDefinition => new CategoryWrapper(categoryDefinition))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void OnOptionChanged(CategoryWrapper? newOption)
|
||||
{
|
||||
if (_configNode is null) return;
|
||||
|
||||
_configNode.IsVisible = newOption is not null;
|
||||
_nothingSelectedTextNode?.IsVisible = newOption is null;
|
||||
if (_nothingSelectedTextNode is not null)
|
||||
_nothingSelectedTextNode.IsVisible = newOption is null;
|
||||
|
||||
_configNode.ConfigurationOption = newOption;
|
||||
}
|
||||
|
||||
private void OnAddNewCategory(ModifyListNode<CategoryWrapper> listNode)
|
||||
{
|
||||
var newCategory = new UserCategoryDefinition
|
||||
{
|
||||
Name = $"New Category {System.Config.Categories.UserCategories.Count + 1}",
|
||||
Order = System.Config.Categories.UserCategories.Count,
|
||||
};
|
||||
|
||||
System.Config.Categories.UserCategories.Add(newCategory);
|
||||
|
||||
var newWrapper = new CategoryWrapper(newCategory);
|
||||
_categoryWrappers.Add(newWrapper);
|
||||
listNode.AddOption(newWrapper);
|
||||
}
|
||||
|
||||
private void OnRemoveCategory(CategoryWrapper categoryWrapper)
|
||||
{
|
||||
if (categoryWrapper.CategoryDefinition is null) return;
|
||||
|
||||
System.Config.Categories.UserCategories.Remove(categoryWrapper.CategoryDefinition);
|
||||
_categoryWrappers.Remove(categoryWrapper);
|
||||
}
|
||||
|
||||
private void RefreshSelectionList()
|
||||
{
|
||||
_selectionListNode?.UpdateList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user