Skip to content

Commit 37d89a9

Browse files
committed
Replaced playerlist style pref with Enum pref, added fallback to ensure playerlist button will always appear, fixed initial currentPageBTK being set to MainPage instead of CVRMainQM.
1 parent 7ca0444 commit 37d89a9

File tree

3 files changed

+54
-37
lines changed

3 files changed

+54
-37
lines changed

BTKUILib.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class BuildInfo
1313
public const string Name = "BTKUILib";
1414
public const string Author = "BTK Development Team";
1515
public const string Company = "BTK Development";
16-
public const string Version = "2.2.0";
16+
public const string Version = "2.2.1";
1717
}
1818

1919
internal class BTKUILib : MelonMod
@@ -26,14 +26,14 @@ internal class BTKUILib : MelonMod
2626
internal UserInterface UI;
2727
internal Queue<Action> MainThreadQueue = new();
2828
internal Dictionary<string, Page> MLPrefsPages = new();
29-
internal MelonPreferences_Entry<string> PlayerListStyle;
29+
internal MelonPreferences_Entry<PlayerListStyleEnum> PlayerListStyle;
3030

3131
private MelonPreferences_Entry<bool> _displayPrefsTab;
3232

3333
private Thread _mainThread;
3434
private Page _mlPrefsPage;
3535
private MultiSelection _playerListButtonStyle;
36-
private string[] _playerListOptions = { "Tab Bar", "Right Bar", "Replace Events" };
36+
private string[] _playerListStyleNames;
3737

3838
public override void OnInitializeMelon()
3939
{
@@ -51,7 +51,7 @@ public override void OnInitializeMelon()
5151
_mlPrefsPage.HideTab = b1;
5252
});
5353

54-
PlayerListStyle = MelonPreferences.CreateEntry("BTKUILib", "PlayerListPosition", "Tab Bar", "PlayerList Button Position", "Sets where the playerlist button will appear");
54+
PlayerListStyle = MelonPreferences.CreateEntry("BTKUILib", "PlayerListStyleNew", PlayerListStyleEnum.TabBar, "PlayerList Button Style", "Sets where the playerlist button will appear");
5555

5656
Patches.Initialize(HarmonyInstance);
5757

@@ -74,6 +74,7 @@ internal void GenerateSettingsPage()
7474
prefsTabDisplay.OnValueUpdated += b =>
7575
{
7676
_displayPrefsTab.Value = b;
77+
MelonPreferences.Save();
7778
};
7879

7980
var openListStyle = mainCat.AddButton("Playerlist Button Position", "BTKList", "Change the position of the playerlist button");
@@ -82,11 +83,16 @@ internal void GenerateSettingsPage()
8283
QuickMenuAPI.OpenMultiSelect(_playerListButtonStyle);
8384
};
8485

85-
_playerListButtonStyle = new MultiSelection("PlayerList Button Position", _playerListOptions, Array.FindIndex(_playerListOptions, x => x.Contains(PlayerListStyle.Value)));
86+
_playerListStyleNames = Enum.GetNames(typeof(PlayerListStyleEnum));
87+
88+
_playerListButtonStyle = new MultiSelection("PlayerList Button Position", _playerListStyleNames, (int)PlayerListStyle.Value);
8689
_playerListButtonStyle.OnOptionUpdated += i =>
8790
{
91+
if(!Enum.IsDefined(typeof(PlayerListStyleEnum), i)) return;
92+
8893
QuickMenuAPI.ShowAlertToast("You must restart ChilloutVR for this change to apply!");
89-
PlayerListStyle.Value = _playerListOptions[i];
94+
PlayerListStyle.Value = (PlayerListStyleEnum)Enum.Parse(typeof(PlayerListStyleEnum), Enum.GetNames(typeof(PlayerListStyleEnum))[i]);
95+
MelonPreferences.Save();
9096
};
9197
}
9298

@@ -154,4 +160,23 @@ public override void OnUpdate()
154160
}
155161
}
156162
}
163+
164+
/// <summary>
165+
/// Enum containing the usable styles of playerlist button
166+
/// </summary>
167+
public enum PlayerListStyleEnum
168+
{
169+
/// <summary>
170+
/// Default style, button appears on the tab bar
171+
/// </summary>
172+
TabBar,
173+
/// <summary>
174+
/// Button replaces the existing TTS button on the right sidebar
175+
/// </summary>
176+
ReplaceTTS,
177+
/// <summary>
178+
/// Button replaces the unused events button on the QM
179+
/// </summary>
180+
ReplaceEvents,
181+
}
157182
}

