Skip to content

Commit

Permalink
Fixed issues with 2023r172ex3
Browse files Browse the repository at this point in the history
  • Loading branch information
ddakebono committed Sep 7, 2023
1 parent 7e30b23 commit a231e8d
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 43 deletions.
2 changes: 1 addition & 1 deletion BTKUILib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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 = "1.2.3";
public const string Version = "1.2.4-preview1";
}

internal class BTKUILib : MelonMod
Expand Down
12 changes: 11 additions & 1 deletion Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static void ApplyPatches(Type type)
[HarmonyPatch(typeof(CVR_MenuManager))]
class CVRMenuManagerPatch
{
[HarmonyPatch("markMenuAsReady")]
[HarmonyPatch("RegisterEvents")]
[HarmonyPostfix]
static void MarkMenuAsReady(CVR_MenuManager __instance)
{
Expand All @@ -108,6 +108,16 @@ static void MarkMenuAsReady(CVR_MenuManager __instance)
BTKUILib.Log.Error(e);
}
}

//We'll use this point to detect a menu reload/setup and ensure BTKUIReady is false
[HarmonyPatch("UpdateModList")]
[HarmonyPrefix]
static bool UpdateModListPatch()
{
UserInterface.BTKUIReady = false;

return true;
}
}

[HarmonyPatch(typeof(ViewManager))]
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.2.0")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyVersion("1.2.4.0")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: MelonInfo(typeof(BTKUILib.BTKUILib), BTKUILib.BuildInfo.Name, BTKUILib.BuildInfo.Version, BTKUILib.BuildInfo.Author)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPriority(-10)]
Expand Down
12 changes: 6 additions & 6 deletions QuickMenuAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal static void UpdateMenuTitle(string title, string subtitle)

if (!UIUtils.IsQMReady()) return;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateTitle", title, subtitle);
UIUtils.GetInternalView().TriggerEvent("btkUpdateTitle", title, subtitle);
}

#endregion
Expand Down Expand Up @@ -179,7 +179,7 @@ public static void ShowConfirm(string title, string content, Action onYes, Actio
ConfirmYes = onYes;
ConfirmNo = onNo;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkShowConfirm", title, content, yesText, noText);
UIUtils.GetInternalView().TriggerEvent("btkShowConfirm", title, content, yesText, noText);
}

/// <summary>
Expand All @@ -194,7 +194,7 @@ public static void ShowNotice(string title, string content, Action onOK = null,
if (!UIUtils.IsQMReady()) return;

NoticeOk = onOK;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkShowNotice", title, content, okText);
UIUtils.GetInternalView().TriggerEvent("btkShowNotice", title, content, okText);
}

/// <summary>
Expand All @@ -208,7 +208,7 @@ public static void OpenNumberInput(string name, float input, Action<float> onCom
if (!UIUtils.IsQMReady()) return;

NumberInputComplete = onCompleted;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkOpenNumberInput", name, input);
UIUtils.GetInternalView().TriggerEvent("btkOpenNumberInput", name, input);
}

/// <summary>
Expand All @@ -220,7 +220,7 @@ public static void OpenMultiSelect(MultiSelection multiSelection)
if (!UIUtils.IsQMReady()) return;

UserInterface.Instance.SelectedMultiSelect = multiSelection;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkOpenMultiSelect", multiSelection.Name, multiSelection.Options, multiSelection.SelectedOption);
UIUtils.GetInternalView().TriggerEvent("btkOpenMultiSelect", multiSelection.Name, multiSelection.Options, multiSelection.SelectedOption);
}

