|
| 1 | +local E, L, V, P, G = unpack(ElvUI) |
| 2 | +local AB = E:GetModule('ActionBars') |
| 3 | + |
| 4 | +local _G = _G |
| 5 | +local pairs = pairs |
| 6 | +local unpack = unpack |
| 7 | +local tinsert = tinsert |
| 8 | + |
| 9 | +local CreateFrame = CreateFrame |
| 10 | +local GetBindingKey = GetBindingKey |
| 11 | +local InCombatLockdown = InCombatLockdown |
| 12 | +local hooksecurefunc = hooksecurefunc |
| 13 | + |
| 14 | +local ActionButton_UpdateCooldown = ActionButton_UpdateCooldown |
| 15 | + |
| 16 | +local extraBtns, extraHooked, ExtraActionBarHolder, ZoneAbilityHolder = {}, {} |
| 17 | + |
| 18 | +function AB:ExtraButtons_BossStyle(frame) |
| 19 | + local button = frame.button |
| 20 | + if button and not button.IsSkinned then |
| 21 | + AB:StyleButton(button, true) -- registers cooldown too |
| 22 | + |
| 23 | + -- the cooldown is already fired sometimes? |
| 24 | + if ActionButton_UpdateCooldown then |
| 25 | + ActionButton_UpdateCooldown(button) |
| 26 | + end |
| 27 | + |
| 28 | + button.icon:SetDrawLayer('ARTWORK', -1) |
| 29 | + button:SetTemplate() |
| 30 | + |
| 31 | + button.holder = ExtraActionBarHolder |
| 32 | + button:HookScript('OnEnter', AB.ExtraButtons_OnEnter) |
| 33 | + button:HookScript('OnLeave', AB.ExtraButtons_OnLeave) |
| 34 | + |
| 35 | + button.HotKey:SetText(GetBindingKey(button.commandName)) |
| 36 | + |
| 37 | + AB:FixKeybindText(button) |
| 38 | + AB:FixKeybindColor(button) |
| 39 | + |
| 40 | + AB:ExtraButtons_BossAlpha(button) |
| 41 | + |
| 42 | + tinsert(extraBtns, button) |
| 43 | + |
| 44 | + button.IsSkinned = true |
| 45 | + end |
| 46 | +end |
| 47 | + |
| 48 | +function AB:ExtraButtons_ZoneStyle() |
| 49 | + local zoneAlpha = AB:ExtraButtons_ZoneAlpha() |
| 50 | + for spellButton in self.SpellButtonContainer:EnumerateActive() do |
| 51 | + if spellButton then |
| 52 | + spellButton:SetAlpha(zoneAlpha) |
| 53 | + |
| 54 | + if not spellButton.IsSkinned then |
| 55 | + spellButton.NormalTexture:SetAlpha(0) |
| 56 | + spellButton:StyleButton() |
| 57 | + spellButton:SetTemplate() |
| 58 | + |
| 59 | + spellButton.Icon:SetDrawLayer('ARTWORK', -1) |
| 60 | + spellButton.Icon:SetTexCoord(unpack(E.TexCoords)) |
| 61 | + spellButton.Icon:SetInside() |
| 62 | + |
| 63 | + spellButton.holder = ZoneAbilityHolder |
| 64 | + spellButton:HookScript('OnEnter', AB.ExtraButtons_OnEnter) |
| 65 | + spellButton:HookScript('OnLeave', AB.ExtraButtons_OnLeave) |
| 66 | + |
| 67 | + if spellButton.Cooldown then |
| 68 | + E:RegisterCooldown(spellButton.Cooldown, 'actionbar') |
| 69 | + spellButton.Cooldown:SetInside(spellButton) |
| 70 | + end |
| 71 | + |
| 72 | + spellButton.IsSkinned = true |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | +end |
| 77 | + |
| 78 | +function AB:ExtraButtons_BossAlpha(button) |
| 79 | + local bossAlpha = E.db.actionbar.extraActionButton.alpha |
| 80 | + button:SetAlpha(bossAlpha or 1) |
| 81 | + |
| 82 | + if button.style then |
| 83 | + button.style:SetAlpha(not E.db.actionbar.extraActionButton.clean and bossAlpha or 0) |
| 84 | + end |
| 85 | +end |
| 86 | + |
| 87 | +function AB:ExtraButtons_ZoneAlpha() |
| 88 | + local zoneAlpha = E.db.actionbar.zoneActionButton.alpha |
| 89 | + _G.ZoneAbilityFrame.Style:SetAlpha(not E.db.actionbar.zoneActionButton.clean and zoneAlpha or 0) |
| 90 | + |
| 91 | + return zoneAlpha |
| 92 | +end |
| 93 | + |
| 94 | +function AB:ExtraButtons_OnEnter() |
| 95 | + if self.holder and self.holder:GetParent() == AB.fadeParent and not AB.fadeParent.mouseLock then |
| 96 | + E:UIFrameFadeIn(AB.fadeParent, 0.2, AB.fadeParent:GetAlpha(), 1) |
| 97 | + end |
| 98 | + |
| 99 | + if self.buttonType == 'EXTRAACTIONBUTTON' then |
| 100 | + AB:BindUpdate(self) |
| 101 | + end |
| 102 | +end |
| 103 | + |
| 104 | +function AB:ExtraButtons_OnLeave() |
| 105 | + if self.holder and self.holder:GetParent() == AB.fadeParent and not AB.fadeParent.mouseLock then |
| 106 | + E:UIFrameFadeOut(AB.fadeParent, 0.2, AB.fadeParent:GetAlpha(), 1 - AB.db.globalFadeAlpha) |
| 107 | + end |
| 108 | +end |
| 109 | + |
| 110 | +function AB:ExtraButtons_GlobalFade() |
| 111 | + if ExtraActionBarHolder then |
| 112 | + ExtraActionBarHolder:SetParent(E.db.actionbar.extraActionButton.inheritGlobalFade and AB.fadeParent or E.UIParent) |
| 113 | + end |
| 114 | + |
| 115 | + if ZoneAbilityHolder then |
| 116 | + ZoneAbilityHolder:SetParent(E.db.actionbar.zoneActionButton.inheritGlobalFade and AB.fadeParent or E.UIParent) |
| 117 | + end |
| 118 | +end |
| 119 | + |
| 120 | +function AB:ExtraButtons_UpdateAlpha() |
| 121 | + if not E.private.actionbar.enable then return end |
| 122 | + |
| 123 | + for _, button in pairs(extraBtns) do |
| 124 | + AB:ExtraButtons_BossAlpha(button) |
| 125 | + end |
| 126 | + |
| 127 | + if _G.ZoneAbilityFrame then |
| 128 | + local zoneAlpha = AB:ExtraButtons_ZoneAlpha() |
| 129 | + for button in _G.ZoneAbilityFrame.SpellButtonContainer:EnumerateActive() do |
| 130 | + button:SetAlpha(zoneAlpha) |
| 131 | + end |
| 132 | + end |
| 133 | +end |
| 134 | + |
| 135 | +function AB:ExtraButtons_UpdateScale() |
| 136 | + if not E.private.actionbar.enable then return end |
| 137 | + |
| 138 | + if _G.ZoneAbilityFrame then |
| 139 | + AB:ExtraButtons_ZoneScale() |
| 140 | + end |
| 141 | + |
| 142 | + if _G.ExtraActionBarFrame then |
| 143 | + local scale = E.db.actionbar.extraActionButton.scale |
| 144 | + _G.ExtraActionBarFrame:SetScale(scale * E.uiscale) |
| 145 | + _G.ExtraActionBarFrame:SetIgnoreParentScale(true) |
| 146 | + |
| 147 | + local width, height = _G.ExtraActionBarFrame.button:GetSize() |
| 148 | + ExtraActionBarHolder:SetSize(width * scale, height * scale) |
| 149 | + end |
| 150 | +end |
| 151 | + |
| 152 | +function AB:ExtraButtons_ZoneScale() |
| 153 | + if not E.private.actionbar.enable then return end |
| 154 | + |
| 155 | + if _G.ZoneAbilityFrame then |
| 156 | + local scale = E.db.actionbar.zoneActionButton.scale |
| 157 | + _G.ZoneAbilityFrame.Style:SetScale(scale) |
| 158 | + _G.ZoneAbilityFrame.SpellButtonContainer:SetScale(scale) |
| 159 | + |
| 160 | + local width, height = _G.ZoneAbilityFrame.SpellButtonContainer:GetSize() |
| 161 | + ZoneAbilityHolder:SetSize(width * scale, height * scale) |
| 162 | + end |
| 163 | +end |
| 164 | + |
| 165 | +function AB:ExtraButtons_BossParent(parent) |
| 166 | + if parent ~= ExtraActionBarHolder and not AB.NeedsReparentExtraButtons then |
| 167 | + AB:ExtraButtons_Reparent() |
| 168 | + end |
| 169 | +end |
| 170 | + |
| 171 | +function AB:ExtraButtons_ZoneParent(parent) |
| 172 | + if parent ~= ZoneAbilityHolder and not AB.NeedsReparentExtraButtons then |
| 173 | + AB:ExtraButtons_Reparent() |
| 174 | + end |
| 175 | +end |
| 176 | + |
| 177 | +function AB:ExtraButtons_Reparent() |
| 178 | + if InCombatLockdown() then |
| 179 | + AB.NeedsReparentExtraButtons = true |
| 180 | + |
| 181 | + AB:RegisterEvent('PLAYER_REGEN_ENABLED') |
| 182 | + |
| 183 | + return |
| 184 | + end |
| 185 | + |
| 186 | + if _G.ZoneAbilityFrame then |
| 187 | + _G.ZoneAbilityFrame:SetParent(ZoneAbilityHolder) |
| 188 | + end |
| 189 | + |
| 190 | + if _G.ExtraActionBarFrame then |
| 191 | + _G.ExtraActionBarFrame:SetParent(ExtraActionBarHolder) |
| 192 | + end |
| 193 | +end |
| 194 | + |
| 195 | +function AB:ExtraButtons_SetupBoss() |
| 196 | + local ExtraActionBarFrame = _G.ExtraActionBarFrame |
| 197 | + if not ExtraActionBarFrame then return end |
| 198 | + |
| 199 | + if not extraHooked[ExtraActionBarFrame] then |
| 200 | + hooksecurefunc(ExtraActionBarFrame, 'SetParent', AB.ExtraButtons_BossParent) |
| 201 | + |
| 202 | + extraHooked[ExtraActionBarFrame] = true |
| 203 | + end |
| 204 | + |
| 205 | + ExtraActionBarFrame:ClearAllPoints() |
| 206 | + ExtraActionBarFrame:SetAllPoints() |
| 207 | + ExtraActionBarFrame.ignoreInLayout = true |
| 208 | +end |
| 209 | + |
| 210 | +function AB:ExtraButtons_SetupZone() |
| 211 | + local ZoneAbilityFrame = _G.ZoneAbilityFrame |
| 212 | + if not ZoneAbilityFrame then return end |
| 213 | + |
| 214 | + if not extraHooked[ZoneAbilityFrame] then |
| 215 | + ZoneAbilityFrame.SpellButtonContainer.holder = ZoneAbilityHolder |
| 216 | + ZoneAbilityFrame.SpellButtonContainer:HookScript('OnEnter', AB.ExtraButtons_OnEnter) |
| 217 | + ZoneAbilityFrame.SpellButtonContainer:HookScript('OnLeave', AB.ExtraButtons_OnLeave) |
| 218 | + |
| 219 | + hooksecurefunc(ZoneAbilityFrame.SpellButtonContainer, 'SetSize', AB.ExtraButtons_ZoneScale) |
| 220 | + hooksecurefunc(ZoneAbilityFrame, 'UpdateDisplayedZoneAbilities', AB.ExtraButtons_ZoneStyle) |
| 221 | + hooksecurefunc(ZoneAbilityFrame, 'SetParent', AB.ExtraButtons_ZoneParent) |
| 222 | + |
| 223 | + extraHooked[ZoneAbilityFrame] = true |
| 224 | + end |
| 225 | + |
| 226 | + ZoneAbilityFrame:ClearAllPoints() |
| 227 | + ZoneAbilityFrame:SetAllPoints() |
| 228 | + ZoneAbilityFrame.ignoreInLayout = true |
| 229 | + |
| 230 | + if ZoneAbilityHolder then |
| 231 | + ZoneAbilityHolder:Size(52 * E.db.actionbar.zoneActionButton.scale) |
| 232 | + end |
| 233 | +end |
| 234 | + |
| 235 | +function AB:ExtraButtons_SetupAbility() |
| 236 | + local ExtraAbilityContainer = _G.ExtraAbilityContainer |
| 237 | + if not ExtraAbilityContainer then return end |
| 238 | + |
| 239 | + if not extraHooked[ExtraAbilityContainer] then |
| 240 | + -- try to shutdown the container movement and taints |
| 241 | + ExtraAbilityContainer:KillEditMode() |
| 242 | + ExtraAbilityContainer:SetScript('OnShow', nil) |
| 243 | + ExtraAbilityContainer:SetScript('OnUpdate', nil) |
| 244 | + ExtraAbilityContainer.OnUpdate = nil -- remove BaseLayoutMixin.OnUpdate |
| 245 | + ExtraAbilityContainer.IsLayoutFrame = nil -- dont let it get readded |
| 246 | + |
| 247 | + hooksecurefunc(ExtraAbilityContainer, 'AddFrame', AB.ExtraButtons_BossStyle) |
| 248 | + |
| 249 | + extraHooked[ExtraAbilityContainer] = true |
| 250 | + end |
| 251 | +end |
| 252 | + |
| 253 | +function AB:CreateExtraHolders() |
| 254 | + if not ExtraActionBarHolder then |
| 255 | + ExtraActionBarHolder = CreateFrame('Frame', 'ElvUI_ExtraActionBarHolder', E.UIParent) |
| 256 | + ExtraActionBarHolder:Point('BOTTOM', E.UIParent, 'BOTTOM', -150, 300) |
| 257 | + E.FrameLocks[ExtraActionBarHolder] = true |
| 258 | + |
| 259 | + E:CreateMover(ExtraActionBarHolder, 'BossButton', L["Boss Button"], nil, nil, nil, 'ALL,ACTIONBARS', nil, 'actionbar,extraButtons,extraActionButton') |
| 260 | + end |
| 261 | + |
| 262 | + if not ZoneAbilityHolder then |
| 263 | + ZoneAbilityHolder = CreateFrame('Frame', 'ElvUI_ZoneAbilityHolder', E.UIParent) |
| 264 | + ZoneAbilityHolder:Point('BOTTOM', E.UIParent, 'BOTTOM', 150, 300) |
| 265 | + E.FrameLocks[ZoneAbilityHolder] = true |
| 266 | + |
| 267 | + E:CreateMover(ZoneAbilityHolder, 'ZoneAbility', L["Zone Ability"], nil, nil, nil, 'ALL,ACTIONBARS', nil, 'actionbar,extraButtons,extraActionButton') |
| 268 | + end |
| 269 | +end |
| 270 | + |
| 271 | +function AB:SetupExtraButtons() |
| 272 | + AB:CreateExtraHolders() -- make the holders |
| 273 | + AB:ExtraButtons_Reparent() -- reparent to the holders (keep before setup) |
| 274 | + AB:ExtraButtons_SetupBoss() -- attach boss |
| 275 | + AB:ExtraButtons_SetupZone() -- attach zone |
| 276 | + AB:ExtraButtons_SetupAbility() -- attach abilities |
| 277 | + AB:UpdateExtraButtons() -- update the settings |
| 278 | +end |
| 279 | + |
| 280 | +function AB:UpdateExtraButtons() |
| 281 | + AB:ExtraButtons_UpdateAlpha() |
| 282 | + AB:ExtraButtons_UpdateScale() |
| 283 | + AB:ExtraButtons_GlobalFade() |
| 284 | +end |
| 285 | + |
| 286 | +function AB:UpdateExtraBindings() |
| 287 | + _G.ExtraActionBarFrame.db = E.db.actionbar.extraActionButton |
| 288 | + |
| 289 | + for _, button in pairs(extraBtns) do |
| 290 | + button.HotKey:SetText(GetBindingKey(button.commandName)) |
| 291 | + |
| 292 | + AB:FixKeybindText(button) |
| 293 | + AB:FixKeybindColor(button) |
| 294 | + end |
| 295 | +end |
0 commit comments