Skip to content

Commit 61aa21c

Browse files
committed
- fix: Resolve stack overflow issue in menu pagination logic
- feat: Add DisableOption support for AddItem method
1 parent 099e0cb commit 61aa21c

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

API/Class/BaseMenu.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ public abstract class BaseMenu(string title, BasePlugin plugin) : IMenu
5050
/// </summary>
5151
/// <param name="display">The text to display for the item.</param>
5252
/// <param name="onSelect">The action to perform when the item is selected.</param>
53+
/// <param name="disableOption">The disable option for the item.</param>
5354
/// <returns>The created item option.</returns>
54-
public virtual ItemOption AddItem(string display, Action<CCSPlayerController, ItemOption> onSelect)
55+
public virtual ItemOption AddItem(string display, Action<CCSPlayerController, ItemOption> onSelect, DisableOption disableOption = DisableOption.None)
5556
{
56-
ItemOption option = new(display, DisableOption.None, onSelect);
57+
ItemOption option = new(display, disableOption, onSelect);
5758
ItemOptions.Add(option);
5859
return option;
5960
}
@@ -272,18 +273,12 @@ internal void DeregisterOnKeyPress()
272273
if (Menu is WasdMenu || (Menu is ScreenMenu screenMenu && screenMenu.MenuType == MenuType.Scrollable))
273274
return;
274275

275-
foreach (KeyValuePair<string, CommandCallback> kvp in _keyCommands)
276-
{
277-
if (_keyCommands.ContainsKey(kvp.Key))
278-
{
279-
Menu.Plugin.RemoveCommand(kvp.Key, kvp.Value);
280-
}
281-
}
276+
foreach (var kvp in _keyCommands)
277+
Menu.Plugin.RemoveCommand(kvp.Key, kvp.Value);
282278

283279
_keyCommands.Clear();
284280
}
285281

286-
287282
internal void RegisterPlayerDisconnectEvent()
288283
{
289284
Menu.Plugin.RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);

API/Interface/IMenu.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public interface IMenu
4444
/// </summary>
4545
/// <param name="display">The text to display for the item.</param>
4646
/// <param name="onSelect">The action to perform when the item is selected.</param>
47+
/// <param name="disableOption">The disable option for the item.</param>
4748
/// <returns>The created item option.</returns>
48-
ItemOption AddItem(string display, Action<CCSPlayerController, ItemOption> onSelect);
49+
ItemOption AddItem(string display, Action<CCSPlayerController, ItemOption> onSelect, DisableOption disableOption = DisableOption.None);
4950

5051
/// <summary>
5152
/// Adds an item to the menu with a specified display text and disable option.

API/Menu/CenterHtmlMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class CenterHtmlMenuInstance : BaseMenuInstance
9797
/// <summary>
9898
/// Gets a value indicating whether the menu has a next button.
9999
/// </summary>
100-
protected override bool HasNextButton => Menu.ItemOptions.Count > MenuItemsPerPage + 1 && CurrentOffset + NumPerPage < Menu.ItemOptions.Count;
100+
protected override bool HasNextButton => Menu.ItemOptions.Count > NumPerPage + 1 && CurrentOffset + NumPerPage < Menu.ItemOptions.Count;
101101

102102
/// <summary>
103103
/// Initializes a new instance of the <see cref="CenterHtmlMenuInstance"/> class.

0 commit comments

Comments
 (0)