private static void openReturnToLobbyConfirmMenu(Level level, int returnIndex)
        {
            level.Paused = true;
            TextMenu menu = new TextMenu();

            menu.AutoScroll = false;
            menu.Position   = new Vector2((float)Engine.Width / 2f, (float)Engine.Height / 2f - 100f);

            // RETURN TO LOBBY?
            menu.Add(new TextMenu.Header(Dialog.Clean("collabutils2_returntolobby_confirm_title")));

            // Save
            if (CollabModule.Instance.Session.SaveAndReturnToLobbyAllowed)
            {
                // add some explanatory text on the "Save" and "Do Not Save" options
                menu.Add(new TextMenu.SubHeader(Dialog.Clean("collabutils2_returntolobby_confirm_note1")));
                menu.Add(new TextMenuExt.SubHeaderExt(Dialog.Clean("collabutils2_returntolobby_confirm_note2"))
                {
                    HeightExtra = 0f
                });
                menu.Add(new TextMenu.SubHeader(""));

                menu.Add(new TextMenu.Button(Dialog.Clean("collabutils2_returntolobby_confirm_save")).Pressed(() => {
                    Engine.TimeRate = 1f;
                    menu.Focused    = false;
                    Audio.SetMusic(null);
                    Audio.BusStopAll("bus:/gameplay_sfx", immediate: true);

                    // add a death, like vanilla Save & Quit
                    level.Session.InArea = true;
                    level.Session.Deaths++;
                    level.Session.DeathsInCurrentLevel++;
                    SaveData.Instance.AddDeath(level.Session.Area);

                    level.DoScreenWipe(wipeIn: false, () => {
                        CollabModule.Instance.SaveData.SessionsPerLevel.Add(level.Session.Area.GetSID(), Encoding.UTF8.GetString(UserIO.Serialize(level.Session)));

                        // save all mod sessions of mods that have mod sessions.
                        Dictionary <string, string> modSessions = new Dictionary <string, string>();
                        foreach (EverestModule mod in Everest.Modules)
                        {
                            if (mod._Session != null && !(mod._Session is EverestModuleBinarySession))
                            {
                                try {
                                    modSessions[mod.Metadata.Name] = YamlHelper.Serializer.Serialize(mod._Session);
                                } catch (Exception e) {
                                    // this is the same fallback message as the base EverestModule class if something goes wrong.
                                    Logger.Log(LogLevel.Warn, "CollabUtils2/ReturnToLobbyHelper", "Failed to save the session of " + mod.Metadata.Name + "!");
                                    Logger.LogDetailed(e);
                                }
                            }
                        }
                        CollabModule.Instance.SaveData.ModSessionsPerLevel.Add(level.Session.Area.GetSID(), modSessions);

                        Engine.Scene = new LevelExitToLobby(LevelExit.Mode.SaveAndQuit, level.Session);
                    });

                    foreach (LevelEndingHook component in level.Tracker.GetComponents <LevelEndingHook>())
                    {
                        component.OnEnd?.Invoke();
                    }
                }));
            }

            // Do Not Save
            menu.Add(new TextMenu.Button(Dialog.Clean(CollabModule.Instance.Session.SaveAndReturnToLobbyAllowed ? "collabutils2_returntolobby_confirm_donotsave" : "menu_return_continue")).Pressed(() => {
                Engine.TimeRate = 1f;
                menu.Focused    = false;
                Audio.SetMusic(null);
                Audio.BusStopAll("bus:/gameplay_sfx", immediate: true);

                level.DoScreenWipe(wipeIn: false, () => {
                    Engine.Scene = new LevelExitToLobby(LevelExit.Mode.GiveUp, level.Session);
                });

                foreach (LevelEndingHook component in level.Tracker.GetComponents <LevelEndingHook>())
                {
                    component.OnEnd?.Invoke();
                }
            }));

            // Cancel
            menu.Add(new TextMenu.Button(Dialog.Clean(CollabModule.Instance.Session.SaveAndReturnToLobbyAllowed ? "collabutils2_returntolobby_confirm_cancel" : "menu_return_cancel")).Pressed(() => {
                menu.OnCancel();
            }));

            // handle Pause button
            menu.OnPause = (menu.OnESC = () => {
                menu.RemoveSelf();
                level.Paused = false;
                Engine.FreezeTimer = 0.15f;
                Audio.Play("event:/ui/game/unpause");
            });

            // handle Cancel button
            menu.OnCancel = () => {
                Audio.Play("event:/ui/main/button_back");
                menu.RemoveSelf();
                level.Pause(returnIndex, minimal: false);
            };

            level.Add(menu);
        }
