Skip to content

Commit

Permalink
Completely redesigned UI, added animations, unified tools, implemente…
Browse files Browse the repository at this point in the history
…d SegmentUpdateRequest tool, added hot-reload
  • Loading branch information
krzychu124 committed May 5, 2022
1 parent 5d34775 commit 073d09a
Show file tree
Hide file tree
Showing 19 changed files with 1,842 additions and 1,127 deletions.
7 changes: 4 additions & 3 deletions BrokenNodeDetector/BndResultHighlightManager.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Collections.Generic;
using System.Reflection;
using BrokenNodeDetector.Highlighter;
using UnityEngine;

namespace BrokenNodeDetector {
public class BndResultHighlightManager: SimulationManagerBase<BndResultHighlightManager, ResultHighlightProperties>, IRenderableManager {
private static bool _instantiated;

private static BndResultHighlightManager _instance;

private IHighlightable _highlightable;

private Dictionary<HighlightType, IHighlightable> _highlightables = new Dictionary<HighlightType, IHighlightable>();
Expand All @@ -22,9 +21,11 @@ private void Awake() {
}

private void OnDestroy() {
_instance = null;
_instantiated = false;
_highlightable = null;
_highlightables.Clear();
GetType().GetField("sInstance", BindingFlags.NonPublic | BindingFlags.Static)
?.SetValue(null, null);
}

private void OnDisable() {
Expand Down
26 changes: 25 additions & 1 deletion BrokenNodeDetector/BrokenNodeDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@
namespace BrokenNodeDetector
{
public class BrokenNodeDetector : IUserMod {
public static readonly string Version = "0.6";
public static readonly string Version = "0.7";

public string Name => "Broken Node Detector " + Version;

public string Description => "Search for broken nodes when TM:PE vehicles despawn.";
#if TEST_UI
private MainUI _testUI;
#endif

public void OnEnabled() {
Debug.Log($"[BND] Broken Node Detector enabled. Version {Version}");
HarmonyHelper.EnsureHarmonyInstalled();
ModSettings.Ensure();

#if TEST_UI
if (UIView.GetAView()) {
TestUI();
} else {
LoadingManager.instance.m_introLoaded += TestUI;
}
#endif
#if DEBUG
LoadingExtension.Patcher.PatchAll();
#endif
Expand All @@ -26,13 +37,26 @@ public void OnDisabled() {
if (LoadingExtension.MainUi) {
Object.Destroy(LoadingExtension.MainUi);
}
#if TEST_UI
if (_testUI) {
Object.Destroy(_testUI.gameObject);
_testUI = null;
}
#endif
#if DEBUG
LoadingManager.instance.m_introLoaded -= TestUI;
LoadingExtension.Patcher.UnpatchAll();
#endif
}

public void OnSettingsUI(UIHelper helper) {
new SettingsUI().BuildUI(helper);
}

#if TEST_UI
private void TestUI() {
_testUI = (MainUI) UIView.GetAView().AddUIComponent(typeof(MainUI));
}
#endif
}
}
12 changes: 12 additions & 0 deletions BrokenNodeDetector/BrokenNodeDetector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,21 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResultHighlight.cs" />
<Compile Include="BndResultHighlightManager.cs" />
<Compile Include="UI\Tools\BrokenNodesTool\BrokenNodes.cs" />
<Compile Include="UI\Tools\BrokenPropsTool\BrokenProps.cs" />
<Compile Include="UI\Tools\DetectorFactory.cs" />
<Compile Include="UI\Tools\DisconnectedBuildingsTool\DisconnectedBuildings.cs" />
<Compile Include="UI\Tools\DisconnectedPublicTransportStopsTool\DisconnectedPublicTransportStops.cs" />
<Compile Include="UI\Tools\GhostNodesTool\GhostNodes.cs" />
<Compile Include="UI\Tools\IDetector.cs" />
<Compile Include="UI\MainPanel.cs" />
<Compile Include="UI\MainUI.cs" />
<Compile Include="UI\ProgressPanel.cs" />
<Compile Include="UI\ResultsPanel.cs" />
<Compile Include="UI\SettingsUI.cs" />
<Compile Include="UI\Tools\SegmentUpdateTool\SegmentUpdateRequest.cs" />
<Compile Include="UI\Tools\ShortSegmentsTool\ShortSegments.cs" />
<Compile Include="UI\Tools\UIHelpers.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
Expand Down
35 changes: 31 additions & 4 deletions BrokenNodeDetector/LoadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@ public class LoadingExtension : LoadingExtensionBase {
public bool DetourInited { get; private set; }
public static MainUI MainUi { get; private set; }

private bool _created;

public override void OnCreated(ILoading loading) {
base.OnCreated(loading);
if (LoadingManager.instance.m_loadingComplete &&
loading.currentMode == AppMode.Game &&
!_created) {
InitDetours();

if (!MainUi) {
MainUi = (MainUI)UIView.GetAView().AddUIComponent(typeof(MainUI));
}
}

_created = true;
}

public override void OnReleased() {
base.OnReleased();
RevertDetours();
if (MainUi) {
Object.Destroy(MainUi);
MainUi = null;
}

_created = false;
}

public override void OnLevelLoaded(LoadMode mode) {
base.OnLevelLoaded(mode);

Expand All @@ -24,7 +52,7 @@ public override void OnLevelLoaded(LoadMode mode) {
}

if (!MainUi) {
MainUi = (MainUI) UIView.GetAView().AddUIComponent(typeof(MainUI));
MainUi = (MainUI)UIView.GetAView().AddUIComponent(typeof(MainUI));
}
}

Expand Down Expand Up @@ -69,7 +97,7 @@ private void RevertDetours() {
Patcher.UnpatchAll();
DetourInited = false;
}

internal static class Patcher {
private const string HarmonyId = "krzychu124.broken-node-detector";
private static bool patched = false;
Expand All @@ -80,7 +108,7 @@ public static void PatchAll() {
patched = true;
var harmony = new Harmony(HarmonyId);
harmony.Patch(typeof(NetNode).GetMethod(nameof(NetNode.UpdateLaneConnection)),
postfix: new HarmonyMethod(typeof(CustomNetNode), nameof(CustomNetNode.Postfix)));
postfix: new HarmonyMethod(typeof(CustomNetNode), nameof(CustomNetNode.Postfix)));
}

public static void UnpatchAll() {
Expand All @@ -91,6 +119,5 @@ public static void UnpatchAll() {
patched = false;
}
}

}
}
Loading

0 comments on commit 073d09a

Please sign in to comment.