mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-24 13:29:01 +08:00
chore: supports when menus are cloned as multiple different objects
This commit is contained in:
parent
90361afdda
commit
6ba5bb911f
@ -235,7 +235,7 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
|
|
||||||
private Dictionary<object, VirtualMenuNode> _resolvedMenu = new Dictionary<object, VirtualMenuNode>();
|
private Dictionary<object, VirtualMenuNode> _resolvedMenu = new Dictionary<object, VirtualMenuNode>();
|
||||||
|
|
||||||
private Dictionary<ObjectReference, VRCExpressionsMenu> _menuMap = new Dictionary<ObjectReference, VRCExpressionsMenu>();
|
private Dictionary<ObjectReference, HashSet<VRCExpressionsMenu>> _menuMap = new Dictionary<ObjectReference, HashSet<VRCExpressionsMenu>>();
|
||||||
|
|
||||||
// TODO: immutable?
|
// TODO: immutable?
|
||||||
public Dictionary<object, VirtualMenuNode> ResolvedMenu => _resolvedMenu;
|
public Dictionary<object, VirtualMenuNode> ResolvedMenu => _resolvedMenu;
|
||||||
@ -278,8 +278,14 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
|
|
||||||
void GetMenuReferences(VRCExpressionsMenu exMenu)
|
void GetMenuReferences(VRCExpressionsMenu exMenu)
|
||||||
{
|
{
|
||||||
if (!exMenu || menu._menuMap.ContainsValue(exMenu)) return;
|
if (!exMenu || menu._menuMap.SelectMany(m => m.Value).Contains(exMenu)) return;
|
||||||
menu._menuMap[ObjectRegistry.GetReference(exMenu)] = exMenu;
|
var reference = ObjectRegistry.GetReference(exMenu);
|
||||||
|
if(!menu._menuMap.TryGetValue(reference, out var hashSet))
|
||||||
|
{
|
||||||
|
hashSet = new HashSet<VRCExpressionsMenu>();
|
||||||
|
menu._menuMap[reference] = hashSet;
|
||||||
|
}
|
||||||
|
hashSet.Add(exMenu);
|
||||||
foreach (var control in exMenu.controls)
|
foreach (var control in exMenu.controls)
|
||||||
{
|
{
|
||||||
if(control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
|
if(control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
|
||||||
@ -327,11 +333,22 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
// initial validation
|
// initial validation
|
||||||
if (installer.menuToAppend == null && installer.GetComponent<MenuSource>() == null) return;
|
if (installer.menuToAppend == null && installer.GetComponent<MenuSource>() == null) return;
|
||||||
|
|
||||||
var installTargetMenu = installer.installTargetMenu &&
|
var menus = new HashSet<object>();
|
||||||
_menuMap.TryGetValue(ObjectRegistry.GetReference(installer.installTargetMenu), out var currentMenu) ?
|
if (installer.installTargetMenu && _menuMap.TryGetValue(ObjectRegistry.GetReference(installer.installTargetMenu), out var hashSet))
|
||||||
currentMenu : installer.installTargetMenu;
|
{
|
||||||
|
menus.UnionWith(hashSet);
|
||||||
|
}
|
||||||
|
else if(installer.installTargetMenu)
|
||||||
|
{
|
||||||
|
menus.Add(installer.installTargetMenu);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menus.Add(RootMenuKey);
|
||||||
|
}
|
||||||
|
|
||||||
var target = installTargetMenu ? (object) installTargetMenu : RootMenuKey;
|
foreach (var target in menus)
|
||||||
|
{
|
||||||
if (!_targetMenuToInstaller.TryGetValue(target, out var targets))
|
if (!_targetMenuToInstaller.TryGetValue(target, out var targets))
|
||||||
{
|
{
|
||||||
targets = new List<ModularAvatarMenuInstaller>();
|
targets = new List<ModularAvatarMenuInstaller>();
|
||||||
@ -340,6 +357,7 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
|
|
||||||
targets.Add(installer);
|
targets.Add(installer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers an install target with this virtual menu. As with menu installers, processing is delayed.
|
/// Registers an install target with this virtual menu. As with menu installers, processing is delayed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user