Exemplo n.º 1
0
        /// <summary>
        ///     Handles the input of the game + individual game modes.
        /// </summary>
        /// <param name="gameTime"></param>
        private void HandleInput(GameTime gameTime)
        {
            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;

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

            if (!IsPlayComplete)
            {
                // Handle the restarting of the map.
                HandlePlayRestart(dt);

                if (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeySkipIntro.Value))
                    SkipToNextObject();

                // 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)
                {
                    // Handle offset +
                    if (KeyboardManager.IsUniqueKeyPress(Keys.OemPlus))
                    {
                        MapManager.Selected.Value.LocalOffset += 5;
                        NotificationManager.Show(NotificationLevel.Success, $"Local map offset is now: {MapManager.Selected.Value.LocalOffset}ms");
                        MapDatabaseCache.UpdateMap(MapManager.Selected.Value);
                    }

                    // Handle offset -
                    if (KeyboardManager.IsUniqueKeyPress(Keys.OemMinus))
                    {
                        MapManager.Selected.Value.LocalOffset -= 5;
                        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);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Does a recalculation for the difficulties on outdated maps.
        /// </summary>
        public static void RecalculateDifficultiesForOutdatedMaps()
        {
            foreach (var map in OutdatedMaps)
            {
                map.DifficultyProcessorVersion = DifficultyProcessorKeys.Version;

                try
                {
                    map.CalculateDifficulties();
                    MapDatabaseCache.UpdateMap(map);
                }
                catch (Exception e)
                {
                    new SQLiteConnection(DatabasePath).Delete(map);
                }
            }

            OutdatedMaps.Clear();
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Creates the local and global offset fix buttons.
        /// </summary>
        private void CreateOffsetFixButtons()
        {
            // Don't draw the buttons if we don't have the hit stats (and therefore don't know the
            // values to adjust the offset by).
            if (Processor.Stats == null)
            {
                return;
            }

            var availableWidth = Width - VerticalDividerLine.X;
            var buttonPadding  = 15;
            var buttonWidth    = (availableWidth - buttonPadding * 3) / 2;

            var localOffsetButton = new BorderedTextButton("Fix Local Offset", Colors.MainAccent,
                                                           (o, e) =>
            {
                // Local offset is scaled with rate, so the adjustment depends on the rate the
                // score was played on.
                var change    = HitStatistics.Mean * ModHelper.GetRateFromMods(Processor.Mods);
                var newOffset = (int)Math.Round(ResultScreen.Map.LocalOffset - change);

                DialogManager.Show(new ConfirmCancelDialog($"Local offset will be changed from {ResultScreen.Map.LocalOffset} ms to {newOffset} ms.",
                                                           (o_, e_) =>
                {
                    ResultScreen.Map.LocalOffset = newOffset;
                    MapDatabaseCache.UpdateMap(ResultScreen.Map);
                    NotificationManager.Show(NotificationLevel.Success, $"Local offset was set to {ResultScreen.Map.LocalOffset} ms.");
                }));
            })
            {
                Parent = this,
                X      = VerticalDividerLine.X + buttonPadding,
                Y      = BottomHorizontalDividerLine.Y - 15 - 25,
                Height = 30,
                Width  = buttonWidth,
                Text   =
                {
                    Font     = Fonts.SourceSansProSemiBold,
                    FontSize = 13
                }
            };
            var globalOffsetButton = new BorderedTextButton("Fix Global Offset", Colors.MainAccent,
                                                            (o, e) =>
            {
                var newOffset = (int)Math.Round(ConfigManager.GlobalAudioOffset.Value + HitStatistics.Mean);

                DialogManager.Show(new ConfirmCancelDialog($"Global offset will be changed from {ConfigManager.GlobalAudioOffset.Value} ms to {newOffset} ms.",
                                                           (o_, e_) =>
                {
                    ConfigManager.GlobalAudioOffset.Value = newOffset;
                    NotificationManager.Show(NotificationLevel.Success, $"Global offset was set to {ConfigManager.GlobalAudioOffset.Value} ms.");
                }));
            })
            {
                Parent = this,
                X      = localOffsetButton.X + localOffsetButton.Width + buttonPadding,
                Y      = BottomHorizontalDividerLine.Y - 15 - 25,
                Height = 30,
                Width  = buttonWidth,
                Text   =
                {
                    Font     = Fonts.SourceSansProSemiBold,
                    FontSize = 13
                }
            };
        }
Exemplo n.º 4
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);
        }