/*********
 ** Private methods
 *********/
 /// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (Context.IsWorldReady) // save is loaded
     {
         this.Monitor.Log($"{Game1.player.Name} pressed {e.Button}.", LogLevel.Debug);
     }
 }
예제 #2
0
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (Context.IsWorldReady && Game1.activeClickableMenu is GameMenu)
            {
                List <IClickableMenu> tabs   = this.Helper.Reflection.GetField <List <IClickableMenu> >(Game1.activeClickableMenu, "pages").GetValue();
                IClickableMenu        curTab = tabs[(Game1.activeClickableMenu as GameMenu).currentTab];

                if (curTab is SkillsPage && e.Button == SButton.S)
                {
                    if (!shouldDraw)
                    {
                        shouldDraw = true;
                    }
                    else
                    {
                        shouldDraw = false;
                    }
                }
                else if (curTab is SkillsPage && e.Button == SButton.MouseLeft)
                {
                    if (shouldDraw && Game1.getMouseY() >= curTab.yPositionOnScreen + (100 * skillIndex[0]) && Game1.getMouseY() <= curTab.yPositionOnScreen + (100 * skillIndex[0]) + 100)
                    {
                        shouldDraw2 = "th";
                        shouldDraw  = false;
                    }
                    else if (!shouldDraw && shouldDraw2 != "")
                    {
                        shouldDraw2 = "";
                        shouldDraw  = true;
                    }
                }
            }
        }
예제 #3
0
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            if (e.Button == config.key && Game1.player.addedSpeed >= 0)
            {
                IList <NPC> chars = Game1.player.currentLocation.getCharacters();
                NPC         minCh = null;

                float minDist = 100.0f;

                foreach (NPC ch in chars)
                {
                    float dist = Vector2.Distance(Game1.player.getTileLocation(), ch.getTileLocation());

                    if (minCh == null || dist < minDist)
                    {
                        minDist = dist;
                        minCh   = ch;
                    }
                }

                if (minCh != null && minDist < 2.0f)
                {
                    attemptPP(minCh);
                }
            }
        }
예제 #4
0
 // Handle opening mod menu and changing tooltip options
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (Context.IsWorldReady && Game1.activeClickableMenu is GameMenu)
     {
         HandleInput((GameMenu)Game1.activeClickableMenu, e.Button);
     }
 }
        private void PlayerInputEvent(object sender, EventArgsInput eventArguments)
        {
            if ((eventArguments.IsActionButton || eventArguments.IsUseToolButton))
            {
                if (Game1.player.ActiveObject != null && !(Game1.player.ActiveObject is Tool) && Game1.player.ActiveObject.Name.Contains("Sapling"))
                {
                    Vector2 plantingPosition = GetPlantingPosition();
                    if (!Game1.eventUp || Game1.isFestival())
                    {
                        if (Game1.tryToCheckAt(plantingPosition, Game1.player) || Game1.player.isRidingHorse() || !Game1.player.canMove)
                        {
                            return;
                        }
                        if (Game1.player.ActiveObject != null && !(Game1.player.ActiveObject is Furniture))
                        {
                            int positionToPlantX = (int)plantingPosition.X * Game1.tileSize + Game1.tileSize / 2;
                            int positionToPlantY = (int)plantingPosition.Y * Game1.tileSize + Game1.tileSize / 2;
                            TryToPlantTree(Game1.currentLocation, Game1.player.ActiveObject, positionToPlantX, positionToPlantY);
                        }
                    }
                }
            }

            /*
             * else if (eventArguments.Button == SButton.K)
             * {
             *  GrowTrees();
             * }
             */
        }
예제 #6
0
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (e.Button == (SButton)Keys.Escape)
            {
                Game1.playSound("bigDeSelect");
            }
            else
            {
                switch (_option)
                {
                case OptionsEnum.OpenReportKey:
                    _config.OpenReportKey = e.Button;
                    break;

                case OptionsEnum.OpenSettings:
                    _config.OpenSettings = e.Button;
                    break;

                case OptionsEnum.ToggleBubbles:
                    _config.ToggleBubbles = e.Button;
                    break;

                default:
                    throw new ArgumentOutOfRangeException($"Option {_option} is not possible on a InputListener.");
                }
                _buttonName = e.Button.ToString();
                Game1.playSound("coin");
            }
            _listening = false;
            InputEvents.ButtonPressed -= InputEvents_ButtonPressed;
            e.SuppressButton();
        }
 private void InputEvents_ButtonReleased(object sender, EventArgsInput e)
 {
     if (e.IsActionButton)
     {
         manager.SetActionButtonDownState(false);
     }
 }
