Skip to content

Commit

Permalink
Fixed ClearChildren not properly clearing and deleting subelements, f…
Browse files Browse the repository at this point in the history
…ixed Page.ClearChildren not really doing anything useful.
  • Loading branch information
ddakebono committed Dec 28, 2023
1 parent a93fdeb commit 59478c5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BTKUILib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class BuildInfo
public const string Name = "BTKUILib";
public const string Author = "BTK Development Team";
public const string Company = "BTK Development";
public const string Version = "2.0.0";
public const string Version = "2.0.1";
}

internal class BTKUILib : MelonMod
Expand Down
18 changes: 18 additions & 0 deletions UIObjects/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ public override void Delete()
/// </summary>
public void ClearChildren()
{
//Iterate through each subelement and ensure ClearChildren and Delete is fired
foreach (var subElement in SubElements.ToArray())
{
if(subElement.Deleted) continue;

switch (subElement)
{
case Page page:
page.ClearChildren();
break;
case Category cat:
cat.ClearChildren();
break;
}

subElement.Delete();
}

SubElements.Clear();

if(UIUtils.IsQMReady() && IsVisible)
Expand Down
22 changes: 21 additions & 1 deletion UIObjects/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,30 @@ public override void Delete()
}

/// <summary>
/// Deletes all children of this category
/// Deletes all children of this page
/// </summary>
public void ClearChildren()
{
//Iterate through each subelement and ensure ClearChildren and Delete is fired
foreach (var subElement in SubElements.ToArray())
{
if(subElement.Deleted) continue;

switch (subElement)
{
case Page page:
page.ClearChildren();
break;
case Category cat:
cat.ClearChildren();
break;
}

subElement.Delete();
}

SubElements.Clear();

if(!IsVisible) return;
UIUtils.GetInternalView().TriggerEvent("btkClearChildren", ElementID + "-Content");
}
Expand Down
7 changes: 7 additions & 0 deletions UIObjects/QMInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ internal virtual void OnInteraction(bool? toggle = null)
{

}

internal override void DeleteInternal(bool tabChange = false)
{
base.DeleteInternal(tabChange);

UserInterface.Interactables.Remove(UUID);
}
}
}
6 changes: 6 additions & 0 deletions UIObjects/QMUIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public bool Disabled
/// Set to prevent changes to some elements (Internal use)
/// </summary>
internal bool Protected;
/// <summary>
/// Set to keep track of deleted elements during a ClearChildren
/// </summary>
internal bool Deleted;

/// <summary>
/// This list contains elements that are children of this element (categories/pages)
Expand Down Expand Up @@ -149,6 +153,8 @@ internal virtual void DeleteInternal(bool tabChange = false)
}
}

Deleted = true;

if (!UIUtils.IsQMReady()) return;
UIUtils.GetInternalView().TriggerEvent("btkDeleteElement", ElementID);
}
Expand Down

0 comments on commit 59478c5

Please sign in to comment.