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
61 changes: 26 additions & 35 deletions SuperAPI.lua
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -84,34 +74,35 @@ 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)
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
Expand All @@ -122,12 +113,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)
Expand All @@ -141,16 +132,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
12 changes: 6 additions & 6 deletions SuperAPIOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ SuperAPI:RegisterDefaults("profile", {
guidcombatlog = false,
})

SuperAPI.IfShiftAutoloot = function()
function SuperAPI:IfShiftAutoloot()
if IsShiftKeyDown() then
SetAutoloot(1)
else
SetAutoloot(0)
end
end

SuperAPI.IfShiftNoAutoloot = function()
function SuperAPI:IfShiftNoAutoloot()
if IsShiftKeyDown() then
SetAutoloot(0)
else
Expand All @@ -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)
Copy link
Owner

@balakethelock balakethelock Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make autoloot check shift every 10 times per sec instead of every frame? Possibly can make the feature unreliable for more time-sensitive people.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested my self - working very well, we can adjust it in future if someone make issue =) i have 120 fps - so every frame its overkill, some one -240 =)))

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,
},
Expand Down