Thread Tools Display Modes
Prev Previous Post   Next Post Next
06-20-17, 06:20 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
LibQTip-1.0 help

I have rewritten FeedTillers from scratch, as it badly needed it for a few reasons. Sure, MoP is way behind us, but some people still use this addon.

Two features I am trying to add are:
  1. The ability to hide any of the Tillers with whom you are Best Friends on saved variable toggle
  2. Clicking a line in the display to send TomTom a waypoint arrow to the Tiller's farm if he/she isn't at Halfhill
I mostly have the code working, but some things elude me. I haven't figured out LibQTip-1.0's API well enough to allow moving the mouse down the frame from whatever LDB display the user has. Instead, when I try to move the mouse down, the whole tooltip display disappears. I'd also like to highlight the line like a faded bar.

Speaking of LibDataBroker-1.1, I have had bug reports that ElvUI and TukUI do not support FeedTillers, but I have zero clue why that might be the case.

Next, I can't be sure I am using TomTom's API correctly, as wading through its code hunting for API arguments is challenging.

Then I have noticed that on first load the tooltip doesn't populate the food items correctly, but I have a guess; I just haven't tested it, but if someone notices where I have erred, I will be appreciative. My guess is move line 116 to line 102.

Finally, assuming that the user is Best Friends with all the Tillers, I would like the help instructions at the bottom to remain, but those go away when toggling Hide_Exalted.

