Skip to content

Commit f5a1502

Browse files
authored
Merge pull request #8 from SoulstoneAddons/dev
Issues fixed
2 parents ab730a2 + 9e6b4b9 commit f5a1502

File tree

9 files changed

+80
-33
lines changed

9 files changed

+80
-33
lines changed

SoulstoneSurvivorsSkada/Bootstrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ private void Update()
8282
{
8383
// order the spells by damage in ascending order
8484
PlayerSkadaHistory.DamageBySpellsOrdered = PlayerSkadaHistory.SortDamageBySpellsOrdered();
85+
86+
if (PlayerSkadaHistory.IsEmpty)
87+
{
88+
PlayerSkadaHistory.Reset();
89+
}
8590
}
8691
}
8792

SoulstoneSurvivorsSkada/History/PlayerSkadaHistory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal static class PlayerSkadaHistory
1616
/// <summary>
1717
/// If the history is empty or not
1818
/// </summary>
19-
public static bool IsEmpty => GameManagerUtil.GameStats.TotalDamageDonePerSkillIdNew.Count == 0;
19+
public static bool IsEmpty => GameManagerUtil.GameStats.TotalDamageDonePerSkillIdNewCount == 0;
2020

2121
public static bool IsStarted => SkadaTime.PlayerStartTime > 0;
2222

SoulstoneSurvivorsSkada/Interfaces/ISkadaView.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ public interface ISkadaView
2323
/// <param name="windowRect">Rectangle of the Window</param>
2424
/// <param name="windowID">ID of the Window</param>
2525
public void OnGUI(ref Rect windowRect, int windowID);
26+
27+
/// <summary>
28+
/// Called when the View is enabled
29+
/// </summary>
30+
public void OnEnable();
31+
32+
/// <summary>
33+
/// Called when the View is disabled
34+
/// </summary>
35+
public void OnDisable();
2636
}

SoulstoneSurvivorsSkada/Patchers/GamePatches.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public static void DoApplyEffects(ChangeHealthEffect __instance,
2626
}
2727

2828
// Hook into the ConfirmationPanel.OnConfirmSelected method to reset the SkadaHistory when the player restarts the game
29-
[HarmonyPatch(typeof(ConfirmationPanel), nameof(ConfirmationPanel.OnConfirmSelected))]
30-
[HarmonyPostfix]
31-
public static void OnRestartPressed()
32-
{
33-
PlayerSkadaHistory.Reset();
34-
}
29+
// [HarmonyPatch(typeof(ConfirmationPanel), nameof(ConfirmationPanel.OnConfirmSelected))]
30+
// [HarmonyPostfix]
31+
// public static void OnRestartPressed()
32+
// {
33+
// PlayerSkadaHistory.Reset();
34+
// }
3535
}

SoulstoneSurvivorsSkada/SkadaPlugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public override void Load()
3737
try
3838
{
3939
_bootstrapper = AddComponent<Bootstrapper>();
40+
Object.DontDestroyOnLoad(_bootstrapper.gameObject);
4041
}
4142
catch (Exception ex)
4243
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using UnityEngine;
2+
3+
namespace SoulstoneSurvivorsSkada;
4+
5+
public class TextureUtility
6+
{
7+
/// <summary>
8+
/// Texture for the Bar
9+
/// </summary>
10+
public static Texture2D BarTexture
11+
{
12+
get
13+
{
14+
// create a 1x1 texture with red color
15+
Texture2D texture = new Texture2D(1, 1, TextureFormat.RGBA32, false);
16+
// set the pixel to red
17+
texture.SetPixel(0, 0, Color.red);
18+
texture.wrapMode = TextureWrapMode.Repeat;
19+
// apply the changes
20+
texture.Apply();
21+
texture.hideFlags = HideFlags.DontSave;
22+
// return the texture
23+
return texture;
24+
}
25+
}
26+
}

SoulstoneSurvivorsSkada/Views/PlayerDamageMeterSkadaView.cs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,26 @@ public sealed class PlayerDamageMeterSkadaView : ISkadaView
1212
{
1313
public int ScrollPosition { get; set; }
1414
public string Title { get; set; } = "Skada - Player Damage";
15-
16-
/// <summary>
17-
/// Style for the Bar
18-
/// </summary>
19-
private static readonly GUIStyle BarStyle = new(GUI.skin.box)
15+
16+
private static GUIStyle BarStyle = new GUIStyle(GUI.skin.box)
2017
{
2118
normal =
2219
{
23-
background = BarTexture
20+
background = TextureUtility.BarTexture
2421
},
2522
overflow = new RectOffset(0,0,0,0),
2623
fixedHeight = ResUtility.GetHeight(20)
2724
};
2825

29-
private static readonly Texture2D Texture = BarTexture;
30-
31-
/// <summary>
32-
/// Texture for the Bar
33-
/// </summary>
34-
private static Texture2D BarTexture
26+
public void OnEnable()
3527
{
36-
get
37-
{
38-
// create a 1x1 texture with red color
39-
Texture2D texture = new Texture2D(1, 1, TextureFormat.RGBA32, false);
40-
// set the pixel to red
41-
texture.SetPixel(0, 0, Color.red);
42-
// apply the changes
43-
texture.Apply();
44-
// return the texture
45-
return texture;
46-
}
4728
}
48-
29+
30+
public void OnDisable()
31+
{
32+
33+
}
34+
4935
public void OnGUI(ref Rect windowRect, int windowID)
5036
{
5137
GUILayout.BeginVertical();
@@ -74,10 +60,12 @@ public void OnGUI(ref Rect windowRect, int windowID)
7460
Rect position = GUILayoutUtility.GetRect(0, ResUtility.GetHeight(20));
7561

7662
BarStyle.fixedHeight = ResUtility.GetHeight(20);
63+
64+
var barRect = new Rect(0, position.y, ResUtility.GetWidth(320) * percent, position.height);
7765

7866
// draw the percentage bar
79-
GUI.Box(new Rect(0, position.y, windowRect.width * percent, position.height),
80-
"", BarStyle);
67+
GUI.Box(barRect,
68+
GUIContent.none, BarStyle);
8169

8270
string text = $"{skillData.SkillName} - {damage.ToHumanReadableString()} - {percent:P2}";
8371

SoulstoneSurvivorsSkada/Views/PlayerDpsSkadaView.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,17 @@ public void OnGUI(ref Rect windowRect, int windowID)
2828
float dps = PlayerSkadaHistory.PlayerDps;
2929
GUILayout.Label($"DPS: {dps.ToHumanReadableString()}");
3030
}
31+
32+
public void OnEnable()
33+
{
34+
// TODO implement view logic
35+
}
36+
37+
/// <summary>
38+
/// Called when the View is disabled
39+
/// </summary>
40+
public void OnDisable()
41+
{
42+
// TODO implement view logic
43+
}
3144
}

SoulstoneSurvivorsSkada/Views/Window.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ public static void ChangeView<T>()
2828
if (Views.TryGetValue(typeof(T), out ISkadaView view))
2929
{
3030
// set the current view to the cached view
31+
_currentView?.OnDisable();
3132
_currentView = view;
33+
view?.OnEnable();
3234
return; // return early to avoid creating a new instance
3335
}
3436
// create a new instance of the view
3537
ISkadaView instance = Activator.CreateInstance<T>();
3638
// cache the view
3739
Views.Add(typeof(T), instance);
40+
_currentView?.OnDisable();
3841
// set the current view to the new instance
3942
_currentView = instance;
43+
instance?.OnEnable();
4044
}
4145
}

0 commit comments

Comments
 (0)