-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicker.as
More file actions
272 lines (222 loc) · 9.09 KB
/
Copy pathTicker.as
File metadata and controls
272 lines (222 loc) · 9.09 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
* Copyright (c) 2023 MisfitMaid <misfit@misfitmaid.com>
* Use of this source code is governed by the MIT license, which
* can be found in the LICENSE file.
*/
namespace Ticker {
uint64 initTime = 0;
uint64 animStartTime = 0;
uint64 tickerOffsetTime = 0;
uint64 lastFrameTime = 0;
uint64 lastRefresh = 0;
TickerItem@[] tickerItems;
bool isRefreshing = false;
SQLite::Database@ cursedTimeDB;
void init() {
initTime = Time::Now;
animStartTime = Time::Now;
@cursedTimeDB = SQLite::Database(":memory:");
if (enableComponentClose) registerTaskbarProviderAddon(Close());
if (enableComponentClock) registerTaskbarProviderAddon(Clock());
if (enableComponentFPS) registerTaskbarProviderAddon(FPS());
if (enableComponentPing) registerTaskbarProviderAddon(Ping());
if (enableComponentCotD) registerTaskbarProviderAddon(COTD());
if (enableComponentTotDRecords) registerTickerItemProviderAddon(TMioTotDLeaderboardProvider());
if (enableComponentCampaignRecords) registerTickerItemProviderAddon(TMioCampaignLeaderboardProvider());
}
void step() {
TickerItemProvider@[]@ tips = getAllTickerItemProviders();
if (lastRefresh == 0 || lastRefresh + (refreshTime * 1000) < Time::Now) {
isRefreshing = true;
lastRefresh = Time::Now;
for (uint i = 0; i < tips.Length; i++) {
tips[i].OnUpdate();
}
isRefreshing = false;
} else {
return;
}
tickerItems.Resize(0);
for (uint i = 0; i < tips.Length; i++) {
TickerItem@[] ti = tips[i].getItems();
for (uint ii = 0; ii < ti.Length; ii++) {
tickerItems.InsertLast(ti[ii]);
}
}
if (tickerItems.Length > 1) {
tickerItems.Sort(function(const TickerItem@ const &in a, const TickerItem@ const &in b) {
if (a is null || b is null) return false;
return a.getSortTime() > b.getSortTime();
});
}
while (tickerCount > 0 && tickerItems.Length > tickerCount) {
tickerItems.RemoveAt(tickerCount);
}
}
void render() {
uint dt = Time::Now - lastFrameTime;
lastFrameTime = Time::Now;
if (!showOnHiddenOverlay && !UI::IsOverlayShown()) {
return;
}
if (GetApp().Editor !is null) return;
auto cmap = GetApp().Network.ClientManiaAppPlayground;
if (!showOnDriving && GetApp().RootMap !is null) {
if (GetApp().Editor !is null) return;
if (cmap.UI.UISequence == CGamePlaygroundUIConfig::EUISequence::Playing && !GetApp().Network.PlaygroundClientScriptAPI.IsInGameMenuDisplayed) {
return;
}
}
RenderTicker(dt);
if (debugMenu) RenderDebug();
}
void RenderTicker(uint dt) {
UI::DrawList@ dl = UI::GetBackgroundDrawList();
vec4 bgCol = bgColBase * globalColorMult * bgColMult;
vec4 textCol = textColBase * globalColorMult * textColMult;
vec4 textDisabledCol = textDisabledColBase * globalColorMult * textDisabledColMult;
vec2 spacing = UI::GetStyleVarVec2(UI::StyleVar::ItemInnerSpacing);
float height = UI::GetTextLineHeight() + 2*spacing.y;
vec4 tickerPos(0, Display::GetHeight() - height, Display::GetWidth(), height);
if (showOnTop) {
tickerPos.y = UI::IsOverlayShown() ? height : 0.f;
}
if (!IsHovered(tickerPos) || !pauseOnHover) {
tickerOffsetTime += dt;
}
dl.AddRectFilled(tickerPos, bgCol);
// draw t.io blurb
string opTag = "\\$3af" + Icons::Heartbeat + "\\$z";
string opTagPlus = " Powered by Trackmania.io";
uint startMS = 5000;
uint animMS = 250;
if (animStartTime + startMS > Time::Now) {
opTag += opTagPlus;
} else if (animStartTime + startMS + animMS > Time::Now) {
uint len = opTagPlus.Length;
float percentThroughAnim = 1.f - float(Time::Now - animStartTime - startMS) / float(animMS);
opTag += opTagPlus.SubStr(0, uint(float(len)*percentThroughAnim));
}
if (isRefreshing) {
opTag += " "+Icons::Undo;
}
vec2 opTagWidth = UI::MeasureString(opTag);
vec4 opTagBG(tickerPos.xy, opTagWidth + spacing*2);
// dl.AddRectFilled(opTagBG, bgCol);
dl.AddText(opTagBG.xy + spacing, textDisabledCol, opTag);
if (IsHovered(opTagBG)) {
animStartTime = Time::Now;
}
if (InvisibleButton(opTagBG)) {
OpenBrowserURL("https://trackmania.io");
}
// draw taskbar providers
vec2 taskbarOffset(tickerPos.z, tickerPos.w+tickerPos.y);
TaskbarProvider@[]@ taskbars = getAllTaskbarProviders();
for (uint i = 0; i < taskbars.Length; i++) {
string content = taskbars[i].getItemText();
if (content.Length == 0) continue;
vec2 cWid = UI::MeasureString(content) + spacing*2 + taskbarItemPadding;
taskbarOffset = vec2(taskbarOffset.x - cWid.x, taskbarOffset.y);
vec4 taskbarBG = vec4(taskbarOffset - vec2(0, cWid.y), cWid) + vec4(taskbarItemPadding.x/2, taskbarItemPadding.y/2, 0, 0);
// dl.AddRectFilled(taskbarBG, bgCol);
dl.AddText(taskbarBG.xy + spacing, textDisabledCol, content);
if (IsHovered(taskbarBG)) {
taskbars[i].OnItemHovered();
}
if (InvisibleButton(taskbarBG)) {
taskbars[i].OnItemClick();
}
}
vec4 clipping(opTagBG.z, 0, taskbarOffset.x - opTagBG.z, Display::GetHeight());
dl.PushClipRect(clipping);
// draw ticker here
vec4 tickerTextPos = tickerPos * vec4(1, 1, tickerOverRender, 1);
float offset = 0;
if (tickerTextPos.z != 0) {
offset = tickerTextPos.z + ((tickerRate * tickerOffsetTime) % tickerTextPos.z);
}
if (tickerItems.Length > 0) {
uint item = 0;
while (offset > 0.f) {
// i hate everything about this math
TickerItem@ ti = tickerItems[item%tickerItems.Length];
string tiText = ti.getItemText();
vec2 myWidth = UI::MeasureString(tiText) + (spacing*2);
offset -= myWidth.x + tickerItemPadding;
float myPos = tickerTextPos.z - myWidth.x - offset;
vec2 finalPos = vec2(myPos, tickerTextPos.y)+spacing;
dl.AddText(finalPos, textCol, tiText);
vec4 rect(vec2(myPos, tickerTextPos.y), myWidth);
if (IsHovered(rect)) {
ti.OnItemHovered();
}
if (InvisibleButton(rect)) {
ti.OnItemClick();
}
item++;
}
}
dl.PopClipRect();
}
void RenderDebug() {
if (UI::Begin("\\$3af" + Icons::Heartbeat + "\\$z Ticker Debug", debugMenu, UI::WindowFlags::None)) {
TaskbarProvider@[]@ taskbars = getAllTaskbarProviders();
for (uint i = 0; i < taskbars.Length; i++) {
string content = taskbars[i].getItemText();
if (content.Length == 0) continue;
if (UI::Button("Click###debugIconTb_"+i)) {
taskbars[i].OnItemClick();
}
UI::SameLine();
UI::Text(content);
if (UI::IsItemHovered()) {
taskbars[i].OnItemHovered();
}
}
UI::Separator();
for (uint i = 0; i < tickerItems.Length; i++) {
TickerItem@ ti = tickerItems[i];
string tiText = ti.getItemText();
if (tiText.Length == 0) continue;
if (UI::Button("Click###debugIconTi_"+i)) {
tickerItems[i].OnItemClick();
}
UI::SameLine();
UI::Text(tiText);
if (UI::IsItemHovered()) {
tickerItems[i].OnItemHovered();
}
}
}
UI::End();
}
/**
* UI::InvisibleButton only works inside windows i guess... so we make our own version
*/
bool InvisibleButton(vec4 rect) {
if (mouseDown && MouseIn(rect, mousePos)) {
mouseDown = false;
return true;
}
return false;
}
bool IsHovered(vec4 rect) {
return MouseIn(rect);
}
bool MouseIn(vec4 rect, vec2 pos = UI::GetMousePos()) {
return (pos.x >= rect.x && pos.x <= (rect.x + rect.z) && pos.y >= rect.y && pos.y <= (rect.y + rect.w));
}
bool mouseDown = false;
int mouseButton;
vec2 mousePos;
bool _mouseDown = false;
void OnMouseButton(bool down, int button, int x, int y) {
if (!_mouseDown) {
mouseDown = down;
mouseButton = button;
mousePos = vec2(x, y);
}
_mouseDown = down;
}
}