/// <summary>
Expand All @@ -246,7 +246,7 @@ public static void ShowAlertToast(string message, int delay = 5)
{
if (!UIUtils.IsQMReady()) return;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkAlertToast", message, delay);
UIUtils.GetInternalView().TriggerEvent("btkAlertToast", message, delay);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions UIObjects/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Page AddPage(string pageName, string pageIcon, string pageTooltip, string
public override void Delete()
{
//Delete the row header with the row
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkDeleteElement", ElementID + "-HeaderRoot");
UIUtils.GetInternalView().TriggerEvent("btkDeleteElement", ElementID + "-HeaderRoot");

base.Delete();
if (Protected) return;
Expand All @@ -140,15 +140,15 @@ public override void Delete()
public void ClearChildren()
{
if(UIUtils.IsQMReady())
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkClearChildren", ElementID);
UIUtils.GetInternalView().TriggerEvent("btkClearChildren", ElementID);
}

internal override void GenerateCohtml()
{
if (!UIUtils.IsQMReady()) return;

if(!IsGenerated)
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkCreateRow", LinkedPage.ElementID, UUID, _showHeader ? _categoryName : null);
UIUtils.GetInternalView().TriggerEvent("btkCreateRow", LinkedPage.ElementID, UUID, _showHeader ? _categoryName : null);

foreach(var element in SubElements)
element.GenerateCohtml();
Expand All @@ -168,7 +168,7 @@ private void UpdateCategoryName()

if (!UIUtils.IsQMReady()) return;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateText", $"btkUI-Row-{UUID}-HeaderText", _categoryName);
UIUtils.GetInternalView().TriggerEvent("btkUpdateText", $"btkUI-Row-{UUID}-HeaderText", _categoryName);
}
}
}
8 changes: 4 additions & 4 deletions UIObjects/Components/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal override void GenerateCohtml()
if (!UIUtils.IsQMReady()) return;

if (!IsGenerated)
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkCreateButton", _category.ElementID, _buttonText, _buttonIcon, _buttonTooltip, UUID, _category.ModName, (int)_style);
UIUtils.GetInternalView().TriggerEvent("btkCreateButton", _category.ElementID, _buttonText, _buttonIcon, _buttonTooltip, UUID, _category.ModName, (int)_style);

base.GenerateCohtml();

Expand All @@ -106,9 +106,9 @@ private void UpdateButton()
}

if(_style != ButtonStyle.TextOnly)
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateIcon", ElementID, _category.ModName, _buttonIcon, _style == ButtonStyle.TextWithIcon ? "Image" : "Tooltip");
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateTooltip", $"{ElementID}-Tooltip", _buttonTooltip);
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateText", $"{ElementID}-Text", _buttonText);
UIUtils.GetInternalView().TriggerEvent("btkUpdateIcon", ElementID, _category.ModName, _buttonIcon, _style == ButtonStyle.TextWithIcon ? "Image" : "Tooltip");
UIUtils.GetInternalView().TriggerEvent("btkUpdateTooltip", $"{ElementID}-Tooltip", _buttonTooltip);
UIUtils.GetInternalView().TriggerEvent("btkUpdateText", $"{ElementID}-Text", _buttonText);
}
}

Expand Down
6 changes: 3 additions & 3 deletions UIObjects/Components/SliderFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ internal override void GenerateCohtml()
AllowDefaultReset = _allowDefaultReset
};

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkCreateSlider", _page.ElementID, UUID, _sliderValue, settings);
UIUtils.GetInternalView().TriggerEvent("btkCreateSlider", _page.ElementID, UUID, _sliderValue, settings);
}

base.GenerateCohtml();
Expand All @@ -205,8 +205,8 @@ private void UpdateSlider()
AllowDefaultReset = _allowDefaultReset
};

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkSliderUpdateSettings", UUID, settings);
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkSliderSetValue", UUID, SliderValue);
UIUtils.GetInternalView().TriggerEvent("btkSliderUpdateSettings", UUID, settings);
UIUtils.GetInternalView().TriggerEvent("btkSliderSetValue", UUID, SliderValue);
}
}

Expand Down
10 changes: 5 additions & 5 deletions UIObjects/Components/ToggleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override void Delete()
UserInterface.QMElements.Remove(this);

if (!UIUtils.IsQMReady()) return;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkDeleteElement", $"{ElementID}-Root");
UIUtils.GetInternalView().TriggerEvent("btkDeleteElement", $"{ElementID}-Root");
}

