Advertisement
Guest User

TooltipHooksWithLoot.lua

a guest
Jul 16th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.57 KB | None | 0 0
  1. local function AddTooltipLine(control, tooltipLine)
  2.     control:AddVerticalPadding(20)
  3.     control:AddLine(tooltipLine, "ZoFontGame", 1, 1, 1, CENTER, MODIFY_TEXT_TYPE_NONE, LEFT, false)
  4. end
  5.  
  6. local function OutputErrorForMissingItemId(itemId)
  7.     d("Unknown crafting item ID "..itemId.." - please submit a bug for CraftingMaterialLevelDisplay")
  8. end
  9.  
  10. local function AddTooltipLineForProvisioningMaterial(control, itemId)
  11.     if ProvisioningMaterials[itemId] then
  12.         local text = ProvisioningMaterials[itemId].tooltip
  13.         if CraftingMaterialLevelDisplay.savedVariables.provisioningFlavor == false then
  14.             if text == "For extra flavor in |c5B90F6blue|r and |cAA00FFpurple|r recipes" then
  15.                 text = "Tier 2 Ingredient"
  16.             elseif text == "For extra flavor in |cAA00FFpurple|r recipes" then
  17.                 text = "Tier 3 Ingredient"
  18.             end
  19.         end
  20.         AddTooltipLine(control, text)
  21.     else
  22.         OutputErrorForMissingItemId(itemId)
  23.     end
  24. end
  25.  
  26. local function AddTooltipLineForAlchemyMaterial(control, itemId)
  27.     if AlchemyMaterials[itemId] then
  28.         -- Ignore the Solvent items until I have information worth displaying
  29.         if AlchemyMaterials[itemId].solvent ~= nil then return end
  30.  
  31.         AddTooltipLine(control, AlchemyMaterials[itemId].tooltip)
  32.     else
  33.         OutputErrorForMissingItemId(itemId)
  34.     end
  35. end
  36.  
  37. local function AddTooltipLineForEnchantingMaterial(control, itemId)
  38.     if EnchantingMaterials[itemId] then
  39.         -- Ignore the Aspect runes until I have information worth displaying
  40.         if EnchantingMaterials[itemId].aspect ~= nil then return end
  41.  
  42.         AddTooltipLine(control, EnchantingMaterials[itemId].tooltip)
  43.     else
  44.         OutputErrorForMissingItemId(itemId)
  45.     end
  46. end
  47.  
  48. local function GetItemIdFromBagAndSlot(bagId, slotIndex)
  49.     local itemLink = GetItemLink(bagId, slotIndex)
  50.     local itemId = select(4, ZO_LinkHandler_ParseLink(itemLink))
  51.     return tonumber(itemId)
  52. end
  53.  
  54. local function GetTradeSkillTypeFromItemId(itemId)
  55.     -- in 1.3.0 it will be possible to get all info from itemLink,
  56.     -- but until then, look for the item in known materials
  57.     if not itemId then
  58.         return nil
  59.     elseif AlchemyMaterials[itemId] then
  60.         return CRAFTING_TYPE_ALCHEMY
  61.     elseif EnchantingMaterials[itemId] then
  62.         return CRAFTING_TYPE_ENCHANTING
  63.     elseif ProvisioningMaterials[itemId] then
  64.         return CRAFTING_TYPE_PROVISIONING
  65.     else
  66.         return nil
  67.     end
  68. end
  69.  
  70. local function AddTooltipByType(control, tradeSkillType, itemType, itemId)
  71.     if tradeSkillType == CRAFTING_TYPE_PROVISIONING then
  72.         if CraftingMaterialLevelDisplay.savedVariables.provisioning then
  73.             AddTooltipLineForProvisioningMaterial(control, itemId)
  74.         end
  75.  
  76.     elseif tradeSkillType == CRAFTING_TYPE_ALCHEMY then
  77.         if CraftingMaterialLevelDisplay.savedVariables.alchemy then
  78.             AddTooltipLineForAlchemyMaterial(control, itemId)
  79.         end
  80.  
  81.     elseif tradeSkillType == CRAFTING_TYPE_ENCHANTING
  82.             and itemType ~= ITEMTYPE_GLYPH_ARMOR
  83.             and itemType ~= ITEMTYPE_GLYPH_JEWELRY
  84.             and itemType ~= ITEMTYPE_GLYPH_WEAPON then
  85.         -- Does not need to account for the created Glyphs, just the runes
  86.         if CraftingMaterialLevelDisplay.savedVariables.enchanting then
  87.             AddTooltipLineForEnchantingMaterial(control, itemId)
  88.         end
  89.     end
  90. end
  91.  
  92. function CraftingMaterialLevelDisplay.HookTooltips()
  93.     local InvokeSetBagItemTooltip = ItemTooltip.SetBagItem
  94.     ItemTooltip.SetBagItem = function(control, bagId, slotIndex, ...)
  95.         local tradeSkillType, itemType = GetItemCraftingInfo(bagId, slotIndex)
  96.         local itemId = GetItemIdFromBagAndSlot(bagId, slotIndex)
  97.         InvokeSetBagItemTooltip(control, bagId, slotIndex, ...)
  98.         AddTooltipByType(control, tradeSkillType, itemType, itemId)
  99.     end
  100.  
  101.     -- hooking InformationTooltip.SetLootItem doesn't work (as of API 100007),
  102.     -- but luckily tinkering with its metatable does ;)
  103.     local InformationTooltip_index = getmetatable(InformationTooltip).__index
  104.     local original_SetLootItem = InformationTooltip_index.SetLootItem
  105.     InformationTooltip_index.SetLootItem = function(control, lootId, ...)
  106.         local itemLink = GetLootItemLink(lootId)
  107.         local itemId = tonumber((select(4, ZO_LinkHandler_ParseLink(itemLink))))
  108.         local tradeSkillType = GetTradeSkillTypeFromItemId(itemId)
  109.         original_SetLootItem(control, lootId, ...)
  110.         AddTooltipByType(control, tradeSkillType, nil, itemId)
  111.     end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement