Menu integration

This commit is contained in:
SDraw 2022-08-07 17:57:49 +03:00
parent a417b41be7
commit b1c3c7f410
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
11 changed files with 223 additions and 12 deletions

View file

@ -31,14 +31,12 @@ namespace ml_fpt
new HarmonyLib.HarmonyMethod(typeof(FourPointTracking).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static))
);
MelonLoader.MelonCoroutines.Start(WaitForMainMenuView());
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
}
public override void OnUpdate()
{
if(Input.GetKeyDown(KeyCode.T) && Input.GetKey(KeyCode.LeftControl) && !m_inCalibration)
PrepareCalibration();
if(m_playerReady && m_inCalibration && (m_hipsTrackerIndex != -1))
{
if(m_origVrIk != null)
@ -83,6 +81,26 @@ namespace ml_fpt
}
}
System.Collections.IEnumerator WaitForMainMenuView()
{
while(ViewManager.Instance == null)
yield return null;
while(ViewManager.Instance.gameMenuView == null)
yield return null;
while(ViewManager.Instance.gameMenuView.Listener == null)
yield return null;
ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () =>
{
ViewManager.Instance.gameMenuView.View.RegisterForEvent("MelonMod_Action_FPT_Calibrate", new System.Action(this.StartCalibration));
};
ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
{
ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("menu.js"));
};
}
System.Collections.IEnumerator WaitForLocalPlayer()
{
while(PlayerSetup.Instance == null)
@ -94,7 +112,7 @@ namespace ml_fpt
m_playerReady = true;
}
void PrepareCalibration()
void StartCalibration()
{
if(m_playerReady && !m_inCalibration && PlayerSetup.Instance._inVr && !PlayerSetup.Instance.fullBodyActive && PlayerSetup.Instance._animator.isHuman && !m_ikCalibrator.inFullbodyCalibration && m_indexIk.calibrated)
{

View file

@ -9,13 +9,12 @@ This mod adds ability to use 4-point tracking.
# Usage
* Be sure that your tracker role is set to `Hips` in SteamVR
* Adjust your avatar at forward direction
* Press `LCtrl-T` keyboard combination to calibrate
* Go to `Settings - Implementation - 4-Point Tracking` and press `Calibrate` button
* Adjust your tracker in a similar way as in FBT calibration
* Press trigger on both hands controllers
* Press trigger on both controllers
# Notes
* You have to recalibrate each time you change avatar
# Planned
* No need for recalibration upon avatar change
* Main menu button for calibration

26
ml_fpt/Scripts.cs Normal file
View file

@ -0,0 +1,26 @@
using System;
using System.IO;
using System.Reflection;
namespace ml_fpt
{
static class Scripts
{
public static string GetEmbeddedScript(string p_name)
{
string l_result = "";
Assembly l_assembly = Assembly.GetExecutingAssembly();
string l_assemblyName = l_assembly.GetName().Name;
try
{
Stream l_libraryStream = l_assembly.GetManifestResourceStream(l_assemblyName + "." + p_name);
StreamReader l_streadReader = new StreamReader(l_libraryStream);
l_result = l_streadReader.ReadToEnd();
}
catch(Exception) { }
return l_result;
}
}
}

6
ml_fpt/menu.js Normal file
View file

@ -0,0 +1,6 @@
var l_block = document.createElement("fpt_block");
l_block.innerHTML = `
<h2>4-Point Tracking</h2>
<div class="action-btn" onclick="engine.trigger('MelonMod_Action_FPT_Calibrate');"><img src=\"gfx/recalibrate.svg\">Calibrate</div>
`;
document.getElementById('settings-implementation').appendChild(l_block);

View file

@ -81,6 +81,10 @@
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scripts.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="menu.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>