mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-11 23:19:00 +08:00
The menu added by the installer should display the installer name
This commit is contained in:
parent
260fdb44a7
commit
3d26682718
@ -150,19 +150,22 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
}
|
||||
|
||||
private void TraverseMenu(int depth, List<TreeViewItem> items, VRCExpressionsMenu menu) {
|
||||
IEnumerable<KeyValuePair<string, VRCExpressionsMenu>> children = this._menuTree.GetChildren(menu)
|
||||
.Where(child => !this._visitedMenuStack.Contains(child.Value));
|
||||
foreach (KeyValuePair<string, VRCExpressionsMenu> child in children) {
|
||||
IEnumerable<MenuTree.ChildElement> children = this._menuTree.GetChildren(menu)
|
||||
.Where(child => !this._visitedMenuStack.Contains(child.menu));
|
||||
foreach (MenuTree.ChildElement child in children) {
|
||||
string displayName = child.installer == null ?
|
||||
$"{child.menuName} ({child.menu.name})" :
|
||||
$"{child.menuName} ({child.menu.name}) InstallerObject : {child.installer.name}";
|
||||
items.Add(
|
||||
new TreeViewItem {
|
||||
id = items.Count,
|
||||
depth = depth,
|
||||
displayName = $"{child.Key} ({child.Value.name})"
|
||||
displayName = displayName
|
||||
}
|
||||
);
|
||||
this._menuItems.Add(child.Value);
|
||||
this._visitedMenuStack.Push(child.Value);
|
||||
this.TraverseMenu(depth + 1, items, child.Value);
|
||||
this._menuItems.Add(child.menu);
|
||||
this._visitedMenuStack.Push(child.menu);
|
||||
this.TraverseMenu(depth + 1, items, child.menu);
|
||||
this._visitedMenuStack.Pop();
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,22 @@ using static VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionsMenu.Control;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace nadena.dev.modular_avatar.core.editor {
|
||||
public class MenuTree {
|
||||
public struct ChildElement {
|
||||
public string menuName;
|
||||
public VRCExpressionsMenu menu;
|
||||
public ModularAvatarMenuInstaller installer;
|
||||
}
|
||||
|
||||
private readonly VRCExpressionsMenu _rootMenu;
|
||||
private readonly HashSet<VRCExpressionsMenu> _included;
|
||||
private readonly Dictionary<VRCExpressionsMenu, List<KeyValuePair<string, VRCExpressionsMenu>>> _childrenMap;
|
||||
private readonly Dictionary<VRCExpressionsMenu, List<ChildElement>> _childrenMap;
|
||||
|
||||
private readonly Dictionary<VRCExpressionsMenu, ImmutableArray<VRCExpressionsMenu>> _flashedChildrenMap;
|
||||
|
||||
public MenuTree(VRCAvatarDescriptor descriptor) {
|
||||
this._rootMenu = descriptor.expressionsMenu;
|
||||
this._included = new HashSet<VRCExpressionsMenu>();
|
||||
this._childrenMap = new Dictionary<VRCExpressionsMenu, List<KeyValuePair<string, VRCExpressionsMenu>>>();
|
||||
this._childrenMap = new Dictionary<VRCExpressionsMenu, List<ChildElement>>();
|
||||
|
||||
if (this._rootMenu == null) {
|
||||
this._rootMenu = ScriptableObject.CreateInstance<VRCExpressionsMenu>();
|
||||
@ -34,46 +40,49 @@ namespace nadena.dev.modular_avatar.core.editor {
|
||||
|
||||
public void MappingMenuInstaller(ModularAvatarMenuInstaller installer) {
|
||||
if (installer.menuToAppend == null) return;
|
||||
VRCExpressionsMenu parent = installer.installTargetMenu;
|
||||
if (parent == null) parent = this._rootMenu;
|
||||
this.MappingMenu(installer.menuToAppend, parent);
|
||||
this.MappingMenu(installer.menuToAppend, installer);
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, VRCExpressionsMenu>> GetChildren(VRCExpressionsMenu parent) {
|
||||
public IEnumerable<ChildElement> GetChildren(VRCExpressionsMenu parent) {
|
||||
// TODO: ライブラリとするのであれば、複製したリスト or ImmutableArray,を返すのが好ましい
|
||||
if (parent == null) parent = this._rootMenu;
|
||||
return this._childrenMap.TryGetValue(parent, out List<KeyValuePair<string, VRCExpressionsMenu>> children)
|
||||
return this._childrenMap.TryGetValue(parent, out List<ChildElement> children)
|
||||
? children
|
||||
: Enumerable.Empty<KeyValuePair<string, VRCExpressionsMenu>>();
|
||||
: Enumerable.Empty<ChildElement>();
|
||||
}
|
||||
|
||||
private void MappingMenu(VRCExpressionsMenu root, VRCExpressionsMenu customParent = null) {
|
||||
private void MappingMenu(VRCExpressionsMenu root, ModularAvatarMenuInstaller installer = null) {
|
||||
Queue<VRCExpressionsMenu> queue = new Queue<VRCExpressionsMenu>();
|
||||
queue.Enqueue(root);
|
||||
bool first = true;
|
||||
|
||||
while (queue.Count > 0) {
|
||||
VRCExpressionsMenu parent = queue.Dequeue();
|
||||
IEnumerable<KeyValuePair<string, VRCExpressionsMenu>> subMenus = GetSubMenus(parent);
|
||||
if (customParent != null) {
|
||||
parent = customParent;
|
||||
customParent = null;
|
||||
IEnumerable<KeyValuePair<string, VRCExpressionsMenu>> childMenus = GetChildMenus(parent);
|
||||
|
||||
if (first && installer != null) {
|
||||
parent = installer.installTargetMenu != null ? installer.installTargetMenu : _rootMenu;
|
||||
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, VRCExpressionsMenu> subMenu in subMenus) {
|
||||
if (!this._childrenMap.TryGetValue(parent, out List<KeyValuePair<string, VRCExpressionsMenu>> children)) {
|
||||
children = new List<KeyValuePair<string, VRCExpressionsMenu>>();
|
||||
foreach (KeyValuePair<string, VRCExpressionsMenu> childMenu in childMenus) {
|
||||
if (!this._childrenMap.TryGetValue(parent, out List<ChildElement> children)) {
|
||||
children = new List<ChildElement>();
|
||||
this._childrenMap[parent] = children;
|
||||
}
|
||||
|
||||
children.Add(subMenu);
|
||||
if (this._included.Contains(subMenu.Value)) continue;
|
||||
queue.Enqueue(subMenu.Value);
|
||||
this._included.Add(subMenu.Value);
|
||||
ChildElement childElement = new ChildElement { menuName = childMenu.Key, menu = childMenu.Value, installer = installer };
|
||||
children.Add(childElement);
|
||||
if (this._included.Contains(childElement.menu)) continue;
|
||||
queue.Enqueue(childElement.menu);
|
||||
this._included.Add(childElement.menu);
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<KeyValuePair<string, VRCExpressionsMenu>> GetSubMenus(VRCExpressionsMenu expressionsMenu) {
|
||||
private static IEnumerable<KeyValuePair<string, VRCExpressionsMenu>> GetChildMenus(VRCExpressionsMenu expressionsMenu) {
|
||||
return expressionsMenu.controls
|
||||
.Where(control => control.type == ControlType.SubMenu && control.subMenu != null)
|
||||
.Select(control => new KeyValuePair<string, VRCExpressionsMenu>(control.name, control.subMenu));
|
||||
|
Loading…
x
Reference in New Issue
Block a user