mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-19 15:51:58 +00:00
110 lines
4.0 KiB
C#
110 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using EHR.Patches;
|
|
using Rewired.Utils;
|
|
using UnityEngine;
|
|
|
|
namespace EHR.Modules;
|
|
|
|
internal static class LoadingScreen
|
|
{
|
|
private const int HintCount = 40;
|
|
private const int JokeHintCount = 6;
|
|
private static Camera Camera;
|
|
private static SpriteRenderer LoadingAnimation;
|
|
private static readonly HashSet<int> ToldHints = [];
|
|
private static float HintHideTimer;
|
|
public static string Hint;
|
|
|
|
private static void UpdateLoadingAnimation()
|
|
{
|
|
try
|
|
{
|
|
if (!LoadingAnimation.IsNullOrDestroyed()) Object.Destroy(LoadingAnimation);
|
|
|
|
LoadingAnimation = Object.Instantiate(ModManager.Instance.ModStamp);
|
|
LoadingAnimation.sprite = Utils.LoadSprite("EHR.Resources.Loading.png", 300f);
|
|
LoadingAnimation.sortingOrder = 100;
|
|
|
|
Camera = HudManager.Instance.GetComponentInChildren<Camera>();
|
|
LoadingAnimation.transform.position = AspectPosition.ComputeWorldPosition(Camera, AspectPosition.EdgeAlignments.LeftBottom, new Vector3(0.6f, 0.6f, Camera.nearClipPlane + 0.1f));
|
|
}
|
|
catch (Exception ex) { Logger.Error(ex.ToString(), "LoadingScreen.UpdateLoadingAnimation"); }
|
|
}
|
|
|
|
private static void NewHint()
|
|
{
|
|
if (GameEndChecker.LoadingEndScreen)
|
|
{
|
|
Hint = string.Empty;
|
|
return;
|
|
}
|
|
|
|
int index;
|
|
if (ToldHints.Count == HintCount) ToldHints.Clear();
|
|
|
|
do index = IRandom.Instance.Next(HintCount);
|
|
while (!ToldHints.Add(index));
|
|
|
|
bool joke = IRandom.Instance.Next(20) == 0;
|
|
if (joke) index = IRandom.Instance.Next(40, 40 + JokeHintCount);
|
|
|
|
string text = Translator.GetString($"LoadingHint.{index}");
|
|
text = text.Insert(0, joke ? "<color=#ffff00>" : "<color=#00ffa5>");
|
|
if (text.Contains('\n')) text = text.Insert(text.IndexOf('\n'), "</color><#ffffff>");
|
|
text += "</color>";
|
|
|
|
int sizePercent = 100;
|
|
if (OperatingSystem.IsAndroid()) sizePercent += 20;
|
|
if (!Main.IntroDestroyed) sizePercent += 25;
|
|
if (sizePercent != 100) text = text.Insert(0, $"<size={sizePercent}%>");
|
|
|
|
Hint = text;
|
|
}
|
|
|
|
public static void Update()
|
|
{
|
|
try
|
|
{
|
|
if (HintHideTimer <= 15f) HintHideTimer += Time.deltaTime;
|
|
|
|
PlayerControl lp = PlayerControl.LocalPlayer;
|
|
if (!lp) return;
|
|
|
|
PlayerAnimations anims = lp.MyPhysics.Animations;
|
|
|
|
bool visible = AmongUsClient.Instance.IsGameStarted && !GameStates.IsCanMove && (!GameStates.IsInTask || ExileController.Instance) && !GameStates.IsMeeting && !HudManager.Instance.Chat.IsOpenOrOpening && !lp.inVent && !anims.IsPlayingAnyLadderAnimation() && !VentButtonDoClickPatch.Animating && !lp.onLadder || GameEndChecker.LoadingEndScreen;
|
|
|
|
switch (visible)
|
|
{
|
|
case false when LoadingAnimation:
|
|
Object.Destroy(LoadingAnimation);
|
|
return;
|
|
case true when !LoadingAnimation:
|
|
UpdateLoadingAnimation();
|
|
return;
|
|
}
|
|
|
|
if (LoadingAnimation)
|
|
{
|
|
LoadingAnimation.transform.position = AspectPosition.ComputeWorldPosition(Camera, AspectPosition.EdgeAlignments.LeftBottom, new Vector3(0.6f, 0.6f, Camera.nearClipPlane + 0.1f));
|
|
LoadingAnimation.transform.Rotate(Vector3.back, 200f * Time.deltaTime);
|
|
}
|
|
|
|
visible &= !GameStates.IsEnded;
|
|
|
|
switch (visible)
|
|
{
|
|
case false when ErrorText.HasHint:
|
|
ErrorText.RemoveHint();
|
|
return;
|
|
case true when !ErrorText.HasHint:
|
|
if (HintHideTimer > 15f) NewHint();
|
|
HintHideTimer = 0f;
|
|
ErrorText.Instance.AddError(ErrorCode.LoadingHint);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex) { Logger.Error(ex.ToString(), "LoadingScreen.Update"); }
|
|
}
|
|
} |