Exemplo n.º 1
0
        public void CreatePauseMenuButtons(Level level, TextMenu menu, bool minimal)
        {
            if (Everest.Flags.IsDisabled || !Settings.ShowModOptionsInGame)
            {
                return;
            }

            List <TextMenu.Item> items = menu.GetItems();
            int index;

            // Find the options button and place our button below it.
            string cleanedOptions = Dialog.Clean("menu_pause_options");

            index = items.FindIndex(_ => {
                TextMenu.Button other = (_ as TextMenu.Button);
                if (other == null)
                {
                    return(false);
                }
                return(other.Label == cleanedOptions);
            });
            if (index != -1)
            {
                index++;
            }
            // Otherwise, place it below the last button.
            else
            {
                index = items.Count;
            }

            TextMenu.Item itemModOptions = null;
            menu.Insert(index, itemModOptions = new TextMenu.Button(Dialog.Clean("menu_pause_modoptions")).Pressed(() => {
                int returnIndex = menu.IndexOf(itemModOptions);
                menu.RemoveSelf();

                level.PauseMainMenuOpen = false;
                level.Paused            = true;

                TextMenu options = OuiModOptions.CreateMenu(true, LevelExt.PauseSnapshot);

                options.OnESC = options.OnCancel = () => {
                    Audio.Play(Sfxs.ui_main_button_back);
                    options.CloseAndRun(Everest.SaveSettings(), () => level.Pause(returnIndex, minimal, false));
                };

                options.OnPause = () => {
                    Audio.Play(Sfxs.ui_main_button_back);
                    options.CloseAndRun(Everest.SaveSettings(), () => {
                        level.Paused       = false;
                        Engine.FreezeTimer = 0.15f;
                    });
                };

                level.Add(options);
            }));
        }
Exemplo n.º 2
0
        public void CreatePauseMenuButtons(Level level, TextMenu menu, bool minimal)
        {
            if (Everest.Flags.IsDisabled || !Settings.ShowModOptionsInGame)
            {
                return;
            }

            List <TextMenu.Item> items = menu.GetItems();
            int index;

            // Find the options button and place our button below it.
            string cleanedOptions = Dialog.Clean("menu_pause_options");

            index = items.FindIndex(_ => {
                TextMenu.Button other = (_ as TextMenu.Button);
                if (other == null)
                {
                    return(false);
                }
                return(other.Label == cleanedOptions);
            });
            if (index != -1)
            {
                index++;
            }
            // Otherwise, place it below the last button.
            else
            {
                index = items.Count;
            }

            TextMenu.Item itemModOptions = null;
            menu.Insert(index, itemModOptions = new TextMenu.Button(Dialog.Clean("menu_pause_modoptions")).Pressed(() => {
                int returnIndex = menu.IndexOf(itemModOptions);
                menu.RemoveSelf();

                level.PauseMainMenuOpen = false;
                level.Paused            = true;

                TextMenu options = OuiModOptions.CreateMenu(true, LevelExt.PauseSnapshot);

                options.OnESC = options.OnCancel = () => {
                    Audio.Play(SFX.ui_main_button_back);
                    options.CloseAndRun(Everest.SaveSettings(), () => {
                        level.Pause(returnIndex, minimal, false);

                        // adjust the Mod Options menu position, in case it moved (pause menu entries added/removed after changing mod options).
                        TextMenu textMenu = level.Entities.GetToAdd().FirstOrDefault((Entity e) => e is TextMenu) as TextMenu;
                        TextMenu.Button modOptionsButton = textMenu?.GetItems().OfType <TextMenu.Button>()
                                                           .FirstOrDefault(button => button.Label == Dialog.Clean("menu_pause_modoptions"));
                        if (modOptionsButton != null)
                        {
                            textMenu.Selection = textMenu.IndexOf(modOptionsButton);
                        }
                    });
                };

                options.OnPause = () => {
                    Audio.Play(SFX.ui_main_button_back);
                    options.CloseAndRun(Everest.SaveSettings(), () => {
                        level.Paused       = false;
                        Engine.FreezeTimer = 0.15f;
                    });
                };

                level.Add(options);
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method getting called on the Oui instance when the method just above is called.
        /// </summary>
        private TextMenuButtonExt buildOpenMenuButton(TextMenu parentMenu, bool inGame, Action backToParentMenu, object[] parameters)
        {
            if (inGame)
            {
                Level level = Engine.Scene as Level;

                // this is how it works in-game
                return((TextMenuButtonExt) new TextMenuButtonExt(getButtonName(parameters)).Pressed(() =>
                {
                    // set up the menu instance
                    this.backToParentMenu = backToParentMenu;
                    this.parameters = parameters;

                    // close the parent menu
                    parentMenu.RemoveSelf();

                    // create our menu and prepare it
                    TextMenu thisMenu = buildMenu(true);

                    // notify the pause menu that we aren't in the main menu anymore (hides the strawberry tracker)
                    bool comesFromPauseMainMenu = level.PauseMainMenuOpen;
                    level.PauseMainMenuOpen = false;

                    thisMenu.OnESC = thisMenu.OnCancel = () =>
                    {
                        // close this menu
                        Audio.Play(SFX.ui_main_button_back);
                        thisMenu.CloseAndRun(Everest.SaveSettings(), () =>
                        {
                            // and open the parent menu back (this should work, right? we only removed it from the scene earlier, but it still exists and is intact)
                            // "what could possibly go wrong?" ~ famous last words
                            level.Add(parentMenu);

                            // restore the pause "main menu" flag to make strawberry tracker appear again if required.
                            level.PauseMainMenuOpen = comesFromPauseMainMenu;
                        });
                    };

                    thisMenu.OnPause = () =>
                    {
                        // we're unpausing, so close that menu, and save the mod Settings because the Mod Options menu won't do that for us
                        Audio.Play(SFX.ui_main_button_back);
                        thisMenu.CloseAndRun(Everest.SaveSettings(), () =>
                        {
                            level.Paused = false;
                            Engine.FreezeTimer = 0.15f;
                        });
                    };

                    // finally, add the menu to the scene
                    level.Add(thisMenu);
                }));
            }
            else
            {
                // this is how it works in the main menu: way more simply than the in-game mess.
                return((TextMenuButtonExt) new TextMenuButtonExt(getButtonName(parameters)).Pressed(() =>
                {
                    // set up the menu instance
                    this.backToParentMenu = backToParentMenu;
                    this.parameters = parameters;

                    gotoMenu(OuiModOptions.Instance.Overworld);
                }));
            }
        }