CohtmlUI/mod.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ cvr.menu.prototype.BTKUI = {
5656
register: function(menu){
5757
uiRefBTK = menu;
5858
breadcrumbsBTK = [];
59-
currentPageBTK = "MainPage";
60-
currentMod = "BTKUI";
59+
currentPageBTK = "CVRMainQM";
60+
currentMod = "CVR";
6161
currentDraggedSliderBTK = {};
6262
currentSliderBarBTK = {};
6363
currentSliderKnobBTK = {};
@@ -363,42 +363,20 @@ cvr.menu.prototype.BTKUI = {
363363
cvr("#btkUI-UserMenu").show();
364364
cvr("#btkUI-SharedRoot").show();
365365

366-
if(plButtonStyle !== "Tab Bar"){
367-
let tabCont = document.getElementById("btkUI-TabContainer");
368-
if(tabCont !== null)
369-
tabCont.classList.remove("container-tabs-left")
370-
let scrollCont = document.getElementById("btkUI-TabScroll-Container");
371-
if(scrollCont !== null)
372-
scrollCont.classList.remove("scroll-bg-left");
373-
cvr("#btkUI-UserMenu").hide();
374-
}
366+
let tabBarMode = false;
375367

376368
switch(plButtonStyle){
377-
case "Replace TTS":
378-
case "Right Bar":
369+
case "ReplaceTTS":
379370
cvr("#btkUI-UserMenuRightBar").show();
380-
/*let ttsElement = document.getElementsByClassName("button-tts");
371+
let ttsElement = document.getElementsByClassName("button-tts");
381372

382-
if(ttsElement.length === 0){
383-
console.error("Couldn't find TTS element! Unable to replace!");
373+
if(ttsElement.length === 0)
384374
return;
385-
}
386375

387376
ttsElement = ttsElement[0];
388-
389-
ttsElement.classList.add("icon-multiuser");
390-
ttsElement.style.backgroundImage = "url(mods/BTKUI/images/Multiuser.png)";
391-
ttsElement.style.backgroundSize = "contain";
392-
ttsElement.style.backgroundPositionY = "0";
393-
ttsElement.style.backgroundPositionX = "0";
394-
395-
ttsElement.removeEventListener("click", uiRefBTK.actions["openTTSKeyboard"]);
396-
ttsElement.addEventListener("click", uiRefBTK.actions["btkUI-pushPage"]);
397-
ttsElement.setAttribute("data-x", "btkUI-pushPage");
398-
ttsElement.setAttribute("data-page", "btkUI-PlayerList");
399-
ttsElement.setAttribute("data-tooltip", "Opens the UILib PlayerList");*/
377+
ttsElement.classList.add("hidden");
400378
break;
401-
case "Replace Events":
379+
case "ReplaceEvents":
402380
let eventButton = document.getElementsByClassName("events");
403381

404382
if(eventButton.length === 0){
@@ -426,6 +404,19 @@ cvr.menu.prototype.BTKUI = {
426404
let label = eventButton.querySelector('.label');
427405
label.innerHTML = "Playerlist";
428406
break;
407+
default:
408+
tabBarMode = true;
409+
break;
410+
}
411+
412+
if(plButtonStyle !== "TabBar" && !tabBarMode){
413+
let tabCont = document.getElementById("btkUI-TabContainer");
414+
if(tabCont !== null)
415+
tabCont.classList.remove("container-tabs-left")
416+
let scrollCont = document.getElementById("btkUI-TabScroll-Container");
417+
if(scrollCont !== null)
418+
scrollCont.classList.remove("scroll-bg-left");
419+
cvr("#btkUI-UserMenu").hide();
429420
}
430421
},
431422

@@ -848,6 +839,7 @@ cvr.menu.prototype.BTKUI = {
848839
}
849840
},
850841
btkOpenMultiSelect: function(name, options, selectedIndex, playerListMode = false){
842+
btkMultiSelectPLMode = playerListMode;
851843
let element = cvr("#btkUI-Dropdown-OptionRoot");
852844
if(playerListMode)
853845
element = cvr("#btkUI-DropdownPL-OptionRoot");

UserInterface.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private void OnMenuIsLoaded()
121121
foreach(var css in CustomCSSStyles)
122122
UIUtils.GetInternalView().TriggerEvent("btkSetCustomCSS", css);
123123

124-
UIUtils.GetInternalView().TriggerEvent("btkModInit", BTKUILib.Instance.PlayerListStyle.Value);
124+
UIUtils.GetInternalView().TriggerEvent("btkModInit", Enum.GetName(typeof(PlayerListStyleEnum), BTKUILib.Instance.PlayerListStyle.Value));
125125

126126
//Run the ml prefs tab generation
127127
BTKUILib.Instance.GenerateMlPrefsTab();

0 commit comments

Comments
 (0)