From 5e1692f00f82605eee6849f84a533cc57152b604 Mon Sep 17 00:00:00 2001 From: Leonardo Emanuele Date: Sat, 1 Jun 2024 18:04:31 +0200 Subject: [PATCH] C# throw an error if filtering results in 0 items in menu --- .../Pause Menus/Elements/Columns/MissionsListColumn.cs | 4 +++- .../Menus/Pause Menus/Elements/Columns/PlayerListColumn.cs | 4 +++- .../Pause Menus/Elements/Columns/SettingsListColumn.cs | 4 +++- .../Menus/Pause Menus/Elements/Columns/StoreListColumn.cs | 4 +++- ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs | 6 ++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/MissionsListColumn.cs b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/MissionsListColumn.cs index 9ed65a55..4041ba74 100644 --- a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/MissionsListColumn.cs +++ b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/MissionsListColumn.cs @@ -308,6 +308,8 @@ public void FilterMissions(Func predicate) } Clear(); Items = _unfilteredItems.Where(predicate.Invoke).ToList(); + if (Items.Count == 0) + throw new Exception("Predicate resulted in a filtering of 0 items.. missions column cannot rebuild!"); Pagination.TotalItems = Items.Count; if (Parent != null && Parent.Visible) { @@ -319,7 +321,7 @@ public void FilterMissions(Func predicate) } catch (Exception ex) { - Debug.WriteLine("ScaleformUI - " + ex.ToString()); + Debug.WriteLine("^1ScaleformUI - " + ex.ToString()); } } diff --git a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/PlayerListColumn.cs b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/PlayerListColumn.cs index 19ad5425..0d03b493 100644 --- a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/PlayerListColumn.cs +++ b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/PlayerListColumn.cs @@ -332,6 +332,8 @@ public void FilterPlayers(Func predicate) } Clear(); Items = _unfilteredItems.Where(predicate.Invoke).ToList(); + if (Items.Count == 0) + throw new Exception("Predicate resulted in a filtering of 0 items.. players column cannot rebuild!"); Pagination.TotalItems = Items.Count; if (Parent != null && Parent.Visible) { @@ -343,7 +345,7 @@ public void FilterPlayers(Func predicate) } catch (Exception ex) { - Debug.WriteLine("ScaleformUI - " + ex.ToString()); + Debug.WriteLine("^1ScaleformUI - " + ex.ToString()); } } diff --git a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/SettingsListColumn.cs b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/SettingsListColumn.cs index 5cfd2806..ad196dfa 100644 --- a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/SettingsListColumn.cs +++ b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/SettingsListColumn.cs @@ -590,6 +590,8 @@ public void FilterSettings(Func predicate) } Clear(); Items = _unfilteredItems.Where(predicate.Invoke).ToList(); + if (Items.Count == 0) + throw new Exception("Predicate resulted in a filtering of 0 items.. settings column cannot rebuild!"); Pagination.TotalItems = Items.Count; if (Parent != null && Parent.Visible) { @@ -601,7 +603,7 @@ public void FilterSettings(Func predicate) } catch (Exception ex) { - Debug.WriteLine("ScaleformUI - " + ex.ToString()); + Debug.WriteLine("^1ScaleformUI - " + ex.ToString()); } } diff --git a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/StoreListColumn.cs b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/StoreListColumn.cs index 005ae75b..eeef2416 100644 --- a/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/StoreListColumn.cs +++ b/ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/StoreListColumn.cs @@ -305,6 +305,8 @@ public void FilterMissions(Func predicate) } Clear(); Items = _unfilteredItems.Where(predicate.Invoke).ToList(); + if (Items.Count == 0) + throw new Exception("Predicate resulted in a filtering of 0 items.. store column cannot rebuild!"); Pagination.TotalItems = Items.Count; if (Parent != null && Parent.Visible) { @@ -316,7 +318,7 @@ public void FilterMissions(Func predicate) } catch (Exception ex) { - Debug.WriteLine("ScaleformUI - " + ex.ToString()); + Debug.WriteLine("^1ScaleformUI - " + ex.ToString()); } } diff --git a/ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs b/ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs index 3efc3e0a..cce26d91 100644 --- a/ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs +++ b/ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs @@ -2608,18 +2608,20 @@ public void SortMenuItems(Comparison compare) public void FilterMenuItems(Func predicate) { if (itemless) throw new("ScaleformUI - You can't compare or sort an itemless menu"); - try + try { MenuItems[CurrentSelection].Selected = false; _unfilteredMenuItems = MenuItems.ToList(); Clear(); MenuItems = _unfilteredMenuItems.Where(predicate.Invoke).ToList(); + if (MenuItems.Count == 0) + throw new Exception("Predicate resulted in a filtering of 0 items.. menu cannot rebuild!"); Pagination.TotalItems = MenuItems.Count; BuildUpMenuAsync(true); } catch (Exception ex) { - Debug.WriteLine("ScaleformUI - " + ex.ToString()); + Debug.WriteLine("^1ScaleformUI - " + ex.ToString()); } }