--[[
file errata
File Author: @file-author@
File Revision: @file-revision@
FIle Date: @file-date-iso@
]]--
-- for Mikk's FindGlobals app -------------------------------------------------
-- GLOBALS: FeedTillersDB
-- main definitions -----------------------------------------------------------
local addon_name, addon = ...
local lqt = LibStub("LibQTip-1.0")
local TOMTOM = _G.TomTom
local player_realm = GetRealmName()
local full_name = UnitName("player") .. " - " .. player_realm
-- localize addon -------------------------------------------------------------
-- see [url]https://phanx.net/addons/tutorials/localize[/url]
local L = setmetatable({}, {__index = function(t, k)
local v = tostring(k)
rawset(t, k, v)
return v
end})
local LOCALE = GetLocale()
if LOCALE == "enUS" then
L["Click a line to set a TomTom waypoint, if installed"] = "Click a line to set a TomTom waypoint, if installed"
L["Click the plugin to sort by Tiller name or item name"] = "Click the plugin to sort by Tiller name or item name"
L["error, cannot find TomTom, no waypoint added."] = "error, cannot find TomTom, no waypoint added."
L["error, items in tooltip not yet populated. Try again later"] = "error, items in tooltip not yet populated. Try again later"
L["Hold the <Control> key and click to hide Best Friend Tillers"] = "Hold the <Control> key and click to hide Best Friend Tillers"
L["Hold the <Shift> key and click to hide already fed Tillers"] = "Hold the <Shift> key and click to hide already fed Tillers"
elseif LOCALE == "esES" then
--@localization(locale="esES", format="lua_additive_table")@
elseif LOCALE == "esMX" then
--@localization(locale="esMX", format="lua_additive_table")@
elseif LOCALE == "itIT" then
--@localization(locale="itIT", format="lua_additive_table")@
elseif LOCALE == "ptBR" then
--@localization(locale="ptBR", format="lua_additive_table")@
elseif LOCALE == "frFR" then
--@localization(locale="frFR", format="lua_additive_table")@
elseif LOCALE == "deDE" then
--@localization(locale="deDE", format="lua_additive_table")@
elseif LOCALE == "ruRU" then
--@localization(locale="ruRU", format="lua_additive_table")@
elseif LOCALE == "zhCN" then
--@localization(locale="zhCN", format="lua_additive_table")@
elseif LOCALE == "zhTW" then
--@localization(locale="zhTW", format="lua_additive_table")@
elseif LOCALE == "koKR" then
--@localization(locale="koKR", format="lua_additive_table")@
end
-- variables ------------------------------------------------------------------
local TILLERS
local npcs = {
{ factionID = 1273, itemID = 74643, questID = 30439, coords = "53.6 52.6" }, -- Jogu the Drunk
{ factionID = 1275, itemID = 74651, questID = 30386, coords = "31.5 58.1" }, -- Ella
{ factionID = 1276, itemID = 74649, questID = 30396, coords = "30.9 53.1" }, -- Old Hillpaw
{ factionID = 1277, itemID = 74647, questID = 30402, coords = "34.4 46.8" }, -- Chee Chee
{ factionID = 1278, itemID = 74645, questID = 30408, coords = "29.5 30.6" }, -- Sho
{ factionID = 1279, itemID = 74642, questID = 30414, coords = "44.6 34.1" }, -- Haohan Mudclaw
{ factionID = 1280, itemID = 74652, questID = 30433, coords = "45.1 33.8" }, -- Tina Mudclaw
{ factionID = 1281, itemID = 74644, questID = 30390, coords = "53.2 51.8" }, -- Gina Mudclaw
{ factionID = 1282, itemID = 74655, questID = 30427, coords = "41.7 30.0" }, -- Fish Fellreed
{ factionID = 1283, itemID = 74654, questID = 30421, coords = "48.3 33.8" }, -- Farmer Fung
}
-- sorting functions ----------------------------------------------------------
local function SortByName(a, b)
return a.name < b.name
end
local function SortByItem(a, b)
if not a.item or not b.item then
return print("|cFFFF0000Feed Tillers: |r" .. L["error, items in tooltip not yet populated. Try again later"])
end
return a.item < b.item
end
-- broker functions -----------------------------------------------------------
local function dataObject_OnEnter(frame)
local tooltip = lqt:Acquire("FeedTillersTT")
tooltip:SmartAnchorTo(frame)
tooltip:EnableMouse(true)
addon:UpdateTooltip()
tooltip:Show()
end
local function dataObject_OnLeave()
-- empty dummy
end
local function dataObject_OnClick(frame, button)
if button == "LeftButton" and IsShiftKeyDown() then
FeedTillersDB[full_name].Hide_Complete = not FeedTillersDB[full_name].Hide_Complete
elseif button == "LeftButton" and IsControlKeyDown() then
FeedTillersDB[full_name].Hide_Exalted = not FeedTillersDB[full_name].Hide_Exalted
else
FeedTillersDB[full_name].Current_Sort = FeedTillersDB[full_name].Current_Sort == "NAME" and "ITEM" or "NAME"
sort(npcs, FeedTillersDB[full_name].Current_Sort == "NAME" and SortByName or SortByItem)
end
end
-- the line script handler
local function line_OnMouseUp(frame, npc)
if TOMTOM then
local x, y = strsplit(" ", npc.coords)
x, y = tonumber(x), tonumber(y)
local desc = GetFactionInfoByID(npc.factionID)
-- TomTom API: continent, mapID, x, y, description, persistant, minimap, world, callbacks, silent, crazyArrow
TOMTOM:AddZWaypoint(862, 807, x, y, desc, true, true, true, nil, nil, true) -- 862 is continent Pandaria, 807 is the mapID for Valley of the Four Winds
else
return print("|cFFFF0000Feed Tillers: |r" .. L["error, cannot find TomTom, no waypoint added."])
end
end
function addon:UpdateTooltip()
if not lqt:IsAcquired("FeedTillersTT") then return end
local tooltip = lqt:Acquire("FeedTillersTT", 3, "LEFT", "LEFT", "RIGHT")
tooltip:Clear()
local currLine, item_name, isBestFriend, isComplete
TILLERS = TILLERS or GetFactionInfoByID(1272) -- cache name of the faction group for localization
currLine = tooltip:AddHeader(TILLERS, ITEMS, COMPLETE)
local hideComplete = FeedTillersDB[full_name].Hide_Complete -- for brevity
local hideExalted = FeedTillersDB[full_name].Hide_Exalted -- for brevity
for i = 1, #npcs do
local npc = npcs[i]
npc.name = GetFactionInfoByID(npc.factionID)
npc.itemName = GetItemInfo(npc.itemID)
-- cache items, try to load from saved variables
FeedTillersDB[npc.name] = FeedTillersDB[npc.name] or npc.name
FeedTillersDB[npc.name].itemName = FeedTillersDB[npc.name].itemName or npc.itemName
item_name = FeedTillersDB[npc.name].itemName
isBestFriend = select(9, GetFriendshipReputation(npc.factionID)) -- number or nil if at max rank
isComplete = IsQuestFlaggedCompleted(npc.questID)
-- populate columns
if hideExalted and isBestFriend == nil then
currLine = tooltip:AddLine() -- add nothing
elseif hideComplete and isComplete then
currLine = tooltip:AddLine() -- add nothing
else
if not isComplete then
local count = GetItemCount(npc.itemID)
currLine = tooltip:AddLine(npc.name, item_name or "", format("%d/%d", count, 5))
if count < 5 then
tooltip:SetLineColor(currLine, 1, 0.1, 0.1, 0.3)
else
currLine = tooltip:AddLine(npc.name, item_name or "", YES)
tooltip:SetLineColor(currLine, 0.1, 1, 0.1, 0.3)
end
end
end
tooltip:SetLineScript(currLine, "OnMouseUp", line_OnMouseUp, npc)
end
currLine = tooltip:AddLine(" ")
currLine = tooltip:AddLine(" ")
currLine = tooltip:SetCell(currLine, 1, NORMAL_FONT_COLOR_CODE .. L["Click the plugin to sort by Tiller name or item name"], "LEFT", 3)
currLine = tooltip:AddLine(" ")
currLine = tooltip:SetCell(currLine, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Shift> key and click to hide already fed Tillers"], "LEFT", 3)
currLine = tooltip:AddLine(" ")
currLine = tooltip:SetCell(currLine, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Control> key and click to hide Best Friend Tillers"], "LEFT", 3)
currLine = tooltip:AddLine(" ")
currLine = tooltip:SetCell(currLine, 1, NORMAL_FONT_COLOR_CODE .. L["Click a line to set a TomTom waypoint, if installed"], "LEFT", 3)
end
local function CreateBroker()
LibStub("LibDataBroker-1.1"):NewDataObject(addon_name, {
type = "data source",
text = "Feed Tillers",
icon = [[Interface/ICONS/Achievement_Profession_ChefHat]],
OnClick = dataObject_OnClick,
OnEnter = dataObject_OnEnter,
OnLeave = dataObject_OnLeave
})
end
-- event handler --------------------------------------------------------------
function addon:ADDON_LOADED(self, event, ...)
if ... ~= addon_name then return end
FeedTillersDB = FeedTillersDB or {}
FeedTillersDB[full_name] = FeedTillersDB[full_name] or {}
FeedTillersDB[full_name].Hide_Complete = FeedTillersDB[full_name].Hide_Complete or false
FeedTillersDB[full_name].Hide_Exalted = FeedTillersDB[full_name].Hide_Exalted or false
FeedTillersDB[full_name].Current_Sort = FeedTillersDB[full_name].Current_Sort or "NAME"
TILLERS = TILLERS or GetFactionInfoByID(1272) -- cache name of the faction group for localization
CreateBroker()
self.event_frame:UnregisterEvent("ADDON_LOADED")
end
-- register events ------------------------------------------------------------
addon.event_frame = CreateFrame("Frame")
addon.event_frame:SetScript("OnEvent", function(self, event, ...)
addon[event](self, ...)
end)
addon.event_frame:RegisterEvent("ADDON_LOADED")