-
Notifications
You must be signed in to change notification settings - Fork 1
/
HintManager.cs
126 lines (110 loc) · 3.99 KB
/
HintManager.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
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OlegEngine.GUI;
using OlegEngine;
namespace WheelOfSteamGames
{
class HintManager
{
/// <summary>
/// Speed at which the hints move in and out of the screen
/// </summary>
public static float MoveSpeed = 3;
class Hint
{
public Text hintText;
public float Duration;
public float Delay;
public float YReal;
public float YSmooth;
public string Name;
/// <summary>
/// Create a new hint object, to be used with the hint manager
/// </summary>
/// <param name="Text">The actual hint text</param>
/// <param name="duration">How long the hint should be displayed</param>
/// <param name="delay">Time to wait before the hint is actually displayed</param>
public Hint(string Text, float duration, float delay, string UniqueName)
{
hintText = new Text("defaultTitle", Text);
Delay = (float)Utilities.Time + delay;
Duration = Delay + duration;
float HintScale = (float)Utilities.window.Height / 700f;
hintText.SetScale(HintScale, HintScale);
hintText.SetPos((Utilities.window.Width / 2) - (hintText.GetTextLength() / 2) * hintText.ScaleW, Utilities.window.Height + 10);
this.YReal = this.YSmooth = hintText.Y;
Name = UniqueName;
}
public void Remove()
{
HintQueue.Remove( this );
}
}
private static List<Hint> HintQueue = new List<Hint>();
public static void Initialize()
{
GUIManager.PostDrawHUD += new GUIManager.OnDrawHUD(GUIManager_PostDrawHUD);
}
static void GUIManager_PostDrawHUD(EventArgs e)
{
for (int i = 0; i < HintQueue.Count; i++)
{
Hint h = HintQueue[i];
if (Utilities.Time > h.Delay)
{
if (Utilities.Time > h.Duration)
{
h.YReal = Utilities.window.Height + 10;
if (Math.Abs(h.YSmooth - h.YReal) > 0.5)
{
h.YSmooth = Utilities.Lerp(h.YSmooth, h.YReal, (float)Utilities.Frametime * MoveSpeed);
}
else
{
HintQueue.RemoveAt(i);
i--;
}
}
else
{
h.YReal = Utilities.window.Height - (h.hintText.GetTextHeight() + 20 * i + 20);
h.YSmooth = Utilities.Lerp(h.YSmooth, h.YReal, (float)Utilities.Frametime * MoveSpeed);
}
h.hintText.SetPos(h.hintText.X, h.YSmooth);
h.hintText.Draw();
}
else h.YReal = h.YSmooth = Utilities.window.Height + 10;
}
}
public static void AddHint(string Text, float delay, float time, string UniqueName = "")
{
Hint h = new Hint(Text, time, delay, UniqueName);
HintQueue.Add(h);
}
public static void RemoveHint(string name)
{
for (int i = 0; i < HintQueue.Count; i++)
{
if (HintQueue[i].Name == name)
{
HintQueue.RemoveAt(i);
i--;
}
}
}
public static void RemoveHintNice(string name)
{
for (int i = 0; i < HintQueue.Count; i++)
{
if (HintQueue[i].Name == name)
{
HintQueue[i].Duration = 0;
HintQueue[i].Delay = 0;
}
}
}
}
}