private void onButtonPressed(object _sender, ButtonPressedEventArgs e) { // Only respond if the TV and the world are ready and the player is // free to interact with a TV. if (tv == null || !Context.IsWorldReady || !Context.IsPlayerFree || Game1.player.UsingTool || Game1.IsChatting) { return; } // On any platform, accept the configured keybinding if a Portable // TV is in inventory. if (e.Button == Config.ActivateKey) { if (!Game1.player.hasItemInInventory(parentSheetIndex, 1)) { return; } } // On Android, must be tapping in the world while the Portable TV // is the current item. else if (Constants.TargetPlatform == GamePlatform.Android) { if (e.Button != SButton.MouseLeft) { return; } int x = (int)e.Cursor.ScreenPixels.X; int y = (int)e.Cursor.ScreenPixels.Y; // Allow a fixed area for the right-edge HUD elements. if (x > Game1.viewport.Width - 80) { return; } this.toolbar.TryGetTarget(out Toolbar toolbar); if (toolbar?.isWithinBounds(x, y) ?? false) { return; } if (!Utility.IsNormalObjectAtParentSheetIndex (Game1.player.CurrentItem, parentSheetIndex)) { return; } } else { // On Linux/Mac/Windows, only respond to the use button. if (!e.Button.IsActionButton()) { return; } // If clicking on the toolbar, must be clicking on a Portable TV. Item toolbarItem = null; foreach (ClickableComponent button in toolbarButtons.GetValue()) { if (button.containsPoint((int)e.Cursor.ScreenPixels.X, (int)e.Cursor.ScreenPixels.Y)) { toolbarItem = Game1.player.Items[Convert.ToInt32(button.name)]; break; } } if (toolbarItem != null && !Utility.IsNormalObjectAtParentSheetIndex (toolbarItem, parentSheetIndex)) { return; } // If not clicking on a toolbar button, must be holding the TV // and have no interaction at the grab tile. if (toolbarItem == null) { if (!Utility.IsNormalObjectAtParentSheetIndex (Game1.player.CurrentItem, parentSheetIndex)) { return; } if (Game1.currentLocation.isActionableTile ((int)e.Cursor.GrabTile.X, (int)e.Cursor.GrabTile.Y, Game1.player)) { return; } } } // Activate the TV. Don't do anything else with this click. tv.turnOnTV(); Helper.Input.Suppress(e.Button); }