This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
267 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Events.Game; | ||
using Events.GameMode; | ||
using Events.Level; | ||
using Events.LevelEditor; | ||
using Events.RaceEnd; | ||
using System.Linq; | ||
|
||
namespace Distance.Heat | ||
{ | ||
public static class Flags | ||
{ | ||
public static bool IsModeStarted { get; private set; } | ||
|
||
public static bool IsPaused { get; private set; } | ||
|
||
public static bool IsMenuOpen => G.Sys.MenuPanelManager_?.panelStack_?.Count > 0; | ||
|
||
public static bool IsLoading => G.Sys.GameManager_.BlackFade_.currentState_ != BlackFadeLogic.FadeState.Idle && !G.Sys.GameManager_.IsLevelLoaded_; | ||
|
||
public static bool IsReplayMode => G.Sys.ReplayManager_.IsReplayMode_; | ||
|
||
public static GameModeID[] NonPlayModeIDS { get; private set; } | ||
|
||
public static bool CurrentModeIsPlayable => !NonPlayModeIDS.Contains(G.Sys.GameManager_.ModeID_); | ||
|
||
static Flags() | ||
{ | ||
NonPlayModeIDS = new GameModeID[] | ||
{ | ||
GameModeID.Count, | ||
GameModeID.MainMenu, | ||
GameModeID.None, | ||
}; | ||
} | ||
|
||
public static bool CanDisplayHudElements | ||
{ | ||
get | ||
{ | ||
return IsModeStarted && !IsLoading && CurrentModeIsPlayable && !IsPaused && !IsMenuOpen && !IsReplayMode; | ||
} | ||
} | ||
|
||
internal static void SubscribeEvents() | ||
{ | ||
PauseToggled.Subscribe(OnGamePauseToggled); | ||
ModeInitialized.Subscribe(OnGameModeInitialized); | ||
ModeStarted.Subscribe(OnGameModeModeStarted); | ||
LocalCarHitFinish.Subscribe(OnRaceEndLocalCarHitFinish); | ||
EnterPlayMode.Subscribe(OnLevelEditorEnterPlayMode); | ||
EnterEditorMode.Subscribe(OnLevelEditorEnterEditorMode); | ||
UninitializeOptimizations.Subscribe(OnLevelUninitializeOptimizations); | ||
} | ||
|
||
private static void OnLevelUninitializeOptimizations(UninitializeOptimizations.Data data) | ||
{ | ||
IsModeStarted = false; | ||
} | ||
|
||
private static void OnGameModeModeStarted(ModeStarted.Data data) | ||
{ | ||
IsPaused = false; | ||
IsModeStarted = true; | ||
} | ||
|
||
private static void OnLevelEditorEnterEditorMode(EnterEditorMode.Data data) | ||
{ | ||
IsPaused = false; | ||
IsModeStarted = false; | ||
} | ||
|
||
private static void OnLevelEditorEnterPlayMode(EnterPlayMode.Data data) | ||
{ | ||
IsModeStarted = true; | ||
} | ||
|
||
private static void OnRaceEndLocalCarHitFinish(LocalCarHitFinish.Data data) | ||
{ | ||
IsModeStarted = false; | ||
} | ||
|
||
private static void OnGameModeInitialized(ModeInitialized.Data data) | ||
{ | ||
IsPaused = false; | ||
} | ||
|
||
private static void OnGamePauseToggled(PauseToggled.Data data) | ||
{ | ||
IsPaused = data.paused_; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
Distance.Heat/Harmony/Assembly-CSharp/SpeedrunTimerLogic/OnEnable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Distance.Heat.Scripts; | ||
using HarmonyLib; | ||
using System; | ||
|
||
namespace Distance.Heat.Harmony | ||
{ | ||
[HarmonyPatch(typeof(SpeedrunTimerLogic), "OnEnable")] | ||
internal static class SpeedrunTimerLogic__OnEnable | ||
{ | ||
[HarmonyPostfix] | ||
internal static void Postfix(SpeedrunTimerLogic __instance) | ||
{ | ||
try | ||
{ | ||
HeatTextLogic.Create(__instance.gameObject); | ||
} | ||
catch (Exception e) | ||
{ | ||
Mod.Instance.Logger.Exception(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using Centrifuge.Distance; | ||
using Centrifuge.Distance.Game; | ||
using System.Collections; | ||
using UnityEngine; | ||
|
||
namespace Distance.Heat.Scripts | ||
{ | ||
public class HeatTextLogic : MonoBehaviour | ||
{ | ||
internal const float MaximumOpacity = 0.7f; | ||
|
||
internal static HeatTextLogic Instance { get; set; } = null; | ||
internal static bool creatingInstance = false; | ||
|
||
internal UILabel label; | ||
internal UIWidget widget; | ||
internal UIPanel panel; | ||
|
||
internal static void Create(GameObject speedrunTimerLogic = null) | ||
{ | ||
if (!Instance && !creatingInstance) | ||
{ | ||
creatingInstance = true; | ||
GameObject alphaVersionAnchorBlueprint = null; | ||
|
||
if (speedrunTimerLogic) | ||
{ | ||
alphaVersionAnchorBlueprint = speedrunTimerLogic.Parent(); | ||
} | ||
else | ||
{ | ||
alphaVersionAnchorBlueprint = GameObject.Find("Anchor : Speedrun Timer"); | ||
} | ||
|
||
if (alphaVersionAnchorBlueprint) | ||
{ | ||
GameObject centrifugeInfoAnchor = Instantiate(alphaVersionAnchorBlueprint, alphaVersionAnchorBlueprint.transform.parent); | ||
|
||
centrifugeInfoAnchor.SetActive(true); | ||
centrifugeInfoAnchor.name = "Anchor : Heat Display"; | ||
|
||
centrifugeInfoAnchor.ForEachChildObjectDepthFirstRecursive((obj) => | ||
{ | ||
obj.SetActive(true); | ||
obj.RemoveComponents<SpeedrunTimerLogic>(); | ||
}); | ||
|
||
UILabel label = centrifugeInfoAnchor.GetComponentInChildren<UILabel>(); | ||
|
||
Instance = label.gameObject.AddComponent<HeatTextLogic>(); | ||
} | ||
|
||
creatingInstance = false; | ||
} | ||
} | ||
|
||
internal void Start() | ||
{ | ||
GameObject anchorObject = gameObject.Parent(); | ||
GameObject panelObject = anchorObject.Parent(); | ||
|
||
label = GetComponent<UILabel>(); | ||
widget = anchorObject.GetComponent<UIWidget>(); | ||
panel = panelObject.GetComponent<UIPanel>(); | ||
|
||
widget.alpha = 0; | ||
|
||
AdjustPosition(); | ||
} | ||
|
||
internal void Update() | ||
{ | ||
Mathf.Clamp(Vehicle.HeatLevel, 0, 1); | ||
|
||
string percent = Mathf.RoundToInt(100 * Mathf.Clamp(Vehicle.HeatLevel, 0, 1)).ToString(); | ||
while (percent.Length < 3) | ||
{ | ||
percent = $"0{percent}"; | ||
} | ||
|
||
|
||
label.text = $"{percent} %"; | ||
|
||
Visible = CanDisplay; | ||
} | ||
|
||
private Coroutine _transitionCoroutine = null; | ||
|
||
private bool _visible = true; | ||
internal bool Visible | ||
{ | ||
get => _visible; | ||
set | ||
{ | ||
if (value != _visible) | ||
{ | ||
if (_transitionCoroutine != null) | ||
{ | ||
StopCoroutine(_transitionCoroutine); | ||
} | ||
|
||
_transitionCoroutine = StartCoroutine(Transition(value)); | ||
} | ||
|
||
_visible = value; | ||
} | ||
} | ||
|
||
internal bool CanDisplay => Flags.CanDisplayHudElements; | ||
|
||
internal void AdjustPosition() | ||
{ | ||
label.SetAnchor(panel.gameObject, 21, 19, -19, -17); | ||
label.pivot = UIWidget.Pivot.TopLeft; | ||
} | ||
|
||
internal IEnumerator Transition(bool visible, float duration = 0.2f) | ||
{ | ||
float target = visible ? MaximumOpacity : 0.0f; | ||
float current = widget.alpha; | ||
|
||
for (float time = 0.0f; time < duration; time += Timex.deltaTime_) | ||
{ | ||
if (!Centrifuge.Distance.Game.Options.General.MenuAnimations) | ||
{ | ||
break; | ||
} | ||
|
||
float value = MathUtil.Map(time, 0, duration, current, target); | ||
widget.alpha = value; | ||
|
||
yield return null; | ||
} | ||
|
||
widget.alpha = target; | ||
|
||
yield break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters