/trunk
local lib, oldminor = LibStub:NewLibrary('idLibrary-1.1', 1) |
if not lib then return end |
lib.events = {} |
lib.timers = {} |
lib.frame = CreateFrame('Frame') |
lib.frame:SetScript('OnEvent', function (frame, event, ...) |
local event = lib.events[event] |
if event then |
for k,v in pairs(event) do |
v(...) |
end |
end |
end) |
lib.frame:SetScript('OnUpdate', function (frame, elapsed) |
local v |
for i = #lib.timers, 1, -1 do |
v = lib.timers[i] |
if v.time >= v.interval then |
v.time = v.time - v.interval |
v.func() |
else |
v.time = v.time + elapsed |
end |
end |
end) |
function lib:Print (mixed) |
ChatFrame1:AddMessage(tostring(mixed) or 'nil') |
end |
-- events |
function lib:RegisterEvent (name, event, func) |
self.events[event] = self.events[event] or {} |
self.events[event][name] = func |
self.frame:RegisterEvent(event) |
end |
function lib:UnregisterEvent (name, event) |
if self.events[event] then |
self.events[event][name] = nil |
if #self.events[event] == 0 then |
self.events[event] = nil |
self.frame:UnregisterEvent(event) |
end |
end |
end |
-- timers |
function lib:RegisterTimer (name, func, interval) |
self.timers[name] = { |
interval = interval or 1, |
time = 0, |
func = func |
} |
end |
function lib:UnregisterTimer (name) |
self.timers[name] = nil |
end |
-- frames |
function lib:Move (f, p1, p, p2, x, y) |
f:ClearAllPoints() |
f:SetPoint(p1, p, p2, x, y) |
end |
function lib:Show (f) |
f:SetScript('OnShow', nil) |
f:Show() |
end |
function lib:Hide (f) |
f:SetScript('OnShow', f.Hide) |
f:Hide() |
end |
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info |
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke |
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS! |
local LibStub = _G[LIBSTUB_MAJOR] |
if not LibStub or LibStub.minor < LIBSTUB_MINOR then |
LibStub = LibStub or {libs = {}, minors = {} } |
_G[LIBSTUB_MAJOR] = LibStub |
LibStub.minor = LIBSTUB_MINOR |
function LibStub:NewLibrary(major, minor) |
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") |
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.") |
local oldminor = self.minors[major] |
if oldminor and oldminor >= minor then return nil end |
self.minors[major], self.libs[major] = minor, self.libs[major] or {} |
return self.libs[major], oldminor |
end |
function LibStub:GetLibrary(major, silent) |
if not self.libs[major] and not silent then |
error(("Cannot find a library instance of %q."):format(tostring(major)), 2) |
end |
return self.libs[major], self.minors[major] |
end |
function LibStub:IterateLibraries() return pairs(self.libs) end |
setmetatable(LibStub, { __call = LibStub.GetLibrary }) |
end |
## Interface: 20400 |
## Interface: 20300 |
## Title: Industrial: Quest Automation |
## Credits: Industrial |
## Notes: Drive by quest NPC interaction |
Libraries\LibStub.lua |
Libraries\idLibrary-1.1.lua |
Addon.lua |
--[[---------------------------------------------------------------------------- |
Copyright (c) 2008, Tom Wieland |
Copyright (c) 2007, Tom Wieland |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
------------------------------------------------------------------------------]] |
local _G = _G |
local lib = LibStub('idLibrary-1.1') |
local quests = {} |
local frame = CreateFrame('Frame') |
local function stripText (t) -- thx Shadowed |
if not t then return end |
end |
local function GOSSIP_SHOW (event) |
if IsShiftKeyDown() then return end |
if IsShiftKeyDown() or not GossipFrame:IsVisible() then return end |
local button |
local text |
local action |
if GossipFrame.buttonIndex then |
for i = 1, GossipFrame.buttonIndex do |
button = _G['GossipTitleButton'..i] |
text = stripText(button:GetText()) |
for i = 1, GossipFrame.buttonIndex do |
button = _G['GossipTitleButton'..i] |
text = stripText(button:GetText()) |
if button:IsVisible() then |
if button.type == 'Available' then |
button:Click() |
elseif button.type == 'Active' then |
if quests[text] then |
quests[text] = nil |
button:Click() |
end |
if button:IsVisible() then |
if button.type == 'Active' then |
if quests[text] then |
action = action or button |
quests[text] = nil |
end |
elseif button.type == 'Available' then |
action = action or button |
end |
end |
end |
end |
local function QUEST_GREETING (event) |
if IsShiftKeyDown() then return end |
local button |
local text |
for i = 1, 38 do |
button = _G['QuestTitleButton'..i] |
if button then |
text = stripText(button:GetText()) |
if button:IsVisible() then |
if button.isActive == 1 then |
if quests[text] then |
quests[text] = nil |
button:Click() |
end |
else |
button:Click() |
end |
end |
end |
if action then |
action:Click() |
end |
end |
AcceptQuest() |
end |
local function QUEST_ACCEPT_CONFIRM (event) |
if IsShiftKeyDown() then return end |
end |
local function QUEST_PROGRESS (event) |
if IsShiftKeyDown() then return end |
if IsQuestCompletable() then |
SelectQuestLogEntry(startingQuestLogSelection) |
end |
local function OnEvent (frame, event, ...) |
AAA = {event, ...} |
if event == 'GOSSIP_SHOW' then |
GOSSIP_SHOW(...) |
elseif event == 'QUEST_GREETING' then |
QUEST_GREETING(...) |
elseif event == 'QUEST_DETAIL' then |
QUEST_DETAIL(...) |
elseif event == 'QUEST_PROGRESS' then |
QUEST_PROGRESS(...) |
elseif event == 'QUEST_COMPLETE' then |
QUEST_COMPLETE(...) |
elseif event == 'QUEST_LOG_UPDATE' then |
QUEST_LOG_UPDATE(...) |
end |
local function enable () |
lib:RegisterEvent('idQuestAutomation', 'GOSSIP_SHOW', GOSSIP_SHOW) |
lib:RegisterEvent('idQuestAutomation', 'QUEST_DETAIL', QUEST_DETAIL) |
lib:RegisterEvent('idQuestAutomation', 'QUEST_PROGRESS', QUEST_PROGRESS) |
lib:RegisterEvent('idQuestAutomation', 'QUEST_COMPLETE', QUEST_COMPLETE) |
lib:RegisterEvent('idQuestAutomation', 'QUEST_LOG_UPDATE', QUEST_LOG_UPDATE) |
end |
frame:SetScript('OnEvent', OnEvent) |
frame:RegisterEvent('GOSSIP_SHOW') |
frame:RegisterEvent('QUEST_GREETING') |
frame:RegisterEvent('QUEST_DETAIL') |
frame:RegisterEvent('QUEST_PROGRESS') |
frame:RegisterEvent('QUEST_COMPLETE') |
frame:RegisterEvent('QUEST_LOG_UPDATE') |
local function disable () |
lib:UnregisterEvent('idQuestAutomation', 'GOSSIP_SHOW') |
lib:UnregisterEvent('idQuestAutomation', 'QUEST_DETAIL') |
lib:UnregisterEvent('idQuestAutomation', 'QUEST_PROGRESS') |
lib:UnregisterEvent('idQuestAutomation', 'QUEST_COMPLETE') |
lib:UnregisterEvent('idQuestAutomation', 'QUEST_LOG_UPDATE') |
end |
lib:RegisterEvent('idQuestAutomation-Enable', 'PLAYER_LOGIN', enable) |
lib:RegisterEvent('idQuestAutomation-Disable', 'PLAYER_LOGOUT', disable) |