Cleanup and add configuration
This commit is contained in:
parent
9a330e3a05
commit
9ee3ffbb8c
4 changed files with 78 additions and 11 deletions
|
@ -4,13 +4,16 @@ class CairnHUDMarker : HUDDistanceMarker
|
|||
{
|
||||
public override void InitCanvasMarker()
|
||||
{
|
||||
int index = OWCairnFinder.getCairnIndex(gameObject);
|
||||
int index = OWCairnFinder.GetCairnIndex(gameObject);
|
||||
_markerLabel = $"[{index}]";
|
||||
_markerTarget = gameObject.transform;
|
||||
OWCairnFinder.Instance.ModHelper.Console.WriteLine($"Transform: {_markerTarget}");
|
||||
_markerRadius = 0;
|
||||
OWCairnFinder.Instance.ModHelper.Console.WriteLine($"Cairn {index}");
|
||||
base.InitCanvasMarker();
|
||||
_canvasMarker.SetVisibility(true);
|
||||
RefreshOwnVisibility();
|
||||
}
|
||||
|
||||
public override void RefreshOwnVisibility()
|
||||
{
|
||||
_canvasMarker.SetVisibility(OWCairnFinder.ShouldShowCairn(gameObject));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using HarmonyLib;
|
||||
using OWML.Common;
|
||||
using OWML.Common;
|
||||
using OWML.ModHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OWCairnFinder;
|
||||
|
@ -12,6 +12,12 @@ public class OWCairnFinder : ModBehaviour
|
|||
public static OWCairnFinder Instance;
|
||||
|
||||
private static NomaiCairn[] _nomaiCairns;
|
||||
private static CairnHUDMarker[] _markers;
|
||||
|
||||
private static bool _enabled = true;
|
||||
private static bool _showAll = false;
|
||||
|
||||
private static List<int> _knockedOverCairns;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
|
@ -26,12 +32,33 @@ public class OWCairnFinder : ModBehaviour
|
|||
// Starting here, you'll have access to OWML's mod helper.
|
||||
ModHelper.Console.WriteLine($"{nameof(OWCairnFinder)} is loaded!", MessageType.Success);
|
||||
|
||||
new Harmony("thearst3rd.OWCairnFinder").PatchAll(Assembly.GetExecutingAssembly());
|
||||
// Read cairns from file if it exists
|
||||
// Possible TODO - integrate with CutAchievements instead of independently doing all the same stuff
|
||||
_knockedOverCairns = ModHelper.Storage.Load<List<int>>("../_nebula.CutAchievements/cairns.json"); // Hacky but works
|
||||
if (_knockedOverCairns == null)
|
||||
_knockedOverCairns = [];
|
||||
|
||||
ModHelper.HarmonyHelper.AddPostfix<NomaiCairn>(nameof(NomaiCairn.KnockOver), typeof(OWCairnFinder), nameof(KnockOverCairn));
|
||||
|
||||
LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad;
|
||||
}
|
||||
|
||||
public static int getCairnIndex(GameObject cairn)
|
||||
public override void Configure(IModConfig config)
|
||||
{
|
||||
string mode = config.GetSettingsValue<string>("Mode");
|
||||
_enabled = mode != "Hide All";
|
||||
_showAll = mode == "Show All";
|
||||
|
||||
if (_markers != null)
|
||||
{
|
||||
foreach (CairnHUDMarker marker in _markers)
|
||||
{
|
||||
marker.RefreshOwnVisibility();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetCairnIndex(GameObject cairn)
|
||||
{
|
||||
for (int i = 0; i < _nomaiCairns.Length; i++)
|
||||
{
|
||||
|
@ -41,18 +68,44 @@ public class OWCairnFinder : ModBehaviour
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static bool ShouldShowCairn(GameObject cairn)
|
||||
{
|
||||
if (!_enabled)
|
||||
return false;
|
||||
if (_showAll)
|
||||
return true;
|
||||
int index = GetCairnIndex(cairn);
|
||||
return !_knockedOverCairns.Contains(index);
|
||||
}
|
||||
|
||||
public void OnCompleteSceneLoad(OWScene previousScene, OWScene newScene)
|
||||
{
|
||||
if (newScene != OWScene.SolarSystem)
|
||||
return;
|
||||
|
||||
_nomaiCairns = Resources.FindObjectsOfTypeAll<NomaiCairn>().Where(x => x.gameObject.activeSelf && x.transform.childCount != 0).ToArray();
|
||||
_markers = new CairnHUDMarker[_nomaiCairns.Length];
|
||||
|
||||
for (int i = 0; i < _nomaiCairns.Length; i++)
|
||||
{
|
||||
NomaiCairn cairn = _nomaiCairns[i];
|
||||
cairn.gameObject.AddComponent<CairnHUDMarker>();
|
||||
_markers[i] = cairn.gameObject.GetComponent<CairnHUDMarker>();
|
||||
}
|
||||
}
|
||||
|
||||
public static void KnockOverCairn(NomaiCairn __instance)
|
||||
{
|
||||
if (_nomaiCairns == null)
|
||||
return;
|
||||
|
||||
int index = Array.IndexOf(_nomaiCairns, __instance);
|
||||
if (_knockedOverCairns.Contains(index))
|
||||
return;
|
||||
|
||||
_knockedOverCairns.Add(index);
|
||||
if (_markers != null && _markers[index] != null)
|
||||
_markers[index].RefreshOwnVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/ow-mods/owml/master/schemas/config_schema.json",
|
||||
"enabled": true
|
||||
"enabled": true,
|
||||
"settings": {
|
||||
"Mode": {
|
||||
"type": "selector",
|
||||
"value": "Show Uncollected",
|
||||
"options": [
|
||||
"Show All",
|
||||
"Show Uncollected",
|
||||
"Hide All"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"$schema": "https://raw.githubusercontent.com/ow-mods/owml/master/schemas/manifest_schema.json",
|
||||
"filename": "OWCairnFinder.dll",
|
||||
"author": "thearst3rd",
|
||||
"name": "OWCairnFinder",
|
||||
"name": "Cairn Finder",
|
||||
"uniqueName": "thearst3rd.OWCairnFinder",
|
||||
"version": "0.1.0",
|
||||
"owmlVersion": "2.15.1",
|
||||
|
|
Loading…
Add table
Reference in a new issue