Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
C# BREAKING: Reorganized project and added NameSpaces
  • Loading branch information
manups4e committed Jul 27, 2023
1 parent 65c400f commit 8ada9ee
Show file tree
Hide file tree
Showing 62 changed files with 108 additions and 88 deletions.
3 changes: 2 additions & 1 deletion MenuExample/MenuExample.cs
Expand Up @@ -4,6 +4,7 @@
using ScaleformUI;
using ScaleformUI.Elements;
using ScaleformUI.LobbyMenu;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenu;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -933,7 +934,7 @@ public void ExampleMenu()
sender.AnimationType = (MenuAnimationType)index;
};

exampleMenu.OnMenuOpen += (menu) =>
exampleMenu.OnMenuOpen += (menu, data) =>
{
Screen.ShowSubtitle($"{menu.Title} just opened!", 3000);
Debug.WriteLine($"{menu.Title} just opened!");
Expand Down
@@ -1,6 +1,6 @@
using System.Drawing;

namespace ScaleformUI
namespace ScaleformUI.Elements
{
public static class Colors
{
Expand Down
@@ -1,8 +1,7 @@
using CitizenFX.Core;
using System.Linq;
using static CitizenFX.Core.Native.API;

namespace ScaleformUI
namespace ScaleformUI.Elements
{
/// <summary>
/// Class that provides tools to handle the game controls.
Expand Down
@@ -1,8 +1,7 @@
using CitizenFX.Core;
using System;
using System.Drawing;

namespace ScaleformUI
namespace ScaleformUI.Elements
{
public static class MiscExtensions
{
Expand Down Expand Up @@ -65,8 +64,8 @@ public static float LinearFloatLerp(float start, float end, int currentTime, int

public static float QuadraticEasingLerp(float start, float end, int currentTime, int duration)
{
var time = (float)currentTime;
var dur = (float)duration;
float time = currentTime;
float dur = duration;

float change = end - start;

Expand Down
@@ -1,11 +1,6 @@
using CitizenFX.Core.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScaleformUI
namespace ScaleformUI.Elements
{
public static class ScaleformFonts
{
Expand Down
@@ -1,11 +1,10 @@
using CitizenFX.Core;
using CitizenFX.Core.Native;
using CitizenFX.Core.UI;
using System;
using System.Drawing;
using static CitizenFX.Core.Native.API;

namespace ScaleformUI
namespace ScaleformUI.Elements
{
/// <summary>
/// Tools to deal with the game screen.
Expand Down
15 changes: 7 additions & 8 deletions ScaleformUI_Csharp/Elements/UIResText.cs
@@ -1,10 +1,9 @@
using CitizenFX.Core.Native;
using CitizenFX.Core.UI;
using System;
using System.Drawing;
using Font = CitizenFX.Core.UI.Font;

namespace ScaleformUI
namespace ScaleformUI.Elements
{
/// <summary>
/// A Text object in the 1080 pixels height base system.
Expand Down Expand Up @@ -37,7 +36,7 @@ public UIResText(string caption, PointF position, float scale, Color color, Font
/// <param name="str"></param>
public static void AddLongString(string str)
{
var utf8ByteCount = System.Text.Encoding.UTF8.GetByteCount(str);
int utf8ByteCount = System.Text.Encoding.UTF8.GetByteCount(str);

if (utf8ByteCount == str.Length)
{
Expand Down Expand Up @@ -73,20 +72,20 @@ internal static void AddLongStringForUtf8(string input)
return;
}

var enc = System.Text.Encoding.UTF8;
System.Text.Encoding enc = System.Text.Encoding.UTF8;

var utf8ByteCount = enc.GetByteCount(input);
int utf8ByteCount = enc.GetByteCount(input);
if (utf8ByteCount < maxByteLengthPerString)
{
API.AddTextComponentString(input);
return;
}

var startIndex = 0;
int startIndex = 0;

for (int i = 0; i < input.Length; i++)
{
var length = i - startIndex;
int length = i - startIndex;
if (enc.GetByteCount(input.Substring(startIndex, length)) > maxByteLengthPerString)
{
string substr = (input.Substring(startIndex, length - 1));
Expand Down Expand Up @@ -125,7 +124,7 @@ public override void Draw(SizeF offset)
int screenh = Screen.Resolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
var width = height * ratio;
float width = height * ratio;

float x = (Position.X) / width;
float y = (Position.Y) / height;
Expand Down
@@ -1,5 +1,7 @@
using CitizenFX.Core;
using CitizenFX.Core.Native;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenus;

namespace ScaleformUI
{
Expand Down Expand Up @@ -41,7 +43,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)
public static async Task SwitchTo(this UIMenu currentMenu, UIMenu 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 Down Expand Up @@ -73,7 +75,7 @@ public static async Task SwitchTo(this UIMenu currentMenu, UIMenu newMenu, int n
currentMenu.Visible = false;
newMenu.Visible = true;
await currentMenu.FadeInMenu();
BreadcrumbsHandler.Forward(newMenu);
BreadcrumbsHandler.Forward(newMenu, data);
BreadcrumbsHandler.SwitchInProgress = false;
}

Expand Down
@@ -1,4 +1,6 @@
namespace ScaleformUI.LobbyMenu
using ScaleformUI.PauseMenus;

namespace ScaleformUI.LobbyMenu
{
public delegate void IndexChanged(int index);
public class Column
Expand Down
@@ -1,4 +1,5 @@
using ScaleformUI.PauseMenu;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenu;

namespace ScaleformUI.LobbyMenu
{
Expand Down
@@ -1,4 +1,6 @@
using CitizenFX.Core;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenus;
using static CitizenFX.Core.Native.API;

namespace ScaleformUI.LobbyMenu
Expand Down
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using ScaleformUI.Menu;

namespace ScaleformUI.LobbyMenu
{
Expand Down
@@ -1,4 +1,5 @@
using ScaleformUI.PauseMenu;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenu;

namespace ScaleformUI.LobbyMenu
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public string Label
label = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_LABEL", idx, label);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -55,7 +56,7 @@ public HudColor ItemColor
itemColor = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_COLOUR", idx, itemColor, coloredTag);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -71,7 +72,7 @@ public bool ColoredTag
coloredTag = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_COLOUR", idx, itemColor, coloredTag);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -87,7 +88,7 @@ public int Rank
rank = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_RANK", idx, rank);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -103,7 +104,7 @@ public string Status
status = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_STATUS", idx, status, (int)statusColor);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -119,7 +120,7 @@ public HudColor StatusColor
statusColor = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_STATUS", idx, status, (int)statusColor);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -135,7 +136,7 @@ public string CrewTag
crewTag = value;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_CREW", idx, crewTag);
else if (ParentColumn.Parent is TabView pause)
Expand Down Expand Up @@ -167,7 +168,7 @@ public void SetLeftIcon(LobbyBadgeIcon icon)
boolL = false;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_ICON_LEFT", idx, iconL, boolL);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -180,7 +181,7 @@ public void SetLeftIcon(BadgeIcon icon)
boolL = true;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_ICON_LEFT", idx, iconL, boolL);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -194,7 +195,7 @@ public void SetRightIcon(LobbyBadgeIcon icon)
boolR = false;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_ICON_RIGHT", idx, iconR, boolR);
else if (ParentColumn.Parent is TabView pause)
Expand All @@ -207,7 +208,7 @@ public void SetRightIcon(BadgeIcon icon)
boolR = true;
if (ParentColumn is not null && ParentColumn.Parent is not null && ParentColumn.Parent.Visible)
{
var idx = ParentColumn.Items.IndexOf(this);
int idx = ParentColumn.Items.IndexOf(this);
if (ParentColumn.Parent is MainView lobby)
lobby._pause._lobby.CallFunction("SET_PLAYER_ITEM_ICON_RIGHT", idx, iconR, boolR);
else if (ParentColumn.Parent is TabView pause)
Expand Down
@@ -1,4 +1,6 @@
namespace ScaleformUI.PauseMenu
using ScaleformUI.Elements;

namespace ScaleformUI.PauseMenu
{
public class BasicTabItem
{
Expand Down
@@ -1,4 +1,6 @@
namespace ScaleformUI.PauseMenu
using ScaleformUI.Menu;

namespace ScaleformUI.PauseMenu
{
public delegate void SettingsCheckboxChanged(SettingsItem item, bool value);
public class SettingsCheckboxItem : SettingsItem
Expand Down
@@ -1,4 +1,6 @@
namespace ScaleformUI.PauseMenu
using ScaleformUI.Elements;

namespace ScaleformUI.PauseMenu
{
public enum StatItemType
{
Expand Down
@@ -1,5 +1,7 @@
using CitizenFX.Core;
using ScaleformUI.LobbyMenu;
using ScaleformUI.Menu;
using ScaleformUI.PauseMenus;
using static CitizenFX.Core.Native.API;

namespace ScaleformUI.PauseMenu
Expand Down
@@ -1,4 +1,7 @@
namespace ScaleformUI.PauseMenu
using ScaleformUI.Elements;
using ScaleformUI.Menu;

namespace ScaleformUI.PauseMenu
{
public enum LeftItemType
{
Expand Down
@@ -1,6 +1,6 @@
using CitizenFX.Core.Native;

namespace ScaleformUI
namespace ScaleformUI.PauseMenus
{
public class PauseMenuBase
{
Expand Down
@@ -1,16 +1,16 @@
namespace ScaleformUI
namespace ScaleformUI.Menu
{
internal static class BreadcrumbsHandler
{
private static readonly List<UIMenu> breadcrumbs = new List<UIMenu>();
private static readonly List<Tuple<UIMenu, dynamic>> breadcrumbs = new List<Tuple<UIMenu, dynamic>>();
internal static int Count => breadcrumbs.Count;
internal static int CurrentDepth => breadcrumbs.Count - 1;
internal static UIMenu PreviousMenu => breadcrumbs[CurrentDepth - 1];
internal static UIMenu PreviousMenu => breadcrumbs[CurrentDepth - 1].Item1;
public static bool SwitchInProgress = false;

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

internal static void Clear()
Expand Down
@@ -1,4 +1,4 @@
namespace ScaleformUI
namespace ScaleformUI.Menu
{
public interface IListItem
{
Expand Down
@@ -1,4 +1,4 @@
namespace ScaleformUI
namespace ScaleformUI.Menu
{
public enum UIMenuCheckboxStyle
{
Expand Down
@@ -1,4 +1,4 @@
namespace ScaleformUI
namespace ScaleformUI.Menu
{
public class UIMenuDynamicListItem : UIMenuItem, IListItem
{
Expand Down
@@ -1,8 +1,9 @@
using CitizenFX.Core.Native;
using ScaleformUI.Elements;
using ScaleformUI.LobbyMenu;
using ScaleformUI.PauseMenu;

namespace ScaleformUI
namespace ScaleformUI.Menu
{
public enum BadgeIcon
{
Expand Down

0 comments on commit 8ada9ee

Please sign in to comment.