diff --git a/src/SharpModMenu/PlayerMenuState.cs b/src/SharpModMenu/PlayerMenuState.cs index b97db3e..28516dc 100644 --- a/src/SharpModMenu/PlayerMenuState.cs +++ b/src/SharpModMenu/PlayerMenuState.cs @@ -410,7 +410,6 @@ public bool DrawActiveMenu() BackgroundSb.Clear(); bool firstLine = true; - int linesWrote = 0; void writeLine(string text, TextStyling style, int? selectionIndex) { if (firstLine) @@ -423,23 +422,30 @@ void writeLine(string text, TextStyling style, int? selectionIndex) BackgroundSb.AppendLine(); } - StringBuilder sb = style.Foreground ? ForegroundTextSb : BackgroundTextSb; + int newlineCount = 0; + for (int i = 0; i < text.Length; i++) + if (text[i] == '\n') + newlineCount++; + var syncNewlines = newlineCount == 0 ? string.Empty : new string('\n', newlineCount); - if (selectionIndex.HasValue) - { - sb.Append($"{selectionIndex}. "); - BackgroundSb.Append($"{selectionIndex}. "); - - if (style.Highlight) - HighlightTextSb.Append($"{selectionIndex}. "); - } - sb.Append(text); - BackgroundSb.Append(text); + var sb = style.Foreground ? ForegroundTextSb : BackgroundTextSb; + var formattedLine = text; + if (selectionIndex.HasValue) + formattedLine = $"{selectionIndex}. {formattedLine}"; + + sb.Append(formattedLine); + BackgroundSb.Append(formattedLine); if (style.Highlight) - HighlightTextSb.Append(text); - - linesWrote++; + HighlightTextSb.Append(formattedLine); + + // keep newlines in sync with the other entities + if (sb == ForegroundTextSb) + BackgroundTextSb.Append(syncNewlines); + else if (sb == BackgroundTextSb) + ForegroundTextSb.Append(syncNewlines); + if (!style.Highlight) + HighlightTextSb.Append(syncNewlines); } BuildMenuStrings(CurrentMenu, writeLine); @@ -491,6 +497,9 @@ void writeLine(string text, TextStyling style, int? selectIndex) if (string.IsNullOrEmpty(text)) return; + if (text.IndexOf('\n') >= 0) + text = text.Replace("\n", "
"); + if (firstLine) firstLine = false; else