public static void AddQuestTagsToTextTable(string s, TextTable textTable) { if (textTable == null || !ContainsAnyTag(s)) { return; } foreach (Match match in Regex.Matches(s, @"\{[^\}]+\}")) { var tag = match.Value; if (IsDynamicTag(tag) || IsIDTag(tag) || tag.Length < 2) { continue; } var fieldName = tag.Substring(1, tag.Length - 2); if (!textTable.HasField(fieldName)) { textTable.AddField(fieldName); } } }
/// <summary> /// Associates tags in a tag dictionary with values from a primary text table /// (i.e., quest giver's text table), or failing that QuestMachine's default text /// table, or failing that the tag name itself. Leaves ID tags such as {QUESTERID} /// untouched. /// </summary> /// <param name="tagDictionary">The tag dictionary containing tags that need values assigned.</param> /// <param name="textTable">The primary text table from which to look up values.</param> public static void AddTagValuesToDictionary(TagDictionary tagDictionary, TextTable textTable) { if (tagDictionary == null) { return; } var newDict = new Dictionary <string, string>(); foreach (var kvp in tagDictionary.dict) { var tag = kvp.Key; if (string.IsNullOrEmpty(tag) || tag.Length <= 2) { continue; } if (IsIDTag(tag)) { // Leave ID tags untouched: newDict.Add(tag, kvp.Value); continue; } var fieldName = tag.Substring(1, tag.Length - 2).Trim(); if (textTable != null && textTable.HasField(fieldName)) { // Check in current text table; newDict.Add(tag, PrepareFieldText(textTable.GetFieldText(fieldName))); } else if (QuestMachine.textTable != null && QuestMachine.textTable.HasField(fieldName)) { // Otherwise look in QuestMachine's text table: newDict.Add(tag, PrepareFieldText(QuestMachine.textTable.GetFieldText(fieldName))); } else { // Otherwise use the tag's text: newDict.Add(tag, fieldName); } } tagDictionary.dict = newDict; }
public virtual void LocalizeText() { if (!started) { return; } // Skip if no language set: if (string.IsNullOrEmpty(PixelCrushers.DialogueSystem.Localization.language)) { return; } if (textTable == null) { textTable = DialogueManager.displaySettings.localizationSettings.textTable; if (textTable == null) { if (DialogueDebug.logWarnings) { Debug.LogWarning(DialogueDebug.Prefix + ": No localized text table is assigned to " + name + " or the Dialogue Manager.", this); } return; } } if (!HasCurrentLanguage()) { if (DialogueDebug.logWarnings) { Debug.LogWarning(DialogueDebug.Prefix + "Localized text table '" + textTable + "' does not have a language '" + PixelCrushers.DialogueSystem.Localization.language + "'", this); } return; } // Make sure we have a Text or Dropdown: if (text == null && dropdown == null) { text = GetComponent <UnityEngine.UI.Text>(); dropdown = GetComponent <UnityEngine.UI.Dropdown>(); if (text == null && dropdown == null) { if (DialogueDebug.logWarnings) { Debug.LogWarning(DialogueDebug.Prefix + ": LocalizeUIText didn't find a Text or Dropdown component on " + name + ".", this); } return; } } // Get the original values to use as field lookups: if (string.IsNullOrEmpty(fieldName)) { fieldName = (text != null) ? text.text : string.Empty; } if ((fieldNames.Count == 0) && (dropdown != null)) { dropdown.options.ForEach(opt => fieldNames.Add(opt.text)); } // Localize Text: if (text != null) { if (!textTable.HasField(fieldName)) { if (DialogueDebug.logWarnings) { Debug.LogWarning(DialogueDebug.Prefix + ": Localized text table '" + textTable.name + "' does not have a field: " + fieldName, this); } } else { text.text = textTable.GetFieldTextForLanguage(fieldName, Localization.GetCurrentLanguageID(textTable)); } } // Localize Dropdown: if (dropdown != null) { for (int i = 0; i < dropdown.options.Count; i++) { if (i < fieldNames.Count) { dropdown.options[i].text = textTable.GetFieldTextForLanguage(fieldNames[i], Localization.GetCurrentLanguageID(textTable)); } } dropdown.captionText.text = textTable.GetFieldTextForLanguage(fieldNames[dropdown.value], Localization.GetCurrentLanguageID(textTable)); } }