Ui-Info-Suite/SDVModTest/Options/ModOptionsPageButton.cs

109 lines
3.9 KiB
C#
Raw Permalink Normal View History

2017-07-20 11:51:05 +08:00
using Microsoft.Xna.Framework;
2018-12-25 12:36:39 +08:00
using StardewModdingAPI;
2017-07-20 11:51:05 +08:00
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using Microsoft.Xna.Framework.Graphics;
namespace UIInfoSuite.Options
{
class ModOptionsPageButton : IClickableMenu
{
public Rectangle Bounds { get; }
//private readonly ModOptionsPageHandler _optionsPageHandler;
//private bool _hasClicked;
public event EventHandler OnLeftClicked;
2018-12-25 12:36:39 +08:00
public ModOptionsPageButton(IModEvents events)
2017-07-20 11:51:05 +08:00
{
//_optionsPageHandler = optionsPageHandler;
width = 64;
height = 64;
GameMenu activeClickableMenu = Game1.activeClickableMenu as GameMenu;
xPositionOnScreen = activeClickableMenu.xPositionOnScreen + activeClickableMenu.width - 200;
yPositionOnScreen = activeClickableMenu.yPositionOnScreen + 16;
Bounds = new Rectangle(xPositionOnScreen, yPositionOnScreen, width, height);
2018-12-25 12:36:39 +08:00
events.Input.ButtonPressed += OnButtonPressed;
events.Display.MenuChanged += OnMenuChanged;
2017-07-20 11:51:05 +08:00
}
2018-12-25 12:36:39 +08:00
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
2017-07-20 11:51:05 +08:00
{
2018-12-25 12:36:39 +08:00
if (e.NewMenu is GameMenu menu)
2017-07-20 11:51:05 +08:00
{
xPositionOnScreen = menu.xPositionOnScreen + menu.width - 200;
}
}
2018-12-25 12:36:39 +08:00
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
public void OnButtonPressed(object sender, ButtonPressedEventArgs e)
2017-07-20 11:51:05 +08:00
{
2018-12-25 12:36:39 +08:00
if (e.Button == SButton.MouseLeft || e.Button == SButton.ControllerA)
2017-07-20 11:51:05 +08:00
{
2018-12-25 12:36:39 +08:00
int x = (int)e.Cursor.ScreenPixels.X;
int y = (int)e.Cursor.ScreenPixels.Y;
if (isWithinBounds(x, y))
{
receiveLeftClick(x, y);
OnLeftClicked?.Invoke(this, null);
}
2017-07-20 11:51:05 +08:00
}
//if (e.NewState.LeftButton != ButtonState.Pressed || !(Game1.activeClickableMenu is GameMenu))
//{
// _hasClicked = false;
//}
//else if ((Game1.activeClickableMenu as GameMenu).currentTab != 3 &&
// isWithinBounds(e.NewPosition.X, e.NewPosition.Y) &&
// !_hasClicked)
//{
// receiveLeftClick(e.NewPosition.X, e.NewPosition.Y);
2018-12-25 12:36:39 +08:00
2017-07-20 11:51:05 +08:00
//}
}
public override void draw(SpriteBatch b)
{
base.draw(b);
Game1.spriteBatch.Draw(Game1.mouseCursors,
new Vector2(xPositionOnScreen, yPositionOnScreen),
new Rectangle(16, 368, 16, 16),
Color.White,
0.0f,
Vector2.Zero,
Game1.pixelZoom,
SpriteEffects.None,
1f);
b.Draw(Game1.mouseCursors,
new Vector2(xPositionOnScreen + 8, yPositionOnScreen + 14),
new Rectangle(32, 672, 16, 16),
Color.White,
0.0f,
Vector2.Zero,
3f,
SpriteEffects.None,
1f);
if (isWithinBounds(Game1.getMouseX(), Game1.getMouseY()))
{
IClickableMenu.drawHoverText(Game1.spriteBatch, "UI Info Mod Options", Game1.smallFont);
}
Tools.DrawMouseCursor();
2017-07-20 11:51:05 +08:00
}
public override void receiveRightClick(int x, int y, bool playSound = true)
{
}
}
}