Exemplo n.º 1
0
        public bool HandleKeyPress(KeyInput e)
        {
            if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
            {
                var h = Hotkey.FromKeyInput(e);
                if (h == combinedViewKey.GetValue() && !limitViews)
                {
                    selected = combined;
                    selected.OnClick();

                    return(true);
                }

                if (h == worldViewKey.GetValue() && !limitViews)
                {
                    selected = disableShroud;
                    selected.OnClick();

                    return(true);
                }

                if (e.Key >= Keycode.NUMBER_0 && e.Key <= Keycode.NUMBER_9)
                {
                    var key  = (int)e.Key - (int)Keycode.NUMBER_0;
                    var team = teams.Where(t => t.Key == key).SelectMany(s => s);
                    if (!team.Any())
                    {
                        return(false);
                    }

                    if (e.Modifiers == Modifiers.Shift)
                    {
                        team = team.Reverse();
                    }

                    selected = team.SkipWhile(t => t.Player != selected.Player).Skip(1).FirstOrDefault() ?? team.FirstOrDefault();
                    selected.OnClick();

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public override bool HandleKeyPress(KeyInput e)
        {
            if (Hotkey.FromKeyInput(e) != Key.GetValue() || e.Event != KeyInputEvent.Down || (DisableKeyRepeat && e.IsRepeat))
            {
                return(false);
            }

            if (!IsDisabled())
            {
                OnKeyPress(e);
                if (!DisableKeySound)
                {
                    Game.Sound.PlayNotification(ModRules, null, "Sounds", "ClickSound", null);
                }
            }
            else if (!DisableKeySound)
            {
                Game.Sound.PlayNotification(ModRules, null, "Sounds", "ClickDisabledSound", null);
            }

            return(true);
        }
Exemplo n.º 3
0
        public override bool HandleKeyPress(KeyInput e)
        {
            if (e.Event != KeyInputEvent.Down)
            {
                return(false);
            }

            var hotkey = Hotkey.FromKeyInput(e);

            if (hotkey == PreviousProductionTabKey.GetValue())
            {
                Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ClickSound", null);
                return(SelectNextTab(true));
            }

            if (hotkey == NextProductionTabKey.GetValue())
            {
                Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ClickSound", null);
                return(SelectNextTab(false));
            }

            return(false);
        }
Exemplo n.º 4
0
        public override bool HandleKeyPress(KeyInput e)
        {
            var key = Hotkey.FromKeyInput(e);

            Func <NamedHotkey, ScrollDirection, bool> handleMapScrollKey = (hotkey, scrollDirection) =>
            {
                var isHotkey = false;
                var keyValue = hotkey.GetValue();
                if (key.Key == keyValue.Key)
                {
                    isHotkey           = key == keyValue;
                    keyboardDirections = keyboardDirections.Set(scrollDirection, e.Event == KeyInputEvent.Down && (isHotkey || keyValue.Modifiers == Modifiers.None));
                }

                return(isHotkey);
            };

            if (handleMapScrollKey(ScrollUpKey, ScrollDirection.Up) || handleMapScrollKey(ScrollDownKey, ScrollDirection.Down) ||
                handleMapScrollKey(ScrollLeftKey, ScrollDirection.Left) || handleMapScrollKey(ScrollRightKey, ScrollDirection.Right))
            {
                return(true);
            }

            if (e.Event != KeyInputEvent.Down)
            {
                return(false);
            }

            if (key == JumpToTopEdgeKey.GetValue())
            {
                worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, 0, 0));
                return(true);
            }

            if (key == JumpToBottomEdgeKey.GetValue())
            {
                worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, worldRenderer.World.Map.ProjectedBottomRight.Y, 0));
                return(true);
            }

            if (key == JumpToLeftEdgeKey.GetValue())
            {
                worldRenderer.Viewport.Center(new WPos(0, worldRenderer.Viewport.CenterPosition.Y, 0));
                return(true);
            }

            if (key == JumpToRightEdgeKey.GetValue())
            {
                worldRenderer.Viewport.Center(new WPos(worldRenderer.World.Map.ProjectedBottomRight.X, worldRenderer.Viewport.CenterPosition.Y, 0));
                return(true);
            }

            for (var i = 0; i < saveBookmarkHotkeys.Length; i++)
            {
                if (key == saveBookmarkHotkeys[i].GetValue())
                {
                    bookmarkPositions[i] = worldRenderer.Viewport.CenterPosition;
                    return(true);
                }
            }

            for (var i = 0; i < restoreBookmarkHotkeys.Length; i++)
            {
                if (key == restoreBookmarkHotkeys[i].GetValue())
                {
                    var bookmark = bookmarkPositions[i];
                    if (bookmark.HasValue)
                    {
                        worldRenderer.Viewport.Center(bookmark.Value);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public override bool HandleKeyPress(KeyInput e)
        {
            var player = World.RenderPlayer ?? World.LocalPlayer;

            if (e.Event == KeyInputEvent.Down)
            {
                var key = Hotkey.FromKeyInput(e);

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

                    // Check if selecting actors on the screen has selected new units
                    if (ownUnitsOnScreen.Count > World.Selection.Actors.Count())
                    {
                        Game.AddChatLine(Color.White, "Battlefield Control", "Selected across screen");
                    }
                    else
                    {
                        // Select actors in the world that have highest selection priority
                        ownUnitsOnScreen = SelectActorsInWorld(World, null, player).SubsetWithHighestSelectionPriority().ToList();
                        Game.AddChatLine(Color.White, "Battlefield Control", "Selected across map");
                    }

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

                    // Get all the selected actors' selection classes
                    var selectedClasses = World.Selection.Actors
                                          .Where(x => !x.IsDead && x.Owner == player)
                                          .Select(a => a.Trait <Selectable>().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, player).ToList();

                    // Check if selecting actors on the screen has selected new units
                    if (newSelection.Count > World.Selection.Actors.Count())
                    {
                        Game.AddChatLine(Color.White, "Battlefield Control", "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, player).ToList();
                        Game.AddChatLine(Color.White, "Battlefield Control", "Selected across map");
                    }

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

            return(false);
        }