Example #1
0
        /// <summary>
        ///     Ctor -
        /// </summary>
        /// <param name="map"></param>
        /// <param name="md5"></param>
        /// <param name="scores"></param>
        /// <param name="replay"></param>
        public GameplayScreen(Qua map, string md5, List<Score> scores, Replay replay = null)
        {
            TimePlayed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            Map = map;
            LocalScores = scores;
            MapHash = md5;
            LoadedReplay = replay;

            Timing = new GameplayAudioTiming(this);

            // Remove paused modifier if enabled.
            if (ModManager.IsActivated(ModIdentifier.Paused))
                ModManager.RemoveMod(ModIdentifier.Paused);

            // Handle autoplay replays.
            if (ModManager.IsActivated(ModIdentifier.Autoplay))
                LoadedReplay = ReplayHelper.GeneratePerfectReplay(map, MapHash);

            // Determine if we're in replay mode.
            if (LoadedReplay != null)
            {
                InReplayMode = true;
                AddModsFromReplay();
            }

            // Create the current replay that will be captured.
            ReplayCapturer = new ReplayCapturer(this);

            SetRuleset();
            SetRichPresence();

            AudioTrack.AllowPlayback = true;
            View = new GameplayScreenView(this);
        }
Example #2
0
        /// <summary>
        ///     Ctor -
        /// </summary>
        /// <param name="map"></param>
        /// <param name="md5"></param>
        /// <param name="scores"></param>
        /// <param name="replay"></param>
        /// <param name="isPlayTesting"></param>
        /// <param name="playTestTime"></param>
        /// <param name="isCalibratingOffset"></param>
        public GameplayScreen(Qua map, string md5, List <Score> scores, Replay replay = null, bool isPlayTesting = false, double playTestTime = 0,
                              bool isCalibratingOffset = false)
        {
            TimePlayed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            if (isPlayTesting)
            {
                var testingQua = ObjectHelper.DeepClone(map);
                testingQua.HitObjects.RemoveAll(x => x.StartTime < playTestTime);

                Map = testingQua;
                OriginalEditorMap = map;
            }
            else
            {
                Map = map;
            }

            LocalScores         = scores;
            MapHash             = md5;
            LoadedReplay        = replay;
            IsPlayTesting       = isPlayTesting;
            PlayTestAudioTime   = playTestTime;
            IsCalibratingOffset = isCalibratingOffset;

            Timing = new GameplayAudioTiming(this);

            // Remove paused modifier if enabled.
            if (ModManager.IsActivated(ModIdentifier.Paused))
            {
                ModManager.RemoveMod(ModIdentifier.Paused);
            }

            // Handle autoplay replays.
            if (ModManager.IsActivated(ModIdentifier.Autoplay))
            {
                LoadedReplay = ReplayHelper.GeneratePerfectReplay(map, MapHash);
            }

            // Determine if we're in replay mode.
            if (LoadedReplay != null)
            {
                InReplayMode = true;
            }

            // Create the current replay that will be captured.
            ReplayCapturer = new ReplayCapturer(this);

            SetRuleset();
            SetRichPresence();

            AudioTrack.AllowPlayback = true;

            if (IsCalibratingOffset)
            {
                Metronome = new Metronome(map);
            }

            View = new GameplayScreenView(this);
        }
Example #3
0
        /// <summary>
        ///     Handles the input of the game + individual game modes.
        /// </summary>
        /// <param name="gameTime"></param>
        private void HandleInput(GameTime gameTime)
        {
            if (Exiting)
            {
                return;
            }

            var dt = gameTime.ElapsedGameTime.TotalMilliseconds;

            // Handle pausing
            if (!Failed && !IsPlayComplete)
            {
                HandlePauseInput(gameTime);
            }

            // Show/hide scoreboard.
            if (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyScoreboardVisible.Value))
            {
                ConfigManager.ScoreboardVisible.Value = !ConfigManager.ScoreboardVisible.Value;
            }

            // CTRL+ input while play testing
            if (IsPlayTesting && (KeyboardManager.CurrentState.IsKeyDown(Keys.LeftControl) ||
                                  KeyboardManager.CurrentState.IsKeyDown(Keys.RightControl)))
            {
                if (KeyboardManager.IsUniqueKeyPress(Keys.P))
                {
                    if (!AudioEngine.Track.IsDisposed)
                    {
                        if (AudioEngine.Track.IsPlaying)
                        {
                            AudioEngine.Track.Pause();
                            IsPaused = true;
                        }
                        else
                        {
                            AudioEngine.Track.Play();
                            IsPaused = false;
                        }
                    }
                }
            }

            // Handle the restarting of the map.
            HandlePlayRestart(dt);

            // Everything after this point is applicable to gameplay ONLY.
            if (IsPaused || Failed)
            {
                return;
            }

            if (!IsPlayComplete && !IsCalibratingOffset || IsMultiplayerGame)
            {
                if (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyQuickExit.Value))
                {
                    HandleQuickExit();
                }
            }

            if (!IsPlayComplete && !IsCalibratingOffset)
            {
                if (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeySkipIntro.Value))
                {
                    SkipToNextObject();
                }

                // Go back to editor at the same time
                if (IsPlayTesting && KeyboardManager.IsUniqueKeyPress(Keys.F2))
                {
                    if (AudioEngine.Track.IsPlaying)
                    {
                        AudioEngine.Track.Pause();
                    }

                    Exit(() => new EditorScreen(OriginalEditorMap));
                }

                // Handle play test autoplay input.
                if (IsPlayTesting && KeyboardManager.IsUniqueKeyPress(Keys.Tab))
                {
                    var inputManager = (KeysInputManager)Ruleset.InputManager;

                    if (LoadedReplay == null)
                    {
                        LoadedReplay = ReplayHelper.GeneratePerfectReplay(Map, MapHash);
                        inputManager.ReplayInputManager = new ReplayInputManagerKeys(this);
                        inputManager.ReplayInputManager.HandleSkip();
                        inputManager.ReplayInputManager.CurrentFrame++;
                    }

                    InReplayMode = !InReplayMode;
                    inputManager.ReplayInputManager.HandleSkip();
                    inputManager.ReplayInputManager.CurrentFrame++;

                    if (!InReplayMode)
                    {
                        for (var i = 0; i < Map.GetKeyCount(); i++)
                        {
                            inputManager.ReplayInputManager.UniquePresses[i]  = false;
                            inputManager.ReplayInputManager.UniqueReleases[i] = true;
                            inputManager.BindingStore[i].Pressed = false;

                            var playfield = (GameplayPlayfieldKeys)Ruleset.Playfield;
                            playfield.Stage.HitLightingObjects[i].StopHolding();
                            playfield.Stage.SetReceptorAndLightingActivity(i, inputManager.BindingStore[i].Pressed);
                        }

                        inputManager.HandleInput(gameTime.ElapsedGameTime.TotalMilliseconds);
                    }

                    NotificationManager.Show(NotificationLevel.Info, $"Autoplay has been turned {(InReplayMode ? "on" : "off")}");
                }

                // Only allow offset changes if the map hasn't started or if we're on a break
                if (Ruleset.Screen.Timing.Time <= 5000 || Ruleset.Screen.EligibleToSkip)
                {
                    var change = 5;
                    if (KeyboardManager.CurrentState.IsKeyDown(Keys.LeftControl) ||
                        KeyboardManager.CurrentState.IsKeyDown(Keys.RightControl))
                    {
                        change = 1;
                    }

                    // Handle offset +
                    if (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyIncreaseMapOffset.Value))
                    {
                        MapManager.Selected.Value.LocalOffset += change;
                        NotificationManager.Show(NotificationLevel.Success, $"Local map offset is now: {MapManager.Selected.Value.LocalOffset} ms");
                        MapDatabaseCache.UpdateMap(MapManager.Selected.Value);
                    }

                    // Handle offset -
                    if (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyDecreaseMapOffset.Value))
                    {
                        MapManager.Selected.Value.LocalOffset -= change;
                        NotificationManager.Show(NotificationLevel.Success, $"Local map offset is now: {MapManager.Selected.Value.LocalOffset} ms");
                        MapDatabaseCache.UpdateMap(MapManager.Selected.Value);
                    }
                }
            }

            // Handle input per game mode.
            Ruleset.HandleInput(gameTime);
        }
Example #4
0
        /// <summary>
        ///     Ctor -
        /// </summary>
        /// <param name="map"></param>
        /// <param name="md5"></param>
        /// <param name="scores"></param>
        /// <param name="replay"></param>
        /// <param name="isPlayTesting"></param>
        /// <param name="playTestTime"></param>
        /// <param name="isCalibratingOffset"></param>
        /// <param name="spectatorClient"></param>
        public GameplayScreen(Qua map, string md5, List <Score> scores, Replay replay = null, bool isPlayTesting = false, double playTestTime = 0,
                              bool isCalibratingOffset = false, SpectatorClient spectatorClient = null)
        {
            TimePlayed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            if (isPlayTesting)
            {
                var testingQua = ObjectHelper.DeepClone(map);
                testingQua.HitObjects.RemoveAll(x => x.StartTime < playTestTime);
                Qua.RestoreDefaultValues(testingQua);

                Map = testingQua;
                OriginalEditorMap = map;
            }
            else
            {
                Map = map;
            }

            LocalScores         = scores;
            MapHash             = md5;
            LoadedReplay        = replay;
            IsPlayTesting       = isPlayTesting;
            PlayTestAudioTime   = playTestTime;
            IsCalibratingOffset = isCalibratingOffset;
            IsMultiplayerGame   = OnlineManager.CurrentGame != null;
            SpectatorClient     = spectatorClient;

            if (SpectatorClient != null)
            {
                LoadedReplay = SpectatorClient.Replay;
            }

            if (IsMultiplayerGame)
            {
                OnlineManager.Client.OnUserJoinedGame    += OnUserJoinedGame;
                OnlineManager.Client.OnUserLeftGame      += OnUserLeftGame;
                OnlineManager.Client.OnAllPlayersLoaded  += OnAllPlayersLoaded;
                OnlineManager.Client.OnAllPlayersSkipped += OnAllPlayersSkipped;
            }

            Timing = new GameplayAudioTiming(this);

            // Initialize the custom audio sample cache and the sound effect index.
            if (!IsCalibratingOffset)
            {
                CustomAudioSampleCache.LoadSamples(MapManager.Selected.Value, MapHash);
            }

            NextSoundEffectIndex = 0;
            UpdateNextSoundEffectIndex();

            // Remove paused modifier if enabled.
            if (ModManager.IsActivated(ModIdentifier.Paused))
            {
                ModManager.RemoveMod(ModIdentifier.Paused);
            }

            // Handle autoplay replays.
            if (ModManager.IsActivated(ModIdentifier.Autoplay))
            {
                LoadedReplay = ReplayHelper.GeneratePerfectReplay(map, MapHash);
            }

            // Determine if we're in replay mode.
            if (LoadedReplay != null)
            {
                InReplayMode = true;
            }

            // Create the current replay that will be captured.
            ReplayCapturer = new ReplayCapturer(this);

            SetRuleset();
            SetRichPresence();

            AudioTrack.AllowPlayback = true;

            if (IsCalibratingOffset)
            {
                Metronome = new Metronome(map);
            }

            View = new GameplayScreenView(this);
        }