View Single Post
12-17-12, 01:29 AM   #10
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Saved variables are in, which save the column sort by name or item, and holding <shift> + click to hide completed Tillers. Also added is localization for the tooltip help. But it looks terrible, and I have tried a few variants of formatting. Any suggestions on how to adjust the placement of the hints, starting line 97, is welcome.

On a side note, there are now four strings that need localizing, up from two. Still a tiny addon.
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. -- GLOBALS: sort, GetAddOnMetadata, GetFactionInfoByID, GetItemInfo, IsQuestFlaggedCompleted, GetLocale
  14. -- GLOBALS: COMPLETE, ITEMS, NO, YES, GameTooltip
  15. -- GLOBALS: LibStub
  16. -- GLOBALS: FeedTillers_hideComplete, FeedTillers_currentSort
  17.  
  18. local ADDON, L = ...
  19. local ADDON_TITLE = GetAddOnMetadata(ADDON, "Title")
  20. local TILLERS
  21. local LOCALE = GetLocale()
  22. local event_frame = CreateFrame("frame")
  23.  
  24. -- translate the tooltips
  25. if LOCALE == "esES" then
  26. --@localization(locale="esES", format="lua_additive_table", namespace="Normal")@
  27. elseif LOCALE == "esMX" then
  28. --@localization(locale="esMX", format="lua_additive_table", namespace="Normal")@
  29. elseif LOCALE == "itIT" then
  30. --@localization(locale="itIT", format="lua_additive_table", namespace="Normal")@
  31. elseif LOCALE == "ptBR" then
  32. --@localization(locale="ptBR", format="lua_additive_table", namespace="Normal")@
  33. elseif LOCALE == "frFR" then
  34. --@localization(locale="frFR", format="lua_additive_table", namespace="Normal")@
  35. elseif LOCALE == "deDE" then
  36. --@localization(locale="deDE", format="lua_additive_table", namespace="Normal")@
  37. elseif LOCALE == "ruRU" then
  38. --@localization(locale="ruRU", format="lua_additive_table", namespace="Normal")@
  39. elseif LOCALE == "zhCN" then
  40. --@localization(locale="zhCN", format="lua_additive_table", namespace="Normal")@
  41. elseif LOCALE == "zhTW" then
  42. --@localization(locale="zhTW", format="lua_additive_table", namespace="Normal")@
  43. else
  44. L["CLICK_SORT"] = "Click the plugin to sort by Tiller name or item name"
  45. L["SHIFT_DOWN"] = "Hold the <Shift> key and click to hide already fed Tillers"
  46. end
  47.  
  48. local qtip = LibStub("LibQTip-1.0")
  49.  
  50. local npcs = {
  51.     { factionID = 1273, itemID = 74643, questID = 30439 }, -- Jogu the Drunk
  52.     { factionID = 1275, itemID = 74651, questID = 30386 }, -- Ella
  53.     { factionID = 1276, itemID = 74649, questID = 30396 }, -- Old Hillpaw
  54.     { factionID = 1277, itemID = 74647, questID = 30402 }, -- Chee Chee
  55.     { factionID = 1278, itemID = 74645, questID = 30408 }, -- Sho
  56.     { factionID = 1279, itemID = 74642, questID = 30414 }, -- Haohan Mudclaw
  57.     { factionID = 1280, itemID = 74652, questID = 30433 }, -- Tina Mudclaw
  58.     { factionID = 1281, itemID = 74644, questID = 30390 }, -- Gina Mudclaw
  59.     { factionID = 1282, itemID = 74655, questID = 30427 }, -- Fish Fellreed
  60.     { factionID = 1283, itemID = 74654, questID = 30421 }, -- Farmer Fung
  61. }
  62.  
  63. local tooltip = "NAME"
  64. local sortByName = function(a, b)
  65.     return a.name < b.name
  66. end
  67. local sortByItem = function(a, b)
  68.     return a.item < b.item
  69. end
  70.  
  71. local function CreateBroker()
  72.     LibStub("LibDataBroker-1.1"):NewDataObject(ADDON, {
  73.         type = "data source",
  74.         text = ADDON_TITLE,
  75.         icon = [[Interface/ICONS/Achievement_Profession_ChefHat]],
  76.         OnClick = function(self)
  77.             if IsShiftKeyDown() then
  78.                 FeedTillers_hideComplete = not FeedTillers_hideComplete
  79.             else
  80.                 FeedTillers_currentSort = FeedTillers_currentSort == "NAME" and "ITEM" or "NAME"
  81.                 sort(npcs, FeedTillers_currentSort == "NAME" and sortByName or sortByItem)
  82.             end
  83.             self:GetScript("OnLeave")(self)
  84.             self:GetScript("OnEnter")(self)
  85.         end,
  86.         OnEnter = function(self)
  87.             if not TILLERS then
  88.                 TILLERS = GetFactionInfoByID(1272)
  89.                 for i = 1, #npcs do
  90.                     local npc = npcs[i]
  91.                     npc.name = GetFactionInfoByID(npc.factionID)
  92.                 end
  93.                 sort(npcs, sortByName)
  94.             end
  95.            
  96.             tooltip = qtip:Acquire("FeedTillersTT", 3, "LEFT", "LEFT", "RIGHT")
  97.             tooltip:AddLine(nil, nil, L.CLICK_SORT)
  98.             tooltip:AddLine(nil, nil, L.SHIFT_DOWN)
  99.             tooltip:AddLine("", "", "")
  100.             tooltip:AddHeader(TILLERS, ITEMS, COMPLETE)
  101.             for i = 1, #npcs do
  102.                 local npc = npcs[i]
  103.                 if not npc.item then
  104.                     npc.item = GetItemInfo(npc.itemID)
  105.                 end
  106.                 if not IsQuestFlaggedCompleted(npc.questID) then
  107.                     local line = tooltip:AddLine(npc.name, npc.item, NO)
  108.                     tooltip:SetLineColor(line, 1, 0.1, 0.1, 0.3)
  109.                 elseif not FeedTillers_hideComplete then
  110.                     local line = tooltip:AddLine(npc.name, npc.item, YES)
  111.                     tooltip:SetLineColor(line, 0.1, 1, 0.1, 0.3)
  112.                 end
  113.             end
  114.             tooltip:SmartAnchorTo(self)
  115.             tooltip:Show()
  116.         end,
  117.         OnLeave = function(self)
  118.             if qtip:IsAcquired("FeedTillersTT") then
  119.                 qtip:Release(tooltip)
  120.             end
  121.             tooltip = nil
  122.         end
  123.     })
  124. end
  125.  
  126. event_frame:RegisterEvent("ADDON_LOADED")
  127. event_frame:SetScript("OnEvent", function(self, event, ...)
  128.     if event == "ADDON_LOADED" and ... == ADDON then   
  129.         if not FeedTillers_hideComplete then
  130.             FeedTillers_hideComplete = false
  131.         end
  132.         if not FeedTillers_currentSort then
  133.             FeedTillers_currentSort = "NAME"
  134.         end
  135.     end
  136.     CreateBroker()
  137.     self:UnregisterEvent("ADDON_LOADED")
  138. end)
Attached Thumbnails
Click image for larger version

Name:	FeedTillers3.jpg
Views:	718
Size:	66.1 KB
ID:	7452  
  Reply With Quote