Quantcast

V0.5.1

Brandon Talbot [07-13-16 - 18:44]
V0.5.1
* Added text to inform the user how much the Junk was worth
* Ensured text on item container shows full name if truncated (with tooltip)
* Added tool to get correct item level for items (also made items in armor/weapon show tooltip whether or not it is equipable)
Filename
DJBags.toc
src/lua/controllers/bag.lua
src/lua/elements/item.lua
src/lua/elements/itemContainer.lua
diff --git a/DJBags.toc b/DJBags.toc
index 3c96d7e..306eddc 100644
--- a/DJBags.toc
+++ b/DJBags.toc
@@ -2,7 +2,7 @@
 ## Title: DJBags
 ## Author: DarkJaguar91
 ## Notes: BagAddon - BETA
-## Version: 0.4.1
+## Version: 0.5.1
 ## SavedVariables: DJBagsConfig

 src/manifest.xml
\ No newline at end of file
diff --git a/src/lua/controllers/bag.lua b/src/lua/controllers/bag.lua
index 3cfda87..43ca673 100644
--- a/src/lua/controllers/bag.lua
+++ b/src/lua/controllers/bag.lua
@@ -32,15 +32,18 @@ end

 function bag:MERCHANT_SHOW()
     if ADDON.settings.auto.sellJunk then
+        local price = 0
         for bag = 0, NUM_BAG_SLOTS do
             for slot = 1 , GetContainerNumSlots(bag) do
                 if select(4, GetContainerItemInfo(bag, slot)) == LE_ITEM_QUALITY_POOR then
                     ShowMerchantSellCursor(1)
                     UseContainerItem(bag, slot)
+                    price = price + select(11, GetItemInfo(GetContainerItemID(bag, slot)))
                 end
             end
         end
         ResetCursor()
+        DEFAULT_CHAT_FRAME:AddMessage("Sold junk for: " .. GetCoinTextureString(price))
     end
 end

diff --git a/src/lua/elements/item.lua b/src/lua/elements/item.lua
index 1679eb3..b724be5 100644
--- a/src/lua/elements/item.lua
+++ b/src/lua/elements/item.lua
@@ -218,19 +218,26 @@ local function UpdateCooldown(self)
 end

 function item:Update()
-    local texture, count, locked, quality, _, _, _, filtered, _, id = GetContainerItemInfo(self:GetID(), self.button:GetID())
+    local texture, count, locked, quality, _, _, link, filtered, _, id = GetContainerItemInfo(self:GetID(), self.button:GetID())
     local equipable = IsEquippableItem(id)
+    local name, level, classId
+    if id then
+        name, _, _, level, _, _, _, _, _, _, _, classId = GetItemInfo(id)
+    end
     self.id = id
-    self.name = id and select(1, GetItemInfo(id)) or ''
+    self.name = name or ''
     self.quality = quality or 0
-    self.ilevel = id and select(4, GetItemInfo(id)) or 0
+    self.ilevel = level or 0
     self.button.hasItem = nil

+    local isEquipment = equipable or classId == LE_ITEM_CLASS_ARMOR or classId == LE_ITEM_CLASS_WEAPON
+    if isEquipment then
+        count = count > 1 and count or (self:GetItemLevel(link) or level)
+    end

     if self:GetID() == BANK_CONTAINER or self:GetID() == REAGENTBANK_CONTAINER then
         BankFrameItemButton_Update(self.button)
-        if (equipable) then
-            count = count > 1 and count or select(4, GetItemInfo(id))
+        if isEquipment then
             SetItemButtonCount(self.button, count)
             UpdateCountcolour(self, equipable, quality)
         end
@@ -242,10 +249,6 @@ function item:Update()

         self.button.hasItem = true

-        if (equipable) then
-            count = count > 1 and count or select(4, GetItemInfo(id))
-        end
-
         SetItemButtonTexture(self.button, texture)
         SetItemButtonQuality(self.button, quality, id)
         SetItemButtonCount(self.button, count)
@@ -281,4 +284,31 @@ function item:OnClick(button)
     end
 end

+function item:GetItemLevel(link)
+    local tooltip = self:GetTooltip()
+
+    tooltip:SetOwner(UIParent, "ANCHOR_NONE")
+    tooltip:SetHyperlink(link)
+
+    for i = 2, tooltip:NumLines() do
+        local text = _G[tooltip:GetName() .. "TextLeft"..i]:GetText()
+        local UPGRADE_LEVEL = gsub(ITEM_LEVEL," %d","")
+
+        if text and text:find(UPGRADE_LEVEL) then
+            local itemLevel = string.match(text,"%d+")
+
+            if itemLevel then
+                return tonumber(itemLevel)
+            end
+        end
+    end
+end
+
+function item:GetTooltip()
+    if not ADDON.DJTooltip then
+        ADDON.DJTooltip = CreateFrame('GameTooltip', 'DJBagsTooltip', UIParent, 'GameTooltipTemplate')
+    end
+    return ADDON.DJTooltip
+end
+
 --endregion
\ No newline at end of file
diff --git a/src/lua/elements/itemContainer.lua b/src/lua/elements/itemContainer.lua
index b50bf04..321c7ae 100644
--- a/src/lua/elements/itemContainer.lua
+++ b/src/lua/elements/itemContainer.lua
@@ -128,7 +128,7 @@ function container:IsEmpty()
 end

 function container:TitleEnter()
-    if (self:GetParent().title:IsTruncated()) then
+    if (self:GetParent().title:IsTruncated() or self:GetParent().title:GetText() ~= self:GetParent().name) then
         GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
         GameTooltip:SetText(self:GetParent().name)
         GameTooltip:Show()