/********* ** 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); } }
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; } } } }
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); } } }
// 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(); * } */ }
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); } }
/// <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); } }
public void ButtonPressed(object sender, EventArgsInput e) { if (Context.IsWorldReady) // save is loaded { this.coreMod.Monitor.Log($"{Game1.player.Name} pressed {e.Button}."); } }
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); } } } } } }
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); } } } }
/*** * 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); } } } }
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); } }
/// <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(); } } }
private void InputEvents_ButtonPressed(object sender, EventArgsInput e) { if (this.inited && this.OpenMenuHandler(e.IsActionButton)) { e.SuppressButton(); } }
/********* ** 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(); } } } }
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); } }
/// <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"); } }
private static void onKeyRelease(object sender, EventArgsInput args) { if (args.Button == Config.Key_Cast) { castPressed = false; } }
//handle key presses private void InputEvents_ButtonReleased(object sender, EventArgsInput e) { if (Context.IsWorldReady && e.Button == Config.ToggleAFKKey) { BroadcastEvent(new ToggleAFKStatus()); } }
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); } }
private void OnButtonPressed(object sender, EventArgsInput e) { if (this.IsBeingDragged && e.Button == SButton.MouseRight) { e.SuppressButton(); } }
/// <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; } }); }
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(); } }
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; } } } }); }
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); }
/// <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()); } }
/********* ** 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}"); } }
private void ButtonReleased(object sender, EventArgsInput e) { if (this.DoesMatchConfigKey(e.Button, this.config.HoverModifierKey) && this.config.ShowRangeOfHoveredOverItem) { this.isModifierKeyDown = false; RefreshRangeItems(Game1.currentLocation); } }