|
|
@ -11,14 +11,14 @@ function NotificationsList:New() |
|
|
|
|
|
|
|
|
|
|
|
-- Create a frame for the notifications |
|
|
|
-- Create a frame for the notifications |
|
|
|
self.frame = CreateFrame("Frame", "BastionNotificationsList", UIParent) |
|
|
|
self.frame = CreateFrame("Frame", "BastionNotificationsList", UIParent) |
|
|
|
self.frame:SetSize(300, 100) |
|
|
|
self.frame:SetSize(600, 60) |
|
|
|
self.frame:SetPoint("TOP", UIParent, "TOP", 0, -100) |
|
|
|
self.frame:SetPoint("TOP", UIParent, "TOP", 0, -100) |
|
|
|
self.frame:SetFrameStrata("HIGH") |
|
|
|
self.frame:SetFrameStrata("HIGH") |
|
|
|
|
|
|
|
|
|
|
|
-- Remove notifications after 5 seconds |
|
|
|
-- Remove notifications after 5 seconds |
|
|
|
C_Timer.NewTicker(0.1, function() |
|
|
|
C_Timer.NewTicker(0.1, function() |
|
|
|
for i, notification in ipairs(self.notifications) do |
|
|
|
for i, notification in ipairs(self.notifications) do |
|
|
|
if GetTime() - notification.addedAt > 2 then |
|
|
|
if GetTime() - notification.addedAt > notification.duration then |
|
|
|
notification:Remove() |
|
|
|
notification:Remove() |
|
|
|
table.remove(self.notifications, i) |
|
|
|
table.remove(self.notifications, i) |
|
|
|
end |
|
|
|
end |
|
|
@ -34,13 +34,15 @@ local Notification = { |
|
|
|
Notification.__index = Notification |
|
|
|
Notification.__index = Notification |
|
|
|
|
|
|
|
|
|
|
|
-- Constructor |
|
|
|
-- Constructor |
|
|
|
function Notification:New(list, icon, text) |
|
|
|
function Notification:New(list, icon, text, duration) |
|
|
|
local self = setmetatable({}, Notification) |
|
|
|
local self = setmetatable({}, Notification) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not duration then duration = 2 end |
|
|
|
|
|
|
|
|
|
|
|
-- Create a frame for the notification |
|
|
|
-- Create a frame for the notification |
|
|
|
self.frame = CreateFrame("Frame", nil, list.frame) |
|
|
|
self.frame = CreateFrame("Frame", nil, list.frame) |
|
|
|
self.frame:SetSize(300, 100) |
|
|
|
self.frame:SetSize(5, 5) |
|
|
|
self.frame:SetPoint("TOP", list.frame, "TOP", 0, 0) |
|
|
|
self.frame:SetPoint("CENTER", list.frame, "CENTER", 0, 0) |
|
|
|
self.frame:SetFrameStrata("HIGH") |
|
|
|
self.frame:SetFrameStrata("HIGH") |
|
|
|
|
|
|
|
|
|
|
|
-- Create a texture for the icon |
|
|
|
-- Create a texture for the icon |
|
|
@ -50,12 +52,16 @@ function Notification:New(list, icon, text) |
|
|
|
self.icon:SetTexture(icon) |
|
|
|
self.icon:SetTexture(icon) |
|
|
|
|
|
|
|
|
|
|
|
-- Create a fontstring for the text |
|
|
|
-- Create a fontstring for the text |
|
|
|
self.text = self.frame:CreateFontString(nil, "BACKGROUND", "GameFontNormal") |
|
|
|
self.text = self.frame:CreateFontString(nil, "BACKGROUND", "NumberFontNormal") |
|
|
|
self.text:SetPoint("CENTER", self.frame, "CENTER", 10, 0) |
|
|
|
self.text:SetPoint("LEFT", self.frame, "LEFT", 32 + 16, 0) |
|
|
|
self.text:SetText(text) |
|
|
|
self.text:SetText(text) |
|
|
|
self.text:SetFont("Fonts\\FRIZQT__.TTF", 14) |
|
|
|
self.text:SetFont("Fonts\\OpenSans-Bold.ttf", 18) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- set the frame size to the size of the text + icon |
|
|
|
|
|
|
|
self.frame:SetSize(self.text:GetStringWidth() + 32 + 16, 32) |
|
|
|
|
|
|
|
|
|
|
|
self.addedAt = GetTime() |
|
|
|
self.addedAt = GetTime() |
|
|
|
|
|
|
|
self.duration = duration |
|
|
|
self.list = list |
|
|
|
self.list = list |
|
|
|
|
|
|
|
|
|
|
|
return self |
|
|
|
return self |
|
|
@ -75,9 +81,9 @@ function Notification:Remove() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Add a notification to the list |
|
|
|
-- Add a notification to the list |
|
|
|
function NotificationsList:AddNotification(icon, text) |
|
|
|
function NotificationsList:AddNotification(icon, text, duration) |
|
|
|
-- Create a new notification |
|
|
|
-- Create a new notification |
|
|
|
local notification = Notification:New(self, icon, text) |
|
|
|
local notification = Notification:New(self, icon, text, duration) |
|
|
|
|
|
|
|
|
|
|
|
-- Add the notification to the list |
|
|
|
-- Add the notification to the list |
|
|
|
table.insert(self.notifications, notification) |
|
|
|
table.insert(self.notifications, notification) |
|
|
@ -92,7 +98,7 @@ function NotificationsList:Update() |
|
|
|
-- Loop through the notifications |
|
|
|
-- Loop through the notifications |
|
|
|
for i, notification in ipairs(self.notifications) do |
|
|
|
for i, notification in ipairs(self.notifications) do |
|
|
|
-- Set the position of the notification |
|
|
|
-- Set the position of the notification |
|
|
|
notification.frame:SetPoint("TOP", self.frame, "TOP", 0, -50 * (i - 1)) |
|
|
|
notification.frame:SetPoint("CENTER", self.frame, "CENTER", 0, -42 * (i - 1)) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|