diff --git a/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs b/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs index 0d0dec7c..809a7a35 100644 --- a/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs +++ b/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs @@ -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; } + /// /// Occurs when the player enters the warp tile event position. /// 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); + } + /// /// Used to update the event and check for interaction. /// public override void update() { + this.clickEvent(); + this.OnMouseEnter(); + this.OnMouseLeave(); this.OnPlayerEnter(); this.OnPlayerLeave(); } diff --git a/GeneralMods/MapEvents/Framework/MapEvent.cs b/GeneralMods/MapEvents/Framework/MapEvent.cs index d07d213e..7156763b 100644 --- a/GeneralMods/MapEvents/Framework/MapEvent.cs +++ b/GeneralMods/MapEvents/Framework/MapEvent.cs @@ -177,6 +177,7 @@ namespace EventSystem.Framework /// 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 /// 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 /// /// Occurs when the tile is clicked. Runs the appropriate event. /// - public virtual void eventClickEvent() + public virtual void clickEvent() { if (this.mouseOnTile == false) return; var mouseState=Mouse.GetState(); @@ -253,7 +254,7 @@ namespace EventSystem.Framework /// public virtual void update() { - eventClickEvent(); //click events + clickEvent(); //click events OnPlayerEnter(); //player enter events OnPlayerLeave(); //player leave events OnMouseEnter(); //on mouse enter events diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs index 8e97d10d..cf3255a0 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs @@ -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(); 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(); - 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 param) + { + StardewSymphony.ModMonitor.Log("Hello"); + } + #endregion } } diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj index c2d4554a..67a0b4eb 100644 --- a/GeneralMods/StardustCore/StardustCore.csproj +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -49,6 +49,9 @@ + + + diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs index ebfc9119..064022bc 100644 --- a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.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; + /// /// Basic Button constructor. /// @@ -23,7 +29,7 @@ namespace StardustCore.UIUtilities.MenuComponents /// /// /// - 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; } /// @@ -54,7 +61,7 @@ namespace StardustCore.UIUtilities.MenuComponents /// /// /// - public Button(string Name,Rectangle Bounds,Texture2DExtended Texture, string displayText, Rectangle sourceRect,float Scale, Animations.Animation defaultAnimation,Dictionary> 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> 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; } /// @@ -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(); + } + } } } diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/DelegatePairing.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/DelegatePairing.cs new file mode 100644 index 00000000..c245d5a6 --- /dev/null +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/DelegatePairing.cs @@ -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 paramaters; + + public DelegatePairing(Delegates.paramaterDelegate buttonDelegate,List Paramaters) + { + this.click = buttonDelegate; + if (this.paramaters == null) + { + this.paramaters = new List(); + } + else + { + this.paramaters = Paramaters; + } + } + + public void run() + { + this.click.Invoke(this.paramaters); + } + } +} diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/Delegates.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/Delegates.cs new file mode 100644 index 00000000..a711a47b --- /dev/null +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/Delegates.cs @@ -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 paramaters); + + } +} diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/Functionality/ButtonFunctionality.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/Functionality/ButtonFunctionality.cs new file mode 100644 index 00000000..5f3b3426 --- /dev/null +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Delegates/Functionality/ButtonFunctionality.cs @@ -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; + } + } +} diff --git a/GeneralMods/SundropMapEvents/Class1.cs b/GeneralMods/SundropMapEvents/Class1.cs index a059bf64..449bdfb7 100644 --- a/GeneralMods/SundropMapEvents/Class1.cs +++ b/GeneralMods/SundropMapEvents/Class1.cs @@ -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!")); } } }