예제 #8
0
        /// <summary>
        /// Handle the click event if it was on the fridge icon.
        /// </summary>
        /// <param name="eventArgsInput"></param>
        public void HandleClick(EventArgsInput eventArgsInput)
        {
            var chest = GetOpenChest();

            if (chest == null)
            {
                return;
            }

            var screenPixels = eventArgsInput.Cursor.ScreenPixels;

            if (!_fridgeSelected.containsPoint((int)screenPixels.X, (int)screenPixels.Y))
            {
                return;
            }

            Game1.playSound("smallSelect");

            if (Chests.Contains(chest))
            {
                Chests.Remove(chest);
            }
            else
            {
                Chests.Add(chest);
            }
        }
예제 #9
0
 public void ButtonPressed(object sender, EventArgsInput e)
 {
     if (Context.IsWorldReady)             // save is loaded
     {
         this.coreMod.Monitor.Log($"{Game1.player.Name} pressed {e.Button}.");
     }
 }
예제 #10
0
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (e.IsActionButton && Game1.currentLocation is GameLocation gl)
     {
         int     tilesize = Game1.tileSize * Game1.pixelZoom;
         Vector2 p        = new Vector2((int)(Game1.getOldMouseX() + Game1.viewport.X) / Game1.tileSize, (int)(Game1.getOldMouseY() + Game1.viewport.Y) / Game1.tileSize);
         if (gl.objects.ContainsKey(p) && gl.objects[p].name.Contains("Sprinkler"))
         {
             if (Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift))
             {
                 gl.objects[p].DayUpdate(Game1.currentLocation);
             }
             else
             {
                 foreach (SObject v in gl.objects.Values)
                 {
                     if (v.name.Contains("Sprinkler"))
                     {
                         v.DayUpdate(gl);
                     }
                 }
             }
         }
     }
 }
예제 #11
0
        private void CheckAction(object sender, EventArgsInput e)
        {
            if (Context.IsPlayerFree && e.IsActionButton)
            {
                Vector2 grabTile = new Vector2((float)(Game1.getOldMouseX() + Game1.viewport.X), (float)(Game1.getOldMouseY() + Game1.viewport.Y)) / (float)Game1.tileSize;
                if (!Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player))
                {
                    grabTile = Game1.player.GetGrabTile();
                }
                Tile tile = Game1.currentLocation.map.GetLayer("Buildings").PickTile(new xTile.Dimensions.Location((int)grabTile.X * Game1.tileSize, (int)grabTile.Y * Game1.tileSize), Game1.viewport.Size);
                xTile.ObjectModel.PropertyValue propertyValue = null;
                if (tile != null)
                {
                    tile.Properties.TryGetValue("Action", out propertyValue);
                }
                if (propertyValue != null)
                {
                    if (propertyValue == "TokenMachine")
                    {
                        Response   basic   = new Response("Basic", $"Basic Tier ({Config.basicBoxCost} Tokens)");
                        Response   premium = new Response("Premium", $"Premium Tier ({Config.premiumBoxCost} Tokens)");
                        Response   cancel  = new Response("Cancel", "Cancel");
                        Response[] answers = { basic, premium, cancel, };

                        Game1.player.currentLocation.createQuestionDialogue($"Would you like to spend your tokens to receive a random item? You currently have {totalTokens} tokens.", answers, AfterQuestion, null);
                    }
                }
            }
        }
예제 #12
0
        /***
         * The next four methods mimic the game's codepath when an action button is pressed,
         * but place a sapling if a sapling could not be placed due to it being too close to another tree.
         ***/
        private void ButtonPressed(object sender, EventArgsInput e)
        {
            if ((e.IsActionButton || e.IsUseToolButton) && Game1.player.ActiveObject != null && Game1.player.ActiveObject.name.Contains("Sapling"))
            {
                Vector2 vector2 = GetMouseTile();

                if (!Game1.eventUp || Game1.isFestival())
                {
                    if (Game1.tryToCheckAt(vector2, Game1.player))
                    {
                        return;
                    }
                    if (Game1.player.isRidingHorse())
                    {
                        Game1.player.getMount().checkAction(Game1.player, Game1.player.currentLocation);
                        return;
                    }
                    if (!Game1.player.canMove)
                    {
                        return;
                    }
                    if (Game1.player.ActiveObject != null && !(Game1.player.ActiveObject is Furniture))
                    {
                        int stack = Game1.player.ActiveObject.Stack;
                        TryToPlaceSapling(Game1.currentLocation, (Item)Game1.player.ActiveObject, (int)vector2.X * Game1.tileSize + Game1.tileSize / 2, (int)vector2.Y * Game1.tileSize + Game1.tileSize / 2);
                    }
                }
            }
        }
예제 #13
0
        private void ButtonPressed(object sender, EventArgsInput e)
        {
            if (DoesMatchConfigKey(e.Button, this.config.CycleActiveDisplayKey))
            {
                if (this.displayIndex == this.allRangeItems.Length - 1)
                {
                    this.displayIndex++;
                    this.displayManager.DisplayAll(true);
                    this.hudMessageManager.AddHudMessage("All");
                    return;
                }
                else if (this.displayIndex == this.allRangeItems.Length)
                {
                    this.displayIndex++;
                    this.displayManager.DisplayAll(false);
                    this.hudMessageManager.AddHudMessage("None");
                    return;
                }

                if (this.displayIndex == this.allRangeItems.Length + 1)
                {
                    this.displayIndex = -1;
                }
                this.displayIndex = (this.displayIndex + 1) % this.allRangeItems.Length;
                this.displayManager.DisplayOnly(this.allRangeItems[this.displayIndex]);
                this.hudMessageManager.AddHudMessage(this.allRangeItems[this.displayIndex]);
            }
            else if (DoesMatchConfigKey(e.Button, this.config.HoverModifierKey) && this.config.ShowRangeOfHoveredOverItem)
            {
                this.isModifierKeyDown = true;
                RefreshRangeItems(Game1.currentLocation);
            }
        }
예제 #14
0
 /// <summary>The event called when the player presses a keyboard button.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (e.Button == _config.ToggleInstantBuildMenuButton && Game1.currentLocation is Farm)
     {
         if (Context.IsPlayerFree && Game1.activeClickableMenu == null)
         {
             if (_tractorModFound)
             {
                 //Get tractor blueprint from carpenter menu
                 var carpenterMenu = new CarpenterMenu();
                 Game1.activeClickableMenu = (IClickableMenu)carpenterMenu;
                 Game1.delayedActions.Add(new DelayedAction(100, new DelayedAction.delayedBehavior(this.getTractorBlueprintFromCarpenterMenu)));
             }
             else
             {
                 activateInstantBuildMenu();
             }
         }
         else if (Game1.activeClickableMenu is InstantBuildMenu)
         {
             Game1.displayFarmer = true;
             ((InstantBuildMenu)Game1.activeClickableMenu).exitThisMenu();
         }
     }
 }
예제 #15
0
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (this.inited && this.OpenMenuHandler(e.IsActionButton))
     {
         e.SuppressButton();
     }
 }
예제 #16
0
        /*********
        ** Private methods
        *********/
        /****
        ** Event handlers
        ****/
        /// <summary>The method invoked when the player presses a button.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (this.Config.EnableDebugFeatures)
            {
                // toggle overlay
                if (this.Config.Controls.ToggleDebug.Contains(e.Button))
                {
                    if (this.DebugOverlay == null)
                    {
                        this.DebugOverlay = new DebugOverlay(this.Helper.Content);
                    }
                    else
                    {
                        this.DebugOverlay.Dispose();
                        this.DebugOverlay = null;
                    }
                    return;
                }

                // cycle textures
                if (this.DebugOverlay != null)
                {
                    if (this.Config.Controls.DebugPrevTexture.Contains(e.Button))
                    {
                        this.DebugOverlay.PrevTexture();
                    }
                    if (this.Config.Controls.DebugNextTexture.Contains(e.Button))
                    {
                        this.DebugOverlay.NextTexture();
                    }
                }
            }
        }
예제 #17
0
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            if (Game1.player.CurrentTool is Wand && e.Button == SButton.MouseRight)
            {
                int power = (int)(((double)Game1.toolHold + 20.0) / 600.0) + 1;

                foreach (Farmer farmer in Game1.getOnlineFarmers())
                {
                    if (farmer.Name != Game1.player.Name)
                    {
                        /*this.Monitor.Log(farmer.Name);
                         * this.Monitor.Log(power.ToString());
                         * this.Monitor.Log(farmer.currentLocation.ToString());
                         * Game1.player.CurrentTool.DoFunction(farmer.currentLocation, farmer.getStandingX(), farmer.getStandingY(), 45, farmer);*/
                        farmer.warpFarmer(new Warp(farmer.getStandingX(), farmer.getStandingY(), "Farm", 64, 15, false));
                    }
                }
                //Game1.player.CurrentTool.DoFunction(Game1.player.currentLocation, Game1.player.getStandingX(), Game1.player.getStandingY(), 45, Game1.player);

                //Game1.warpFarmer("Farm", 64, 15, false);
                //int power = (int)(((double)Game1.toolHold + 20.0) / 600.0) + 1;
                //Game1.player.CurrentTool.DoFunction(Game1.currentLocation, Game1.player.getStandingX(), Game1.player.getStandingY(), power, Game1.player);
            }
        }
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (e.IsActionButton)
     {
         this.manager.SetActionButtonDownState(true);
     }
 }
예제 #19
0
        /// <summary>The method invoked when the player presses a button.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            try
            {
                var controls = this.Config.Controls;

                // open menu
                if (controls.Toggle.Contains(e.Button))
                {
                    // open if no conflict
                    if (Game1.activeClickableMenu == null)
                    {
                        this.OpenMenu();
                    }

                    // open from inventory if it's safe to close the inventory screen
                    else if (Game1.activeClickableMenu is GameMenu gameMenu && gameMenu.currentTab == GameMenu.inventoryTab)
                    {
                        IClickableMenu inventoryPage = this.Helper.Reflection.GetField <List <IClickableMenu> >(gameMenu, "pages").GetValue()[GameMenu.inventoryTab];
                        if (inventoryPage.readyToClose())
                        {
                            this.OpenMenu();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandleError(ex, "handling key input");
            }
        }
예제 #20
0
 private static void onKeyRelease(object sender, EventArgsInput args)
 {
     if (args.Button == Config.Key_Cast)
     {
         castPressed = false;
     }
 }
예제 #21
0
 //handle key presses
 private void InputEvents_ButtonReleased(object sender, EventArgsInput e)
 {
     if (Context.IsWorldReady && e.Button == Config.ToggleAFKKey)
     {
         BroadcastEvent(new ToggleAFKStatus());
     }
 }
예제 #22
0
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            // TODO: remove ControllerA check once IsActionButton works for gamepads. https://github.com/Pathoschild/SMAPI/issues/416
            if (e.IsActionButton || e.Button == SButton.ControllerA)
            {
                const int controllerOffset = 2000;
                bool      isGamepad        = (int)e.Button > controllerOffset;
                this.CurrentInputContext = isGamepad ? (IInputContext)GamepadInputContext.DefaultContext : MouseInputContext.DefaultContext;
                this.CurrentInputContext.CursorPosition = e.Cursor;

                if (this.ActionManager.CanCheckForAction())
                {
                    this.ActionManager.CheckForAction(this.CurrentInputContext);
                }
            }
            else if (e.Button.Equals(SButton.F7))
            {
                Game1.warpFarmer(BathhouseLocationName, 27, 30, false);
            }
        }
예제 #23
0
 private void OnButtonPressed(object sender, EventArgsInput e)
 {
     if (this.IsBeingDragged && e.Button == SButton.MouseRight)
     {
         e.SuppressButton();
     }
 }
예제 #24
0
        /// <summary>The method invoked when the player presses a button.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            // perform bound action
            this.Monitor.InterceptErrors("handling your input", $"handling input '{e.Button}'", () =>
            {
                var controls = this.Config.Controls;

                if (controls.ToggleLookup.Contains(e.Button))
                {
                    this.ToggleLookup(LookupMode.Cursor);
                }
                else if (controls.ToggleLookupInFrontOfPlayer.Contains(e.Button))
                {
                    this.ToggleLookup(LookupMode.FacingPlayer);
                }
                else if (controls.ScrollUp.Contains(e.Button))
                {
                    (Game1.activeClickableMenu as LookupMenu)?.ScrollUp();
                }
                else if (controls.ScrollDown.Contains(e.Button))
                {
                    (Game1.activeClickableMenu as LookupMenu)?.ScrollDown();
                }
                else if (controls.ToggleDebug.Contains(e.Button))
                {
                    this.DebugInterface.Enabled = !this.DebugInterface.Enabled;
                }
            });
        }
예제 #25
0
 private void InputEvents_ButtonReleased(object s, EventArgsInput e)
 {
     if ((!Game1.eventUp || Game1.currentLocation.currentEvent != null && Game1.currentLocation.currentEvent.showActiveObject) && !Game1.player.FarmerSprite.pauseForSingleAnimation && !Game1.player.isRidingHorse() && !Game1.player.bathingClothes.Value && e.Button == SButton.MouseRight)
     {
         (Game1.player.CurrentItem as Book)?.Activate();
     }
 }
