From d6280b5c1b3c95d0f77c17b5730d3599c8662126 Mon Sep 17 00:00:00 2001 From: Date: Tue, 18 Sep 2018 18:04:38 -0700 Subject: [PATCH] Working on updates to happy birthday. Trying to add in more language support and spouse birthday wishes as well as a more modify-able birthday dialogue file. --- GeneralMods/HappyBirthday/BirthdayMessages.cs | 158 +++++++++++ .../HappyBirthday/Framework/ModConfig.cs | 45 +++- .../Framework/TranslationInfo.cs | 252 ++++++++++++++++++ GeneralMods/HappyBirthday/HappyBirthday.cs | 190 ++++++++----- .../HappyBirthday/HappyBirthday.csproj | 3 + GeneralMods/HappyBirthday/packages.config | 1 + .../StardustCore/Menus/ModualGameMenu.cs | 8 +- GeneralMods/StardustCore/ModCore.cs | 2 +- GeneralMods/StardustCore/manifest.json | 2 +- 9 files changed, 588 insertions(+), 73 deletions(-) create mode 100644 GeneralMods/HappyBirthday/BirthdayMessages.cs create mode 100644 GeneralMods/HappyBirthday/Framework/TranslationInfo.cs diff --git a/GeneralMods/HappyBirthday/BirthdayMessages.cs b/GeneralMods/HappyBirthday/BirthdayMessages.cs new file mode 100644 index 00000000..fd9c0b00 --- /dev/null +++ b/GeneralMods/HappyBirthday/BirthdayMessages.cs @@ -0,0 +1,158 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Omegasis.HappyBirthday +{ + public class BirthdayMessages + { + /// + /// The actual birthday wishes given by an npc. + /// + public Dictionary birthdayWishes; + + public Dictionary spouseBirthdayWishes; + + /// + /// TODO: Make this. + /// + public Dictionary defaultSpouseBirthdayWishes = new Dictionary() + { + ["Alex"] = "", + ["Elliott"] = "", + ["Harvey"] = "", + ["Sam"] = "", + ["Sebastian"] = "", + ["Shane"] = "", + ["Abigail"] = "", + ["Emily"] = "", + ["Haley"] = "", + ["Leah"] = "", + ["Maru"] = "", + ["Penny"] = "", + }; + + /// + /// Used to contain + /// + private Dictionary defaultBirthdayWishes = new Dictionary() + { + ["Robin"] = "Hey @, happy birthday! I'm glad you choose this town to move here to. ", + ["Demetrius"] = "Happy birthday @! Make sure you take some time off today to enjoy yourself. $h", + ["Maru"] = "Happy birthday @. I tried to make you an everlasting candle for you, but sadly that didn't work out. Maybe next year right? $h", + ["Sebastian"] = "Happy birthday @. Here's to another year of chilling. ", + ["Linus"] = "Happy birthday @. Thanks for visiting me even on your birthday. It makes me really happy. ", + ["Pierre"] = "Hey @, happy birthday! Hopefully this next year for you will be a great one! ", + ["Caroline"] = "Happy birthday @. Thank you for all that you've done for our community. I'm sure your parents must be proud of you.$h", + ["Abigail"] = "Happy birthday @! Hopefully this year we can go on even more adventures together $h!", + ["Alex"] = "Yo @, happy birthday! Maybe this will be your best year yet.$h", + ["George"] = "When you get to my age birthdays come and go. Still happy birthday @.", + ["Evelyn"] = "Happy birthday @. You have grown up to be such a fine individual and I'm sure you'll continue to grow. ", + ["Lewis"] = "Happy birthday @! I'm thankful for what you have done for the town and I'm sure your grandfather would be proud of you.", + ["Clint"] = "Hey happy birthday @. I'm sure this year is going to be great for you.", + ["Penny"] = "Happy birthday @. May you enjoy all of life's blessings this year. ", + ["Pam"] = "Happy birthday kid. We should have a drink to celebrate another year of life for you! $h", + ["Emily"] = "I'm sensing a strong positive life energy about you, so it must be your birthday. Happy birthday @!$h", + ["Haley"] = "Happy birthday @. Hopefully this year you'll get some good presents!$h", + ["Jas"] = "Happy birthday @. I hope you have a good birthday.", + ["Vincent"] = "Hey @ have you come to pl...oh it's your birthday? Happy birthday! ", + ["Jodi"] = "Hello there @. Rumor has it that today is your birthday. In that case, happy birthday!$h", + ["Kent"] = "Jodi told me that it was your birthday today @. Happy birthday and make sure to cherish every single day.", + ["Sam"] = "Yo @ happy birthday! We'll have to have a birthday jam session for you some time!$h ", + ["Leah"] = "Hey @ happy birthday! We should go to the saloon tonight and celebrate!$h ", + ["Shane"] = "Happy birthday @. Keep working hard and I'm sure this next year for you will be a great one.", + ["Marnie"] = "Hello there @. Everyone is talking about your birthday today and I wanted to make sure that I wished you a happy birthday as well, so happy birthday! $h ", + ["Elliott"] = "What a wonderful day isn't it @? Especially since today is your birthday. I tried to make you a poem but I feel like the best way of putting it is simply, happy birthday. $h ", + ["Gus"] = "Hey @ happy birthday! Hopefully you enjoy the rest of the day and make sure you aren't a stranger at the saloon!", + ["Dwarf"] = "Happy birthday @. I hope that what I got you is acceptable for humans as well. ", + ["Wizard"] = "The spirits told me that today is your birthday. In that case happy birthday @. ", + ["Harvey"] = "Hey @, happy birthday! Make sure to come in for a checkup some time to make sure you live many more years! ", + ["Sandy"] = "Hello there @. I heard that today was your birthday and I didn't want you feeling left out, so happy birthday!", + ["Willy"] = "Aye @ happy birthday. Looking at you reminds me of ye days when I was just a guppy swimming out to sea. Continue to enjoy them youngin.$h", + ["Krobus"] = "I have heard that it is tradition to give a gift to others on their birthday. In that case, happy birthday @." + }; + + /// + /// Used to load all of the default birthday greetings. + /// + private void createBirthdayGreetings() + { + + var serializer = JsonSerializer.Create(); + serializer.Formatting = Formatting.Indented; + + //English logic. + string defaultPath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", "English"); + if (!Directory.Exists(defaultPath)) Directory.CreateDirectory(defaultPath); + + string birthdayFileDict=HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); + string path = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue","English", birthdayFileDict); + + //Handle normal birthday wishes. + if (!File.Exists(path)) + { + + StreamWriter writer = new StreamWriter(path); + serializer.Serialize(writer, defaultBirthdayWishes); + this.birthdayWishes = defaultBirthdayWishes; + } + else + { + StreamReader reader = new StreamReader(path); + birthdayWishes = new Dictionary(); + birthdayWishes = (Dictionary)serializer.Deserialize(reader, typeof(Dictionary)); + } + + //handle spouse birthday wishes. + string spouseBirthdayFileDict = HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); + string spousePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue","English",spouseBirthdayFileDict); + if (!File.Exists(path)) + { + + StreamWriter writer = new StreamWriter(spousePath); + serializer.Serialize(writer, defaultSpouseBirthdayWishes); + this.spouseBirthdayWishes = defaultSpouseBirthdayWishes; + } + else + { + StreamReader reader = new StreamReader(path); + birthdayWishes = new Dictionary(); + birthdayWishes = (Dictionary)serializer.Deserialize(reader, typeof(Dictionary)); + } + + //Non-english logic + foreach(var translation in HappyBirthday.Config.translationInfo.translationCodes) + { + if (translation.Key == "English") continue; + string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", translation.Key); + if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); + string tempBirthdayFile =Path.Combine(basePath,HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", translation.Key)); + string tempSpouseBirthdayFile =Path.Combine(basePath,HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", translation.Key)); + + + Dictionary tempBirthdayDict = new Dictionary(); + foreach(var pair in defaultBirthdayWishes) + { + tempBirthdayDict.Add(pair.Key, ""); + } + StreamWriter writer = new StreamWriter(tempBirthdayFile); + serializer.Serialize(writer, tempBirthdayDict); + + + Dictionary tempSpouseBirthdayDict = new Dictionary(); + foreach (var pair in defaultSpouseBirthdayWishes) + { + tempSpouseBirthdayDict.Add(pair.Key, ""); + } + StreamWriter writer2 = new StreamWriter(tempSpouseBirthdayFile); + serializer.Serialize(writer, tempSpouseBirthdayDict); + } + } + + + } +} diff --git a/GeneralMods/HappyBirthday/Framework/ModConfig.cs b/GeneralMods/HappyBirthday/Framework/ModConfig.cs index db05d90f..efbc1955 100644 --- a/GeneralMods/HappyBirthday/Framework/ModConfig.cs +++ b/GeneralMods/HappyBirthday/Framework/ModConfig.cs @@ -1,9 +1,52 @@ namespace Omegasis.HappyBirthday.Framework { /// The mod configuration. - internal class ModConfig + public class ModConfig { /// The key which shows the menu. public string KeyBinding { get; set; } = "O"; + + /// + /// The minimum amount of friendship needed to get a birthday gift. + /// + public int minNeutralFriendshipGiftLevel = 3; + + /// + /// The max amount of friendship needed to get a neutral gift from an npc. + /// + public int maxNeutralFriendshipGiftLevel = 4; + + /// + ///The minimum amount of friendship to get a like gift from an npc. + /// + public int minLikeFriendshipLevel = 5; + + /// + /// The max amount of friendship needed to get a liked gift from an npc. + /// + public int maxLikeFriendshipLevel = 6; + + /// + /// The minimum amount of friendship needed to get a loved gift from an npc. + /// + public int minLoveFriendshipLevel = 7; + + /// + /// The minimum amount of friendship needed to get a happy birthday greeting from an npc. + /// + public int minimumFriendshipLevelForBirthdayWish=2; + + /// + /// Handles different translations of files. + /// + public TranslationInfo translationInfo; + + /// + /// Constructor. + /// + public ModConfig() + { + this.translationInfo = new TranslationInfo(); + } } } diff --git a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs new file mode 100644 index 00000000..8f5c38bb --- /dev/null +++ b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs @@ -0,0 +1,252 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Omegasis.HappyBirthday.Framework +{ + /// + /// A class which deals with handling different translations for Vocalization should other voice teams ever wish to voice act for that language. + /// + public class TranslationInfo + { + /// + /// The list of all supported translations by this mod. + /// + public List translations; + + /// + /// The current translation mode for the mod, so that it knows what files to load at the beginning of the game. + /// + public string currentTranslation; + + /// + /// Holds the info for what translation has what file extension. + /// + public Dictionary translationFileInfo; + + + public Dictionary translationCodes; + /// + /// Default constructor. + /// + public TranslationInfo() + { + translations = new List(); + + translationFileInfo = new Dictionary(); + translationCodes = new Dictionary(); + translations.Add("English"); + translations.Add("Spanish"); + translations.Add("Chinese"); + translations.Add("Japanese"); + translations.Add("Russian"); + translations.Add("German"); + translations.Add("Brazillian Portuguese"); + + currentTranslation = "English"; + + translationFileInfo.Add("English", ".json"); + translationFileInfo.Add("Spanish", ".es-ES.json"); + translationFileInfo.Add("Chinese", ".zh-CN.json"); + translationFileInfo.Add("Japanese", ".ja-JP.json"); + translationFileInfo.Add("Russian", ".ru-RU.json"); + translationFileInfo.Add("German", ".de-DE.json"); + translationFileInfo.Add("Brazillian Portuguese", ".pt-BR.json"); + + + translationCodes.Add("English", LocalizedContentManager.LanguageCode.en); + translationCodes.Add("Spanish", LocalizedContentManager.LanguageCode.es); + translationCodes.Add("Chinese", LocalizedContentManager.LanguageCode.zh); + translationCodes.Add("Japanese", LocalizedContentManager.LanguageCode.ja); + translationCodes.Add("Russian", LocalizedContentManager.LanguageCode.ru); + translationCodes.Add("German", LocalizedContentManager.LanguageCode.de); + translationCodes.Add("Brazillian Portuguese", LocalizedContentManager.LanguageCode.pt); + + } + + public string getTranslationNameFromPath(string fullPath) + { + return Path.GetFileName(fullPath); + } + + + public void changeLocalizedContentManagerFromTranslation(string translation) + { + string tra = getTranslationNameFromPath(translation); + bool f = translationCodes.TryGetValue(tra, out LocalizedContentManager.LanguageCode code); + if (f == false) LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; + else LocalizedContentManager.CurrentLanguageCode = code; + return; + } + + public void resetLocalizationCode() + { + LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; + } + + /// + /// Gets the proper file extension for the current translation. + /// + /// + /// + public string getFileExtentionForTranslation(string path) + { + /* + bool f = translationFileInfo.TryGetValue(translation, out string value); + if (f == false) return ".json"; + else return value; + */ + string translation = Path.GetFileName(path); + try + { + return translationFileInfo[translation]; + } + catch (Exception err) + { + + //Vocalization.ModMonitor.Log(err.ToString()); + //Vocalization.ModMonitor.Log("Attempted to get translation: " + translation); + return ".json"; + } + } + + /// + /// Gets the proper json for Buildings (aka Blueprints) from the data folder. + /// + /// + /// + public string getBuildingjsonForTranslation(string translation) + { + string buildings = "Blueprints"; + return buildings + getFileExtentionForTranslation(translation); + } + + /// + /// Gets the proper json file for the name passed in. Combines the file name with it's proper translation extension. + /// + /// + /// + /// + public string getjsonForTranslation(string jsonFileName, string translation) + { + return jsonFileName + getFileExtentionForTranslation(translation); + } + + + + /// + /// Loads an json file from StardewValley/Content + /// + /// + /// + /// + /// + public string LoadjsonFile(string jsonFileName, string key, string translation) + { + string json = jsonFileName + getFileExtentionForTranslation(translation); + Dictionary loadedDict = Game1.content.Load>(json); + + string loaded; + bool f = loadedDict.TryGetValue(key, out loaded); + if (f == false) + { + //Vocalization.ModMonitor.Log("Big issue: Key not found in file:" + json + " " + key); + return ""; + } + else return loaded; + } + + /// + /// Loads a string dictionary from a json file. + /// + /// + /// + /// + public Dictionary LoadJsonFileDictionary(string jsonFileName, string translation) + { + string json = jsonFileName + getFileExtentionForTranslation(translation); + Dictionary loadedDict = Game1.content.Load>(json); + + return loadedDict; + } + + public virtual string LoadString(string path, string translation, object sub1, object sub2, object sub3) + { + string format = this.LoadString(path, translation); + try + { + return string.Format(format, sub1, sub2, sub3); + } + catch (Exception ex) + { + } + + return format; + } + + public virtual string LoadString(string path, string translation, object sub1, object sub2) + { + string format = this.LoadString(path, translation); + try + { + return string.Format(format, sub1, sub2); + } + catch (Exception ex) + { + } + + return format; + } + + public virtual string LoadString(string path, string translation, object sub1) + { + string format = this.LoadString(path, translation); + try + { + return string.Format(format, sub1); + } + catch (Exception ex) + { + } + + return format; + } + + public virtual string LoadString(string path, string translation) + { + string assetName; + string key; + this.parseStringPath(path, out assetName, out key); + + return LoadjsonFile(assetName, key, translation); + } + + public virtual string LoadString(string path, string translation, params object[] substitutions) + { + string format = this.LoadString(path, translation); + if (substitutions.Length != 0) + { + try + { + return string.Format(format, substitutions); + } + catch (Exception ex) + { + } + } + return format; + } + + + private void parseStringPath(string path, out string assetName, out string key) + { + int length = path.IndexOf(':'); + assetName = path.Substring(0, length); + key = path.Substring(length + 1, path.Length - length - 1); + } + } +} diff --git a/GeneralMods/HappyBirthday/HappyBirthday.cs b/GeneralMods/HappyBirthday/HappyBirthday.cs index 28a5913f..6fbd4192 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.cs +++ b/GeneralMods/HappyBirthday/HappyBirthday.cs @@ -2,18 +2,22 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; using Omegasis.HappyBirthday.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; using StardewValley.Characters; +using StardewValley.Menus; using StardewValley.Monsters; using SObject = StardewValley.Object; namespace Omegasis.HappyBirthday { /// The mod entry point. - public class HappyBirthday : Mod, IAssetEditor, IAssetLoader + public class HappyBirthday : Mod, IAssetEditor { /********* ** Properties @@ -25,7 +29,7 @@ namespace Omegasis.HappyBirthday private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "Player_Birthdays", $"HappyBirthday_{Game1.player.Name}.txt"); /// The mod configuration. - private ModConfig Config; + public static ModConfig Config; /// The data for the current player. private PlayerData PlayerData; @@ -46,52 +50,6 @@ namespace Omegasis.HappyBirthday private bool CheckedForBirthday; //private Dictionary Dialogue; //private bool SeenEvent; - public bool CanLoad(IAssetInfo asset) - { - return asset.AssetNameEquals(@"Data\FarmerBirthdayDialogue"); - } - - /// Load a matched asset. - /// Basic metadata about the asset being loaded. - public T Load(IAssetInfo asset) - { - return (T)(object)new Dictionary // (T)(object) is a trick to cast anything to T if we know it's compatible - { - ["Robin"] = "Hey @, happy birthday! I'm glad you choose this town to move here to. ", - ["Demetrius"] = "Happy birthday @! Make sure you take some time off today to enjoy yourself. $h", - ["Maru"] = "Happy birthday @. I tried to make you an everlasting candle for you, but sadly that didn't work out. Maybe next year right? $h", - ["Sebastian"] = "Happy birthday @. Here's to another year of chilling. ", - ["Linus"] = "Happy birthday @. Thanks for visiting me even on your birthday. It makes me really happy. ", - ["Pierre"] = "Hey @, happy birthday! Hopefully this next year for you will be a great one! ", - ["Caroline"] = "Happy birthday @. Thank you for all that you've done for our community. I'm sure your parents must be proud of you.$h", - ["Abigail"] = "Happy birthday @! Hopefully this year we can go on even more adventures together $h!", - ["Alex"] = "Yo @, happy birthday! Maybe this will be your best year yet.$h", - ["George"] = "When you get to my age birthdays come and go. Still happy birthday @.", - ["Evelyn"] = "Happy birthday @. You have grown up to be such a fine individual and I'm sure you'll continue to grow. ", - ["Lewis"] = "Happy birthday @! I'm thankful for what you have done for the town and I'm sure your grandfather would be proud of you.", - ["Clint"] = "Hey happy birthday @. I'm sure this year is going to be great for you.", - ["Penny"] = "Happy birthday @. May you enjoy all of life's blessings this year. ", - ["Pam"] = "Happy birthday kid. We should have a drink to celebrate another year of life for you! $h", - ["Emily"] = "I'm sensing a strong positive life energy about you, so it must be your birthday. Happy birthday @!$h", - ["Haley"] = "Happy birthday @. Hopefully this year you'll get some good presents!$h", - ["Jas"] = "Happy birthday @. I hope you have a good birthday.", - ["Vincent"] = "Hey @ have you come to pl...oh it's your birthday? Happy birthday! ", - ["Jodi"] = "Hello there @. Rumor has it that today is your birthday. In that case, happy birthday!$h", - ["Kent"] = "Jodi told me that it was your birthday today @. Happy birthday and make sure to cherish every single day.", - ["Sam"] = "Yo @ happy birthday! We'll have to have a birthday jam session for you some time!$h ", - ["Leah"] = "Hey @ happy birthday! We should go to the saloon tonight and celebrate!$h ", - ["Shane"] = "Happy birthday @. Keep working hard and I'm sure this next year for you will be a great one.", - ["Marnie"] = "Hello there @. Everyone is talking about your birthday today and I wanted to make sure that I wished you a happy birthday as well, so happy birthday! $h ", - ["Elliott"] = "What a wonderful day isn't it @? Especially since today is your birthday. I tried to make you a poem but I feel like the best way of putting it is simply, happy birthday. $h ", - ["Gus"] = "Hey @ happy birthday! Hopefully you enjoy the rest of the day and make sure you aren't a stranger at the saloon!", - ["Dwarf"] = "Happy birthday @. I hope that what I got you is acceptable for humans as well. ", - ["Wizard"] = "The spirits told me that today is your birthday. In that case happy birthday @. ", - ["Harvey"] = "Hey @, happy birthday! Make sure to come in for a checkup some time to make sure you live many more years! ", - ["Sandy"] = "Hello there @. I heard that today was your birthday and I didn't want you feeling left out, so happy birthday!", - ["Willy"] = "Aye @ happy birthday. Looking at you reminds me of ye days when I was just a guppy swimming out to sea. Continue to enjoy them youngin.$h", - ["Krobus"] = "I have heard that it is tradition to give a gift to others on their birthday. In that case, happy birthday @." - }; - } public bool CanEdit(IAssetInfo asset) { @@ -109,6 +67,9 @@ namespace Omegasis.HappyBirthday .Set("birthdayDad", "Dear @,^ Happy birthday kiddo. It's been a little quiet around here on your birthday since you aren't around, but your mother and I know that you are making both your grandpa and us proud. We both know that living on your own can be tough but we believe in you one hundred percent, just keep following your dreams.^ Love, Dad ^ P.S. Here's some spending money to help you out on the farm. Good luck! %item money 5000 5001 %%"); } + public static IModHelper ModHelper; + + /********* ** Public methods @@ -125,8 +86,98 @@ namespace Omegasis.HappyBirthday SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; SaveEvents.BeforeSave += this.SaveEvents_BeforeSave; ControlEvents.KeyPressed += this.ControlEvents_KeyPressed; + MenuEvents.MenuChanged += MenuEvents_MenuChanged; + GraphicsEvents.OnPostRenderGuiEvent += GraphicsEvents_OnPostRenderGuiEvent; + StardewModdingAPI.Events.GraphicsEvents.OnPostRenderHudEvent += GraphicsEvents_OnPostRenderHudEvent; ; //MultiplayerSupport.initializeMultiplayerSupport(); + ModHelper = Helper; + } + + + /// + /// Used to properly display hovertext for all events happening on a calendar day. + /// + /// + /// + private void GraphicsEvents_OnPostRenderHudEvent(object sender, EventArgs e) + { + if (Game1.activeClickableMenu == null) return; + if (PlayerData.BirthdaySeason.ToLower() != Game1.currentSeason.ToLower()) return; + if (Game1.activeClickableMenu is Billboard) + { + int index = PlayerData.BirthdayDay; + //Game1.player.FarmerRenderer.drawMiniPortrat(Game1.spriteBatch, new Vector2(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 230 + (index - 1) / 7 * 32 * 4), 1f, 4f, 2, Game1.player); + + string hoverText = ""; + foreach (var clicky in (Game1.activeClickableMenu as Billboard).calendarDays) + { + if (clicky.containsPoint(Game1.getMouseX(), Game1.getMouseY())) + { + hoverText += clicky.hoverText + Environment.NewLine; + } + } + + if (!String.IsNullOrEmpty(hoverText)) + { + hoverText.Remove(hoverText.Length - 2, 1); + var oldText = Helper.Reflection.GetField(Game1.activeClickableMenu, "hoverText", true); + oldText.SetValue(hoverText); + } + + } + } + + /// + /// Used to show the farmer's portrait on the billboard menu. + /// + /// + /// + private void GraphicsEvents_OnPostRenderGuiEvent(object sender, EventArgs e) + { + if (Game1.activeClickableMenu == null) return; + if (PlayerData.BirthdaySeason.ToLower() != Game1.currentSeason.ToLower()) return; + if (Game1.activeClickableMenu is Billboard) + { + int index = PlayerData.BirthdayDay; + Game1.player.FarmerRenderer.drawMiniPortrat(Game1.spriteBatch, new Vector2(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 230 + (index - 1) / 7 * 32 * 4), 0.5f, 4f, 2, Game1.player); + + string hoverText = ""; + foreach(var clicky in (Game1.activeClickableMenu as Billboard).calendarDays) + { + if (clicky.containsPoint(Game1.getMouseX(), Game1.getMouseY())) + { + hoverText += clicky.hoverText+Environment.NewLine; + } + } + if (hoverText != "") + { + var oldText=Helper.Reflection.GetField(Game1.activeClickableMenu, "hoverText", true); + oldText.SetValue(hoverText); + } + + } + } + + /// + /// Functionality to display the player's birthday on the billboard. + /// + /// + /// + public void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) + { + if (Game1.activeClickableMenu == null) return; + if(Game1.activeClickableMenu is Billboard) + { + Texture2D text = new Texture2D(Game1.graphics.GraphicsDevice,1,1); + Color[] col = new Color[1]; + col[0] = new Color(0, 0, 0, 1); + text.SetData(col); + //players birthdy position rect=new .... + int index = PlayerData.BirthdayDay; + Rectangle birthdayRect = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 200 + (index - 1) / 7 * 32 * 4, 124, 124); + (Game1.activeClickableMenu as Billboard).calendarDays.Add(new ClickableTextureComponent("", birthdayRect, "", Game1.player.name + "'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false)); + } } @@ -168,7 +219,8 @@ namespace Omegasis.HappyBirthday // load settings this.MigrateLegacyData(); this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); - + + createBirthdayGreetings(); //this.SeenEvent = false; //this.Dialogue = new Dictionary(); } @@ -226,16 +278,22 @@ namespace Omegasis.HappyBirthday try { - Dialogue d = new Dialogue(Game1.content.Load>("Data\\FarmerBirthdayDialogue")[npc.Name], npc); - npc.CurrentDialogue.Push(d); - if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(Game1.content.Load>("Data\\FarmerBirthdayDialogue")[npc.Name]); + if (Game1.player.getFriendshipHeartLevelForNPC(npc.Name) >= Config.minimumFriendshipLevelForBirthdayWish) + { + Dialogue d = new Dialogue(Game1.content.Load>("Data\\FarmerBirthdayDialogue")[npc.Name], npc); + npc.CurrentDialogue.Push(d); + if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(Game1.content.Load>("Data\\FarmerBirthdayDialogue")[npc.Name]); + } } catch { - Dialogue d = new Dialogue("Happy Birthday @!", npc); - npc.CurrentDialogue.Push(d); - if (npc.CurrentDialogue.ElementAt(0) != d) - npc.setNewDialogue("Happy Birthday @!"); + if (Game1.player.getFriendshipHeartLevelForNPC(npc.Name) >= Config.minimumFriendshipLevelForBirthdayWish) + { + Dialogue d = new Dialogue("Happy Birthday @!", npc); + npc.CurrentDialogue.Push(d); + if (npc.CurrentDialogue.ElementAt(0) != d) + npc.setNewDialogue("Happy Birthday @!"); + } } } } @@ -341,7 +399,7 @@ namespace Omegasis.HappyBirthday /// Set the next birthday gift the player will receive. /// The villager's name who's giving the gift. - /// This returns gifts based on the speaker's heart level towards the player: neutral for 0-3, good for 4-6, and best for 7-10. + /// This returns gifts based on the speaker's heart level towards the player: neutral for 3-4, good for 5-6, and best for 7-10. private void SetNextBirthdayGift(string name) { Item gift; @@ -395,7 +453,7 @@ namespace Omegasis.HappyBirthday string[] fields = text.Split('/'); // love - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 7) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLoveFriendshipLevel) { string[] loveFields = fields[1].Split(' '); for (int i = 0; i < loveFields.Length; i += 2) @@ -409,7 +467,7 @@ namespace Omegasis.HappyBirthday } // like - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 4 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 6) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxLikeFriendshipLevel) { string[] likeFields = fields[3].Split(' '); for (int i = 0; i < likeFields.Length; i += 2) @@ -423,7 +481,7 @@ namespace Omegasis.HappyBirthday } // neutral - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 0 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 3) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel) { string[] neutralFields = fields[5].Split(' '); @@ -439,27 +497,27 @@ namespace Omegasis.HappyBirthday } // get NPC's preferred gifts - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 7) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLoveFriendshipLevel) gifts.AddRange(this.GetUniversalItems("Love", true)); - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 4 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 6) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxLikeFriendshipLevel) this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Like", true)); - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 0 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 3) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel) this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Neutral", true)); } catch { // get NPC's preferred gifts - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 7) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLoveFriendshipLevel) { this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Love", false)); this.PossibleBirthdayGifts.AddRange(this.GetLovedItems(name)); } - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 4 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 6) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxLikeFriendshipLevel) { this.PossibleBirthdayGifts.AddRange(this.GetLikedItems(name)); this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Like", false)); } - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 0 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 3) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel) this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Neutral", false)); } //TODO: Make different tiers of gifts depending on the friendship, and if it is the spouse. diff --git a/GeneralMods/HappyBirthday/HappyBirthday.csproj b/GeneralMods/HappyBirthday/HappyBirthday.csproj index 52734b5a..dcd531c6 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.csproj +++ b/GeneralMods/HappyBirthday/HappyBirthday.csproj @@ -71,6 +71,9 @@ MinimumRecommendedRules.ruleset + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + diff --git a/GeneralMods/HappyBirthday/packages.config b/GeneralMods/HappyBirthday/packages.config index 87b1c41e..6766c23b 100644 --- a/GeneralMods/HappyBirthday/packages.config +++ b/GeneralMods/HappyBirthday/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/GeneralMods/StardustCore/Menus/ModualGameMenu.cs b/GeneralMods/StardustCore/Menus/ModualGameMenu.cs index 32b559eb..572377d0 100644 --- a/GeneralMods/StardustCore/Menus/ModualGameMenu.cs +++ b/GeneralMods/StardustCore/Menus/ModualGameMenu.cs @@ -39,20 +39,20 @@ namespace StardustCore.Menus 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); + //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); + //ModCore.ModMonitor.Log("INITIALIZE MENU: ", LogLevel.Alert); foreach (var v in StaticMenuTabsAndPages) { - ModCore.ModMonitor.Log("LIST A GO GO", LogLevel.Alert); + //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); + //ModCore.ModMonitor.Log("ADD IN A PART", LogLevel.Alert); } //this.menuTabsAndPages.Add(v.Key,v.Value.clone()); } diff --git a/GeneralMods/StardustCore/ModCore.cs b/GeneralMods/StardustCore/ModCore.cs index 8ede36c2..73576b95 100644 --- a/GeneralMods/StardustCore/ModCore.cs +++ b/GeneralMods/StardustCore/ModCore.cs @@ -191,7 +191,7 @@ namespace StardustCore { if(e.KeyPressed.ToString()== config.modularMenuKey && Game1.activeClickableMenu==null) { - Game1.activeClickableMenu = new ModularGameMenu(0); + //Game1.activeClickableMenu = new ModularGameMenu(0); } } diff --git a/GeneralMods/StardustCore/manifest.json b/GeneralMods/StardustCore/manifest.json index af19a410..033a06b3 100644 --- a/GeneralMods/StardustCore/manifest.json +++ b/GeneralMods/StardustCore/manifest.json @@ -1,7 +1,7 @@ { "Name": "StardustCore", "Author": "Alpha_Omegasis", - "Version": "2.0.4", + "Version": "2.0.5", "Description": "A core mod that allows for other mods of mine to be run.", "UniqueID": "Omegasis.StardustCore", "EntryDll": "StardustCore.dll",