vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Omni Cooldown Count |
||
3 | A universal cooldown count, based on Gello's spec |
||
4 | --]] |
||
5 | |||
6 | --[[ |
||
7 | Saved Variables |
||
8 | These values are reloaded from saved variables if the user already has saved settings. |
||
9 | So, the settings always exist |
||
10 | --]] |
||
11 | |||
12 | OmniCC = { |
||
13 | min = 3, --minimum duration to show text |
||
14 | font = STANDARD_TEXT_FONT, --cooldown text font; ClearFont loads before OmniCC and will be used if its there. |
||
15 | size = 20, --cooldown text size |
||
16 | long = {r = 0.8, g = 0.8, b = 0.9}, --long duration color |
||
17 | medium = {r = 1, g = 1, b = 0.4}, --medium duration color |
||
18 | short = {r = 1, g = 0, b = 0}, --short duration color |
||
19 | --hideModel = nil, |
||
20 | } |
||
21 | |||
22 | --returns the formatted time, scaling to use, color, and the time until the next update is needed |
||
23 | local function GetFormattedTime(time) |
||
24 | --day |
||
25 | if (time >= 86400) then |
||
26 | return ( math.floor((time / 86400 + 0.5)) .. DAY_ONELETTER_ABBR ), 0.6, OmniCC.long.r, OmniCC.long.g, OmniCC.long.b, math.mod(time, 86400); |
||
27 | --hour |
||
28 | elseif (time >= 3600) then |
||
29 | return ( math.floor((time / 3600 + 0.5)) .. HOUR_ONELETTER_ABBR ), 0.6, OmniCC.long.r, OmniCC.long.g, OmniCC.long.b, math.mod(time, 3600); |
||
30 | --minute |
||
31 | elseif (time >= 60) then |
||
32 | return ( math.floor((time / 60 + 0.5)) .. MINUTE_ONELETTER_ABBR ), 0.8, OmniCC.long.r, OmniCC.long.g, OmniCC.long.b, math.mod(time, 60); |
||
33 | --second, more than 5 seconds left |
||
34 | elseif (time > 5) then |
||
35 | return math.floor(time + 1), 1.0, OmniCC.medium.r, OmniCC.medium.g, OmniCC.medium.b, 0.2; |
||
36 | end |
||
37 | --[[ |
||
38 | Tenths of seconds left, doesn't look all that good |
||
39 | if( OmniCC.useTenths and time <= 1) then |
||
40 | return string.format("%.1f", time), 1.1, OmniCC.short.r, OmniCC.short.g, OmniCC.short.b, 0; |
||
41 | end |
||
42 | --]] |
||
43 | --second, 5 or less left |
||
44 | return math.floor(time + 0.5), 1.3, OmniCC.short.r, OmniCC.short.g, OmniCC.short.b, 0.1; |
||
45 | end |
||
46 | |||
47 | --[[ |
||
48 | Text cooldown constructor |
||
49 | Its a seperate frame to prevent some rendering issues. |
||
50 | --]] |
||
51 | local function CreateCooldownCount(cooldown, start, duration) |
||
52 | --yet another failsafe for the font |
||
53 | if(not OmniCCFont) then |
||
54 | CreateFont("OmniCCFont"); |
||
55 | if( not OmniCCFont:SetFont(OmniCC.font, OmniCC.size) ) then |
||
56 | OmniCC.font = STANDARD_TEXT_FONT; |
||
57 | end |
||
58 | end |
||
59 | |||
60 | cooldown.textFrame = CreateFrame("Frame", nil, cooldown:GetParent()); |
||
61 | cooldown.textFrame:SetAllPoints(cooldown:GetParent()); |
||
62 | cooldown.textFrame:SetFrameLevel(cooldown.textFrame:GetFrameLevel() + 1); |
||
63 | |||
64 | cooldown.textFrame.text = cooldown.textFrame:CreateFontString(nil, "OVERLAY"); |
||
65 | cooldown.textFrame.text:SetPoint("CENTER", cooldown.textFrame, "CENTER", 0, 1); |
||
66 | |||
67 | cooldown.textFrame:SetAlpha(cooldown:GetParent():GetAlpha()); |
||
68 | |||
69 | --[[ |
||
70 | OmniCC hides the text cooldown if the icon the button is hidden or not. |
||
71 | This makes it a bit more dependent on other mods as far as their icon format goes. |
||
72 | Its the only way I can think of to absolutely make sure that the text cooldown is hidden properly. |
||
73 | --]] |
||
74 | cooldown.textFrame.icon = |
||
75 | --standard action button icon, $parentIcon |
||
76 | getglobal(cooldown:GetParent():GetName() .. "Icon") or |
||
77 | --standard item button icon, $parentIconTexture |
||
78 | getglobal(cooldown:GetParent():GetName() .. "IconTexture") or |
||
79 | --discord action button, $parent_Icon |
||
80 | getglobal(cooldown:GetParent():GetName() .. "_Icon"); |
||
81 | |||
82 | if(cooldown.textFrame.icon) then |
||
83 | cooldown.textFrame:SetScript("OnUpdate", OmniCC_OnUpdate); |
||
84 | end |
||
85 | |||
86 | cooldown.textFrame:Hide(); |
||
87 | end |
||
88 | |||
89 | --[[ |
||
90 | Slash Command Handler |
||
91 | --]] |
||
92 | SlashCmdList["OmniCCCOMMAND"] = function(msg) |
||
93 | if(not msg or msg == "" or msg == "help" or msg == "?") then |
||
94 | --print help messages |
||
95 | DEFAULT_CHAT_FRAME:AddMessage("OmniCC Commands:"); |
||
96 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc size <value> - Set font size. 24 is the default."); |
||
97 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc font <value> - Set the font to use. " .. STANDARD_TEXT_FONT .. " is the default."); |
||
98 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc color <duration> <red> <green> <blue> - Set the color to use for cooldowns of <duration>. Duration can be long, medium or short."); |
||
99 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc min <value> - Set the minimum duration (seconds) a cooldown should be to show text. Default value of 3."); |
||
100 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc hidemodel - Hide the cooldown model"); |
||
101 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc showmodel - Show the cooldown model (default behavior)"); |
||
102 | DEFAULT_CHAT_FRAME:AddMessage("/omnicc reset - Go back to default settings."); |
||
103 | else |
||
104 | local args = {}; |
||
105 | |||
106 | local word; |
||
107 | for word in string.gfind(msg, "[^%s]+") do |
||
108 | table.insert(args, word ); |
||
109 | end |
||
110 | |||
111 | cmd = string.lower(args[1]); |
||
112 | |||
113 | --/omnicc size <size> |
||
114 | if(cmd == "size" and tonumber(args[2]) ) then |
||
115 | if(tonumber(args[2]) > 0) then |
||
116 | OmniCC.size = tonumber(args[2]); |
||
117 | else |
||
118 | DEFAULT_CHAT_FRAME:AddMessage("Invalid font size."); |
||
119 | end |
||
120 | --/omnicc font <font> |
||
121 | elseif(cmd == "font" and args[2] ) then |
||
122 | --this font is created solely for testing if the user's selection is a valid font or not. |
||
123 | if(not OmniCCFont) then |
||
124 | CreateFont("OmniCCFont"); |
||
125 | end |
||
126 | |||
127 | if( OmniCCFont:SetFont(args[2], OmniCC.size) ) then |
||
128 | OmniCC.font = args[2]; |
||
129 | DEFAULT_CHAT_FRAME:AddMessage("Set font to " .. OmniCC.font .. "."); |
||
130 | else |
||
131 | DEFAULT_CHAT_FRAME:AddMessage(args[2] .. " is an invalid font. Using previous selection."); |
||
132 | end |
||
133 | --/omnicc min <size> |
||
134 | elseif(cmd == "min" and tonumber(args[2]) ) then |
||
135 | OmniCC.min = tonumber(args[2]); |
||
136 | elseif(cmd == "hidemodel") then |
||
137 | OmniCC.hideModel = 1; |
||
138 | elseif(cmd == "showmodel") then |
||
139 | OmniCC.hideModel = nil; |
||
140 | elseif(cmd == "color" and args[2] and tonumber(args[3]) and tonumber(args[4]) and tonumber(args[5]) ) then |
||
141 | local index = string.lower(args[2]); |
||
142 | if(index == "long" or index == "short" or index == "medium") then |
||
143 | OmniCC[index] = {r = tonumber(args[3]), g = tonumber(args[4]), b = tonumber(args[5])}; |
||
144 | end |
||
145 | elseif(cmd == "reset") then |
||
146 | OmniCC = { |
||
147 | min = 3, --minimum duration to show text |
||
148 | font = STANDARD_TEXT_FONT, --cooldown text font |
||
149 | size = 20, --cooldown text size |
||
150 | long = {r = 0.8, g = 0.8, b = 0.9}, --long duration color |
||
151 | medium = {r = 1, g = 1, b = 0.4}, --medium duration color |
||
152 | short = {r = 1, g = 0, b = 0}, --short duration color |
||
153 | --hideModel = nil, |
||
154 | } |
||
155 | end |
||
156 | end |
||
157 | end |
||
158 | SLASH_OmniCCCOMMAND1 = "/omnicc"; |
||
159 | |||
160 | --[[ |
||
161 | OnX functions |
||
162 | It now uses a seperate OnX function, but it no longer blinks. |
||
163 | --]] |
||
164 | function OmniCC_OnUpdate() |
||
165 | if( this.timeToNextUpdate <= 0 or not this.icon:IsVisible() ) then |
||
166 | local remain = this.duration - (GetTime() - this.start); |
||
167 | |||
168 | if( remain >= 0 and this.icon:IsVisible() ) then |
||
169 | local time, scale, r, g, b, timeToNextUpdate = GetFormattedTime( remain ); |
||
170 | this.text:SetFont(OmniCC.font , OmniCC.size * scale, "OUTLINE"); |
||
171 | this.text:SetText( time ); |
||
172 | this.text:SetTextColor(r, g, b); |
||
173 | this.timeToNextUpdate = timeToNextUpdate; |
||
174 | else |
||
175 | this:Hide(); |
||
176 | end |
||
177 | else |
||
178 | this.timeToNextUpdate = this.timeToNextUpdate - arg1; |
||
179 | end |
||
180 | end |
||
181 | |||
182 | --[[ |
||
183 | Function Overrides |
||
184 | --]] |
||
185 | |||
186 | function CooldownFrame_SetTimer(this, start, duration, enable) |
||
187 | if ( start > 0 and duration > 0 and enable > 0) then |
||
188 | this.start = start; |
||
189 | this.duration = duration; |
||
190 | this.stopping = 0; |
||
191 | this:SetSequence(0); |
||
192 | |||
193 | if(OmniCC.hideModel) then |
||
194 | this:Hide(); |
||
195 | else |
||
196 | this:Show(); |
||
197 | end |
||
198 | |||
199 | if( duration > OmniCC.min ) then |
||
200 | if( not this.textFrame ) then |
||
201 | CreateCooldownCount(this, start, duration); |
||
202 | end |
||
203 | this.textFrame.start = start; |
||
204 | this.textFrame.duration = duration; |
||
205 | |||
206 | this.textFrame.timeToNextUpdate = 0; |
||
207 | this.textFrame:Show(); |
||
208 | elseif( this.textFrame ) then |
||
209 | this.textFrame:Hide(); |
||
210 | end |
||
211 | else |
||
212 | this:Hide(); |
||
213 | if( this.textFrame ) then |
||
214 | this.textFrame:Hide(); |
||
215 | end |
||
216 | end |
||
217 | end |