diff --git a/Core.lua b/Core.lua index 417c71f..5349490 100644 --- a/Core.lua +++ b/Core.lua @@ -1,4 +1,3 @@ - -- LOCALS local addonName, mod = ... local frame = CreateFrame("Frame", "CappingFrame", UIParent) @@ -12,6 +11,21 @@ local zoneIds = {} local activeBars = { } frame.bars = activeBars +local function UpdateBarMouseState() + if not db then return end + local enabled = (IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE") + for bar in next, activeBars do + bar:EnableMouse(enabled) + end +end + +local function IsInPvPZone() + local _, instanceType = GetInstanceInfo() + return instanceType == "pvp" or instanceType == "arena" +end + -- LIBRARIES local candy = LibStub("LibCandyBar-3.0") local media = LibStub("LibSharedMedia-3.0") @@ -138,11 +152,9 @@ do bar.candyBarLabel:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar.candyBarDuration:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar:SetScript("OnMouseUp", BarOnClick) - if db.profile.barOnShift ~= "NONE" or db.profile.barOnControl ~= "NONE" or db.profile.barOnAlt ~= "NONE" then - bar:EnableMouse(true) - else - bar:EnableMouse(false) - end + bar:EnableMouse((IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE")) bar:Start(maxBarTime) RearrangeBars() return bar @@ -174,6 +186,17 @@ do for bar in next, activeBars do bar:Stop() end + -- Clean up test mode timer + if core and core.testModeTimer then + core.testModeTimer:Cancel() + core.testModeTimer = nil + end + -- Clean up any remaining events outside of PvP zones + if core and core:IsEventRegistered("MODIFIER_STATE_CHANGED") then + if not IsInPvPZone() then + core:UnregisterEvent("MODIFIER_STATE_CHANGED") + end + end end function API:GetBar(text) @@ -187,11 +210,13 @@ do do local eventMap = {} frame:SetScript("OnEvent", function(_, event, ...) - for k,v in next, eventMap[event] do - if type(v) == "function" then - v(...) - else - k[v](k, ...) + if eventMap[event] then + for k,v in next, eventMap[event] do + if type(v) == "function" then + v(...) + else + k[v](k, ...) + end end end end) @@ -209,8 +234,10 @@ do eventMap[event] = nil end end + function API:IsEventRegistered(event) + return eventMap[event] and eventMap[event][self] and true or false + end end - function API:RegisterZone(id) zoneIds[id] = self end @@ -834,21 +861,26 @@ do local GetInstanceInfo = GetInstanceInfo function core:PLAYER_ENTERING_WORLD() local _, instanceType, _, _, _, _, _, id = GetInstanceInfo() - if zoneIds[id] then - prevZone = id - self:RegisterEvent("PLAYER_LEAVING_WORLD") - zoneIds[id]:EnterZone(id) - elseif zoneIds[instanceType] then - prevZone = instanceType - self:RegisterEvent("PLAYER_LEAVING_WORLD") - zoneIds[instanceType]:EnterZone(id) - end + if zoneIds[id] then + prevZone = id + self:RegisterEvent("PLAYER_LEAVING_WORLD") + zoneIds[id]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() + elseif zoneIds[instanceType] then + prevZone = instanceType + self:RegisterEvent("PLAYER_LEAVING_WORLD") + zoneIds[instanceType]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() + end end function core:PLAYER_LEAVING_WORLD() - self:UnregisterEvent("PLAYER_LEAVING_WORLD") - self:StopAllBars() - zoneIds[prevZone]:ExitZone() - prevZone = nil + self:UnregisterEvent("PLAYER_LEAVING_WORLD") + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + self:StopAllBars() + zoneIds[prevZone]:ExitZone() + prevZone = nil end end @@ -857,6 +889,15 @@ function core:Test(locale) core:StartBar(locale.otherBars, 75, 1582141, "colorOther") -- Interface/Icons/Achievement_PVP_Legion03 core:StartBar(locale.allianceBars, 45, 132486, "colorAlliance") -- Interface/Icons/INV_BannerPVP_02 core:StartBar(locale.hordeBars, 25, 132485, "colorHorde") -- Interface/Icons/INV_BannerPVP_01 + + -- Use polling only outside of PvP zones where MODIFIER_STATE_CHANGED doesn't work + if not IsInPvPZone() then + self.testModeTimer = C_Timer.NewTicker(0.2, function() + UpdateBarMouseState() + end) + end + + UpdateBarMouseState() end frame.Test = core.Test @@ -900,4 +941,4 @@ do openOpts() end end) -end +end \ No newline at end of file diff --git a/Core_BCC.lua b/Core_BCC.lua index 16a42eb..953aef3 100644 --- a/Core_BCC.lua +++ b/Core_BCC.lua @@ -11,6 +11,21 @@ local zoneIds = {} local activeBars = { } frame.bars = activeBars +local function UpdateBarMouseState() + if not db then return end + local enabled = (IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE") + for bar in next, activeBars do + bar:EnableMouse(enabled) + end +end + +local function IsInPvPZone() + local _, instanceType = GetInstanceInfo() + return instanceType == "pvp" or instanceType == "arena" +end + -- LIBRARIES local candy = LibStub("LibCandyBar-3.0") local media = LibStub("LibSharedMedia-3.0") @@ -137,11 +152,9 @@ do bar.candyBarLabel:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar.candyBarDuration:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar:SetScript("OnMouseUp", BarOnClick) - if db.profile.barOnShift ~= "NONE" or db.profile.barOnControl ~= "NONE" or db.profile.barOnAlt ~= "NONE" then - bar:EnableMouse(true) - else - bar:EnableMouse(false) - end + bar:EnableMouse((IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE")) bar:Start(maxBarTime) RearrangeBars() return bar @@ -173,6 +186,17 @@ do for bar in next, activeBars do bar:Stop() end + -- Clean up test mode timer + if self.testModeTimer then + self.testModeTimer:Cancel() + self.testModeTimer = nil + end + -- Clean up any remaining events outside of PvP zones + if self:IsEventRegistered("MODIFIER_STATE_CHANGED") then + if not IsInPvPZone() then + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + end + end end function API:GetBar(text) @@ -209,7 +233,6 @@ do end end end - function API:RegisterZone(id) zoneIds[id] = self end @@ -796,6 +819,11 @@ do SelectAvailableQuest(id) end end + + function API:IsEventRegistered(event) + if not frame.events then return false end + return frame.events[event] and true or false + end function mod:NewMod() local t = {} @@ -887,21 +915,26 @@ do local GetInstanceInfo = GetInstanceInfo function core:PLAYER_ENTERING_WORLD() local _, instanceType, _, _, _, _, _, id = GetInstanceInfo() - if zoneIds[id] then - prevZone = id - self:RegisterEvent("PLAYER_LEAVING_WORLD") - zoneIds[id]:EnterZone(id) - elseif zoneIds[instanceType] then - prevZone = instanceType - self:RegisterEvent("PLAYER_LEAVING_WORLD") - zoneIds[instanceType]:EnterZone(id) - end + if zoneIds[id] then + prevZone = id + self:RegisterEvent("PLAYER_LEAVING_WORLD") + zoneIds[id]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() + elseif zoneIds[instanceType] then + prevZone = instanceType + self:RegisterEvent("PLAYER_LEAVING_WORLD") + zoneIds[instanceType]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() + end end function core:PLAYER_LEAVING_WORLD() - self:UnregisterEvent("PLAYER_LEAVING_WORLD") - self:StopAllBars() - zoneIds[prevZone]:ExitZone() - prevZone = nil + self:UnregisterEvent("PLAYER_LEAVING_WORLD") + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + self:StopAllBars() + zoneIds[prevZone]:ExitZone() + prevZone = nil end end @@ -910,6 +943,13 @@ function core:Test(locale) core:StartBar(locale.otherBars, 75, 132333, "colorOther") -- Interface/Icons/Ability_warrior_battleshout core:StartBar(locale.allianceBars, 45, 132486, "colorAlliance") -- Interface/Icons/INV_BannerPVP_02 core:StartBar(locale.hordeBars, 25, 132485, "colorHorde") -- Interface/Icons/INV_BannerPVP_01 + + if not IsInPvPZone() then + if self.testModeTimer then self.testModeTimer:Cancel() end + self.testModeTimer = C_Timer.NewTicker(0.2, function() + UpdateBarMouseState() + end) + end end frame.Test = core.Test diff --git a/Core_Vanilla.lua b/Core_Vanilla.lua index e24123d..89173ff 100644 --- a/Core_Vanilla.lua +++ b/Core_Vanilla.lua @@ -11,6 +11,21 @@ local zoneIds = {} local activeBars = { } frame.bars = activeBars +local function UpdateBarMouseState() + if not db then return end + local enabled = (IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE") + for bar in next, activeBars do + bar:EnableMouse(enabled) + end +end + +local function IsInPvPZone() + local _, instanceType = GetInstanceInfo() + return instanceType == "pvp" or instanceType == "arena" +end + -- LIBRARIES local candy = LibStub("LibCandyBar-3.0") local media = LibStub("LibSharedMedia-3.0") @@ -137,11 +152,9 @@ do bar.candyBarLabel:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar.candyBarDuration:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar:SetScript("OnMouseUp", BarOnClick) - if db.profile.barOnShift ~= "NONE" or db.profile.barOnControl ~= "NONE" or db.profile.barOnAlt ~= "NONE" then - bar:EnableMouse(true) - else - bar:EnableMouse(false) - end + bar:EnableMouse((IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE")) bar:Start(maxBarTime) RearrangeBars() return bar @@ -173,6 +186,17 @@ do for bar in next, activeBars do bar:Stop() end + -- Clean up test mode timer + if self.testModeTimer then + self.testModeTimer:Cancel() + self.testModeTimer = nil + end + -- Clean up any remaining events outside of PvP zones + if self:IsEventRegistered("MODIFIER_STATE_CHANGED") then + if not IsInPvPZone() then + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + end + end end function API:GetBar(text) @@ -209,6 +233,7 @@ do end end end +-- UpdateBarMouseState removed (already defined above) function API:RegisterZone(id) zoneIds[id] = self @@ -790,6 +815,11 @@ do SelectAvailableQuest(id) end end + + function API:IsEventRegistered(event) + if not frame.events then return false end + return frame.events[event] and true or false + end function mod:NewMod() local t = {} @@ -881,21 +911,26 @@ do local GetInstanceInfo = GetInstanceInfo function core:PLAYER_ENTERING_WORLD() local _, instanceType, _, _, _, _, _, id = GetInstanceInfo() - if zoneIds[id] then - prevZone = id - self:RegisterEvent("PLAYER_LEAVING_WORLD") - zoneIds[id]:EnterZone(id) - elseif zoneIds[instanceType] then - prevZone = instanceType - self:RegisterEvent("PLAYER_LEAVING_WORLD") - zoneIds[instanceType]:EnterZone(id) - end + if zoneIds[id] then + prevZone = id + self:RegisterEvent("PLAYER_LEAVING_WORLD") + zoneIds[id]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() + elseif zoneIds[instanceType] then + prevZone = instanceType + self:RegisterEvent("PLAYER_LEAVING_WORLD") + zoneIds[instanceType]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() + end end function core:PLAYER_LEAVING_WORLD() - self:UnregisterEvent("PLAYER_LEAVING_WORLD") - self:StopAllBars() - zoneIds[prevZone]:ExitZone() - prevZone = nil + self:UnregisterEvent("PLAYER_LEAVING_WORLD") + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + self:StopAllBars() + zoneIds[prevZone]:ExitZone() + prevZone = nil end end @@ -904,6 +939,13 @@ function core:Test(locale) core:StartBar(locale.otherBars, 75, 132089, "colorOther") -- Interface/Icons/Ability_ambush core:StartBar(locale.allianceBars, 45, 132486, "colorAlliance") -- Interface/Icons/INV_BannerPVP_02 core:StartBar(locale.hordeBars, 25, 132485, "colorHorde") -- Interface/Icons/INV_BannerPVP_01 + + if not IsInPvPZone() then + if self.testModeTimer then self.testModeTimer:Cancel() end + self.testModeTimer = C_Timer.NewTicker(0.2, function() + UpdateBarMouseState() + end) + end end frame.Test = core.Test diff --git a/Core_Wrath.lua b/Core_Wrath.lua index 4fb1e7d..7ca7e75 100644 --- a/Core_Wrath.lua +++ b/Core_Wrath.lua @@ -11,6 +11,21 @@ local zoneIds = {} local activeBars = { } frame.bars = activeBars +local function UpdateBarMouseState() + if not db then return end + local enabled = (IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE") + for bar in next, activeBars do + bar:EnableMouse(enabled) + end +end + +local function IsInPvPZone() + local _, instanceType = GetInstanceInfo() + return instanceType == "pvp" or instanceType == "arena" +end + -- LIBRARIES local candy = LibStub("LibCandyBar-3.0") local media = LibStub("LibSharedMedia-3.0") @@ -137,11 +152,9 @@ do bar.candyBarLabel:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar.candyBarDuration:SetFont(media:Fetch("font", db.profile.font), db.profile.fontSize, flags) bar:SetScript("OnMouseUp", BarOnClick) - if db.profile.barOnShift ~= "NONE" or db.profile.barOnControl ~= "NONE" or db.profile.barOnAlt ~= "NONE" then - bar:EnableMouse(true) - else - bar:EnableMouse(false) - end + bar:EnableMouse((IsShiftKeyDown() and db.profile.barOnShift ~= "NONE") + or (IsControlKeyDown() and db.profile.barOnControl ~= "NONE") + or (IsAltKeyDown() and db.profile.barOnAlt ~= "NONE")) bar:Start(maxBarTime) RearrangeBars() return bar @@ -173,6 +186,17 @@ do for bar in next, activeBars do bar:Stop() end + -- Clean up test mode timer + if self.testModeTimer then + self.testModeTimer:Cancel() + self.testModeTimer = nil + end + -- Clean up any remaining events outside of PvP zones + if self:IsEventRegistered("MODIFIER_STATE_CHANGED") then + if not IsInPvPZone() then + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + end + end end function API:GetBar(text) @@ -208,6 +232,9 @@ do eventMap[event] = nil end end + function API:IsEventRegistered(event) + return eventMap[event] and eventMap[event][self] and true or false + end end function API:RegisterZone(id) @@ -891,17 +918,22 @@ do prevZone = id self:RegisterEvent("PLAYER_LEAVING_WORLD") zoneIds[id]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() elseif zoneIds[instanceType] then prevZone = instanceType self:RegisterEvent("PLAYER_LEAVING_WORLD") zoneIds[instanceType]:EnterZone(id) + self:RegisterEvent("MODIFIER_STATE_CHANGED", UpdateBarMouseState) + UpdateBarMouseState() end end function core:PLAYER_LEAVING_WORLD() - self:UnregisterEvent("PLAYER_LEAVING_WORLD") - self:StopAllBars() - zoneIds[prevZone]:ExitZone() - prevZone = nil + self:UnregisterEvent("PLAYER_LEAVING_WORLD") + self:UnregisterEvent("MODIFIER_STATE_CHANGED") + self:StopAllBars() + zoneIds[prevZone]:ExitZone() + prevZone = nil end end @@ -910,6 +942,13 @@ function core:Test(locale) core:StartBar(locale.otherBars, 75, 132333, "colorOther") -- Interface/Icons/Ability_warrior_battleshout core:StartBar(locale.allianceBars, 45, 132486, "colorAlliance") -- Interface/Icons/INV_BannerPVP_02 core:StartBar(locale.hordeBars, 25, 132485, "colorHorde") -- Interface/Icons/INV_BannerPVP_01 + + if not IsInPvPZone() then + if self.testModeTimer then self.testModeTimer:Cancel() end + self.testModeTimer = C_Timer.NewTicker(0.2, function() + UpdateBarMouseState() + end) + end end frame.Test = core.Test