Skip to content

Commit

Permalink
performance improvements in macro updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ollidiemaus committed Aug 29, 2024
1 parent 1c818f4 commit 2f6ebcb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
2 changes: 1 addition & 1 deletion AutoPotion.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Interface-Classic: 11503
## Interface-WOTLKC: 30403
## Interface-Cata: 40400
## Version: 3.5.10
## Version: 3.5.11
## Title: Auto Potion
## Author: ollidiemaus
## Notes: Updates the Macro AutoPotion to use either Healthstone or the highest Potion found in Bags
Expand Down
58 changes: 25 additions & 33 deletions FrameXML/InterfaceOptionsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local isWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
local isCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)

---@class Frame
local panel = CreateFrame("Frame")
ham.settingsFrame = CreateFrame("Frame")
local ICON_SIZE = 50
local PADDING_CATERGORY = 60
local PADDING = 30
Expand All @@ -20,9 +20,8 @@ local positionx = 0
local currentPrioTitle = nil
local lastStaticElement = nil

local onCombat = true

function panel:OnEvent(event, addOnName)
function ham.settingsFrame:OnEvent(event, addOnName)
if addOnName == "AutoPotion" then
if event == "ADDON_LOADED" then
HAMDB = HAMDB or CopyTable(ham.defaults)
Expand All @@ -35,35 +34,18 @@ function panel:OnEvent(event, addOnName)
end
if event == "PLAYER_LOGIN" then
self:InitializeClassSpells(lastStaticElement)
self:updatePrio()
onCombat = false
end
if event == "PLAYER_REGEN_DISABLED" then
onCombat = true
return
end
if event == "PLAYER_REGEN_ENABLED" then
onCombat = false
end

if onCombat == false then
ham.updateHeals()
ham.updateMacro()
self:updatePrio()
end
end

panel:RegisterEvent("PLAYER_LOGIN")
panel:RegisterEvent("ADDON_LOADED")

panel:RegisterEvent("BAG_UPDATE")
if isClassic == false then
panel:RegisterEvent("TRAIT_CONFIG_UPDATED")
end
panel:RegisterEvent("PLAYER_REGEN_ENABLED")
panel:RegisterEvent("PLAYER_REGEN_DISABLED")
ham.settingsFrame:RegisterEvent("PLAYER_LOGIN")
ham.settingsFrame:RegisterEvent("ADDON_LOADED")

panel:SetScript("OnEvent", panel.OnEvent)
ham.settingsFrame:SetScript("OnEvent", ham.settingsFrame.OnEvent)

function panel:createPrioFrame(id, iconTexture, positionx, isSpell)
function ham.settingsFrame:createPrioFrame(id, iconTexture, positionx, isSpell)
local icon = CreateFrame("Frame", nil, self.panel, UIParent)
icon:SetFrameStrata("MEDIUM")
icon:SetWidth(ICON_SIZE)
Expand Down Expand Up @@ -99,9 +81,7 @@ function panel:createPrioFrame(id, iconTexture, positionx, isSpell)
return icon
end

function panel:updatePrio()
ham.updateHeals()
ham.updateMacro()
function ham.settingsFrame:updatePrio()
local spellCounter = 0
local itemCounter = 0

Expand Down Expand Up @@ -172,7 +152,8 @@ function panel:updatePrio()
end
end

function panel:InitializeOptions()
function ham.settingsFrame:InitializeOptions()
print("init frame")
self.panel = CreateFrame("Frame", addonName, InterfaceOptionsFramePanelContainer)
---@diagnostic disable-next-line: inject-field
self.panel.name = addonName
Expand All @@ -184,6 +165,7 @@ function panel:InitializeOptions()
self.panel.categoryID = category:GetID() -- for OpenToCategory use
end


------------- HEADER -------------
local title = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge")
title:SetPoint("TOP", 0, -2)
Expand Down Expand Up @@ -211,13 +193,16 @@ function panel:InitializeOptions()

lastStaticElement = cdResetButton


