Terraria v1.4.4.9
Terraria 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 438 of file Utils.cs.

439 {
443 foreach (TextSnippet textSnippet in array)
444 {
445 string[] array2 = textSnippet.Text.Split('\n');
446 for (int j = 0; j < array2.Length - 1; j++)
447 {
448 list2.Add(textSnippet.CopyMorph(array2[j]));
449 list.Add(list2);
450 list2 = new List<TextSnippet>();
451 }
452 list2.Add(textSnippet.CopyMorph(array2[array2.Length - 1]));
453 }
454 list.Add(list2);
455 if (maxWidth != -1)
456 {
457 for (int k = 0; k < list.Count; k++)
458 {
460 float num = 0f;
461 for (int l = 0; l < list3.Count; l++)
462 {
463 float stringLength = list3[l].GetStringLength(font);
464 if (stringLength + num > (float)maxWidth)
465 {
466 int num2 = maxWidth - (int)num;
467 if (num > 0f)
468 {
469 num2 -= 16;
470 }
471 int num3 = Math.Min(list3[l].Text.Length, num2 / 8);
472 if (num3 < 0)
473 {
474 num3 = 0;
475 }
476 string[] array3 = list3[l].Text.Split(' ');
477 int num4 = num3;
478 if (array3.Length > 1)
479 {
480 num4 = 0;
481 for (int m = 0; m < array3.Length; m++)
482 {
483 bool flag = num4 == 0;
484 if (!(num4 + array3[m].Length <= num3 || flag))
485 {
486 break;
487 }
488 num4 += array3[m].Length + 1;
489 }
490 if (num4 > num3)
491 {
492 num4 = num3;
493 }
494 }
495 string newText = list3[l].Text.Substring(0, num4);
496 string newText2 = list3[l].Text.Substring(num4);
497 list2 = new List<TextSnippet> { list3[l].CopyMorph(newText2) };
498 for (int n = l + 1; n < list3.Count; n++)
499 {
500 list2.Add(list3[n]);
501 }
502 list3[l] = list3[l].CopyMorph(newText);
503 list[k] = list[k].Take(l + 1).ToList();
504 list.Insert(k + 1, list2);
505 break;
506 }
507 num += stringLength;
508 }
509 num = 0f;
510 }
511 }
512 if (maxLines != -1)
513 {
514 while (list.Count > maxLines)
515 {
516 list.RemoveAt(maxLines);
517 }
518 }
519 return list;
520 }
void Add(TKey key, TValue value)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static List< TextSnippet > ParseMessage(string text, Color baseColor)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.array, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.list, System.Math.Min(), Terraria.UI.Chat.ChatManager.ParseMessage(), and System.text.

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