Skip to content

Commit

Permalink
C# throw an error if filtering results in 0 items in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
manups4e committed Jun 1, 2024
1 parent 4f72a21 commit 5e1692f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ public void FilterMissions(Func<MissionItem, bool> 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)
{
Expand All @@ -319,7 +321,7 @@ public void FilterMissions(Func<MissionItem, bool> predicate)
}
catch (Exception ex)
{
Debug.WriteLine("ScaleformUI - " + ex.ToString());
Debug.WriteLine("^1ScaleformUI - " + ex.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ public void FilterPlayers(Func<LobbyItem, bool> 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)
{
Expand All @@ -343,7 +345,7 @@ public void FilterPlayers(Func<LobbyItem, bool> predicate)
}
catch (Exception ex)
{
Debug.WriteLine("ScaleformUI - " + ex.ToString());
Debug.WriteLine("^1ScaleformUI - " + ex.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ public void FilterSettings(Func<UIMenuItem, bool> 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)
{
Expand All @@ -601,7 +603,7 @@ public void FilterSettings(Func<UIMenuItem, bool> predicate)
}
catch (Exception ex)
{
Debug.WriteLine("ScaleformUI - " + ex.ToString());
Debug.WriteLine("^1ScaleformUI - " + ex.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ public void FilterMissions(Func<StoreItem, bool> 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)
{
Expand All @@ -316,7 +318,7 @@ public void FilterMissions(Func<StoreItem, bool> predicate)
}
catch (Exception ex)
{
Debug.WriteLine("ScaleformUI - " + ex.ToString());
Debug.WriteLine("^1ScaleformUI - " + ex.ToString());
}
}

Expand Down
6 changes: 4 additions & 2 deletions ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2608,18 +2608,20 @@ public void SortMenuItems(Comparison<UIMenuItem> compare)
public void FilterMenuItems(Func<UIMenuItem, bool> 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());
}
}

Expand Down

0 comments on commit 5e1692f

Please sign in to comment.