Esempio n. 1
0
                /// <summary> Creates a button and optionally registers it for automatic management </summary>
                /// <param name="label"> Text to appear on the button </param>
                /// <param name="tooltip"> Tooltip to appear on hover. Appears at the top of the menu </param>
                /// <param name="x"> Horizontal position </param>
                /// <param name="y"> Vertical position </param>
                /// <param name="parent"> Parent transform </param>
                /// <param name="OnClick"> Called when the button is clicked </param>
                /// <remarks>Note: this class is very basic but fast. It is recommended to use a more abstract interface</remarks>
                public Button(string label, string tooltip, float x, float y, Transform parent, Action OnClick)
                {
                    this.OnClick = OnClick;

                    GameObject button = UnityEngine.Object.Instantiate(BaseButton.gameObject, parent);

                    button.transform.localPosition = new Vector3(
                        button.transform.localPosition.x + (ButtonSize * (x - 1)),
                        button.transform.localPosition.y + (ButtonSize * y),
                        button.transform.localPosition.z
                        );

                    Text text = button.transform.GetComponentInChildren <Text>();

                    text.color = Colors.ButtonText;
                    text.text  = label;

                    button.transform.GetComponentInChildren <Image>().color = Colors.ButtonBackground;

                    UiTooltip buttonTooltip = button.transform.GetComponentInChildren <UiTooltip>();

                    buttonTooltip.field_Public_String_0 = tooltip;
                    buttonTooltip.field_Public_String_1 = tooltip;

                    UnityEngine.UI.Button buttonClick = button.transform.GetComponentInChildren <UnityEngine.UI.Button>();
                    buttonClick.onClick = new UnityEngine.UI.Button.ButtonClickedEvent();
                    buttonClick.onClick.AddListener(OnClick);

                    self = button;
                }
Esempio n. 2
0
        public SingleButton(GameObject parent, GameObject template, Vector3 position, string text, Action onClick, string tooltip, string buttonName, bool resize = false, Color?color = null) : base(parent, template, position, text, buttonName, resize, color)
        {
            gameObject.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(onClick);
            tooltipComponent = gameObject.GetComponent <UiTooltip>();
            tooltipComponent.field_Public_String_0 = tooltip;
            tooltipComponent.field_Public_String_1 = tooltip;

            Position = position;
        }
Esempio n. 3
0
                /// <summary> Creates a new dual state UI element </summary>
                /// <param name="label"> Text to appear on the toggle </param>
                /// <param name="tooltip"> Tooltip to appear on hover. Appears at the top of the menu </param>
                /// <param name="x"> Horizontal position </param>
                /// <param name="y"> Vertical position </param>
                /// <param name="state"> Initial state </param>
                /// <param name="parent"> Parent transform </param>
                /// <param name="OnEnable"> Called when the value becomes true </param>
                /// <param name="OnDisable"> Called when the value becomes false </param>
                /// <remarks>Note: this class is very basic but fast. It is recommended to use a more abstract interface</remarks>
                public Toggle(string label, string tooltip, float x, float y, bool state, Transform parent, Action OnEnable, Action OnDisable)
                {
                    this.state     = state;
                    this.OnEnable  = OnEnable;
                    this.OnDisable = OnDisable;

                    GameObject button = UnityEngine.Object.Instantiate(BaseToggle.gameObject, parent);

                    button.transform.localPosition = new Vector3(
                        button.transform.localPosition.x + (ButtonSize * (x + 1)),
                        button.transform.localPosition.y + (ButtonSize * (y + 1)) + 18,
                        button.transform.localPosition.z
                        );

                    on = button.transform.Find("Toggle_States_HUDEnabled/ON").gameObject;
                    on.SetActive(state);
                    on.GetComponentInChildren <Image>().color = Colors.ToggleOn;

                    off = button.transform.Find("Toggle_States_HUDEnabled/OFF").gameObject;
                    off.SetActive(!state);
                    off.GetComponentInChildren <Image>().color = Colors.ToggleOff;

                    Text[] onTexts = on.GetComponentsInChildren <Text>();
                    onTexts[0].text = label + " On";
                    onTexts[1].text = label + " Off";
                    onTexts[0].resizeTextForBestFit = true;
                    onTexts[1].resizeTextForBestFit = true;

                    Text[] offTexts = off.GetComponentsInChildren <Text>();
                    offTexts[0].text = label + " On";
                    offTexts[1].text = label + " Off";
                    offTexts[0].resizeTextForBestFit = true;
                    offTexts[1].resizeTextForBestFit = true;

                    UiTooltip buttonTooltip = button.transform.GetComponent <UiTooltip>();

                    buttonTooltip.field_Public_String_0 = tooltip;
                    buttonTooltip.field_Public_String_1 = tooltip;

                    UnityEngine.UI.Button _button = button.transform.GetComponent <UnityEngine.UI.Button>();
                    _button.onClick = new UnityEngine.UI.Button.ButtonClickedEvent();
                    _button.onClick.AddListener(new Action(() =>
                    {
                        SetState();
                    }));

                    button.gameObject.active = true;

                    self = button;
                }
