mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-02 20:24:26 -07:00
Initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FistVR;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
public class HoldCounter : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
transform.parent = GameObject.Find("_NewTAHReticle/TAHReticle_HealthBar").transform;
|
||||
transform.localPosition = new Vector3(-1f, 0, -.5f);
|
||||
transform.localRotation = Quaternion.Euler(90, 0, 0);
|
||||
transform.localScale = new Vector3(0.002f, 0.002f, 0.002f);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
string display = "";
|
||||
if (InPlay.tnhManager.ProgressionMode == TNHSetting_ProgressionType.Marathon)
|
||||
display = string.Format("{0} / ∞", InPlay.tnhManager.m_level);
|
||||
else
|
||||
display = string.Format("{0} / {1}", InPlay.tnhManager.m_level, InPlay.tnhManager.m_maxLevels);
|
||||
|
||||
transform.GetChild(1).GetComponent<Text>().text = display;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 326e8d2367ceda54b967f0b1125e6d80
|
||||
timeCreated: 1642908727
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FistVR;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
/// <summary>
|
||||
/// Code here should only be run when in TNH play.
|
||||
/// </summary>
|
||||
public class InPlay : MonoBehaviour
|
||||
{
|
||||
private GameObject gObjHUD;
|
||||
private GameObject gObjTokens;
|
||||
public static TNH_Manager tnhManager;
|
||||
|
||||
#region INITIALIZATION
|
||||
void ImproveHPTextReadability()
|
||||
{
|
||||
var canvas = gObjHUD.GetComponent<Canvas>();
|
||||
var gObjBG = new GameObject();
|
||||
var tranHPTitle = gObjHUD.transform.Find("Label_Title (1)");
|
||||
var tranHP = gObjHUD.transform.Find("Label_Title");
|
||||
|
||||
// apply background
|
||||
if (MeatKitPlugin.showHPBackground.Value)
|
||||
{
|
||||
gObjBG.transform.parent = gObjHUD.transform;
|
||||
gObjBG.transform.SetSiblingIndex(0);
|
||||
gObjBG.transform.localPosition = new Vector3(0, 1, 0);
|
||||
gObjBG.transform.localRotation = Quaternion.identity;
|
||||
gObjBG.transform.localScale = tranHP.localScale;
|
||||
var rawImage = gObjBG.AddComponent<RawImage>();
|
||||
rawImage.color = new Color(0, 0, 0, MeatKitPlugin.hpBackgroundOpacity.Value);
|
||||
rawImage.rectTransform.SetWidth(100);
|
||||
rawImage.rectTransform.SetHeight(52);
|
||||
}
|
||||
|
||||
// full text alphas
|
||||
tranHPTitle.GetComponent<Text>().color = Color.white;
|
||||
tranHP.GetComponent<Text>().color = Color.white;
|
||||
// text shadows
|
||||
var shadow = tranHPTitle.gameObject.AddComponent<Shadow>();
|
||||
shadow.effectColor = new Color(0, 0, 0, .95f);
|
||||
shadow.effectDistance = new Vector2(0.5f, -0.5f);
|
||||
shadow = tranHP.gameObject.AddComponent<Shadow>();
|
||||
shadow.effectColor = new Color(0, 0, 0, .95f);
|
||||
shadow.effectDistance = new Vector2(0.5f, -0.5f);
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
tnhManager = GameObject.Find("_GameManager").GetComponent<TNH_Manager>();
|
||||
gObjHUD = GameObject.Find("HealthBar(Clone)/f");
|
||||
|
||||
ImproveHPTextReadability();
|
||||
if (MeatKitPlugin.showTokens.Value)
|
||||
Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("TokenCounter"));
|
||||
if (MeatKitPlugin.showHolds.Value)
|
||||
Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("HoldCounter"));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe22950149f00884eadae4da41fa5ee3
|
||||
timeCreated: 1642761823
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using BepInEx.Bootstrap;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FistVR;
|
||||
using RUST.Steamworks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
public class LeaderboardPlayerCount : MonoBehaviour
|
||||
{
|
||||
private bool initialized = false;
|
||||
private bool tnhTweakerInstalled = false;
|
||||
|
||||
private string curID;
|
||||
|
||||
private TNH_ScoreDisplay scoreDisplay;
|
||||
private Text lblGlobalScores;
|
||||
private GameObject gObjLoading;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Debug.Log("--- Installed BepInEx Plugins ---");
|
||||
foreach (var plugin in Chainloader.PluginInfos)
|
||||
{
|
||||
Debug.Log(plugin.Key);
|
||||
}
|
||||
Debug.Log("--- End Plugins ---");
|
||||
}
|
||||
|
||||
public void Init(TNH_ScoreDisplay tnhScore, Text scoreLabel, GameObject gObjLoading)
|
||||
{
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
this.scoreDisplay = tnhScore;
|
||||
this.lblGlobalScores = scoreLabel;
|
||||
this.lblGlobalScores.resizeTextForBestFit = true;
|
||||
this.lblGlobalScores.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
this.gObjLoading = gObjLoading;
|
||||
|
||||
var loadedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
|
||||
if (Array.Exists<Assembly>(loadedAssemblies, x => x.GetName().Name == "TakeAndHoldTweaker"))
|
||||
{
|
||||
tnhTweakerInstalled = true;
|
||||
this.gObjLoading.transform.GetChild(0).GetComponent<Text>().text = "<color=lightblue>Online leaderboards player count is incompatible with TNHTweaker.</color>";
|
||||
this.gObjLoading.SetActive(true);
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!initialized || tnhTweakerInstalled)
|
||||
return;
|
||||
|
||||
string newID = scoreDisplay.m_curSequenceID;
|
||||
if (newID != curID)
|
||||
UpdatePlayerCountDisplay(newID);
|
||||
}
|
||||
|
||||
private void UpdatePlayerCountDisplay(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
string playerCountText = Steamworks.SteamUserStats
|
||||
.GetLeaderboardEntryCount(HighScoreManager.Leaderboards[id])
|
||||
.ToString("N0");
|
||||
lblGlobalScores.text = "Global Scores: <color=lightblue>(" + playerCountText + " players)</color>";
|
||||
curID = id;
|
||||
gObjLoading.SetActive(false);
|
||||
}
|
||||
catch (KeyNotFoundException e)
|
||||
{
|
||||
lblGlobalScores.text = "Global Scores:";
|
||||
gObjLoading.SetActive(true);
|
||||
curID = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5ac26e534584c84babdbf9380fec1c9
|
||||
timeCreated: 1642852455
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,58 @@
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FistVR;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class LeaderboardPlayerCountPatch
|
||||
{
|
||||
Harmony harmony;
|
||||
private static GameObject gObjLoading;
|
||||
private static Text uiGlobalText;
|
||||
|
||||
public LeaderboardPlayerCountPatch()
|
||||
{
|
||||
harmony = new Harmony("me.muskit.TNHQualityOfLifeImprovements.LeaderboardPlayerCount");
|
||||
harmony.PatchAll();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TNH_ScoreDisplay), "Start")]
|
||||
public static void Setup(TNH_ScoreDisplay __instance)
|
||||
{
|
||||
GameObject gObjLeaderboard = null;
|
||||
gObjLoading = GameObject.Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("PlayerCount_LoadingText"));
|
||||
if (__instance.gameObject.name == "_MainMenu") // lobby
|
||||
{
|
||||
gObjLeaderboard = __instance.transform.GetChild(3).gameObject; // MainMenuCanvas_RightFar
|
||||
gObjLoading.transform.SetParent(gObjLeaderboard.transform, false);
|
||||
gObjLoading.GetComponent<RectTransform>().pivot = new Vector2(0, 1);
|
||||
gObjLoading.transform.localPosition = new Vector3(520, 380, 0);
|
||||
gObjLoading.transform.GetChild(0).GetComponent<Text>().alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
if (__instance.gameObject.name == "_FinalScoreDisplay(Clone)") // game over room
|
||||
{
|
||||
gObjLeaderboard = __instance.transform.GetChild(0).gameObject; // ScoreCanvas_PastScores
|
||||
gObjLoading.transform.SetParent(gObjLeaderboard.transform, false);
|
||||
gObjLoading.GetComponent<RectTransform>().pivot = new Vector2(1, 1);
|
||||
gObjLoading.transform.localPosition = new Vector3(-520, 380, 0);
|
||||
gObjLoading.transform.GetChild(0).GetComponent<Text>().alignment = TextAnchor.UpperRight;
|
||||
}
|
||||
uiGlobalText = gObjLeaderboard.transform.GetChild(0).GetChild(2).GetComponent<Text>();
|
||||
gObjLoading.transform.rotation = gObjLeaderboard.transform.rotation;
|
||||
gObjLoading.transform.GetChild(0).GetComponent<Text>().font = uiGlobalText.font;
|
||||
|
||||
var playerCountComponent = gObjLeaderboard.AddComponent<LeaderboardPlayerCount>();
|
||||
playerCountComponent.Init(__instance, uiGlobalText, gObjLoading);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TNH_ScoreDisplay), "SwitchToModeID")]
|
||||
public static void OnModeIDSwitch_Post(string id, TNH_ScoreDisplay __instance)
|
||||
{
|
||||
Debug.Log(string.Format("Changing scoreboard mode to {0}!", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e36ded23fd7c7b40acf6063a3a8c3db
|
||||
timeCreated: 1642841022
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
public class TokenCounter : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
transform.parent = GameObject.Find("_NewTAHReticle/TAHReticle_HealthBar").transform;
|
||||
transform.localPosition = new Vector3(1, 0, -.5f);
|
||||
transform.localRotation = Quaternion.Euler(90, 0, 0);
|
||||
transform.localScale = new Vector3(0.002f, 0.002f, 0.002f);
|
||||
|
||||
StartCoroutine(SetTokenImage());
|
||||
}
|
||||
|
||||
private IEnumerator SetTokenImage()
|
||||
{
|
||||
int debug_iterations = 0;
|
||||
Sprite tokenSprite = null;
|
||||
while (tokenSprite == null) // END: loop until Token sprite is found
|
||||
{
|
||||
var obj = GameObject.Find("_TNH_ObjectConstructor(Clone)/_CanvasHolder/_UITest_Canvas/Icon_0/Cost_1/Image");
|
||||
if (obj != null)
|
||||
{
|
||||
tokenSprite = obj.GetComponent<Image>().sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug_iterations++;
|
||||
yield return new WaitForSeconds(0.25f);
|
||||
}
|
||||
}
|
||||
Debug.Log("Token sprite found after " + debug_iterations.ToString() + " iterations.");
|
||||
transform.GetChild(0).GetComponent<Image>().sprite = tokenSprite;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
int tokens = InPlay.tnhManager.GetNumTokens();
|
||||
transform.GetChild(1).GetComponent<Text>().text = tokens.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3224502095ea8c64bb61578336e0ae1b
|
||||
timeCreated: 1642908735
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static class _RectTransformExtensions
|
||||
{
|
||||
public static void SetDefaultScale(this RectTransform trans)
|
||||
{
|
||||
trans.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
public static void SetPivotAndAnchors(this RectTransform trans, Vector2 aVec)
|
||||
{
|
||||
trans.pivot = aVec;
|
||||
trans.anchorMin = aVec;
|
||||
trans.anchorMax = aVec;
|
||||
}
|
||||
|
||||
public static Vector2 GetSize(this RectTransform trans)
|
||||
{
|
||||
return trans.rect.size;
|
||||
}
|
||||
public static float GetWidth(this RectTransform trans)
|
||||
{
|
||||
return trans.rect.width;
|
||||
}
|
||||
public static float GetHeight(this RectTransform trans)
|
||||
{
|
||||
return trans.rect.height;
|
||||
}
|
||||
|
||||
public static void SetPositionOfPivot(this RectTransform trans, Vector2 newPos)
|
||||
{
|
||||
trans.localPosition = new Vector3(newPos.x, newPos.y, trans.localPosition.z);
|
||||
}
|
||||
|
||||
public static void SetLeftBottomPosition(this RectTransform trans, Vector2 newPos)
|
||||
{
|
||||
trans.localPosition = new Vector3(newPos.x + (trans.pivot.x * trans.rect.width), newPos.y + (trans.pivot.y * trans.rect.height), trans.localPosition.z);
|
||||
}
|
||||
public static void SetLeftTopPosition(this RectTransform trans, Vector2 newPos)
|
||||
{
|
||||
trans.localPosition = new Vector3(newPos.x + (trans.pivot.x * trans.rect.width), newPos.y - ((1f - trans.pivot.y) * trans.rect.height), trans.localPosition.z);
|
||||
}
|
||||
public static void SetRightBottomPosition(this RectTransform trans, Vector2 newPos)
|
||||
{
|
||||
trans.localPosition = new Vector3(newPos.x - ((1f - trans.pivot.x) * trans.rect.width), newPos.y + (trans.pivot.y * trans.rect.height), trans.localPosition.z);
|
||||
}
|
||||
public static void SetRightTopPosition(this RectTransform trans, Vector2 newPos)
|
||||
{
|
||||
trans.localPosition = new Vector3(newPos.x - ((1f - trans.pivot.x) * trans.rect.width), newPos.y - ((1f - trans.pivot.y) * trans.rect.height), trans.localPosition.z);
|
||||
}
|
||||
|
||||
public static void SetSize(this RectTransform trans, Vector2 newSize)
|
||||
{
|
||||
Vector2 oldSize = trans.rect.size;
|
||||
Vector2 deltaSize = newSize - oldSize;
|
||||
trans.offsetMin = trans.offsetMin - new Vector2(deltaSize.x * trans.pivot.x, deltaSize.y * trans.pivot.y);
|
||||
trans.offsetMax = trans.offsetMax + new Vector2(deltaSize.x * (1f - trans.pivot.x), deltaSize.y * (1f - trans.pivot.y));
|
||||
}
|
||||
public static void SetWidth(this RectTransform trans, float newSize)
|
||||
{
|
||||
SetSize(trans, new Vector2(newSize, trans.rect.size.y));
|
||||
}
|
||||
public static void SetHeight(this RectTransform trans, float newSize)
|
||||
{
|
||||
SetSize(trans, new Vector2(trans.rect.size.x, newSize));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2738f251e64b4104f94dd7e0907680af
|
||||
timeCreated: 1642904567
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user