Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
C# RadialMenu:
- Added quantity for SegmentItems
- Added Enable3D parameter for menu
  • Loading branch information
manups4e committed Aug 3, 2023
1 parent 874efa2 commit d94cb16
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
7 changes: 5 additions & 2 deletions MenuExample/MenuExample.cs
Expand Up @@ -985,15 +985,18 @@ public void CreateRadialMenu()
long imgdui = API.CreateDui("https://giphy.com/embed/ckT59CvStmUsU", 64, 64);
API.CreateRuntimeTextureFromDuiHandle(txd, "item1", API.GetDuiHandle(imgdui));

long imgdui1 = API.CreateDui("https://giphy.com/embed/10bTCLE8GtHHS8", 64, 96);
long imgdui1 = API.CreateDui("https://giphy.com/embed/10bTCLE8GtHHS8", 96, 64);
API.CreateRuntimeTextureFromDuiHandle(txd, "item2", API.GetDuiHandle(imgdui1));

long imgdui2 = API.CreateDui("https://giphy.com/embed/nHyZigjdO4hEodq9fv", 64, 64);
API.CreateRuntimeTextureFromDuiHandle(txd, "item3", API.GetDuiHandle(imgdui2));

SegmentItem item = new SegmentItem("This is the label!", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item1", 64, 64, HudColor.HUD_COLOUR_FREEMODE);
SegmentItem item1 = new SegmentItem("It's so long it scrolls automatically! Isn't this amazing?", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item2", 64, 96, HudColor.HUD_COLOUR_GREEN);
SegmentItem item1 = new SegmentItem("It's so long it scrolls automatically! Isn't this amazing?", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item2", 96, 64, HudColor.HUD_COLOUR_GREEN);
SegmentItem item2 = new SegmentItem("Label 3", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item3", 64, 64, HudColor.HUD_COLOUR_RED);
item.SetQuantity(8000, 9999);
item1.SetQuantity(50, 100);
item2.SetQuantity(5000, 0);

for (int i = 0; i < 8; i++)
{
Expand Down
18 changes: 16 additions & 2 deletions ScaleformUI_Csharp/Menus/RadialMenu/RadialMenu.cs
Expand Up @@ -29,6 +29,20 @@ public class RadialMenu : MenuBase
public SegmentChanged OnSegmentHighlighted;
public IndexChanged OnSegmentIndexChanged;
public SegmentSelected OnSegmentSelected;
private bool enable3D = true;

public bool Enable3D
{
get => enable3D;
set
{
enable3D = value;
if (Visible)
{
Main.radialMenu.CallFunction("ENABLE_3D", value);
}
}
}

public override bool Visible
{
Expand Down Expand Up @@ -83,14 +97,14 @@ public RadialMenu(PointF offset)
internal async void BuildMenu()
{
if (_offset.IsEmpty) _offset = new PointF(Screen.Width / 2, (Screen.Height / 2) - 60);
Main.radialMenu.CallFunction("CREATE_MENU", false, _offset.X, _offset.Y);
Main.radialMenu.CallFunction("CREATE_MENU", enable3D, _offset.X, _offset.Y);
for (int i = 0; i < 8; i++)
{
RadialSegment segment = Segments[i];
for (int j = 0; j < segment.Items.Count; j++)
{
SegmentItem item = segment.Items[j];
Main.radialMenu.CallFunction("ADD_ITEM", i, item.Label, item.Description, item.TextureDict, item.TextureName, item.TextureWidth, item.TextureHeight, (int)item.Color);
Main.radialMenu.CallFunction("ADD_ITEM", i, item.Label, item.Description, item.TextureDict, item.TextureName, item.TextureWidth, item.TextureHeight, (int)item.Color, item.qtty, item.max);
}
}
Main.radialMenu.CallFunction("LOAD_MENU", currentSelection, Segments[0].CurrentSelection, Segments[1].CurrentSelection, Segments[2].CurrentSelection, Segments[3].CurrentSelection, Segments[4].CurrentSelection, Segments[5].CurrentSelection, Segments[6].CurrentSelection, Segments[7].CurrentSelection);
Expand Down
4 changes: 2 additions & 2 deletions ScaleformUI_Csharp/Menus/RadialMenu/RadialSegment.cs
Expand Up @@ -23,7 +23,7 @@ public void AddItem(SegmentItem item)
Items.Add(item);
if (Parent != null && Parent.Visible)
{
Main.radialMenu.CallFunction("ADD_ITEM", item.Label, item.Description, item.TextureDict, item.TextureName, item.TextureWidth, item.TextureHeight, item.Color);
Main.radialMenu.CallFunction("ADD_ITEM", item.Label, item.Description, item.TextureDict, item.TextureName, item.TextureWidth, item.TextureHeight, item.Color, item.qtty, item.max);
}
}

Expand All @@ -39,7 +39,7 @@ public void RemoveItem(SegmentItem item)
}
}

public async Task<int> CycleItems(int direction)
internal async Task<int> CycleItems(int direction)
{
currentSelection = await Main.radialMenu.CallFunctionReturnValueInt("SET_INPUT_EVENT", direction == -1 ? 10 : 11);
OnIndexChanged?.Invoke(this, currentSelection);
Expand Down
31 changes: 24 additions & 7 deletions ScaleformUI_Csharp/Menus/RadialMenu/SegmentItem.cs
Expand Up @@ -10,6 +10,8 @@ public class SegmentItem
private string textureName;
private string textureDict;
internal RadialSegment Parent;
internal int qtty = 0;
internal int max = 0;

public string Label
{
Expand All @@ -19,7 +21,7 @@ public string Label
label = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}
Expand All @@ -31,7 +33,7 @@ public string Description
description = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}
Expand All @@ -43,7 +45,7 @@ public string TextureDict
textureDict = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}
Expand All @@ -55,7 +57,7 @@ public string TextureName
textureName = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}
Expand All @@ -67,7 +69,7 @@ public int TextureWidth
textureWidth = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}
Expand All @@ -79,7 +81,7 @@ public int TextureHeight
textureHeight = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}
Expand All @@ -91,11 +93,26 @@ public HudColor Color
color = value;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color);
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}
}

/// <summary>
/// Set the quantity of this item, if max == 0 then the quantity will be centered
/// </summary>
/// <param name="qtty"></param>
/// <param name="max"></param>
public void SetQuantity(int qtty, int max = 0)
{
this.qtty = qtty;
this.max = max;
if (Parent != null && Parent.Parent != null && Parent.Parent.Visible)
{
Main.radialMenu.CallFunction("UPDATE_SUBITEM", Parent.index, Parent.Items.IndexOf(this), label, description, textureName, textureDict, textureHeight, textureWidth, color, qtty, max);
}
}

public SegmentItem(string label, string desc, string txd, string txn, int txwidth, int txheight, HudColor color)
{
Label = label;
Expand Down

0 comments on commit d94cb16

Please sign in to comment.