Skip to content

Commit 4bf9a55

Browse files
authored
feat: Add support for disabling exit button (#135)
1 parent eeab02f commit 4bf9a55

File tree

6 files changed

+54
-17
lines changed

6 files changed

+54
-17
lines changed

managed/src/SwiftlyS2.Core/Modules/Menus/MenuAPI.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,17 +423,17 @@ private string BuildMenuHtml( IPlayer player, IReadOnlyList<IMenuOption> visible
423423
"wasd" => string.Concat(
424424
"<br>", guideLine, "<br>",
425425
"<font class='fontSize-s' color='#FFFFFF'>",
426-
$"<font color='{footerColor}'>Move:</font> W/S | ",
427-
$"<font color='{footerColor}'>Use:</font> D | ",
428-
$"<font color='{footerColor}'>Exit:</font> A",
426+
$"<font color='{footerColor}'>Move:</font> W/S",
427+
$" | <font color='{footerColor}'>Use:</font> D",
428+
Configuration.DisableExit ? string.Empty : $" | <font color='{footerColor}'>Exit:</font> A",
429429
"</font>"
430430
),
431431
_ => string.Concat(
432432
"<br>", guideLine, "<br>",
433433
"<font class='fontSize-s' color='#FFFFFF'>",
434-
$"<font color='{footerColor}'>Move:</font> {KeybindOverrides.Move?.ToString() ?? core.MenusAPI.Configuration.ButtonsScroll.ToUpper()}/{KeybindOverrides.MoveBack?.ToString() ?? core.MenusAPI.Configuration.ButtonsScrollBack.ToUpper()} | ",
435-
$"<font color='{footerColor}'>Use:</font> {KeybindOverrides.Select?.ToString() ?? core.MenusAPI.Configuration.ButtonsUse.ToUpper()} | ",
436-
$"<font color='{footerColor}'>Exit:</font> {KeybindOverrides.Exit?.ToString() ?? core.MenusAPI.Configuration.ButtonsExit.ToUpper()}",
434+
$"<font color='{footerColor}'>Move:</font> {KeybindOverrides.Move?.ToString() ?? core.MenusAPI.Configuration.ButtonsScroll.ToUpper()}/{KeybindOverrides.MoveBack?.ToString() ?? core.MenusAPI.Configuration.ButtonsScrollBack.ToUpper()}",
435+
$" | <font color='{footerColor}'>Use:</font> {KeybindOverrides.Select?.ToString() ?? core.MenusAPI.Configuration.ButtonsUse.ToUpper()}",
436+
Configuration.DisableExit ? string.Empty : $" | <font color='{footerColor}'>Exit:</font> {KeybindOverrides.Exit?.ToString() ?? core.MenusAPI.Configuration.ButtonsExit.ToUpper()}",
437437
"</font>"
438438
)
439439
};

managed/src/SwiftlyS2.Core/Modules/Menus/MenuBuilderAPI.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public IMenuBuilderAPI DisableSound()
4949
return this;
5050
}
5151

52+
public IMenuBuilderAPI EnableExit()
53+
{
54+
configuration.DisableExit = false;
55+
return this;
56+
}
57+
58+
public IMenuBuilderAPI DisableExit()
59+
{
60+
configuration.DisableExit = true;
61+
return this;
62+
}
63+
5264
public IMenuBuilderAPI SetPlayerFrozen( bool frozen = false )
5365
{
5466
configuration.FreezePlayer = frozen;

managed/src/SwiftlyS2.Core/Modules/Menus/MenuManagerAPI.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ internal void OnClientKeyStateChanged( IOnClientKeyStateChangedEvent @event )
151151
}
152152
else if (exitKey.HasFlag(@event.Key.ToKeyBind()))
153153
{
154-
CloseMenuForPlayerInternal(player, menu, true);
155-
156-
if (menu.Configuration.PlaySound)
154+
if (!menu.Configuration.DisableExit)
157155
{
158-
exitSound.Recipients.AddRecipient(@event.PlayerId);
159-
_ = exitSound.Emit();
160-
exitSound.Recipients.RemoveRecipient(@event.PlayerId);
156+
CloseMenuForPlayerInternal(player, menu, true);
157+
158+
if (menu.Configuration.PlaySound)
159+
{
160+
exitSound.Recipients.AddRecipient(@event.PlayerId);
161+
_ = exitSound.Emit();
162+
exitSound.Recipients.RemoveRecipient(@event.PlayerId);
163+
}
161164
}
162165
}
163166
else if (useKey.HasFlag(@event.Key.ToKeyBind()))
@@ -202,12 +205,16 @@ internal void OnClientKeyStateChanged( IOnClientKeyStateChangedEvent @event )
202205
}
203206
else if (KeyBind.A.HasFlag(@event.Key.ToKeyBind()))
204207
{
205-
CloseMenuForPlayerInternal(player, menu, true);
206-
if (menu.Configuration.PlaySound)
208+
if (!menu.Configuration.DisableExit)
207209
{
208-
exitSound.Recipients.AddRecipient(@event.PlayerId);
209-
_ = exitSound.Emit();
210-
exitSound.Recipients.RemoveRecipient(@event.PlayerId);
210+
CloseMenuForPlayerInternal(player, menu, true);
211+
212+
if (menu.Configuration.PlaySound)
213+
{
214+
exitSound.Recipients.AddRecipient(@event.PlayerId);
215+
_ = exitSound.Emit();
216+
exitSound.Recipients.RemoveRecipient(@event.PlayerId);
217+
}
211218
}
212219
}
213220
else if (KeyBind.D.HasFlag(@event.Key.ToKeyBind()))

managed/src/SwiftlyS2.Shared/Modules/Menus/IMenuAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public int MaxVisibleItems {
7676
/// </summary>
7777
public bool FreezePlayer { get; set; } = false;
7878

79+
/// <summary>
80+
/// Whether to disable the exit button for this menu.
81+
/// </summary>
82+
public bool DisableExit { get; set; } = false;
83+
7984
/// <summary>
8085
/// Time in seconds before the menu automatically closes. Set to 0 or less to disable auto-close.
8186
/// </summary>

managed/src/SwiftlyS2.Shared/Modules/Menus/IMenuBuilderAPI.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public interface IMenuBuilderAPI
3737
/// <returns>This builder for method chaining.</returns>
3838
public IMenuBuilderAPI DisableSound();
3939

40+
/// <summary>
41+
/// Enables the exit button for this menu.
42+
/// </summary>
43+
/// <returns>This builder for method chaining.</returns>
44+
public IMenuBuilderAPI EnableExit();
45+
46+
/// <summary>
47+
/// Disables the exit button for this menu.
48+
/// </summary>
49+
/// <returns>This builder for method chaining.</returns>
50+
public IMenuBuilderAPI DisableExit();
51+
4052
/// <summary>
4153
/// Controls whether player movement is frozen while the menu is open.
4254
/// </summary>

managed/src/TestPlugin/TestPlugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ public void RefactoredMenuTestCommand( ICommandContext context )
885885
var player = context.Sender!;
886886
var menu = Core.MenusAPI
887887
.CreateBuilder()
888+
.EnableExit()
888889
.SetPlayerFrozen(false)
889890
.Design.SetMaxVisibleItems(5)
890891
.Design.SetMenuTitle($"{HtmlGradient.GenerateGradientText("Redesigned Menu", "#00FA9A", "#F5FFFA")}")

0 commit comments

Comments
 (0)