diff --git a/GeneralMods/HappyBirthday/BirthdayMessages.cs b/GeneralMods/HappyBirthday/BirthdayMessages.cs index 31ba55fe..4dc41af7 100644 --- a/GeneralMods/HappyBirthday/BirthdayMessages.cs +++ b/GeneralMods/HappyBirthday/BirthdayMessages.cs @@ -1,6 +1,11 @@ +using System; using System.Collections.Generic; using System.IO; +using System.Text; using Newtonsoft.Json; +using StardewModdingAPI; +using StardewValley; +using static StardewValley.LocalizedContentManager; namespace Omegasis.HappyBirthday { @@ -27,6 +32,8 @@ namespace Omegasis.HappyBirthday ["Penny"] = "", }; + public Dictionary> spouseEnglishGeneratedMessages = new Dictionary>(); + /// Used to contain birthday wishes should the mod not find any available. public Dictionary defaultBirthdayWishes = new Dictionary() { @@ -67,6 +74,18 @@ namespace Omegasis.HappyBirthday public BirthdayMessages() { + this.spouseEnglishGeneratedMessages.Add("Alex", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Elliott", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Harvey", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Sam", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Sebastian", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Shane", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Abigail", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Emily", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Haley", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Leah", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Maru", this.generateSpouseMessage); + this.spouseEnglishGeneratedMessages.Add("Penny", this.generateSpouseMessage); this.createBirthdayGreetings(); this.loadTranslationStrings(); } @@ -142,11 +161,11 @@ namespace Omegasis.HappyBirthday serializer.Formatting = Formatting.Indented; //English logic. - string defaultPath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation); + string defaultPath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(HappyBirthday.Config.translationInfo.CurrentTranslation)); if (!Directory.Exists(defaultPath)) Directory.CreateDirectory(defaultPath); - string birthdayFileDict = HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); - string path = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, birthdayFileDict); + string birthdayFileDict = HappyBirthday.Config.translationInfo.getJSONForTranslation("BirthdayWishes", HappyBirthday.Config.translationInfo.CurrentTranslation); + string path = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(HappyBirthday.Config.translationInfo.CurrentTranslation), birthdayFileDict); //Handle normal birthday wishes. if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, path))) @@ -159,8 +178,8 @@ namespace Omegasis.HappyBirthday this.birthdayWishes = HappyBirthday.ModHelper.Data.ReadJsonFile>(path); //handle spouse birthday wishes. - string spouseBirthdayFileDict = HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); - string spousePath = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, spouseBirthdayFileDict); + string spouseBirthdayFileDict = HappyBirthday.Config.translationInfo.getJSONForTranslation("SpouseBirthdayWishes", HappyBirthday.Config.translationInfo.CurrentTranslation); + string spousePath = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(HappyBirthday.Config.translationInfo.CurrentTranslation), spouseBirthdayFileDict); if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, spousePath))) { HappyBirthday.ModMonitor.Log("Creating Spouse Messages", StardewModdingAPI.LogLevel.Alert); @@ -171,16 +190,16 @@ namespace Omegasis.HappyBirthday this.spouseBirthdayWishes = HappyBirthday.ModHelper.Data.ReadJsonFile>(spousePath); //Non-english logic for creating templates. - foreach (var translation in HappyBirthday.Config.translationInfo.translationCodes) + foreach (var translation in HappyBirthday.Config.translationInfo.TranslationCodes) { - if (translation.Key == "English") + if (translation.Key == Framework.TranslationInfo.LanguageName.English) continue; - string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", translation.Key); + string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(translation.Key)); if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); - string tempBirthdayFile = Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", translation.Key)); - string tempSpouseBirthdayFile = Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", translation.Key)); + string tempBirthdayFile = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(translation.Key), HappyBirthday.Config.translationInfo.getJSONForTranslation("BirthdayWishes", translation.Key)); + string tempSpouseBirthdayFile = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(translation.Key), HappyBirthday.Config.translationInfo.getJSONForTranslation("SpouseBirthdayWishes", translation.Key)); Dictionary tempBirthdayDict = new Dictionary(); @@ -205,7 +224,7 @@ namespace Omegasis.HappyBirthday tempSpouseBirthdayDict = HappyBirthday.ModHelper.Data.ReadJsonFile>(tempSpouseBirthdayFile); //Set translated birthday info. - if (HappyBirthday.Config.translationInfo.currentTranslation == translation.Key) + if (HappyBirthday.Config.translationInfo.CurrentTranslation == translation.Key) { this.birthdayWishes = tempBirthdayDict; this.spouseBirthdayWishes = tempSpouseBirthdayDict; @@ -216,7 +235,7 @@ namespace Omegasis.HappyBirthday public static string GetTranslatedString(string key) { - StardewValley.LocalizedContentManager.LanguageCode code = HappyBirthday.Config.translationInfo.translationCodes[HappyBirthday.Config.translationInfo.currentTranslation]; + StardewValley.LocalizedContentManager.LanguageCode code = HappyBirthday.Config.translationInfo.TranslationCodes[HappyBirthday.Config.translationInfo.CurrentTranslation]; string value= HappyBirthday.Instance.messages.translatedStrings[code][key]; if (string.IsNullOrEmpty(value)) { @@ -235,15 +254,15 @@ namespace Omegasis.HappyBirthday { //Non-english logic for creating templates. - foreach (var translation in HappyBirthday.Config.translationInfo.translationCodes) + foreach (var translation in HappyBirthday.Config.translationInfo.TranslationCodes) { StardewValley.LocalizedContentManager.LanguageCode code = translation.Value; - string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", translation.Key); + string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(translation.Key)); if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); - string stringsFile = Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("TranslatedStrings", translation.Key)); + string stringsFile = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.getFileExtentionForDirectory(translation.Key), HappyBirthday.Config.translationInfo.getJSONForTranslation("TranslatedStrings", translation.Key)); if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, stringsFile))) @@ -256,5 +275,137 @@ namespace Omegasis.HappyBirthday } } + public string getAffectionateSpouseWord() + { + + List words = new List(); + if (Game1.player.IsMale) + { + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4507", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4509", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4511", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4514", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4515", HappyBirthday.Config.translationInfo.CurrentTranslation)); + + + } + else + { + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4512", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4513", HappyBirthday.Config.translationInfo.CurrentTranslation)); + + } + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4508", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4510", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4516", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4517", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4518", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4519", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4522", HappyBirthday.Config.translationInfo.CurrentTranslation)); + words.Add(HappyBirthday.Config.translationInfo.LoadStringFromXNBFile("StringsFromCSFiles", "NPC.cs.4523", HappyBirthday.Config.translationInfo.CurrentTranslation)); + return words[Game1.random.Next(0, words.Count - 1)]; + } + + public string getTimeOfDayString() + { + if (Game1.timeOfDay >= 600 && Game1.timeOfDay < 1200) + { + return "morning"; + } + else if (Game1.timeOfDay >= 1200 && Game1.timeOfDay < 600) + { + return "afternoon"; + } + else return "evening"; + } + + + public void generateSpouseBirthdayDialogue(string SpeakerName) + { + this.spouseEnglishGeneratedMessages[SpeakerName].Invoke(SpeakerName); + } + + /// + /// + /// + /// + /// + private string generateSpouseMessage(string SpeakerName) + { + StringBuilder b = new StringBuilder(); + switch (SpeakerName) + { + case ("Alex"): + b.Append("Hey "); + b.Append(this.getAffectionateSpouseWord()); + b.Append("."); + b.Append("I'm so glad that I married you. You make every day feel like winning a sports match. Happy birthday! $h"); + + break; + case ("Elliott"): + b.Append("Good "); + b.Append(this.getTimeOfDayString()); + b.Append(this.getAffectionateSpouseWord()); + b.Append("."); + b.Append("I was just thinking on how you have been a muse for my work. You inspire me every day I spend with you. Happy birthday! $h"); + + break; + case ("Harvey"): + b.Append("Good "); + b.Append(this.getTimeOfDayString()); + b.Append(this.getAffectionateSpouseWord()); + b.Append("."); + b.Append("I was just thinking on how invigorated I've felt since marrying you. When I look at you I feel as I'm positively glowing with joy. Happy birthday! $h"); + + break; + case ("Sam"): + b.Append("Good "); + b.Append(this.getTimeOfDayString()); + b.Append(this.getAffectionateSpouseWord()); + b.Append("."); + b.Append("You know I never saw myself settling down before I met you, but now that I have I feel like I never want to look back. Happy birthday! $h"); + + break; + case ("Sebastian"): + b.Append("I was never a big celebrater of birthdays but with you, today is special. Happy birthday"); + b.Append(this.getAffectionateSpouseWord()); + b.Append("$h"); + b.Append("."); + + break; + case ("Shane"): + + + break; + case ("Abigail"): + + + break; + case ("Emily"): + + + break; + case ("Haley"): + + + break; + case ("Leah"): + + + break; + case ("Maru"): + + + break; + case ("Penny"): + + + break; + default: + + break; + } + return b.ToString(); + } } } diff --git a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs index d534dd4d..2c5e2faf 100644 --- a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs +++ b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs @@ -1,5 +1,6 @@ +using System; using System.Collections.Generic; -using System.IO; +using System.Linq; using StardewValley; namespace Omegasis.HappyBirthday.Framework @@ -7,65 +8,85 @@ 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; + + public enum LanguageName + { + English, + Spanish, + Chinese, + Japanese, + Russian, + German, + Portuguese, + Italian, + French, + Korean, + Turkish, + Hungarian + } + /********* + ** Accessors + *********/ + /// The language names supported by this mod. + public LanguageName[] LanguageNames { get; } = (from LanguageName language in Enum.GetValues(typeof(LanguageName)) select language).ToArray(); /// The current translation mode for the mod, so that it knows what files to load at the beginning of the game. - public string currentTranslation; + public LanguageName CurrentTranslation { get; set; } = LanguageName.English; /// Holds the info for what translation has what file extension. - public Dictionary translationFileInfo; + public Dictionary TranslationFileExtensions { get; } = new Dictionary(); - public Dictionary translationCodes; + public Dictionary TranslationCodes { get; } = new Dictionary(); - /// Construct an instance.. + + /********* + ** Public methods + *********/ + /// Construct an instance. public TranslationInfo() { - this.translations = new List(); - - this.translationFileInfo = new Dictionary(); - this.translationCodes = new Dictionary(); - this.translations.Add("English"); - this.translations.Add("Spanish"); - this.translations.Add("Chinese"); - this.translations.Add("Japanese"); - this.translations.Add("Russian"); - this.translations.Add("German"); - this.translations.Add("Brazillian Portuguese"); - - this.currentTranslation = "English"; - - this.translationFileInfo.Add("English", ".json"); - this.translationFileInfo.Add("Spanish", ".es-ES.json"); - this.translationFileInfo.Add("Chinese", ".zh-CN.json"); - this.translationFileInfo.Add("Japanese", ".ja-JP.json"); - this.translationFileInfo.Add("Russian", ".ru-RU.json"); - this.translationFileInfo.Add("German", ".de-DE.json"); - this.translationFileInfo.Add("Brazillian Portuguese", ".pt-BR.json"); + this.TranslationFileExtensions.Add(LanguageName.English, ".xnb"); + this.TranslationFileExtensions.Add(LanguageName.Spanish, ".es-ES.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Chinese, ".zh-CN.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Japanese, ".ja-JP.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Russian, ".ru-RU.xnb"); + this.TranslationFileExtensions.Add(LanguageName.German, ".de-DE.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Portuguese, ".pt-BR.xnb"); + //1.3 languages. + this.TranslationFileExtensions.Add(LanguageName.Italian, ".it-IT.xnb"); + this.TranslationFileExtensions.Add(LanguageName.French, ".fr-FR.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Hungarian, ".hu-HU.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Turkish, ".tr-TR.xnb"); + this.TranslationFileExtensions.Add(LanguageName.Korean, ".ko-KR.xnb"); - this.translationCodes.Add("English", LocalizedContentManager.LanguageCode.en); - this.translationCodes.Add("Spanish", LocalizedContentManager.LanguageCode.es); - this.translationCodes.Add("Chinese", LocalizedContentManager.LanguageCode.zh); - this.translationCodes.Add("Japanese", LocalizedContentManager.LanguageCode.ja); - this.translationCodes.Add("Russian", LocalizedContentManager.LanguageCode.ru); - this.translationCodes.Add("German", LocalizedContentManager.LanguageCode.de); - this.translationCodes.Add("Brazillian Portuguese", LocalizedContentManager.LanguageCode.pt); - + this.TranslationCodes.Add(LanguageName.English, LocalizedContentManager.LanguageCode.en); + this.TranslationCodes.Add(LanguageName.Spanish, LocalizedContentManager.LanguageCode.es); + this.TranslationCodes.Add(LanguageName.Chinese, LocalizedContentManager.LanguageCode.zh); + this.TranslationCodes.Add(LanguageName.Japanese, LocalizedContentManager.LanguageCode.ja); + this.TranslationCodes.Add(LanguageName.Russian, LocalizedContentManager.LanguageCode.ru); + this.TranslationCodes.Add(LanguageName.German, LocalizedContentManager.LanguageCode.de); + this.TranslationCodes.Add(LanguageName.Portuguese, LocalizedContentManager.LanguageCode.pt); + //1.3 languages + this.TranslationCodes.Add(LanguageName.Italian, LocalizedContentManager.LanguageCode.it); + this.TranslationCodes.Add(LanguageName.French, LocalizedContentManager.LanguageCode.fr); + this.TranslationCodes.Add(LanguageName.Hungarian, LocalizedContentManager.LanguageCode.hu); + this.TranslationCodes.Add(LanguageName.Turkish, LocalizedContentManager.LanguageCode.tr); + this.TranslationCodes.Add(LanguageName.Korean, LocalizedContentManager.LanguageCode.ko); } - public string getTranslationNameFromPath(string fullPath) + /// Get the language name from a string. + /// The language name. + public string getTranslationName(LanguageName language) { - return Path.GetFileName(fullPath); + return language.ToString(); } - public void changeLocalizedContentManagerFromTranslation(string translation) + public void changeLocalizedContentManagerFromTranslation(LanguageName language) { - string tra = this.getTranslationNameFromPath(translation); - bool f = this.translationCodes.TryGetValue(tra, out LocalizedContentManager.LanguageCode code); - if (!f) LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; - else LocalizedContentManager.CurrentLanguageCode = code; - return; + LocalizedContentManager.CurrentLanguageCode = !this.TranslationCodes.TryGetValue(language, out LocalizedContentManager.LanguageCode code) + ? LocalizedContentManager.LanguageCode.en + : code; } public void resetLocalizationCode() @@ -74,77 +95,75 @@ namespace Omegasis.HappyBirthday.Framework } /// Gets the proper file extension for the current translation. - /// - public string getFileExtentionForTranslation(string path) + /// The translation language name. + public string getFileExtentionForTranslation(LanguageName language) { - /* - bool f = translationFileInfo.TryGetValue(translation, out string value); - if (!f) return ".json"; - else return value; - */ - string translation = Path.GetFileName(path); try { - return this.translationFileInfo[translation]; + return this.TranslationFileExtensions[language]; } - catch + catch (Exception err) { - HappyBirthday.ModMonitor.Log("WTF SOMETHING IS WRONG!", StardewModdingAPI.LogLevel.Warn); - //Vocalization.ModMonitor.Log(err.ToString()); - //Vocalization.ModMonitor.Log("Attempted to get translation: " + translation); - return ".json"; + + Omegasis.HappyBirthday.HappyBirthday.ModMonitor.Log(err.ToString()); + Omegasis.HappyBirthday.HappyBirthday.ModMonitor.Log($"Attempted to get translation: {language}"); + return ".xnb"; } } - /// Gets the proper json for Buildings (aka Blueprints) from the data folder. - public string getBuildingjsonForTranslation(string translation) + public string getFileExtentionForDirectory(LanguageName language) + { + try + { + string s=this.TranslationFileExtensions[language]; + s = s.Replace(".xnb", ""); + s = s.Replace(".",""); + return s; + } + catch (Exception err) + { + + Omegasis.HappyBirthday.HappyBirthday.ModMonitor.Log(err.ToString()); + Omegasis.HappyBirthday.HappyBirthday.ModMonitor.Log($"Attempted to get translation: {language}"); + return ".xnb"; + } + } + + /// Gets the proper XNB for Buildings (aka Blueprints) from the data folder. + public string getBuildingXNBForTranslation(LanguageName language) { string buildings = "Blueprints"; - return buildings + this.getFileExtentionForTranslation(translation); + return buildings + this.getFileExtentionForTranslation(language); } - /// 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) + /// Gets the proper XNB file for the name passed in. Combines the file name with it's proper translation extension. + public string getXNBForTranslation(string xnbFileName, LanguageName language) { - return jsonFileName + this.getFileExtentionForTranslation(translation); + return xnbFileName + this.getFileExtentionForTranslation(language); } - - - /// Loads an json file from StardewValley/Content - /// - /// - /// - public string LoadjsonFile(string jsonFileName, string key, string translation) + public string getJSONForTranslation(string FileName,LanguageName language) { - string json = jsonFileName + this.getFileExtentionForTranslation(translation); - Dictionary loadedDict = Game1.content.Load>(json); + return this.getXNBForTranslation(FileName, language); + } - bool f = loadedDict.TryGetValue(key, out string loaded); - if (!f) + /// Loads an XNB file from StardewValley/Content + public string LoadStringFromXNBFile(string xnbFileName, string key, LanguageName language) + { + string xnb = xnbFileName + this.getFileExtentionForTranslation(language); + Dictionary loadedDict = Game1.content.Load>(xnb); + + if (!loadedDict.TryGetValue(key, out string loaded)) { - //Vocalization.ModMonitor.Log("Big issue: Key not found in file:" + json + " " + key); + Omegasis.HappyBirthday.HappyBirthday.ModMonitor.Log("Big issue: Key not found in file:" + xnb + " " + key); return ""; } - else return loaded; + return loaded; } - /// Loads a string dictionary from a json file. - /// - /// - public Dictionary LoadJsonFileDictionary(string jsonFileName, string translation) + public virtual string LoadString(string path, LanguageName language, object sub1, object sub2, object sub3) { - string json = jsonFileName + this.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); + string format = this.LoadString(path, language); try { return string.Format(format, sub1, sub2, sub3); @@ -154,9 +173,9 @@ namespace Omegasis.HappyBirthday.Framework return format; } - public virtual string LoadString(string path, string translation, object sub1, object sub2) + public virtual string LoadString(string path, LanguageName language, object sub1, object sub2) { - string format = this.LoadString(path, translation); + string format = this.LoadString(path, language); try { return string.Format(format, sub1, sub2); @@ -166,9 +185,9 @@ namespace Omegasis.HappyBirthday.Framework return format; } - public virtual string LoadString(string path, string translation, object sub1) + public virtual string LoadString(string path, LanguageName language, object sub1) { - string format = this.LoadString(path, translation); + string format = this.LoadString(path, language); try { return string.Format(format, sub1); @@ -178,15 +197,16 @@ namespace Omegasis.HappyBirthday.Framework return format; } - public virtual string LoadString(string path, string translation) + public virtual string LoadString(string path, LanguageName language) { this.parseStringPath(path, out string assetName, out string key); - return this.LoadjsonFile(assetName, key, translation); + + return this.LoadStringFromXNBFile(assetName, key, language); } - public virtual string LoadString(string path, string translation, params object[] substitutions) + public virtual string LoadString(string path, LanguageName language, params object[] substitutions) { - string format = this.LoadString(path, translation); + string format = this.LoadString(path, language); if (substitutions.Length != 0) { try diff --git a/GeneralMods/HappyBirthday/HappyBirthday.cs b/GeneralMods/HappyBirthday/HappyBirthday.cs index f212612c..8bc4921f 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.cs +++ b/GeneralMods/HappyBirthday/HappyBirthday.cs @@ -301,8 +301,11 @@ namespace Omegasis.HappyBirthday if (this.PlayerData.BirthdaySeason.ToLower() == Game1.currentSeason.ToLower()) { int index = this.PlayerData.BirthdayDay; + + string bdayDisplay = Game1.content.LoadString("Strings\\UI:Billboard_Birthday"); Rectangle birthdayRect = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 200 + (index - 1) / 7 * 32 * 4, 124, 124); - billboard.calendarDays.Add(new ClickableTextureComponent("", birthdayRect, "", $"{Game1.player.Name}'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false)); + billboard.calendarDays.Add(new ClickableTextureComponent("", birthdayRect, "", string.Format(bdayDisplay, Game1.player.Name), text, new Rectangle(0, 0, 124, 124), 1f, false)); + //billboard.calendarDays.Add(new ClickableTextureComponent("", birthdayRect, "", $"{Game1.player.Name}'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false)); } } @@ -310,8 +313,10 @@ namespace Omegasis.HappyBirthday { if (pair.Value.BirthdaySeason != Game1.currentSeason.ToLower()) continue; int index = pair.Value.BirthdayDay; + + string bdayDisplay = Game1.content.LoadString("Strings\\UI:Billboard_Birthday"); Rectangle otherBirthdayRect = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 200 + (index - 1) / 7 * 32 * 4, 124, 124); - billboard.calendarDays.Add(new ClickableTextureComponent("", otherBirthdayRect, "", $"{Game1.getFarmer(pair.Key).Name}'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false)); + billboard.calendarDays.Add(new ClickableTextureComponent("", otherBirthdayRect, "", string.Format(bdayDisplay, Game1.getFarmer(pair.Key).Name), text, new Rectangle(0, 0, 124, 124), 1f, false)); } break; @@ -406,8 +411,22 @@ namespace Omegasis.HappyBirthday { if (this.messages.spouseBirthdayWishes.ContainsKey(Game1.currentSpeaker.Name)) { + if (string.IsNullOrEmpty(this.messages.spouseBirthdayWishes[Game1.currentSpeaker.Name])== false){ + d = new Dialogue(this.messages.spouseBirthdayWishes[Game1.currentSpeaker.Name], Game1.currentSpeaker); + } + else + { + if (this.messages.birthdayWishes.ContainsKey(Game1.currentSpeaker.Name)) + { - d = new Dialogue(this.messages.spouseBirthdayWishes[Game1.currentSpeaker.Name], Game1.currentSpeaker); + d = new Dialogue(this.messages.birthdayWishes[Game1.currentSpeaker.Name], Game1.currentSpeaker); + } + else + { + d = new Dialogue("Happy Birthday @!", Game1.currentSpeaker); + } + } + } else { @@ -418,7 +437,6 @@ namespace Omegasis.HappyBirthday { if (this.messages.birthdayWishes.ContainsKey(Game1.currentSpeaker.Name)) { - d = new Dialogue(this.messages.birthdayWishes[Game1.currentSpeaker.Name], Game1.currentSpeaker); } else