Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Fixed not being able to recreate a wing menu after it has been destro…
Browse files Browse the repository at this point in the history
…yed.
  • Loading branch information
RequiDev committed Jul 14, 2022
1 parent 06d2c47 commit eb44862
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion UI/UiElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public UiElement(GameObject original, Transform parent, string name, bool defaul
RectTransform = GameObject.GetComponent<RectTransform>();
}

public void Destroy()
public virtual void Destroy()
{
Object.Destroy(GameObject);
}
Expand Down
4 changes: 2 additions & 2 deletions UI/Wings/ReMirroredWingMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public ReMirroredWingMenu AddSubMenu(string text, string tooltip, Sprite sprite

public void Destroy()
{
UnityEngine.Object.Destroy(_leftMenu.GameObject);
UnityEngine.Object.Destroy(_rightMenu.GameObject);
_leftMenu.Destroy();
_rightMenu.Destroy();

_leftMenu = null;
_rightMenu = null;
Expand Down
28 changes: 26 additions & 2 deletions UI/Wings/ReWingMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static GameObject WingMenuPrefab

private readonly Wing _wing;
private readonly string _menuName;

public ReWingMenu(string text, bool left = true) : base(WingMenuPrefab, (left ? QuickMenuEx.LeftWing : QuickMenuEx.RightWing).field_Public_RectTransform_0, text, false)
{
_menuName = GetCleanName(text);
Expand Down Expand Up @@ -82,31 +82,55 @@ public ReWingMenu(string text, bool left = true) : base(WingMenuPrefab, (left ?
uiPage.field_Private_Boolean_1 = true;
uiPage.field_Protected_MenuStateController_0 = menuStateCtrl;
uiPage.field_Private_List_1_UIPage_0 = new Il2CppSystem.Collections.Generic.List<UIPage>();
uiPage.field_Private_List_1_UIPage_0.Add(uiPage);
uiPage.field_Private_List_1_UIPage_0.Add(uiPage); // what is this for? I forgot

menuStateCtrl.field_Private_Dictionary_2_String_UIPage_0.Add(uiPage.field_Public_String_0, uiPage);
}

public void Open()
{
if (!GameObject)
throw new NullReferenceException("This wing menu has been destroyed.");

_wing.field_Private_MenuStateController_0.PushPage(_menuName);
}

public ReWingButton AddButton(string text, string tooltip, Action onClick, Sprite sprite = null, bool arrow = true, bool background = true, bool separator = false)
{
if (!GameObject)
throw new NullReferenceException("This wing menu has been destroyed.");

return new ReWingButton(text, tooltip, onClick, Container, sprite, arrow, background, separator);
}

public ReWingToggle AddToggle(string text, string tooltip, Action<bool> onToggle, bool defaultValue = false)
{
if (!GameObject)
throw new NullReferenceException("This wing menu has been destroyed.");

return new ReWingToggle(text, tooltip, onToggle, Container, defaultValue);
}

public ReWingMenu AddSubMenu(string text, string tooltip)
{
if (!GameObject)
throw new NullReferenceException("This wing menu has been destroyed.");

var menu = new ReWingMenu(text, _wing._wingType == WingType.Left);
AddButton(text, tooltip, menu.Open);
return menu;
}

public override void Destroy()
{
if (!GameObject)
return;

var menuStateCtrl = _wing.GetComponent<MenuStateController>();
var uiPage = GameObject.GetComponent<UIPage>();
menuStateCtrl.field_Private_Dictionary_2_String_UIPage_0.Remove(uiPage.field_Public_String_0);

UnityEngine.Object.Destroy(GameObject);
}
}
}

0 comments on commit eb44862

Please sign in to comment.