Exemplo n.º 2
0
        private void ModifyLevelMenu(Level level, TextMenu pausemenu, bool minimal)
        {
            var settings = this.InRandomizerSettings;

            if (settings != null)
            {
                foreach (var item in new System.Collections.Generic.List <TextMenu.Item>(pausemenu.GetItems()))
                {
                    if (item.GetType() == typeof(TextMenu.Button))
                    {
                        var btn = (TextMenu.Button)item;
                        if (btn.Label == Dialog.Clean("MENU_PAUSE_SAVEQUIT") || btn.Label == Dialog.Clean("MENU_PAUSE_RETURN"))
                        {
                            pausemenu.Remove(item);
                        }
                        if (btn.Label == Dialog.Clean("MENU_PAUSE_RESTARTAREA"))
                        {
                            if (settings.Algorithm == LogicType.Endless)
                            {
                                pausemenu.Remove(item);
                            }
                            else
                            {
                                btn.Label = Dialog.Clean("MENU_PAUSE_RESTARTRANDO");
                            }
                        }
                    }
                }

                int returnIdx = pausemenu.GetItems().Count;
                pausemenu.Add(new TextMenu.Button(Dialog.Clean("MENU_PAUSE_QUITRANDO")).Pressed(() => {
                    level.PauseMainMenuOpen = false;
                    pausemenu.RemoveSelf();

                    TextMenu menu   = new TextMenu();
                    menu.AutoScroll = false;
                    menu.Position   = new Vector2((float)Engine.Width / 2f, (float)((double)Engine.Height / 2.0 - 100.0));
                    menu.Add(new TextMenu.Header(Dialog.Clean("MENU_QUITRANDO_TITLE")));
                    menu.Add(new TextMenu.Button(Dialog.Clean("MENU_QUITRANDO_CONFIRM")).Pressed((Action)(() => {
                        Engine.TimeRate = 1f;
                        menu.Focused = false;
                        level.Session.InArea = false;
                        Audio.SetMusic((string)null, true, true);
                        Audio.BusStopAll("bus:/gameplay_sfx", true);
                        level.DoScreenWipe(false, (Action)(() => Engine.Scene = (Scene) new LevelExit(LevelExit.Mode.SaveAndQuit, level.Session, level.HiresSnow)), true);
                        foreach (LevelEndingHook component in level.Tracker.GetComponents <LevelEndingHook>())
                        {
                            if (component.OnEnd != null)
                            {
                                component.OnEnd();
                            }
                        }
                    })));
                    menu.Add(new TextMenu.Button(Dialog.Clean("MENU_QUITRANDO_CANCEL")).Pressed((Action)(() => menu.OnCancel())));
                    menu.OnPause = menu.OnESC = (Action)(() => {
                        menu.RemoveSelf();
                        level.Paused = false;
                        Engine.FreezeTimer = 0.15f;
                        Audio.Play("event:/ui/game/unpause");
                    });
                    menu.OnCancel = (Action)(() => {
                        Audio.Play("event:/ui/main/button_back");
                        menu.RemoveSelf();
                        level.Pause(returnIdx, minimal, false);
                    });
                    level.Add((Entity)menu);
                }));
            }
        }
Exemplo n.º 3
0
        //创建暂停界面逻辑
        public void CreatePauseMenu()
        {
            Audio.Play(Sfxs.ui_game_pause);
            Audio.PauseGameplaySfx = true;
            snapshot = Audio.CreateSnapshot(Snapshots.PAUSE_MENU);

            var menu = new TextMenu();

            // Resume Button
            menu.Add(new TextMenu.Button(Dialog.Clean("pico8_pause_continue")).Pressed(() => menu.OnCancel()));

            // Restart Button
            menu.Add(new TextMenu.Button(Dialog.Clean("pico8_pause_restart")).Pressed(() =>
            {
                pauseMenu = null;
                music(-1, 0, 0);

                new FadeWipe(this, false, () =>
                {
                    Audio.BusStopAll(Buses.GAMEPLAY, false);
                    Audio.PauseGameplaySfx = false;
                    Audio.EndSnapshot(snapshot);
                    snapshot = null;

                    ResetScreen();
                    game       = null;
                    gameFrame  = 0;
                    gameActive = true;
                    new FadeWipe(this, true);
                });
            }));

            // Quit Button
            menu.Add(new TextMenu.Button(Dialog.Clean("pico8_pause_quit")).Pressed(() =>
            {
                leaving    = true;
                gameActive = false;
                pauseMenu  = null;
                music(-1, 0, 0);

                new FadeWipe(this, false, () =>
                {
                    Audio.BusStopAll(Buses.GAMEPLAY, false);
                    Audio.PauseGameplaySfx = false;
                    Audio.EndSnapshot(snapshot);
                    Audio.Stop(bgSfx);
                    snapshot = null;
                    //返回关卡场景
                    if (ReturnTo != null)
                    {
                        if (ReturnTo is Level)
                        {
                            (ReturnTo as Level).Session.Audio.Apply();
                            new FadeWipe(ReturnTo, true);
                        }

                        Engine.Scene = ReturnTo;
                    }
                    //返回主菜单场景
                    else
                    {
                        Engine.Scene = new OverworldLoader(Overworld.StartMode.Titlescreen);
                    }
                });
            }));

            menu.OnCancel = menu.OnESC = menu.OnPause = () =>
            {
                Audio.PauseGameplaySfx = false;
                Audio.EndSnapshot(snapshot);
                snapshot = null;

                gameDelay  = 0.1f;
                pauseMenu  = null;
                gameActive = true;
                menu.RemoveSelf();
            };

            gameActive = false;
            pauseMenu  = menu;
        }