Esempio n. 4
0
        public static void SetToolTipBasedOnToggle(this UiTooltip tooltip)
        {
            UiToggleButton componentInChildren = tooltip.gameObject.GetComponentInChildren <UiToggleButton>();

            if (componentInChildren != null && !string.IsNullOrEmpty(tooltip.alternateText))
            {
                string displayText = (!componentInChildren.toggledOn) ? tooltip.alternateText : tooltip.text;
                if (TooltipManager.field_Text_0 != null)                //Only return type field of text
                {
                    TooltipManager.Method_Public_String_3(displayText); //Last function to take string parameter
                }
                else if (tooltip != null)
                {
                    tooltip.text = displayText;
                }
            }
        }
Esempio n. 5
0
        public static void LoadAssetBundle()
        {
            // Stolen from UIExpansionKit (https://github.com/knah/VRCMods/blob/master/UIExpansionKit) #Imnotaskidiswear
            MelonLogger.Msg("Loading List UI...");
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PlayerList.playerlistmod.assetbundle"))
            {
                using (var memoryStream = new MemoryStream((int)stream.Length))
                {
                    stream.CopyTo(memoryStream);
                    AssetBundle assetBundle = AssetBundle.LoadFromMemory_Internal(memoryStream.ToArray(), 0);
                    assetBundle.hideFlags |= HideFlags.DontUnloadUnusedAsset;
                    playerList             = UnityEngine.Object.Instantiate(assetBundle.LoadAsset_Internal("Assets/Prefabs/PlayerListMod.prefab", Il2CppType.Of <GameObject>()).Cast <GameObject>(), Constants.quickMenu.transform);
                    menuButton             = UnityEngine.Object.Instantiate(assetBundle.LoadAsset_Internal("Assets/Prefabs/PlayerListMenuButton.prefab", Il2CppType.Of <GameObject>()).Cast <GameObject>(), Constants.shortcutMenu.transform);
                }
            }
            menuButton.SetLayerRecursive(12);
            menuButton.transform.localPosition = Converters.ConvertToUnityUnits(new Vector3(4, -1));
            menuButton.GetComponent <RectTransform>().pivot = new Vector2(0, 0);

            UiTooltip tooltip = menuButton.AddComponent <UiTooltip>();

            tooltip.field_Public_String_0 = "Open PlayerList menu";
            tooltip.field_Public_String_1 = "Open PlayerList menu";

            playerList.SetLayerRecursive(12);
            playerListRect = playerList.GetComponent <RectTransform>();
            playerListRect.anchoredPosition = Config.PlayerListPosition;
            playerListRect.localPosition    = new Vector3(playerListRect.localPosition.x, playerListRect.localPosition.y, 25); // Do this or else it looks off for whatever reason
            playerList.SetActive(false);

            MenuManager.shouldStayHidden = !Config.enabledOnStart.Value;
            _fontSize          = Config.fontSize.Value;
            MenuButtonPosition = Config.MenuButtonPosition;

            Constants.playerListLayout  = playerList.transform.Find("PlayerList Viewport/PlayerList").GetComponent <VerticalLayoutGroup>();
            Constants.generalInfoLayout = playerList.transform.Find("GeneralInfo Viewport/GeneralInfo").GetComponent <VerticalLayoutGroup>();

            EnableDisableListener playerListListener = playerList.AddComponent <EnableDisableListener>();

            playerListListener.OnEnableEvent += EntryManager.RefreshAllEntries;
        }
Esempio n. 6
0
        public static void set_tooltip(this UiTooltip t)
        {
            var a = t.gameObject.GetComponentInChildren <UiToggleButton>();

            if (a == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(t.alternateText))
            {
                return;
            }
            var text = (!a.toggledOn) ? t.alternateText : t.text;

            if (TooltipManager.field_Private_Static_Text_0 != null)
            {
                TooltipManager.Method_Public_Static_Void_String_2(text);
            }
            if (t.tooltip != null)
            {
                t.tooltip.text = text;
            }
        }