From 258deb99b0c412312e847d255059a371c1df4cd1 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Fri, 15 Dec 2023 22:30:58 -0300 Subject: [PATCH 1/7] Added spacer item --- LemonUI/Menus/NativeSpacerItem.cs | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 LemonUI/Menus/NativeSpacerItem.cs diff --git a/LemonUI/Menus/NativeSpacerItem.cs b/LemonUI/Menus/NativeSpacerItem.cs new file mode 100644 index 0000000..f017a4e --- /dev/null +++ b/LemonUI/Menus/NativeSpacerItem.cs @@ -0,0 +1,47 @@ +using System.Drawing; +using GTA.UI; + +namespace LemonUI.Menus +{ + /// + /// An item used to have a space between the items with text. + /// + public class NativeSpacerItem : NativeItem + { + #region Constructor + + /// + /// Creates a new Spacer with no text. + /// + public NativeSpacerItem() : this(string.Empty) + { + } + /// + /// Creates a new Spacer with a specific title. + /// + /// The title of the item. + public NativeSpacerItem(string title) : base(title, string.Empty, string.Empty) + { + this.title.Alignment = Alignment.Center; + } + + #endregion + + #region Function + + /// + public override void Recalculate(PointF pos, SizeF size, bool selected) + { + base.Recalculate(pos, size, selected); + + title.Position = new PointF(pos.X + (size.Width * 0.5f), title.Position.Y); + } + /// + public override void Draw() + { + title.Draw(); + } + + #endregion + } +} From 11e32cba2e30a2bf0734eb9a8d3b892b6deb889f Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 02:55:34 -0300 Subject: [PATCH 2/7] Added missing using statements --- LemonUI/Menus/NativeSpacerItem.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/LemonUI/Menus/NativeSpacerItem.cs b/LemonUI/Menus/NativeSpacerItem.cs index f017a4e..2c6b0ca 100644 --- a/LemonUI/Menus/NativeSpacerItem.cs +++ b/LemonUI/Menus/NativeSpacerItem.cs @@ -1,5 +1,11 @@ -using System.Drawing; +#if FIVEM +using CitizenFX.Core.UI; +#elif RAGEMP +using RAGE.Game; +#elif SHVDN3 || SHVDNC using GTA.UI; +#endif +using System.Drawing; namespace LemonUI.Menus { From 0eb4e55b077139d56f57c3bce4dc1471576278ba Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 03:19:25 -0300 Subject: [PATCH 3/7] Make NativeSeparatorItem obsolete Fixes #148 --- LemonUI/Menus/NativeSeparatorItem.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/LemonUI/Menus/NativeSeparatorItem.cs b/LemonUI/Menus/NativeSeparatorItem.cs index 2633e54..32a17db 100644 --- a/LemonUI/Menus/NativeSeparatorItem.cs +++ b/LemonUI/Menus/NativeSeparatorItem.cs @@ -1,8 +1,11 @@ -namespace LemonUI.Menus +using System; + +namespace LemonUI.Menus { /// /// A Blank Separator Item for creating empty spaces between menu items. /// + [Obsolete("Use LemonUI.Menus.NativeSpacerItem instead.", true)] public class NativeSeparatorItem : NativeItem { #region Constructors From 7ebc4c02599437b97ab7cda76c213ae248e4e262 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 03:25:50 -0300 Subject: [PATCH 4/7] Make sure that Spacers can't be clicked --- LemonUI/Menus/NativeItem.cs | 2 +- LemonUI/Menus/NativeMenu.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/LemonUI/Menus/NativeItem.cs b/LemonUI/Menus/NativeItem.cs index a36969b..9128523 100644 --- a/LemonUI/Menus/NativeItem.cs +++ b/LemonUI/Menus/NativeItem.cs @@ -393,7 +393,7 @@ public virtual void UpdateColors() badgeRight.Color = Colors.BadgeRightDisabled; } } - else if (lastSelected) + else if (lastSelected && !(this is NativeSpacerItem)) { background.Color = Colors.BackgroundHovered; title.Color = Colors.TitleHovered; diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index c941294..d4bc6ab 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -1284,6 +1284,11 @@ private void ProcessControls() // If the cursor is inside of the selection rectangle if (GameScreen.IsCursorInArea(item.title.Position.X - itemOffsetX, item.title.Position.Y - itemOffsetY, Width, itemHeight)) { + if (item is NativeSpacerItem) + { + return; + } + // If the item is selected, activate it if (item == selectedItem) { @@ -1426,7 +1431,7 @@ private void Draw() continue; } - if (item.IsHovered && UseMouse) + if (item.IsHovered && UseMouse && !(item is NativeSpacerItem)) { hoveredRect.Position = item.lastPosition; hoveredRect.Size = item.lastSize; From 2fa213db7834f6b11e87d220292cca137b6d7c7a Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 03:26:52 -0300 Subject: [PATCH 5/7] Make sure that we check that the items are actually hovered Fixes #147 --- LemonUI/Menus/NativeMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index d4bc6ab..479acc0 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -1282,7 +1282,7 @@ private void ProcessControls() } // If the cursor is inside of the selection rectangle - if (GameScreen.IsCursorInArea(item.title.Position.X - itemOffsetX, item.title.Position.Y - itemOffsetY, Width, itemHeight)) + if (item.IsHovered) { if (item is NativeSpacerItem) { From 436cfcadb522010fd34414bfea20ea44da06e8e9 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 03:36:55 -0300 Subject: [PATCH 6/7] Revert "Make NativeSeparatorItem obsolete" This reverts commit 0eb4e55b077139d56f57c3bce4dc1471576278ba. --- LemonUI/Menus/NativeSeparatorItem.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/LemonUI/Menus/NativeSeparatorItem.cs b/LemonUI/Menus/NativeSeparatorItem.cs index 32a17db..2633e54 100644 --- a/LemonUI/Menus/NativeSeparatorItem.cs +++ b/LemonUI/Menus/NativeSeparatorItem.cs @@ -1,11 +1,8 @@ -using System; - -namespace LemonUI.Menus +namespace LemonUI.Menus { /// /// A Blank Separator Item for creating empty spaces between menu items. /// - [Obsolete("Use LemonUI.Menus.NativeSpacerItem instead.", true)] public class NativeSeparatorItem : NativeItem { #region Constructors From 905155365e80673ce9cc38a32836b57115cd6f91 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 03:43:09 -0300 Subject: [PATCH 7/7] Merge the features of NativeSpacerItem into NativeSeparatorItem --- LemonUI/Menus/NativeItem.cs | 2 +- LemonUI/Menus/NativeMenu.cs | 66 +++++++++++++++++++--------- LemonUI/Menus/NativeSeparatorItem.cs | 37 +++++++++++++--- LemonUI/Menus/NativeSpacerItem.cs | 53 ---------------------- 4 files changed, 77 insertions(+), 81 deletions(-) delete mode 100644 LemonUI/Menus/NativeSpacerItem.cs diff --git a/LemonUI/Menus/NativeItem.cs b/LemonUI/Menus/NativeItem.cs index 9128523..9bbbd7c 100644 --- a/LemonUI/Menus/NativeItem.cs +++ b/LemonUI/Menus/NativeItem.cs @@ -393,7 +393,7 @@ public virtual void UpdateColors() badgeRight.Color = Colors.BadgeRightDisabled; } } - else if (lastSelected && !(this is NativeSpacerItem)) + else if (lastSelected && !(this is NativeSeparatorItem)) { background.Color = Colors.BackgroundHovered; title.Color = Colors.TitleHovered; diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index 479acc0..758480d 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -1284,7 +1284,7 @@ private void ProcessControls() // If the cursor is inside of the selection rectangle if (item.IsHovered) { - if (item is NativeSpacerItem) + if (item is NativeSeparatorItem) { return; } @@ -1431,7 +1431,7 @@ private void Draw() continue; } - if (item.IsHovered && UseMouse && !(item is NativeSpacerItem)) + if (item.IsHovered && UseMouse && !(item is NativeSeparatorItem)) { hoveredRect.Position = item.lastPosition; hoveredRect.Size = item.lastSize; @@ -1779,21 +1779,34 @@ public void Back() /// public void Previous() { - // If there are no items, return if (Items.Count == 0) { return; } - // If we are on the first item, go back to the last one - if (SelectedIndex <= 0) - { - SelectedIndex = Items.Count - 1; - } - // Otherwise, reduce it by one - else + int nextIndex = SelectedIndex; + + while (true) { - SelectedIndex -= 1; + nextIndex -= 1; + + if (nextIndex < 0) + { + nextIndex = Items.Count - 1; + } + + if (Items[nextIndex] is NativeSeparatorItem) + { + continue; + } + + if (nextIndex == SelectedIndex) + { + return; + } + + SelectedIndex = nextIndex; + return; } } /// @@ -1802,21 +1815,34 @@ public void Previous() /// public void Next() { - // If there are no items, return if (Items.Count == 0) { return; } - // If we are on the last item, go back to the first one - if (Items.Count - 1 == SelectedIndex) - { - SelectedIndex = 0; - } - // Otherwise, increase it by one - else + int nextIndex = SelectedIndex; + + while (true) { - SelectedIndex += 1; + nextIndex += 1; + + if (nextIndex >= Items.Count) + { + nextIndex = 0; + } + + if (Items[nextIndex] is NativeSeparatorItem) + { + continue; + } + + if (nextIndex == SelectedIndex) + { + return; + } + + SelectedIndex = nextIndex; + return; } } diff --git a/LemonUI/Menus/NativeSeparatorItem.cs b/LemonUI/Menus/NativeSeparatorItem.cs index 2633e54..0e9526a 100644 --- a/LemonUI/Menus/NativeSeparatorItem.cs +++ b/LemonUI/Menus/NativeSeparatorItem.cs @@ -1,28 +1,51 @@ -namespace LemonUI.Menus +#if FIVEM +using CitizenFX.Core.UI; +#elif RAGEMP +using RAGE.Game; +#elif SHVDN3 || SHVDNC +using GTA.UI; +#endif +using System.Drawing; + +namespace LemonUI.Menus { /// - /// A Blank Separator Item for creating empty spaces between menu items. + /// An item used to have a space between the items with text or no text. /// public class NativeSeparatorItem : NativeItem { #region Constructors /// - /// Creates a new Menu Separator. + /// Creates a new separator. + /// + public NativeSeparatorItem() : this(string.Empty) + { + } + /// + /// Creates a new separator with a specific title. /// - public NativeSeparatorItem() : base(string.Empty, string.Empty, string.Empty) + /// The title of the item. + public NativeSeparatorItem(string title) : base(title, string.Empty, string.Empty) { + this.title.Alignment = Alignment.Center; } #endregion #region Functions - /// - /// Draws nothing. - /// + /// + public override void Recalculate(PointF pos, SizeF size, bool selected) + { + base.Recalculate(pos, size, selected); + + title.Position = new PointF(pos.X + (size.Width * 0.5f), title.Position.Y); + } + /// public override void Draw() { + title.Draw(); } #endregion diff --git a/LemonUI/Menus/NativeSpacerItem.cs b/LemonUI/Menus/NativeSpacerItem.cs deleted file mode 100644 index 2c6b0ca..0000000 --- a/LemonUI/Menus/NativeSpacerItem.cs +++ /dev/null @@ -1,53 +0,0 @@ -#if FIVEM -using CitizenFX.Core.UI; -#elif RAGEMP -using RAGE.Game; -#elif SHVDN3 || SHVDNC -using GTA.UI; -#endif -using System.Drawing; - -namespace LemonUI.Menus -{ - /// - /// An item used to have a space between the items with text. - /// - public class NativeSpacerItem : NativeItem - { - #region Constructor - - /// - /// Creates a new Spacer with no text. - /// - public NativeSpacerItem() : this(string.Empty) - { - } - /// - /// Creates a new Spacer with a specific title. - /// - /// The title of the item. - public NativeSpacerItem(string title) : base(title, string.Empty, string.Empty) - { - this.title.Alignment = Alignment.Center; - } - - #endregion - - #region Function - - /// - public override void Recalculate(PointF pos, SizeF size, bool selected) - { - base.Recalculate(pos, size, selected); - - title.Position = new PointF(pos.X + (size.Width * 0.5f), title.Position.Y); - } - /// - public override void Draw() - { - title.Draw(); - } - - #endregion - } -}