79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using gay.lilyy.MenuStyling;
|
|
using nadena.dev.ndmf;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
|
using static VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionsMenu;
|
|
|
|
[assembly: ExportsPlugin(typeof(MenuStylingPlugin))]
|
|
|
|
namespace gay.lilyy.MenuStyling
|
|
{
|
|
public class MenuStylingPlugin : Plugin<MenuStylingPlugin>
|
|
{
|
|
public override string DisplayName => "MenuStyling";
|
|
public override string QualifiedName => "gay.lilyy.MenuStyling";
|
|
protected override void Configure()
|
|
{
|
|
InPhase(BuildPhase.Optimizing).AfterPlugin("gay.lilyy.MenuIconRemover").Run("SetMenuStyling", ctx =>
|
|
{
|
|
var obj = ctx.AvatarRootObject.GetComponent<MenuStylingConfig>();
|
|
if (obj != null)
|
|
{
|
|
ctx.AvatarDescriptor.expressionsMenu = DuplicateMenu(ctx.AvatarDescriptor.expressionsMenu);
|
|
WalkMenu(obj, ctx.AvatarDescriptor.expressionsMenu);
|
|
Object.DestroyImmediate(obj);
|
|
}
|
|
});
|
|
}
|
|
|
|
private VRCExpressionsMenu DuplicateMenu(VRCExpressionsMenu menu)
|
|
{
|
|
if (menu == null) return null;
|
|
|
|
var newMenu = ScriptableObject.CreateInstance<VRCExpressionsMenu>();
|
|
newMenu.controls = new List<Control>();
|
|
|
|
foreach (var control in menu.controls)
|
|
{
|
|
var newControl = new Control
|
|
{
|
|
name = control.name,
|
|
type = control.type,
|
|
icon = control.icon,
|
|
parameter = control.parameter,
|
|
subMenu = DuplicateMenu(control.subMenu),
|
|
value = control.value,
|
|
style = control.style,
|
|
labels = control.labels,
|
|
subParameters = control.subParameters
|
|
};
|
|
newMenu.controls.Add(newControl);
|
|
}
|
|
|
|
return newMenu;
|
|
}
|
|
|
|
private void WalkMenu(MenuStylingConfig config, VRCExpressionsMenu menu)
|
|
{
|
|
foreach (var child in menu.controls)
|
|
{
|
|
if (child.name != " " && child.name != "" && child.name != null) {
|
|
if (!child.name.StartsWith(config.Prefix))
|
|
{
|
|
child.name = config.Prefix + child.name;
|
|
}
|
|
if (!child.name.EndsWith(config.Suffix))
|
|
{
|
|
child.name += config.Suffix;
|
|
}
|
|
|
|
}
|
|
if (child.type == Control.ControlType.SubMenu && child.subMenu != null)
|
|
{
|
|
WalkMenu(config, child.subMenu);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|