fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosAdded a 20xx overlay theme Made the default skip track combo L+DPAD_RIGHTe9088ad

settings-overhaul
2.8 KiB128 linesraw
1local graphics = love.graphics
2local newImage = graphics.newImage
3local newFont = graphics.newFont
4local timer = love.timer
5
6local log = require("log")
7
8local notification = {
9	messages = {},
10	font = newFont("fonts/melee-bold.otf", 12),
11	padding = 8,
12}
13
14local dummy = function(height, fade) end
15
16function notification.add(height, length, fade, draw)
17	height = height or 16
18	length = length or 3
19	fade = fade or 0.75
20
21	local now = timer.getTime()
22
23	table.insert(notification.messages, {
24		time = now,
25		length = length,
26		fade = fade,
27		finish = now + length + fade,
28
29		height = height,
30
31		draw = draw or dummy,
32
33		lerp = {},
34	})
35end
36
37function notification.update(x, y)
38	local now = timer.getTime()
39
40	local prevh = 0
41
42	for k, message in pairs(notification.messages) do
43		if (message.finish >= now) then
44			x = x * 0.5 + (message.lerp.x or x) * 0.5
45			y = y * 0.5 + (message.lerp.y or y) * 0.5
46			y = y + prevh/2 + notification.padding/2
47
48			message.lerp.x = x
49			message.lerp.y = y
50
51			prevh = message.height
52		end
53	end
54	
55	for k, message in pairs(notification.messages) do
56		if (message.finish >= now) then
57			return
58		end
59	end
60	
61	notification.messages = {}
62end
63
64function notification.draw()
65	local now = timer.getTime()
66	for k, message in pairs(notification.messages) do
67
68		local fade = 1
69
70		if now >= message.time + message.length then
71			fade = 1-((now - message.time - message.length)/message.fade)
72		end
73
74		local x, y = message.lerp.x, message.lerp.y
75
76		if x and y then
77			graphics.push("transform")
78			graphics.translate(x, y)
79			graphics.setFont(notification.font)
80			graphics.setColor(255, 255, 255, 255 * fade)
81			local succ, ret = xpcall(message.draw, debug.traceback, message.height, fade)
82			if not succ then
83				log.error("notification error: %s", ret)
84			end
85			graphics.pop()
86		end
87	end
88end
89
90function notification.error(text)
91	love.window.requestAttention()
92	notification.add(14, 10, 0.75, function(height, fade)
93		graphics.setColor(0, 0, 0, 255 * fade)
94		graphics.textOutline(text, 1, 1, 1)
95		graphics.setColor(241, 73, 82, 255 * fade)
96		graphics.print(text, 0, 0)
97	end)
98end
99
100function notification.warning(text)
101	notification.add(14, 5, 0.75, function(height, fade)
102		graphics.setColor(0, 0, 0, 255 * fade)
103		graphics.textOutline(text, 1, 1, 1)
104		graphics.setColor(255, 242, 0, 255 * fade)
105		graphics.print(text, 0, 0)
106	end)
107end
108
109function notification.info(text)
110	notification.add(14, 5, 0.75, function(height, fade)
111		graphics.setColor(0, 0, 0, 255 * fade)
112		graphics.textOutline(text, 1, 1, 1)
113		graphics.setColor(79, 202, 255, 255 * fade)
114		graphics.print(text, 0, 0)
115	end)
116end
117
118function notification.coloredMessage(...)
119	local args = {...}
120	notification.add(14, 5, 0.75, function(height, fade)
121		graphics.setColor(0, 0, 0, 255 * fade)
122		graphics.textOutline(args, 1, 1, 1)
123		graphics.setColor(255, 255, 255, 255 * fade)
124		graphics.print(args, 0, 0)
125	end)
126end
127
128return notification