zz_Quest/core.lua

96 lines
3.2 KiB
Lua

local name, addon = ...
local parentName = addon['parentName'] or "BrokerPack"
local childName = "zz_Quest" -- Change childName to your addons foldername
local defaults = {
}
local options = {
}
local db
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
local function OnClick(self, button)
if(IsShiftKeyDown() and button == "LeftButton") then
addon['db']['global']['ldbicons'][childName]['hide'] = not addon['db']['global']['ldbicons'][childName]['hide']
if(ldbicon) then
if(addon['db']['global']['ldbicons'][childName]['hide']) then
ldbicon:Hide(childName)
else
ldbicon:Show(childName)
end
end
else
if(InterfaceOptionsFrame:IsVisible() and not InCombatLockdown()) then
InterfaceOptionsFrame:Hide()
else
InterfaceOptionsFrame_OpenToCategory(name)
InterfaceOptionsFrame_OpenToCategory(name) -- Twice because of a bug in InterfaceOptionsFrame_OpenToCategory
end
end
end
local function OnText(message)
addon:OnText(childName, message)
end
local function getPref(pref)
return db[pref[#pref]]
end
local function QuestUpdate(self, event, ...)
local maxNumQuests = C_QuestLog.GetMaxNumQuestsCanAccept()
local numEntries, numQuests
if(C_QuestLog.GetNumQuestLogEntries) then
numEntries, numQuests = C_QuestLog.GetNumQuestLogEntries()
else
numEntries, numQuests = GetNumQuestLogEntries()
end
if(db['slots']) then
numQuests = maxNumQuests - numQuests
end
local line = format("%i/%i",numQuests, maxNumQuests)
if(numQuests==maxNumQuests or numQuests==0) then
line = addon:colorize(line, 'ff0000')
end
OnText(line)
end
local function setPref(pref,value)
db[pref[#pref]] = value
if(pref[#pref]=='slots') then
QuestUpdate()
end
end
local function OnTooltip(tip)
tip:AddLine(childName)
local mapid = C_Map.GetBestMapForUnit("player")
local quests = C_QuestLog.GetQuestsOnMap(mapid)
local header = {}
for num, quest in ipairs(quests) do
local objectives = C_QuestLog.GetQuestObjectives(quest['questID'])
if(#objectives>0) then
for num, objective in ipairs(objectives) do
if(not objective['finished']) then
if(not header[quest['questID']]) then
header[quest['questID']] = true
if(C_QuestLog.GetTitleForQuestID) then
tip:AddLine(C_QuestLog.GetTitleForQuestID(quest['questID']))
else
tip:AddLine(C_QuestLog.GetQuestInfo(quest['questID']))
end
end
tip:AddLine(addon:colorize(format(" %s", objective['text']),'ffffff'))
end
end
end
end
end
local function init()
options = addon:InitConfig(childName, true, {
['type'] = "data source", -- 'data source | launcher'
['name'] = childName,
['OnClick'] = OnClick,
['OnTooltipShow'] = OnTooltip,
}, getPref, setPref)
db = addon['db']['profile'][childName]
addon:AddConfigEntry(childName, "toggle","slots","Show free slots",nil,1,nil,nil,nil,nil,options['args'][childName])
addon:RegisterFunc({'QUEST_ACCEPTED','QUEST_AUTOCOMPLETE','QUEST_COMPLETE','QUEST_DATA_LOAD_RESULT','QUEST_DETAIL','QUEST_LOG_CRITERIA_UPDATE','QUEST_LOG_UPDATE','QUEST_POI_UPDATE','QUEST_REMOVED','QUEST_TURNED_IN','QUEST_WATCH_LIST_CHANGED','QUEST_WATCH_UPDATE','QUESTLINE_UPDATE','TASK_PROGRESS_UPDATE','TREASURE_PICKER_CACHE_FLUSH','WAYPOINT_UPDATE','WORLD_QUEST_COMPLETED_BY_SPELL'}, "OnEvent", QuestUpdate)
end
addon:startup(name, childName, init, true, defaults)