Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/SharpModMenu/PlayerMenuState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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", "<br>");

if (firstLine)
firstLine = false;
else
Expand Down
Loading