--[[
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 = ...
local lqt = LibStub("LibQTip-1.0")
local TOMTOM = _G.TomTom
local player_name, player_realm = UnitFullName("player")
local full_name = player_name .. " - " .. 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["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)
return a.item < b.item
end
-- handle current_line scripts ------------------------------------------------
local function line_OnEnter(frame)
frame:SetHighlightTexture(1, 1, 1, 0.2)
end
local function line_OnLeave(frame)
frame:SetHighlightTexture(1, 1, 1, 0)
end
local function line_OnMouseUp(self, npc)
if TOMTOM then
local x, y = strsplit(", ", npc.coords)
TOMTOM:AddWaypoint(5805, 0, x, y)
end
end
-- DataBroker -----------------------------------------------------------------
local function dataObject_OnEnter(self)
-- give it something so it doesn't nil on start
if not TILLERS then
TILLERS = GetFactionInfoByID(1272) -- cache name of the faction group for localization
for i = 1, #npcs do
local npc = npcs[i]
npc.name = GetFactionInfoByID(npc.factionID)
end
sort(npcs, SortByName)
end
-- populate tooltip
local tooltip = lqt:Acquire("FeedTillersTT", 3, "LEFT", "LEFT", "RIGHT")
self.tooltip = tooltip
tooltip:AddHeader(TILLERS, ITEMS, COMPLETE) -- "ITEMS" and "COMPLETE" are global strings
local current_line
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.item = npc.item or GetItemInfo(npc.itemID)
local isNotBestFriend = select(9, GetFriendshipReputation(npc.factionID)) -- number or nil if at max rank
hideExalted = hideExalted and isNotBestFriend == nil -- for my sanity
if not IsQuestFlaggedCompleted(npc.questID) and not hideExalted then
local count = GetItemCount(npc.itemID)
current_line = tooltip:AddLine(npc.name, npc.item, format("%d/%d", count, 5))
if count < 5 then
tooltip:SetLineColor(current_line, 1, 0.1, 0.1, 0.3)
end
elseif not hideComplete and not hideExalted then
current_line = tooltip:AddLine(npc.name, npc.item, YES)
tooltip:SetLineColor(current_line, 0.1, 1, 0.1, 0.3)
end
-- current_line scripts
tooltip:SetLineScript(current_line, "OnEnter", line_OnEnter, npc)
tooltip:SetLineScript(current_line, "OnLeave", line_OnLeave, npc)
tooltip:SetLineScript(current_line, "OnMouseUp", line_OnMouseUp, npc)
end
if not current_line then
hideComplete, hideExalted = nil, nil
self:GetScript("OnLeave")(self)
return self:GetScript("OnEnter")(self)
end
current_line = tooltip:AddLine(" ")
current_line = tooltip:AddLine(" ")
tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Click the plugin to sort by Tiller name or item name"], "LEFT", 3)
current_line = tooltip:AddLine(" ")
tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Shift> key and click to hide already fed Tillers"], "LEFT", 3)
current_line = tooltip:AddLine(" ")
tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Control> key and click to hide Best Friend Tillers"], "LEFT", 3)
current_line = tooltip:AddLine(" ")
tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Click a line to set a TomTom waypoint, if installed"], "LEFT", 3)
-- smart anchoring of tooltip to DataBroker frame
tooltip:SmartAnchorTo(self)
tooltip:SetAutoHideDelay(0.25, self)
-- show the tooltip
tooltip:Show()
end
local function dataObject_OnLeave(self)
if lqt:IsAcquired("FeedTillersTT") then
lqt:Release(self.tooltip)
end
self.tooltip = nil
end
local function dataObject_OnClick(self)
if IsShiftKeyDown() then
FeedTillersDB[full_name].Hide_Complete = not FeedTillersDB[full_name].Hide_Complete
elseif 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
-- refresh display
self:GetScript("OnLeave")(self)
self:GetScript("OnEnter")(self)
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
-- handle events --------------------------------------------------------------
local event_frame = CreateFrame("frame")
event_frame:RegisterEvent("ADDON_LOADED")
event_frame:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" and ... == addon_name then
-- load or initialize saved variables
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"
-- groovy data display
CreateBroker()
end
self:UnregisterEvent("ADDON_LOADED")
end)