Skip to content

Commit 3904303

Browse files
committed
Added: css_sharpmodmenu_pos_x/y
- Allow players to position their menu position - Selected a better default for 5:4 players
1 parent f5598bd commit 3904303

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/SharpModMenu/PlayerMenuState.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,20 @@ private void UpdateEntity(
327327
Utilities.SetStateChanged(ent, "CPointWorldText", "m_messageText");
328328
}
329329

330-
private readonly Vector MenuPosition = new(-6.9f, 0.0f);
330+
private Vector2 _MenuPosition = new(-6.55f, 0.0f);
331+
public Vector2 MenuPosition
332+
{
333+
get => _MenuPosition;
334+
set
335+
{
336+
_MenuPosition = value;
337+
if (CurrentMenu is not null)
338+
{
339+
CurrentMenu.IsDirty = true;
340+
Refresh(false);
341+
}
342+
}
343+
}
331344

332345
private Menu? LastPresented { get; set; }
333346
private readonly StringBuilder HighlightTextSb = new();

src/SharpModMenu/SharpModMenu.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Runtime.InteropServices;
45
using System.Text;
56

@@ -447,6 +448,56 @@ public void Css0(CCSPlayerController player, CommandInfo info)
447448
menuState.HandleInput(PlayerKey.SelectItem0, info.CallingContext == CommandCallingContext.Console);
448449
}
449450

451+
[ConsoleCommand("css_sharpmodmenu_pos_x")]
452+
public void SharpModMenuPosX(CCSPlayerController player, CommandInfo info)
453+
{
454+
if (player is null || !player.IsValid)
455+
return;
456+
var menuState = DriverInstance?.GetMenuState(player, create: true);
457+
if (menuState is null)
458+
return;
459+
460+
if (info.ArgCount != 2)
461+
{
462+
info.ReplyToCommand($"css_sharpmodmenu_pos_x: Invalid number of arguments provided");
463+
return;
464+
}
465+
466+
var valStr = info.ArgByIndex(1);
467+
if (!float.TryParse(valStr, CultureInfo.InvariantCulture, out var val))
468+
{
469+
info.ReplyToCommand($"css_sharpmodmenu_pos_x: Failed to parse argument as float: {valStr}");
470+
return;
471+
}
472+
473+
menuState.MenuPosition = menuState.MenuPosition with { X = val };
474+
}
475+
476+
[ConsoleCommand("css_sharpmodmenu_pos_y")]
477+
public void SharpModMenuPosY(CCSPlayerController player, CommandInfo info)
478+
{
479+
if (player is null || !player.IsValid)
480+
return;
481+
var menuState = DriverInstance?.GetMenuState(player, create: true);
482+
if (menuState is null)
483+
return;
484+
485+
if (info.ArgCount != 2)
486+
{
487+
info.ReplyToCommand($"css_sharpmodmenu_pos_y: Invalid number of arguments provided");
488+
return;
489+
}
490+
491+
var valStr = info.ArgByIndex(1);
492+
if (!float.TryParse(valStr, CultureInfo.InvariantCulture, out var val))
493+
{
494+
info.ReplyToCommand($"css_sharpmodmenu_pos_y: failed to parse argument as float: {valStr}");
495+
return;
496+
}
497+
498+
menuState.MenuPosition = menuState.MenuPosition with { Y = val };
499+
}
500+
450501

451502
public static string[] PrimaryGuns { get; } =
452503
{

0 commit comments

Comments
 (0)