Skip to content

Commit f9b4177

Browse files
committed
added percent and config options
1 parent d58a2ac commit f9b4177

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

PerfectDisplay.cs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class PerfectDisplay : MonoBehaviour
1313
{
1414
TextMeshPro scoreMesh;
1515
ScoreController scoreController;
16-
17-
int[] scoreRanges = { 100, 90, 50 };
18-
string[] colors = { "blue", "green", "yellow", "orange", "red" };
16+
public static Vector3 displayPosition = new Vector3(0, 2.3f, 7f);
17+
public static int[] scoreRanges = { 100, 90, 50 };
18+
public static string[] colors = { "blue", "green", "yellow", "orange", "red" };
1919
int[] scoreCount;
20-
int misses;
20+
int misses = 0;
21+
int notes = 0;
22+
public static bool showNumbers = true;
23+
public static bool showPercent = true;
2124
IEnumerator WaitForLoad()
2225
{
2326
bool loaded = false;
@@ -45,7 +48,7 @@ private void Init()
4548
scoreMesh.color = Color.white;
4649
scoreMesh.font = Resources.Load<TMP_FontAsset>("Teko-Medium SDF No Glow");
4750
scoreMesh.alignment = TextAlignmentOptions.Center;
48-
scoreMesh.rectTransform.position = Plugin.scoreCounterPosition;
51+
scoreMesh.rectTransform.position = displayPosition;
4952
if (scoreController != null)
5053
{
5154
scoreController.noteWasMissedEvent += Miss;
@@ -56,10 +59,12 @@ private void Init()
5659
public void Miss(NoteData data, int c)
5760
{
5861
misses++;
62+
notes++;
5963
UpdateText();
6064
}
6165
public void Cut(NoteData data, NoteCutInfo info, int combo)
6266
{
67+
notes++;
6368
bool didDone = false;
6469
info.afterCutSwingRatingCounter.didFinishEvent += c => {
6570
if (didDone) return;
@@ -83,13 +88,30 @@ public void Cut(NoteData data, NoteCutInfo info, int combo)
8388
public void UpdateText()
8489
{
8590
String text = "";
86-
for(int i = 0; i < scoreRanges.Length; i++)
91+
if (showNumbers)
8792
{
88-
text += "<color=\""+colors[i] +"\">"+">"+scoreRanges[i] + "-" + scoreCount[i] + "<color=\"black\">|";
93+
for (int i = 0; i < scoreRanges.Length; i++)
94+
{
95+
text += "<color=\"" + colors[i] + "\">" + ">" + scoreRanges[i] + "-" + scoreCount[i] + "<color=\"black\">|";
96+
}
97+
text += "<color=\"" + colors[scoreRanges.Length] + "\">" + "<" + scoreRanges[scoreRanges.Length - 1] + "-" + scoreCount[scoreRanges.Length] + "<color=\"black\">|";
98+
text += "<color=\"" + colors[scoreRanges.Length + 1] + "\">" + "MISS-" + misses +"\n";
99+
}
100+
if (showPercent)
101+
{
102+
for (int i = 0; i < scoreRanges.Length; i++)
103+
{
104+
text += "<color=\"" + colors[i] + "\">" + ">" + scoreRanges[i] + "-" + GetPercent(scoreCount[i]) + "%<color=\"black\">|";
105+
}
106+
text += "<color=\"" + colors[scoreRanges.Length] + "\">" + "<" + scoreRanges[scoreRanges.Length - 1] + "-" + GetPercent(scoreCount[scoreRanges.Length]) + "%<color=\"black\">|";
107+
text += "<color=\"" + colors[scoreRanges.Length + 1] + "\">" + "MISS-" + GetPercent(misses) + "%";
89108
}
90-
text += "<color=\"" + colors[scoreRanges.Length] + "\">" + "<" + scoreRanges[scoreRanges.Length-1] + "-" + scoreCount[scoreRanges.Length] + "<color=\"black\">|";
91-
text += "<color=\"" + colors[scoreRanges.Length + 1] + "\">" + "MISS-" +misses;
92109
scoreMesh.text = text;
93110
}
111+
private String GetPercent(int hits)
112+
{
113+
if (hits == 0) return "0";
114+
return ((hits * 1f / notes) * 100).ToString("0.0");
115+
}
94116
}
95117
}

Plugin.cs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using IllusionPlugin;
2+
using System;
3+
using System.Globalization;
24
using System.Linq;
35
using UnityEngine;
46
using UnityEngine.SceneManagement;
@@ -8,16 +10,45 @@ namespace PerfectionDisplay
810
public class Plugin : IPlugin
911
{
1012
public string Name => "Perfection Display";
11-
public string Version => "1.0";
13+
public string Version => "1.1";
1214

1315
private readonly string[] env = { "DefaultEnvironment", "BigMirrorEnvironment", "TriangleEnvironment", "NiceEnvironment" };
14-
bool _init = false;
15-
16-
public static Vector3 scoreCounterPosition = new Vector3(0, 2.3f, 7f);
17-
16+
1817
public void OnApplicationStart()
1918
{
2019
SceneManager.activeSceneChanged += OnSceneChanged;
20+
21+
if (ModPrefs.GetString("PerfectionDisplay", "Position") == "")
22+
{
23+
ModPrefs.SetString("PerfectionDisplay", "Position",FormattableString.Invariant($"{PerfectDisplay.displayPosition.x:0.00},{PerfectDisplay.displayPosition.y:0.00},{PerfectDisplay.displayPosition.z:0.00}"));
24+
}
25+
else
26+
{
27+
var posString = ModPrefs.GetString("PerfectionDisplay", "Position");
28+
var posVals = posString.Split(',').Select(f => float.Parse(f, CultureInfo.InvariantCulture)).ToArray();
29+
PerfectDisplay.displayPosition = new Vector3(posVals[0], posVals[1], posVals[2]);
30+
}
31+
if (ModPrefs.GetString("PerfectionDisplay", "Score Ranges") == "")
32+
{
33+
ModPrefs.SetString("PerfectionDisplay", "Score Ranges", string.Join(",", PerfectDisplay.scoreRanges));
34+
}
35+
else
36+
{
37+
var rangeString = ModPrefs.GetString("PerfectionDisplay", "Score Ranges");
38+
PerfectDisplay.scoreRanges = rangeString.Split(',').Select(f => int.Parse(f, CultureInfo.InvariantCulture)).ToArray();
39+
}
40+
if (ModPrefs.GetString("PerfectionDisplay", "Colors") == "")
41+
{
42+
ModPrefs.SetString("PerfectionDisplay", "Colors", string.Join(",", PerfectDisplay.colors));
43+
}
44+
else
45+
{
46+
var rangeString = ModPrefs.GetString("PerfectionDisplay", "Colors");
47+
PerfectDisplay.colors = rangeString.Split(',');
48+
}
49+
if (PerfectDisplay.scoreRanges.Length+2 != PerfectDisplay.colors.Length) Console.WriteLine("[PerfectionDisplay] Config error - colors should have 2 more colors than there are score ranges");
50+
PerfectDisplay.showNumbers = ModPrefs.GetBool("PerfectionDisplay", "Show Count", PerfectDisplay.showNumbers, true);
51+
PerfectDisplay.showPercent = ModPrefs.GetBool("PerfectionDisplay", "Show Percent", PerfectDisplay.showPercent, true);
2152
}
2253

2354
private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)

0 commit comments

Comments
 (0)