mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
i dont rememebr
This commit is contained in:
parent
374ab6c11e
commit
86828a94e2
48 changed files with 1637 additions and 841 deletions
|
@ -1,4 +1,5 @@
|
|||
using ABI_RC.Core.IO;
|
||||
using System.Collections;
|
||||
using ABI_RC.Core.IO;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Player.AvatarTracking;
|
||||
using ABI_RC.Core.UI;
|
||||
|
@ -11,14 +12,29 @@ namespace NAK.AvatarScaleMod.AvatarScaling;
|
|||
|
||||
public class AvatarScaleManager : MonoBehaviour
|
||||
{
|
||||
// Universal Scaling Limits
|
||||
public const float MinHeight = 0.1f;
|
||||
public const float MaxHeight = 10f;
|
||||
|
||||
public static AvatarScaleManager Instance;
|
||||
public static AvatarScaleManager Instance { get; private set; }
|
||||
|
||||
private LocalScaler _localAvatarScaler;
|
||||
private Dictionary<string, NetworkScaler> _networkedScalers;
|
||||
|
||||
private Coroutine _heightUpdateCoroutine;
|
||||
private readonly YieldInstruction _heightUpdateYield = new WaitForEndOfFrame();
|
||||
|
||||
#region Universal Scaling Limits
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// To match AvatarScaleTool: https://github.com/NotAKidOnSteam/AvatarScaleTool/tree/main
|
||||
public const float DefaultMinHeight = 0.25f;
|
||||
public const float DefaultMaxHeight = 2.50f;
|
||||
// ReSharper restore MemberCanBePrivate.Global
|
||||
|
||||
// Universal Scaling Limits
|
||||
public static float MinHeight { get; private set; } = DefaultMinHeight;
|
||||
public static float MaxHeight { get; private set; } = DefaultMaxHeight;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
|
||||
private bool _settingUniversalScaling;
|
||||
public bool Setting_UniversalScaling
|
||||
|
@ -27,21 +43,25 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
set
|
||||
{
|
||||
if (value != _settingUniversalScaling && value == false)
|
||||
ResetHeight();
|
||||
ResetTargetHeight();
|
||||
|
||||
_settingUniversalScaling = value;
|
||||
SetTargetHeight(_lastTargetHeight); // immediate height update
|
||||
}
|
||||
}
|
||||
|
||||
public bool Setting_PersistantHeight;
|
||||
public bool Setting_AnimationClipScalingOverride;
|
||||
public bool Setting_PersistentHeight;
|
||||
private float _lastTargetHeight = -1;
|
||||
|
||||
|
||||
#region Unity Methods
|
||||
#endregion
|
||||
|
||||
#region Unity Events
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
if (Instance != null
|
||||
&& Instance != this)
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
return;
|
||||
|
@ -53,22 +73,82 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
|
||||
private void Start()
|
||||
{
|
||||
_localAvatarScaler = PlayerSetup.Instance.gameObject.AddComponent<LocalScaler>();
|
||||
_localAvatarScaler.Initialize();
|
||||
|
||||
_settingUniversalScaling = ModSettings.EntryUseUniversalScaling.Value;
|
||||
Setting_AnimationClipScalingOverride = ModSettings.EntryAnimationScalingOverride.Value;
|
||||
Setting_PersistentHeight = ModSettings.EntryPersistentHeight.Value;
|
||||
_lastTargetHeight = ModSettings.EntryPersistThroughRestart.Value
|
||||
? ModSettings.EntryHiddenAvatarHeight.Value : -1f; // -1f is default
|
||||
|
||||
// listen for events
|
||||
_localAvatarScaler.OnAnimatedHeightOverride += OnAnimationHeightOverride;
|
||||
|
||||
CVRGameEventSystem.Instance.OnConnected.AddListener(OnInstanceConnected);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_heightUpdateCoroutine != null) StopCoroutine(_heightUpdateCoroutine);
|
||||
_heightUpdateCoroutine = StartCoroutine(HeightUpdateCoroutine());
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_heightUpdateCoroutine != null) StopCoroutine(_heightUpdateCoroutine);
|
||||
_heightUpdateCoroutine = null;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_heightUpdateCoroutine = null;
|
||||
CVRGameEventSystem.Instance.OnConnected.RemoveListener(OnInstanceConnected);
|
||||
|
||||
if (_localAvatarScaler != null) Destroy(_localAvatarScaler);
|
||||
_localAvatarScaler = null;
|
||||
|
||||
foreach (NetworkScaler scaler in _networkedScalers.Values) Destroy(scaler);
|
||||
_networkedScalers.Clear();
|
||||
|
||||
if (Instance == this)
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
// only update the height per scaler once per frame, to prevent spam & jitter
|
||||
// this is to ensure that the height is also set at correct time during frame, no matter when it is called
|
||||
private IEnumerator HeightUpdateCoroutine()
|
||||
{
|
||||
while (enabled)
|
||||
{
|
||||
yield return _heightUpdateYield;
|
||||
|
||||
// update local scaler
|
||||
if (_localAvatarScaler != null && _localAvatarScaler.heightNeedsUpdate)
|
||||
{
|
||||
if (_localAvatarScaler.ApplyTargetHeight())
|
||||
AvatarScaleEvents.OnLocalAvatarHeightChanged.Invoke(_localAvatarScaler);
|
||||
}
|
||||
|
||||
// update networked scalers (probably a better way to do this)
|
||||
foreach (var netScaler in _networkedScalers)
|
||||
{
|
||||
if (!netScaler.Value.heightNeedsUpdate) continue;
|
||||
if (netScaler.Value.ApplyTargetHeight())
|
||||
AvatarScaleEvents.OnRemoteAvatarHeightChanged.Invoke(netScaler.Key, netScaler.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once IteratorNeverReturns
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
#region Game Events
|
||||
|
||||
public void OnInstanceConnected(string instanceId)
|
||||
{
|
||||
// TODO: need to know if this causes issues when in a reconnection loop
|
||||
SchedulerSystem.AddJob(ModNetwork.RequestHeightSync, 2f, 1f, 1);
|
||||
}
|
||||
|
||||
|
@ -81,19 +161,13 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
if (playerSetup._avatar == null)
|
||||
return;
|
||||
|
||||
if (_localAvatarScaler == null)
|
||||
{
|
||||
_localAvatarScaler = playerSetup.gameObject.AddComponent<LocalScaler>();
|
||||
_localAvatarScaler.Initialize();
|
||||
}
|
||||
|
||||
_localAvatarScaler.OnAvatarInstantiated(playerSetup._avatar, playerSetup._initialAvatarHeight,
|
||||
playerSetup.initialScale);
|
||||
|
||||
if (!_settingUniversalScaling)
|
||||
return;
|
||||
|
||||
SetHeight(Setting_PersistantHeight ? _lastTargetHeight : -1f);
|
||||
SetTargetHeight(_lastTargetHeight);
|
||||
}
|
||||
|
||||
public void OnAvatarDestroyed(PlayerSetup playerSetup)
|
||||
|
@ -102,35 +176,34 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
_localAvatarScaler.OnAvatarDestroyed();
|
||||
}
|
||||
|
||||
public void SetHeight(float targetHeight)
|
||||
public void SetTargetHeight(float targetHeight)
|
||||
{
|
||||
_lastTargetHeight = targetHeight; // save for persistent height
|
||||
ModSettings.EntryHiddenAvatarHeight.Value = targetHeight; // save for restart
|
||||
|
||||
if (!_settingUniversalScaling)
|
||||
return;
|
||||
|
||||
if (_localAvatarScaler == null)
|
||||
return;
|
||||
|
||||
_lastTargetHeight = targetHeight;
|
||||
|
||||
_localAvatarScaler.SetTargetHeight(targetHeight);
|
||||
ModNetwork.SendNetworkHeight(targetHeight);
|
||||
|
||||
// immediately update play space scale
|
||||
PlayerSetup.Instance.CheckUpdateAvatarScaleToPlaySpaceRelation();
|
||||
_localAvatarScaler.SetTargetHeight(_lastTargetHeight);
|
||||
_localAvatarScaler.heightNeedsUpdate = true; // only local scaler forces update
|
||||
}
|
||||
|
||||
public void ResetHeight()
|
||||
|
||||
public void ResetTargetHeight()
|
||||
{
|
||||
if (_localAvatarScaler == null)
|
||||
return;
|
||||
|
||||
if (!_localAvatarScaler.IsHeightAdjustedFromInitial())
|
||||
if (!_localAvatarScaler.IsForcingHeight())
|
||||
return;
|
||||
|
||||
// TODO: doesnt work when hitting Reset on slider in BTK UI (is it on main thread?)
|
||||
CohtmlHud.Instance.ViewDropTextImmediate("(Local) AvatarScaleMod", "Avatar Scale Reset!",
|
||||
"Universal Scaling is now disabled.");
|
||||
|
||||
SetHeight(-1f);
|
||||
SetTargetHeight(-1f);
|
||||
}
|
||||
|
||||
public float GetHeight()
|
||||
|
@ -138,10 +211,21 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
if (_localAvatarScaler == null)
|
||||
return PlayerAvatarPoint.defaultAvatarHeight;
|
||||
|
||||
if (!_localAvatarScaler.IsHeightAdjustedFromInitial())
|
||||
if (!_localAvatarScaler.IsForcingHeight())
|
||||
return PlayerSetup.Instance.GetAvatarHeight();
|
||||
|
||||
return _localAvatarScaler.GetHeight();
|
||||
return _localAvatarScaler.GetTargetHeight();
|
||||
}
|
||||
|
||||
public float GetAnimationClipHeight()
|
||||
{
|
||||
if (_localAvatarScaler == null)
|
||||
return PlayerAvatarPoint.defaultAvatarHeight;
|
||||
|
||||
if (!_localAvatarScaler.IsForcingHeight())
|
||||
return PlayerSetup.Instance.GetAvatarHeight();
|
||||
|
||||
return _localAvatarScaler.GetAnimatedHeight();
|
||||
}
|
||||
|
||||
public float GetHeightForNetwork()
|
||||
|
@ -152,10 +236,10 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
if (_localAvatarScaler == null)
|
||||
return -1f;
|
||||
|
||||
if (!_localAvatarScaler.IsHeightAdjustedFromInitial())
|
||||
if (!_localAvatarScaler.IsForcingHeight())
|
||||
return -1f;
|
||||
|
||||
return _localAvatarScaler.GetHeight();
|
||||
return _localAvatarScaler.GetTargetHeight();
|
||||
}
|
||||
|
||||
public float GetInitialHeight()
|
||||
|
@ -168,17 +252,23 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
|
||||
public bool IsHeightAdjustedFromInitial()
|
||||
{
|
||||
return _localAvatarScaler != null && _localAvatarScaler.IsHeightAdjustedFromInitial();
|
||||
return _localAvatarScaler != null && _localAvatarScaler.IsForcingHeight();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Network Methods
|
||||
|
||||
public bool DoesNetworkHeightScalerExist(string playerId)
|
||||
=> _networkedScalers.ContainsKey(playerId);
|
||||
|
||||
public int GetNetworkHeightScalerCount()
|
||||
=> _networkedScalers.Count;
|
||||
|
||||
public float GetNetworkHeight(string playerId)
|
||||
{
|
||||
if (_networkedScalers.TryGetValue(playerId, out NetworkScaler scaler))
|
||||
if (scaler.IsHeightAdjustedFromInitial()) return scaler.GetHeight();
|
||||
if (scaler.IsForcingHeight()) return scaler.GetTargetHeight();
|
||||
|
||||
//doesn't have mod or has no custom height, get from player avatar directly
|
||||
CVRPlayerEntity playerEntity = CVRPlayerManager.Instance.NetworkPlayers.Find((players) => players.Uuid == playerId);
|
||||
|
@ -266,4 +356,40 @@ public class AvatarScaleManager : MonoBehaviour
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manager Methods
|
||||
|
||||
// sometimes fun to play with via UE
|
||||
public void SetUniversalScalingLimit(float min, float max)
|
||||
{
|
||||
const float HardCodedMinLimit = 0.01f;
|
||||
const float HardCodedMaxLimit = 100f;
|
||||
|
||||
MinHeight = Mathf.Clamp(min, HardCodedMinLimit, HardCodedMaxLimit);
|
||||
MaxHeight = Mathf.Clamp(max, HardCodedMinLimit, HardCodedMaxLimit);
|
||||
|
||||
AvatarScaleMod.Logger.Msg($"Universal Scaling Limits changed: {min} - {max}");
|
||||
AvatarScaleMod.Logger.Warning("This will not network to other users unless they also have the same limits set!");
|
||||
}
|
||||
|
||||
public void ResetUniversalScalingLimit()
|
||||
{
|
||||
MinHeight = DefaultMinHeight;
|
||||
MaxHeight = DefaultMaxHeight;
|
||||
|
||||
AvatarScaleMod.Logger.Msg("Universal Scaling Limits reset to default!");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Listeners
|
||||
|
||||
private static void OnAnimationHeightOverride(BaseScaler scaler)
|
||||
{
|
||||
AvatarScaleMod.Logger.Msg("AnimationClip-based avatar scaling detected. Disabling Universal Scaling.");
|
||||
CohtmlHud.Instance.ViewDropTextImmediate("(Local) AvatarScaleMod", "Avatar Scale Changed!",
|
||||
"Universal Scaling is now disabled in favor of built-in avatar scaling.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
using ABI_RC.Core;
|
||||
using ABI_RC.Core.Player;
|
||||
using System.Diagnostics;
|
||||
using ABI_RC.Core;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
using NAK.AvatarScaleMod.ScaledComponents;
|
||||
using UnityEngine;
|
||||
|
@ -12,143 +12,201 @@ public class BaseScaler : MonoBehaviour
|
|||
{
|
||||
#region Constants
|
||||
|
||||
public const string ScaleFactorParameterName = "ScaleFactor";
|
||||
public const string ScaleFactorParameterNameLocal = "#ScaleFactor";
|
||||
protected const string ScaleFactorParameterName = "ScaleFactor";
|
||||
protected const string ScaleFactorParameterNameLocal = "#" + ScaleFactorParameterName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
// OnAnimatedHeightChanged
|
||||
public delegate void AnimatedHeightChangedDelegate(BaseScaler scaler);
|
||||
public event AnimatedHeightChangedDelegate OnAnimatedHeightChanged;
|
||||
|
||||
// OnAnimatedHeightOverride
|
||||
public delegate void AnimatedHeightOverrideDelegate(BaseScaler scaler);
|
||||
public event AnimatedHeightOverrideDelegate OnAnimatedHeightOverride;
|
||||
|
||||
// OnTargetHeightChanged
|
||||
public delegate void TargetHeightChangedDelegate(BaseScaler scaler);
|
||||
public event TargetHeightChangedDelegate OnTargetHeightChanged;
|
||||
|
||||
// OnHeightReset
|
||||
public delegate void HeightResetDelegate(BaseScaler scaler);
|
||||
public event HeightResetDelegate OnTargetHeightReset;
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
protected void InvokeAnimatedHeightChanged()
|
||||
=> OnAnimatedHeightChanged?.Invoke(this);
|
||||
|
||||
protected void InvokeAnimatedHeightOverride()
|
||||
=> OnAnimatedHeightOverride?.Invoke(this);
|
||||
|
||||
protected void InvokeTargetHeightChanged()
|
||||
=> OnTargetHeightChanged?.Invoke(this);
|
||||
|
||||
protected void InvokeTargetHeightReset()
|
||||
=> OnTargetHeightReset?.Invoke(this);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables
|
||||
|
||||
internal bool _isAvatarInstantiated;
|
||||
internal bool _isHeightAdjustedFromInitial;
|
||||
internal bool _heightNeedsUpdate;
|
||||
// Height update requested
|
||||
public bool heightNeedsUpdate { get; internal set; }
|
||||
|
||||
// Config variables
|
||||
public bool avatarIsHidden { get; set; }
|
||||
public bool useTargetHeight { get; set; }
|
||||
public bool overrideAnimationHeight { get; set; }
|
||||
|
||||
// State variables
|
||||
internal bool _isAvatarInstantiated;
|
||||
internal bool _shouldForceHeight => useTargetHeight || avatarIsHidden; // universal or hidden avatar
|
||||
|
||||
// Avatar info
|
||||
internal Transform _avatarTransform;
|
||||
internal CVRAnimatorManager _animatorManager;
|
||||
|
||||
|
||||
// Initial scaling
|
||||
internal float _initialHeight;
|
||||
internal Vector3 _initialScale;
|
||||
|
||||
// Forced scaling (Universal & Hidden Avatar)
|
||||
internal float _targetHeight = -1;
|
||||
internal Vector3 _targetScale = Vector3.one;
|
||||
internal float _scaleFactor = 1f;
|
||||
|
||||
// detection for animation clip-based scaling
|
||||
internal Vector3 _legacyAnimationScale;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// AnimationClip-based scaling (Local Avatar)
|
||||
internal float _animatedHeight;
|
||||
internal Vector3 _animatedScale;
|
||||
internal float _animatedScaleFactor = 1f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Events
|
||||
|
||||
public virtual void OnAvatarInstantiated(GameObject avatarObject, float initialHeight, Vector3 initialScale)
|
||||
{
|
||||
if (_isAvatarInstantiated) return;
|
||||
_isAvatarInstantiated = true;
|
||||
|
||||
_initialHeight = Mathf.Clamp(initialHeight, 0.01f, 100f);
|
||||
_initialScale = initialScale;
|
||||
_initialHeight = _animatedHeight = Mathf.Clamp(initialHeight, 0.01f, 100f);
|
||||
_initialScale = _animatedScale = initialScale;
|
||||
_animatedScaleFactor = 1f;
|
||||
|
||||
if (!_shouldForceHeight) // not universal or hidden avatar
|
||||
{
|
||||
_targetHeight = _initialHeight;
|
||||
_targetScale = _initialScale;
|
||||
_scaleFactor = 1f;
|
||||
}
|
||||
|
||||
_avatarTransform = avatarObject.transform;
|
||||
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
FindComponentsOfType(scalableComponentTypes);
|
||||
|
||||
stopwatch.Stop();
|
||||
if (ModSettings.Debug_ComponentSearchTime.Value)
|
||||
AvatarScaleMod.Logger.Msg($"({typeof(LocalScaler)}) Component search time for {avatarObject}: {stopwatch.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
public void OnAvatarDestroyed()
|
||||
{
|
||||
if (!_isAvatarInstantiated) return;
|
||||
_isAvatarInstantiated = false;
|
||||
|
||||
|
||||
_avatarTransform = null;
|
||||
_heightNeedsUpdate = false;
|
||||
heightNeedsUpdate = false;
|
||||
ClearComponentLists();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public float GetInitialHeight() => _initialHeight;
|
||||
public float GetTargetHeight() => _targetHeight;
|
||||
public float GetAnimatedHeight() => _animatedHeight;
|
||||
public bool IsForcingHeight() => _shouldForceHeight;
|
||||
|
||||
public void SetTargetHeight(float height)
|
||||
{
|
||||
if (_isHeightAdjustedFromInitial
|
||||
&& Math.Abs(height - _targetHeight) < float.Epsilon)
|
||||
return;
|
||||
|
||||
if (height < float.Epsilon)
|
||||
{
|
||||
ResetHeight();
|
||||
ResetTargetHeight();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isHeightAdjustedFromInitial)
|
||||
_legacyAnimationScale = Vector3.zero;
|
||||
|
||||
_isHeightAdjustedFromInitial = true;
|
||||
|
||||
_targetHeight = Mathf.Clamp(height, AvatarScaleManager.MinHeight, AvatarScaleManager.MaxHeight);
|
||||
_heightNeedsUpdate = true;
|
||||
|
||||
UpdateScaleIfInstantiated();
|
||||
}
|
||||
|
||||
public void ResetHeight()
|
||||
{
|
||||
if (!_isHeightAdjustedFromInitial) return;
|
||||
_isHeightAdjustedFromInitial = false;
|
||||
|
||||
if (Math.Abs(_initialHeight - _targetHeight) < float.Epsilon)
|
||||
return;
|
||||
|
||||
_legacyAnimationScale = Vector3.zero;
|
||||
_scaleFactor = Mathf.Max(_targetHeight / _initialHeight, 0.01f); //safety
|
||||
_targetScale = _initialScale * _scaleFactor;
|
||||
|
||||
_targetHeight = _initialHeight;
|
||||
_heightNeedsUpdate = true;
|
||||
|
||||
UpdateScaleIfInstantiated();
|
||||
InvokeTargetHeightChanged();
|
||||
}
|
||||
|
||||
public float GetHeight() => _targetHeight;
|
||||
public float GetInitialHeight() => _initialHeight;
|
||||
public bool IsHeightAdjustedFromInitial() => _isHeightAdjustedFromInitial;
|
||||
public void ResetTargetHeight()
|
||||
{
|
||||
// if (Math.Abs(_initialHeight - _targetHeight) < float.Epsilon)
|
||||
// return; // no need to change, is close enough
|
||||
|
||||
useTargetHeight = false;
|
||||
|
||||
_targetHeight = _animatedHeight;
|
||||
_targetScale = _animatedScale;
|
||||
_scaleFactor = _animatedScaleFactor;
|
||||
|
||||
InvokeTargetHeightReset();
|
||||
}
|
||||
|
||||
public bool ApplyTargetHeight()
|
||||
{
|
||||
if (!_isAvatarInstantiated || _initialHeight == 0)
|
||||
return false;
|
||||
|
||||
if (_avatarTransform == null)
|
||||
return false;
|
||||
|
||||
heightNeedsUpdate = false;
|
||||
|
||||
ScaleAvatarRoot();
|
||||
UpdateAnimatorParameter();
|
||||
ApplyComponentScaling();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Private Methods
|
||||
|
||||
internal void ScaleAvatarRoot()
|
||||
private void ScaleAvatarRoot()
|
||||
{
|
||||
if (_avatarTransform == null) return;
|
||||
_avatarTransform.localScale = _targetScale;
|
||||
}
|
||||
|
||||
internal virtual void UpdateAnimatorParameter()
|
||||
|
||||
protected virtual void UpdateAnimatorParameter()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
internal void UpdateScaleIfInstantiated()
|
||||
{
|
||||
if (!_isAvatarInstantiated || _initialHeight == 0)
|
||||
return;
|
||||
|
||||
if (_avatarTransform == null)
|
||||
return;
|
||||
|
||||
_scaleFactor = Mathf.Max(_targetHeight / _initialHeight, 0.01f); //safety
|
||||
|
||||
_heightNeedsUpdate = false;
|
||||
_targetScale = _initialScale * _scaleFactor;
|
||||
|
||||
ScaleAvatarRoot();
|
||||
UpdateAnimatorParameter();
|
||||
ApplyComponentScaling();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
#region Unity Events
|
||||
|
||||
public virtual void LateUpdate()
|
||||
{
|
||||
if (!_isHeightAdjustedFromInitial)
|
||||
return;
|
||||
if (!_isAvatarInstantiated)
|
||||
return; // no avatar
|
||||
|
||||
if (!_isAvatarInstantiated)
|
||||
return;
|
||||
|
||||
ScaleAvatarRoot(); // override animationclip-based scaling
|
||||
if (!_shouldForceHeight)
|
||||
return; // not universal scaling or hidden avatar
|
||||
|
||||
ScaleAvatarRoot();
|
||||
}
|
||||
|
||||
internal virtual void OnDestroy()
|
||||
|
@ -169,13 +227,13 @@ public class BaseScaler : MonoBehaviour
|
|||
typeof(PositionConstraint),
|
||||
typeof(ScaleConstraint)
|
||||
};
|
||||
|
||||
private readonly List<ScaledLight> _scaledLights = new List<ScaledLight>();
|
||||
private readonly List<ScaledAudioSource> _scaledAudioSources = new List<ScaledAudioSource>();
|
||||
private readonly List<ScaledParentConstraint> _scaledParentConstraints = new List<ScaledParentConstraint>();
|
||||
private readonly List<ScaledPositionConstraint> _scaledPositionConstraints = new List<ScaledPositionConstraint>();
|
||||
private readonly List<ScaledScaleConstraint> _scaledScaleConstraints = new List<ScaledScaleConstraint>();
|
||||
|
||||
|
||||
private readonly List<ScaledLight> _scaledLights = new();
|
||||
private readonly List<ScaledAudioSource> _scaledAudioSources = new();
|
||||
private readonly List<ScaledParentConstraint> _scaledParentConstraints = new();
|
||||
private readonly List<ScaledPositionConstraint> _scaledPositionConstraints = new();
|
||||
private readonly List<ScaledScaleConstraint> _scaledScaleConstraints = new();
|
||||
|
||||
private void ClearComponentLists()
|
||||
{
|
||||
_scaledLights.Clear();
|
||||
|
@ -184,10 +242,9 @@ public class BaseScaler : MonoBehaviour
|
|||
_scaledPositionConstraints.Clear();
|
||||
_scaledScaleConstraints.Clear();
|
||||
}
|
||||
|
||||
internal async Task FindComponentsOfTypeAsync(Type[] types)
|
||||
|
||||
internal void FindComponentsOfType(Type[] types)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
var components = _avatarTransform.gameObject.GetComponentsInChildren<Component>(true);
|
||||
|
||||
foreach (Component component in components)
|
||||
|
@ -195,19 +252,12 @@ public class BaseScaler : MonoBehaviour
|
|||
if (this == null) break;
|
||||
if (component == null) continue;
|
||||
|
||||
tasks.Add(Task.Run(() =>
|
||||
{
|
||||
Type componentType = component.GetType();
|
||||
if (types.Contains(componentType))
|
||||
{
|
||||
AddScaledComponent(componentType, component);
|
||||
}
|
||||
}));
|
||||
Type componentType = component.GetType();
|
||||
if (types.Contains(componentType))
|
||||
AddScaledComponent(componentType, component);
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
|
||||
private void AddScaledComponent(Type type, Component component)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -229,7 +279,7 @@ public class BaseScaler : MonoBehaviour
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ApplyComponentScaling()
|
||||
{
|
||||
// UpdateLightScales(); // might break dps
|
||||
|
@ -273,6 +323,6 @@ public class BaseScaler : MonoBehaviour
|
|||
foreach (ScaledScaleConstraint scaleConstraint in _scaledScaleConstraints)
|
||||
scaleConstraint.Scale(_scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.UI;
|
||||
using ABI.CCK.Components;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -14,31 +13,23 @@ public class LocalScaler : BaseScaler
|
|||
{
|
||||
_animatorManager = GetComponentInParent<PlayerSetup>().animatorManager;
|
||||
|
||||
_heightNeedsUpdate = false;
|
||||
heightNeedsUpdate = false;
|
||||
_isAvatarInstantiated = false;
|
||||
_isHeightAdjustedFromInitial = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
public override async void OnAvatarInstantiated(GameObject avatarObject, float initialHeight, Vector3 initialScale)
|
||||
public override void OnAvatarInstantiated(GameObject avatarObject, float initialHeight, Vector3 initialScale)
|
||||
{
|
||||
if (avatarObject == null)
|
||||
return;
|
||||
|
||||
base.OnAvatarInstantiated(avatarObject, initialHeight, initialScale);
|
||||
await FindComponentsOfTypeAsync(scalableComponentTypes);
|
||||
|
||||
_targetHeight = initialHeight;
|
||||
_scaleFactor = 1f;
|
||||
|
||||
_isHeightAdjustedFromInitial = false;
|
||||
_legacyAnimationScale = Vector3.zero;
|
||||
}
|
||||
|
||||
internal override void UpdateAnimatorParameter()
|
||||
|
||||
protected override void UpdateAnimatorParameter()
|
||||
{
|
||||
if (_animatorManager == null)
|
||||
return;
|
||||
|
@ -49,14 +40,8 @@ public class LocalScaler : BaseScaler
|
|||
|
||||
public override void LateUpdate()
|
||||
{
|
||||
if (!_isHeightAdjustedFromInitial)
|
||||
return;
|
||||
|
||||
if (!_isAvatarInstantiated)
|
||||
return;
|
||||
|
||||
if (!CheckForAnimationScaleChange())
|
||||
ScaleAvatarRoot();
|
||||
base.LateUpdate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -65,30 +50,43 @@ public class LocalScaler : BaseScaler
|
|||
|
||||
private bool CheckForAnimationScaleChange()
|
||||
{
|
||||
if (_avatarTransform == null) return false;
|
||||
if (_avatarTransform == null)
|
||||
return false;
|
||||
|
||||
//scale matches last recorded animation scale
|
||||
if (_avatarTransform.localScale == _legacyAnimationScale)
|
||||
Vector3 localScale = _avatarTransform.localScale;
|
||||
|
||||
// scale matches last recorded animation scale
|
||||
if (localScale == _animatedScale)
|
||||
return false;
|
||||
|
||||
// avatar may not have scale animation, check if it isn't equal to targetScale
|
||||
if (_avatarTransform.localScale == _targetScale)
|
||||
if (localScale == _targetScale)
|
||||
return false;
|
||||
|
||||
// scale was likely reset or not initiated
|
||||
if (_legacyAnimationScale == Vector3.zero)
|
||||
// this is the first time we've seen the avatar animated scale, record it!
|
||||
if (_animatedScale == Vector3.zero)
|
||||
{
|
||||
_legacyAnimationScale = _avatarTransform.localScale;
|
||||
_animatedScale = localScale;
|
||||
return false;
|
||||
}
|
||||
|
||||
_legacyAnimationScale = _avatarTransform.localScale;
|
||||
// animation scale changed, record it!
|
||||
Vector3 scaleDifference = PlayerSetup.DivideVectors(localScale - _initialScale, _initialScale);
|
||||
_animatedScaleFactor = scaleDifference.y;
|
||||
_animatedHeight = (_initialHeight * _animatedScaleFactor) + _initialHeight;
|
||||
_animatedScale = localScale;
|
||||
InvokeAnimatedHeightChanged();
|
||||
|
||||
if (overrideAnimationHeight
|
||||
|| !useTargetHeight)
|
||||
return false; // user has disabled animation height override or is not using universal scaling
|
||||
|
||||
// animation scale changed and now will override universal scaling
|
||||
ResetTargetHeight();
|
||||
InvokeAnimatedHeightOverride();
|
||||
|
||||
AvatarScaleMod.Logger.Msg("AnimationClip-based avatar scaling detected. Disabling Universal Scaling.");
|
||||
CohtmlHud.Instance.ViewDropTextImmediate("(Local) AvatarScaleMod", "Avatar Scale Changed!", "Universal Scaling is now disabled in favor of built-in avatar scaling.");
|
||||
AvatarScaleManager.Instance.ResetHeight(); // disable mod, user used a scale slider
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using System.Diagnostics;
|
||||
using ABI_RC.Core.Player;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -16,28 +17,34 @@ public class NetworkScaler : BaseScaler
|
|||
|
||||
_animatorManager = GetComponentInParent<PuppetMaster>().animatorManager;
|
||||
|
||||
_heightNeedsUpdate = false;
|
||||
heightNeedsUpdate = false;
|
||||
_isAvatarInstantiated = false;
|
||||
_isHeightAdjustedFromInitial = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
public override async void OnAvatarInstantiated(GameObject avatarObject, float initialHeight, Vector3 initialScale)
|
||||
public override void OnAvatarInstantiated(GameObject avatarObject, float initialHeight, Vector3 initialScale)
|
||||
{
|
||||
if (avatarObject == null)
|
||||
return;
|
||||
|
||||
base.OnAvatarInstantiated(avatarObject, initialHeight, initialScale);
|
||||
await FindComponentsOfTypeAsync(scalableComponentTypes);
|
||||
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
FindComponentsOfType(scalableComponentTypes);
|
||||
stopwatch.Stop();
|
||||
if (ModSettings.Debug_ComponentSearchTime.Value)
|
||||
AvatarScaleMod.Logger.Msg($"({typeof(NetworkScaler)}) Component search time for {avatarObject}: {stopwatch.ElapsedMilliseconds}ms");
|
||||
|
||||
if (_isHeightAdjustedFromInitial && _heightNeedsUpdate)
|
||||
UpdateScaleIfInstantiated();
|
||||
// TODO: why did i do this? height is never set prior to this method being called
|
||||
// if (_isHeightAdjustedFromInitial && heightNeedsUpdate)
|
||||
// UpdateScaleIfInstantiated();
|
||||
}
|
||||
|
||||
internal override void UpdateAnimatorParameter()
|
||||
|
||||
protected override void UpdateAnimatorParameter()
|
||||
{
|
||||
_animatorManager?.SetAnimatorParameter(ScaleFactorParameterNameLocal, _scaleFactor);
|
||||
}
|
||||
|
|
105
AvatarScale/AvatarScaling/Events/AvatarScaleEvents.cs
Normal file
105
AvatarScale/AvatarScaling/Events/AvatarScaleEvents.cs
Normal file
|
@ -0,0 +1,105 @@
|
|||
using NAK.AvatarScaleMod.Components;
|
||||
|
||||
namespace NAK.AvatarScaleMod.AvatarScaling;
|
||||
|
||||
public static class AvatarScaleEvents
|
||||
{
|
||||
#region Local Avatar Scaling Events
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the local avatar's height changes for any reason.
|
||||
/// </summary>
|
||||
public static readonly AvatarScaleEvent<LocalScaler> OnLocalAvatarHeightChanged = new();
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the local avatar's animated height changes.
|
||||
/// </summary>
|
||||
public static readonly AvatarScaleEvent<LocalScaler> OnLocalAvatarAnimatedHeightChanged = new();
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the local avatar's target height changes.
|
||||
/// </summary>
|
||||
public static readonly AvatarScaleEvent<LocalScaler> OnLocalAvatarTargetHeightChanged = new();
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the local avatar's height is reset.
|
||||
/// </summary>
|
||||
public static readonly AvatarScaleEvent<LocalScaler> OnLocalAvatarHeightReset = new();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Avatar Scaling Events
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a remote avatar's height changes.
|
||||
/// </summary>
|
||||
public static readonly AvatarScaleEvent<string, NetworkScaler> OnRemoteAvatarHeightChanged = new();
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a remote avatar's height is reset.
|
||||
/// </summary>
|
||||
public static readonly AvatarScaleEvent<string, NetworkScaler> OnRemoteAvatarHeightReset = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Classes
|
||||
|
||||
public class AvatarScaleEvent<T>
|
||||
{
|
||||
private Action<T> _listener = arg => { };
|
||||
|
||||
public void AddListener(Action<T> listener) => _listener += listener;
|
||||
public void RemoveListener(Action<T> listener) => _listener -= listener;
|
||||
|
||||
public void Invoke(T arg)
|
||||
{
|
||||
var invokeList = _listener.GetInvocationList();
|
||||
foreach (Delegate method in invokeList)
|
||||
{
|
||||
if (method is not Action<T> action)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
action(arg);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AvatarScaleMod.Logger.Error($"Unable to invoke listener, an exception was thrown and not handled: {e}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AvatarScaleEvent<T1, T2>
|
||||
{
|
||||
private Action<T1, T2> _listener = (arg1, arg2) => { };
|
||||
|
||||
public void AddListener(Action<T1, T2> listener) => _listener += listener;
|
||||
public void RemoveListener(Action<T1, T2> listener) => _listener -= listener;
|
||||
|
||||
public void Invoke(T1 arg1, T2 arg2)
|
||||
{
|
||||
var invokeList = _listener.GetInvocationList();
|
||||
foreach (Delegate method in invokeList)
|
||||
{
|
||||
if (method is not Action<T1, T2> action)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
action(arg1, arg2);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AvatarScaleMod.Logger.Error($"Unable to invoke listener, an exception was thrown and not handled: {e}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -48,7 +48,6 @@ public class ScaledLight
|
|||
public void Reset()
|
||||
{
|
||||
Component.range = InitialRange;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ internal class PlayerSetupPatches
|
|||
{
|
||||
try
|
||||
{
|
||||
if (__instance == null) return; // this is called when the game is closed
|
||||
AvatarScaleManager.Instance.OnAvatarDestroyed(__instance);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -80,6 +81,7 @@ internal class PuppetMasterPatches
|
|||
{
|
||||
try
|
||||
{
|
||||
if (__instance == null) return; // this is called when the game is closed
|
||||
AvatarScaleManager.Instance.OnNetworkAvatarDestroyed(__instance);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -30,14 +30,14 @@ internal static class DebugKeybinds
|
|||
{
|
||||
float currentHeight = AvatarScaleManager.Instance.GetHeight() + adjustment;
|
||||
currentHeight = Mathf.Max(0f, currentHeight);
|
||||
AvatarScaleManager.Instance.SetHeight(currentHeight);
|
||||
AvatarScaleManager.Instance.SetTargetHeight(currentHeight);
|
||||
|
||||
AvatarScaleMod.Logger.Msg($"[Debug] Setting height: {currentHeight}");
|
||||
}
|
||||
|
||||
private static void ResetHeight()
|
||||
{
|
||||
AvatarScaleManager.Instance.ResetHeight();
|
||||
AvatarScaleManager.Instance.ResetTargetHeight();
|
||||
AvatarScaleMod.Logger.Msg("[Debug] Resetting height.");
|
||||
}
|
||||
}
|
|
@ -92,7 +92,7 @@ public static class ScaleReconizer
|
|||
float heightAdjustmentFactor = (modifierRatio > 1) ? 1 + (modifierRatio - 1) : 1 - (1 - modifierRatio);
|
||||
|
||||
// Apply the adjustment to the target height
|
||||
AvatarScaleManager.Instance.SetHeight(_initialTargetHeight * heightAdjustmentFactor);
|
||||
AvatarScaleManager.Instance.SetTargetHeight(_initialTargetHeight * heightAdjustmentFactor);
|
||||
}
|
||||
|
||||
private static void OnScaleEnd(float modifier, Transform transform1, Transform transform2)
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.IO;
|
||||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using MelonLoader;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static class BtkUiAddon
|
||||
{
|
||||
private static string _selectedPlayer;
|
||||
|
||||
#region Initialization
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
PrepareIcons();
|
||||
SetupRootPage();
|
||||
SetupPlayerSelectPage();
|
||||
RegisterEventHandlers();
|
||||
}
|
||||
|
||||
private static void PrepareIcons()
|
||||
{
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "ASM_Icon_AvatarHeightConfig", GetIconStream("ASM_Icon_AvatarHeightConfig.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "ASM_Icon_AvatarHeightCopy", GetIconStream("ASM_Icon_AvatarHeightCopy.png"));
|
||||
}
|
||||
|
||||
private static void SetupRootPage()
|
||||
{
|
||||
// we only need the page, as we inject our own elements into it aa
|
||||
Page rootPage = new Page(ModSettings.ModName, ModSettings.SettingsCategory, true, "ASM_Icon_AvatarHeightConfig")
|
||||
{
|
||||
MenuTitle = ModSettings.SettingsCategory,
|
||||
MenuSubtitle = "Universal Scaling Settings"
|
||||
};
|
||||
}
|
||||
|
||||
private static void SetupPlayerSelectPage()
|
||||
{
|
||||
// what other things would be worth adding here?
|
||||
Category category = QuickMenuAPI.PlayerSelectPage.AddCategory(ModSettings.SettingsCategory, ModSettings.ModName);
|
||||
Button button = category.AddButton("Copy Height", "ASM_Icon_AvatarHeightCopy", "Copy selected players Eye Height.");
|
||||
button.OnPress += OnCopyPlayerHeight;
|
||||
}
|
||||
|
||||
private static void RegisterEventHandlers()
|
||||
{
|
||||
QuickMenuAPI.OnPlayerSelected += (_, id) => _selectedPlayer = id;
|
||||
QuickMenuAPI.OnMenuRegenerate += _ => ScheduleMenuInjection();
|
||||
QuickMenuAPI.OnTabChange += OnTabChange;
|
||||
}
|
||||
|
||||
private static void ScheduleMenuInjection()
|
||||
{
|
||||
CVR_MenuManager.Instance.quickMenu.View.BindCall("asm-AvatarHeightUpdated", new Action<float>(OnAvatarHeightUpdated));
|
||||
SchedulerSystem.AddJob(InjectMenu, 1f, 1f, 1);
|
||||
}
|
||||
|
||||
private static void InjectMenu()
|
||||
{
|
||||
AvatarScaleMod.Logger.Msg("Injecting into our BTKUI AvatarScaleMod page!");
|
||||
string menuJsPath = Path.Combine(Application.streamingAssetsPath, "Cohtml", "UIResources", "AvatarScaleMod", "menu.js");
|
||||
string menuJsContent = File.Exists(menuJsPath) ? File.ReadAllText(menuJsPath) : string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(menuJsContent))
|
||||
{
|
||||
AvatarScaleMod.Logger.Msg("Injecting embedded menu.js included with mod!");
|
||||
CVR_MenuManager.Instance.quickMenu.View._view.ExecuteScript(Scripts.GetEmbeddedScript("menu.js"));
|
||||
}
|
||||
else
|
||||
{
|
||||
AvatarScaleMod.Logger.Msg($"Injecting development menu.js found in: {menuJsPath}");
|
||||
CVR_MenuManager.Instance.quickMenu.View._view.ExecuteScript(menuJsContent);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void OnCopyPlayerHeight()
|
||||
{
|
||||
float networkHeight = AvatarScaleManager.Instance.GetNetworkHeight(_selectedPlayer);
|
||||
if (networkHeight < 0) return;
|
||||
AvatarScaleManager.Instance.SetHeight(networkHeight);
|
||||
}
|
||||
|
||||
private static void OnAvatarHeightUpdated(float height)
|
||||
{
|
||||
AvatarScaleManager.Instance.SetHeight(height);
|
||||
}
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static DateTime lastTime = DateTime.Now;
|
||||
private static void OnTabChange(string newTab, string previousTab)
|
||||
{
|
||||
if (newTab == "btkUI-AvatarScaleMod-MainPage")
|
||||
{
|
||||
TimeSpan timeDifference = DateTime.Now - lastTime;
|
||||
if (timeDifference.TotalSeconds <= 0.5)
|
||||
{
|
||||
AvatarScaleManager.Instance.ResetHeight();
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastTime = DateTime.Now;
|
||||
}
|
||||
|
||||
private static Stream GetIconStream(string iconName)
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
string assemblyName = assembly.GetName().Name;
|
||||
return assembly.GetManifestResourceStream($"{assemblyName}.resources.{iconName}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Melon Pref Helpers
|
||||
|
||||
internal static void AddMelonToggle(ref Category category, MelonPreferences_Entry<bool> entry)
|
||||
{
|
||||
category.AddToggle(entry.DisplayName, entry.Description, entry.Value).OnValueUpdated += b => entry.Value = b;
|
||||
}
|
||||
|
||||
internal static void AddMelonSlider(ref Page page, MelonPreferences_Entry<float> entry, float min, float max, int decimalPlaces = 2)
|
||||
{
|
||||
page.AddSlider(entry.DisplayName, entry.Description, entry.Value, min, max, decimalPlaces).OnValueUpdated += f => entry.Value = f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
100
AvatarScale/Integrations/BTKUI/BtkUiAddon.cs
Normal file
100
AvatarScale/Integrations/BTKUI/BtkUiAddon.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static Page _asmRootPage;
|
||||
private static string _rootPageElementID;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Prepare_Icons();
|
||||
Setup_AvatarScaleModTab();
|
||||
Setup_PlayerSelectPage();
|
||||
}
|
||||
|
||||
#region Initialization
|
||||
|
||||
private static void Prepare_Icons()
|
||||
{
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "ASM_Icon_AvatarHeightConfig",
|
||||
GetIconStream("ASM_Icon_AvatarHeightConfig.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "ASM_Icon_AvatarHeightCopy",
|
||||
GetIconStream("ASM_Icon_AvatarHeightCopy.png"));
|
||||
}
|
||||
|
||||
private static void Setup_AvatarScaleModTab()
|
||||
{
|
||||
_asmRootPage = new Page(ModSettings.ModName, ModSettings.ASM_SettingsCategory, true, "ASM_Icon_AvatarHeightConfig")
|
||||
{
|
||||
MenuTitle = ModSettings.ASM_SettingsCategory,
|
||||
MenuSubtitle = "Everything Avatar Scaling!"
|
||||
};
|
||||
|
||||
_rootPageElementID = _asmRootPage.ElementID;
|
||||
QuickMenuAPI.OnTabChange += OnTabChange;
|
||||
QuickMenuAPI.UserJoin += OnUserJoinLeave;
|
||||
QuickMenuAPI.UserLeave += OnUserJoinLeave;
|
||||
QuickMenuAPI.OnWorldLeave += OnWorldLeave;
|
||||
|
||||
// Avatar Scale Mod
|
||||
Setup_AvatarScaleModCategory(_asmRootPage);
|
||||
|
||||
// Avatar Scale Tool
|
||||
Setup_AvatarScaleToolCategory(_asmRootPage);
|
||||
|
||||
// Universal Scaling Settings
|
||||
Setup_UniversalScalingSettings(_asmRootPage);
|
||||
|
||||
// Debug Options
|
||||
Setup_DebugOptionsCategory(_asmRootPage);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Player Count Display
|
||||
|
||||
private static void OnWorldLeave()
|
||||
=> UpdatePlayerCountDisplay();
|
||||
|
||||
private static void OnUserJoinLeave(CVRPlayerEntity _)
|
||||
=> UpdatePlayerCountDisplay();
|
||||
|
||||
private static void UpdatePlayerCountDisplay()
|
||||
{
|
||||
if (_asmRootPage == null)
|
||||
return;
|
||||
|
||||
int modUserCount = AvatarScaleManager.Instance.GetNetworkHeightScalerCount();
|
||||
int playerCount = CVRPlayerManager.Instance.NetworkPlayers.Count;
|
||||
_asmRootPage.MenuSubtitle = $"Everything Avatar Scaling! :: ({modUserCount}/{playerCount} players using ASM)";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Double-Click Reset Height
|
||||
|
||||
private static DateTime lastTime = DateTime.Now;
|
||||
|
||||
private static void OnTabChange(string newTab, string previousTab)
|
||||
{
|
||||
if (newTab == _rootPageElementID)
|
||||
{
|
||||
UpdatePlayerCountDisplay();
|
||||
TimeSpan timeDifference = DateTime.Now - lastTime;
|
||||
if (timeDifference.TotalSeconds <= 0.5)
|
||||
{
|
||||
AvatarScaleManager.Instance.ResetTargetHeight();
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastTime = DateTime.Now;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using BTKUILib.UIObjects;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static void Setup_AvatarScaleModCategory(Page page)
|
||||
{
|
||||
Category avScaleModCategory = AddMelonCategory(ref page, ModSettings.Hidden_Foldout_ASM_SettingsCategory);
|
||||
|
||||
AddMelonToggle(ref avScaleModCategory, ModSettings.EntryScaleGestureEnabled);
|
||||
AddMelonToggle(ref avScaleModCategory, ModSettings.EntryScaleKeybindingsEnabled);
|
||||
AddMelonToggle(ref avScaleModCategory, ModSettings.EntryPersistentHeight);
|
||||
AddMelonToggle(ref avScaleModCategory, ModSettings.EntryPersistThroughRestart);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static void Setup_AvatarScaleToolCategory(Page page)
|
||||
{
|
||||
Category avScaleToolCategory = AddMelonCategory(ref page, ModSettings.Hidden_Foldout_AST_SettingsCategory);
|
||||
|
||||
AddMelonStringInput(ref avScaleToolCategory, ModSettings.EntryASTScaleParameter, "icon");
|
||||
AddMelonNumberInput(ref avScaleToolCategory, ModSettings.EntryASTMinHeight, "icon");
|
||||
AddMelonNumberInput(ref avScaleToolCategory, ModSettings.EntryASTMaxHeight, "icon");
|
||||
avScaleToolCategory.AddButton("Reset Overrides", "", "Reset to Avatar Scale Tool default values.", ButtonStyle.TextOnly)
|
||||
.OnPress += () =>{
|
||||
ModSettings.EntryASTScaleParameter.ResetToDefault();
|
||||
ModSettings.EntryASTMinHeight.ResetToDefault();
|
||||
ModSettings.EntryASTMaxHeight.ResetToDefault();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using BTKUILib.UIObjects;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static void Setup_DebugOptionsCategory(Page page)
|
||||
{
|
||||
Category debugCategory = AddMelonCategory(ref page, ModSettings.Hidden_Foldout_DEBUG_SettingsCategory);
|
||||
|
||||
AddMelonToggle(ref debugCategory, ModSettings.Debug_NetworkInbound);
|
||||
AddMelonToggle(ref debugCategory, ModSettings.Debug_NetworkOutbound);
|
||||
AddMelonToggle(ref debugCategory, ModSettings.Debug_ComponentSearchTime);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
using System.Collections.Generic; // Added for list support
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static readonly List<QMUIElement> USM_QmUiElements = new();
|
||||
|
||||
private static void Setup_UniversalScalingSettings(Page page)
|
||||
{
|
||||
Category uniScalingCategory = AddMelonCategory(ref page, ModSettings.Hidden_Foldout_USM_SettingsCategory);
|
||||
|
||||
SliderFloat scaleSlider = AddMelonSlider(ref uniScalingCategory, ModSettings.EntryHiddenAvatarHeight, AvatarScaleManager.DefaultMinHeight, AvatarScaleManager.DefaultMaxHeight);
|
||||
|
||||
Button resetHeightButton = uniScalingCategory.AddButton(ModSettings.EntryUseUniversalScaling.DisplayName, "icon", ModSettings.EntryUseUniversalScaling.Description, ButtonStyle.TextOnly);
|
||||
resetHeightButton.OnPress += () =>
|
||||
{
|
||||
if (ModSettings.EntryUseUniversalScaling.Value)
|
||||
{
|
||||
ModSettings.EntryUseUniversalScaling.Value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
QuickMenuAPI.ShowConfirm("Use Universal Scaling?",
|
||||
"Universal scaling only works when other users also have the mod! Are you sure you want to use Universal Scaling?",
|
||||
() => ModSettings.EntryUseUniversalScaling.Value = true);
|
||||
};
|
||||
|
||||
// Elements that should be disabled when universal scaling is disabled
|
||||
USM_QmUiElements.AddRange(new QMUIElement[]
|
||||
{
|
||||
scaleSlider,
|
||||
AddMelonToggle(ref uniScalingCategory, ModSettings.EntryScaleComponents),
|
||||
AddMelonToggle(ref uniScalingCategory, ModSettings.EntryAnimationScalingOverride)
|
||||
});
|
||||
|
||||
// Events for the slider
|
||||
scaleSlider.OnValueUpdated += OnAvatarHeightSliderChanged;
|
||||
scaleSlider.OnSliderReset += OnAvatarHeightSliderReset;
|
||||
AvatarScaleEvents.OnLocalAvatarAnimatedHeightChanged.AddListener((scaler) =>
|
||||
{
|
||||
scaleSlider.SetSliderValue(scaler.GetTargetHeight());
|
||||
scaleSlider.DefaultValue = scaler.GetAnimatedHeight();
|
||||
});
|
||||
|
||||
// Initial values
|
||||
OnUniversalScalingChanged(ModSettings.EntryUseUniversalScaling.Value);
|
||||
ModSettings.EntryUseUniversalScaling.OnEntryValueChanged.Subscribe((_, newValue) => OnUniversalScalingChanged(newValue));
|
||||
}
|
||||
|
||||
private static void OnUniversalScalingChanged(bool value)
|
||||
{
|
||||
foreach (QMUIElement uiElement in USM_QmUiElements)
|
||||
uiElement.Disabled = !value;
|
||||
}
|
||||
|
||||
#region Slider Events
|
||||
|
||||
private static void OnAvatarHeightSliderChanged(float height)
|
||||
{
|
||||
AvatarScaleManager.Instance.SetTargetHeight(height);
|
||||
}
|
||||
|
||||
private static void OnAvatarHeightSliderReset()
|
||||
{
|
||||
AvatarScaleManager.Instance.ResetTargetHeight();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static Button _playerHasModElement;
|
||||
private static string _selectedPlayer;
|
||||
|
||||
private static void Setup_PlayerSelectPage()
|
||||
{
|
||||
QuickMenuAPI.OnPlayerSelected += OnPlayerSelected;
|
||||
|
||||
Category category = QuickMenuAPI.PlayerSelectPage.AddCategory(ModSettings.ASM_SettingsCategory, ModSettings.ModName);
|
||||
|
||||
_playerHasModElement = category.AddButton("PLAYER_HAS_MOD", "ASM_Icon_AvatarHeightCopy", "PLAYER_HAS_MOD_TOOLTIP");
|
||||
|
||||
Button button = category.AddButton("Copy Height", "ASM_Icon_AvatarHeightCopy", "Copy selected players Eye Height.");
|
||||
button.OnPress += OnCopyPlayerHeight;
|
||||
}
|
||||
|
||||
#region QM Events
|
||||
|
||||
private static void OnPlayerSelected(string _, string id)
|
||||
{
|
||||
_selectedPlayer = id;
|
||||
UpdatePlayerHasModIcon();
|
||||
}
|
||||
|
||||
private static void OnCopyPlayerHeight()
|
||||
{
|
||||
float networkHeight = AvatarScaleManager.Instance.GetNetworkHeight(_selectedPlayer);
|
||||
if (networkHeight < 0) return;
|
||||
AvatarScaleManager.Instance.SetTargetHeight(networkHeight);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void UpdatePlayerHasModIcon()
|
||||
{
|
||||
if (_playerHasModElement == null)
|
||||
return;
|
||||
|
||||
if (AvatarScaleManager.Instance.DoesNetworkHeightScalerExist(_selectedPlayer))
|
||||
{
|
||||
_playerHasModElement.ButtonIcon = "ASM_Icon_AvatarHeightCopy";
|
||||
_playerHasModElement.ButtonText = "Player Has Mod";
|
||||
_playerHasModElement.ButtonTooltip = "This player has the Avatar Scale Mod installed!";
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerHasModElement.ButtonIcon = "ASM_Icon_AvatarHeightConfig";
|
||||
_playerHasModElement.ButtonText = "Player Does Not Have Mod";
|
||||
_playerHasModElement.ButtonTooltip = "This player does not have the Avatar Scale Mod installed!";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
78
AvatarScale/Integrations/BTKUI/BtkUiAddon_Utils.cs
Normal file
78
AvatarScale/Integrations/BTKUI/BtkUiAddon_Utils.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System.Reflection;
|
||||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AvatarScaleMod.Integrations
|
||||
{
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
#region Melon Preference Helpers
|
||||
|
||||
private static ToggleButton AddMelonToggle(ref Category category, MelonPreferences_Entry<bool> entry)
|
||||
{
|
||||
ToggleButton toggle = category.AddToggle(entry.DisplayName, entry.Description, entry.Value);
|
||||
toggle.OnValueUpdated += b => entry.Value = b;
|
||||
return toggle;
|
||||
}
|
||||
|
||||
private static SliderFloat AddMelonSlider(ref Category category, MelonPreferences_Entry<float> entry, float min,
|
||||
float max, int decimalPlaces = 2, bool allowReset = true)
|
||||
{
|
||||
SliderFloat slider = category.AddSlider(entry.DisplayName, entry.Description,
|
||||
Mathf.Clamp(entry.Value, min, max), min, max, decimalPlaces, entry.DefaultValue, allowReset);
|
||||
slider.OnValueUpdated += f => entry.Value = f;
|
||||
return slider;
|
||||
}
|
||||
|
||||
private static Button AddMelonStringInput(ref Category category, MelonPreferences_Entry<string> entry, string buttonIcon = "", ButtonStyle buttonStyle = ButtonStyle.TextOnly)
|
||||
{
|
||||
Button button = category.AddButton(entry.DisplayName, buttonIcon, entry.Description, buttonStyle);
|
||||
button.OnPress += () => QuickMenuAPI.OpenKeyboard(entry.Value, s => entry.Value = s);
|
||||
return button;
|
||||
}
|
||||
|
||||
private static Button AddMelonNumberInput(ref Category category, MelonPreferences_Entry<float> entry, string buttonIcon = "", ButtonStyle buttonStyle = ButtonStyle.TextOnly)
|
||||
{
|
||||
Button button = category.AddButton(entry.DisplayName, buttonIcon, entry.Description, buttonStyle);
|
||||
button.OnPress += () => QuickMenuAPI.OpenNumberInput(entry.DisplayName, entry.Value, f => entry.Value = f);
|
||||
return button;
|
||||
}
|
||||
|
||||
// private static SliderFloat AddMelonSlider(ref Page page, MelonPreferences_Entry<float> entry, float min, float max, int decimalPlaces = 2, bool allowReset = true)
|
||||
// {
|
||||
// SliderFloat slider = page.AddSlider(entry.DisplayName, entry.Description, Mathf.Clamp(entry.Value, min, max), min, max, decimalPlaces, entry.DefaultValue, allowReset);
|
||||
// slider.OnValueUpdated += f => entry.Value = f;
|
||||
// return slider;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to create a category that saves its collapsed state to a MelonPreferences entry.
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="entry"></param>
|
||||
/// <param name="showHeader"></param>
|
||||
/// <returns></returns>
|
||||
private static Category AddMelonCategory(ref Page page, MelonPreferences_Entry<bool> entry, bool showHeader = true)
|
||||
{
|
||||
Category category = page.AddCategory(entry.DisplayName, showHeader, true, entry.Value);
|
||||
category.OnCollapse += b => entry.Value = b;
|
||||
return category;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Icon Utils
|
||||
|
||||
private static Stream GetIconStream(string iconName)
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
string assemblyName = assembly.GetName().Name;
|
||||
return assembly.GetManifestResourceStream($"{assemblyName}.resources.{iconName}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -10,43 +10,113 @@ internal static class ModSettings
|
|||
{
|
||||
// Constants
|
||||
internal const string ModName = nameof(AvatarScaleMod);
|
||||
internal const string SettingsCategory = "Avatar Scale Mod";
|
||||
|
||||
public static readonly MelonPreferences_Category Category =
|
||||
internal const string ASM_SettingsCategory = "Avatar Scale Mod";
|
||||
internal const string AST_SettingsCategory = "Avatar Scale Tool Support";
|
||||
internal const string USM_SettingsCategory = "Universal Scaling (Mod Network)";
|
||||
internal const string DEBUG_SettingsCategory = "Debug Options";
|
||||
|
||||
private static readonly MelonPreferences_Category Category =
|
||||
MelonPreferences.CreateCategory(ModName);
|
||||
|
||||
#region Hidden Foldout Entries
|
||||
|
||||
// Avatar Scale Mod Foldout
|
||||
internal static readonly MelonPreferences_Entry<bool> Hidden_Foldout_ASM_SettingsCategory =
|
||||
Category.CreateEntry("hidden_foldout_asm", true, is_hidden: true, display_name: ASM_SettingsCategory, description: "Foldout state for Avatar Scale Mod settings.");
|
||||
|
||||
// Avatar Scale Tool Foldout
|
||||
internal static readonly MelonPreferences_Entry<bool> Hidden_Foldout_AST_SettingsCategory =
|
||||
Category.CreateEntry("hidden_foldout_ast", false, is_hidden: true, display_name: AST_SettingsCategory, description: "Foldout state for Avatar Scale Tool settings.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryUseUniversalScaling =
|
||||
Category.CreateEntry("use_universal_scaling", true, display_name: "Use Universal Scaling", description: "Enable or disable universal scaling.");
|
||||
// Universal Scaling (Mod Network) Foldout
|
||||
internal static readonly MelonPreferences_Entry<bool> Hidden_Foldout_USM_SettingsCategory =
|
||||
Category.CreateEntry("hidden_foldout_usm", false, is_hidden: true, display_name: USM_SettingsCategory, description: "Foldout state for Universal Scaling (Mod Network) settings.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryPersistantHeight =
|
||||
Category.CreateEntry("persistant_height", false, display_name: "Persistant Height", description: "Should the avatar height persist between avatar switches?");
|
||||
// Debug Options Foldout
|
||||
internal static readonly MelonPreferences_Entry<bool> Hidden_Foldout_DEBUG_SettingsCategory =
|
||||
Category.CreateEntry("hidden_foldout_debug", false, is_hidden: true, display_name: DEBUG_SettingsCategory, description: "Foldout state for Debug Options settings.");
|
||||
|
||||
// Player Select Page Foldout
|
||||
internal static readonly MelonPreferences_Entry<bool> Hidden_Foldout_PlayerSelectPage =
|
||||
Category.CreateEntry("hidden_foldout_player_select_page", true, is_hidden: true, display_name: ASM_SettingsCategory, description: "Foldout state for Player Select Page.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Scale Mod Settings
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryScaleGestureEnabled =
|
||||
Category.CreateEntry("scale_gesture_enabled", true, display_name: "Scale Gesture Enabled", description: "Enable or disable scale gesture.");
|
||||
Category.CreateEntry("scale_gesture_enabled", true, display_name: "Scale Gesture", description: "Enable or disable scale gesture.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryDebugNetworkInbound =
|
||||
public static readonly MelonPreferences_Entry<bool> EntryScaleKeybindingsEnabled =
|
||||
Category.CreateEntry("scale_keybindings_enabled", true, display_name: "Scale Keybindings", description: "Enable or disable scale keybindings.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryPersistentHeight =
|
||||
Category.CreateEntry("persistent_height", false, display_name: "Persistent Height", description: "Should the avatar height persist between avatar switches?");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryPersistThroughRestart =
|
||||
Category.CreateEntry("persistent_height_through_restart", false, display_name: "Persist Through Restart", description: "Should the avatar height persist between game restarts?");
|
||||
|
||||
// stores the last avatar height as a melon pref
|
||||
public static readonly MelonPreferences_Entry<float> EntryHiddenAvatarHeight =
|
||||
Category.CreateEntry("hidden_avatar_height", -2f, is_hidden: true, display_name: "Avatar Height", description: "Set your avatar height.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Scale Tool Settings
|
||||
|
||||
public static readonly MelonPreferences_Entry<string> EntryASTScaleParameter =
|
||||
Category.CreateEntry("override_scale_parameter", "AvatarScale", display_name: "Override Scale Parameter", description: "Override the scale parameter on the avatar.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<float> EntryASTMinHeight =
|
||||
Category.CreateEntry("override_min_height", 0.25f, display_name: "Override Min Height", description: "Override the minimum height.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<float> EntryASTMaxHeight =
|
||||
Category.CreateEntry("override_max_height", 2.5f, display_name: "Override Max Height", description: "Override the maximum height.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Universal Scaling Settings
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryUseUniversalScaling =
|
||||
Category.CreateEntry("use_universal_scaling", false, display_name: "Use Universal Scaling", description: "Enable or disable universal scaling. This allows scaling to work on any avatar as well as networking via Mod Network.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryScaleComponents =
|
||||
Category.CreateEntry("scale_components", true, display_name: "Scale Components", description: "Scale components on the avatar. (Constraints, Audio Sources, etc.)");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryAnimationScalingOverride =
|
||||
Category.CreateEntry("allow_anim_clip_scale_override", true, display_name: "Animation-Clip Scaling Override", description: "Allow animation-clip scaling to override universal scaling.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Debug Settings
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> Debug_NetworkInbound =
|
||||
Category.CreateEntry("debug_inbound", false, display_name: "Debug Inbound", description: "Log inbound Mod Network height updates.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryDebugNetworkOutbound =
|
||||
public static readonly MelonPreferences_Entry<bool> Debug_NetworkOutbound =
|
||||
Category.CreateEntry("debug_outbound", false, display_name: "Debug Outbound", description: "Log outbound Mod Network height updates.");
|
||||
|
||||
public static readonly MelonPreferences_Entry<float> EntryHiddenLastAvatarScale =
|
||||
Category.CreateEntry("last_avatar_scale", -1f, is_hidden: true);
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> Debug_ComponentSearchTime =
|
||||
Category.CreateEntry("debug_component_search_time", false, display_name: "Debug Search Time", description: "Log component search time.");
|
||||
|
||||
#endregion
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
foreach (MelonPreferences_Entry entry in Category.Entries)
|
||||
entry.OnEntryValueChangedUntyped.Subscribe(OnSettingsChanged);
|
||||
// subscribe to all bool settings that aren't hidden
|
||||
foreach (MelonPreferences_Entry entry in Category.Entries.Where(entry => entry.GetReflectedType() == typeof(bool) && !entry.IsHidden))
|
||||
entry.OnEntryValueChangedUntyped.Subscribe(OnSettingsBoolChanged);
|
||||
}
|
||||
|
||||
private static void OnSettingsChanged(object _, object __)
|
||||
private static void OnSettingsBoolChanged(object _, object __)
|
||||
{
|
||||
AvatarScaleManager.Instance.Setting_UniversalScaling = EntryUseUniversalScaling.Value;
|
||||
AvatarScaleManager.Instance.Setting_PersistantHeight = EntryPersistantHeight.Value;
|
||||
|
||||
GestureReconizer.ScaleReconizer.Enabled = EntryScaleGestureEnabled.Value;
|
||||
ModNetwork.Debug_NetworkInbound = Debug_NetworkInbound.Value;
|
||||
ModNetwork.Debug_NetworkOutbound = Debug_NetworkOutbound.Value;
|
||||
|
||||
ModNetwork.Debug_NetworkInbound = EntryDebugNetworkInbound.Value;
|
||||
ModNetwork.Debug_NetworkOutbound = EntryDebugNetworkOutbound.Value;
|
||||
if (AvatarScaleManager.Instance == null) return;
|
||||
AvatarScaleManager.Instance.Setting_UniversalScaling = EntryUseUniversalScaling.Value;
|
||||
AvatarScaleManager.Instance.Setting_AnimationClipScalingOverride = EntryAnimationScalingOverride.Value;
|
||||
AvatarScaleManager.Instance.Setting_PersistentHeight = EntryPersistentHeight.Value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
using ABI_RC.Core.Networking;
|
||||
using ABI_RC.Systems.ModNetwork;
|
||||
using DarkRift;
|
||||
using MelonLoader;
|
||||
using NAK.AvatarScaleMod.AvatarScaling;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -32,7 +31,7 @@ public static class ModNetwork
|
|||
public string TargetPlayer { get; set; }
|
||||
public string Sender { get; set; }
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private State
|
||||
|
@ -62,10 +61,15 @@ public static class ModNetwork
|
|||
|
||||
internal static void Subscribe()
|
||||
{
|
||||
_isSubscribedToModNetwork = true;
|
||||
ModNetworkManager.Subscribe(ModId, OnMessageReceived);
|
||||
|
||||
_isSubscribedToModNetwork = ModNetworkManager.IsSubscribed(ModId);
|
||||
if (!_isSubscribedToModNetwork)
|
||||
AvatarScaleMod.Logger.Error("Failed to subscribe to Mod Network! This is a critical error! Please report this to the mod author! (NAK) (ModNetwork.cs) (Subscribe) (Line 150) (AvatarScaleMod) (AvatarScale) (MelonLoader) (MelonLoader.Mods) (MelonLoader.Mods.MelonMod) (MelonLoader.MelonMod) (MelonLoader.MelonMod.MelonBaseMod) (MelonLoader.MelonMod.MelonMod) (MelonLoader.MelonMod.MelonModBase) (MelonLoader.MelonMod.MelonModBase`1) (MelonLoader.MelonMod.MelonModBase`1[[NAK.AvatarScaleMod.AvatarScaling.AvatarScaleMod, NAK.AvatarScaleMod, Version=123");
|
||||
|
||||
AvatarScaleEvents.OnLocalAvatarHeightChanged.AddListener(scaler => SendNetworkHeight(scaler.GetTargetHeight()));
|
||||
}
|
||||
|
||||
|
||||
internal static void Update()
|
||||
{
|
||||
if (!_isSubscribedToModNetwork)
|
||||
|
@ -244,4 +248,36 @@ public static class ModNetwork
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Messages
|
||||
|
||||
private class AvatarHeightMessage
|
||||
{
|
||||
public float Height { get; set; }
|
||||
public bool IsUniversal { get; set; }
|
||||
}
|
||||
|
||||
private static void AddAvatarHeightMessageConverter()
|
||||
{
|
||||
ModNetworkMessage.AddConverter(Reader, Writer);
|
||||
return;
|
||||
|
||||
AvatarHeightMessage Reader(ModNetworkMessage msg)
|
||||
{
|
||||
AvatarHeightMessage avatarHeightMessage = new();
|
||||
msg.Read(out float height);
|
||||
avatarHeightMessage.Height = height;
|
||||
msg.Read(out bool isUniversal);
|
||||
avatarHeightMessage.IsUniversal = isUniversal;
|
||||
return avatarHeightMessage;
|
||||
}
|
||||
|
||||
void Writer(ModNetworkMessage msg, AvatarHeightMessage value)
|
||||
{
|
||||
msg.Write(value.Height);
|
||||
msg.Write(value.IsUniversal);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue