Skip to content

Commit 41493e2

Browse files
committed
Improve fallback HTML menu
- Accept bound numeric keys as inputs without blocking player movement - Format as "1. Item" and not "/1 Item" matching the entity based renderer - Accept empty lines as valid - Sizes empty lines using a black period, which is effectively invisible
1 parent 75b678a commit 41493e2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

docs/CenterHtmlFallbackCropped.png

36.8 KB
Loading

src/SharpModMenu/PlayerMenuState.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ public Vector2 MenuPosition
358358
private nint MenuCurrentObserver { get; set; } = nint.Zero;
359359
private ObserverMode MenuCurrentObserverMode { get; set; }
360360
private CBaseEntity? MenuCurrentViewmodel { get; set; }
361+
361362
public bool DrawActiveMenu()
362363
{
363364
return false; // nothing to parent to right now, further work needed
@@ -391,12 +392,9 @@ public bool DrawActiveMenu()
391392
CurrentMenu.IsDirty = false;
392393

393394
var observerInfo = Player.GetObserverInfo();
395+
CanUseKeybinds = observerInfo.Mode == ObserverMode.FirstPerson && observerInfo.Observing?.Index == Player.Pawn.Index;
394396
if (observerInfo.Mode != ObserverMode.FirstPerson)
395-
{
396-
CanUseKeybinds = false;
397397
return false;
398-
}
399-
CanUseKeybinds = observerInfo.Mode == ObserverMode.FirstPerson && observerInfo.Observing?.Index == Player.Pawn.Index;
400398

401399
var maybeEyeAngles = observerInfo.GetEyeAngles();
402400
if (!maybeEyeAngles.HasValue)
@@ -487,21 +485,24 @@ void writeLine(string text, TextStyling style, int? selectionIndex)
487485

488486
public void DrawActiveMenuHtml()
489487
{
488+
var observerInfo = Player.GetObserverInfo();
489+
CanUseKeybinds = observerInfo.Mode == ObserverMode.FirstPerson && observerInfo.Observing?.Index == Player.Pawn.Index;
490+
490491
if (CurrentMenu is null)
491492
{
492493
HtmlContent = null;
493494
return;
494495
}
495496

496497
bool firstLine = true;
497-
int linesWrote = 0;
498498
void writeLine(string text, TextStyling style, int? selectIndex)
499499
{
500-
if (string.IsNullOrEmpty(text))
501-
return;
502-
503500
if (text.IndexOf('\n') >= 0)
501+
{
504502
text = text.Replace("\n", "<br>");
503+
while (text.Contains("<br><br>"))
504+
text = text.Replace("<br><br>", "<br><font color='#000'>.</font><br>");
505+
}
505506

506507
if (firstLine)
507508
firstLine = false;
@@ -516,9 +517,11 @@ void writeLine(string text, TextStyling style, int? selectIndex)
516517
{ Foreground: false, Highlight: false } => "#E7CCA5",
517518
};
518519

519-
var selectionPrefix = selectIndex.HasValue ? $"/{selectIndex.Value} " : string.Empty;
520-
HtmlTextSb.Append($"<font color='{color}'>{selectionPrefix}{text}</font>");
521-
linesWrote++;
520+
var selectionPrefix = selectIndex.HasValue ? $"{selectIndex.Value}. " : string.Empty;
521+
if (string.IsNullOrEmpty(text))
522+
HtmlTextSb.Append($"<font color='#000'>.</font>");
523+
else
524+
HtmlTextSb.Append($"<font color='{color}'>{selectionPrefix}{text}</font>");
522525
}
523526

524527
HtmlTextSb.Clear();

0 commit comments

Comments
 (0)