-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAISceneManager.cs
173 lines (155 loc) · 7.84 KB
/
LAISceneManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using LobbyAppearanceImprovements.Layouts;
using LobbyAppearanceImprovements.Scenes;
using RoR2;
using RoR2.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
using static LobbyAppearanceImprovements.ConfigSetup;
namespace LobbyAppearanceImprovements
{
internal static class LAISceneManager
{
public static LAIScene chosenScene = null;
public static string chosenSceneAsString = "None";
public static Dictionary<string, Type> scenesDict = new Dictionary<string, Type>();
public static Dictionary<Type, string> scenesReverseDict = new Dictionary<Type, string>();
public static List<string> sceneNameList = new List<string>();
public static GameObject sceneInstance;
public static GameObject TitleInstance;
public static GameObject SubTitleInstance;
public static GameObject LayoutTitleInstance;
public static GameObject SeerTextInstance;
public static Action<LAIScene> onVoteStarted;
public static bool VoteHasStarted = false;
/*public static bool ShouldStartEventBeActive
{
get
{
var con = ConfigSetup.Scene_EnableTimerStartEvent.Value;
return con == EventStateType.AlwaysOn
|| con == EventStateType.On && VoteHasStarted;
}
}*/
public static void Initialize()
{
SceneSetup.Init();
On.RoR2.PreGameController.RefreshLobbyBackground += RemoveDefaultLobby;
LAIScene.onSceneLoaded += CreateHeaderIfMissing;
LAIScene.onSceneLoaded += OnSceneLoaded;
//LAIScene.onSceneLoaded += CreateSeerTextOnLoad;
LAILayout.onLayoutLoaded += OnLayoutLoaded;
//On.RoR2.UI.CharacterSelectController.ClientSetReady += CharacterSelectController_ClientSetReady;
On.RoR2.PreGameController.Start += PreGameController_Start;
LAIScene.onSceneLoaded += ActivateVoteStartEffectIfNewSceneLoaded;
LAIScene.onSceneUnloaded += DestroySeerText;
}
private static void DestroySeerText(LAIScene scene)
{
if (SeerTextInstance)
{
//UnityEngine.Object.Destroy(SeerTextInstance);
}
}
private static void CreateSeerTextOnLoad(LAIScene scene)
{
if (!SeerTextInstance)
{
LAISceneManager.SeerTextInstance = UnityEngine.Object.Instantiate(LAIAssets.bombardierTextObject, LAIPlugin.LAITextHolder.transform);
LAISceneManager.SeerTextInstance.name = $"LobbyAppearanceImprovements_Seer_Text";
LAISceneManager.SeerTextInstance.transform.localPosition = new Vector3(0f, -480f, 0f);
SeerTextInstance.GetComponent<HGTextMeshProUGUI>().fontSizeMin = 50f;
}
LAISceneManager.SeerTextInstance.GetComponent<HGTextMeshProUGUI>().text = RoR2.Language.GetStringFormatted("LAI_MAP_LAYOUT_FORMAT", RoR2.Language.GetString(LAISceneManager.chosenScene.SeerToken));
HookMethods.Hook_ToggleSceneSeerVisibility(ConfigSetup.Scene_Seer.Value);
}
private static void ActivateVoteStartEffectIfNewSceneLoaded(LAIScene scene)
{
if (VoteHasStarted)
onVoteStarted.Invoke(scene);
}
private static void PreGameController_Start(On.RoR2.PreGameController.orig_Start orig, PreGameController self)
{
orig(self);
VoteHasStarted = false;
self.gameObject.AddComponent<VoteStartedEventController>();
}
public class VoteStartedEventController : MonoBehaviour
{
public VoteController voteController;
public float stopwatch;
public float duration = 1f;
public void Start()
{
voteController = PreGameController.instance.GetComponent<VoteController>();
}
public void FixedUpdate()
{
stopwatch -= Time.fixedDeltaTime;
if (stopwatch > 0)
{
return;
}
stopwatch = duration;
if (!VoteHasStarted && voteController.NetworktimerIsActive)
{
onVoteStarted.Invoke(chosenScene);
}
VoteHasStarted = voteController.NetworktimerIsActive;
}
}
private static void OnSceneLoaded(LAIScene scene)
{
HookMethods.Hook_MusicChoice(MusicChoice.Value);
HookMethods.Hook_Lobby_DisableShaking(ConfigSetup.Lobby_Shaking.Value);
RenderSettings.skybox = scene.SkyboxOverride;
}
private static void OnLayoutLoaded(LAILayout layout)
{
CreateOrUpdateHeaderText();
}
private static void RemoveDefaultLobby(On.RoR2.PreGameController.orig_RefreshLobbyBackground orig, PreGameController self)
{
orig(self);
if (self.lobbyBackground) self.lobbyBackground.SetActive(false);
}
private static void CreateHeaderIfMissing(LAIScene scene)
{
if (scene == null) return;
CreateOrUpdateHeaderText();
}
public static void CreateOrUpdateHeaderText()
{
//LAILogging.LogMessage($"LAITITLEREF existing!, attempting spawn", LoggingStyle.UserShouldSee);
if (!TitleInstance)
{
LAISceneManager.TitleInstance = UnityEngine.Object.Instantiate(LAIAssets.bombardierTextObject, LAIPlugin.LAITextHolder.transform);
LAISceneManager.TitleInstance.name = $"LobbyAppearanceImprovements_Scene_Title";
LAISceneManager.TitleInstance.transform.localPosition = new Vector3(0f, 450f, 0f);
TitleInstance.GetComponent<HGTextMeshProUGUI>().fontSizeMin = 80;
//TitleInstance.GetComponent<HGTextMeshProUGUI>().CrossFadeAlpha(1f, 3f, false);
}
LAISceneManager.TitleInstance.GetComponent<HGTextMeshProUGUI>().text = RoR2.Language.GetString(LAISceneManager.chosenScene.SceneTitleToken);
if (!SubTitleInstance)
{
LAISceneManager.SubTitleInstance = UnityEngine.Object.Instantiate(LAIAssets.bombardierTextObject, LAIPlugin.LAITextHolder.transform);
LAISceneManager.SubTitleInstance.name = $"LobbyAppearanceImprovements_Scene_Subtitle";
LAISceneManager.SubTitleInstance.transform.localPosition = new Vector3(0f, 400f, 0f);
SubTitleInstance.GetComponent<HGTextMeshProUGUI>().fontSizeMin = 50;
//SubTitleInstance.GetComponent<HGTextMeshProUGUI>().alpha = 0f;
//SubTitleInstance.GetComponent<HGTextMeshProUGUI>().CrossFadeAlpha(1f, 3f, false);
}
LAISceneManager.SubTitleInstance.GetComponent<HGTextMeshProUGUI>().text = RoR2.Language.GetStringFormatted("LAI_MAP_SUBTTILE_FORMAT", RoR2.Language.GetString(LAISceneManager.chosenScene.SceneSubtitleToken));
if (!LayoutTitleInstance)
{
LAISceneManager.LayoutTitleInstance = UnityEngine.Object.Instantiate(LAIAssets.bombardierTextObject, LAIPlugin.LAITextHolder.transform);
LAISceneManager.LayoutTitleInstance.name = $"LobbyAppearanceImprovements_Layout_Title";
LAISceneManager.LayoutTitleInstance.transform.localPosition = new Vector3(0f, 360f, 0f);
LayoutTitleInstance.GetComponent<HGTextMeshProUGUI>().fontSizeMin = 40f;
}
LAISceneManager.LayoutTitleInstance.GetComponent<HGTextMeshProUGUI>().text = RoR2.Language.GetStringFormatted("LAI_MAP_LAYOUT_FORMAT", RoR2.Language.GetString(LAILayoutManager.GetLayoutTitleToken()));
HookMethods.Hook_ToggleSceneHeaderVisibility(ConfigSetup.Scene_Header.Value);
CreateSeerTextOnLoad(LAISceneManager.chosenScene);
}
}
}