Skip to content

Commit ffd7751

Browse files
authored
Merge pull request #5 from SoulstoneMeter/dev
Fixed bugs
2 parents df1993d + e1edadb commit ffd7751

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

SoulstoneSurvivorsSkada/Bootstrapper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Il2CppInterop.Runtime.InteropTypes.Arrays;
99
using Il2CppSystem.Collections.Generic;
1010
using Il2CppSystem.IO;
11+
using SoulstoneSurvivorsSkada.Logging;
1112
using SoulstoneSurvivorsSkada.Patchers;
1213
using SoulstoneSurvivorsSkada.Views;
1314
using UnityEngine;
@@ -77,10 +78,10 @@ private void Update()
7778
return;
7879

7980
// every second order the spells by damage to reduce the calls
80-
if (Time.time % 1.0f < 0.01f)
81+
if (Time.frameCount % 60 == 0)
8182
{
8283
// order the spells by damage in ascending order
83-
PlayerSkadaHistory.DamageBySpellsOrdered = PlayerSkadaHistory.Sort();
84+
PlayerSkadaHistory.DamageBySpellsOrdered = PlayerSkadaHistory.SortDamageBySpellsOrdered();
8485
}
8586
}
8687

SoulstoneSurvivorsSkada/History/PlayerSkadaHistory.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,23 @@ internal static class PlayerSkadaHistory
3636
/// <summary>
3737
/// Ordered array of spells by damage
3838
/// </summary>
39-
public static Il2CppReferenceArray<GameStatsSkillData> DamageBySpellsOrdered { get; set; } = Sort();
40-
41-
/// <summary>
42-
/// Sort the spells by damage in ascending order
43-
/// </summary>
44-
/// <returns></returns>
45-
public static Il2CppReferenceArray<GameStatsSkillData> Sort()
39+
public static Il2CppReferenceArray<GameStatsSkillData> DamageBySpellsOrdered =
40+
SortDamageBySpellsOrdered();
41+
42+
public static Il2CppReferenceArray<GameStatsSkillData> SortDamageBySpellsOrdered()
4643
{
47-
// get the array of spells
4844
Il2CppReferenceArray<GameStatsSkillData> spells = DamageBySpells;
49-
// get the length of the array
50-
int length = spells.Length;
51-
// if the array is empty or has only one element
52-
if (length <= 1)
53-
// return the array
54-
return spells;
55-
56-
// sort the array
57-
Array.Sort<GameStatsSkillData>(spells, (a, b) => b.FloatValue.CompareTo(a.FloatValue));
58-
59-
// return the ordered array
45+
for (int a = 0; a < spells.Count - 1; a++)
46+
{
47+
for (int b = 0; b < spells.Count - a - 1; b++)
48+
{
49+
if (spells[b].FloatValue > spells[b + 1].FloatValue)
50+
{
51+
(spells[b], spells[b + 1]) = (spells[b + 1], spells[b]);
52+
}
53+
}
54+
}
55+
6056
return spells;
6157
}
6258

SoulstoneSurvivorsSkada/Utilities/ResUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public static float GetHeight(float height)
1919

2020
public static int GetFontSize(int i)
2121
{
22-
return (int) (i * (Screen.width / DefaultWidth));
22+
return (int) (i * (Screen.height / DefaultHeight));
2323
}
2424
}

SoulstoneSurvivorsSkada/Views/PlayerDamageMeterSkadaView.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using Il2CppInterop.Runtime.InteropTypes.Arrays;
34
using Il2CppSystem.Collections.Generic;
45
using SoulstoneSurvivorsSkada.Extensions;
@@ -21,9 +22,12 @@ public sealed class PlayerDamageMeterSkadaView : ISkadaView
2122
{
2223
background = BarTexture
2324
},
24-
fixedHeight = 20
25+
overflow = new RectOffset(0,0,0,0),
26+
fixedHeight = ResUtility.GetHeight(20)
2527
};
2628

29+
private static readonly Texture2D Texture = BarTexture;
30+
2731
/// <summary>
2832
/// Texture for the Bar
2933
/// </summary>
@@ -48,6 +52,7 @@ public void OnGUI(ref Rect windowRect, int windowID)
4852
{
4953
// save spells into a variable to avoid multiple calls
5054
float totalDamage = PlayerSkadaHistory.PlayerTotalDamage;
55+
5156
Il2CppReferenceArray<GameStatsSkillData> spells = PlayerSkadaHistory.DamageBySpellsOrdered;
5257

5358
GUILayout.Label($"DPS: {PlayerSkadaHistory.PlayerDps.ToHumanReadableString()}");
@@ -62,23 +67,27 @@ public void OnGUI(ref Rect windowRect, int windowID)
6267
if (skillData.SkillNameHash == 0) continue;
6368
// get the damage value and make it positive
6469
float damage = Mathf.Abs(skillData.FloatValue);
65-
6670
// calculate the percentage of the damage
6771
float percent = skillData.GetPercent(totalDamage);
6872

6973
// get the position of the GUI
7074
Rect position = GUILayoutUtility.GetRect(0, ResUtility.GetHeight(20));
75+
76+
BarStyle.fixedHeight = ResUtility.GetHeight(20);
7177

7278
// draw the percentage bar
73-
GUI.Box(new Rect(position.x, position.y, windowRect.width * percent, position.height),
79+
GUI.Box(new Rect(0, position.y, windowRect.width * percent, position.height),
7480
"", BarStyle);
75-
76-
// set font size scaled by the resolution
77-
GUI.skin.label.fontSize = ResUtility.GetFontSize(14);
7881

82+
string text = $"{skillData.SkillName} - {damage.ToHumanReadableString()} - {percent:P2}";
83+
84+
// set font size
85+
GUI.skin.label.fontSize = ResUtility.GetFontSize(12);
86+
7987
// write the spell name, damage, and percentage to the GUI
80-
GUI.Label(new Rect(position.x, position.y, position.width, position.height),
81-
$"{skillData.SkillName} - {damage.ToHumanReadableString()} - {percent:P2}");
88+
// allow overflow to the next line
89+
GUI.Label(new Rect(0, position.y, windowRect.width, position.height),
90+
text);
8291

8392
// Add some space between the bars
8493
GUILayout.Space(ResUtility.GetHeight(5));

0 commit comments

Comments
 (0)