forked from loukylor/VRC-Mods
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathListPositionManager.cs
120 lines (106 loc) · 6.24 KB
/
ListPositionManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using MelonLoader;
using PlayerList.Config;
using PlayerList.Utilities;
using UnhollowerRuntimeLib;
using UnityEngine;
using VRChatUtilityKit.Ui;
using VRChatUtilityKit.Utilities;
namespace PlayerList
{
public class ListPositionManager
{
public static bool shouldMove = false;
public static Label snapToGridSizeLabel;
public static void Init()
{
PlayerListConfig.snapToGridSize.OnValueChanged += OnSnapToGridSizeChanged;
}
public static void OnSnapToGridSizeChanged(int oldValue, int newValue)
{
snapToGridSizeLabel.TextComponent.text = $"{newValue}";
}
public static void MovePlayerListToEndOfMenu()
{
GameObject temp = new GameObject("temp", new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Type>(new Il2CppSystem.Type[] { Il2CppType.Of<RectTransform>() }));
RectTransform furthestTransform = temp.GetComponent<RectTransform>(); // Create new gameobject with recttransform on it
foreach (var child in Constants.quickMenu.transform)
{
RectTransform childRect = child.Cast<RectTransform>();
if (childRect.gameObject.activeSelf && childRect.anchoredPosition.x + childRect.rect.width > furthestTransform.anchoredPosition.x + furthestTransform.rect.width)
furthestTransform = childRect;
}
PlayerListConfig.playerListPosition.Value = new Vector2(furthestTransform.anchoredPosition.x + (furthestTransform.rect.width / 2), MenuManager.playerListRect.anchoredPosition.y);
CombineQMColliderAndPlayerListRect(useConfigValues: true);
UnityEngine.Object.Destroy(temp);
}
public static void MovePlayerList()
{
MenuManager.playerListRect.anchoredPosition = PlayerListConfig.playerListPosition.Value; // So old position var works properly
shouldMove = true;
MelonCoroutines.Start(WaitForPress(MenuManager.playerList, new Action<GameObject>((gameObject) =>
{
PlayerListConfig.playerListPosition.Value = MenuManager.playerListRect.anchoredPosition;
gameObject.SetActive(!MenuManager.shouldStayHidden);
//UiManager.OpenSubMenu(MenuManager.playerListMenus[1].Path);
MenuManager.playerListRect.localPosition = MenuManager.playerListRect.localPosition.SetZ(25);
})));
//UiManager.OpenSubMenu("UserInterface/QuickMenu/ShortcutMenu");
MenuManager.playerList.SetActive(true);
}
private static System.Collections.IEnumerator WaitForPress(GameObject movingGameObject, Action<GameObject> onComplete = null)
{
RectTransform movingGameObjectRect = movingGameObject.GetComponent<RectTransform>();
Vector3 oldPosition = movingGameObjectRect.anchoredPosition3D;
while (CursorUtils.IsUseInputPressed && shouldMove)
{
CombineQMColliderAndPlayerListRect();
movingGameObjectRect.transform.position = CursorUtils.HitPosition;
movingGameObjectRect.transform.localPosition = movingGameObjectRect.transform.localPosition.SetZ(oldPosition.z);
movingGameObjectRect.anchoredPosition = movingGameObjectRect.anchoredPosition.RoundAmount(PlayerListConfig.snapToGridSize.Value);
yield return null;
}
while (!CursorUtils.IsUseInputPressed && shouldMove)
{
CombineQMColliderAndPlayerListRect();
movingGameObjectRect.transform.position = CursorUtils.HitPosition;
movingGameObjectRect.transform.localPosition = movingGameObjectRect.transform.localPosition.SetZ(oldPosition.z);
movingGameObjectRect.anchoredPosition = movingGameObjectRect.anchoredPosition.RoundAmount(PlayerListConfig.snapToGridSize.Value);
yield return null;
}
Constants.quickMenu.GetComponent<BoxCollider>().size = Constants.quickMenuColliderSize;
if (shouldMove)
onComplete.DelegateSafeInvoke(movingGameObject);
else
movingGameObjectRect.anchoredPosition3D = oldPosition;
shouldMove = false;
}
public static void CombineQMColliderAndPlayerListRect(bool useConfigValues = false)
{
BoxCollider collider = Constants.quickMenu.GetComponent<BoxCollider>();
float colliderLeft = -Constants.quickMenuColliderSize.x / 2;
float colliderTop = Constants.quickMenuColliderSize.y / 2;
float colliderRight = Constants.quickMenuColliderSize.x / 2;
float colliderBottom = -Constants.quickMenuColliderSize.y / 2;
float playerListLeft;
float playerListTop;
float playerListRight;
float playerListBottom;
if (!useConfigValues)
{
playerListLeft = MenuManager.playerListRect.anchoredPosition.x - MenuManager.playerListRect.sizeDelta.x / 2;
playerListTop = MenuManager.playerListRect.anchoredPosition.y + (MenuManager.playerListRect.sizeDelta.y / 2);
playerListRight = MenuManager.playerListRect.anchoredPosition.x + MenuManager.playerListRect.sizeDelta.x / 2;
playerListBottom = MenuManager.playerListRect.anchoredPosition.y - (MenuManager.playerListRect.sizeDelta.y / 2);
}
else
{
playerListLeft = PlayerListConfig.playerListPosition.Value.x - MenuManager.playerListRect.sizeDelta.x / 2;
playerListTop = PlayerListConfig.playerListPosition.Value.y + (MenuManager.playerListRect.sizeDelta.y / 2);
playerListRight = PlayerListConfig.playerListPosition.Value.x + MenuManager.playerListRect.sizeDelta.x / 2;
playerListBottom = PlayerListConfig.playerListPosition.Value.y - (MenuManager.playerListRect.sizeDelta.y / 2);
}
collider.size = new Vector2(Math.Abs(Math.Max(Math.Abs(Math.Min(colliderLeft, playerListLeft)), Math.Abs(Math.Max(colliderRight, playerListRight)))) * 2, Math.Abs(Math.Max(Math.Abs(Math.Min(colliderBottom, playerListBottom)), Math.Abs(Math.Max(colliderTop, playerListTop)))) * 2);
}
}
}