예제 #1
0
        public void Awake()
        {
            SetupConfig();

            AssetBundle bundle;

            // Make our assets available to load
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("QuickRestart.booth_assets"))
            {
                bundle = AssetBundle.LoadFromStream(stream);
            }

            // Set up textures for the UI button
            Texture2D buttonTexture          = bundle.LoadAsset <Texture2D>("Assets/Texture2D/Booth_texUICleanButton.png");
            Texture2D buttonHighlightTexture = bundle.LoadAsset <Texture2D>("Assets/Texture2D/Booth_texUIHighlightHeader.png");
            Texture2D buttonBorderTexture    = bundle.LoadAsset <Texture2D>("Assets/Texture2D/Booth_texUIOutlineOnly.png");
            Texture2D buttonOutlineTexture   = bundle.LoadAsset <Texture2D>("Assets/Texture2D/Booth_texUIHighlightBoxOutlineThick.png");

            // Needed to convert the textures to sprites
            Rect buttonTextureDimensions          = new Rect(0, 0, buttonTexture.width, buttonTexture.height);
            Rect buttonHighlightTextureDimensions = new Rect(0, 0, buttonHighlightTexture.width, buttonHighlightTexture.height);
            Rect buttonBorderTextureeDimensions   = new Rect(0, 0, buttonBorderTexture.width, buttonBorderTexture.height);
            Rect buttonOutlineTextureeDimensions  = new Rect(0, 0, buttonOutlineTexture.width, buttonOutlineTexture.height);

            // Used to draw the button on UI
            Sprite buttonSprite          = Sprite.Create(buttonTexture, buttonTextureDimensions, new Vector2(0, 0));
            Sprite buttonHighlightSprite = Sprite.Create(buttonHighlightTexture, buttonHighlightTextureDimensions, new Vector2(0, 0));
            Sprite buttonBorderSprite    = Sprite.Create(buttonBorderTexture, buttonBorderTextureeDimensions, new Vector2(0, 0));
            Sprite buttonOutlineSprite   = Sprite.Create(buttonOutlineTexture, buttonOutlineTextureeDimensions, new Vector2(0, 0));

            On.RoR2.UI.ChatBox.FocusInputField   += (orig, self) => { orig(self); IsInChatBox = true; };
            On.RoR2.UI.ChatBox.UnfocusInputField += (orig, self) => { orig(self); IsInChatBox = false; };

            //Add restart button to the pause screen
            On.RoR2.UI.PauseScreenController.Awake += (orig, self) => {
                orig(self);
                if (Run.instance is null || PreGameController.instance)
                {
                    // Don't show in lobby
                    return;
                }

                Vector2    buttonSize = new Vector2(320, 48);
                GameObject button     = BoothUtil.CreateButton(self.mainPanel.GetChild(0).gameObject, buttonSize, buttonSprite);

                // Add in the stylized highlight/border
                List <Image> images = new List <Image>();
                BoothUtil.SpawnImage(images, button, new Color(1, 1, 1, 1), new Vector2(0.5f, 0.5f), new Vector2(-6, -6), new Vector2(6, 6), buttonHighlightSprite);
                images[images.Count - 1].gameObject.SetActive(false);

                // Add in the sharp white border line
                BoothUtil.SpawnImage(new List <Image>(), button, new Color(1, 1, 1, 0.286f), new Vector2(0.5f, 0.5f), new Vector2(0, 0), new Vector2(0, 0), buttonBorderSprite);

                // Add in the thicker surrounding outline for when you hover on the button
                Image highlightImage = BoothUtil.SpawnImage(new List <Image>(), button, new Color(1, 1, 1, 1), new Vector2(0.5f, 0.5f), new Vector2(-4, -12), new Vector2(14, 4), buttonOutlineSprite);
                button.GetComponent <RoR2.UI.HGButton>().imageOnHover = highlightImage;

                // Add in the restart text
                List <TMPro.TextMeshProUGUI> buttonText = new List <TMPro.TextMeshProUGUI>();
                BoothUtil.CreateText(buttonText, button, new Color(1, 1, 1, 1), 24, 0, new Vector2(12, 4), new Vector2(-12, -4), "Restart");

                if ("top".Equals(ConfigRestartButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
                {
                    button.transform.SetAsFirstSibling();
                }
                else if ("bottom".Equals(ConfigRestartButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
                {
                    button.transform.SetAsLastSibling();
                }
                else
                {
                    try
                    {
                        int position = Convert.ToInt32(ConfigRestartButtonPosition.Value);
                        if (position < 0)
                        {
                            position = 0;
                        }
                        else if (position >= button.transform.parent.childCount)
                        {
                            position = button.transform.parent.childCount - 1;
                        }
                        button.transform.SetSiblingIndex(position);
                    }
                    catch (FormatException e)
                    {
                        //default to bottom
                        button.transform.SetAsLastSibling();
                    }
                }

                if (PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost())
                {
                    // Disable on multiplayer, unless they are the host
                    button.SetActive(false);
                }

                // Set up what to do when the button is clicked
                button.GetComponent <RoR2.UI.HGButton>().onClick.AddListener(() => {
                    BoothUtil.ResetGame(self, ConfigConfirmationDialog.Value, this, true);
                });
            };

            //Add Back to Character Select to the pause screen
            On.RoR2.UI.PauseScreenController.Awake += (orig, self) => {
                orig(self);
                if (Run.instance is null || PreGameController.instance)
                {
                    // Don't show in lobby
                    return;
                }

                Vector2    buttonSize = new Vector2(320, 48);
                GameObject button     = BoothUtil.CreateButton(self.mainPanel.GetChild(0).gameObject, buttonSize, buttonSprite);

                // Add in the stylized highlight/border
                List <Image> images = new List <Image>();
                BoothUtil.SpawnImage(images, button, new Color(1, 1, 1, 1), new Vector2(0.5f, 0.5f), new Vector2(-6, -6), new Vector2(6, 6), buttonHighlightSprite);
                images[images.Count - 1].gameObject.SetActive(false);

                // Add in the sharp white border line
                BoothUtil.SpawnImage(new List <Image>(), button, new Color(1, 1, 1, 0.286f), new Vector2(0.5f, 0.5f), new Vector2(0, 0), new Vector2(0, 0), buttonBorderSprite);

                // Add in the thicker surrounding outline for when you hover on the button
                Image highlightImage = BoothUtil.SpawnImage(new List <Image>(), button, new Color(1, 1, 1, 1), new Vector2(0.5f, 0.5f), new Vector2(-4, -12), new Vector2(14, 4), buttonOutlineSprite);
                button.GetComponent <RoR2.UI.HGButton>().imageOnHover = highlightImage;

                // Add in the character select text
                List <TMPro.TextMeshProUGUI> buttonText = new List <TMPro.TextMeshProUGUI>();
                BoothUtil.CreateText(buttonText, button, new Color(1, 1, 1, 1), 24, 0, new Vector2(12, 4), new Vector2(-12, -4), "Character Select");

                if ("top".Equals(ConfigCharacterButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
                {
                    button.transform.SetAsFirstSibling();
                }
                else if ("bottom".Equals(ConfigCharacterButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
                {
                    button.transform.SetAsLastSibling();
                }
                else
                {
                    try
                    {
                        int position = Convert.ToInt32(ConfigCharacterButtonPosition.Value);
                        if (position < 0)
                        {
                            position = 0;
                        }
                        else if (position >= button.transform.parent.childCount)
                        {
                            position = button.transform.parent.childCount - 1;
                        }
                        button.transform.SetSiblingIndex(position);
                    }
                    catch (FormatException e)
                    {
                        //default to bottom
                        button.transform.SetAsLastSibling();
                    }
                }

                if (PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost())
                {
                    // Disable on multiplayer, unless they are the host
                    button.SetActive(false);
                }

                // Set up what to do when the button is clicked
                button.GetComponent <RoR2.UI.HGButton>().onClick.AddListener(() => {
                    BoothUtil.ResetGame(self, ConfigConfirmationDialog.Value, this, false);
                });
            };
        }
예제 #2
0
 void Update()
 {
     if (ConfigResetKeyEnabled.Value)
     {
         bool InRun       = !(Run.instance is null);
         bool Multiplayer = PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost();
         if (InRun && !Multiplayer && !IsInChatBox)
         {
             // Done this way so we can have other things in the update function
             HandleResetKey();
         }
     }
 }