Last active
September 27, 2019 20:56
-
-
Save thefuzzy0ne/f66001d6dfd161d20dee3b9a2631971c to your computer and use it in GitHub Desktop.
A WowLua script to allow searching for reagents from the trade skills window using Auctioneer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Note: Run this only once. If you load it twice, you may have | |
-- unexpected results. If that does happen, just reload your UI | |
-- and reload this script, but ONCE this time. | |
-- | |
--------------------------------------------------------------- | |
-- Instructions for use (After loading the script, of course!): | |
--------------------------------------------------------------- | |
-- | |
-- Step 1: Open The auction window and any professions window and | |
-- navigate to a spell. | |
-- | |
-- Step 2: ALT and LEFT-CLICK the reagent or item you want to | |
-- search for in the trade skills window. | |
-- | |
-- Step 3: Profit! | |
-- | |
-- Note: It doesn't matter which order Steps 1 & 2 are carried | |
-- out in, so long as both windows are open. | |
-- A quick note on `self`. When calling a function on a table like this: | |
-- | |
-- tbl:func() (note the colon) | |
-- | |
-- it's the equivalent of: | |
-- | |
-- tbl.func(tbl) | |
-- | |
-- It's syntactical sugar and table passes itself in as the first argument | |
-- to the function. However, self is set implicitly. It does not appear in | |
-- the function signature unless no colon is used. | |
-- A quick note on global variables (and functions): | |
-- | |
-- _G["someString"] is how we access and set global variables. You can just | |
-- call the global without _G, for example, MyAddon instead of _G["MyAddon"], | |
-- but _G makes it possible to use dynamically generated strings to call a | |
-- global. For example, if you know you have 5 globals, Var1...Var5, in a | |
-- loop, you can call _G["Var"..i], where `i` is a number. | |
------------------------------------------------------------------------ | |
-- Create a frame to register events on. This will also serve as a table | |
-- on which to bolt all of our functions. | |
local frame = CreateFrame("Frame") | |
------------------------------------------------- | |
-- Search the auction house for the given string. | |
------------------------------------------------- | |
local function SearchAuctionHouseForItem(str) | |
-- No string, no service. Sorry! | |
if not str then return end | |
-- Does the auction frame exist and is the browse frame visible? | |
-- Sometimes we need to test for the existance of a frame, because | |
-- a lot of Blizzard's addons are load-on-demand, and therefore won't | |
-- always exist. | |
if AuctionFrame and AuctionFrameBrowse and AuctionFrameBrowse:IsVisible() then | |
-- WoW Retail function. Call if this BrowseResetButton frame exists. | |
if BrowseResetButton then | |
AuctionFrameBrowse_Reset(BrowseResetButton) | |
end | |
AuctionFrameBrowse.page = 0 -- Set the auction page to 0 | |
BrowseName:SetText(str) -- Set the item to search for. | |
AuctionFrameBrowse_Search() -- Go go go! | |
end | |
end | |
----------------------------------------- | |
-- Handle Alt + Left-click on a reagent. | |
----------------------------------------- | |
local function ClickReagantLinkHook(self, button) | |
if button == "LeftButton" and IsAltKeyDown() then | |
local reagentName = getglobal(self:GetName().."Name"):GetText() | |
SearchAuctionHouseForItem(reagentName) | |
end | |
end | |
---------------------------------------------------- | |
-- Handle ALT + Left-click on the Trade Skill icon. | |
---------------------------------------------------- | |
local function ClickCraftIconHook(self, button) | |
if button == "LeftButton" and IsAltKeyDown() then | |
SearchAuctionHouseForItem(CraftName:GetText()) | |
end | |
end | |
------------------------------------------------------------------------- | |
-- Handle Alt + Left-click on the Craft Skill icon. | |
------------------------------------------------------------------------- | |
-- This needs a separate function from the above because of the naming | |
-- inconsistency. The icon for Crafting is called "CraftIcon" but the one | |
-- for Trade Skills is called "TradeSkillSkillIcon". I mean, SkillSkill? | |
-- Heard you the first time, Blizzard. Ever heard of DRY? ;-) | |
------------------------------------------------------------------------- | |
function ClickTradeSkillIconHook(self, button) | |
if button == "LeftButton" and IsAltKeyDown() then | |
SearchAuctionHouseForItem(TradeSkillSkillName:GetText()) | |
end | |
end | |
------------------------------------- | |
-- Handle the TRADE_SKILL_SHOW event. | |
------------------------------------- | |
function frame:TRADE_SKILL_SHOW() | |
-- We only need to call this once for initialization when the frame | |
-- is shown for the first time, so unregister the event. | |
frame:UnregisterEvent("TRADE_SKILL_SHOW") | |
-- Hook onclick event onto the Trade Skill icon. | |
-- Since we can't use a colon here, we have to pass the frame in as the first argument | |
TradeSkillSkillIcon:HookScript("OnClick", ClickTradeSkillIconHook) | |
-- Hook an OnCick handler onto each reagent button. | |
for i=1, MAX_TRADE_SKILL_REAGENTS do | |
local reagentButton = _G["TradeSkillReagent"..i] | |
reagentButton:HookScript("OnClick", ClickReagantLinkHook) | |
end | |
end | |
------------------------------- | |
-- Handle the CRAFT_SHOW event. | |
------------------------------- | |
function frame:CRAFT_SHOW() | |
-- We only need to call this once for initialization when the frame | |
-- is shown for the first time, so unregister the event. | |
frame:UnregisterEvent("CRAFT_SHOW") | |
-- Hook onclick event onto the Trade Skill icon. | |
CraftIcon:HookScript("OnClick", ClickCraftIconHook) | |
-- Hook an OnCick handler onto each reagent button. | |
for i=1, MAX_CRAFT_REAGENTS do | |
local reagentButton = _G["CraftReagent"..i] | |
reagentButton:HookScript("OnClick", ClickReagantLinkHook) | |
end | |
end | |
-- Register the event handler. When an event is fired, the method will be | |
-- called on the frame object for the event. For example, when the | |
-- CRAFT_SHOW event fires, frame:CRAFT_SHOW() will be called. | |
frame:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end) | |
-- Register some events for when the Trade and craft windows are open. | |
-- If the've already been opened, certain constants will be set, so if | |
-- they are set, just run the intialisation functions instead. | |
if not MAX_TRADE_SKILL_REAGENTS then | |
frame:RegisterEvent("TRADE_SKILL_SHOW") | |
else | |
frame:TRADE_SKILL_SHOW() | |
end | |
if not MAX_CRAFT_REAGENTS then | |
frame:RegisterEvent("CRAFT_SHOW") | |
else | |
frame:CRAFT_SHOW() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment