314 lines
9.4 KiB
Lua
314 lines
9.4 KiB
Lua
local name, addon = ...
|
|
local parentName = addon['parentName'] or "BrokerPack"
|
|
local childName = "zz_GarrisonToggle"
|
|
local realm = GetRealmName()
|
|
local player = UnitName('player').."-"..realm
|
|
local defaults = {
|
|
['garrisonText'] = 'GS',
|
|
['garrisonHideCombat'] = false,
|
|
['hideStandard'] = true,
|
|
}
|
|
|
|
local options = {
|
|
}
|
|
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
|
|
local db
|
|
local GBM = Enum.GarrisonFollowerType.FollowerType_8_0
|
|
local function OnText(message)
|
|
addon:OnText(childName, message)
|
|
end
|
|
local function switchDisplay(value)
|
|
if(value) then
|
|
AlertFrame:UnregisterEvent("GARRISON_MISSION_FINISHED")
|
|
AlertFrame:UnregisterEvent("GARRISON_BUILDING_ACTIVATABLE")
|
|
else
|
|
AlertFrame:RegisterEvent("GARRISON_MISSION_FINISHED")
|
|
AlertFrame:RegisterEvent("GARRISON_BUILDING_ACTIVATABLE")
|
|
end
|
|
end
|
|
local function getPref(pref)
|
|
return db[pref[#pref]]
|
|
end
|
|
|
|
local function setPref(pref,value)
|
|
if(pref[#pref] == "garrisonText" and value=="") then
|
|
value = nil
|
|
elseif(pref[#pref] == "garrisonHideCombat") then
|
|
switchDisplay(value)
|
|
end
|
|
db[pref[#pref]] = value
|
|
OnText(db['garrisonText'] or GARRISON_LOCATION_TOOLTIP)
|
|
end
|
|
|
|
local gtypes = {}
|
|
local function ResetGBM()
|
|
for k,v in pairs(gtypes) do
|
|
local l = C_Garrison.GetGarrisonInfo(v)
|
|
if(l and l>0) then
|
|
GBM = k
|
|
db['GBM'] = GBM
|
|
GarrisonLandingPage.garrTypeID = gtypes[GBM]
|
|
break
|
|
end
|
|
end
|
|
end
|
|
local function findTypes()
|
|
for k, v in pairs(Enum.GarrisonType) do
|
|
local l = C_Garrison.GetGarrisonInfo(v)
|
|
if(l and tonumber(l)>0) then
|
|
local _, ver, subver = strsplit('_', k)
|
|
local followerType = Enum.GarrisonFollowerType[format('FollowerType_%i_%i',ver, subver)]
|
|
if(followerType) then
|
|
db['missions'][player][followerType] = db['missions'][player][followerType] or {}
|
|
gtypes[followerType] = v
|
|
end
|
|
end
|
|
end
|
|
if(not gtypes[GBM]) then
|
|
ResetGBM()
|
|
end
|
|
end
|
|
local function bclick(swap)
|
|
if(GarrisonLandingPage) then
|
|
if(GarrisonLandingPage:IsShown()) then
|
|
GarrisonLandingPage_Toggle()
|
|
if(not swap) then
|
|
return
|
|
end
|
|
end
|
|
GarrisonLandingPage.garrTypeID = gtypes[GBM]
|
|
if(not GarrisonLandingPage.garrTypeID) then
|
|
ResetGBM()
|
|
findTypes()
|
|
if(not GarrisonLandingPage.garrTypeID) then
|
|
-- print("still no garrType")
|
|
GarrisonLandingPage_Toggle()
|
|
return
|
|
end
|
|
end
|
|
if (C_Garrison.GetGarrisonInfo(GarrisonLandingPage.garrTypeID)) then
|
|
ShowGarrisonLandingPage(gtypes[GBM])
|
|
GarrisonLandingPageReportList_OnShow(GarrisonLandingPage)
|
|
C_Garrison.RequestLandingPageShipmentInfo()
|
|
if ( not GarrisonLandingPageReport.selectedTab ) then
|
|
GarrisonLandingPageReport.unselectedTab = GarrisonLandingPageReport.InProgress
|
|
GarrisonLandingPageReport.selectedTab = GarrisonLandingPageReport.Available
|
|
GarrisonLandingPageReport_SetTab(GarrisonLandingPageReport.unselectedTab)
|
|
else
|
|
GarrisonLandingPageReportList_UpdateItems()
|
|
end
|
|
else
|
|
ResetGBM()
|
|
end
|
|
end
|
|
end
|
|
local function OnButton(self,button)
|
|
local level = C_Garrison.GetGarrisonInfo(C_Garrison.GetLandingPageGarrisonType())
|
|
if(tonumber(level) and tonumber(level)<1) then
|
|
ResetGBM()
|
|
end
|
|
if(button=="LeftButton") then
|
|
if(IsShiftKeyDown()) then
|
|
findTypes()
|
|
local k = 0
|
|
local picknext = nil
|
|
for a,b in pairs(gtypes) do
|
|
local level = C_Garrison.GetGarrisonInfo(b)
|
|
if(level and level > 0) then
|
|
if(picknext) then
|
|
k = a
|
|
break
|
|
end
|
|
if(GBM == a) then
|
|
picknext = true
|
|
end
|
|
|
|
end
|
|
end
|
|
if(k==0) then
|
|
ResetGBM()
|
|
else
|
|
GBM = k
|
|
db['GBM'] = GBM
|
|
end
|
|
bclick(true)
|
|
else
|
|
bclick()
|
|
end
|
|
elseif(button=="RightButton") then
|
|
if(InterfaceOptionsFrame:IsVisible() and not InCombatLockdown()) then
|
|
InterfaceOptionsFrame:Hide()
|
|
else
|
|
InterfaceOptionsFrame_OpenToCategory(childName)
|
|
InterfaceOptionsFrame_OpenToCategory(childName) -- Call it twice because auf WoW-Bug
|
|
end
|
|
end
|
|
end
|
|
|
|
local function IsInProgress(mid)
|
|
for k,v in pairs(C_Garrison.GetInProgressMissions(GBM) or {}) do
|
|
if(tonumber(v['missionID'])==tonumber(mid)) then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
local function GetMission(missionID)
|
|
for k,v in pairs(C_Garrison.GetInProgressMissions(GBM) or {}) do
|
|
if(missionID==v['missionID']) then
|
|
return v
|
|
end
|
|
end
|
|
end
|
|
local function AddDB(missionID)
|
|
local missionInfo = GetMission(missionID)
|
|
if(missionInfo) then
|
|
local mt = {C_Garrison.GetMissionTimes(missionID)}
|
|
db['missions'][player][GBM][missionID] = time() + mt[5]
|
|
end
|
|
end
|
|
local function CheckDB(missionID)
|
|
local missionInfo = GetMission(missionID)
|
|
if(missionInfo and db['missions'][player][GBM]) then
|
|
local old = db['missions'][player][GBM][missionID]
|
|
local mt = {C_Garrison.GetMissionTimes(missionID)}
|
|
db['missions'][player][GBM][missionID] = db['missions'][player][GBM][missionID] or (time() + mt[5])
|
|
if(db['missions'][player][GBM][missionID] ~= old) then
|
|
-- print("RESET",missionInfo['name'])
|
|
end
|
|
end
|
|
end
|
|
local function prune()
|
|
if(C_Garrison.GetInProgressMissions and GBM) then
|
|
local temp = C_Garrison.GetInProgressMissions(GBM)
|
|
if(temp) then
|
|
db['missions'][player][GBM] = {}
|
|
local ti = time()
|
|
for k, v in pairs(temp) do
|
|
if(v['missionEndTime']) then
|
|
db['missions'][player][GBM][v['missionID']] = v['missionEndTime']
|
|
else
|
|
local mt = {C_Garrison.GetMissionTimes(v['missionID'])}
|
|
db['missions'][player][GBM][v['missionID']] = ti + mt[5]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
local function tooltipsort(a, b)
|
|
return (db['missions'][player][GBM][a['missionID']] or 0) < (db['missions'][player][GBM][b['missionID']] or 0)
|
|
end
|
|
local function OnTooltipShow(GameTooltip)
|
|
GameTooltip:AddLine(childName)
|
|
local num = C_Garrison.GetNumFollowers(GBM)
|
|
if(GBM and db['missions'][player][GBM]) then
|
|
local temp = C_Garrison.GetInProgressMissions(GBM)
|
|
local ti = time()
|
|
if(temp) then
|
|
db['missions'][player][GBM] = {}
|
|
for k, v in pairs(temp) do
|
|
db['missions'][player][GBM][v['missionID']] = v['missionEndTime']
|
|
end
|
|
sort(temp,tooltipsort)
|
|
for k,v in pairs(temp) do
|
|
-- CheckDB(tonumber(v['missionID']))
|
|
GameTooltip:AddDoubleLine(v['name'],db['missions'][player][GBM][tonumber(v['missionID'])]>ti and v['timeLeft'] or addon:colorize("Done","00ff00"))
|
|
num = num - v['numFollowers']
|
|
end
|
|
end
|
|
for k, v in pairs(db['missions']) do
|
|
if(k ~= player and v[GBM]) then
|
|
for a,b in pairs(v[GBM]) do
|
|
if(b<ti) then
|
|
GameTooltip:AddDoubleLine(k, addon:colorize(L["Mission done"],"00ff00"))
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
if(IsShiftKeyDown()) then
|
|
for k, v in pairs(db['missions']) do
|
|
if(v[GBM]) then
|
|
local found = 0
|
|
for a,b in pairs(v[GBM]) do
|
|
if(b>=ti) then
|
|
local r = b - ti
|
|
if(r<found or found==0) then
|
|
found = r
|
|
end
|
|
end
|
|
end
|
|
if(found>0) then
|
|
GameTooltip:AddDoubleLine(k, addon:colorize(L['next'](found),"ffff00"))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
local nr = C_Garrison.GetInProgressMissions(GBM)
|
|
local nr2 = C_Garrison.GetAvailableMissions(GBM)
|
|
if(GBM == 123) then
|
|
if(C_ArdenwealdGardening.IsGardenAccessible()) then
|
|
local data = C_ArdenwealdGardening.GetGardenData()
|
|
if(data and data['ready'] and data['ready']>0) then
|
|
GameTooltip:AddLine(addon:colorize(L['ArdenwealdGardening_attention'](data['ready']),'00ff00'))
|
|
end
|
|
end
|
|
end
|
|
if(num>0) then
|
|
GameTooltip:AddDoubleLine(addon:colorize(L["Follower:"],"ffffff"),num.."/"..C_Garrison.GetNumFollowers(GBM))
|
|
end
|
|
if(nr and nr2) then
|
|
GameTooltip:AddDoubleLine(addon:colorize(L["Missions:"],"ffffff"),#nr.."/"..#nr2)
|
|
end
|
|
else
|
|
GameTooltip:AddLine(L["No garrison found!"])
|
|
end
|
|
GameTooltip:AddLine(addon:colorize(L["SHIFT LEFTCLICK toggles Garrison"],"00ff00"))
|
|
GameTooltip:AddLine(addon:colorize(L["Press SHIFT for other characters info"],"00ff00"))
|
|
end
|
|
local function event(self,event,missionID,...)
|
|
if(event == "GARRISON_MISSION_COMPLETE_RESPONSE") then
|
|
local canComplete, succeeded = ...
|
|
if(canComplete) then
|
|
-- db['missions'][player][GBM][missionID] = nil
|
|
end
|
|
elseif(event == "GARRISON_MISSION_STARTED") then
|
|
AddDB(missionID)
|
|
elseif(event == "ADDON_LOADED") then
|
|
if(missionID == 'Blizzard_GarrisonUI') then
|
|
findTypes()
|
|
self:UnregisterEvent(event)
|
|
end
|
|
return
|
|
end
|
|
prune()
|
|
end
|
|
local function init()
|
|
db = addon['db']['profile'][childName]
|
|
db['missions'] = db['missions'] or {}
|
|
db['missions'][player] = db['missions'][player] or {}
|
|
options = addon:InitConfig(childName, true, {
|
|
['type'] = "launcher",
|
|
['OnClick'] = OnButton,
|
|
['text'] = db['garrisonText'] or GARRISON_LOCATION_TOOLTIP,
|
|
['OnTooltipShow'] = OnTooltipShow,
|
|
['icon'] = "Interface\\Icons\\Achievement_Arena_2v2_6",
|
|
}, getPref, setPref)
|
|
addon:AddConfigEntry(childName,'toggle','garrisonHideCombat',L["Hide Alert"],L["Hide mission complete alert"],1,nil,nil,nil,nil)
|
|
addon:AddConfigEntry(childName,'toggle','hideStandard',L["Hide Blizzard"],L["Hide Blizzards default garrison button"],1,nil,nil,nil,nil)
|
|
addon:AddConfigEntry(childName,'input','garrisonText',L["Display Text"],L["Display Text description"],1,nil,nil,nil,nil)
|
|
addon:RegisterFunc({"ADDON_LOADED","GARRISON_MISSION_STARTED","GARRISON_MISSION_FINISHED","GARRISON_MISSION_COMPLETE_RESPONSE","PLAYER_LOGOUT"},"OnEvent", event)
|
|
db['GBM'] = db['GBM'] or Enum.GarrisonFollowerType.FollowerType_8_0
|
|
GBM = db['GBM']
|
|
if(not IsAddOnLoaded("Blizzard_GarrisonUI")) then
|
|
UIParentLoadAddOn("Blizzard_GarrisonUI")
|
|
end
|
|
if(db['hideStandard']) then
|
|
GarrisonLandingPageMinimapButton:UnregisterAllEvents()
|
|
GarrisonLandingPageMinimapButton:Hide()
|
|
end
|
|
|
|
switchDisplay(db['garrisonHideCombat'])
|
|
end
|
|
addon:startup(name, childName, init, true, defaults) |