Is there anything else I have missed that fresh eyes can spot?
Lua Code:
  1. --[[
  2.     file errata
  3.     File Author:    @file-author@
  4.     File Revision:  @file-revision@
  5.     FIle Date:      @file-date-iso@
  6. ]]--
  7.  
  8. -- for Mikk's FindGlobals app -------------------------------------------------
  9. -- GLOBALS: FeedTillersDB
  10.  
  11. -- main definitions -----------------------------------------------------------
  12. local addon_name = ...
  13. local lqt = LibStub("LibQTip-1.0")
  14. local TOMTOM = _G.TomTom
  15. local player_name, player_realm = UnitFullName("player")
  16. local full_name = player_name .. " - " .. player_realm
  17.  
  18. -- localize addon -------------------------------------------------------------
  19. -- see [url]https://phanx.net/addons/tutorials/localize[/url]
  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. local LOCALE = GetLocale()
  27.  
  28. if LOCALE == "enUS" then
  29. L["Click a line to set a TomTom waypoint, if installed"] = "Click a line to set a TomTom waypoint, if installed"
  30. L["Click the plugin to sort by Tiller name or item name"] = "Click the plugin to sort by Tiller name or item name"
  31. L["Hold the <Control> key and click to hide Best Friend Tillers"] = "Hold the <Control> key and click to hide Best Friend Tillers"
  32. L["Hold the <Shift> key and click to hide already fed Tillers"] = "Hold the <Shift> key and click to hide already fed Tillers"
  33. elseif LOCALE == "esES" then
  34. --@localization(locale="esES", format="lua_additive_table")@
  35. elseif LOCALE == "esMX" then
  36. --@localization(locale="esMX", format="lua_additive_table")@
  37. elseif LOCALE == "itIT" then
  38. --@localization(locale="itIT", format="lua_additive_table")@
  39. elseif LOCALE == "ptBR" then
  40. --@localization(locale="ptBR", format="lua_additive_table")@
  41. elseif LOCALE == "frFR" then
  42. --@localization(locale="frFR", format="lua_additive_table")@
  43. elseif LOCALE == "deDE" then
  44. --@localization(locale="deDE", format="lua_additive_table")@
  45. elseif LOCALE == "ruRU" then
  46. --@localization(locale="ruRU", format="lua_additive_table")@
  47. elseif LOCALE == "zhCN" then
  48. --@localization(locale="zhCN", format="lua_additive_table")@
  49. elseif LOCALE == "zhTW" then
  50. --@localization(locale="zhTW", format="lua_additive_table")@
  51. elseif LOCALE == "koKR" then
  52. --@localization(locale="koKR", format="lua_additive_table")@
  53. end
  54.  
  55. -- variables ------------------------------------------------------------------
  56. local TILLERS
  57. local npcs = {
  58.     { factionID = 1273, itemID = 74643, questID = 30439, coords = "53.6, 52.6" }, -- Jogu the Drunk
  59.     { factionID = 1275, itemID = 74651, questID = 30386, coords = "31.5, 58.1" }, -- Ella
  60.     { factionID = 1276, itemID = 74649, questID = 30396, coords = "30.9, 53.1" }, -- Old Hillpaw
  61.     { factionID = 1277, itemID = 74647, questID = 30402, coords = "34.4, 46.8" }, -- Chee Chee
  62.     { factionID = 1278, itemID = 74645, questID = 30408, coords = "29.5, 30.6" }, -- Sho
  63.     { factionID = 1279, itemID = 74642, questID = 30414, coords = "44.6, 34.1" }, -- Haohan Mudclaw
  64.     { factionID = 1280, itemID = 74652, questID = 30433, coords = "45.1, 33.8" }, -- Tina Mudclaw
  65.     { factionID = 1281, itemID = 74644, questID = 30390, coords = "53.2, 51.8" }, -- Gina Mudclaw
  66.     { factionID = 1282, itemID = 74655, questID = 30427, coords = "41.7, 30.0" }, -- Fish Fellreed
  67.     { factionID = 1283, itemID = 74654, questID = 30421, coords = "48.3, 33.8" }, -- Farmer Fung
  68. }
  69.  
  70. -- sorting functions ----------------------------------------------------------
  71. local function SortByName(a, b)
  72.     return a.name < b.name
  73. end
  74. local function SortByItem(a, b)
  75.     return a.item < b.item
  76. end
  77.  
  78. -- handle current_line scripts ------------------------------------------------
  79. local function line_OnEnter(frame)
  80.     frame:SetHighlightTexture(1, 1, 1, 0.2)
  81. end
  82.  
  83. local function line_OnLeave(frame)
  84.     frame:SetHighlightTexture(1, 1, 1, 0)
  85. end
  86.  
  87. local function line_OnMouseUp(self, npc)
  88.     if TOMTOM then
  89.         local x, y = strsplit(", ", npc.coords)
  90.         TOMTOM:AddWaypoint(5805, 0, x, y)
  91.     end
  92. end
  93.  
  94. -- DataBroker -----------------------------------------------------------------
  95. local function dataObject_OnEnter(self)
  96.     -- give it something so it doesn't nil on start
  97.     if not TILLERS then
  98.         TILLERS = GetFactionInfoByID(1272) -- cache name of the faction group for localization
  99.         for i = 1, #npcs do
  100.             local npc = npcs[i]
  101.             npc.name = GetFactionInfoByID(npc.factionID)
  102.         end
  103.         sort(npcs, SortByName)
  104.     end
  105.  
  106.     -- populate tooltip
  107.     local tooltip = lqt:Acquire("FeedTillersTT", 3, "LEFT", "LEFT", "RIGHT")
  108.     self.tooltip = tooltip
  109.     tooltip:AddHeader(TILLERS, ITEMS, COMPLETE) -- "ITEMS" and "COMPLETE" are global strings
  110.     local current_line
  111.     local hideComplete = FeedTillersDB[full_name].Hide_Complete -- for brevity
  112.     local hideExalted = FeedTillersDB[full_name].Hide_Exalted -- for brevity
  113.  
  114.     for i = 1, #npcs do
  115.         local npc = npcs[i]
  116.         npc.item = npc.item or GetItemInfo(npc.itemID)
  117.         local isNotBestFriend = select(9, GetFriendshipReputation(npc.factionID)) -- number or nil if at max rank
  118.         hideExalted = hideExalted and isNotBestFriend == nil -- for my sanity
  119.  
  120.         if not IsQuestFlaggedCompleted(npc.questID) and not hideExalted then
  121.             local count = GetItemCount(npc.itemID)
  122.             current_line = tooltip:AddLine(npc.name, npc.item, format("%d/%d", count, 5))
  123.             if count < 5 then
  124.                 tooltip:SetLineColor(current_line, 1, 0.1, 0.1, 0.3)
  125.             end
  126.         elseif not hideComplete and not hideExalted then
  127.             current_line = tooltip:AddLine(npc.name, npc.item, YES)
  128.             tooltip:SetLineColor(current_line, 0.1, 1, 0.1, 0.3)
  129.         end
  130.  
  131.         -- current_line scripts
  132.         tooltip:SetLineScript(current_line, "OnEnter", line_OnEnter, npc)
  133.         tooltip:SetLineScript(current_line, "OnLeave", line_OnLeave, npc)
  134.         tooltip:SetLineScript(current_line, "OnMouseUp", line_OnMouseUp, npc)
  135.     end
  136.  
  137.     if not current_line then
  138.         hideComplete, hideExalted = nil, nil
  139.         self:GetScript("OnLeave")(self)
  140.         return self:GetScript("OnEnter")(self)
  141.     end
  142.  
  143.     current_line = tooltip:AddLine(" ")
  144.     current_line = tooltip:AddLine(" ")
  145.     tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Click the plugin to sort by Tiller name or item name"], "LEFT", 3)
  146.     current_line = tooltip:AddLine(" ")
  147.     tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Shift> key and click to hide already fed Tillers"], "LEFT", 3)
  148.     current_line = tooltip:AddLine(" ")
  149.     tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Control> key and click to hide Best Friend Tillers"], "LEFT", 3)
  150.     current_line = tooltip:AddLine(" ")
  151.     tooltip:SetCell(current_line, 1, NORMAL_FONT_COLOR_CODE .. L["Click a line to set a TomTom waypoint, if installed"], "LEFT", 3)
  152.  
  153.     -- smart anchoring of tooltip to DataBroker frame
  154.     tooltip:SmartAnchorTo(self)
  155.     tooltip:SetAutoHideDelay(0.25, self)
  156.  
  157.     -- show the tooltip
  158.     tooltip:Show()
  159. end
  160.  
  161. local function dataObject_OnLeave(self)
  162.     if lqt:IsAcquired("FeedTillersTT") then
  163.         lqt:Release(self.tooltip)
  164.     end
  165.     self.tooltip = nil
  166. end
  167.  
  168. local function dataObject_OnClick(self)
  169.     if IsShiftKeyDown() then
  170.         FeedTillersDB[full_name].Hide_Complete = not FeedTillersDB[full_name].Hide_Complete
  171.     elseif IsControlKeyDown() then
  172.         FeedTillersDB[full_name].Hide_Exalted = not FeedTillersDB[full_name].Hide_Exalted
  173.     else
  174.         FeedTillersDB[full_name].Current_Sort = FeedTillersDB[full_name].Current_Sort == "NAME" and "ITEM" or "NAME"
  175.         sort(npcs, FeedTillersDB[full_name].Current_Sort == "NAME" and SortByName or SortByItem)
  176.     end
  177.  
  178.     -- refresh display
  179.     self:GetScript("OnLeave")(self)
  180.     self:GetScript("OnEnter")(self)
  181. end
  182.  
  183. local function CreateBroker()
  184.     LibStub("LibDataBroker-1.1"):NewDataObject(addon_name, {
  185.         type = "data source",
  186.         text = "Feed Tillers",
  187.         icon = [[Interface/ICONS/Achievement_Profession_ChefHat]],
  188.         OnClick = dataObject_OnClick,
  189.         OnEnter = dataObject_OnEnter,
  190.         OnLeave = dataObject_OnLeave
  191.     })
  192. end
  193.  
  194. -- handle events --------------------------------------------------------------
  195. local event_frame = CreateFrame("frame")
  196. event_frame:RegisterEvent("ADDON_LOADED")
  197. event_frame:SetScript("OnEvent", function(self, event, ...)
  198.     if event == "ADDON_LOADED" and ... == addon_name then
  199.         -- load or initialize saved variables
  200.         FeedTillersDB = FeedTillersDB or {}
  201.         FeedTillersDB[full_name] = FeedTillersDB[full_name] or {}
  202.         FeedTillersDB[full_name].Hide_Complete = FeedTillersDB[full_name].Hide_Complete or false
  203.         FeedTillersDB[full_name].Hide_Exalted = FeedTillersDB[full_name].Hide_Exalted or false     
  204.         FeedTillersDB[full_name].Current_Sort = FeedTillersDB[full_name].Current_Sort or "NAME"
  205.  
  206.         -- groovy data display
  207.         CreateBroker()
  208.     end
  209.     self:UnregisterEvent("ADDON_LOADED")
  210. end)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » LibQTip-1.0 help


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off