mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 10:29:22 +00:00
Impovement of UI extension
This commit is contained in:
parent
2828de3818
commit
c0e9ee15b3
16 changed files with 439 additions and 426 deletions
|
@ -27,16 +27,23 @@ namespace ml_vei
|
|||
float l_mag = ((!__instance.HasEmoteOverride) ? __instance.Primary2DAxis : __instance.EmoteOverride).magnitude;
|
||||
if(__instance.ViveDirectionPressed && (l_mag >= CVRInputManager.VrViveGestureDeadZone))
|
||||
{
|
||||
if(__instance.Grip > 0.5f)
|
||||
if(Settings.GripTrigger)
|
||||
{
|
||||
__instance.GestureRaw = -1f;
|
||||
__instance.Gesture = -1f;
|
||||
switch(Settings.AxisPriority)
|
||||
{
|
||||
case Settings.PriorityAxis.Grip:
|
||||
__instance.GestureRaw = ((__instance.Grip > 0.5f) ? -1f : __instance.Trigger);
|
||||
break;
|
||||
|
||||
case Settings.PriorityAxis.Trigger:
|
||||
__instance.GestureRaw = (!UnityEngine.Mathf.Approximately(__instance.Trigger, 0f) ? __instance.Trigger : ((__instance.Grip > 0.5f) ? -1f : 0f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.GestureRaw = __instance.Trigger;
|
||||
__instance.Gesture = __instance.Trigger;
|
||||
}
|
||||
__instance.GestureRaw = 0f;
|
||||
|
||||
__instance.Gesture = __instance.GestureRaw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,29 @@ namespace ml_vei
|
|||
{
|
||||
static class Settings
|
||||
{
|
||||
public enum ModSetting
|
||||
enum ModSetting
|
||||
{
|
||||
Gestures = 0
|
||||
Gestures = 0,
|
||||
GripTrigger,
|
||||
AxisPriority
|
||||
}
|
||||
|
||||
public enum PriorityAxis
|
||||
{
|
||||
Grip = 0,
|
||||
Trigger
|
||||
}
|
||||
|
||||
public static bool Gestures { get; private set; } = true;
|
||||
public static bool GripTrigger { get; private set; } = true;
|
||||
public static PriorityAxis AxisPriority { get; private set; } = PriorityAxis.Grip;
|
||||
|
||||
static MelonLoader.MelonPreferences_Category ms_category = null;
|
||||
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
||||
|
||||
static public event Action<bool> GesturesChange;
|
||||
static public event Action<bool> GripTriggerChange;
|
||||
static public event Action<PriorityAxis> AxisPriorityChange;
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
|
@ -25,9 +37,13 @@ namespace ml_vei
|
|||
ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
|
||||
{
|
||||
ms_category.CreateEntry(ModSetting.Gestures.ToString(), Gestures),
|
||||
ms_category.CreateEntry(ModSetting.GripTrigger.ToString(), GripTrigger),
|
||||
ms_category.CreateEntry(ModSetting.AxisPriority.ToString(), (int)AxisPriority),
|
||||
};
|
||||
|
||||
Load();
|
||||
Gestures = (bool)ms_entries[(int)ModSetting.Gestures].BoxedValue;
|
||||
GripTrigger = (bool)ms_entries[(int)ModSetting.GripTrigger].BoxedValue;
|
||||
AxisPriority = (PriorityAxis)(int)ms_entries[(int)ModSetting.AxisPriority].BoxedValue;
|
||||
|
||||
MelonLoader.MelonCoroutines.Start(WaitMainMenuUi());
|
||||
}
|
||||
|
@ -43,22 +59,18 @@ namespace ml_vei
|
|||
|
||||
ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () =>
|
||||
{
|
||||
ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_VEI_Call_InpToggle", new Action<string, string>(OnToggleUpdate));
|
||||
ViewManager.Instance.gameMenuView.View.BindCall("OnToggleUpdate_" + ms_category.Identifier, new Action<string, string>(OnToggleUpdate));
|
||||
ViewManager.Instance.gameMenuView.View.BindCall("OnDropdownUpdate_" + ms_category.Identifier, new Action<string, string>(OnDropdownUpdate));
|
||||
};
|
||||
ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
|
||||
{
|
||||
ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("ui_elements.js"));
|
||||
ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("ui_menu.js"));
|
||||
ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("mods_extension.js"));
|
||||
ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("mod_menu.js"));
|
||||
foreach(var l_entry in ms_entries)
|
||||
ViewManager.Instance.gameMenuView.View.TriggerEvent("updateModSettingVEI", l_entry.DisplayName, l_entry.GetValueAsString());
|
||||
ViewManager.Instance.gameMenuView.View.TriggerEvent("updateModSetting", ms_category.Identifier, l_entry.DisplayName, l_entry.GetValueAsString());
|
||||
};
|
||||
}
|
||||
|
||||
static void Load()
|
||||
{
|
||||
Gestures = (bool)ms_entries[(int)ModSetting.Gestures].BoxedValue;
|
||||
}
|
||||
|
||||
static void OnToggleUpdate(string p_name, string p_value)
|
||||
{
|
||||
if(Enum.TryParse(p_name, out ModSetting l_setting))
|
||||
|
@ -71,10 +83,34 @@ namespace ml_vei
|
|||
GesturesChange?.Invoke(Gestures);
|
||||
}
|
||||
break;
|
||||
|
||||
case ModSetting.GripTrigger:
|
||||
{
|
||||
GripTrigger = bool.Parse(p_value);
|
||||
GripTriggerChange?.Invoke(GripTrigger);
|
||||
} break;
|
||||
}
|
||||
|
||||
ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnDropdownUpdate(string p_name, string p_value)
|
||||
{
|
||||
if(Enum.TryParse(p_name, out ModSetting l_setting))
|
||||
{
|
||||
switch(l_setting)
|
||||
{
|
||||
case ModSetting.AxisPriority:
|
||||
{
|
||||
AxisPriority = (PriorityAxis)int.Parse(p_value);
|
||||
AxisPriorityChange?.Invoke(AxisPriority);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<None Remove="PlayerRagdollMod.json" />
|
||||
<None Remove="resources\ui_menu.js" />
|
||||
<None Remove="resources\mod_menu.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -53,8 +53,11 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\js\ui_elements.js" Link="resources\ui_elements.js" />
|
||||
<EmbeddedResource Include="resources\ui_menu.js" />
|
||||
<EmbeddedResource Include="resources\mod_menu.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\js\mods_extension.js" Link="resources\mods_extension.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
|
39
ml_vei/resources/mod_menu.js
Normal file
39
ml_vei/resources/mod_menu.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
let l_block = document.createElement('div');
|
||||
l_block.innerHTML = `
|
||||
<div class ="settings-subcategory">
|
||||
<div class ="subcategory-name">Vive Extended Input</div>
|
||||
<div class ="subcategory-description"></div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Disable gestures while moving: </div>
|
||||
<div class ="option-input">
|
||||
<div id="Gestures" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Apply grip/trigger while moving: </div>
|
||||
<div class ="option-input">
|
||||
<div id="GripTrigger" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Axis priority: </div>
|
||||
<div class ="option-input">
|
||||
<div id="AxisPriority" class ="inp_dropdown no-scroll" data-options="0:Grip,1:Trigger" data-current="0"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('settings-input').appendChild(l_block);
|
||||
|
||||
// Toggles
|
||||
for (let l_toggle of l_block.querySelectorAll('.inp_toggle'))
|
||||
modsExtension.addSetting('VEI', l_toggle.id, modsExtension.createToggle(l_toggle, 'OnToggleUpdate_VEI'));
|
||||
|
||||
// Dropdowns
|
||||
for (let l_dropdown of l_block.querySelectorAll('.inp_dropdown'))
|
||||
modsExtension.addSetting('VEI', l_dropdown.id, modsExtension.createDropdown(l_dropdown, 'OnDropdownUpdate_VEI'));
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// Add settings
|
||||
var g_modSettingsVEI = [];
|
||||
|
||||
engine.on('updateModSettingVEI', function (_name, _value) {
|
||||
for (var i = 0; i < g_modSettingsVEI.length; i++) {
|
||||
if (g_modSettingsVEI[i].name == _name) {
|
||||
g_modSettingsVEI[i].updateValue(_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Add own menu
|
||||
{
|
||||
let l_block = document.createElement('div');
|
||||
l_block.innerHTML = `
|
||||
<div class ="settings-subcategory">
|
||||
<div class ="subcategory-name">Vive Extended Input</div>
|
||||
<div class ="subcategory-description"></div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Disable gestures while moving: </div>
|
||||
<div class ="option-input">
|
||||
<div id="Gestures" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('settings-input').appendChild(l_block);
|
||||
|
||||
// Update toggles in new menu block
|
||||
let l_toggles = l_block.querySelectorAll('.inp_toggle');
|
||||
for (var i = 0; i < l_toggles.length; i++) {
|
||||
g_modSettingsVEI[g_modSettingsVEI.length] = new inp_toggle_mod(l_toggles[i], 'MelonMod_VEI_Call_InpToggle');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue