Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 67 additions & 26 deletions Core.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- LOCALS
local addonName, mod = ...
local frame = CreateFrame("Frame", "CappingFrame", UIParent)
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -900,4 +941,4 @@ do
openOpts()
end
end)
end
end
78 changes: 59 additions & 19 deletions Core_BCC.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -209,7 +233,6 @@ do
end
end
end

function API:RegisterZone(id)
zoneIds[id] = self
end
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
Loading