protected override bool OnHotkeyActivated(KeyInput e)
        {
            Game.Settings.Sound.Mute ^= true;

            if (Game.Settings.Sound.Mute)
            {
                Game.Sound.MuteAudio();
                TextNotificationsManager.AddFeedbackLine("Audio muted.");
            }
            else
            {
                Game.Sound.UnmuteAudio();
                TextNotificationsManager.AddFeedbackLine("Audio unmuted.");
            }

            return(true);
        }
        protected override bool OnHotkeyActivated(KeyInput e)
        {
            if (world.IsGameOver)
            {
                return(false);
            }

            var eligiblePlayers = SelectionUtils.GetPlayersToIncludeInSelection(world);

            // Select actors on the screen which belong to the current player(s)
            var newSelection = SelectionUtils.SelectActorsOnScreen(world, worldRenderer, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();

            // Check if selecting actors on the screen has selected new units
            if (newSelection.Count > selection.Actors.Count())
            {
                if (newSelection.Count > 1)
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected {newSelection.Count} units across screen.");
                }
                else
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected one unit across screen.");
                }
            }
            else
            {
                // Select actors in the world that have highest selection priority
                newSelection = SelectionUtils.SelectActorsInWorld(world, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();

                if (newSelection.Count > 1)
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected {newSelection.Count} units across map.");
                }
                else
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected one unit across map.");
                }
            }

            selection.Combine(world, newSelection, false, false);

            Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickSound, null);

            return(true);
        }
Beispiel #3
0
        public override bool HandleKeyPress(KeyInput e)
        {
            if (e.Event == KeyInputEvent.Down)
            {
                // Players to be included in the selection (the viewer or all players in "Disable shroud" / "All players" mode)
                var viewer           = World.RenderPlayer ?? World.LocalPlayer;
                var isShroudDisabled = viewer == null || (World.RenderPlayer == null && World.LocalPlayer.Spectating);
                var isEveryone       = viewer != null && viewer.NonCombatant && viewer.Spectating;
                var eligiblePlayers  = isShroudDisabled || isEveryone ? World.Players : new[] { viewer };

                if (SelectAllKey.IsActivatedBy(e) && !World.IsGameOver)
                {
                    // Select actors on the screen which belong to the current player(s)
                    var ownUnitsOnScreen = SelectActorsOnScreen(World, worldRenderer, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();

                    // Check if selecting actors on the screen has selected new units
                    if (ownUnitsOnScreen.Count > World.Selection.Actors.Count())
                    {
                        TextNotificationsManager.AddFeedbackLine("Selected across screen");
                    }
                    else
                    {
                        // Select actors in the world that have highest selection priority
                        ownUnitsOnScreen = SelectActorsInWorld(World, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();
                        TextNotificationsManager.AddFeedbackLine("Selected across map");
                    }

                    World.Selection.Combine(World, ownUnitsOnScreen, false, false);
                }
                else if (SelectSameTypeKey.IsActivatedBy(e) && !World.IsGameOver)
                {
                    if (!World.Selection.Actors.Any())
                    {
                        return(false);
                    }

                    var ownedActors = World.Selection.Actors
                                      .Where(x => !x.IsDead && eligiblePlayers.Contains(x.Owner))
                                      .ToList();

                    if (!ownedActors.Any())
                    {
                        return(false);
                    }

                    // Get all the selected actors' selection classes
                    var selectedClasses = ownedActors
                                          .Select(a => a.Trait <ISelectable>().Class)
                                          .ToHashSet();

                    // Select actors on the screen that have the same selection class as one of the already selected actors
                    var newSelection = SelectActorsOnScreen(World, worldRenderer, selectedClasses, eligiblePlayers).ToList();

                    // Check if selecting actors on the screen has selected new units
                    if (newSelection.Count > World.Selection.Actors.Count())
                    {
                        TextNotificationsManager.AddFeedbackLine("Selected across screen");
                    }
                    else
                    {
                        // Select actors in the world that have the same selection class as one of the already selected actors
                        newSelection = SelectActorsInWorld(World, selectedClasses, eligiblePlayers).ToList();
                        TextNotificationsManager.AddFeedbackLine("Selected across map");
                    }

                    World.Selection.Combine(World, newSelection, true, false);
                }
            }

            return(false);
        }
        protected override bool OnHotkeyActivated(KeyInput e)
        {
            if (world.IsGameOver)
            {
                return(false);
            }

            if (!selection.Actors.Any())
            {
                TextNotificationsManager.AddFeedbackLine("Nothing selected.");
                Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickDisabledSound, null);

                return(false);
            }

            var eligiblePlayers = SelectionUtils.GetPlayersToIncludeInSelection(world);

            var ownedActors = selection.Actors
                              .Where(x => !x.IsDead && eligiblePlayers.Contains(x.Owner))
                              .ToList();

            if (!ownedActors.Any())
            {
                return(false);
            }

            // Get all the selected actors' selection classes
            var selectedClasses = ownedActors
                                  .Select(a => a.Trait <ISelectable>().Class)
                                  .ToHashSet();

            // Select actors on the screen that have the same selection class as one of the already selected actors
            var newSelection = SelectionUtils.SelectActorsOnScreen(world, worldRenderer, selectedClasses, eligiblePlayers).ToList();

            // Check if selecting actors on the screen has selected new units
            if (newSelection.Count > selection.Actors.Count())
            {
                if (newSelection.Count > 1)
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected {newSelection.Count} units across screen.");
                }
                else
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected one unit across screen.");
                }
            }
            else
            {
                // Select actors in the world that have the same selection class as one of the already selected actors
                newSelection = SelectionUtils.SelectActorsInWorld(world, selectedClasses, eligiblePlayers).ToList();

                if (newSelection.Count > 1)
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected {newSelection.Count} units across map.");
                }
                else
                {
                    TextNotificationsManager.AddFeedbackLine($"Selected one unit across map.");
                }
            }

            selection.Combine(world, newSelection, true, false);

            Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickSound, null);

            return(true);
        }