Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
now uses nameplate opacity setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tetra-fox committed Jul 16, 2021
1 parent ed4ba57 commit 4ed9256
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
18 changes: 18 additions & 0 deletions ProPlates/Components/OpacityListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using UnityEngine;

namespace ProPlates.Components
{
public class OpacityListener : MonoBehaviour
{
public OpacityListener(IntPtr ptr) : base(ptr) {}
public ImageThreeSlice reference;
public ImageThreeSlice target;

private void Update()
{
if (target.color == reference.color) return;
target.color = reference.color;
}
}
}
4 changes: 4 additions & 0 deletions ProPlates/ProPlates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<Reference Include="UnityEngine.UI">
<HintPath>$(MelonLoaderPath)\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>H:\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="VRC.SDKBase.Editor.BuildPipeline">
<HintPath>H:\Steam\steamapps\common\VRChat\MelonLoader\Managed\VRC.SDKBase.Editor.BuildPipeline.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -136,6 +139,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Components\OpacityListener.cs" />
<Compile Include="ProPlatesMod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProPlatesSettings.cs" />
Expand Down
27 changes: 19 additions & 8 deletions ProPlates/ProPlatesMod.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using MelonLoader;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using ProPlates.Components;
using TMPro;
using UnhollowerRuntimeLib;
using UnityEngine;
using VRC;
using Array = System.Array;
using Object = UnityEngine.Object;
using StringComparer = System.StringComparer;

namespace ProPlates
{
public static class BuildInfo
{
public const string Name = "ProPlates";
public const string Author = "tetra";
public const string Version = "1.1.0";
public const string Version = "1.1.1";
public const string DownloadLink = "https://github.com/tetra-fox/VRCMods";
}

Expand All @@ -31,12 +34,15 @@ public override void OnApplicationStart()
MelonLogger.Msg("Registering settings...");
Settings.Register();
Settings.OnConfigChanged += ReloadPronouns;

MelonLogger.Msg("Registering components...");
ClassInjector.RegisterTypeInIl2Cpp<OpacityListener>();

MelonLogger.Msg("Loading pronoun table...");
using Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(BuildInfo.Name + ".pronouns.csv");

// pronoun table sourced from https://github.com/witch-house/pronoun.is/blob/master/resources/pronouns.tab
_pronounTable = new StreamReader(s).ReadToEnd().Split(',', '\n');
_pronounTable = new StreamReader(s!).ReadToEnd().Split(',', '\n');

// BIG LIST, it's *probably* fine
foreach (string p1 in _pronounTable)
Expand Down Expand Up @@ -69,23 +75,28 @@ private static void MakePlate(Player player, string text)
if (Settings.MaxPronouns.Value < 1) return;

PlayerNameplate nameplate = player._vrcplayer.field_Public_PlayerNameplate_0;
if (nameplate.transform.Find("Contents/ProPlates Container")) return;

MelonLogger.Msg("Setting pronouns for {0}", player.prop_APIUser_0.displayName);

Transform pronounPlate = Object.Instantiate(nameplate.transform.Find("Contents/Quick Stats"),
nameplate.transform.Find("Contents"), false);

if (nameplate.transform.Find("Contents/Pronouns Container")) return;
MelonLogger.Msg("Setting pronouns for {0}", player.prop_APIUser_0.displayName);

pronounPlate.name = "Pronouns Container";
pronounPlate.name = "ProPlates Container";
pronounPlate.localPosition = new Vector3(0f, -60f, 0f); // y coordinate is in increments of 30, yes i'm aware the avatar DL progress covers this
pronounPlate.gameObject.active = true;

OpacityListener opacityListener = pronounPlate.gameObject.AddComponent<OpacityListener>();
opacityListener.reference = nameplate.transform.Find("Contents/Main/Background").GetComponent<ImageThreeSlice>();
opacityListener.target = pronounPlate.gameObject.GetComponent<ImageThreeSlice>();

// remove unnecessary gameobjects and set pronoun text
for (int i = pronounPlate.childCount; i > 0; i--)
{
Transform c = pronounPlate.GetChild(i - 1);
if (c.name == "Trust Text")
{
c.name = "Pronouns Text";
c.name = "Text";
c.GetComponent<TextMeshProUGUI>().text = text;
c.GetComponent<TextMeshProUGUI>().color = Color.white;
continue;
Expand Down

0 comments on commit 4ed9256

Please sign in to comment.