-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDisplaySystem.cs
More file actions
62 lines (50 loc) · 1.58 KB
/
DisplaySystem.cs
File metadata and controls
62 lines (50 loc) · 1.58 KB
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
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.UI;
namespace MusicDisplay;
internal class DisplaySystem : ModSystem
{
float Delta => (float)(Main._drawInterfaceGameTime.TotalGameTime.TotalSeconds - setTime.TotalSeconds);
float alpha = 0;
TimeSpan setTime = TimeSpan.MinValue;
MusicText text = default;
short lastMusicSlot = -1;
public static void SetDisplay(MusicText text)
{
if (Main.dedServ || Main.netMode == NetmodeID.Server)
return;
var system = ModContent.GetInstance<DisplaySystem>();
system.alpha = 0;
system.setTime = Main.gameTimeCache.TotalGameTime;
system.text = text;
}
public override void UpdateUI(GameTime gameTime)
{
if (Main.curMusic != lastMusicSlot && Main.musicVolume > 0)
{
lastMusicSlot = (short)Main.curMusic;
var musicText = MusicDatabase.GetMusicText(lastMusicSlot);
bool hide = ModContent.GetInstance<DisplayConfig>().HideUnknown;
if (musicText.ShouldDisplay() && (!hide || !musicText.IsUnknown))
SetDisplay(musicText);
}
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int inventoryIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Info Accessories Bar"));
layers.Insert(inventoryIndex + 1, new LegacyGameInterfaceLayer(
"MusicDisplay: Music Display",
delegate
{
if (lastMusicSlot > 0)
DisplayDrawing.DrawMusicDisplay(Delta, ref alpha, text);
return true;
},
InterfaceScaleType.UI)
);
}
}