5--! \brief
Notifications module for FrameworkZ. Queues and sends notifications.
6--! \class FrameworkZ.Notifications
7FrameworkZ.Notifications = {}
8FrameworkZ.Notifications.__index = FrameworkZ.Notifications
9FrameworkZ.Notifications.Queue = {}
10FrameworkZ.Notifications.List = {}
11FrameworkZ.Notifications.Types = {
18FrameworkZ.Notifications.Colors = {
19 Default = {r = 1, g = 1, b = 1, a = 1},
20 Info = {r = 0.051, g = 0.792, b = 0.941, a = 1},
21 Success = {r = 0.098, g = 0.529, b = 0.329, a = 1},
22 Warning = {r = 1, g = 0.757, b = 0.027, a = 1},
23 Danger = {r = 0.863, g = 0.208, b = 0.271, a = 1}
25FrameworkZ.Notifications = FrameworkZ.Foundation:NewModule(FrameworkZ.Notifications, "Notifications")
27function FrameworkZ.Notifications:ProcessQueue(isProcessingContinued)
28 if not (isProcessingContinued or not self.isProcessing) and not (#self.Queue > 0 or #self.List > 0) then return false end
30 if isProcessingContinued or not self.isProcessing then
31 if #self.Queue > 0 then
32 self.isProcessing = true
33 local queuedNotification = self.Queue[1]
35 queuedNotification:initialise()
37 if queuedNotification.parentUI then
38 queuedNotification.parentUI:addChild(queuedNotification)
40 queuedNotification:addToUIManager()
43 local player = FrameworkZ.Players:GetPlayerByID(getPlayer():getUsername())
44 if player then player:PlayLocalSound("pfw_lightswitch2") end
46 table.remove(self.Queue, 1)
47 table.insert(self.List, 1, queuedNotification)
49 if #self.List > 1 then
50 for i = 2, #self.List, 1 do
51 local position = i - 1
52 local topNotification = self.List[1]
53 local notification = self.List[i]
54 notification:setY(topNotification:getY() + notification:getHeight() * position + 10 * position)
58 FrameworkZ.Timers:Simple(1, function()
59 self.isProcessing = self:ProcessQueue(true)
63 elseif #self.List > 0 then
64 self.isProcessing = true
65 local processingID = nil
67 for i = 1, #self.List, 1 do
68 local notification = self.List[i]
69 local expired = notification.hasExpired
72 notification.isExpiring = true
78 if not processingID then return false end
80 local processingNotification = self.List[processingID]
82 FrameworkZ.Timers:Create("NotificationFadeOut", 0, 0, function()
83 if processingNotification.isExpiring and processingNotification.textLabel.a > 0 then
84 processingNotification.backgroundColor.a = processingNotification.backgroundColor.a - processingNotification.originalAlpha * 0.01
85 processingNotification.borderColor.a = processingNotification.borderColor.a - processingNotification.originalAlpha * 0.01
86 processingNotification.textLabel.a = processingNotification.textLabel.a - 1 * 0.01
87 elseif processingNotification.isExpiring and FrameworkZ.Timers:Exists("NotificationFadeOut") then
88 FrameworkZ.Timers:Remove("NotificationFadeOut")
89 processingNotification.hasFullyExpired = true
90 processingNotification.backgroundColor.a = 0
91 processingNotification.borderColor.a = 0
92 processingNotification.textLabel.a = 0
94 FrameworkZ.Timers:Simple(0.5, function()
95 for i = processingID, #self.List, 1 do
96 local notification = self.List[i]
98 if not notification.isExpiring then
99 notification:setY(notification:getY() - (processingNotification:getHeight() + 10))
103 processingNotification:removeFromUIManager()
104 table.remove(self.List, processingID)
106 FrameworkZ.Timers:Simple(1, function()
107 self.isProcessing = self:ProcessQueue(true)
110 elseif not processingNotification.hasFullyExpired and not processingNotification.isExpiring then
111 FrameworkZ.Timers:Remove("NotificationFadeOut")
112 processingNotification.backgroundColor.a = math.min(processingNotification.originalAlpha + 0.25, 1)
113 processingNotification.borderColor.a = processingNotification.originalAlpha
114 processingNotification.textLabel.a = 1
116 FrameworkZ.Timers:Simple(1, function()
117 self.isProcessing = self:ProcessQueue(true)
127--! \brief Adds a notification to the queue.
128--! \param message \string The message to display.
129--! \param notificationType \string The type of notification to display. See notification types.
130--! \param duration \integer The duration the notification should be displayed for.
131--! \param ui \object The UI object that would cover where notifications display. Useful if you want to display notifications over top of a specific UI object.
132--! \return \object The notification UI object.
133function FrameworkZ.Notifications:AddToQueue(message, notificationType, duration, ui)
134 if not message then return end
136 local notification = FrameworkZ.UI.Notification:new(notificationType or FrameworkZ.Notifications.Types.Default, message, duration or 10, getPlayer())
139 notification.parentUI = ui
142 table.insert(self.Queue, notification)
144 if not self.isProcessing then
145 self.isProcessing = self:ProcessQueue(false)
152function FrameworkZ.Notifications:OnGameStart()
153 FrameworkZ.Timers:Create("NotificationTick", 0.5, 0, function()
154 if not self.isProcessing then
155 self.isProcessing = self:ProcessQueue(false)
161function FrameworkZ.Notifications:PlayerTick(isoPlayer)
162 if not self.isProcessing then
163 self.isProcessing = self:ProcessQueue(false)
167FrameworkZ.Foundation:RegisterModule(FrameworkZ.Notifications)
void local topNotification()
void local processingNotification()
void local processingID()
void local notification()
Notifications module for FrameworkZ. Queues and sends notifications.
void PlayerTick(isoPlayer)
FrameworkZ Notifications Colors
object AddToQueue(message, notificationType, duration, ui)
Adds a notification to the queue.
FrameworkZ Notifications __index
void ProcessQueue(isProcessingContinued)
FrameworkZ Notifications List
FrameworkZ Notifications Types
FrameworkZ Notifications Queue