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
|
Class = require("libs.hump.class")
Timer = require("libs.hump.timer")
require("core.constants")
Notifications = Class {
init = function(self, zoomFactor)
self.calculateWindowDimensions()
end,
messages={}
}
function Notifications:calculateWindowDimensions()
windowWidth, windowHeight = love.graphics.getDimensions()
end
function Notifications:update(dt)
for i,obj in pairs(self.messages) do
if obj.timer then
obj.timer:update(dt)
end
end
end
function Notifications:draw()
love.graphics.setFont(constants.defaultFont)
local defaultY = windowHeight - 20
for i,obj in pairs(self.messages) do
love.graphics.setColor(obj.color)
love.graphics.print(obj.message, 10, defaultY)
defaultY = defaultY - 15
end
end
function Notifications:send(message)
local messageItem={
message=message,
color={1, 0, 0, 1},
timer=nil
}
table.insert(self.messages, messageItem)
for i,obj in pairs(self.messages) do
if obj.timer==nil then
obj.timer = Timer.new()
obj.timer:tween(5, obj.color, {0, 0, 0, 0}, 'linear', function()
obj.timer:clear()
obj.timer = nil
table.remove(self.messages, 1)
end)
end
end
end
return Notifications
|