FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
Notification.lua
Go to the documentation of this file.
1require "ISUI/ISPanel"
3PFW_Notification = ISPanel:derive("PFW_Notification")
5function PFW_Notification:initialise()
7
8 ISPanel.initialise(self)
9
10 self.textLabel = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Medium, self.text), self:getY() - self:getHeight() / 2 + getTextManager():MeasureStringY(UIFont.Medium, self.text) / 2, self:getHeight(), self.text, 1, 1, 1, 1, UIFont.Medium, true)
11 self.textLabel.r = 0
12 self.textLabel.g = 0
13 self.textLabel.b = 0
14 self.textLabel.a = 1
15 self.textLabel:initialise()
16 self:addChild(self.textLabel)
18 self:restartFadeOut()
20 FrameworkZ.Timers:Create("NotificationSlide" .. self.ID, 0, 0, function()
21 if self.x > self.x2 then
22 self:setX(self:getX() - self:getWidth() * 0.05)
23 else
24 self:setX(self.x2)
25 FrameworkZ.Timers:Remove("NotificationSlide" .. self.ID)
26 end
27 end)
28end
29
30function PFW_Notification:restartFadeOut()
31 self.isExpiring = false
32 self.hasExpired = false
33
34 if FrameworkZ.Timers:Exists("NotificationFadeDelay" .. self.ID) then
35 FrameworkZ.Timers:Remove("NotificationFadeDelay" .. self.ID)
36 end
37
38 FrameworkZ.Timers:Create("NotificationFadeDelay" .. self.ID, self.duration, 1, function()
39 self.hasExpired = true
40 end)
41end
42
43function PFW_Notification:onMouseMove(x, y)
44 ISPanel.onMouseMove(self, x, y)
45
46 if not self.hasEntered then
47 self.hasEntered = true
48
49 if not self.hasFullyExpired then
50 self:restartFadeOut()
51 self.backgroundColor.a = math.min(self.originalAlpha - 0.25, 1)
52 end
53 end
54end
55
56function PFW_Notification:onMouseMoveOutside(x, y)
57 ISPanel.onMouseMoveOutside(self, x, y)
58
59 if self.hasEntered then
60 self.hasEntered = false
61
62 if not self.hasFullyExpired then
63 self.backgroundColor.a = self.originalAlpha
64 end
65 end
66end
67
68function PFW_Notification:update()
69 ISPanel.update(self)
70end
71
72function PFW_Notification:new(type, text, duration, playerObject)
73 local padding = 10
74 local margin = 10
75 local textWidth = getTextManager():MeasureStringX(UIFont.Medium, text)
76 local textHeight = getTextManager():MeasureStringY(UIFont.Medium, text)
77 local color = FrameworkZ.Notifications.Colors[type]
78 local x = getCore():getScreenWidth() - textWidth - padding - margin * 2
79 local y = padding
80 local width = textWidth + margin * 2
81 local height = textHeight + margin * 2
82
83 local o = {}
84
85 o = ISPanel:new(getCore():getScreenWidth(), y, width, height)
86 setmetatable(o, self)
88 o.backgroundColor = {r = color.r, g = color.g, b = color.b, a = color.a}
89 o.borderColor = {r=1, g=1, b=1, a=color.a}
90 o.moveWithMouse = false
91 o.keepOnScreen = false
92 o.text = text
93 o.duration = duration
94 o.playerObject = playerObject
95 o.x2 = x
96 o.y2 = y
97 o.width2 = width
98 o.height2 = height
99 o.originalAlpha = color.a
100
101 return o
102end
103
104return PFW_Notification
void local color()
void local y()
void self uiHelper()
void local x()
void local height()
void local width
void type()
void self self
Definition MainMenu.lua:85
void self hasExpired()
void PFW_Notification()
void processingNotification backgroundColor a()
void processingNotification hasFullyExpired()
void notification isExpiring()
void FrameworkZ DollarFormats __index()
FrameworkZ global table.
void onMouseMoveOutside(x, y)
void onMouseMove(x, y)