Skip to content

Commit

Permalink
# Changelog
Browse files Browse the repository at this point in the history
- Fixed Nameplate Rotation
- Enable with QM works thanks to CVR update
- Ratelimit default updated to 2
- Optimized Settings updates

# Known Issues
- Nameplate colors do not update immedietely, requiring a reload. *strings do not call value change event*
  • Loading branch information
fs-sys committed Oct 11, 2022
1 parent 061eb18 commit f04dd1d
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 179 deletions.
343 changes: 190 additions & 153 deletions VRCPlates/MonoScripts/OldNameplate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Networking.IO.Social;
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
Expand Down Expand Up @@ -420,181 +421,217 @@ public void ApplySettings()

if (Player != null)
{
if (Player.PlayerDescriptor.TryGetComponent<PuppetMaster>(out var puppetMaster))
{
var animator = puppetMaster.GetAnimator();
OnScaleUpdate();

if (Settings.Scale != null)
{
var scaleValue = Settings.Scale.Value * .001f;
if (_transform != null) _transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);
}
OnOffsetUpdate();

if (Settings.Offset != null)
{
if (animator != null && animator.isHuman)
{
_headTransform = animator.GetBoneTransform(HumanBodyBones.Head);
}
else
{
_headTransform = puppetMaster.voicePosition!.transform;
}
OnModernMovementToggle();

var pos = Player.PuppetMaster.GetNamePlatePosition(Settings.Offset.Value);
if (_transform != null)
{
_transform.position = pos;
}
}
OnShowRankToggle();

if (Settings.ModernMovement is {Value: true})
{
if (_constraint == null)
{
_constraint = Nameplate.AddComponent<PositionConstraint>();
VRCPlates.Error("[0000] Constraint is null, forcefully adding it.");
}
OnShowPfpToggle();

if (_constraint.sourceCount > 1)
{
VRCPlates.Error("[0001] Constraint.sourceCount is greater than 1, resetting...");
_constraint.SetSources(null);
}
OnVoiceBubbleToggle();

if (_constraint.sourceCount == 1)
{
if (_constraint.GetSource(0).sourceTransform == null)
{
VRCPlates.Debug("[0002] Removing Null Constraint Source");
_constraint.RemoveSource(0);
}
}
OnPlateColorUpdate();

if (_constraint.sourceCount < 1)
{
_constraint.AddSource(new ConstraintSource
{
sourceTransform = _headTransform,
weight = 1
});
}
}

if (Settings.Offset != null)
{
if (_constraint != null)
{
_constraint.translationOffset = new Vector3(0f, Settings.Offset.Value, 0f);
if (Settings.ModernMovement != null)
_constraint.constraintActive = Settings.ModernMovement.Value;
}
}

IsFriend = Friends.FriendsWith(Player.Uuid);

if (Settings.ShowRank != null)
if (_rankText != null && Player != null)
{
// ShowSocialRank = player.field_Private_APIUser_0.showSocialRank;
Rank = Player.ApiUserRank;
}
OnNameColorUpdate();

var showPfp = MetaPort.Instance.settings.GetSettingInt("GeneralNameplatesImageVisibility");
if (((showPfp == 1 && IsFriend) || showPfp == 2) && ProfilePicture != "" &&
ProfilePicture != "https://files.abidata.io/user_images/00default.png")
{
if (_userPlate != null)
_userPlate.gameObject.SetActive(true);
}
else
{
if (_userPlate != null)
_userPlate.gameObject.SetActive(false);
}
IsFriend = Friends.FriendsWith(Player.Uuid);

if (Settings.ShowVoiceBubble != null)
if (_voiceBubble != null)
_voiceBubble.gameObject.SetActive(Settings.ShowVoiceBubble.Value &&
Player?.TalkerAmplitude > 0f);
OnVisibilityUpdate();
}
else
{
VRCPlates.Error("[0006] Player is null, cannot apply settings.");
}
}
catch (Exception e)
{
VRCPlates.Error("[0003] Unable to Apply Nameplate Settings:\n" + e);
}
}

if (Settings.PlateColor != null && Settings.PlateColorByRank != null &&
Settings.BtkColorPlates != null)
{
if (Settings.BtkColorPlates.Value)
{
PlateColor = Utils.GetColourFromUserID(Player?.Uuid ?? "00000000-0000-0000-0000-000000000000");
}
else
{
if (Settings.PlateColorByRank.Value)
{
PlateColor = Utils.GetColorForSocialRank(Player?.ApiUserRank ?? "User");
}
else
{
if (ColorUtility.TryParseHtmlString(Settings.PlateColor.Value, out var color))
PlateColor = color;
else
{
PlateColor = Color.green;
Settings.PlateColor.Value = "#00FF00";
VRCPlates.DebugError("Invalid color string for nameplate color.");
}
}
}
}
public void OnVisibilityUpdate()
{
var nameplateSetting = MetaPort.Instance.settings.GetSettingInt("GeneralNameplatesVisibility");
if (!MetaPort.Instance.worldEnableNameplates || nameplateSetting == 2 ||
(nameplateSetting == 1 && !ViewManager.Instance.isGameMenuOpen()))
{
Nameplate!.SetActive(false);
}
else
{
Nameplate!.SetActive(true);
}

if (Settings.NameColor == null || Settings.NameColorByRank == null ||
Settings.BtkColorNames == null) return;
{
if (Settings.BtkColorNames.Value)
{
NameColor = Utils.GetColourFromUserID(Player?.Uuid ?? "00000000-0000-0000-0000-000000000000");
}
else
{
if (Settings.NameColorByRank.Value)
{
NameColor = Utils.GetColorForSocialRank(Player?.ApiUserRank ?? "User");
}
else
{
if (ColorUtility.TryParseHtmlString(Settings.NameColor.Value, out var color))
NameColor = color;
else
{
NameColor = Color.white;
Settings.NameColor.Value = "#FFFFFF";
VRCPlates.DebugError("Invalid color string for name color.");
}
}
}
}
Nameplate!.SetActive(Settings.Enabled is {Value: true});
}

