Skip to content

Commit

Permalink
this caeden guy is a dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
Caeden117 authored Jan 8, 2020
2 parents 1a743b6 + f0bd9f1 commit e55f515
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
1 change: 1 addition & 0 deletions Counters+/Counters+.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="Counters\NotesLeftCounter.cs" />
<Compile Include="Counters\Spinometer.cs" />
<Compile Include="Custom\CustomCounters.cs" />
<Compile Include="Custom\CustomCounterTemplate.cs" />
<Compile Include="Harmony\ScoreCounterHook.cs" />
<Compile Include="UI\AdvancedCounterSettings.cs" />
<Compile Include="UI\CounterWarning.cs" />
Expand Down
12 changes: 9 additions & 3 deletions Counters+/CountersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public static void OnLoad()
/// <typeparam name="T">ConfigModel to use for settings.</typeparam>
/// <typeparam name="R">MonoBehaviour to attach to the new GameObject.</typeparam>
/// <param name="settings">ConfigModel settings reference.</param>
internal static void LoadCounter<T, R>(T settings) where T : ConfigModel where R : Counter<T>
internal static void LoadCounter<T, R>(T settings, Type counterInstance = null) where T : ConfigModel where R : Counter<T>
{
if (counterInstance is null) counterInstance = typeof(R);
if (!settings.Enabled || GameObject.Find($"Counters+ | {settings.DisplayName} Counter")) return;
R counter = new GameObject($"Counters+ | {settings.DisplayName} Counter").AddComponent(typeof(R)) as R;
R counter = new GameObject($"Counters+ | {settings.DisplayName} Counter").AddComponent(counterInstance) as R;
counter.settings = settings;
Plugin.Log($"Loaded Counter: {settings.DisplayName}");
LoadedCounters.Add(counter.gameObject);
Expand Down Expand Up @@ -87,7 +88,12 @@ public static void LoadCounters()
LoadCounter<NotesLeftConfigModel, NotesLeftCounter>(settings.notesLeftConfig);
LoadCounter<FailConfigModel, FailCounter>(settings.failsConfig);
foreach (CustomCounter potential in CustomCounterCreator.LoadedCustomCounters)
LoadCounter<CustomConfigModel, CustomCounterHook>(potential.ConfigModel);
{
if (potential.TemplateCounter != null)
LoadCounter<CustomConfigModel, CustomCounterTemplate>(potential.ConfigModel, potential.TemplateCounter);
else
LoadCounter<CustomConfigModel, CustomCounterHook>(potential.ConfigModel);
}
Plugin.Log("Counters loaded!", LogInfo.Notice);
Instance.StartCoroutine(Instance.ObtainRequiredData());
}
Expand Down
40 changes: 40 additions & 0 deletions Counters+/Custom/CustomCounterTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CountersPlus.Counters;
using TMPro;
using UnityEngine;

namespace CountersPlus.Custom
{
public abstract class CustomCounterTemplate : Counter<CustomConfigModel>
{
public abstract string DisplayName { get; }
public abstract string FormattedText { get; }

private TMP_Text label;
private TMP_Text counter;

internal override void Init(CountersData data)
{
Vector3 position = CountersController.DeterminePosition(gameObject, settings.Position, settings.Distance);

TextHelper.CreateText(out counter, position - new Vector3(0, 0.4f, 0));
counter.text = "Data";
counter.fontSize = 4;
counter.color = Color.white;
counter.alignment = TextAlignmentOptions.Center;

TextHelper.CreateText(out label, position);
label.text = $"{settings.CustomCounter.Name}";
label.fontSize = 3;
label.color = Color.white;
label.alignment = TextAlignmentOptions.Center;

RefreshCounter();
}

public void RefreshCounter()
{
label.text = DisplayName;
counter.text = FormattedText;
}
}
}
6 changes: 5 additions & 1 deletion Counters+/Custom/CustomCounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ public class CustomCounter
/// <summary>
/// Location to a BSML (*.bsml) file to load extra settings in the Counters+ menu.
/// </summary>
public string CustomSettingsResource;
public string CustomSettingsResource = null;
/// <summary>
/// The <see cref="Type"/> of a <see cref="MonoBehaviour"/> that will handle the file defined in <see cref="CustomSettingsResource"/>.
/// </summary>
public Type CustomSettingsHandler;
/// <summary>
/// A template counter that inherits from <see cref="CustomCounterTemplate"/>.
/// </summary>
public Type TemplateCounter;

/// <summary>
/// Local name of the mod from BSIPA or IPA.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public static ConfigModelController GenerateController(ConfigModel model, Type c
return controller;
}

public static ConfigModelController GenerateController(string bsmlFileName, Type controllerType, GameObject baseTransform,
bool addBaseSettings = false, ConfigModel model = null)
public static ConfigModelController GenerateController(Type controllerType, GameObject baseTransform,
string bsmlFileName = null, bool addBaseSettings = false, ConfigModel model = null)
{
GameObject controllerGO = new GameObject($"Counters+ | {bsmlFileName} Settings Controller");
string name = bsmlFileName == null ? "Blank" : bsmlFileName;
GameObject controllerGO = new GameObject($"Counters+ | {name} Settings Controller");
controllerGO.transform.parent = baseTransform.transform;
ConfigModelController controller = controllerGO.AddComponent<ConfigModelController>();
controller.ConfigModel = model;
Expand All @@ -71,8 +72,9 @@ public static ConfigModelController GenerateController(string bsmlFileName, Type
BSMLParser.instance.Parse(controller.baseConfigLocation, baseTransform, controller);
try
{
BSMLParser.instance.Parse(Utilities.GetResourceContent(controllerType.Assembly,
bsmlFileName), baseTransform, controller.ModelSpecificController);
if (bsmlFileName != null)
BSMLParser.instance.Parse(Utilities.GetResourceContent(controllerType.Assembly,
bsmlFileName), baseTransform, controller.ModelSpecificController);
}catch(Exception e)
{
Plugin.Log($"Exception thrown while attempting to load a non-Counters+ BSML file:\n{bsmlFileName}\n{e}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal static void ShowMainSettings()
ClearScreen(true);
Instance.SettingsName.text = "Main Settings";
Type controllerType = Type.GetType($"CountersPlus.UI.ViewControllers.ConfigModelControllers.MainSettingsController");
ConfigModelController.GenerateController("CountersPlus.UI.BSML.MainSettings.bsml", controllerType, Instance.SettingsContainer);
ConfigModelController.GenerateController(controllerType, Instance.SettingsContainer,"CountersPlus.UI.BSML.MainSettings.bsml");
MockCounter.Highlight<ConfigModel>(null);
}

Expand All @@ -120,8 +120,8 @@ public static void UpdateSettings<T>(T settings) where T : ConfigModel
string name = string.Join("", settings.DisplayName.Split(' '));
if (settings is CustomConfigModel custom)
{
ConfigModelController.GenerateController(custom.CustomCounter.CustomSettingsResource,
custom.CustomCounter.CustomSettingsHandler, Instance.SettingsContainer, true, settings);
ConfigModelController.GenerateController(custom.CustomCounter.CustomSettingsHandler,
Instance.SettingsContainer, custom.CustomCounter.CustomSettingsResource, true, settings);
name = custom.CustomCounter.Name;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private void RefreshScreen(string name, string title)
{
CountersPlusEditViewController.UpdateTitle(title);
Type controllerType = Type.GetType($"CountersPlus.UI.ViewControllers.ConfigModelControllers.HUD.{name}");
ConfigModelController.GenerateController($"CountersPlus.UI.BSML.HUD.{name}.bsml", controllerType,
CountersPlusEditViewController.Instance.SettingsContainer);
ConfigModelController.GenerateController(controllerType,
CountersPlusEditViewController.Instance.SettingsContainer, $"CountersPlus.UI.BSML.HUD.{name}.bsml");
}
}
}
2 changes: 1 addition & 1 deletion Counters+/Utils/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Canvas CreateCanvas(Vector3 Position, bool floatingHUD = false, fl
CanvasGO.transform.position = Position;
CanvasGO.transform.rotation = Quaternion.Euler(CountersController.settings.hudConfig.HUDRotation);

GameObject coreGameHUD = Resources.FindObjectsOfTypeAll<CoreGameHUDController>()?.FirstOrDefault()?.gameObject ?? null;
GameObject coreGameHUD = Resources.FindObjectsOfTypeAll<CoreGameHUDController>()?.FirstOrDefault(x => x.isActiveAndEnabled)?.gameObject ?? null;
FlyingGameHUDRotation flyingGameHUD = Resources.FindObjectsOfTypeAll<FlyingGameHUDRotation>().FirstOrDefault(x => x.isActiveAndEnabled);
bool attachToHUD = flyingGameHUD != null && CountersController.settings.hudConfig.AttachToBaseGameHUDFor360;
if (CountersController.settings.hudConfig.AttachBaseGameHUD && !attachToHUD && coreGameHUD != null)
Expand Down

0 comments on commit e55f515

Please sign in to comment.