------------- Healthstone button -------------
local raidStoneButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate")
raidStoneButton:SetPoint("TOPLEFT", lastStaticElement, 0, -PADDING)
---@diagnostic disable-next-line: undefined-field
raidStoneButton.Text:SetText("Low Priority Healthstones(Instance only)")
raidStoneButton:HookScript("OnClick", function(_, btn, down)
HAMDB.raidStone = raidStoneButton:GetChecked()
ham.updateHeals()
ham.updateMacro()
self:updatePrio()
end)
raidStoneButton:HookScript("OnEnter", function(_, btn, down)
Expand All @@ -233,6 +218,7 @@ function panel:InitializeOptions()
raidStoneButton:SetChecked(HAMDB.raidStone)
lastStaticElement = raidStoneButton


------------- ITEMS -------------
local witheringPotionButton = nil
local witheringDreamsPotionButton = nil
Expand All @@ -247,6 +233,8 @@ function panel:InitializeOptions()
witheringPotionButton.Text:SetText("Use Potion of Withering Vitality")
witheringPotionButton:HookScript("OnClick", function(_, btn, down)
HAMDB.witheringPotion = witheringPotionButton:GetChecked()
ham.updateHeals()
ham.updateMacro()
self:updatePrio()
end)
witheringPotionButton:HookScript("OnEnter", function(_, btn, down)
Expand All @@ -268,6 +256,8 @@ function panel:InitializeOptions()
witheringDreamsPotionButton.Text:SetText("Use Potion of Withering Dreams")
witheringDreamsPotionButton:HookScript("OnClick", function(_, btn, down)
HAMDB.witheringDreamsPotion = witheringDreamsPotionButton:GetChecked()
ham.updateHeals()
ham.updateMacro()
self:updatePrio()
end)
witheringDreamsPotionButton:HookScript("OnEnter", function(_, btn, down)
Expand All @@ -291,8 +281,6 @@ function panel:InitializeOptions()
currentPrioTitle:SetText("Current Priority")




------------- RESET BUTTON -------------
local btn = CreateFrame("Button", nil, self.panel, "UIPanelButtonTemplate")
btn:SetPoint("BOTTOMLEFT", 2, 3)
Expand All @@ -314,12 +302,14 @@ function panel:InitializeOptions()
witheringPotionButton:SetChecked(HAMDB.witheringPotion)
witheringDreamsPotionButton:SetChecked(HAMDB.witheringDreamsPotion)
end
ham.updateHeals()
ham.updateMacro()
self:updatePrio()
print("Reset successful!")
end)
end

function panel:InitializeClassSpells(relativeTo)
function ham.settingsFrame:InitializeClassSpells(relativeTo)
------------- CLASS / RACIALS -------------
local myClassTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge")
myClassTitle:SetPoint("TOPLEFT", relativeTo, 0, -PADDING_CATERGORY)
Expand Down Expand Up @@ -352,6 +342,8 @@ function panel:InitializeClassSpells(relativeTo)
else
ham.removeFromDB(spell)
end
ham.updateHeals()
ham.updateMacro()
self:updatePrio()
end)
button:HookScript("OnEnter", function(_, btn, down)
Expand Down
11 changes: 6 additions & 5 deletions code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function ham.updateMacro()
EditMacro(macroName, macroName, nil, macroStr)
end

local onCombat = true
local inCombat = true
local updateFrame = CreateFrame("Frame")
updateFrame:RegisterEvent("BAG_UPDATE")
updateFrame:RegisterEvent("PLAYER_LOGIN")
Expand All @@ -181,18 +181,19 @@ updateFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
updateFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
updateFrame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
onCombat = false
inCombat = false
end
if event == "PLAYER_REGEN_DISABLED" then
onCombat = true
inCombat = true
return
end
if event == "PLAYER_REGEN_ENABLED" then
onCombat = false
inCombat = false
end

if onCombat == false then
if inCombat == false then
ham.updateHeals()
ham.updateMacro()
ham.settingsFrame:updatePrio()
end
end)

0 comments on commit 2f6ebcb

Please sign in to comment.