public static void Postfix(IngameMenu __instance) { if (GameModeUtils.IsPermadeath()) { return; } if (__instance != null && quitButton == null) { // make a new confirmation Menu var quitConfirmationPrefab = __instance.gameObject.FindChild("QuitConfirmation"); quitConfirmation = GameObject.Instantiate(quitConfirmationPrefab, __instance.gameObject.FindChild("QuitConfirmation").transform.parent); quitConfirmation.name = "QuitToDesktopConfirmation"; // get the No Button and add the needed listeners to it var noButtonPrefab = quitConfirmation.gameObject.transform.Find("ButtonNo").GetComponent <Button>(); noButtonPrefab.onClick.RemoveAllListeners(); noButtonPrefab.onClick.AddListener(() => { __instance.Close(); }); // get the Yes Button and add the needed listeners to it var yesButtonPrefab = quitConfirmation.gameObject.transform.Find("ButtonYes").GetComponent <Button>(); yesButtonPrefab.onClick.RemoveAllListeners(); yesButtonPrefab.onClick.AddListener(() => { __instance.QuitGame(true); }); // make the Quit To Desktop Button var buttonPrefab = __instance.quitToMainMenuButton; quitButton = GameObject.Instantiate(buttonPrefab, __instance.quitToMainMenuButton.transform.parent); quitButton.name = "ButtonQuitToDesktop"; quitButton.onClick.RemoveAllListeners(); quitButton.onClick.AddListener(() => { __instance.gameObject.FindChild("QuitConfirmationWithSaveWarning").SetActive(false); }); // set the confirmation with save false so it doesn't conflict quitButton.onClick.AddListener(() => { __instance.gameObject.FindChild("QuitConfirmation").SetActive(false); }); // set the Quit To Main Menu confirmation to false so it doesn't conflict if (!QPatch.Config.ShowConfirmationDialog) { quitButton.onClick.AddListener(() => { __instance.QuitGame(true); }); } else if (QPatch.Config.ShowConfirmationDialog) { quitButton.onClick.AddListener(() => { quitConfirmation.SetActive(true); }); // set our new confirmation to true } IEnumerable <Text> texts = quitButton.GetComponents <Text>().Concat(quitButton.GetComponentsInChildren <Text>()); foreach (Text text in texts) { text.text = "Quit to Desktop"; } texts = __instance.quitToMainMenuButton.GetComponents <Text>().Concat(__instance.quitToMainMenuButton.GetComponentsInChildren <Text>()); foreach (Text text in texts) { text.text = "Quit to Main Menu"; } } }
public static void Postfix(IngameMenu __instance) { if (GameModeUtils.IsPermadeath()) { return; } if (__instance != null && quitButton == null) { // make a new Confirmation Menu var confirmationMenuPrefab = __instance.gameObject.FindChild("QuitConfirmation"); quitConfirmation = GameObject.Instantiate(confirmationMenuPrefab, __instance.gameObject.FindChild("QuitConfirmation").transform.parent); quitConfirmation.name = "QuitToDesktopConfirmation"; // get the no button from the confirmation menu and add the needed listener var noButtonPrefab = quitConfirmation.gameObject.transform.Find("ButtonNo").GetComponent <Button>(); noButtonPrefab.onClick.RemoveAllListeners(); noButtonPrefab.onClick.AddListener(() => { __instance.Close(); }); // get the yes button from the confirmation menu and add the needed listener var yesButtonPrefab = quitConfirmation.gameObject.transform.Find("ButtonYes").GetComponent <Button>(); yesButtonPrefab.onClick.RemoveAllListeners(); yesButtonPrefab.onClick.AddListener(() => { __instance.QuitGame(true); }); // make a new button var buttonPrefab = __instance.quitToMainMenuButton.gameObject.GetComponent <Button>(); quitButton = GameObject.Instantiate(buttonPrefab, __instance.quitToMainMenuButton.transform.parent); quitButton.name = "ButtonQuitToDesktop"; quitButton.onClick.RemoveAllListeners(); quitButton.onClick.AddListener(() => { __instance.gameObject.FindChild("QuitConfirmationWithSaveWarning").SetActive(false); }); quitButton.onClick.AddListener(() => { __instance.gameObject.FindChild("QuitConfirmation").SetActive(false); }); quitButton.onClick.AddListener(() => { quitConfirmation.SetActive(true); }); IEnumerable <TextMeshProUGUI> texts = quitButton.GetComponents <TextMeshProUGUI>().Concat(quitButton.GetAllComponentsInChildren <TextMeshProUGUI>()); foreach (var text in texts) { text.text = "Quit to Desktop"; // change our Button text to Quit To Desktop } texts = __instance.quitToMainMenuButton.GetComponents <TextMeshProUGUI>().Concat(__instance.quitToMainMenuButton.GetAllComponentsInChildren <TextMeshProUGUI>()); foreach (var text in texts) { text.text = "Quit to Main Menu"; // change the Quit button text into Quit to Main Menu } } }