View Single Post
01-21-20, 01:30 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Thanks to you guys and your suggestions, plus looking at ElkFaction's code, I got it almost working. Setting a waypoint in TomTom isn't working, but the display is correct and the mouse works over the menu.

What I had to do:
  • Run an iterator over the npcs table twice for some reason and then sort the list
  • Enable mouse in the OnEnter handler
  • Comment out the OnLeave code
Lua Code:
  1. --[[
  2.     -- file and project errata --
  3.     Project Author:     @project-author@
  4.     Project Date:       @project-date-iso@
  5.     Project Version:    @project-version@
  6.     Project Revision:   @project-revision@
  7.  
  8.     File Author:        @file-author@
  9.     File Date:          @file-date-iso@
  10.     File Revision:      @file-revision@
  11. ]]--
  12.  
  13. local ADDON, _ = ...
  14. local ADDON_TITLE = GetAddOnMetadata(ADDON, "Title")
  15. local TILLERS
  16. local LOCALE = GetLocale()
  17. local event_frame = CreateFrame("frame")
  18. local TomTom = TomTom
  19.  
  20. local L = setmetatable({}, {__index = function(t, k)
  21.     local v = tostring(k)
  22.     rawset(t, k, v)
  23.     return v
  24. end})
  25.  
  26. -- translate the tooltips
  27. --[[
  28. -- don't actually need enUS as that's the default. using this as a reminder
  29. if LOCALE == "enUS" then
  30. L["Click a Tiller's line to set a waypoint in TomTom"] = true
  31. L["Click the plugin to sort by Tiller name or item name"] = true
  32. L["Hold the <Control> key and click to hide Best Friend Tillers"] = true
  33. L["Hold the <Shift> key and click to hide already fed Tillers"] = true
  34. return end
  35. ]]--
  36.  
  37. if LOCALE == "deDE" then
  38. --@localization(locale="deDE", format="lua_additive_table")@
  39. return end
  40.  
  41. if LOCALE == "esES" or LOCALE == "esMX" then
  42. --@localization(locale="esES", format="lua_additive_table")@
  43. return end
  44.  
  45. if LOCALE == "frFR" then
  46. --@localization(locale="frFR", format="lua_additive_table")@
  47. return end
  48.  
  49. if LOCALE == "itIT" then
  50. --@localization(locale="itIT", format="lua_additive_table")@
  51. return end
  52.  
  53. if LOCALE == "koKR" then
  54. --@localization(locale="koKR", format="lua_additive_table")@
  55. return end
  56.  
  57. if LOCALE == "ptBR" then
  58. --@localization(locale="ptBR", format="lua_additive_table")@
  59. return end
  60.  
  61. if LOCALE == "ruRU" then
  62. --@localization(locale="ruRU", format="lua_additive_table")@
  63. return end
  64.  
  65. if LOCALE == "zhCN" then
  66. --@localization(locale="zhCN", format="lua_additive_table")@
  67. return end
  68.  
  69. if LOCALE == "zhTW" then
  70. --@localization(locale="zhTW", format="lua_additive_table")@
  71. return end
  72.  
  73. local qtip = LibStub("LibQTip-1.0")
  74.  
  75. local npcs = {
  76.     { factionID = 1273, itemID = 74643, questID = 30439, x = 52.6, y = 49.2 }, -- Jogu the Drunk
  77.     { factionID = 1275, itemID = 74651, questID = 30386, x = 31.6, y = 58.0 }, -- Ella
  78.     { factionID = 1276, itemID = 74649, questID = 30396, x = 31.0, y = 53.0 }, -- Old Hillpaw
  79.     { factionID = 1277, itemID = 74647, questID = 30402, x = 34.4, y = 46.8 }, -- Chee Chee
  80.     { factionID = 1278, itemID = 74645, questID = 30408, x = 29.6, y = 30.6 }, -- Sho
  81.     { factionID = 1279, itemID = 74642, questID = 30414, x = 44.6, y = 34.0 }, -- Haohan Mudclaw
  82.     { factionID = 1280, itemID = 74652, questID = 30433, x = 45.0, y = 33.8 }, -- Tina Mudclaw
  83.     { factionID = 1281, itemID = 74644, questID = 30390, x = 53.2, y = 51.6 }, -- Gina Mudclaw
  84.     { factionID = 1282, itemID = 74655, questID = 30427, x = 41.6, y = 30.0 }, -- Fish Fellreed
  85.     { factionID = 1283, itemID = 74654, questID = 30421, x = 48.2, y = 33.8 }, -- Farmer Fung
  86. }
  87.  
  88. local tooltip = "NAME"
  89. local sortByName = function(a, b)
  90.     return a.name < b.name
  91. end
  92. local sortByItem = function(a, b)
  93.     return a.item < b.item
  94. end
  95.  
  96. local function UseTomTom(frame, npc)
  97.     local x, y = npc.x, npc.y
  98.     local opts = {title = GetFactionInfoByID(npc.factionID), persistant = true, minimap = true, world = true, crazy = true}
  99.     TomTom:AddWaypoint(376, x, y, opts) -- 376 is the uiMapID for Valley of the Four Winds
  100. end
  101.  
  102. local function CreateBroker()
  103.     LibStub("LibDataBroker-1.1"):NewDataObject(ADDON, {
  104.         type = "data source",
  105.         text = ADDON_TITLE,
  106.         icon = [[Interface/ICONS/Achievement_Profession_ChefHat]],
  107.         OnClick = function(self)
  108.             if IsShiftKeyDown() then
  109.                 FeedTillersDB.hideComplete = not FeedTillersDB.hideComplete
  110.             elseif IsControlKeyDown() then
  111.                 FeedTillersDB.hideBestFriends = not FeedTillersDB.hideBestFriends
  112.             else
  113.                 FeedTillersDB.currentSort = FeedTillersDB.currentSort == "NAME" and "ITEM" or "NAME"
  114.                 sort(npcs, FeedTillersDB.currentSort == "NAME" and sortByName or sortByItem)
  115.             end
  116.  
  117.             self:GetScript("OnLeave")(self)
  118.             self:GetScript("OnEnter")(self)
  119.         end,
  120.         OnEnter = function(self)
  121.             if not TILLERS then
  122.                 TILLERS = GetFactionInfoByID(1272)
  123.                 for i = 1, #npcs do
  124.                     local npc = npcs[i]
  125.                     npc.name = GetFactionInfoByID(npc.factionID)
  126.                 end
  127.                 sort(npcs, sortByName)
  128.             end
  129.  
  130.             tooltip = qtip:Acquire("FeedTillersTT", 3, "LEFT", "LEFT", "RIGHT")
  131.             tooltip:AddHeader(TILLERS, ITEMS, COMPLETE)
  132.             local line
  133.             local hideComplete = FeedTillersDB.hideComplete
  134.             local hideBestFriends = FeedTillersDB.hideBestFriends
  135.  
  136.             for i = 1, #npcs do
  137.                 local npc = npcs[i]
  138.                 npc.name, npc.noop, npc.standingID = GetFactionInfoByID(npc.factionID) -- npc.noop is not used by FeedTillers
  139.                 hideBestFriends = hideBestFriends == true and npc.standingID == MAX_REPUTATION_REACTION
  140.  
  141.                 -- cache the item so we don't have to keep looking it up
  142.                 if not FeedTillersDB[npc.name] then
  143.                     print("|cFFFF0000" .. L["FeedTillers error:"] .. "|r " .. L["the food item is being cached. Please wait and try viewing the display a few times until it is updated."])
  144.                     FeedTillersDB[npc.name] = GetItemInfo(npc.itemID)
  145.                 end
  146.  
  147.                 if not hideBestFriends then
  148.                     if not IsQuestFlaggedCompleted(npc.questID) then
  149.                         -- note "line" is no longer local to this scope!
  150.                         local count = GetItemCount(npc.itemID)
  151.                         line = tooltip:AddLine(npc.name, FeedTillersDB[npc.name], format("%d/%d", count, 5))
  152.                         if TomTom then
  153.                             tooltip:SetLineScript(line, "OnMouseUp", UseTomTom, npc)
  154.                             tooltip:SetHighlightTexture(1, 1, 1, 0.7)
  155.                         end
  156.  
  157.                         if count < 5 then
  158.                             tooltip:SetLineColor(line, 1, 0.1, 0.1, 0.3)
  159.                         end
  160.                     elseif not hideComplete then
  161.                         line = tooltip:AddLine(npc.name, FeedTillersDB[npc.name], YES)
  162.                         tooltip:SetLineColor(line, 0.1, 1, 0.1, 0.3)
  163.                     end
  164.                 end
  165.             end
  166.  
  167.             if not line then
  168.                 hideComplete = nil
  169.                 hideBestFriends = nil
  170.                 self:GetScript("OnLeave")(self)
  171.                 return self:GetScript("OnEnter")(self)
  172.             end
  173.  
  174.             line = tooltip:AddLine(" ") -- blank line
  175.  
  176.             line = tooltip:AddLine(" ")
  177.             tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Click the plugin to sort by Tiller name or item name"], "LEFT", 3)
  178.  
  179.             line = tooltip:AddLine(" ")
  180.             tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Shift> key and click to hide already fed Tillers"], "LEFT", 3)
  181.  
  182.             line = tooltip:AddLine(" ")
  183.             tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Control> key and click to hide Best Friend Tillers"], "LEFT", 3)
  184.  
  185.             if TomTom then
  186.                 line = tooltip:AddLine(" ")
  187.                 tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Click a Tiller's line to set a waypoint in TomTom"], "LEFT", 3)
  188.             end
  189.  
  190.             tooltip:SmartAnchorTo(self)
  191.             tooltip:SetAutoHideDelay(0.1, self)
  192.             tooltip:EnableMouse(true)
  193.             tooltip:Show()
  194.         end,
  195.         OnLeave = function(self)
  196.             --[[
  197.             if qtip:IsAcquired("FeedTillersTT") then
  198.                 qtip:Release(tooltip)
  199.             end
  200.             tooltip = nil
  201.             ]]--
  202.         end
  203.     })
  204. end
  205.  
  206. event_frame:RegisterEvent("PLAYER_LOGIN")
  207. event_frame:SetScript("OnEvent", function(self, ...)
  208.     if ... == "PLAYER_LOGIN" then
  209.         FeedTillersDB = FeedTillersDB or {}
  210.         FeedTillersDB.hideComplete = FeedTillersDB.hideComplete or false
  211.         FeedTillersDB.currentSort = FeedTillersDB.currentSort or "NAME"
  212.         FeedTillersDB.hideBestFriends = FeedTillersDB.hideBestFriends or false
  213.  
  214.         -- clean up old saved variables
  215.         FeedTillers_hideComplete = nil
  216.         FeedTillers_currentSort = nil
  217.  
  218.         CreateBroker()
  219.     end
  220. end)
Attached Thumbnails
Click image for larger version

Name:	FeedTillers WIP1.jpg
Views:	101
Size:	52.8 KB
ID:	9405  
  Reply With Quote