From e3a616ee03a38a57923e733a7084fa3c66801d99 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 24 Oct 2022 07:05:23 -0300 Subject: [PATCH] Implemented IEnumerable on classes that hold object's Closes #97 --- LemonUI/Menus/NativeColorPanel.cs | 7 ++++++- LemonUI/Menus/NativeListItem.cs | 7 ++++++- LemonUI/Menus/NativeMenu.cs | 12 +++++++++++- LemonUI/Menus/NativeStatsPanel.cs | 7 ++++++- LemonUI/ObjectPool.cs | 7 ++++++- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/LemonUI/Menus/NativeColorPanel.cs b/LemonUI/Menus/NativeColorPanel.cs index b643ca47..be024211 100644 --- a/LemonUI/Menus/NativeColorPanel.cs +++ b/LemonUI/Menus/NativeColorPanel.cs @@ -11,6 +11,7 @@ #endif using LemonUI.Elements; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -19,7 +20,7 @@ namespace LemonUI.Menus /// /// A Panel that allows you to select a Color. /// - public class NativeColorPanel : NativePanel + public class NativeColorPanel : NativePanel, IEnumerable { #region Constants @@ -487,6 +488,10 @@ private void UpdateOpacityBar() #region Public Functions + /// + public IEnumerator GetEnumerator() => Colors.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Moves to the Previous Color. /// diff --git a/LemonUI/Menus/NativeListItem.cs b/LemonUI/Menus/NativeListItem.cs index be3c6a91..b2c803be 100644 --- a/LemonUI/Menus/NativeListItem.cs +++ b/LemonUI/Menus/NativeListItem.cs @@ -1,5 +1,6 @@ using LemonUI.Elements; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -29,7 +30,7 @@ public NativeListItem(string title, string subtitle) : base(title, subtitle) /// /// An item that allows you to scroll between a set of objects. /// - public class NativeListItem : NativeListItem + public class NativeListItem : NativeListItem, IEnumerable { #region Fields @@ -188,6 +189,10 @@ private void UpdateIndex() #region Functions + /// + public IEnumerator GetEnumerator() => Items.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds a into this item. /// diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index e52f34fb..236fbc17 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -24,6 +24,7 @@ using LemonUI.Extensions; using LemonUI.Scaleform; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -32,7 +33,7 @@ namespace LemonUI.Menus /// /// Menu that looks like the ones used by Rockstar. /// - public class NativeMenu : IContainer + public class NativeMenu : IContainer, IEnumerable { #region Public Fields @@ -1361,12 +1362,21 @@ private void Draw() #region Public Functions + /// + public IEnumerator GetEnumerator() => Items.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds an item at the end of the menu. /// /// The item to add. public void Add(NativeItem item) => Add(Items.Count, item); /// + /// Adds a specific menu as a submenu with an item. + /// + /// The menu to add. + public void Add(NativeMenu menu) => AddSubMenu(menu); + /// /// Adds an item at the specified position. /// /// The position of the item. diff --git a/LemonUI/Menus/NativeStatsPanel.cs b/LemonUI/Menus/NativeStatsPanel.cs index f6798052..97fa435e 100644 --- a/LemonUI/Menus/NativeStatsPanel.cs +++ b/LemonUI/Menus/NativeStatsPanel.cs @@ -1,5 +1,6 @@ using LemonUI.Elements; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -8,7 +9,7 @@ namespace LemonUI.Menus /// /// Represents a Statistics panel. /// - public class NativeStatsPanel : NativePanel, IContainer + public class NativeStatsPanel : NativePanel, IContainer, IEnumerable { #region Fields @@ -75,6 +76,10 @@ public NativeStatsPanel(params NativeStatsInfo[] stats) #region Functions + /// + public IEnumerator GetEnumerator() => fields.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds a stat to the player field. /// diff --git a/LemonUI/ObjectPool.cs b/LemonUI/ObjectPool.cs index f0fd451d..918168cb 100644 --- a/LemonUI/ObjectPool.cs +++ b/LemonUI/ObjectPool.cs @@ -13,6 +13,7 @@ using GTA.UI; #endif using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -75,7 +76,7 @@ internal SafeZoneChangedEventArgs(float before, float after) /// /// Manager for Menus and Items. /// - public class ObjectPool + public class ObjectPool : IEnumerable { #region Private Fields @@ -206,6 +207,10 @@ private void DetectSafezoneChanges() #region Public Function + /// + public IEnumerator GetEnumerator() => objects.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds the object into the pool. ///