private static UnderFont getUnderFont(string fontName) { XmlDocument xml = new XmlDocument(); string fontPath = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".png"); string xmlPath = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".xml", false); if (xmlPath == null) { return(null); } xml.Load(xmlPath); Dictionary <char, Sprite> fontMap = loadBuiltinFont(xml["font"]["spritesheet"], fontPath); AudioClip defaultVoice = null; if (xml["font"]["voice"] != null) { defaultVoice = AudioClipRegistry.GetVoice(xml["font"]["voice"].InnerText); } UnderFont underfont = new UnderFont(fontMap, defaultVoice); if (xml["font"]["linespacing"] != null) { underfont.LineSpacing = ParseUtil.getFloat(xml["font"]["linespacing"].InnerText); } if (xml["font"]["color"] != null) { underfont.DefaultColor = ParseUtil.getColor(xml["font"]["color"].InnerText); } return(underfont); }
public void resetFont() { if (Charset == null || default_charset == null) { setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DEFAULT_NAME)); } Charset = default_charset; letterSound.clip = default_charset.Sound; }
public void setFont(UnderFont font) { Charset = font; if (default_charset == null) { default_charset = font; } letterSound.clip = Charset.Sound; currentColor = Charset.DefaultColor; }
public static int fontStringWidth(UnderFont font, string s, int hSpacing = 3) { int width = 0; foreach (char c in s) { if (font.Letters.ContainsKey(c)) { width += (int)font.Letters[c].rect.width + hSpacing; } } return(width); }
public void SetFont(string fontName, bool firstTime = false) { UnderFont uf = SpriteFontRegistry.Get(fontName); if (uf == null) { throw new CYFException("The font \"" + fontName + "\" doesn't exist.\nYou should check if you haven't made a typo or if the font really is in your mod."); } SetFont(uf, firstTime); //if (forced) // default_charset = uf; containerBubble.GetComponent <RectTransform>().localPosition = new Vector2(-12, 24); GetComponent <RectTransform>().localPosition = new Vector2(0, 16); }
private static UnderFont GetUnderFont(string fontName) { XmlDocument xml = new XmlDocument(); string fontPath = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".png"); string xmlPath = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".xml", false); if (xmlPath == null) { return(null); } try { xml.Load(xmlPath); } catch (XmlException ex) { UnitaleUtil.DisplayLuaError("Instanciating a font", "An error was encountered while loading the font \"" + fontName + "\":\n\n" + ex.Message); return(null); } if (xml["font"] == null) { UnitaleUtil.DisplayLuaError("Instanciating a font", "The font '" + fontName + "' doesn't have a font element at its root."); return(null); } Dictionary <char, Sprite> fontMap = LoadBuiltInFont(xml["font"]["spritesheet"], fontPath); UnderFont underfont; try { underfont = new UnderFont(fontMap, fontName); } catch { UnitaleUtil.DisplayLuaError("Instanciating a font", "The fonts need a space character to compute their line height, and the font '" + fontName + "' doesn't have one."); return(null); } if (xml["font"]["voice"] != null) { underfont.Sound = AudioClipRegistry.GetVoice(xml["font"]["voice"].InnerText); } if (xml["font"]["linespacing"] != null) { underfont.LineSpacing = ParseUtil.GetFloat(xml["font"]["linespacing"].InnerText); } if (xml["font"]["charspacing"] != null) { underfont.CharSpacing = ParseUtil.GetFloat(xml["font"]["charspacing"].InnerText); } if (xml["font"]["color"] != null) { underfont.DefaultColor = ParseUtil.GetColor(xml["font"]["color"].InnerText); } return(underfont); }
public static UnderFont TryLoad(string key) { string k = key; key = key.ToLower(); if (dictMod.ContainsKey(key) || dictDefault.ContainsKey(key)) { UnderFont underfont = GetUnderFont(k); //if (underfont != null) dict[key] = underfont; } else { return(null); } return(dict[key]); }
public void SetFont(string fontName, bool firstTime = false) { if (fontName == null) { throw new CYFException("Text.SetFont: The first argument (the font name) is nil.\n\nSee the documentation for proper usage."); } CheckExists(); UnderFont uf = SpriteFontRegistry.Get(fontName); if (uf == null) { throw new CYFException("The font \"" + fontName + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod."); } SetFont(uf, firstTime); if (!firstTime) { default_charset = uf; } UpdateBubble(); }
public void SetFont(string fontName, bool firstTime = false) { if (fontName == null) { throw new CYFException("Text.SetFont: The first argument (the font name) is nil.\n\nSee the documentation for proper usage."); } CheckExists(); UnderFont uf = SpriteFontRegistry.Get(fontName); if (uf == null) { throw new CYFException("The font \"" + fontName + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod."); } SetFont(uf, firstTime); //if (forced) // default_charset = uf; containerBubble.GetComponent <RectTransform>().localPosition = new Vector2(-12, 24); // GetComponent<RectTransform>().localPosition = new Vector2(0, 16); GetComponent <RectTransform>().localPosition = new Vector2(0, 0); }
private static void loadAllFrom(string directoryPath) { DirectoryInfo dInfo = new DirectoryInfo(directoryPath); if (!dInfo.Exists) { return; } FileInfo[] fInfo = dInfo.GetFiles("*.png", SearchOption.TopDirectoryOnly); foreach (FileInfo file in fInfo) { string fontName = Path.GetFileNameWithoutExtension(file.FullName); if (dict.ContainsKey(fontName.ToLower())) { continue; } UnderFont underfont = getUnderFont(fontName); if (underfont == null) { continue; } dict[fontName.ToLower()] = underfont; } }
public static LuaTextManager CreateText(Script scr, DynValue text, DynValue position, int textWidth, string layer = "BelowPlayer", int bubbleHeight = -1) { // Check if the arguments are what they should be if (text == null || (text.Type != DataType.Table && text.Type != DataType.String)) { throw new CYFException("CreateText: The text argument must be a non-empty table of strings or a simple string."); } if (position == null || position.Type != DataType.Table || position.Table.Get(1).Type != DataType.Number || position.Table.Get(2).Type != DataType.Number) { throw new CYFException("CreateText: The position argument must be a non-empty table of two numbers."); } GameObject go = UnityEngine.Object.Instantiate(Resources.Load <GameObject>("Prefabs/CstmTxtContainer")); LuaTextManager luatm = go.GetComponentInChildren <LuaTextManager>(); go.GetComponent <RectTransform>().position = new Vector2((float)position.Table.Get(1).Number, (float)position.Table.Get(2).Number); UnitaleUtil.GetChildPerName(go.transform, "BubbleContainer").GetComponent <RectTransform>().pivot = new Vector2(0, 1); UnitaleUtil.GetChildPerName(go.transform, "BubbleContainer").GetComponent <RectTransform>().localPosition = new Vector2(-12, 8); UnitaleUtil.GetChildPerName(go.transform, "BubbleContainer").GetComponent <RectTransform>().sizeDelta = new Vector2(textWidth + 20, 100); //Used to set the borders UnitaleUtil.GetChildPerName(go.transform, "BackHorz").GetComponent <RectTransform>().sizeDelta = new Vector2(textWidth + 20, 100 - 20 * 2); //BackHorz UnitaleUtil.GetChildPerName(go.transform, "BackVert").GetComponent <RectTransform>().sizeDelta = new Vector2(textWidth - 20, 100); //BackVert UnitaleUtil.GetChildPerName(go.transform, "CenterHorz").GetComponent <RectTransform>().sizeDelta = new Vector2(textWidth + 16, 96 - 16 * 2); //CenterHorz UnitaleUtil.GetChildPerName(go.transform, "CenterVert").GetComponent <RectTransform>().sizeDelta = new Vector2(textWidth - 16, 96); //CenterVert foreach (ScriptWrapper scrWrap in ScriptWrapper.instances) { if (scrWrap.script == scr) { luatm.SetCaller(scrWrap); break; } } // Layers don't exist in the overworld, so we don't set it if (!UnitaleUtil.IsOverworld || GlobalControls.isInShop) { luatm.layer = layer; } else { luatm.layer = (layer == "BelowPlayer" ? "Default" : layer); } luatm.textMaxWidth = textWidth; luatm.bubbleHeight = bubbleHeight; luatm.ShowBubble(); // Converts the text argument into a table if it's a simple string text = text.Type == DataType.String ? DynValue.NewTable(scr, new DynValue[1] { text }) : text; if (text.Table.Length == 0) { text = null; } ////////////////////////////////////////// /////////// LATE START SETTER ////////// ////////////////////////////////////////// // Text objects' Late Start will be disabled if the first line of text contains [instant] before any regular characters bool enableLateStart = true; // if we've made it this far, then the text is valid. // so, let's scan the first line of text for [instant] string firstLine = text.Table.Get(1).String; // if [instant] or [instant:allowcommand] is found, check for the earliest match, and whether it is at the beginning if (firstLine.IndexOf("[instant]") > -1 || firstLine.IndexOf("[instant:allowcommand]") > -1) { // determine whether [instant] or [instant:allowcommand] is first string testFor = "[instant]"; if (firstLine.IndexOf("[instant:allowcommand]") > -1 && ((firstLine.IndexOf("[instant]") > -1 && firstLine.IndexOf("[instant:allowcommand]") < firstLine.IndexOf("[instant]")) || firstLine.IndexOf("[instant]") == -1)) { testFor = "[instant:allowcommand]"; } // grab all of the text that comes before the matched command string precedingText = firstLine.Substring(0, firstLine.IndexOf(testFor)); // remove all commands other than the matched command from this variable while (precedingText.IndexOf('[') > -1) { int i = 0; if (UnitaleUtil.ParseCommandInline(precedingText, ref i) == null) { break; } else { precedingText = precedingText.Replace(precedingText.Substring(0, i + 1), ""); } } // if the length of the remaining string is 0, then disable late start! if (precedingText.Length == 0) { enableLateStart = false; } } ////////////////////////////////////////// /////////// INITIAL FONT SETTER ////////// ////////////////////////////////////////// // If the first line of text has [font] at the beginning, use it initially! if (firstLine.IndexOf("[font:") > -1 && firstLine.Substring(firstLine.IndexOf("[font:")).IndexOf(']') > -1) { // grab all of the text that comes before the matched command string precedingText = firstLine.Substring(0, firstLine.IndexOf("[font:")); // remove all commands other than the matched command from this variable while (precedingText.IndexOf('[') > -1) { int i = 0; if (UnitaleUtil.ParseCommandInline(precedingText, ref i) == null) { break; } else { precedingText = precedingText.Replace(precedingText.Substring(0, i + 1), ""); } } // if the length of the remaining string is 0, then set the font! if (precedingText.Length == 0) { int startCommand = firstLine.IndexOf("[font:"); string command = UnitaleUtil.ParseCommandInline(precedingText, ref startCommand); if (command != null) { string fontPartOne = command.Substring(6); string fontPartTwo = fontPartOne.Substring(0, fontPartOne.IndexOf("]")); UnderFont font = SpriteFontRegistry.Get(fontPartTwo); if (font == null) { throw new CYFException("The font \"" + fontPartTwo + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod."); } luatm.SetFont(font, true); luatm.UpdateBubble(); } else { luatm.ResetFont(); } } else { luatm.ResetFont(); } } else { luatm.ResetFont(); } if (enableLateStart) { luatm.lateStartWaiting = true; } luatm.SetText(text); if (enableLateStart) { luatm.DestroyChars(); luatm.LateStart(); } return(luatm); }