if (MetaPort.Instance.settings.GetSettingsBool("GeneralShowNameplates") &&
MetaPort.Instance.worldEnableNameplates)
{
Nameplate.SetActive(true);
}
else
{
Nameplate.SetActive(false);
}
public void OnNameColorUpdate()
{
if (Settings.BtkColorNames is {Value: true})
{
NameColor = Utils.GetColourFromUserID(Player.Uuid ?? "00000000-0000-0000-0000-000000000000");
}
else
{
if (Settings.NameColorByRank is {Value: true})
{
NameColor = Utils.GetColorForSocialRank(Player.ApiUserRank ?? "User");
}
else
{
if (Settings.NameColor != null &&
ColorUtility.TryParseHtmlString(Settings.NameColor.Value, out var color))
NameColor = color;
else
{
NameColor = Color.white;
if (Settings.NameColor != null) Settings.NameColor.Value = "#FFFFFF";
VRCPlates.DebugError("Invalid color string for name color.");
}
}
}
}

public void OnPlateColorUpdate()
{
if (Settings.BtkColorPlates is {Value: true})
{
PlateColor = Utils.GetColourFromUserID(Player.Uuid ?? "00000000-0000-0000-0000-000000000000");
}
else
{
if (Settings.PlateColorByRank is {Value: true})
{
PlateColor = Utils.GetColorForSocialRank(Player.ApiUserRank ?? "User");
}
else
{
if (Settings.PlateColor != null && ColorUtility.TryParseHtmlString(Settings.PlateColor.Value, out var color))
PlateColor = color;
else
{
VRCPlates.Error("[0005] PuppetMaster is null, cannot apply settings.");
PlateColor = Color.green;
if (Settings.PlateColor != null) Settings.PlateColor.Value = "#00FF00";
VRCPlates.DebugError("Invalid color string for nameplate color.");
}
}
}
}

public void OnVoiceBubbleToggle()
{
if (Settings.ShowVoiceBubble == null) return;
if (_voiceBubble != null)
_voiceBubble.gameObject.SetActive(Settings.ShowVoiceBubble.Value &&
Player.TalkerAmplitude > 0f);
}

public void OnShowPfpToggle()
{
var showPfp = MetaPort.Instance.settings.GetSettingInt("GeneralNameplatesImageVisibility");
if ((showPfp == 0 || (showPfp == 1 && IsFriend)) && ProfilePicture != "" &&
ProfilePicture != "https://files.abidata.io/user_images/00default.png")
{
if (_userPlate != null)
_userPlate.gameObject.SetActive(true);
}
else
{
if (_userPlate != null)
_userPlate.gameObject.SetActive(false);
}
}

public void OnShowRankToggle()
{
if (Settings.ShowRank != null)
if (_rankText != null && Player != null)
{
// ShowSocialRank = player.field_Private_APIUser_0.showSocialRank;
Rank = Player.ApiUserRank;
}
}

public void OnOffsetUpdate()
{
if (Settings.Offset == null) return;

if (Player.PlayerDescriptor.TryGetComponent<PuppetMaster>(out var puppetMaster))
{
var animator = puppetMaster.GetAnimator();

if (animator != null && animator.isHuman)
{
_headTransform = animator.GetBoneTransform(HumanBodyBones.Head);
}
else
{
VRCPlates.Error("[0006] Player is null, cannot apply settings.");
_headTransform = puppetMaster.voicePosition!.transform;
}

var pos = Player.PuppetMaster.GetNamePlatePosition(Settings.Offset.Value);
if (_transform != null)
{
_transform.position = pos;
}
}
catch (Exception e)
else
{
VRCPlates.Error("[0003] Unable to Apply Nameplate Settings:\n" + e);
VRCPlates.Error("PuppetMaster is null, cannot apply offset.");
}
}

public void OnScaleUpdate()
{
if (Settings.Scale != null)
{
var scaleValue = Settings.Scale.Value * .001f;
if (_transform != null) _transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);
}
}

public void OnModernMovementToggle()
{
if (Settings.ModernMovement is not {Value: true}) return;
if (Settings.Offset == null) return;

if (_constraint == null)
{
_constraint = Nameplate!.AddComponent<PositionConstraint>();
VRCPlates.Error("[0000] Constraint is null, forcefully adding it.");
}

if (_constraint.sourceCount > 1)
{
VRCPlates.Error("[0001] Constraint.sourceCount is greater than 1, resetting...");
_constraint.SetSources(null);
}

if (_constraint.sourceCount == 1)
{
if (_constraint.GetSource(0).sourceTransform == null)
{
VRCPlates.Debug("[0002] Removing Null Constraint Source");
_constraint.RemoveSource(0);
}
}

if (_constraint.sourceCount < 1)
{
_constraint.AddSource(new ConstraintSource
{
sourceTransform = _headTransform,
weight = 1
});
}

if (_constraint != null)
{
_constraint.translationOffset = new Vector3(0f, Settings.Offset.Value, 0f);
_constraint.constraintActive = Settings.ModernMovement.Value;
}
}
}
Loading

0 comments on commit f04dd1d

Please sign in to comment.