Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
C#:
- Added RadialMenu
- Generalized with MenuBase for UIMenu and RadialMenu
- Adapted BreadcrumbsHandler to support MenuBase and its variants
  • Loading branch information
manups4e committed Jul 31, 2023
1 parent 912b76b commit f39bc3f
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 37 deletions.
63 changes: 61 additions & 2 deletions MenuExample/MenuExample.cs
Expand Up @@ -6,6 +6,7 @@
using ScaleformUI.LobbyMenu;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenu;
using ScaleformUI.Radial;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand All @@ -20,6 +21,7 @@ public class MenuExample : BaseScript
private long txd;
private Random Random = new Random(API.GetGameTimer());

#region UIMenu
public void ExampleMenu()
{
long _titledui = API.CreateDui("https://i.imgur.com/3yrFYbF.gif", 288, 130);
Expand Down Expand Up @@ -974,6 +976,60 @@ public async Task FloatingHelpTimer()
Tick -= FloatingHelpTimer;
await Task.FromResult(0);
}
#endregion

public void CreateRadialMenu()
{
RadialMenu menu = new RadialMenu();

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);
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 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);

for (int i = 0; i < 8; i++)
{
menu.Segments[i].AddItem(item);
menu.Segments[i].AddItem(item1);
menu.Segments[i].AddItem(item2);
}

menu.OnMenuOpen += (menu, _) =>
{
Screen.ShowSubtitle("Radial Menu opened!");
};

menu.OnMenuClose += (menu) =>
{
Screen.ShowSubtitle("Radial Menu closed!");
};

menu.OnSegmentHighlighted += (segment) =>
{
Screen.ShowSubtitle($"Segment {segment.Index} highlighted!");
};

menu.OnSegmentIndexChanged += (segment, index) =>
{
Screen.ShowSubtitle($"Segment {segment.Index}, index changed to {index}!");
};

menu.OnSegmentSelected += (segment) =>
{
Screen.ShowSubtitle($"Segment {segment.Index} selected!");
};

menu.CurrentSegment = 1;
menu.Visible = true;
}

public async void PauseMenuShowcase(UIMenu _menu)
{
Expand Down Expand Up @@ -1486,8 +1542,6 @@ public async void LobbyPauseMenuShowcase(UIMenu _menu)

pauseMenu.Visible = true;
//API.UnregisterPedheadshot(mugshot);


}

bool feedOpen = false;
Expand Down Expand Up @@ -1516,6 +1570,11 @@ public MenuExample()
if (Game.IsControlJustPressed(0, Control.SelectCharacterMichael) && !MenuHandler.IsAnyMenuOpen) // Our menu enabler (to exit menu simply press Back on the main menu)
ExampleMenu();
if (Game.IsControlJustPressed(0, Control.DropAmmo) && !MenuHandler.IsAnyMenuOpen)
{
CreateRadialMenu();
}
// to open the pause menu without opening the normal menu.
if (Game.IsControlJustPressed(0, Control.SelectCharacterFranklin) && !MenuHandler.IsAnyMenuOpen && !MenuHandler.IsAnyPauseMenuOpen)
PauseMenuShowcase(null);
Expand Down
@@ -1,16 +1,16 @@
namespace ScaleformUI.Menu
namespace ScaleformUI.Menus
{
internal static class BreadcrumbsHandler
{
private static readonly List<Tuple<UIMenu, dynamic>> breadcrumbs = new List<Tuple<UIMenu, dynamic>>();
private static readonly List<Tuple<MenuBase, dynamic>> breadcrumbs = new List<Tuple<MenuBase, dynamic>>();
internal static int Count => breadcrumbs.Count;
internal static int CurrentDepth => breadcrumbs.Count - 1;
internal static UIMenu PreviousMenu => breadcrumbs[CurrentDepth - 1].Item1;
internal static MenuBase PreviousMenu => breadcrumbs[CurrentDepth - 1].Item1;
public static bool SwitchInProgress = false;

internal static void Forward(UIMenu menu, dynamic data)
internal static void Forward(MenuBase menu, dynamic data)
{
breadcrumbs.Add(new Tuple<UIMenu, dynamic>(menu, data));
breadcrumbs.Add(new Tuple<MenuBase, dynamic>(menu, data));
}

internal static void Clear()
Expand Down
10 changes: 6 additions & 4 deletions ScaleformUI_Csharp/Menus/MenuBase.cs
@@ -1,4 +1,6 @@
namespace ScaleformUI.Menus
using ScaleformUI.Menu;

namespace ScaleformUI.Menus
{
public class MenuBase
{
Expand All @@ -13,15 +15,15 @@ public virtual bool Visible
}
}
public List<InstructionalButton> InstructionalButtons { get; set; }
public virtual void ProcessControls()
internal virtual void ProcessControl(Keys key = Keys.None)
{

}
public virtual void ProcessMouse()
internal virtual void ProcessMouse()
{

}
public virtual void Draw()
internal virtual void Draw()
{
}
}
Expand Down
47 changes: 30 additions & 17 deletions ScaleformUI_Csharp/Menus/MenuHandler.cs
@@ -1,7 +1,9 @@
using CitizenFX.Core;
using CitizenFX.Core.Native;
using ScaleformUI.Menu;
using ScaleformUI.Menus;
using ScaleformUI.PauseMenus;
using ScaleformUI.Radial;

namespace ScaleformUI
{
Expand All @@ -12,7 +14,7 @@ namespace ScaleformUI
/// </summary>
public static class MenuHandler
{
internal static UIMenu currentMenu;
internal static MenuBase currentMenu;
internal static PauseMenuBase currentBase;
internal static bool ableToDraw;
private static Ped _ped;
Expand All @@ -31,7 +33,7 @@ internal static Ped PlayerPed
}
}

public static UIMenu CurrentMenu
public static MenuBase CurrentMenu
{
get => currentMenu;
private set => currentMenu = value;
Expand All @@ -43,7 +45,7 @@ public static PauseMenuBase CurrentPauseMenu
private set => currentBase = value;
}

public static async Task SwitchTo(this UIMenu currentMenu, UIMenu newMenu, int newMenuCurrentSelection = 0, bool inheritOldMenuParams = false, dynamic data = null)
public static async Task SwitchTo(this MenuBase currentMenu, MenuBase newMenu, int newMenuCurrentSelection = 0, bool inheritOldMenuParams = false, dynamic data = null)
{
if (currentMenu == null)
throw new ArgumentNullException("The menu you're switching from cannot be null.");
Expand All @@ -57,24 +59,35 @@ public static async Task SwitchTo(this UIMenu currentMenu, UIMenu newMenu, int n

BreadcrumbsHandler.SwitchInProgress = true;

if (inheritOldMenuParams)
if (newMenu is UIMenu newer)
{
if (currentMenu._customTexture.Key != null && currentMenu._customTexture.Value != null)
newMenu.SetBannerType(currentMenu._customTexture);
newMenu.Offset = currentMenu.Offset;
newMenu.MouseEdgeEnabled = currentMenu.MouseEdgeEnabled;
newMenu.MouseWheelControlEnabled = currentMenu.MouseWheelControlEnabled;
newMenu.MouseControlsEnabled = currentMenu.MouseControlsEnabled;
newMenu.MaxItemsOnScreen = currentMenu.MaxItemsOnScreen;
newMenu.AnimationType = currentMenu.AnimationType;
newMenu.BuildingAnimation = currentMenu.BuildingAnimation;
newMenu.ScrollingType = currentMenu.ScrollingType;
if (currentMenu is UIMenu old)
{
if (inheritOldMenuParams)
{
if (old._customTexture.Key != null && old._customTexture.Value != null)
newer.SetBannerType(old._customTexture);
newer.Offset = old.Offset;
newer.MouseEdgeEnabled = old.MouseEdgeEnabled;
newer.MouseWheelControlEnabled = old.MouseWheelControlEnabled;
newer.MouseControlsEnabled = old.MouseControlsEnabled;
newer.MaxItemsOnScreen = old.MaxItemsOnScreen;
newer.AnimationType = old.AnimationType;
newer.BuildingAnimation = old.BuildingAnimation;
newer.ScrollingType = old.ScrollingType;
}
newer.CurrentSelection = newMenuCurrentSelection != 0 ? newMenuCurrentSelection : 0;
}
else if (currentMenu is RadialMenu rad)
rad.CurrentSegment = newMenuCurrentSelection != 0 ? newMenuCurrentSelection : 0;
}
newMenu.CurrentSelection = newMenuCurrentSelection != 0 ? newMenuCurrentSelection : 0;
await currentMenu.FadeOutMenu();

if (currentMenu is UIMenu _old)
await _old.FadeOutMenu();
currentMenu.Visible = false;
newMenu.Visible = true;
await currentMenu.FadeInMenu();
if (newMenu is UIMenu _newer)
await _newer.FadeInMenu();
BreadcrumbsHandler.Forward(newMenu, data);
BreadcrumbsHandler.SwitchInProgress = false;
}
Expand Down

0 comments on commit f39bc3f

Please sign in to comment.