Skip to content
Open
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
33 changes: 30 additions & 3 deletions MenuAPI/items/MenuListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -29,6 +31,7 @@ public string GetCurrentSelection()
}

public MenuListItem(string text, List<string> items, int index) : this(text, items, index, null) { }

public MenuListItem(string text, List<string> items, int index, string description) : base(text, description)
{
ListItems = items;
Expand Down Expand Up @@ -71,6 +74,7 @@ internal override void GoRight()
{
int oldIndex = ListIndex;
int newIndex = oldIndex;

if (ListIndex >= ItemsCount - 1)
{
newIndex = 0;
Expand All @@ -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
}
Expand All @@ -97,6 +102,7 @@ internal override void GoLeft()
{
int oldIndex = ListIndex;
int newIndex = oldIndex;

if (ListIndex < 1)
{
newIndex = ItemsCount - 1;
Expand All @@ -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);
Expand Down