Ui buttons work, dialogue events now work for left click which could lead to some spicy mods.
This commit is contained in:
parent
4fc3466608
commit
16c77a1497
|
@ -13,17 +13,21 @@ namespace EventSystem.Framework.Events
|
|||
public class DialogueDisplayEvent :MapEvent
|
||||
{
|
||||
string dialogue;
|
||||
public DialogueDisplayEvent(string Name, GameLocation Location, Vector2 Position, PlayerEvents playerEvents, string Dialogue) : base(Name, Location, Position, playerEvents)
|
||||
public DialogueDisplayEvent(string Name, GameLocation Location, Vector2 Position, PlayerEvents playerEvents, MouseButtonEvents MouseEvents,MouseEntryLeaveEvent EntryLeave, string Dialogue) : base(Name, Location, Position, playerEvents)
|
||||
{
|
||||
this.name = Name;
|
||||
this.location = Location;
|
||||
this.tilePosition = Position;
|
||||
this.playerEvents = playerEvents;
|
||||
this.mouseButtonEvents = MouseEvents;
|
||||
|
||||
this.doesInteractionNeedToRun = true;
|
||||
this.dialogue = Dialogue;
|
||||
|
||||
this.mouseEntryLeaveEvents = EntryLeave;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the player enters the warp tile event position.
|
||||
/// </summary>s
|
||||
|
@ -33,7 +37,10 @@ namespace EventSystem.Framework.Events
|
|||
{
|
||||
this.doesInteractionNeedToRun = false;
|
||||
this.playerOnTile = true;
|
||||
if (this.playerEvents.onPlayerEnter != null) this.playerEvents.onPlayerEnter.run(); //used to run a function before the warp.
|
||||
if (this.playerEvents != null)
|
||||
{
|
||||
if (this.playerEvents.onPlayerEnter != null) this.playerEvents.onPlayerEnter.run(); //used to run a function before the warp.
|
||||
}
|
||||
Game1.activeClickableMenu =new StardewValley.Menus.DialogueBox(this.dialogue);
|
||||
//Game1.drawDialogueBox(this.dialogue);
|
||||
}
|
||||
|
@ -48,15 +55,31 @@ namespace EventSystem.Framework.Events
|
|||
{
|
||||
this.playerOnTile = false;
|
||||
this.doesInteractionNeedToRun = true;
|
||||
if (this.playerEvents.onPlayerLeave != null) this.playerEvents.onPlayerLeave.run();
|
||||
if (this.playerEvents != null)
|
||||
{
|
||||
if (this.playerEvents.onPlayerLeave != null) this.playerEvents.onPlayerLeave.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLeftClick()
|
||||
{
|
||||
if (Game1.activeClickableMenu != null) return;
|
||||
if (this.mouseButtonEvents == null) return;
|
||||
if (this.mouseOnTile == false) return;
|
||||
if (this.location.isObjectAt((int)this.tilePosition.X*Game1.tileSize, (int)this.tilePosition.Y*Game1.tileSize)) return;
|
||||
if (this.mouseButtonEvents.onLeftClick != null) this.mouseButtonEvents.onLeftClick.run();
|
||||
Game1.activeClickableMenu = new StardewValley.Menus.DialogueBox(this.dialogue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to update the event and check for interaction.
|
||||
/// </summary>
|
||||
public override void update()
|
||||
{
|
||||
this.clickEvent();
|
||||
this.OnMouseEnter();
|
||||
this.OnMouseLeave();
|
||||
this.OnPlayerEnter();
|
||||
this.OnPlayerLeave();
|
||||
}
|
||||
|
|
|
@ -177,6 +177,7 @@ namespace EventSystem.Framework
|
|||
/// </summary>
|
||||
public virtual void OnLeftClick()
|
||||
{
|
||||
if (Game1.activeClickableMenu != null) return;
|
||||
if (this.mouseOnTile==false) return;
|
||||
if (this.mouseButtonEvents.onLeftClick != null) this.mouseButtonEvents.onLeftClick.run();
|
||||
}
|
||||
|
@ -230,7 +231,7 @@ namespace EventSystem.Framework
|
|||
/// <returns></returns>
|
||||
public virtual bool isMouseOnTile()
|
||||
{
|
||||
Vector2 mousePosition = new Vector2(Game1.getMouseX(), Game1.getMouseY());
|
||||
Vector2 mousePosition = Game1.currentCursorTile;
|
||||
if (mousePosition.X == this.tilePosition.X && mousePosition.Y == this.tilePosition.Y) return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -238,7 +239,7 @@ namespace EventSystem.Framework
|
|||
/// <summary>
|
||||
/// Occurs when the tile is clicked. Runs the appropriate event.
|
||||
/// </summary>
|
||||
public virtual void eventClickEvent()
|
||||
public virtual void clickEvent()
|
||||
{
|
||||
if (this.mouseOnTile == false) return;
|
||||
var mouseState=Mouse.GetState();
|
||||
|
@ -253,7 +254,7 @@ namespace EventSystem.Framework
|
|||
/// </summary>
|
||||
public virtual void update()
|
||||
{
|
||||
eventClickEvent(); //click events
|
||||
clickEvent(); //click events
|
||||
OnPlayerEnter(); //player enter events
|
||||
OnPlayerLeave(); //player leave events
|
||||
OnMouseEnter(); //on mouse enter events
|
||||
|
|
|
@ -8,30 +8,46 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
using StardewValley;
|
||||
using StardustCore.UIUtilities;
|
||||
using StardustCore.UIUtilities.MenuComponents;
|
||||
using StardustCore.UIUtilities.MenuComponents.Delegates;
|
||||
using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality;
|
||||
|
||||
namespace StardewSymphonyRemastered.Framework.Menus
|
||||
{
|
||||
public class MusicManagerMenu : IClickableMenuExtended
|
||||
{
|
||||
private string musicNotePath;
|
||||
|
||||
public MusicManagerMenu(float width, float height)
|
||||
{
|
||||
|
||||
|
||||
|
||||
this.width = (int)width;
|
||||
this.height = (int)height;
|
||||
this.texturedStrings = new List<StardustCore.UIUtilities.SpriteFonts.Components.TexturedString>();
|
||||
this.texturedStrings.Add(StardustCore.UIUtilities.SpriteFonts.SpriteFont.vanillaFont.ParseString("Hello", new Microsoft.Xna.Framework.Vector2(100, 100),StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.LightColorsList.Blue)));
|
||||
this.buttons = new List<StardustCore.UIUtilities.MenuComponents.Button>();
|
||||
this.buttons.Add(new Button("myButton", new Rectangle(100, 100, 200, 100), StardewSymphony.textureManager.getTexture("MusicNote").Copy(StardewSymphony.ModHelper), "mynote", new Rectangle(0, 0, 16, 16), 4f, new StardustCore.Animations.Animation(new Rectangle(0, 0, 16, 16)), Color.White, Color.White, false));
|
||||
|
||||
this.buttons.Add(new Button("myButton", new Rectangle(100, 100, 64, 64), StardewSymphony.textureManager.getTexture("MusicNote").Copy(StardewSymphony.ModHelper), "mynote", new Rectangle(0, 0, 16, 16), 4f, new StardustCore.Animations.Animation(new Rectangle(0, 0, 16, 16)), Color.White, Color.White,new ButtonFunctionality(new DelegatePairing(hello,null),null,null),false)); //A button that does nothing on the left click.
|
||||
}
|
||||
|
||||
public override void receiveRightClick(int x, int y, bool playSound = true)
|
||||
{
|
||||
foreach (var v in this.buttons)
|
||||
{
|
||||
if (v.containsPoint(x, y)) v.onRightClick();
|
||||
}
|
||||
}
|
||||
|
||||
public override void performHoverAction(int x, int y)
|
||||
{
|
||||
foreach(var v in this.buttons)
|
||||
{
|
||||
if (v.containsPoint(x, y)) v.onHover();
|
||||
}
|
||||
}
|
||||
|
||||
public override void receiveLeftClick(int x, int y, bool playSound = true)
|
||||
{
|
||||
foreach (var v in this.buttons)
|
||||
{
|
||||
if (v.containsPoint(x, y)) v.onLeftClick();
|
||||
}
|
||||
}
|
||||
|
||||
public override void drawBackground(SpriteBatch b)
|
||||
|
@ -54,5 +70,13 @@ namespace StardewSymphonyRemastered.Framework.Menus
|
|||
}
|
||||
this.drawMouse(b);
|
||||
}
|
||||
|
||||
//Button Functionality
|
||||
#region
|
||||
private void hello(List<object> param)
|
||||
{
|
||||
StardewSymphony.ModMonitor.Log("Hello");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,9 @@
|
|||
<Compile Include="Math\Hex32.cs" />
|
||||
<Compile Include="UIUtilities\IClickableMenuExtended.cs" />
|
||||
<Compile Include="UIUtilities\LayeredTexture.cs" />
|
||||
<Compile Include="UIUtilities\MenuComponents\Delegates\Delegates.cs" />
|
||||
<Compile Include="UIUtilities\MenuComponents\Delegates\DelegatePairing.cs" />
|
||||
<Compile Include="UIUtilities\MenuComponents\Delegates\Functionality\ButtonFunctionality.cs" />
|
||||
<Compile Include="UIUtilities\SpriteFonts\CharacterSheets\GenericCharacterSheets.cs" />
|
||||
<Compile Include="UIUtilities\SpriteFonts\CharacterSheets\VanillaCharacterSheet.cs" />
|
||||
<Compile Include="UIUtilities\SpriteFonts\Fonts\Components\CharacterSpacing.cs" />
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using StardewValley;
|
||||
using StardustCore.UIUtilities.MenuComponents.Delegates;
|
||||
using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static StardustCore.UIUtilities.MenuComponents.Delegates.Delegates;
|
||||
|
||||
namespace StardustCore.UIUtilities.MenuComponents
|
||||
{
|
||||
|
@ -14,6 +17,9 @@ namespace StardustCore.UIUtilities.MenuComponents
|
|||
public Animations.AnimationManager animationManager;
|
||||
public Color textureColor;
|
||||
public Color textColor;
|
||||
|
||||
public ButtonFunctionality buttonFunctionality;
|
||||
|
||||
/// <summary>
|
||||
/// Basic Button constructor.
|
||||
/// </summary>
|
||||
|
@ -23,7 +29,7 @@ namespace StardustCore.UIUtilities.MenuComponents
|
|||
/// <param name="Scale"></param>
|
||||
/// <param name="defaultAnimation"></param>
|
||||
/// <param name="AnimationEnabled"></param>
|
||||
public Button(string Name,Rectangle Bounds,Texture2DExtended Texture,string displayText,Rectangle sourceRect,float Scale,Animations.Animation defaultAnimation, Color DrawColor,Color TextColor, bool AnimationEnabled=true) : base(Bounds,Texture.texture,sourceRect,Scale)
|
||||
public Button(string Name,Rectangle Bounds,Texture2DExtended Texture,string displayText,Rectangle sourceRect,float Scale,Animations.Animation defaultAnimation, Color DrawColor,Color TextColor, ButtonFunctionality Functionality, bool AnimationEnabled=true) : base(Bounds,Texture.texture,sourceRect,Scale)
|
||||
{
|
||||
this.animationManager = new Animations.AnimationManager(Texture, defaultAnimation,AnimationEnabled);
|
||||
this.label = displayText;
|
||||
|
@ -38,6 +44,7 @@ namespace StardustCore.UIUtilities.MenuComponents
|
|||
{
|
||||
this.textColor = StardustCore.IlluminateFramework.Colors.getColorFromList("White");
|
||||
}
|
||||
this.buttonFunctionality = Functionality;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -54,7 +61,7 @@ namespace StardustCore.UIUtilities.MenuComponents
|
|||
/// <param name="startingAnimationKey"></param>
|
||||
/// <param name="startingAnimationFrame"></param>
|
||||
/// <param name="AnimationEnabled"></param>
|
||||
public Button(string Name,Rectangle Bounds,Texture2DExtended Texture, string displayText, Rectangle sourceRect,float Scale, Animations.Animation defaultAnimation,Dictionary<string, List<Animations.Animation>> animationsToPlay,string startingAnimationKey,Color DrawColor,Color TextColor,int startingAnimationFrame=0,bool AnimationEnabled=true) : base(Bounds, Texture.texture, sourceRect, Scale)
|
||||
public Button(string Name,Rectangle Bounds,Texture2DExtended Texture, string displayText, Rectangle sourceRect,float Scale, Animations.Animation defaultAnimation,Dictionary<string, List<Animations.Animation>> animationsToPlay,string startingAnimationKey,Color DrawColor,Color TextColor, ButtonFunctionality Functionality,int startingAnimationFrame=0,bool AnimationEnabled=true) : base(Bounds, Texture.texture, sourceRect, Scale)
|
||||
{
|
||||
this.animationManager = new Animations.AnimationManager(Texture, defaultAnimation, animationsToPlay, startingAnimationKey, startingAnimationFrame, AnimationEnabled);
|
||||
this.label = displayText;
|
||||
|
@ -69,6 +76,7 @@ namespace StardustCore.UIUtilities.MenuComponents
|
|||
{
|
||||
this.textColor = StardustCore.IlluminateFramework.Colors.getColorFromList("White");
|
||||
}
|
||||
this.buttonFunctionality = Functionality;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -104,5 +112,35 @@ namespace StardustCore.UIUtilities.MenuComponents
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void onRightClick()
|
||||
{
|
||||
if (this.buttonFunctionality == null) return;
|
||||
else
|
||||
{
|
||||
if (this.buttonFunctionality.rightClick == null) return;
|
||||
else this.buttonFunctionality.rightClick.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void onLeftClick()
|
||||
{
|
||||
if (this.buttonFunctionality == null) return;
|
||||
else
|
||||
{
|
||||
if (this.buttonFunctionality.leftClick == null) return;
|
||||
else this.buttonFunctionality.leftClick.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void onHover()
|
||||
{
|
||||
if (this.buttonFunctionality == null) return;
|
||||
else
|
||||
{
|
||||
if (this.buttonFunctionality.hover == null) return;
|
||||
else this.buttonFunctionality.hover.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StardustCore.UIUtilities.MenuComponents.Delegates
|
||||
{
|
||||
public class DelegatePairing
|
||||
{
|
||||
public Delegates.paramaterDelegate click;
|
||||
public List<object> paramaters;
|
||||
|
||||
public DelegatePairing(Delegates.paramaterDelegate buttonDelegate,List<object> Paramaters)
|
||||
{
|
||||
this.click = buttonDelegate;
|
||||
if (this.paramaters == null)
|
||||
{
|
||||
this.paramaters = new List<object>();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.paramaters = Paramaters;
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
this.click.Invoke(this.paramaters);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StardustCore.UIUtilities.MenuComponents.Delegates
|
||||
{
|
||||
public class Delegates
|
||||
{
|
||||
public delegate void paramaterDelegate(List<object> paramaters);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StardustCore.UIUtilities.MenuComponents.Delegates.Functionality
|
||||
{
|
||||
public class ButtonFunctionality
|
||||
{
|
||||
public DelegatePairing leftClick;
|
||||
public DelegatePairing rightClick;
|
||||
public DelegatePairing hover;
|
||||
|
||||
public ButtonFunctionality(DelegatePairing LeftClick, DelegatePairing RightClick, DelegatePairing OnHover)
|
||||
{
|
||||
this.leftClick = LeftClick;
|
||||
this.rightClick = RightClick;
|
||||
this.hover = OnHover;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ namespace SundropMapEvents
|
|||
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
||||
{
|
||||
EventSystem.EventSystem.eventManager.addEvent(Game1.getLocationFromName("BusStop"), new WarpEvent("toRR", Game1.getLocationFromName("BusStop"), new Vector2(6, 11), new PlayerEvents(null, null), new WarpInformation("BusStop", 10, 12, 2, false)));
|
||||
EventSystem.EventSystem.eventManager.addEvent(Game1.getLocationFromName("BusStop"), new DialogueDisplayEvent("Hello.", Game1.getLocationFromName("BusStop"), new Vector2(10, 13), new PlayerEvents(null, null), "Hello there!"));
|
||||
EventSystem.EventSystem.eventManager.addEvent(Game1.getLocationFromName("BusStop"), new DialogueDisplayEvent("Hello.", Game1.getLocationFromName("BusStop"), new Vector2(10, 13), new PlayerEvents(null, null),new MouseButtonEvents(null,null) , new MouseEntryLeaveEvent(null,null),"Hello there!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue