Skip to content

Commit 2b35051

Browse files
authored
Merge pull request #249 from manups4e/experimental
ScaleformUI - Update 3: Make FiveM Great Again - Part 1 Completely rewrote the main Scaleform movie. Fixed Glare position across resolutions (16:10 is completely bad on fivem for certain ui elements) Code Breaking: Removed fading time parameter in Lua/C# UIMenu constructors Removed TextColor and HighlightedTextColor parameters in Items (unused and legacy) Disabled all animations in menu. Rewrote menu building system. Rewrote menu and components updating process. Modularized Scaleform movie to give the R* feeling we didn't know we were missing and didn't know we needed. Fixed menu switching inheritance, it's now almost instant. Performances increased up to by 40% across ScRTs. All the exposed API has not been edited to maintain compatibility with the new update, marking as obsolete all the removed features. UIMenuItem is now dynamic. UIMenuListItem supports now virtually infinite list elements I'm sure i forgot something.. 😛 All UIMenus are now updated. Next update will bring a totally renewed and rewrote PauseMenu.
2 parents 7c2e810 + 8638e0f commit 2b35051

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2299
-4044
lines changed

MenuExample/MenuExample.cs

+26-19
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ public class MenuExample : BaseScript
2929
#region UIMenu
3030
public async void ExampleMenu()
3131
{
32-
long _titledui = API.CreateDui("https://i.imgur.com/3yrFYbF.gif", 288, 130);
32+
long _titledui = API.CreateDui("https://media.tenor.com/-sL5lSwzQSkAAAAi/rolling-cute.gif", 288, 130);
3333
API.CreateRuntimeTextureFromDuiHandle(txd, "bannerbackground", API.GetDuiHandle(_titledui));
3434

3535
long _kitten = API.CreateDui("https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExczA0dXhscDRqbHBmb3I2bmk4dDVzd25uNmhhbHNmMnE5N3hkYTM0MiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/tY27Dk0H8IisGidQv6/giphy.gif", 480, 480);
3636
API.CreateRuntimeTextureFromDuiHandle(txd, "kitty", API.GetDuiHandle(_kitten));
3737

3838
// first true means add menu Glare scaleform to the menu
3939
// last true means it's using the alternative title style
40-
UIMenu exampleMenu = new UIMenu("ScaleformUI", "ScaleformUI ~o~SHOWCASE", new PointF(0, 0), "commonmenu", "interaction_bgd", true, true, 0f, MenuAlignment.RIGHT);
40+
UIMenu exampleMenu = new UIMenu("ScaleformUI", "ScaleformUI ~o~SHOWCASE", new PointF(376, 50), "commonmenu", "interaction_bgd", true, true, MenuAlignment.RIGHT);
4141
exampleMenu.MaxItemsOnScreen = 7; // To decide max items on screen at time, default 7
42-
exampleMenu.SetAnimations(true, true, MenuAnimationType.LINEAR, MenuBuildingAnimation.LEFT_RIGHT);
43-
exampleMenu.SetMouse(false, false, false, false, false);
42+
exampleMenu.SetMouse(true, false, true, false, false);
4443

4544
//exampleMenu.CounterColor = HudColor.HUD_COLOUR_PINK;
4645
// let's add the menu to the Pool
@@ -152,7 +151,7 @@ public async void ExampleMenu()
152151
UIMenuCheckboxItem ketchupItem = new UIMenuCheckboxItem("~g~Scrolling animation enabled? ~b~in a very long label to ~o~test the text scrolling feature!", UIMenuCheckboxStyle.Tick, enabled, "Do you wish to enable the scrolling animation?");
153152
long _paneldui = API.CreateDui("https://i.imgur.com/mH0Y65C.gif", 288, 160);
154153
API.CreateRuntimeTextureFromDuiHandle(txd, "panelbackground", API.GetDuiHandle(_paneldui));
155-
UIMissionDetailsPanel sidePanel = new UIMissionDetailsPanel(PanelSide.Right, "Side Panel", true, "scaleformui", "panelbackground");
154+
UIMissionDetailsPanel sidePanel = new UIMissionDetailsPanel(PanelSide.Right, "Side Panel", true, "scaleformui", "bannerbackground");
156155
UIFreemodeDetailsItem detailItem1 = new UIFreemodeDetailsItem("Left Label", "RIGHT LABEL", ScaleformFonts.SIGNPAINTER_HOUSESCRIPT, ScaleformFonts.GTAV_TAXI_DIGITAL, BadgeIcon.BRIEFCASE, SColor.FromRandomValues());
157156
UIFreemodeDetailsItem detailItem2 = new UIFreemodeDetailsItem("Left Label", "RIGHT LABEL", ScaleformFonts.SIGNPAINTER_HOUSESCRIPT, ScaleformFonts.GTAV_TAXI_DIGITAL, BadgeIcon.MISSION_STAR, SColor.FromRandomValues());
158157
UIFreemodeDetailsItem detailItem3 = new UIFreemodeDetailsItem("Left Label", "RIGHT LABEL", ScaleformFonts.SIGNPAINTER_HOUSESCRIPT, ScaleformFonts.GTAV_TAXI_DIGITAL, BadgeIcon.ARMOR, SColor.FromRandomValues());
@@ -230,10 +229,6 @@ public async void ExampleMenu()
230229
exampleMenu.AddItem(BlankItem);
231230
exampleMenu.AddItem(BlankItem_2);
232231

233-
UIMenuListItem colorListItem = new UIMenuListItem("Choose the scrolling animation", foodsList, (int)exampleMenu.AnimationType, "~BLIP_BARBER~ ~BLIP_INFO_ICON~ ~BLIP_TANK~ ~BLIP_OFFICE~ ~BLIP_CRIM_DRUGS~ ~BLIP_WAYPOINT~ ~INPUTGROUP_MOVE~~n~You can use Blips and Inputs in description as you prefer!~n~⚠ 🐌 ❤️ 🥺 💪🏻 You can use Emojis too!", SColor.HUD_Freemode_dark, SColor.HUD_Freemode);
234-
colorListItem.BlinkDescription = true;
235-
exampleMenu.AddItem(colorListItem);
236-
237232
UIMenuSliderItem slider = new UIMenuSliderItem("Slider Item", "Cool!", true); // by default max is 100 and multipler 5 = 20 steps.
238233
exampleMenu.AddItem(slider);
239234
UIMenuProgressItem progress = new UIMenuProgressItem("Slider Progress Item", 10, 0);
@@ -275,6 +270,22 @@ public async void ExampleMenu()
275270
statistics.UpdateStatistic(0, 10f);
276271
statistics.UpdateStatistic(1, 50f);
277272
statistics.UpdateStatistic(2, 100f);
273+
listPanelItem4.OnListChanged += (a, b) =>
274+
{
275+
switch (b)
276+
{
277+
case 0:
278+
statistics.UpdateStatistic(0, 10f);
279+
statistics.UpdateStatistic(1, 50f);
280+
statistics.UpdateStatistic(2, 100f);
281+
break;
282+
case 1:
283+
statistics.UpdateStatistic(0, 100f);
284+
statistics.UpdateStatistic(1, 50f);
285+
statistics.UpdateStatistic(2, 10f);
286+
break;
287+
}
288+
};
278289
//and you can get / set their percentage
279290

280291

@@ -292,12 +303,13 @@ public async void ExampleMenu()
292303
windowSubmenu.AddWindow(statsWindow);
293304
List<dynamic> momfaces = new List<dynamic>() { "Hannah", "Audrey", "Jasmine", "Giselle", "Amelia", "Isabella", "Zoe", "Ava", "Camilla", "Violet", "Sophia", "Eveline", "Nicole", "Ashley", "Grace", "Brianna", "Natalie", "Olivia", "Elizabeth", "Charlotte", "Emma", "Misty" };
294305
List<dynamic> dadfaces = new List<dynamic>() { "Benjamin", "Daniel", "Joshua", "Noah", "Andrew", "Joan", "Alex", "Isaac", "Evan", "Ethan", "Vincent", "Angel", "Diego", "Adrian", "Gabriel", "Michael", "Santiago", "Kevin", "Louis", "Samuel", "Anthony", "Claude", "Niko", "John" };
295-
UIMenuListItem mom = new UIMenuListItem("Mamma", momfaces, 0);
296-
UIMenuListItem dad = new UIMenuListItem("Papà", dadfaces, 0);
306+
UIMenuListItem mom = new UIMenuListItem("Mom", momfaces, 0);
307+
UIMenuListItem dad = new UIMenuListItem("Dad", dadfaces, 0);
297308
UIMenuSliderItem newItem = new UIMenuSliderItem("Heritage Slider", "This is Useful on heritage", 100, 5, 50, true);
298309
windowSubmenu.AddItem(mom);
299310
windowSubmenu.AddItem(dad);
300311
windowSubmenu.AddItem(newItem);
312+
301313
statsWindow.DetailMid = "Dad: " + newItem.Value + "%";
302314
statsWindow.DetailBottom = "Mom: " + (100 - newItem.Value) + "%";
303315
statsWindow.DetailStats = new List<UIDetailStat>()
@@ -419,6 +431,7 @@ public async void ExampleMenu()
419431
align.OnListChanged += (item, index) =>
420432
{
421433
item.Parent.MenuAlignment = (MenuAlignment)index;
434+
exampleMenu.MenuAlignment = (MenuAlignment)index;
422435
};
423436

424437
UIMenuDynamicListItem offsetX = new UIMenuDynamicListItem("Offset X", "Change the X offset of the menu", exampleMenu.Offset.X.ToString("F3"), async (sender, direction) =>
@@ -995,8 +1008,8 @@ public async void ExampleMenu()
9951008
if (item == ketchupItem)
9961009
{
9971010
enabled = checked_;
998-
sender.EnableAnimation = enabled;
999-
colorListItem.Enabled = enabled;
1011+
scrollType.Enabled = checked_;
1012+
scrollType.SetLeftBadge(checked_ ? BadgeIcon.NONE : BadgeIcon.LOCK);
10001013
Notifications.ShowNotification("~r~Menu animation: ~b~" + (enabled ? "Enabled" : "Disabled"));
10011014
}
10021015
};
@@ -1016,12 +1029,6 @@ public async void ExampleMenu()
10161029
//cookItem.SetLeftBadge(BadgeIcon.NONE);
10171030
};
10181031

1019-
exampleMenu.OnListChange += (sender, item, index) =>
1020-
{
1021-
if (item == colorListItem)
1022-
sender.AnimationType = (MenuAnimationType)index;
1023-
};
1024-
10251032
exampleMenu.OnMenuOpen += (menu, data) =>
10261033
{
10271034
Screen.ShowSubtitle($"{menu.Title} just opened!", 3000);

ScaleformUI_Csharp/Elements/ScreenTools.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static Vector2 ConvertScaleformCoordsToScreenCoords(float scaleformX, flo
7676
// Normalize coordinates to 0.0 - 1.0 range
7777
int w = 0, h = 0;
7878
GetActiveScreenResolution(ref w, ref h);
79-
return new Vector2((scaleformX / w) * 2f - 1f, (scaleformY / h) * 2f - 1f);
79+
return new Vector2(scaleformX / w, scaleformY / h);
8080
}
8181

8282
public static Vector2 ConvertResolutionCoordsToScreenCoords(float x, float y)
@@ -87,6 +87,21 @@ public static Vector2 ConvertResolutionCoordsToScreenCoords(float x, float y)
8787
return new Vector2(normalizedX, normalizedY);
8888
}
8989

90+
91+
/// <summary>
92+
/// Converts scaleform size(1280 x 720) into screen size(0.0 - 1.0)
93+
/// </summary>
94+
/// <param name="scaleformWidth"></param>
95+
/// <param name="scaleformHeight"></param>
96+
/// <returns></returns>
97+
public static SizeF ConvertScaleformSizeToScreenSize(float scaleformWidth, float scaleformHeight)
98+
{
99+
//Normalize size to 0.0 - 1.0 range
100+
int w = 0, h = 0;
101+
GetActiveScreenResolution(ref w, ref h);
102+
return new SizeF(scaleformWidth / w, scaleformHeight / h);
103+
}
104+
90105
public static void AdjustNormalized16_9ValuesForCurrentAspectRatio(int widescreen, ref Vector2 pos, ref SizeF size)
91106
{
92107
if (widescreen == 0)

ScaleformUI_Csharp/Menus/MenuBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public virtual bool Visible
1616
}
1717
}
1818
public List<InstructionalButton> InstructionalButtons { get; set; }
19-
internal virtual void ProcessControl(Keys key = Keys.None)
19+
internal virtual void ProcessControl()
2020
{
2121

2222
}

ScaleformUI_Csharp/Menus/MenuHandler.cs

-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static async Task SwitchTo(this MenuBase currentMenu, MenuBase newMenu, i
6464

6565
if (currentMenu is UIMenu old)
6666
{
67-
await old.FadeOutMenu();
6867
currentMenu.Visible = false;
6968
if (newMenu is UIMenu newer)
7069
{
@@ -79,9 +78,7 @@ public static async Task SwitchTo(this MenuBase currentMenu, MenuBase newMenu, i
7978
newer.MaxItemsOnScreen = old.MaxItemsOnScreen;
8079
newer.ScrollingType = old.ScrollingType;
8180
newer.Glare = old.Glare;
82-
newer.fadingTime = old.fadingTime;
8381
newer.SetMouse(old.MouseControlsEnabled, old.MouseEdgeEnabled, old.MouseWheelControlEnabled, old.ResetCursorOnOpen, old.leftClickEnabled);
84-
newer.SetAnimations(old.EnableAnimation, old.Enabled3DAnimations, old.AnimationType, old.BuildingAnimation);
8582
newer.SubtitleColor = old.SubtitleColor;
8683
}
8784
newer.CurrentSelection = newMenuCurrentSelection != 0 ? newMenuCurrentSelection : 0;

0 commit comments

Comments
 (0)