TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ WordwrapStringSmart()

static List< List< TextSnippet > > Terraria.Utils.WordwrapStringSmart ( string text,
Color c,
DynamicSpriteFont font,
int maxWidth,
int maxLines )
inlinestatic

Definition at line 522 of file Utils.cs.

523 {
524 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
525 //IL_0124: Unknown result type (might be due to invalid IL or missing references)
526 TextSnippet[] array4 = ChatManager.ParseMessage(text, c).ToArray();
530 foreach (TextSnippet textSnippet in array5)
531 {
532 string[] array2 = textSnippet.Text.Split('\n');
533 for (int j = 0; j < array2.Length - 1; j++)
534 {
535 list2.Add(textSnippet.CopyMorph(array2[j]));
536 list.Add(list2);
537 list2 = new List<TextSnippet>();
538 }
539 list2.Add(textSnippet.CopyMorph(array2[^1]));
540 }
541 list.Add(list2);
542 if (maxWidth != -1)
543 {
544 for (int k = 0; k < list.Count; k++)
545 {
546 List<TextSnippet> list3 = list[k];
547 float num = 0f;
548 for (int l = 0; l < list3.Count; l++)
549 {
550 float stringLength = list3[l].GetStringLength(font);
551 if (stringLength + num > (float)maxWidth)
552 {
553 int num2 = maxWidth - (int)num;
554 if (num > 0f)
555 {
556 num2 -= 16;
557 }
558 int num3 = Math.Min(list3[l].Text.Length, num2 / 8);
559 for (int i = 0; i < list3[l].Text.Length; i++)
560 {
561 if (font.MeasureString(list3[l].Text.Substring(0, i)).X * list3[l].Scale < (float)num2)
562 {
563 num3 = i;
564 }
565 }
566 if (num3 < 0)
567 {
568 num3 = 0;
569 }
570 string[] array3 = list3[l].Text.Split(' ');
571 int num4 = num3;
572 if (array3.Length > 1)
573 {
574 num4 = 0;
575 for (int m = 0; m < array3.Length; m++)
576 {
577 bool flag = num4 == 0;
578 if (!(num4 + array3[m].Length <= num3 || flag))
579 {
580 break;
581 }
582 num4 += array3[m].Length + 1;
583 }
584 if (num4 > num3)
585 {
586 num4 = num3;
587 }
588 }
589 string newText = list3[l].Text.Substring(0, num4);
590 string newText2 = list3[l].Text.Substring(num4);
591 list2 = new List<TextSnippet> { list3[l].CopyMorph(newText2) };
592 for (int n = l + 1; n < list3.Count; n++)
593 {
594 list2.Add(list3[n]);
595 }
596 list3[l] = list3[l].CopyMorph(newText);
597 list[k] = list[k].Take(l + 1).ToList();
598 list.Insert(k + 1, list2);
599 break;
600 }
601 num += stringLength;
602 }
603 num = 0f;
604 }
605 }
606 if (maxLines != -1)
607 {
608 while (list.Count > maxLines)
609 {
610 list.RemoveAt(maxLines);
611 }
612 }
613 return list;
614 }
static List< TextSnippet > ParseMessage(string text, Color baseColor)

References Terraria.UI.Chat.ChatManager.ParseMessage().

Referenced by Terraria.GameContent.UI.Chat.LegacyChatMonitor.NewTextMultiline(), Terraria.Main.TextDisplayCache.PrepareCache(), and Terraria.UI.Chat.ChatMessageContainer.Refresh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: