From 8cfff47a58dda86131859e661381eee0474e6c21 Mon Sep 17 00:00:00 2001 From: Date: Thu, 23 Aug 2018 01:23:42 -0700 Subject: [PATCH] Modular game menu working with Vocalization tab added in. --- GeneralMods/StardewMods.sln | 3 - .../StardustCore/Menus/ModualGameMenu.cs | 339 ++++++++++++++++++ GeneralMods/StardustCore/ModConfig.cs | 2 + GeneralMods/StardustCore/ModCore.cs | 9 +- GeneralMods/StardustCore/StardustCore.csproj | 1 + .../UIUtilities/IClickableMenuExtended.cs | 20 ++ .../UIUtilities/LayeredTexture.cs | 19 +- .../UIUtilities/MenuComponents/Button.cs | 84 ++++- .../Vocalization/Content/Graphics/MenuTab.png | Bin 0 -> 265 bytes .../Content/Graphics/SpeechBubble.png | Bin 0 -> 270 bytes .../Vocalization/Vocalization/Vocalization.cs | 92 +++++ .../Vocalization/Vocalization.csproj | 20 +- .../Vocalization/Vocalization/packages.config | 2 +- 13 files changed, 573 insertions(+), 18 deletions(-) create mode 100644 GeneralMods/StardustCore/Menus/ModualGameMenu.cs create mode 100644 GeneralMods/Vocalization/Vocalization/Content/Graphics/MenuTab.png create mode 100644 GeneralMods/Vocalization/Vocalization/Content/Graphics/SpeechBubble.png diff --git a/GeneralMods/StardewMods.sln b/GeneralMods/StardewMods.sln index 577b29d2..e0d2337c 100644 --- a/GeneralMods/StardewMods.sln +++ b/GeneralMods/StardewMods.sln @@ -75,9 +75,6 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedSaveBackup", "AdvancedSaveBackup\AdvancedSaveBackup.csproj", "{12984468-2B79-4B3B-B045-EE917301DEE0}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vocalization", "Vocalization\Vocalization\Vocalization.csproj", "{1651701C-DB36-43C7-B66D-2700171DD9A9}" - ProjectSection(ProjectDependencies) = postProject - {7B1E9A54-ED9E-47AA-BBAA-98A6E7CB527A} = {7B1E9A54-ED9E-47AA-BBAA-98A6E7CB527A} - EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/GeneralMods/StardustCore/Menus/ModualGameMenu.cs b/GeneralMods/StardustCore/Menus/ModualGameMenu.cs new file mode 100644 index 00000000..3edfc8d9 --- /dev/null +++ b/GeneralMods/StardustCore/Menus/ModualGameMenu.cs @@ -0,0 +1,339 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Menus; +using StardustCore.UIUtilities; +using StardustCore.UIUtilities.MenuComponents; + +namespace StardustCore.Menus +{ + public class ModularGameMenu : StardustCore.UIUtilities.IClickableMenuExtended + { + public static SortedDictionary>> StaticMenuTabsAndPages = new SortedDictionary>>(); + + + + public string hoverText = ""; + public string descriptionText = ""; + public Dictionary menuTabsAndPages; + + public Button currentButton; + public IClickableMenuExtended currentMenu; + + public bool invisible; + public static bool forcePreventClose; + + public const int tabsPerPage = 12; + + public ModularGameMenu() + : base(Game1.viewport.Width / 2 - (800 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, 800 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2, true) + { + ModCore.ModMonitor.Log("INITIALIZE MENU: ", LogLevel.Alert); + if (Game1.activeClickableMenu == null) + Game1.playSound("bigSelect"); + GameMenu.forcePreventClose = false; + + this.menuTabsAndPages = new Dictionary(); + ModCore.ModMonitor.Log("INITIALIZE MENU: ", LogLevel.Alert); + foreach (var v in StaticMenuTabsAndPages) + { + ModCore.ModMonitor.Log("LIST A GO GO", LogLevel.Alert); + foreach (var pair in v.Value) + { + this.AddMenuTab(pair.Key, pair.Value.clone()); + ModCore.ModMonitor.Log("ADD IN A PART", LogLevel.Alert); + } + //this.menuTabsAndPages.Add(v.Key,v.Value.clone()); + } + } + + public static void AddTabsForMod(IManifest modManifest, List> menuComponents) + { + StaticMenuTabsAndPages.Add(modManifest.UniqueID, menuComponents); + } + + public void AddMenuTab(Button b, IClickableMenuExtended menu) + { + int count = menuTabsAndPages.Count % tabsPerPage; + int xPos = this.xPositionOnScreen + count * 64; + int yPos = this.yPositionOnScreen; + + b.bounds = new Rectangle(xPos, yPos, b.bounds.Width, b.bounds.Height); + + + if (b.extraTextures == null) + { + menuTabsAndPages.Add(b, menu); + return; + } + for (int i = 0; i < b.extraTextures.Count; i++) + { + ClickableTextureComponent text = b.extraTextures.ElementAt(i).Key; + Rectangle bounds = new Rectangle(b.bounds.X + text.bounds.X, b.bounds.Y + text.bounds.Y, text.bounds.Width, text.bounds.Height); + text.bounds = bounds; + b.extraTextures[i] =new KeyValuePair(text,b.extraTextures.ElementAt(i).Value); + } + + menuTabsAndPages.Add(b, menu); + } + + /// + /// Get how many pages there should be for the modular menu. + /// + public int getNumberOfPages() + { + int count = (menuTabsAndPages.Count / tabsPerPage); + return count; + } + + /// + /// Takes in the static declared tabs and tries to set the menu tabs to that. + /// + /// + public ModularGameMenu(int startingTab) : base(Game1.viewport.Width / 2 - (800 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, 800 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2, true) + { + ModCore.ModMonitor.Log("INITIALIZE MENU: ", LogLevel.Alert); + if (Game1.activeClickableMenu == null) + Game1.playSound("bigSelect"); + GameMenu.forcePreventClose = false; + + this.menuTabsAndPages = new Dictionary(); + ModCore.ModMonitor.Log("INITIALIZE MENU: ", LogLevel.Alert); + foreach (var v in StaticMenuTabsAndPages) + { + ModCore.ModMonitor.Log("LIST A GO GO", LogLevel.Alert); + foreach (var pair in v.Value) + { + this.AddMenuTab(pair.Key, pair.Value.clone()); + ModCore.ModMonitor.Log("ADD IN A PART", LogLevel.Alert); + } + //this.menuTabsAndPages.Add(v.Key,v.Value.clone()); + } + this.changeTab(startingTab); + } + + /// + /// More modular menu to only have a subset of buttons and pages. + /// + /// + /// + public ModularGameMenu(int startingTab, Dictionary tabsAndPages) + : this() + { + foreach (var v in tabsAndPages) + { + this.AddMenuTab(v.Key, v.Value.clone()); + } + this.changeTab(startingTab); + } + + public override void snapToDefaultClickableComponent() + { + /* + if (this.currentTab < this.pages.Count) + this.pages[this.currentTab].snapToDefaultClickableComponent(); + if (this.junimoNoteIcon == null || this.currentTab >= this.pages.Count || this.pages[this.currentTab].allClickableComponents.Contains((ClickableComponent)this.junimoNoteIcon)) + return; + this.pages[this.currentTab].allClickableComponents.Add((ClickableComponent)this.junimoNoteIcon); + */ + currentMenu.snapToDefaultClickableComponent(); + } + + public override void receiveGamePadButton(Buttons b) + { + base.receiveGamePadButton(b); + /* + switch (b) + { + case Buttons.Back: + if (this.currentTab != 0) + break; + this.pages[this.currentTab].receiveGamePadButton(b); + break; + case Buttons.RightTrigger: + if (this.currentTab == 3) + { + Game1.activeClickableMenu = (IClickableMenu)new GameMenu(4, -1); + break; + } + if (this.currentTab >= 7 || !this.pages[this.currentTab].readyToClose()) + break; + this.changeTab(this.currentTab + 1); + break; + case Buttons.LeftTrigger: + if (this.currentTab == 3) + { + Game1.activeClickableMenu = (IClickableMenu)new GameMenu(2, -1); + break; + } + if (this.currentTab <= 0 || !this.pages[this.currentTab].readyToClose()) + break; + this.changeTab(this.currentTab - 1); + break; + } + */ + currentMenu.receiveGamePadButton(b); + } + + public override void setUpForGamePadMode() + { + base.setUpForGamePadMode(); + } + + public override void receiveLeftClick(int x, int y, bool playSound = true) + { + base.receiveLeftClick(x, y, playSound); + //click the menu and stuff here I guess. + foreach (var v in menuTabsAndPages) + { + if (v.Key.containsPoint(x, y)) + { + //Make sub menu this menu value. + } + } + //Check for submenu leftclick + currentMenu.receiveLeftClick(x, y, playSound); + } + + public override void receiveRightClick(int x, int y, bool playSound = true) + { + //base.receiveLeftClick(x, y, playSound); + //click the menu and stuff here I guess. + foreach (var v in menuTabsAndPages) + { + if (v.Key.containsPoint(x, y)) + { + //Make sub menu this menu value. + } + } + //Check for submenu right + currentMenu.receiveRightClick(x, y); + } + + public override void receiveScrollWheelAction(int direction) + { + base.receiveScrollWheelAction(direction); + //this.pages[this.currentTab].receiveScrollWheelAction(direction); + //check for submenu scroll action. + currentMenu.receiveScrollWheelAction(direction); + } + + public override void performHoverAction(int x, int y) + { + base.performHoverAction(x, y); + this.hoverText = ""; + currentMenu.performHoverAction(x, y); + //this.pages[this.currentTab].performHoverAction(x, y); + foreach (var tab in this.menuTabsAndPages) + { + if (tab.Key.containsPoint(x, y)) + { + this.hoverText = tab.Key.label; + return; + } + } + } + + public override void releaseLeftClick(int x, int y) + { + base.releaseLeftClick(x, y); + //this.pages[this.currentTab].releaseLeftClick(x, y); + currentMenu.releaseLeftClick(x, y); + } + + public override void leftClickHeld(int x, int y) + { + base.leftClickHeld(x, y); + //this.pages[this.currentTab].leftClickHeld(x, y); + currentMenu.leftClickHeld(x, y); + } + + public override bool readyToClose() + { + if (!GameMenu.forcePreventClose) + return currentMenu.readyToClose(); + return false; + } + + public void changeTab(int which) + { + currentButton = menuTabsAndPages.ElementAt(which).Key; + currentMenu = menuTabsAndPages.ElementAt(which).Value; + } + + public void setTabNeighborsForCurrentPage() + { + + } + + public override void draw(SpriteBatch b) + { + if (!this.invisible) + { + if (!Game1.options.showMenuBackground) + b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.4f); + //Game1.drawDialogueBox(this.xPositionOnScreen, this.yPositionOnScreen, currentMenu.width, currentMenu.height, false, true, (string)null, false); + //this.pages[this.currentTab].draw(b); + drawDialogueBoxBackground(); + + b.End(); + b.Begin(SpriteSortMode.FrontToBack, BlendState.NonPremultiplied, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); + Dictionary subTabs = new Dictionary(); + for (int i = getNumberOfPages() * tabsPerPage; i < (getNumberOfPages() + 1) * tabsPerPage; i++) + { + if (i >= menuTabsAndPages.Count) break; + else + { + var pair = menuTabsAndPages.ElementAt(i); + subTabs.Add(pair.Key, pair.Value); + } + } + + foreach (var tab in subTabs) + { + if (tab.Key.visible) + { + if (tab.Key == currentButton) + { + tab.Key.draw(b, Color.White, new Vector2(0,0)); + continue; + } + tab.Key.draw(b); + } + } + //currentMenu.draw(b); + + if (Game1.options.hardwareCursor) + return; + b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getOldMouseX(), (float)Game1.getOldMouseY()), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, Game1.options.gamepadControls ? 44 : 0, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f); + } + } + + public override bool areGamePadControlsImplemented() + { + return false; + } + + public override void receiveKeyPress(Keys key) + { + if (((IEnumerable)Game1.options.menuButton).Contains(new InputButton(key)) && this.readyToClose()) + { + Game1.exitActiveMenu(); + Game1.playSound("bigDeSelect"); + } + //this.pages[this.currentTab].receiveKeyPress(key); + currentMenu.receiveKeyPress(key); + } + + public override void emergencyShutDown() + { + base.emergencyShutDown(); + currentMenu.emergencyShutDown(); + } + } +} \ No newline at end of file diff --git a/GeneralMods/StardustCore/ModConfig.cs b/GeneralMods/StardustCore/ModConfig.cs index 7c44a1c5..4ecca703 100644 --- a/GeneralMods/StardustCore/ModConfig.cs +++ b/GeneralMods/StardustCore/ModConfig.cs @@ -9,6 +9,8 @@ namespace StardustCore public class ModConfig { public bool enableMultiplayerHack { get; set; } = false; + public string modularMenuKey { get; set; } = "P"; + public ModConfig() { diff --git a/GeneralMods/StardustCore/ModCore.cs b/GeneralMods/StardustCore/ModCore.cs index 2fb081b7..8ede36c2 100644 --- a/GeneralMods/StardustCore/ModCore.cs +++ b/GeneralMods/StardustCore/ModCore.cs @@ -4,6 +4,7 @@ using StardewModdingAPI; using StardewValley; using StardewValley.Menus; using StardewValley.Network; +using StardustCore.Menus; using StardustCore.ModInfo; using StardustCore.NetCode; using StardustCore.Objects; @@ -30,6 +31,7 @@ namespace StardustCore public static UIUtilities.TextureManager TextureManager; public static Dictionary TextureManagers; + public static Multiplayer multiplayer; bool serverHack; @@ -187,6 +189,10 @@ namespace StardustCore private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) { + if(e.KeyPressed.ToString()== config.modularMenuKey && Game1.activeClickableMenu==null) + { + Game1.activeClickableMenu = new ModularGameMenu(0); + } } private void SaveEvents_AfterLoad(object sender, EventArgs e) @@ -232,7 +238,8 @@ namespace StardustCore private void ControlEvents_MouseChanged(object sender, StardewModdingAPI.Events.EventArgsMouseStateChanged e) { - + //??? + return; if (Game1.activeClickableMenu == null) return; var MouseState = Mouse.GetState(); if (Game1.activeClickableMenu is StardewValley.Menus.ItemGrabMenu && MouseState.LeftButton == ButtonState.Released) diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj index 2b041fbe..bc8188ed 100644 --- a/GeneralMods/StardustCore/StardustCore.csproj +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -93,6 +93,7 @@ + diff --git a/GeneralMods/StardustCore/UIUtilities/IClickableMenuExtended.cs b/GeneralMods/StardustCore/UIUtilities/IClickableMenuExtended.cs index e178a63b..f895e82d 100644 --- a/GeneralMods/StardustCore/UIUtilities/IClickableMenuExtended.cs +++ b/GeneralMods/StardustCore/UIUtilities/IClickableMenuExtended.cs @@ -15,11 +15,31 @@ namespace StardustCore.UIUtilities public List buttons; public Color dialogueBoxBackgroundColor; public List menuTextures; + + public bool showRightCloseButton; + + public IClickableMenuExtended(): base() + { + + } + + public IClickableMenuExtended(int x, int y, int width, int height, bool showCloseButton): base(x, y, width, height, showCloseButton) + { + this.showRightCloseButton = showCloseButton; + } + + public override void receiveRightClick(int x, int y, bool playSound = true) { } + public virtual IClickableMenuExtended clone() + { + return new IClickableMenuExtended(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, this.showRightCloseButton); + + } + /// /// Draws a dialogue box background with the menu's position and dimentions as the paramaters for size and position. /// diff --git a/GeneralMods/StardustCore/UIUtilities/LayeredTexture.cs b/GeneralMods/StardustCore/UIUtilities/LayeredTexture.cs index 3744067e..99cc55e2 100644 --- a/GeneralMods/StardustCore/UIUtilities/LayeredTexture.cs +++ b/GeneralMods/StardustCore/UIUtilities/LayeredTexture.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Linq; @@ -12,9 +13,9 @@ namespace StardustCore.UIUtilities /// public class LayeredTexture { - public List textureLayers; + public List> textureLayers; - public LayeredTexture(List textures) + public LayeredTexture(List> textures) { this.textureLayers = textures; } @@ -23,7 +24,7 @@ namespace StardustCore.UIUtilities /// Adds a new texture as the top layer. /// /// - public void addTexture(Texture2DExtended texture) + public void addTexture(KeyValuePair texture) { this.textureLayers.Add(texture); } @@ -33,7 +34,7 @@ namespace StardustCore.UIUtilities /// /// /// - public void addTexture(Texture2DExtended texture, int index) + public void addTexture(KeyValuePairtexture , int index) { this.textureLayers.Insert(index, texture); } @@ -43,5 +44,13 @@ namespace StardustCore.UIUtilities return new LayeredTexture(this.textureLayers); } + public void draw(SpriteBatch b, Color color, float layerDepth) + { + foreach(var texture in this.textureLayers) + { + b.Draw(texture.Value.getTexture(), texture.Key, color); + } + } + } } diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs index 79771249..608527fa 100644 --- a/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/Button.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; +using StardewValley.Menus; using StardustCore.UIUtilities.MenuComponents.Delegates; using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality; using System; @@ -12,14 +13,27 @@ using static StardustCore.UIUtilities.MenuComponents.Delegates.Delegates; namespace StardustCore.UIUtilities.MenuComponents { + public enum ExtraTextureDrawOrder + { + before, + after + } + public class Button : StardewValley.Menus.ClickableTextureComponent { + + + public Animations.AnimationManager animationManager; public Color textureColor; public Color textColor; public ButtonFunctionality buttonFunctionality; + /// + /// A list of textures to be drawn on top of the button. + /// + public List> extraTextures; /// /// Empty Constructor. @@ -38,7 +52,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, ButtonFunctionality Functionality, bool AnimationEnabled=true) : base(Bounds,Texture.getTexture(), 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,List> extraTexture=null) : base(Bounds,Texture.getTexture(), sourceRect,Scale) { this.animationManager = new Animations.AnimationManager(Texture, defaultAnimation,AnimationEnabled); this.label = displayText; @@ -54,6 +68,10 @@ namespace StardustCore.UIUtilities.MenuComponents this.textColor = StardustCore.IlluminateFramework.Colors.getColorFromList("White"); } this.buttonFunctionality = Functionality; + if (extraTexture == null) extraTexture = new List>(); + extraTextures = extraTexture; + + this.scale = Scale; } /// @@ -70,7 +88,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, ButtonFunctionality Functionality,int startingAnimationFrame=0,bool AnimationEnabled=true) : base(Bounds, Texture.getTexture(), 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, List> extraTexture =null) : base(Bounds, Texture.getTexture(), sourceRect, Scale) { this.animationManager = new Animations.AnimationManager(Texture, defaultAnimation, animationsToPlay, startingAnimationKey, startingAnimationFrame, AnimationEnabled); this.label = displayText; @@ -86,6 +104,10 @@ namespace StardustCore.UIUtilities.MenuComponents this.textColor = StardustCore.IlluminateFramework.Colors.getColorFromList("White"); } this.buttonFunctionality = Functionality; + if (extraTexture == null) extraTexture = new List>(); + this.extraTextures = extraTexture; + + this.scale = Scale; } /// @@ -94,9 +116,19 @@ namespace StardustCore.UIUtilities.MenuComponents /// /// /// - public void draw(SpriteBatch b,Color color ,float layerDepth) + public new void draw(SpriteBatch b,Color color ,float layerDepth) { - + if (this.extraTextures != null) + { + foreach (var v in this.extraTextures) + { + if (v.Value == ExtraTextureDrawOrder.before) + { + v.Key.draw(b); + } + } + } + this.animationManager.tickAnimation(); if (!this.visible) return; @@ -119,7 +151,17 @@ namespace StardustCore.UIUtilities.MenuComponents { //Game1.drawDialogueBox(Game1.getMousePosition().X, Game1.getMousePosition().Y, false, false, this.hoverText); //StardustCore.ModCore.ModMonitor.Log("HOVER???"); - b.DrawString(Game1.smallFont, this.hoverText, new Vector2((float)(this.bounds.X + this.bounds.Width), (float)this.bounds.Y + ((float)(this.bounds.Height) - Game1.smallFont.MeasureString(this.label).Y / 2f)), this.textColor,0f,Vector2.Zero,1f,SpriteEffects.None,layerDepth-0.5f); + b.DrawString(Game1.smallFont, this.hoverText, new Vector2((float)(this.bounds.X + this.bounds.Width), (float)this.bounds.Y + ((float)(this.bounds.Height) - Game1.smallFont.MeasureString(this.label).Y / 2f)), this.textColor,0f,Vector2.Zero,scale,SpriteEffects.None,layerDepth-0.5f); + } + if (this.extraTextures != null) + { + foreach(var v in this.extraTextures) + { + if (v.Value == ExtraTextureDrawOrder.after) + { + v.Key.draw(b); + } + } } } @@ -132,7 +174,7 @@ namespace StardustCore.UIUtilities.MenuComponents { if (!this.visible) return; - this.draw(b, Color.White, (float)(0.860000014305115 + (double)this.bounds.Y / 20000.0)); + this.draw(b, Color.White, Vector2.Zero); } /// @@ -144,7 +186,35 @@ namespace StardustCore.UIUtilities.MenuComponents { if (!this.visible) return; - this.draw(b, color, (float)(0.860000014305115 + (double)this.bounds.Y / 20000.0)); + this.draw(b, color, Vector2.Zero); + } + + public virtual void draw(SpriteBatch b, Color color, Vector2 offset) + { + if (this.extraTextures != null) + { + foreach (var v in this.extraTextures) + { + if (v.Value == ExtraTextureDrawOrder.before) + { + v.Key.draw(b,color,0.4f); + } + } + } + + float depth = 0.4f; + b.Draw(this.animationManager.getTexture(), new Vector2(this.bounds.X + (int)offset.X, this.bounds.Y + (int)offset.Y),this.sourceRect,color,0f,Vector2.Zero,this.scale,SpriteEffects.None, depth); + + if (this.extraTextures != null) + { + foreach (var v in this.extraTextures) + { + if (v.Value == ExtraTextureDrawOrder.after) + { + v.Key.draw(b,color,0.4f); + } + } + } } /// diff --git a/GeneralMods/Vocalization/Vocalization/Content/Graphics/MenuTab.png b/GeneralMods/Vocalization/Vocalization/Content/Graphics/MenuTab.png new file mode 100644 index 0000000000000000000000000000000000000000..d7bb377f8ccbd8172aff880e2144dc76c3e8b3f3 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmUKs7M+SzC{oH>NS%G}c0*}aI z1_r)EAj~ML;ne^Xlq_+LC<)F_D=AMbN@XZW%*-p%%S$a$Fwry6Gcx?BkU15osLj*G zF(kr0*@6Ayt*HN*oeQr$V7p-wDD1rUAd3O3^xuesKm1Hf4bQ~P;gd9A7uY1B=BIZo zRql>r^D)L9B6g9}-38lbHs}3&P|Bd!{XafSk#q5D_wo}L3K`4}dmdcOCsBG}1+$y1 z!K;Qq_8zN*D~v!PE4~KJhQt|eS&1c|**lrH{9|U2z37&%_O#In=pqJBS3j3^P6NS%G}c0*}aI z1_r)EAj~ML;ne^Xlq_+LC<)F_D=AMbN@XZW%*-p%%S$a$Fwry6Gcx?BkU15osN2)U zF(ktM?c|G`2NZZ*?yi$v`n#m--9`TI8RZ&Zju$0(O;FsV@o+|IiP!lU+{s@o%dp?`yq zPWr^#{u;er2PI6OJ!6u}&U9WI^N!tT!VS~h-uTNxP8^EO!iShc`&OBFd-=%#oyFkk L>gTe~DWM4f0K8wy literal 0 HcmV?d00001 diff --git a/GeneralMods/Vocalization/Vocalization/Vocalization.cs b/GeneralMods/Vocalization/Vocalization/Vocalization.cs index 0817d70a..f4b00fe8 100644 --- a/GeneralMods/Vocalization/Vocalization/Vocalization.cs +++ b/GeneralMods/Vocalization/Vocalization/Vocalization.cs @@ -12,6 +12,9 @@ using StardewModdingAPI; using StardewValley; using StardewValley.BellsAndWhistles; using StardewValley.Menus; +using StardustCore.Menus; +using StardustCore.UIUtilities; +using StardustCore.UIUtilities.MenuComponents; using Vocalization.Framework; namespace Vocalization @@ -166,6 +169,7 @@ namespace Vocalization /// public static SimpleSoundManager.Framework.SoundManager soundManager; + /// @@ -190,6 +194,7 @@ namespace Vocalization StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; StardewModdingAPI.Events.MenuEvents.MenuClosed += MenuEvents_MenuClosed; + StardewModdingAPI.Events.MenuEvents.MenuChanged += MenuEvents_MenuChanged; ModMonitor = Monitor; ModHelper = Helper; DialogueCues = new Dictionary(); @@ -205,6 +210,15 @@ namespace Vocalization config.verifyValidMode(); //Make sure the current mode is valid. soundManager.volume = config.voiceVolume; //Set the volume for voices. + + } + + private void MenuEvents_MenuChanged(object sender, StardewModdingAPI.Events.EventArgsClickableMenuChanged e) + { + if (Game1.activeClickableMenu.GetType() == typeof(ModularGameMenu)) + { + npcPortraitHack(); + } } /// @@ -233,10 +247,86 @@ namespace Vocalization /// private void SaveEvents_AfterLoad(object sender, EventArgs e) { + + + initialzeModualGameMenuHack(); initialzeDirectories(); loadAllVoiceFiles(); } + /// + /// Initializes the menu tab for Vocalization for the modular menu. + /// + public void initialzeModualGameMenuHack() + { + List textures = new List(); + foreach (GameLocation loc in Game1.locations) + { + foreach (NPC npc in loc.characters) + { + if (npc.isVillager() == false) continue; + Texture2D text = npc.Sprite.Texture; + if (text == null) continue; + textures.Add(text); + } + } + int randNum = Game1.random.Next(0, textures.Count); + Texture2D myText = textures.ElementAt(randNum); + ClickableTextureComponent c = new ClickableTextureComponent(new Rectangle(0, 16, 16, 24), myText, new Rectangle(0, 0, 16, 24), 2f, false); + + ClickableTextureComponent speech = new ClickableTextureComponent(new Rectangle(0, 0, 32, 32), ModHelper.Content.Load (Path.Combine("Content", "Graphics", "SpeechBubble.png")), new Rectangle(0, 0, 32, 32), 2f, false); + List> components = new List>(); + + components.Add(new KeyValuePair(c,ExtraTextureDrawOrder.after)); + components.Add(new KeyValuePair(speech, ExtraTextureDrawOrder.after)); + + Button menuTab = new Button("Vocalization", new Rectangle(0, 0, 32, 32), new Texture2DExtended(ModHelper, ModManifest, Path.Combine("Content", "Graphics", "MenuTab.png")), "Vocalization", new Rectangle(0, 0, 32, 32), 2f, new StardustCore.Animations.Animation(new Rectangle(0, 0, 32, 32)), Color.White, Color.White, new StardustCore.UIUtilities.MenuComponents.Delegates.Functionality.ButtonFunctionality(new StardustCore.UIUtilities.MenuComponents.Delegates.DelegatePairing(null,null), new StardustCore.UIUtilities.MenuComponents.Delegates.DelegatePairing(null,null), new StardustCore.UIUtilities.MenuComponents.Delegates.DelegatePairing(null,null)), false, components); + + //Change this to take the vocalization menu instead + List> modTabs = new List>(); + modTabs.Add(new KeyValuePair(menuTab, new IClickableMenuExtended(0,0,300,300,false))); + StardustCore.Menus.ModularGameMenu.AddTabsForMod(ModManifest,modTabs); + + ModMonitor.Log("VOCALIZATION MENU HACK COMPLETE!", LogLevel.Alert); + } + + /// + /// Randomize the npc below the speech bubble every time the modular game menu is drawn. + /// + public void npcPortraitHack() + { + List> menuHacks = new List>(); + + List textures = new List(); + foreach (GameLocation loc in Game1.locations) + { + foreach (NPC npc in loc.characters) + { + if (npc.isVillager() == false) continue; + Texture2D text = npc.Sprite.Texture; + textures.Add(text); + } + } + int randNum = Game1.random.Next(0, textures.Count); + Texture2D myText = textures.ElementAt(randNum); + ClickableTextureComponent c = new ClickableTextureComponent(new Rectangle(0, 16, 16, 24), myText, new Rectangle(0, 0, 16, 24), 2f, false); + List> components = new List>(); + + + ClickableTextureComponent speech = new ClickableTextureComponent(new Rectangle(0, 0, 32, 32), ModHelper.Content.Load(Path.Combine("Content", "Graphics", "SpeechBubble.png")), new Rectangle(0, 0, 32, 32), 2f, false); + + components.Add(new KeyValuePair(c, ExtraTextureDrawOrder.after)); + components.Add(new KeyValuePair(speech, ExtraTextureDrawOrder.after)); + + Button menuTab = new Button("Vocalization", new Rectangle(0,0, 32, 32), new Texture2DExtended(ModHelper, ModManifest, Path.Combine("Content", "Graphics", "MenuTab.png")), "Vocalization", new Rectangle(0, 0, 32, 32), 2f, new StardustCore.Animations.Animation(new Rectangle(0, 0, 32, 32)), Color.White, Color.White, new StardustCore.UIUtilities.MenuComponents.Delegates.Functionality.ButtonFunctionality(null, null, null), false, components); + + //Change this to take the vocalization menu instead + List> modTabs = new List>(); + modTabs.Add(new KeyValuePair(menuTab, new IClickableMenuExtended(0, 0, 300, 300,false))); + + StardustCore.Menus.ModularGameMenu.StaticMenuTabsAndPages[ModManifest.UniqueID] = modTabs; + } + public static object GetInstanceField(Type type, object instance, string fieldName) { BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; @@ -499,9 +589,11 @@ namespace Vocalization { string basePath = ModHelper.DirectoryPath; string contentPath = Path.Combine(basePath, "Content"); + string graphicsPath = Path.Combine(contentPath, "Graphics"); string audioPath = Path.Combine(contentPath, "Audio"); string voicePath = Path.Combine(audioPath, "VoiceFiles"); + if (!Directory.Exists(graphicsPath)) Directory.CreateDirectory(graphicsPath); VoicePath = voicePath; //Set a static reference to my voice files directory. diff --git a/GeneralMods/Vocalization/Vocalization/Vocalization.csproj b/GeneralMods/Vocalization/Vocalization/Vocalization.csproj index b2b86b6a..80d9bcd3 100644 --- a/GeneralMods/Vocalization/Vocalization/Vocalization.csproj +++ b/GeneralMods/Vocalization/Vocalization/Vocalization.csproj @@ -61,7 +61,23 @@ - + + + {0756D36A-95C8-480D-8EA6-4584C03010C6} + StardustCore + + + + + + + + Always + + + Always + + @@ -69,5 +85,7 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + \ No newline at end of file diff --git a/GeneralMods/Vocalization/Vocalization/packages.config b/GeneralMods/Vocalization/Vocalization/packages.config index 33db9a9b..28b59b1d 100644 --- a/GeneralMods/Vocalization/Vocalization/packages.config +++ b/GeneralMods/Vocalization/Vocalization/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file