From a0923c10842657f2313e8140cbfb1733dff05309 Mon Sep 17 00:00:00 2001 From: Katt Date: Wed, 23 Jul 2025 07:23:48 -0400 Subject: [PATCH] Update MenuListItem.cs --- MenuAPI/items/MenuListItem.cs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/MenuAPI/items/MenuListItem.cs b/MenuAPI/items/MenuListItem.cs index e83ab37..b3e8a29 100644 --- a/MenuAPI/items/MenuListItem.cs +++ b/MenuAPI/items/MenuListItem.cs @@ -12,11 +12,13 @@ public class MenuListItem : MenuItem public bool ShowOpacityPanel { get; set; } = false; public bool ShowColorPanel { get; set; } = false; public ColorPanelType ColorPanelColorType = ColorPanelType.Hair; + public enum ColorPanelType { Hair, Makeup } + public int ItemsCount => ListItems.Count; public string GetCurrentSelection() @@ -29,6 +31,7 @@ public string GetCurrentSelection() } public MenuListItem(string text, List items, int index) : this(text, items, index, null) { } + public MenuListItem(string text, List items, int index, string description) : base(text, description) { ListItems = items; @@ -71,6 +74,7 @@ internal override void GoRight() { int oldIndex = ListIndex; int newIndex = oldIndex; + if (ListIndex >= ItemsCount - 1) { newIndex = 0; @@ -79,13 +83,14 @@ internal override void GoRight() { newIndex++; } + ListIndex = newIndex; ParentMenu.ListItemIndexChangeEvent(ParentMenu, this, oldIndex, newIndex, Index); + #if FIVEM PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false); #endif #if REDM - // Has invalid parameter types in API. Call((CitizenFX.Core.Native.Hash)0xCE5D0FFE83939AF1, -1, "NAV_RIGHT", "HUD_SHOP_SOUNDSET", 1); #endif } @@ -97,6 +102,7 @@ internal override void GoLeft() { int oldIndex = ListIndex; int newIndex = oldIndex; + if (ListIndex < 1) { newIndex = ItemsCount - 1; @@ -105,19 +111,40 @@ internal override void GoLeft() { newIndex--; } - ListIndex = newIndex; + ListIndex = newIndex; ParentMenu.ListItemIndexChangeEvent(ParentMenu, this, oldIndex, newIndex, Index); + #if FIVEM PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false); #endif #if REDM - // Has invalid parameter types in API. Call((CitizenFX.Core.Native.Hash)0xCE5D0FFE83939AF1, -1, "NAV_LEFT", "HUD_SHOP_SOUNDSET", 1); #endif } } + public void SetIndex(int index) + { + if (ItemsCount == 0) return; + + int clampedIndex = index; + + while (clampedIndex < 0) + clampedIndex += ItemsCount; + + while (clampedIndex >= ItemsCount) + clampedIndex -= ItemsCount; + + if (ListIndex != clampedIndex) + { + int oldIndex = ListIndex; + ListIndex = clampedIndex; + + ParentMenu?.ListItemIndexChangeEvent(ParentMenu, this, oldIndex, ListIndex, Index); + } + } + internal override void Select() { ParentMenu.ListItemSelectEvent(ParentMenu, this, ListIndex, Index);