forked from maddie480/DashCountMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDashCountDisplayInLevel.cs
executable file
·123 lines (97 loc) · 4.54 KB
/
DashCountDisplayInLevel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using Celeste.Mod.CollabUtils2;
using Celeste.Mod.CollabUtils2.UI;
using Microsoft.Xna.Framework;
using Monocle;
using MonoMod.Utils;
using System;
using System.Collections.Generic;
namespace Celeste.Mod.DashCountMod {
class DashCountDisplayInLevel : Entity {
private Session session;
private DashCountModSettings.ShowDashCountInGameOptions format;
private Level level;
private TotalStrawberriesDisplay berryCounter;
private SpeedrunTimerDisplay speedrunTimer;
private bool collabUtilsExists;
private MTexture bg = GFX.Gui["DashCountMod/extendedStrawberryCountBG"];
private MTexture dashIcon = GFX.Gui["collectables/dashes"];
private MTexture x = GFX.Gui["x"];
public DashCountDisplayInLevel(Session session, DashCountModSettings.ShowDashCountInGameOptions format) {
this.session = session;
this.format = format;
Tag = (Tags.HUD | Tags.Global | Tags.PauseUpdate | Tags.TransitionUpdate);
Position = new Vector2(0, -1000);
}
public void SetFormat(DashCountModSettings.ShowDashCountInGameOptions format) {
this.format = format;
}
public override void Awake(Scene scene) {
base.Awake(scene);
level = SceneAs<Level>();
berryCounter = Scene.Entities.FindFirst<TotalStrawberriesDisplay>();
speedrunTimer = Scene.Entities.FindFirst<SpeedrunTimerDisplay>();
collabUtilsExists = Everest.Loader.DependencyLoaded(new EverestModuleMetadata { Name = "CollabUtils2", Version = new Version(1, 6, 7) });
}
public override void Update() {
base.Update();
float y = 85f;
// leave room for the speedrun timer.
if (speedrunTimer.DrawLerp > 0f) {
if (Settings.Instance.SpeedrunClock == SpeedrunType.Chapter) {
y += 58f;
} else if (Settings.Instance.SpeedrunClock == SpeedrunType.File) {
y += 78f;
}
}
// leave room for the strawberries counter.
if (berryCounter.DrawLerp > 0f) {
y += 78f;
}
if (collabUtilsExists) {
y += getSpeedBerryOffset();
}
Y = y;
}
private float getSpeedBerryOffset() {
SpeedBerryTimerDisplay speedBerryTimer = level.Tracker.GetEntity<SpeedBerryTimerDisplay>();
if (speedBerryTimer != null && CollabModule.Instance.Settings.SpeedBerryTimerPosition == CollabSettings.SpeedBerryTimerPositions.TopLeft) {
float offsetY = 110f;
if (new DynData<SpeedBerryTimerDisplay>(speedBerryTimer).Get<long>("startChapterTimer") == -1) {
// more times are displayed.
offsetY += 70f;
}
return offsetY;
}
// no speed berry timer, or it is not on the top left so it doesn't affect us.
return 0f;
}
public override void Render() {
base.Render();
string count = getCountToDisplay();
float dashCountSize = ActiveFont.Measure(count).X;
bg.Draw(Position + new Vector2(-402 + dashCountSize, 0));
dashIcon.Draw(Position + new Vector2(9, -36));
x.Draw(Position + new Vector2(94, -14));
ActiveFont.DrawOutline(count, Position + new Vector2(144, -26), Vector2.Zero, Vector2.One, Color.White, 2f, Color.Black);
}
private string getCountToDisplay() {
int dashCountInLevel = 0;
AreaKey area = SceneAs<Level>().Session.Area;
if ((DashCountModModule.Instance._SaveData as DashCountModSaveData).DashCountPerLevel.TryGetValue(area.GetSID(), out Dictionary<AreaMode, int> areaModes)) {
if (areaModes.TryGetValue(area.Mode, out int totalDashes)) {
dashCountInLevel = totalDashes;
}
}
switch (format) {
case DashCountModSettings.ShowDashCountInGameOptions.Session:
return "" + session.Dashes;
case DashCountModSettings.ShowDashCountInGameOptions.Chapter:
return "" + dashCountInLevel;
case DashCountModSettings.ShowDashCountInGameOptions.File:
return "" + SaveData.Instance.TotalDashes;
default:
return SaveData.Instance.TotalDashes + " (" + dashCountInLevel + ")";
}
}
}
}