internal override void OnInteraction(bool? toggle = null)
Expand All @@ -99,7 +99,7 @@ internal override void GenerateCohtml()
if (!UIUtils.IsQMReady()) return;

if(!IsGenerated)
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkCreateToggle", _category.ElementID, _toggleName, UUID, _toggleTooltip, _toggleValue);
UIUtils.GetInternalView().TriggerEvent("btkCreateToggle", _category.ElementID, _toggleName, UUID, _toggleTooltip, _toggleValue);

base.GenerateCohtml();

Expand All @@ -116,9 +116,9 @@ private void UpdateToggle()

if (!UIUtils.IsQMReady()) return;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkSetToggleState", ElementID, _toggleValue);
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateTooltip", $"{ElementID}-Tooltip", _toggleTooltip);
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdateText", $"{ElementID}-Text", _toggleName);
UIUtils.GetInternalView().TriggerEvent("btkSetToggleState", ElementID, _toggleValue);
UIUtils.GetInternalView().TriggerEvent("btkUpdateTooltip", $"{ElementID}-Tooltip", _toggleTooltip);
UIUtils.GetInternalView().TriggerEvent("btkUpdateText", $"{ElementID}-Text", _toggleName);
}
}
}
12 changes: 6 additions & 6 deletions UIObjects/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public string PageDisplayName

if (!UIUtils.IsQMReady() || !IsGenerated) return;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkUpdatePageTitle", ElementID, value);
UIUtils.GetInternalView().TriggerEvent("btkUpdatePageTitle", ElementID, value);
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public void OpenPage()
{
if (!UIUtils.IsQMReady() || !IsGenerated) return;

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkPushPage", ElementID);
UIUtils.GetInternalView().TriggerEvent("btkPushPage", ElementID);
}

/// <summary>
Expand Down Expand Up @@ -246,7 +246,7 @@ public override void Delete()
if (RootPage)
{
UserInterface.RootPages.Remove(this);
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkDeleteElement", _tabID);
UIUtils.GetInternalView().TriggerEvent("btkDeleteElement", _tabID);
}

//Remove this page from the category list
Expand All @@ -259,7 +259,7 @@ public override void Delete()
/// </summary>
public void ClearChildren()
{
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkClearChildren", ElementID + "-Content");
UIUtils.GetInternalView().TriggerEvent("btkClearChildren", ElementID + "-Content");
}

internal override void DeleteInternal()
Expand All @@ -269,7 +269,7 @@ internal override void DeleteInternal()
if (RootPage)
{
UserInterface.RootPages.Remove(this);
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkDeleteElement", _tabID);
UIUtils.GetInternalView().TriggerEvent("btkDeleteElement", _tabID);
}

//Remove this page from the category list
Expand All @@ -282,7 +282,7 @@ internal override void GenerateCohtml()
if (!UIUtils.IsQMReady()) return;

if(!IsGenerated)
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkCreatePage", _displayName, ModName, _tabIcon, ElementID, RootPage, UIUtils.GetCleanString(PageName), InPlayerlist);
UIUtils.GetInternalView().TriggerEvent("btkCreatePage", _displayName, ModName, _tabIcon, ElementID, RootPage, UIUtils.GetCleanString(PageName), InPlayerlist);

IsGenerated = true;

Expand Down
6 changes: 3 additions & 3 deletions UIObjects/QMUIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public bool Disabled
_disabled = value;

if (!UIUtils.IsQMReady()) return;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkSetDisabled", ElementID, value);
UIUtils.GetInternalView().TriggerEvent("btkSetDisabled", ElementID, value);
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ internal virtual void DeleteInternal()
}

if (!UIUtils.IsQMReady()) return;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkDeleteElement", ElementID);
UIUtils.GetInternalView().TriggerEvent("btkDeleteElement", ElementID);
}

/// <summary>
Expand All @@ -103,7 +103,7 @@ internal virtual void DeleteInternal()
internal virtual void GenerateCohtml()
{
if (!UIUtils.IsQMReady()) return;
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkSetDisabled", ElementID, _disabled);
UIUtils.GetInternalView().TriggerEvent("btkSetDisabled", ElementID, _disabled);
}
}
}
15 changes: 13 additions & 2 deletions UIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace BTKUILib
public static class UIUtils
{
private static MD5 _hasher = MD5.Create();
private static FieldInfo _qmReady = typeof(CVR_MenuManager).GetField("_quickMenuReady", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo _internalCohtmlView = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic);
private static View _internalViewCache;

/// <summary>
/// Check if the CVR_MenuManager view is ready
Expand All @@ -25,7 +26,7 @@ public static bool IsQMReady()
if (CVR_MenuManager.Instance == null)
return false;

return (bool)_qmReady.GetValue(CVR_MenuManager.Instance) && UserInterface.BTKUIReady;
return UserInterface.BTKUIReady;
}

/// <summary>
Expand Down Expand Up @@ -58,5 +59,15 @@ internal static string CreateMD5(byte[] bytes)

return sb.ToString();
}

internal static View GetInternalView()
{
if (CVR_MenuManager.Instance == null || CVR_MenuManager.Instance.quickMenu == null) return null;

if (_internalViewCache == null)
_internalViewCache = (View)_internalCohtmlView.GetValue(CVR_MenuManager.Instance.quickMenu.View);

return _internalViewCache;
}
}
}
12 changes: 6 additions & 6 deletions UserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void OnMenuIsLoaded()

QuickMenuAPI.OnMenuRegenerate?.Invoke(CVR_MenuManager.Instance);

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkModInit");
UIUtils.GetInternalView().TriggerEvent("btkModInit");

//Run the ml prefs tab generation
BTKUILib.Instance.GenerateMlPrefsTab();
Expand Down Expand Up @@ -100,17 +100,17 @@ internal void RegisterRootPage(Page rootPage)

private void UserLeave(CVRPlayerEntity obj)
{
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkRemovePlayer", obj.Uuid, CVRPlayerManager.Instance.NetworkPlayers.Count);
UIUtils.GetInternalView().TriggerEvent("btkRemovePlayer", obj.Uuid, CVRPlayerManager.Instance.NetworkPlayers.Count);
}

private void UserJoin(CVRPlayerEntity obj)
{
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkAddPlayer", obj.Username, obj.Uuid, obj.ApiProfileImageUrl, CVRPlayerManager.Instance.NetworkPlayers.Count);
UIUtils.GetInternalView().TriggerEvent("btkAddPlayer", obj.Username, obj.Uuid, obj.ApiProfileImageUrl, CVRPlayerManager.Instance.NetworkPlayers.Count);
}

private void OnWorldLeave()
{
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkLeaveWorld");
UIUtils.GetInternalView().TriggerEvent("btkLeaveWorld");
}

#region Cohtml Event Functions
Expand All @@ -126,7 +126,7 @@ private void OnTabChange(string tabTarget)
{
if (tabTarget == "CVRMainQM")
{
CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkChangeTab", tabTarget, "CVR", "", "");
UIUtils.GetInternalView().TriggerEvent("btkChangeTab", tabTarget, "CVR", "", "");
QuickMenuAPI.OnTabChange?.Invoke(tabTarget, _lastTab);
_lastTab = tabTarget;
return;
Expand All @@ -140,7 +140,7 @@ private void OnTabChange(string tabTarget)
return;
}

CVR_MenuManager.Instance.quickMenu.View.TriggerEvent("btkChangeTab", tabTarget, root.ModName, root.MenuTitle, root.MenuSubtitle);
UIUtils.GetInternalView().TriggerEvent("btkChangeTab", tabTarget, root.ModName, root.MenuTitle, root.MenuSubtitle);
QuickMenuAPI.OnTabChange?.Invoke(tabTarget, _lastTab);
_lastTab = tabTarget;
}
Expand Down

0 comments on commit a231e8d

Please sign in to comment.