Skip to content
Merged
Show file tree
Hide file tree
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
Binary file modified docs/CenterHtmlFallbackCropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 14 additions & 11 deletions src/SharpModMenu/PlayerMenuState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
private bool CreateInitialInvisibleWorldTextEntity()
{
return false;
var observerInfo = Player.GetObserverInfo();

Check warning on line 245 in src/SharpModMenu/PlayerMenuState.cs

View workflow job for this annotation

GitHub Actions / Continuous integration

Unreachable code detected

if (_CreatedFor.HasValue && _CreatedFor.Value == observerInfo.Observing?.Handle)
return false;
Expand Down Expand Up @@ -358,11 +358,12 @@
private nint MenuCurrentObserver { get; set; } = nint.Zero;
private ObserverMode MenuCurrentObserverMode { get; set; }
private CBaseEntity? MenuCurrentViewmodel { get; set; }

public bool DrawActiveMenu()
{
return false; // nothing to parent to right now, further work needed

if (ReferenceEquals(CurrentMenu, LastPresented))

Check warning on line 366 in src/SharpModMenu/PlayerMenuState.cs

View workflow job for this annotation

GitHub Actions / Continuous integration

Unreachable code detected
{
if (CurrentMenu is not null && !CurrentMenu.IsDirty)
return true;
Expand Down Expand Up @@ -391,12 +392,9 @@
CurrentMenu.IsDirty = false;

var observerInfo = Player.GetObserverInfo();
CanUseKeybinds = observerInfo.Mode == ObserverMode.FirstPerson && observerInfo.Observing?.Index == Player.Pawn.Index;
if (observerInfo.Mode != ObserverMode.FirstPerson)
{
CanUseKeybinds = false;
return false;
}
CanUseKeybinds = observerInfo.Mode == ObserverMode.FirstPerson && observerInfo.Observing?.Index == Player.Pawn.Index;

var maybeEyeAngles = observerInfo.GetEyeAngles();
if (!maybeEyeAngles.HasValue)
Expand Down Expand Up @@ -487,21 +485,24 @@

public void DrawActiveMenuHtml()
{
var observerInfo = Player.GetObserverInfo();
CanUseKeybinds = observerInfo.Mode == ObserverMode.FirstPerson && observerInfo.Observing?.Index == Player.Pawn.Index;

if (CurrentMenu is null)
{
HtmlContent = null;
return;
}

bool firstLine = true;
int linesWrote = 0;
void writeLine(string text, TextStyling style, int? selectIndex)
{
if (string.IsNullOrEmpty(text))
return;

if (text.IndexOf('\n') >= 0)
{
text = text.Replace("\n", "<br>");
while (text.Contains("<br><br>"))
text = text.Replace("<br><br>", "<br><font color='#000'>.</font><br>");
}

if (firstLine)
firstLine = false;
Expand All @@ -516,9 +517,11 @@
{ Foreground: false, Highlight: false } => "#E7CCA5",
};

var selectionPrefix = selectIndex.HasValue ? $"/{selectIndex.Value} " : string.Empty;
HtmlTextSb.Append($"<font color='{color}'>{selectionPrefix}{text}</font>");
linesWrote++;
var selectionPrefix = selectIndex.HasValue ? $"{selectIndex.Value}. " : string.Empty;
if (string.IsNullOrEmpty(text))
HtmlTextSb.Append($"<font color='#000'>.</font>");
else
HtmlTextSb.Append($"<font color='{color}'>{selectionPrefix}{text}</font>");
}

HtmlTextSb.Clear();
Expand Down
Loading