예제 #26
0
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            this.Monitor.InterceptErrors("handling your input", $"handling input '{e.Button}'", () => {
                if (e.IsUseToolButton && IsEnabled())
                {
                    switch (Game1.activeClickableMenu)
                    {
                    case GameMenu menu: {
                        List <IClickableMenu> pages = this.Helper.Reflection.GetField <List <IClickableMenu> >(menu, "pages").GetValue();
                        CraftingPage craftingPage   = pages[menu.currentTab] as CraftingPage;
                        if (craftingPage == null)
                        {
                            return;
                        }

                        CraftingRecipe recipe = this.Helper.Reflection.GetField <CraftingRecipe>(craftingPage, "hoverRecipe").GetValue();
                        if (recipe == null)
                        {
                            return;
                        }

                        int repeat    = this.Is5x() ? 5 : 1;
                        bool didCraft = false;
                        while (repeat-- > 0 && recipe.doesFarmerHaveIngredientsInInventory())
                        {
                            Item item = recipe.createItem();
                            if (!Game1.player.couldInventoryAcceptThisItem(item))
                            {
                                break;
                            }
                            recipe.consumeIngredients();
                            Game1.player.addItemToInventory(item);
                            didCraft = true;
                        }

                        if (didCraft)
                        {
                            Game1.playSound("Ship");
                        }

                        e.SuppressButton();
                        break;
                    }

                    case ShopMenu menu: {
                        int repeat = this.Is5x() ? 500 : 100;
                        BuyHoveredItem(menu, repeat, Game1.getMousePosition());
                        e.SuppressButton();
                        break;
                    }
                    }
                }
            });
        }
예제 #27
0
        public virtual bool ButtonPressed(EventArgsInput e)
        {
            if (this.CurrentModal != null)
            {
                return(this.CurrentModal.ButtonPressed(e));
            }

            bool clicked = false;

            if (e.IsUseToolButton)
            {
                foreach (IClickable clickable in this.drawables.OfType <IClickable>())
                {
                    if (clickable.Bounds.Contains((int)e.Cursor.ScreenPixels.X, (int)e.Cursor.ScreenPixels.Y))
                    {
                        clickable.Clicked();
                        clicked = true;
                    }
                }

                foreach (IDrawable drawable in this.drawables)
                {
                    switch (drawable)
                    {
                    case IClickable clickable:
                        if (clickable.Bounds.Contains((int)e.Cursor.ScreenPixels.X, (int)e.Cursor.ScreenPixels.Y))
                        {
                            clickable.Clicked();
                            clicked = true;
                        }
                        break;

                    case ConditionalElement conditional:
                        if (conditional.GetElementForHighlight() is IClickable condClickable)
                        {
                            if (condClickable.Bounds.Contains((int)e.Cursor.ScreenPixels.X, (int)e.Cursor.ScreenPixels.Y))
                            {
                                condClickable.Clicked();
                                clicked = true;
                            }
                        }
                        break;

                    case ElementContainer container:
                        foreach (IClickable clickable in container.Elements.OfType <IClickable>())
                        {
                            if (clickable.Bounds.Contains((int)e.Cursor.ScreenPixels.X, (int)e.Cursor.ScreenPixels.Y))
                            {
                                clickable.Clicked();
                                clicked = true;
                            }
                        }
                        break;
                    }
                }
            }

            return(clicked);
        }
예제 #28
0
 /// <summary>The event called when the player presses a keyboard button.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     // summon tractor
     if (this.Config.Controls.SummonTractor.Contains(e.Button))
     {
         this.Tractor?.SetLocation(Game1.currentLocation, Game1.player.getTileLocation());
     }
 }
예제 #29
0
 /*********
 ** Private methods
 *********/
 /// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
 {
     if (Context.IsWorldReady) // save is loaded
     {
         // this.Monitor.Log($"Save ID: {Game1.uniqueIDForThisGame}");
         // this.Monitor.Log($"Seed: {seed}");
     }
 }
예제 #30
0
 private void ButtonReleased(object sender, EventArgsInput e)
 {
     if (this.DoesMatchConfigKey(e.Button, this.config.HoverModifierKey) && this.config.ShowRangeOfHoveredOverItem)
     {
         this.isModifierKeyDown = false;
         RefreshRangeItems(Game1.currentLocation);
     }
 }