public static TextField ParseText(string s, FontManager fManager) { if (!s.Contains("textParam:")) { throw new FormatException("[ProceduralObjects] TextField Parse : Input string was not in the correct format"); } try { TextField f = new TextField(0); bool newVersion = s.Contains(" m_rotation:"); f.SetFont(s.GetStringBetween(" m_font:", " m_size:"), fManager); f.m_fontSize = uint.Parse(s.GetStringBetween(" m_size:", " m_spacing:")); f.m_spacing = uint.Parse(s.GetStringBetween(" m_spacing:", " m_style:")); f.m_style = TextCustomizationManager.IntToStyle(int.Parse(s.GetStringBetween(" m_style:", " m_x:"))); f.x = float.Parse(s.GetStringBetween(" m_x:", " m_y:")); f.y = float.Parse(s.GetStringBetween(" m_y:", " m_scaleX:")); f.m_scaleX = float.Parse(s.GetStringBetween(" m_scaleX:", " m_scaleY:")); f.m_scaleY = float.Parse(s.GetStringBetween(" m_scaleY:", newVersion ? " m_rotation:" : " m_fontcolor:")); if (newVersion) { f.m_rotation = byte.Parse(s.GetStringBetween(" m_rotation:", " m_fontcolor:")); } f.m_fontColor = SerializableColor.Parse(s.GetStringBetween(" m_fontcolor:", " m_text:")); f.m_text = s.GetStringAfter(" m_text:"); return(f); } catch (Exception e) { Debug.LogError("[ProceduralObjects] Error : " + e.GetType().ToString() + " while parsing a TextField : " + e.Message); return(new TextField(0)); } }
public void DrawUI(Rect rect, TextCustomizationManager textManager, Action <TextureFont> openCharTable) { // GUI.Box(rect, string.Empty); GUI.BeginGroup(rect); // copy if (GUI.Button(new Rect(220, 3, 25, 23), ProceduralObjectsMod.Icons[15])) { ProceduralObjectsLogic.PlaySound(); textManager.copiedField = TextField.Clone(this, false); } if (m_type == 0) { if (!m_font.m_disableColorOverwriting) { painter = GUIPainter.DrawPainterSampleOnly(painter, new Vector2(3, 4), m_fontColor, (c) => { m_fontColor = c; }, () => { if (textManager.colorPickerSelected == painter) { textManager.colorPickerSelected = null; } else { textManager.colorPickerSelected = painter; } }); } GUI.SetNextControlName("TextFieldPOTextCustom"); m_text = GUI.TextField(new Rect(m_font.m_disableColorOverwriting ? 3 : 31, 3, m_font.m_disableColorOverwriting ? 214 : 186, 25), m_text); } else // if m_type == 1 { painter = GUIPainter.DrawPainterSampleOnly(painter, new Vector2(3, 4), m_fontColor, (c) => { m_fontColor = c.KeepAlphaFrom(m_fontColor); }, () => { if (textManager.colorPickerSelected == painter) { textManager.colorPickerSelected = null; } else { textManager.colorPickerSelected = painter; } }); GUI.Label(new Rect(30, 5, 190, 23), LocalizationManager.instance.current["colorRect"]); } GUIUtils.DrawSeparator(new Vector2(3, 75), 241); if (m_type == 0) // TEXT FIELD { //size GUI.Label(new Rect(3, 80, 95, 22), "<size=12>" + LocalizationManager.instance.current["font_size"] + " : " + m_fontSize.ToString() + "</size>"); m_fontSize = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(100, 85, 140, 25), m_fontSize, 5, 150)); //spacing GUI.Label(new Rect(3, 105, 95, 22), "<size=12>" + LocalizationManager.instance.current["font_spacing"] + " : " + m_spacing.ToString() + "</size>"); m_spacing = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(100, 110, 140, 25), m_spacing, 0, 9)); //scale GUI.Label(new Rect(3, 130, 120, 26), LocalizationManager.instance.current["scale_txt"] + " :"); if (GUI.Button(new Rect(3, 155, 24, 26), "X :", GUI.skin.label)) { m_scaleX = 1f; } m_scaleX = GUI.HorizontalSlider(new Rect(30, 158, 90, 18), m_scaleX, 0.1f, 5f); if (GUI.Button(new Rect(125, 155, 24, 26), "Y :", GUI.skin.label)) { m_scaleY = 1f; } m_scaleY = GUI.HorizontalSlider(new Rect(150, 158, 90, 18), m_scaleY, 0.1f, 5f); //font bool supportStyles = m_font.m_boldExists && m_font.m_italicExists; if (GUI.Button(new Rect(3, 180, (supportStyles ? 126 : 213), 25), m_fontName)) { ProceduralObjectsLogic.PlaySound(); openCharTable.Invoke(m_font); } if (GUI.Button(new Rect((supportStyles ? 128 : 215), 180, 26, 25), "▼")) { ProceduralObjectsLogic.PlaySound(); // SetFont(textManager.fontManager.GetNextFont(m_font)); scrollFontsPos = Vector2.zero; expandFontsSelector = !expandFontsSelector; } if (supportStyles) { string[] styles = new string[] { LocalizationManager.instance.current["textStyle_normal"], "<b>" + LocalizationManager.instance.current["textStyle_bold"] + "</b>", "<i>" + LocalizationManager.instance.current["textStyle_italic"] + "</i>" }; if (m_font.m_stylesNames != null) { if (m_font.m_stylesNames.Length == 3) { styles = m_font.m_stylesNames; } } m_style = TextCustomizationManager.IntToStyle(GUI.Toolbar(new Rect(158, 180, 85, 25), TextCustomizationManager.SelectedStyle(m_style), styles)); } if (expandFontsSelector) { TextureFont fontSelected; if (FontManager.instance.FontSelector(new Rect(3, 207, 240, 160), scrollFontsPos, out fontSelected, out scrollFontsPos)) { SetFont(fontSelected); expandFontsSelector = false; scrollFontsPos = Vector2.zero; } } } else if (m_type == 1) // COLOR RECT { GUI.Label(new Rect(4, 80, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_width"] + " :</size>"); // m_width = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(4, 44, 200, 25), m_width, 1, 2048)); if (widthField == null) { widthField = new GUIUtils.FloatInputField(m_width); } m_width = (uint)widthField.DrawField(new Rect(74, 79, 170, 35), m_width, false, 0f, 1024f, true, Mathf.Abs(Mathf.Round(textManager.windowTex.width - x))).returnValue; GUI.Label(new Rect(4, 115, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_height"] + " :</size>"); if (heightField == null) { heightField = new GUIUtils.FloatInputField(m_height); } m_height = (uint)heightField.DrawField(new Rect(74, 117, 170, 35), m_height, false, 0f, 1024f, true, Mathf.Abs(Mathf.Round(textManager.windowTex.height - y))).returnValue; GUI.Label(new Rect(4, 154, 200, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_opacity"] + " : " + ((int)(m_fontColor.a * 100)).ToString() + "%</size>"); m_fontColor.a = GUI.HorizontalSlider(new Rect(4, 176, 200, 25), m_fontColor.a, 0f, 1f); if (borderColor == null) { borderColor = Color.white; } GUI.Label(new Rect(4, 193, 200, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_border"] + " : " + borderSize.ToString() + " px</size>"); borderSize = (uint)Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(4, 215, 200, 25), borderSize, 0f, 20f)); borderPainter = GUIPainter.DrawPainterSampleOnly(borderPainter, new Vector2(214, 198), borderColor, (c) => { borderColor = c; }, () => { if (textManager.colorPickerSelected == borderPainter) { textManager.colorPickerSelected = null; } else { textManager.colorPickerSelected = borderPainter; } }); } // POSITION GUIUtils.DrawSeparator(new Vector2(3, 29), 241); GUI.Label(new Rect(3, 30, 75, 21), "<size=12>" + LocalizationManager.instance.current["position"] + " :</size>"); // float newX, newY; if (posXfield == null) { posXfield = new GUIUtils.FloatInputField(x); posYfield = new GUIUtils.FloatInputField(y); } GUI.Label(new Rect(3, 51, 24, 22), "<size=12>X :</size>"); x = posXfield.DrawField(new Rect(27, 50, 83, 22), "textPosX", x, true).returnValue; GUI.Label(new Rect(111, 51, 24, 22), "<size=12>Y :</size>"); y = posYfield.DrawField(new Rect(135, 50, 83, 22), "textPosY", y, true).returnValue; // rotation if (GUI.Button(new Rect(220, 50, 25, 23), ProceduralObjectsMod.Icons[5])) { ProceduralObjectsLogic.PlaySound(); if (m_type == 0) { if (m_rotation == 0) { m_rotation = 4; } else if (m_rotation == 4) { m_rotation = 1; } else if (m_rotation == 1) { m_rotation = 2; } else if (m_rotation == 2) { m_rotation = 0; } } else if (m_type == 1) { var h = m_height; m_height = m_width; m_width = h; } } GUI.EndGroup(); }
public void DrawUI(Vector2 position, TextCustomizationManager textManager, Action <TextureFont> openCharTable, bool showDelete) { Rect rect = new Rect(position.x, position.y, 350, minimized ? 31 : 123); GUI.Box(rect, string.Empty); GUI.BeginGroup(rect); if (m_type == 0) { m_text = GUI.TextField(new Rect(3, 3, textManager.parameters.m_textFields.Count == 1 ? 268 : 242, 25), m_text); } else // if m_type == 1 { GUI.color = m_fontColor; GUI.Label(new Rect(3, 4, 25, 24), "██"); GUI.color = Color.white; GUI.Label(new Rect(28, 5, 212, 23), LocalizationManager.instance.current["colorRect"]); if (GUI.Button(new Rect(textManager.parameters.Count() == 1 ? 246 : 220, 3, 25, 25), ProceduralObjectsMod.Icons[locked ? 8 : 9])) { ProceduralObjectsLogic.PlaySound(); locked = !locked; } } if (!minimized) { if (m_type == 0) // TEXT FIELD { GUI.Label(new Rect(4, 26, 75, 22), "<size=12>" + LocalizationManager.instance.current["font_size"] + " : " + m_fontSize.ToString() + "</size>"); m_fontSize = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(80, 32, 113, 25), m_fontSize, 5, 150)); GUI.Label(new Rect(4, 47, 90, 22), "<size=12>" + LocalizationManager.instance.current["font_spacing"] + " : " + m_spacing.ToString() + "</size>"); m_spacing = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(95, 53, 98, 25), m_spacing, 0, 9)); if (!m_font.m_disableColorOverwriting) { GUI.Label(new Rect(205, 29, 75, 22), "<size=12>" + LocalizationManager.instance.current["font_color"] + " :</size>"); m_fontColor.r = GUI.HorizontalSlider(new Rect(205, 52, 80, 18), m_fontColor.r, 0f, 1f); m_fontColor.g = GUI.HorizontalSlider(new Rect(205, 69, 80, 18), m_fontColor.g, 0f, 1f); m_fontColor.b = GUI.HorizontalSlider(new Rect(205, 86, 80, 18), m_fontColor.b, 0f, 1f); GUI.Label(new Rect(289, 48, 75, 22), "<size=12>" + LocalizationManager.instance.current["rgb_r"] + " : " + (int)(m_fontColor.r * 255f) + "</size>"); GUI.Label(new Rect(289, 65, 75, 22), "<size=12>" + LocalizationManager.instance.current["rgb_g"] + " : " + (int)(m_fontColor.g * 255f) + "</size>"); GUI.Label(new Rect(289, 82, 75, 22), "<size=12>" + LocalizationManager.instance.current["rgb_b"] + " : " + (int)(m_fontColor.b * 255f) + "</size>"); } if (textManager.fontManager.previousFontExists(m_font)) { if (GUI.Button(new Rect(4, 68, 26, 25), "◄")) { ProceduralObjectsLogic.PlaySound(); SetFont(textManager.fontManager.GetPreviousFont(m_font)); } } else { GUI.skin.box.normal.textColor = TextCustomizationManager.inactiveGrey; GUI.Label(new Rect(4, 68, 26, 25), "◄", GUI.skin.box); GUI.skin.box.normal.textColor = Color.white; } if (GUI.Button(new Rect(30, 68, 147, 25), m_fontName)) { ProceduralObjectsLogic.PlaySound(); openCharTable.Invoke(m_font); } if (textManager.fontManager.nextFontExists(m_font)) { if (GUI.Button(new Rect(177, 68, 26, 25), "►")) { ProceduralObjectsLogic.PlaySound(); SetFont(textManager.fontManager.GetNextFont(m_font)); } } else { GUI.skin.box.normal.textColor = TextCustomizationManager.inactiveGrey; GUI.Label(new Rect(177, 68, 26, 25), "►", GUI.skin.box); GUI.skin.box.normal.textColor = Color.white; } if (m_font.m_boldExists && m_font.m_italicExists) { string[] styles = new string[] { LocalizationManager.instance.current["textStyle_normal"], "<b>" + LocalizationManager.instance.current["textStyle_bold"] + "</b>", "<i>" + LocalizationManager.instance.current["textStyle_italic"] + "</i>" }; if (m_font.m_stylesNames != null) { if (m_font.m_stylesNames.Length == 3) { styles = m_font.m_stylesNames; } } m_style = TextCustomizationManager.IntToStyle(GUI.Toolbar(new Rect(4, 95, 91, 25), TextCustomizationManager.SelectedStyle(m_style), styles)); } GUI.Label(new Rect(98, 99, 67, 26), LocalizationManager.instance.current["scale_txt"] + " :"); if (GUI.Button(new Rect(165, 99, 10, 26), "X", GUI.skin.label)) { m_scaleX = 1f; } m_scaleX = GUI.HorizontalSlider(new Rect(176, 103, 78, 18), m_scaleX, 0.1f, 5f); if (GUI.Button(new Rect(255, 99, 10, 26), "Y", GUI.skin.label)) { m_scaleY = 1f; } m_scaleY = GUI.HorizontalSlider(new Rect(266, 103, 78, 18), m_scaleY, 0.1f, 5f); } else if (m_type == 1) // COLOR RECT { GUI.Label(new Rect(4, 26, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_width"] + " : " + m_width.ToString() + "</size>"); m_width = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(4, 44, 200, 25), m_width, 1, 2048)); GUI.Label(new Rect(4, 57, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_height"] + " : " + m_height.ToString() + "</size>"); m_height = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(4, 75, 200, 25), m_height, 1, 2048)); GUI.Label(new Rect(4, 90, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_opacity"] + " : " + ((int)(m_fontColor.a * 100)).ToString() + "%</size>"); m_fontColor.a = GUI.HorizontalSlider(new Rect(4, 108, 150, 25), m_fontColor.a, 0f, 1f); GUI.Label(new Rect(217, 36, 75, 22), "<size=12>" + LocalizationManager.instance.current["font_color"] + " :</size>"); m_fontColor.r = GUI.HorizontalSlider(new Rect(217, 59, 80, 18), m_fontColor.r, 0f, 1f); m_fontColor.g = GUI.HorizontalSlider(new Rect(217, 76, 80, 18), m_fontColor.g, 0f, 1f); m_fontColor.b = GUI.HorizontalSlider(new Rect(217, 93, 80, 18), m_fontColor.b, 0f, 1f); GUI.Label(new Rect(301, 55, 75, 22), "<size=12>" + LocalizationManager.instance.current["rgb_r"] + " : " + (int)(m_fontColor.r * 255f) + "</size>"); GUI.Label(new Rect(301, 72, 75, 22), "<size=12>" + LocalizationManager.instance.current["rgb_g"] + " : " + (int)(m_fontColor.g * 255f) + "</size>"); GUI.Label(new Rect(301, 89, 75, 22), "<size=12>" + LocalizationManager.instance.current["rgb_b"] + " : " + (int)(m_fontColor.b * 255f) + "</size>"); } // rotation if (GUI.Button(new Rect(324, 28.6f, 25, 23), ProceduralObjectsMod.Icons[5])) { ProceduralObjectsLogic.PlaySound(); if (m_type == 0) { if (m_rotation == 0) { m_rotation = 4; } else if (m_rotation == 4) { m_rotation = 1; } else if (m_rotation == 1) { m_rotation = 2; } else if (m_rotation == 2) { m_rotation = 0; } } else if (m_type == 1) { var h = m_height; m_height = m_width; m_width = h; } } } if (textManager.parameters.CanFieldMoveUp(this)) { if (GUI.Button(new Rect(246, 3, 25, 12), ProceduralObjectsMod.Icons[6])) { ProceduralObjectsLogic.PlaySound(); textManager.parameters.MoveFieldUp(this); } } if (textManager.parameters.CanFieldMoveDown(this)) { if (GUI.Button(new Rect(246, 15.5f, 25, 12), ProceduralObjectsMod.Icons[7])) { ProceduralObjectsLogic.PlaySound(); textManager.parameters.MoveFieldDown(this); } } if (GUI.Button(new Rect(272, 3, 25, 25), ProceduralObjectsMod.Icons[0])) { ProceduralObjectsLogic.PlaySound(); textManager.parameters.AddField(TextField.Clone(this, false)); } if (GUI.Button(new Rect(298, 3, 25, 25), ProceduralObjectsMod.Icons[minimized ? 1 : 2])) { ProceduralObjectsLogic.PlaySound(); minimized = !minimized; } if (showDelete) { GUI.color = Color.red; if (GUI.Button(new Rect(324, 3, 25, 25), "X")) { ProceduralObjectsLogic.PlaySound(); textManager.parameters.RemoveField(this); } GUI.color = Color.white; } GUI.EndGroup(); }