public void BigTextTab(OpTab[] TabList, int tabNum, string txt, FLabelAlignment alignment = FLabelAlignment.Left) { OpRect TextBoxContainer = new OpRect(new Vector2(65f, 37f), new Vector2(475f, 450f)); OpLabel TextBoxID = new OpLabel(new Vector2(90f, 60f), new Vector2(424f, 402f), txt, alignment, false) { autoWrap = true }; TabList[tabNum].AddItems(TextBoxContainer); TabList[tabNum].AddItems(TextBoxID); }
/// <summary> /// Simple Label that displays text. See also <seealso cref="OpLabel(float, float, string, bool)"/> for lazier version. /// </summary> /// <param name="pos">BottomLeft Position</param> /// <param name="size">Size of the Box</param> /// <param name="text">Text you want to display; max length 600. See also <seealso cref="OpLabelLong"/><para>Leaving this as TEXT will call <see cref="LoremIpsum"/>.</para></param> /// <param name="alignment">Alignment. Left/Center/Right. Center is default.</param> /// <param name="bigText">Whether this uses bigFont or not</param> public OpLabel(Vector2 pos, Vector2 size, string text = "TEXT", FLabelAlignment alignment = FLabelAlignment.Center, bool bigText = false) : base(pos, size) { this._size = new Vector2(Mathf.Max(size.x, 20f), Mathf.Max(size.y, 20f)); this._bigText = bigText; this.autoWrap = false; if (text == "TEXT") { //Lorem Ipsum int lc = this.IsLong ? Math.Max(1, Mathf.FloorToInt(_size.y * 0.65f / LabelTest.LineHeight(_bigText))) : 1; int charLim = Mathf.FloorToInt(_size.x / LabelTest.CharMean(_bigText)) * lc; int sentLim = charLim / LoremIpsum.meanCharPerSentence; if (this.IsLong) { int pn = UnityEngine.Random.Range(1, Mathf.CeilToInt(lc / 1.5f)); text = LoremIpsum.Generate(Math.Max(1, (sentLim - 2) / pn), Math.Max(2, sentLim / pn), pn); //charLim = Mathf.FloorToInt(charLim * 0.65f); } else { text = LoremIpsum.Generate(Math.Max(1, sentLim - 2), Math.Max(1, sentLim)); } text = text.Length > charLim?text.Substring(0, charLim - 2).TrimEnd() + "." : text; } if (this.IsLong) { this._text = text; _verticalAlignment = LabelVAlignment.Top; } else { this._text = text; _verticalAlignment = LabelVAlignment.Center; } //this.lineLength = Mathf.FloorToInt((size.x - 10f) / 6f); string cleanText = Regex.Replace(_text, @"\s+", ""); this.isVFont = cleanText.Length > 0 && !LabelTest.HasNonASCIIChars(cleanText); if (!_init) { return; } this.color = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.MediumGrey); this._alignment = alignment; if (!this.IsLong) { this.label = new MenuLabel(menu, owner, _text, this.pos, this.size, this._bigText); this.label.label.color = this.color; this.subObjects.Add(this.label); OnChange(); } }
/// <summary> /// Simply Label that displays text. /// </summary> /// <param name="pos">BottomLeft Position</param> /// <param name="size">Size of the Box</param> /// <param name="text">Text you want to display; max length 600</param> /// <param name="alignment">Alignment. Left/Center/Right</param> /// <param name="bigText">Whether this use bigFont or not</param> public OpLabel(Vector2 pos, Vector2 size, string text = "TEXT", FLabelAlignment alignment = FLabelAlignment.Center, bool bigText = false) : base(pos, size) { Vector2 minSize = new Vector2(Mathf.Max(size.x, 20f), Mathf.Max(size.y, 20f)); this._size = minSize; this._text = text.Length < 600 ? text : text.Substring(0, 600); this._bigText = bigText; this.lineLength = Mathf.FloorToInt((size.x - 10f) / 6f); this.autoWrap = false; this.color = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.MediumGrey); if (_init) { this.label = new MenuLabel(menu, owner, _text, this.pos, minSize, this._bigText); this.label.label.color = this.color; this.subObjects.Add(this.label); } this._alignment = alignment; OnChange(); }
/// <summary> /// Special Label that creates multiple <see cref="MenuLabel"/>s to break Futile's character limits. /// </summary> /// <param name="pos">BottomLeft Position</param> /// <param name="size">Size of the Box</param> /// <param name="text">Text you want to display</param> /// <param name="autoWrap">Whether you want to wrap text automatically.</param> /// <param name="alignment">Alignment. Left/Center/Right. Left is default.</param> public OpLabelLong(Vector2 pos, Vector2 size, string text = "TEXT", bool autoWrap = true, FLabelAlignment alignment = FLabelAlignment.Left) : base(pos, size, text, alignment, false) { this.autoWrap = autoWrap; this.labels = new List <MenuLabel>(); this.allowOverflow = true; if (!_init) { return; } OnChange(); }
internal override void OnChange() { if (!_init) { return; } base.OnChange(); if (!this.autoWrap) { this.label.text = _text.Length < 600 ? _text : _text.Substring(0, 600); } else { string ml = _text.Length < 600 ? _text : _text.Substring(0, 600); char[] array = ml.ToCharArray(); int d = 0; bool f = true; int l = 0; do { if (f) { //forward if (array[d] == '\n') { l = 0; d++; continue; } if (l < this.lineLength) { d++; l++; continue; } else { f = false; continue; } } else { //backward if (array[d] == ' ') { array[d] = '\n'; l = 0; d++; f = true; continue; } d--; l--; continue; } } while (d < array.Length); this.label.text = new string(array); } switch (this._alignment) { default: case FLabelAlignment.Center: this.label.label.alignment = FLabelAlignment.Center; this.label.pos = this.pos; break; case FLabelAlignment.Left: this.label.label.alignment = FLabelAlignment.Left; this.label.pos = this.pos - new Vector2(this.size.x * 0.5f, 0f); break; case FLabelAlignment.Right: this.label.label.alignment = FLabelAlignment.Right; this.label.pos = this.pos + new Vector2(this.size.x * 0.5f, 0f); break; } }
public override void OnChange() { this._size = new Vector2(Mathf.Max(this._size.x, 20f), Mathf.Max(this._size.y, 20f)); base.OnChange(); if (!_init) { return; } if (string.IsNullOrEmpty(this._text)) { this._displayText = ""; goto displaySkip; } if (!this.autoWrap) { if (this.IsLong) { this._displayText = _text; } else { this._displayText = _text.Length < LabelTest.CharLimit(_bigText, isVFont) ? _text : _text.Substring(0, LabelTest.CharLimit(_bigText, isVFont)); } } else { string ml; if (this.IsLong) { ml = _text; } else { ml = _text.Length < LabelTest.CharLimit(_bigText, isVFont) ? _text : _text.Substring(0, LabelTest.CharLimit(_bigText, isVFont)); } this._displayText = LabelTest.WrapText(ml, _bigText, _size.x, isVFont); } displaySkip: if (this.IsLong) { return; } if (this.GetLineCount() > 10) { int IndexOfOccurence(int occurence) { int i = 1; int index = 0; while (i <= occurence && (index = _displayText.IndexOf('\n', index + 1)) != -1) { if (i == occurence) { return(index); } i++; } return(-1); } int sp = IndexOfOccurence(10); if (sp > 0) { _displayText = _displayText.Substring(0, sp); } } this.label.text = this._displayText; this.label.size = this.size; switch (this._alignment) { default: case FLabelAlignment.Center: this.label.label.alignment = FLabelAlignment.Center; this.label.pos = this.pos; break; case FLabelAlignment.Left: this.label.label.alignment = FLabelAlignment.Left; this.label.pos = this.pos - new Vector2(this.size.x * 0.5f, 0f); break; case FLabelAlignment.Right: this.label.label.alignment = FLabelAlignment.Right; this.label.pos = this.pos + new Vector2(this.size.x * 0.5f, 0f); break; } float lh = LabelTest.LineHeight(_bigText, isVFont) * GetLineCount(); switch (this._verticalAlignment) { default: case LabelVAlignment.Center: break; case LabelVAlignment.Top: this.label.size.y = lh; this.label.pos.y = this.pos.y + this.size.y - lh; break; case LabelVAlignment.Bottom: this.label.size.y = lh; this.label.pos.y = this.pos.y + lh; break; } }