From 1136201cf5d276440158394589ce328b7759bbab Mon Sep 17 00:00:00 2001 From: LaYt Date: Thu, 14 Nov 2024 15:35:09 +0700 Subject: [PATCH 1/2] Proper use of Ace libs. Dont use onUpdate for monitor 'Shift' key state. --- SuperAPI.lua | 58 +++++++++++++++++++-------------------------- SuperAPIOptions.lua | 12 +++++----- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/SuperAPI.lua b/SuperAPI.lua index ef7465a..60d6541 100644 --- a/SuperAPI.lua +++ b/SuperAPI.lua @@ -1,5 +1,5 @@ -- No superwow, no superapi -if not SUPERWOW_VERSION then +if not SUPERWOW_VERSION and not SetAutoloot then DEFAULT_CHAT_FRAME:AddMessage("No SuperWoW detected"); -- this version of SuperAPI is made for SuperWoW 1.2 -- can somebody make this warning better? @@ -10,7 +10,6 @@ SUPERAPI_ContainerItemsTable = {} SuperAPI = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceDebug-2.0", "AceModuleCore-2.0", "AceConsole-2.0", "AceDB-2.0", "AceHook-2.1") SuperAPI:RegisterDB("SuperAPIDB") -SuperAPI.frame = CreateFrame("Frame", "SuperAPI", UIParent) function SuperAPI:OnEnable() -- Let macro frame allow 511 characters @@ -22,24 +21,15 @@ function SuperAPI:OnEnable() OPTION_TOOLTIP_PARTY_CHAT_BUBBLES = "Shows whisper, party, raid, and battleground chat text in speech bubbles above characters' heads."; PARTY_CHAT_BUBBLES_TEXT = "Show Whisper and Group Chat Bubbles"; - SuperAPI.SetItemRefOriginal = SetItemRef - SuperAPI.SpellButton_OnClickOriginal = SpellButton_OnClick - SuperAPI.SetItemButtonCountOriginal = SetItemButtonCount - SuperAPI.SetActionOriginal = GameTooltip.SetAction - SuperAPI.UnitFrame_OnEnterOriginal = UnitFrame_OnEnter - SuperAPI.UnitFrame_OnLeaveOriginal = UnitFrame_OnLeave - - -- activate hooks - SetItemRef = SuperAPI.SetItemRef - SpellButton_OnClick = SuperAPI.SpellButton_OnClick - SetItemButtonCount = SuperAPI.SetItemButtonCount - GameTooltip.SetAction = SuperAPI.SetAction - UnitFrame_OnEnter = SuperAPI.UnitFrame_OnEnter - UnitFrame_OnLeave = SuperAPI.UnitFrame_OnLeave - - SuperAPI.frame:RegisterEvent("BAG_UPDATE") - SuperAPI.frame:RegisterEvent("BAG_UPDATE_COOLDOWN") - SuperAPI.frame:SetScript("OnEvent", SuperAPI.OnEvent) + self:Hook('SetItemRef', true) + self:Hook('SpellButton_OnClick', true) + self:Hook('SetItemButtonCount', true) + self:Hook(GameTooltip, 'SetAction', true) + self:Hook('UnitFrame_OnEnter', true) + self:Hook('UnitFrame_OnLeave', true) + + SuperAPI:RegisterEvent("BAG_UPDATE",'OnEvent') + SuperAPI:RegisterEvent("BAG_UPDATE_COOLDOWN",'OnEvent') -- this chatcommand is empty. It is essential for showing tooltips of macros -- the format for showing a tooltip on a macro is EXACTLY this: /tooltip spell:spellid and then skip line @@ -84,34 +74,34 @@ end -- HOOKS -- -- Global function to get a spell link from its exact id -SuperAPI.GetSpellLink = function(id) +function SuperAPI:GetSpellLink(id) local spellname = SpellInfo(id) local link = "\124cffffffff\124Henchant:" .. id .. "\124h[" .. spellname .. "]\124h\124r" return link end -- reformat "Enchant" itemlinks to better supported "Spell" itemlinks -SuperAPI.SetItemRef = function(link, text, button) +function SuperAPI:SetItemRef(link, text, button) link = gsub(link, "spell:", "enchant:") - SuperAPI.SetItemRefOriginal(link, text, button) + SuperAPI.hooks['SetItemRef'](link, text, button) end -- hooking spellbook frame to get a spell link on shift clicking a spell's button with chatframe open -SuperAPI.SpellButton_OnClick = function(drag) +function SuperAPI:SpellButton_OnClick(drag) if ((not drag) and IsShiftKeyDown() and ChatFrameEditBox:IsVisible() and (not MacroFrame or not MacroFrame:IsVisible())) then local bookId = SpellBook_GetSpellID(this:GetID()); local _, _, spellID = GetSpellName(bookId, SpellBookFrame.bookType) local link = SuperAPI.GetSpellLink(spellID) ChatFrameEditBox:Insert(link) else - SuperAPI.SpellButton_OnClickOriginal(drag) + SuperAPI.hooks['SpellButton_OnClick'](drag) end end -- hooking bags item button frames to show uses count -SuperAPI.SetItemButtonCount = function(button, count) +function SuperAPI:SetItemButtonCount(button, count) if not button or not count then - return SuperAPI.SetItemButtonCountOriginal(button, count) + return SuperAPI.hooks['SetItemButtonCount'](button, count) end if (count < 0) then if (count < -999) then @@ -122,12 +112,12 @@ SuperAPI.SetItemButtonCount = function(button, count) getglobal(button:GetName() .. "Count"):SetFontObject(NumberFontNormalYellow); else getglobal(button:GetName() .. "Count"):SetFontObject(NumberFontNormal); - SuperAPI.SetItemButtonCountOriginal(button, count) + SuperAPI.hooks['SetItemButtonCount'](button, count) end end -- hooking actionbutton tooltip to show item tooltip on macros -SuperAPI.SetAction = function(this, buttonID) +function SuperAPI:SetAction(this, buttonID) --local name, actiontype, macroID = GetActionText(buttonID) --if actiontype == "MACRO" then -- local _,_, body = GetMacroInfo(macroID) @@ -141,16 +131,16 @@ SuperAPI.SetAction = function(this, buttonID) -- end --end -- - return SuperAPI.SetActionOriginal(this, buttonID) + return SuperAPI.hooks[GameTooltip]['SetAction'](this, buttonID) end -- Add Mouseover casting to default blizzard unitframes and all unitframe addons that use the same function -SuperAPI.UnitFrame_OnEnter = function() - SuperAPI.UnitFrame_OnEnterOriginal() + function SuperAPI:UnitFrame_OnEnter() + SuperAPI.hooks['UnitFrame_OnEnter']() SetMouseoverUnit(this.unit) end -SuperAPI.UnitFrame_OnLeave = function() - SuperAPI.UnitFrame_OnLeaveOriginal() +function SuperAPI:UnitFrame_OnLeave() + SuperAPI.hooks['UnitFrame_OnLeave']() SetMouseoverUnit() end diff --git a/SuperAPIOptions.lua b/SuperAPIOptions.lua index 7e5a794..caca7bf 100644 --- a/SuperAPIOptions.lua +++ b/SuperAPIOptions.lua @@ -23,7 +23,7 @@ SuperAPI:RegisterDefaults("profile", { guidcombatlog = false, }) -SuperAPI.IfShiftAutoloot = function() +function SuperAPI:IfShiftAutoloot() if IsShiftKeyDown() then SetAutoloot(1) else @@ -31,7 +31,7 @@ SuperAPI.IfShiftAutoloot = function() end end -SuperAPI.IfShiftNoAutoloot = function() +function SuperAPI:IfShiftNoAutoloot() if IsShiftKeyDown() then SetAutoloot(0) else @@ -57,19 +57,19 @@ SuperAPI.cmdtable = { if v == SuperAPI.AUTOLOOT_OPTIONS[1] then -- "Always on" SetAutoloot(1) - SuperAPI.frame:SetScript("OnUpdate", nil) + SuperAPI:CancelScheduledEvent('SuperAPIAutoloot') elseif v == SuperAPI.AUTOLOOT_OPTIONS[2] then -- "Always off" SetAutoloot(0) - SuperAPI.frame:SetScript("OnUpdate", nil) + SuperAPI:CancelScheduledEvent('SuperAPIAutoloot') elseif v == SuperAPI.AUTOLOOT_OPTIONS[3] then -- "Shift to toggle on" SetAutoloot(0) - SuperAPI.frame:SetScript("OnUpdate", SuperAPI.IfShiftAutoloot) + SuperAPI:ScheduleRepeatingEvent('SuperAPIAutoloot',SuperAPI.IfShiftAutoloot, 1/10) elseif v == SuperAPI.AUTOLOOT_OPTIONS[4] then -- "Shift to toggle off" SetAutoloot(1) - SuperAPI.frame:SetScript("OnUpdate", SuperAPI.IfShiftNoAutoloot) + SuperAPI:ScheduleRepeatingEvent('SuperAPIAutoloot',SuperAPI.IfShiftNoAutoloot, 1/10) end end, }, From 025fc8977080e21caa11338892e8e08e808d30fd Mon Sep 17 00:00:00 2001 From: LaYt Date: Wed, 20 Nov 2024 15:24:44 +0700 Subject: [PATCH 2/2] some function calls tested and fixed --- SuperAPI.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/SuperAPI.lua b/SuperAPI.lua index 60d6541..4cacddf 100644 --- a/SuperAPI.lua +++ b/SuperAPI.lua @@ -83,7 +83,8 @@ end -- reformat "Enchant" itemlinks to better supported "Spell" itemlinks function SuperAPI:SetItemRef(link, text, button) link = gsub(link, "spell:", "enchant:") - SuperAPI.hooks['SetItemRef'](link, text, button) + + SuperAPI.hooks.SetItemRef(link, text, button) end -- hooking spellbook frame to get a spell link on shift clicking a spell's button with chatframe open @@ -91,17 +92,17 @@ function SuperAPI:SpellButton_OnClick(drag) if ((not drag) and IsShiftKeyDown() and ChatFrameEditBox:IsVisible() and (not MacroFrame or not MacroFrame:IsVisible())) then local bookId = SpellBook_GetSpellID(this:GetID()); local _, _, spellID = GetSpellName(bookId, SpellBookFrame.bookType) - local link = SuperAPI.GetSpellLink(spellID) + local link = SuperAPI:GetSpellLink(spellID) ChatFrameEditBox:Insert(link) else - SuperAPI.hooks['SpellButton_OnClick'](drag) + SuperAPI.hooks.SpellButton_OnClick(drag) end end -- hooking bags item button frames to show uses count function SuperAPI:SetItemButtonCount(button, count) if not button or not count then - return SuperAPI.hooks['SetItemButtonCount'](button, count) + return SuperAPI.hooks.SetItemButtonCount(button, count) end if (count < 0) then if (count < -999) then @@ -112,7 +113,7 @@ function SuperAPI:SetItemButtonCount(button, count) getglobal(button:GetName() .. "Count"):SetFontObject(NumberFontNormalYellow); else getglobal(button:GetName() .. "Count"):SetFontObject(NumberFontNormal); - SuperAPI.hooks['SetItemButtonCount'](button, count) + SuperAPI.hooks.SetItemButtonCount(button, count) end end @@ -131,16 +132,16 @@ function SuperAPI:SetAction(this, buttonID) -- end --end -- - return SuperAPI.hooks[GameTooltip]['SetAction'](this, buttonID) + return SuperAPI.hooks[GameTooltip].SetAction(this, buttonID) end -- Add Mouseover casting to default blizzard unitframes and all unitframe addons that use the same function function SuperAPI:UnitFrame_OnEnter() - SuperAPI.hooks['UnitFrame_OnEnter']() + SuperAPI.hooks.UnitFrame_OnEnter() SetMouseoverUnit(this.unit) end function SuperAPI:UnitFrame_OnLeave() - SuperAPI.hooks['UnitFrame_OnLeave']() + SuperAPI.hooks.UnitFrame_OnLeave() SetMouseoverUnit() end