forked from nikita/muzika-gromche
				
			
		
			
				
	
	
		
			73 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections;
 | |
| using HarmonyLib;
 | |
| using TMPro;
 | |
| using UnityEngine;
 | |
| 
 | |
| namespace MuzikaGromche
 | |
| {
 | |
|     static class DeathScreenGameOverTextManager
 | |
|     {
 | |
|         private const string GameOverTextVanilla = "[LIFE SUPPORT: OFFLINE]";
 | |
| 
 | |
|         public const string GameOverTextModdedDefault = "[ MUZIKA: GROMCHE ]";
 | |
| 
 | |
|         public static void Clear()
 | |
|         {
 | |
|             SetTextImpl(GameOverTextVanilla);
 | |
|         }
 | |
| 
 | |
|         public static void SetText(string? text)
 | |
|         {
 | |
|             SetTextImpl(text ?? GameOverTextModdedDefault);
 | |
|         }
 | |
| 
 | |
|         public static IEnumerator SetTextAndClear(string? text)
 | |
|         {
 | |
|             SetText(text);
 | |
|             // Game Over animation duration is about 4.25 seconds
 | |
|             yield return new WaitForSeconds(5f);
 | |
|             Clear();
 | |
|         }
 | |
| 
 | |
|         private static void SetTextImpl(string text)
 | |
|         {
 | |
|             GameObject textGameObject = GameObject.Find("Systems/UI/Canvas/DeathScreen/GameOverText");
 | |
|             if (textGameObject == null)
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
|             TextMeshProUGUI tmp = textGameObject.GetComponent<TextMeshProUGUI>();
 | |
|             if (tmp == null)
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
|             var transform = textGameObject.GetComponent<RectTransform>();
 | |
|             if (transform == null)
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
|             // Default transform width is 645.8 which only fit the default message and no extra characters
 | |
|             Vector2 size = transform.sizeDelta;
 | |
|             if (Mathf.Approximately(size.x, 645.8f))
 | |
|             {
 | |
|                 size.x += 100f;
 | |
|                 transform.sizeDelta = size;
 | |
|             }
 | |
|             tmp.text = text;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     [HarmonyPatch(typeof(RoundManager))]
 | |
|     static class DeathScreenGameOverTextResetPatch
 | |
|     {
 | |
|         [HarmonyPatch(nameof(RoundManager.DespawnPropsAtEndOfRound))]
 | |
|         [HarmonyPatch(nameof(RoundManager.OnDestroy))]
 | |
|         [HarmonyPrefix]
 | |
|         static void OnDestroy(RoundManager __instance)
 | |
|         {
 | |
|             var _ = __instance;
 | |
|             DeathScreenGameOverTextManager.Clear();
 | |
|         }
 | |
|     }
 | |
| }
 |