Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor optimizations and fix lines being cut when newlines are in the string #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions MenuAPI/MenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static Menu GetCurrentMenu()
/// Returns true if any menu is currently open.
/// </summary>
/// <returns></returns>
public static bool IsAnyMenuOpen() => VisibleMenus.Any();
public static bool IsAnyMenuOpen() => VisibleMenus.Count > 0;


#region Process Menu Buttons
Expand Down Expand Up @@ -446,12 +446,15 @@ private async Task ProcessToggleMenuButton()
#endif
#if REDM
ProcessToggleMenuButtonRedM();
await Task.FromResult(0);
#endif
}
#if REDM
private void ProcessToggleMenuButtonRedM()
{
if (MenuToggleKey == 0)
{
return;
}
DisableControlAction(0, (uint)MenuToggleKey, true);
if (
!IsPauseMenuActive() &&
Expand Down
19 changes: 3 additions & 16 deletions MenuAPI/items/MenuItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using CitizenFX.Core;
using System.Text.RegularExpressions;
using static CitizenFX.Core.Native.API;
using static CitizenFX.Core.Native.Function;
using static CitizenFX.Core.Native.Hash;
Expand Down Expand Up @@ -226,23 +227,9 @@ public string Description
{
string text = value;
int maxLength = 50;
List<string> lines = new List<string>();
while (text.Length > maxLength)
if (text.Length > maxLength)
{
var substr = text.Substring(0, Math.Min(text.Length - 1, maxLength));
var lastIndex = substr.LastIndexOf(" ");
if (lastIndex == -1)
{
lastIndex = Math.Min(text.Length - 1, maxLength);
}
lines.Add(text.Substring(0, lastIndex));
text = text.Substring(lastIndex);
}
lines.Add(text);
text = "";
foreach (var str in lines)
{
text += str + "\n";
text = Regex.Replace(text, @"(.{1," + maxLength + @"})(?:\s|$)", "$1\n");
}
_description = text;
}
Expand Down