-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMessageFrame.lua
More file actions
152 lines (118 loc) · 5.98 KB
/
MessageFrame.lua
File metadata and controls
152 lines (118 loc) · 5.98 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
local L = LibStub("AceLocale-3.0"):GetLocale("CritMatic")
local MESSAGE_SPACING = 3
local activeMessages = {}
--/run CritMatic.ShowNewCritMessage("Killing Spree", 300)CritMatic.ShowNewNormalMessage("Killing Spree",435)
-- Utility function to adjust message positions
local function AdjustMessagePositions()
-- Position the first message at the top
activeMessages[1]:SetPoint("CENTER", UIParent, "CENTER", 0, 350)
-- Position subsequent messages relative to the previous one
for i = 2, #activeMessages do
activeMessages[i]:SetPoint("TOP", activeMessages[i - 1], "BOTTOM", 0, -MESSAGE_SPACING)
end
end
-- Utility function to remove the oldest message and adjust the rest
local function RemoveOldestMessage()
local oldestMessage = table.remove(activeMessages) -- Remove the oldest message (first in the table)
-- Hide the message frame and perform any necessary cleanup
if oldestMessage then
oldestMessage:Hide()
end
end
Critmatic.MessageFrame = {}
function Critmatic.MessageFrame:CreateMessage(text, r, g, b)
local MAX_MESSAGES = Critmatic.db.profile.alertNotificationFormat.global.maxMessages
local delayInSeconds = 0.45
local function delayedExecution()
-- Replace frame creation with a call to CreateNewMessageFrame()
local f = Critmatic.CreateNewMessageFrame()
-- Set the text and color
f.text:SetText(text)
f.text:SetTextColor(r, g, b)
-- Create or update the fade-out animation (if it's not already in CreateNewMessageFrame)
f.fadeOut = f:CreateAnimationGroup()
local fade = f.fadeOut:CreateAnimation("Alpha")
fade:SetFromAlpha(1)
fade:SetToAlpha(0)
fade:SetDuration(Critmatic.db.profile.alertNotificationFormat.global.fadeTime)
fade:SetStartDelay(Critmatic.db.profile.alertNotificationFormat.global.startDelay)
f.fadeOut:SetScript("OnFinished", function()
f:Hide()
end)
-- Play the animations
f.bounce:Play()
f.fadeOut:Play()
-- Insert the new message at the beginning
table.insert(activeMessages, 1, f)
-- Adjust positions of all messages
AdjustMessagePositions()
-- Remove the oldest message if there are too many
if #activeMessages > MAX_MESSAGES then
RemoveOldestMessage()
end
return f
end
-- Delay the execution using C_Timer
C_Timer.After(delayInSeconds, delayedExecution)
end
local message = ""
function Critmatic.ShowNewCritMessage(spellName, amount)
if Critmatic.db.profile.alertNotificationFormat.global.isUpper then
-- If spellName does not end with 'Heal', use the format string as is
message = string.upper(string.format(Critmatic.db.profile.alertNotificationFormat.strings
.critAlertNotificationFormat, spellName, amount))
else
message = string.format(Critmatic.db.profile.alertNotificationFormat.strings.critAlertNotificationFormat,
spellName, amount)
end
local r, g, b = unpack(Critmatic.db.profile.fontSettings.fontColorCrit)
Critmatic.MessageFrame:CreateMessage(message, r, g, b)
end
function Critmatic.ShowNewNormalMessage(spellName, amount)
if Critmatic.db.profile.alertNotificationFormat.global.isUpper then
message = string.upper(string.format(Critmatic.db.profile.alertNotificationFormat.strings
.hitAlertNotificationFormat, spellName, amount))
else
message = string.format(Critmatic.db.profile.alertNotificationFormat.strings.hitAlertNotificationFormat,
spellName, amount)
end
local r, g, b = unpack(Critmatic.db.profile.fontSettings.fontColor)
Critmatic.MessageFrame:CreateMessage(message, r, g, b)
end
function Critmatic.ShowNewHealCritMessage(spellName, amount)
if Critmatic.db.profile.alertNotificationFormat.global.isUpper then
-- If spellName does not end with 'Heal', use the format string as is
message = string.upper(string.format(Critmatic.db.profile.alertNotificationFormat.strings
.critHealAlertNotificationFormat, spellName, amount))
else
message = string.format(Critmatic.db.profile.alertNotificationFormat.strings.critHealAlertNotificationFormat,
spellName, amount)
end
local r, g, b = unpack(Critmatic.db.profile.fontSettings.fontColorCrit)
Critmatic.MessageFrame:CreateMessage(message, r, g, b) -- Gold color
end
function Critmatic.ShowNewHealMessage(spellName, amount)
-- Check if the spellName ends with 'Heal', 'heal', or 'HEAL'
if string.sub(spellName, -4):lower() == "heal" then
-- Remove the redundant 'Heal' from the format string
local formatString = Critmatic.db.profile.alertNotificationFormat.strings.healAlertNotificationFormat
formatString = string.gsub(formatString, "%%s Heal", "%%s")
formatString = string.gsub(formatString, "%%s heal", "%%s")
formatString = string.gsub(formatString, "%%s HEAL", "%%s")
if Critmatic.db.profile.alertNotificationFormat.global.isUpper then
message = string.upper(string.format(formatString, spellName, amount))
else
message = string.format(formatString, spellName, amount)
end
else
if Critmatic.db.profile.alertNotificationFormat.global.isUpper then
-- If spellName does not end with 'Heal', use the format string as is
message = string.upper(string.format(Critmatic.db.profile.alertNotificationFormat.strings
.healAlertNotificationFormat, spellName, amount))
else
message = string.format(Critmatic.db.profile.alertNotificationFormat.strings.healAlertNotificationFormat, spellName, amount)
end
end
local r, g, b = unpack(Critmatic.db.profile.fontSettings.fontColor)
Critmatic.MessageFrame:CreateMessage(message, r, g, b)
end