예제 #1
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyPress <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            this.Monitor.InterceptErrors("handling your input", $"handling input '{key}'", () =>
            {
                if (key.Equals(map.ToggleLookup))
                {
                    this.ToggleLookup(LookupMode.Cursor);
                }
                else if (key.Equals(map.ToggleLookupInFrontOfPlayer))
                {
                    this.ToggleLookup(LookupMode.FacingPlayer);
                }
                else if (key.Equals(map.ScrollUp))
                {
                    (Game1.activeClickableMenu as LookupMenu)?.ScrollUp();
                }
                else if (key.Equals(map.ScrollDown))
                {
                    (Game1.activeClickableMenu as LookupMenu)?.ScrollDown();
                }
                else if (key.Equals(map.ToggleDebug))
                {
                    this.DebugInterface.Enabled = !this.DebugInterface.Enabled;
                }
            });
        }
        /*********
        ** Private methods
        *********/
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyPress <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            this.Monitor.InterceptErrors("handling your input", $"handling input '{key}'", () =>
            {
                if (key.Equals(map.ToggleMap))
                {
                    if (this.CurrentOverlay != null)
                    {
                        this.CurrentOverlay.Dispose();
                        this.CurrentOverlay = null;
                    }
                    else
                    {
                        this.CurrentOverlay = new TraversableOverlay();
                    }

                    this.Monitor.Log($"set overlay: {this.CurrentOverlay?.GetType().Name ?? "none"}", LogLevel.Trace);
                }
            });
        }
예제 #3
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyPress <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            GameHelper.InterceptErrors("handling your input", $"handling input '{key}'", () =>
            {
                if (key.Equals(map.ToggleLookup))
                {
                    this.ToggleLookup();
                }
                if (key.Equals(map.ScrollUp))
                {
                    (Game1.activeClickableMenu as LookupMenu)?.ScrollUp(this.Config.ScrollAmount);
                }
                else if (key.Equals(map.ScrollDown))
                {
                    (Game1.activeClickableMenu as LookupMenu)?.ScrollDown(this.Config.ScrollAmount);
                }
                else if (key.Equals(map.ToggleDebug))
                {
                    this.DebugInterface.Enabled = !this.DebugInterface.Enabled;
                }
            });
        }
예제 #4
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TSButton"></typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        /// <returns>Returns whether the key was handled.</returns>
        private bool ReceiveKeyPress <TSButton>(TSButton key, InputMapConfiguration <TSButton> map)
        {
            if (!map.IsValidKey(key))
            {
                return(false);
            }

            // perform bound action
            try
            {
                if (key.Equals(map.SetToNothing))
                {
                    UnsetActiveItem();
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Monitor.Log($"Something went wrong handling input '{key}':\n{ex}", LogLevel.Error);
                Game1.addHUDMessage(new HUDMessage("Huh. Something went wrong handling your input. The error log has the technical details.", HUDMessage.error_type));
                return(true);
            }
        }
        /// <summary>The method invoked when the player presses a key.</summary>
        /// <typeparam name="T">The key type.</typeparam>
        /// <param name="input">The key that was pressed.</param>
        /// <param name="config">The input configuration.</param>
        /// <returns>Whether the key has been handled and shouldn't be propagated further.</returns>
        public bool ReceiveKey <T>(T input, InputMapConfiguration <T> config)
        {
            // ignore invalid input
            if (this.IsInitialising() || !config.IsValidKey(input))
            {
                return(false);
            }

            switch (this.ActiveElement)
            {
            case Element.Menu:
                if (input.Equals(config.Toggle) || input.Equals(Keys.Escape) || input.Equals(Buttons.B))
                {
                    this.Exit();
                }
                else if (input.Equals(config.PrevChest))
                {
                    this.SelectPreviousChest();
                }
                else if (input.Equals(config.NextChest))
                {
                    this.SelectNextChest();
                }
                else if (input.Equals(config.PrevCategory))
                {
                    this.SelectPreviousCategory();
                }
                else if (input.Equals(config.NextCategory))
                {
                    this.SelectNextCategory();
                }
                else if (input.Equals(config.EditChest))
                {
                    this.OpenEdit();
                }
                else if (input.Equals(config.SortItems))
                {
                    this.SortInventory();
                }
                else
                {
                    return(false);
                }
                return(true);

            case Element.ChestList:
            case Element.GroupList:
            case Element.EditForm:
                if (input.Equals(Keys.Escape) || input.Equals(Buttons.B))
                {
                    this.ActiveElement = Element.Menu;
                }
                return(true);

            default:
                return(false);
            }
        }
예제 #6
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void HandleInput <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            if (key.Equals(map.ToggleDebug))
            {
                this.DebugMode = !this.DebugMode;
            }
        }
예제 #7
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyRelease <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            GameHelper.InterceptErrors("handling your input", $"handling input '{key}'", () =>
            {
                if (key.Equals(map.ToggleLookup))
                {
                    this.HideLookup();
                }
            });
        }
예제 #8
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyRelease <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            this.Monitor.InterceptErrors("handling your input", $"handling input '{key}'", () =>
            {
                if (key.Equals(map.ToggleLookup) || key.Equals(map.ToggleLookupInFrontOfPlayer))
                {
                    this.PreviousMenus.Clear();
                    this.HideLookup();
                }
            });
        }
예제 #9
0
        /****
        ** Methods
        ****/
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyPress <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            if (!map.IsValidKey(key))
            {
                return;
            }

            // perform bound action
            this.Monitor.InterceptErrors("handling your input", $"handling input '{key}'", () =>
            {
                if (key.Equals(map.ShiftToNext))
                {
                    this.RotateToolbar(true, this.Config.DeselectItemOnRotate);
                }
                else if (key.Equals(map.ShiftToPrevious))
                {
                    this.RotateToolbar(false, this.Config.DeselectItemOnRotate);
                }
            });
        }
예제 #10
0
        /// <summary>The method invoked when the player presses an input button.</summary>
        /// <typeparam name="TKey">The input type.</typeparam>
        /// <param name="key">The pressed input.</param>
        /// <param name="map">The configured input mapping.</param>
        private void ReceiveKeyPress <TKey>(TKey key, InputMapConfiguration <TKey> map)
        {
            try
            {
                if (!map.IsValidKey(key))
                {
                    return;
                }

                // open menu
                if (key.Equals(map.Toggle) && (Game1.activeClickableMenu == null || (Game1.activeClickableMenu as GameMenu)?.currentTab == 0))
                {
                    this.OpenMenu();
                }
            }
            catch (Exception ex)
            {
                this.HandleError(ex, "handling key input");
            }
        }