fork/m-overlay

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

blackops7799Started work on context menus Made APMDisplay its own seperate panel Renamed fonts Modified the script loading environement to just be a copy of _Ge093899

GUI
2.1 KiB100 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/ultimate-bold", 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.coloredMessage(...)
91	local args = {...}
92	notification.add(14, 5, 0.5, function(height, fade)
93		graphics.setColor(0, 0, 0, 255 * fade)
94		graphics.textOutline(args, 1, 1, 1)
95		graphics.setColor(255, 255, 255, 255 * fade)
96		graphics.print(args, 0, 0)
97	end)
98end
99
100return notification