changeset 31:44c285acfff0 v8

fixed item display bug on summary tab
author yellowfive
date Sat, 18 Oct 2014 10:33:33 -0700
parents 55906ac875ae
children a401dd0e200e
files AskMrRobot.lua AskMrRobot.toc amr-constants.lua localization/localization.en.lua ui/GearComparisonTab.lua ui/ItemLinkText.lua ui/SummaryTab.lua
diffstat 7 files changed, 177 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/AskMrRobot.lua	Fri Oct 17 02:44:16 2014 -0700
+++ b/AskMrRobot.lua	Sat Oct 18 10:33:33 2014 -0700
@@ -35,6 +35,9 @@
 AskMrRobot.AddonName = ...
 AskMrRobot.ChatPrefix = "_AMR"
 
+-- flag to turn on debugging behavior
+AskMrRobot.debug = false
+
 -- the main user interface window
 AskMrRobot.mainWindow = nil
 
@@ -450,7 +453,7 @@
     local currencies = {};
     currencies[-1] = GetMoney()
     
-    local currencyList = {61, 81, 241, 361, 384, 394, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 416, 515, 614, 615, 676, 679}
+    local currencyList = {61, 81, 241, 361, 384, 394, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 416, 515, 614, 615, 676, 679, 823}
 	for i, currency in pairs(currencyList) do
 		local amount = getCurrencyAmount(currency)
 		if amount ~= 0 then
@@ -803,7 +806,7 @@
 --
 -- Import a character, returning nil on success, otherwise an error message, import result stored in AskMrRobot.ImportData
 --
-function AskMrRobot.ImportCharacter(data)
+function AskMrRobot.ImportCharacter(data, isTest)
 
     -- make sure all data is up to date before importing
     AskMrRobot.SaveAll()
@@ -826,54 +829,57 @@
     end
     
     -- require realm/name match
-    local realm = parts[2]
-    local name = parts[3]
-    if name ~= AmrDb.CharacterName then
-        local badPers = name .. " (" .. realm .. ")"
-        local goodPers = AmrDb.CharacterName .. " (" .. AmrDb.RealmName .. ")"
-        return L.AMR_IMPORT_ERROR_CHAR:format(badPers, goodPers)
+    if not isTest then
+        local realm = parts[2]
+        local name = parts[3]
+        if name ~= AmrDb.CharacterName then
+            local badPers = name .. " (" .. realm .. ")"
+            local goodPers = AmrDb.CharacterName .. " (" .. AmrDb.RealmName .. ")"
+            return L.AMR_IMPORT_ERROR_CHAR:format(badPers, goodPers)
+        end
+        
+        -- require race match
+        local race = tonumber(parts[5])
+        if race ~= AskMrRobot.raceIds[AmrDb.Race] then
+            return L.AMR_IMPORT_ERROR_RACE
+        end
+        
+        -- require faction match
+        local faction = tonumber(parts[6])
+        if faction ~= AskMrRobot.factionIds[AmrDb.Faction] then
+            return L.AMR_IMPORT_ERROR_FACTION
+        end
+        
+        -- require level match
+        local level = tonumber(parts[7])
+        if level ~= AmrDb.Level then
+            return L.AMR_IMPORT_ERROR_LEVEL
+        end
+
+        -- require spec match
+        local spec = tonumber(parts[11])
+        if spec ~= AmrDb.Specs[AmrDb.ActiveSpec] then
+            print(AmrDb.ActiveSpec)
+            print(spec)
+            print(AmrDb.Specs[AmrDb.ActiveSpec])
+            local _, specName = GetSpecializationInfoByID(AskMrRobot.gameSpecIds[spec])
+            return L.AMR_IMPORT_ERROR_SPEC:format(specName)
+        end
+        
+        -- require talent match
+        local talents = parts[12]
+        if talents ~= AmrDb.Talents[AmrDb.ActiveSpec] then
+            return L.AMR_IMPORT_ERROR_TALENT
+        end
+        
+        -- require glyph match
+        -- TODO: re-enable this check when glyphs are more consistent
+        --local glyphs = parts[13]
+        --if glyphs ~= AskMrRobot.toCompressedNumberList(AmrDb.Glyphs[AmrDb.ActiveSpec]) then
+        --    return L.AMR_IMPORT_ERROR_GLYPH
+        --end
     end
     
-    -- require race match
-    local race = tonumber(parts[5])
-    if race ~= AskMrRobot.raceIds[AmrDb.Race] then
-        return L.AMR_IMPORT_ERROR_RACE
-    end
-    
-    -- require faction match
-    local faction = tonumber(parts[6])
-    if faction ~= AskMrRobot.factionIds[AmrDb.Faction] then
-        return L.AMR_IMPORT_ERROR_FACTION
-    end
-    
-    -- require level match
-    local level = tonumber(parts[7])
-    if level ~= AmrDb.Level then
-        return L.AMR_IMPORT_ERROR_LEVEL
-    end
-
-    -- require spec match
-    local spec = tonumber(parts[11])
-    if spec ~= AmrDb.Specs[AmrDb.ActiveSpec] then
-        print(AmrDb.ActiveSpec)
-        print(spec)
-        print(AmrDb.Specs[AmrDb.ActiveSpec])
-        local _, specName = GetSpecializationInfoByID(AskMrRobot.gameSpecIds[spec])
-        return L.AMR_IMPORT_ERROR_SPEC:format(specName)
-    end
-    
-    -- require talent match
-    local talents = parts[12]
-    if talents ~= AmrDb.Talents[AmrDb.ActiveSpec] then
-        return L.AMR_IMPORT_ERROR_TALENT
-    end
-    
-    -- require glyph match
-    -- TODO: re-enable this check when glyphs are more consistent
-    --local glyphs = parts[13]
-    --if glyphs ~= AskMrRobot.toCompressedNumberList(AmrDb.Glyphs[AmrDb.ActiveSpec]) then
-    --    return L.AMR_IMPORT_ERROR_GLYPH
-    --end
     
     -- if we make it this far, the data is valid, so read item information
     local importData = {}
@@ -1045,12 +1051,20 @@
         end
     end
     
-    -- we have succeeded, record the result
-    AskMrRobot.ImportData = importData
-    AskMrRobot.ExtraItemData = itemInfo
-    AskMrRobot.ExtraGemData = gemInfo
-    AskMrRobot.ExtraEnchantData = enchantInfo    
-    
-    AmrDb.LastCharacterImport = data
-    AmrDb.LastCharacterImportDate = date()    
+    if isTest then
+        -- print result for debugging
+        local blah = importData[1]
+        local name, link = GetItemInfo(AskMrRobot.createItemLink(blah))
+        print(link)
+        
+    else
+        -- we have succeeded, record the result
+        AskMrRobot.ImportData = importData
+        AskMrRobot.ExtraItemData = itemInfo
+        AskMrRobot.ExtraGemData = gemInfo
+        AskMrRobot.ExtraEnchantData = enchantInfo    
+        
+        AmrDb.LastCharacterImport = data
+        AmrDb.LastCharacterImportDate = date()
+    end
 end
--- a/AskMrRobot.toc	Fri Oct 17 02:44:16 2014 -0700
+++ b/AskMrRobot.toc	Sat Oct 18 10:33:33 2014 -0700
@@ -1,7 +1,7 @@
 ## Interface: 60000
 ## Title: Ask Mr. Robot
 ## Author: Team Robot, Inc.
-## Version: 7
+## Version: 8
 ## Notes: Exports/Imports data to/from askmrrobot.com.
 ## URL: www.askmrrobot.com
 ## DefaultState: Enabled
--- a/amr-constants.lua	Fri Oct 17 02:44:16 2014 -0700
+++ b/amr-constants.lua	Sat Oct 18 10:33:33 2014 -0700
@@ -33,6 +33,40 @@
     return item
 end
 
+-- item link format:  |cffa335ee|Hitem:itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2...|h[item name]|h|r
+
+function AskMrRobot.createItemLink(itemObj)
+
+    if itemObj == nil or itemObj.id == nil or itemObj.id == 0 then return nil end
+    
+    local parts = {}
+    table.insert(parts, "item")
+    table.insert(parts, itemObj.id)
+    table.insert(parts, itemObj.enchantId)
+    table.insert(parts, itemObj.gemIds[1])
+    table.insert(parts, itemObj.gemIds[2])
+    table.insert(parts, itemObj.gemIds[3])
+    table.insert(parts, itemObj.gemIds[4])
+    table.insert(parts, -math.abs(itemObj.suffixId))
+    table.insert(parts, 0)
+    table.insert(parts, UnitLevel("player"))
+    table.insert(parts, itemObj.upgradeId)
+    table.insert(parts, 0)
+    
+    if itemObj.bonusIds then
+        table.insert(parts, #itemObj.bonusIds)
+        for i,v in ipairs(itemObj.bonusIds) do
+            table.insert(parts, v)
+        end
+    end
+    
+    return table.concat(parts, ":")
+end
+
+function AskMrRobot.createGemLink(gemId)
+
+end
+
 -- convenience to get just the item id (or 0 if not a valid link) from an item link
 function AskMrRobot.getItemIdFromLink(itemLink)
 	if not itemLink then return 0 end
@@ -223,12 +257,12 @@
     [6] = _G["WAISTSLOT"],
     [7] = _G["LEGSSLOT"],
     [8] = _G["FEETSLOT"],
-    [9] = _G["WROSTSLOT"],
+    [9] = _G["WRISTSLOT"],
     [10] = _G["HANDSSLOT"],
-    [11] = _G["FINGER0SLOT"],
-    [12] = _G["FINGER1SLOT"],
-    [13] = _G["TRINKET0SLOT"],
-    [14] = _G["TRINKET1SLOT"],
+    [11] = _G["FINGER0SLOT"] .. " 1",
+    [12] = _G["FINGER1SLOT"] .. " 2",
+    [13] = _G["TRINKET0SLOT"] .. " 1",
+    [14] = _G["TRINKET1SLOT"] .. " 2",
     [15] = _G["BACKSLOT"],
     [16] = _G["MAINHANDSLOT"],
     [17] = _G["SECONDARYHANDSLOT"]
--- a/localization/localization.en.lua	Fri Oct 17 02:44:16 2014 -0700
+++ b/localization/localization.en.lua	Sat Oct 18 10:33:33 2014 -0700
@@ -1,4 +1,4 @@
-local _, AskMrRobot = ...
+local _, AskMrRobot = ...
 AskMrRobot.L = {};
 local L = AskMrRobot.L;
 
@@ -481,7 +481,7 @@
 L.AMR_HELPTAB_A2 = "|c0066dd66A:|r Yes. Go to the |c00ffd100website|r and click the green '|c0000ff00Update from Armory|r' button found just above your character name, to make sure you have updated gear. Optimize your gear and then click the blue '|c0018C0F7Export to Addon|r' button found to the right of your gear, in the purple '|c00BF28D6Now What?|r section.  Return to this |c00ffd100addon|r, go to the '|c00ffd100Load a Gear Set|r' tab and paste the text in the box."
 L.AMR_HELPTAB_Q3 = "|c00999999Q:|r Can I send my shopping list to an alt?"
 L.AMR_HELPTAB_A3 = '|c0066dd66A:|r Yes, go to the shopping list tab and select the "mail" option in the drop down. You can mail the list to your alt.'
-L.AMR_HELPTAB_Q4 = "|c00999999Q:|r I am in the middle of a raid and just won a piece of loot. Can I optimize really quick"
+L.AMR_HELPTAB_Q4 = "|c00999999Q:|r I am in the middle of a raid and just won a piece of loot. Can I optimize really quickly?"
 L.AMR_HELPTAB_A4 = "|c0066dd66A:|r Yes! You'll want to read the tutorial on that here: \r|c003333ffhttp://blog.askmrrobot.com/addon#raid"
 L.AMR_HELPTAB_Q5 = "|c00999999Q:|r Where is auto gemming?"
 L.AMR_HELPTAB_A5 = "|c0066dd66A:|r We have temporarily removed it.  We plan to bring it back for WoD"
--- a/ui/GearComparisonTab.lua	Fri Oct 17 02:44:16 2014 -0700
+++ b/ui/GearComparisonTab.lua	Sat Oct 18 10:33:33 2014 -0700
@@ -119,27 +119,39 @@
 end
 
 function AskMrRobot.GearComparisonTab:On_SOCKET_INFO_CLOSE()
-    self:Import()
+    if self.initialized then
+        self:Import()
+    end
 end
 
 function AskMrRobot.GearComparisonTab:On_SOCKET_INFO_UPDATE()
-    self:Import()
+    if self.initialized then
+        self:Import()
+    end
 end
 
 function AskMrRobot.GearComparisonTab:On_PLAYER_SPECIALIZATION_CHANGED()
-    self:Import()
+    if self.initialized then
+        self:Import()
+    end
 end
 
 function AskMrRobot.GearComparisonTab:On_BAG_UPDATE()
-    self:Import()
+    if self.initialized then
+        self:Import()
+    end
 end
 
 function AskMrRobot.GearComparisonTab:On_ITEM_PUSH()
-    self:Import()
+    if self.initialized then
+        self:Import()
+    end
 end
 
 function AskMrRobot.GearComparisonTab:On_DELETE_ITEM_CONFIRM()
-    self:Import()
+    if self.initialized then
+        self:Import()
+    end
 end
 
 function AskMrRobot.GearComparisonTab:OnShow()
@@ -150,6 +162,7 @@
         if AmrDb.LastCharacterImport and AmrDb.LastCharacterImport ~= "" then
             self.importTab:SetImportText(AmrDb.LastCharacterImport)
             self:Import()
+            self.tabButtonClick(self.tabButtons[2])
         else
             self:Update()
         end
@@ -160,10 +173,7 @@
 
 function AskMrRobot.GearComparisonTab:Import()
 
-    -- example string
-    -- $2;Brill (EU);Yellowfive;Twisted Legion;11;2;90;7:600,9:600;1;s1;34;2123320;68164,47782,7833;q1;99195s7u493x4647y0c22e4823;1s3u0x0y0c11e90;6s10u0x0y0c11e-481;1s1u0x383y-383c41;3047s15u12x0c1e-8;3109s5u-12x0y0z0c112e445;55s8u12x0c1e-442;5371s16u0b450x0c1e18;1691s13u-14b-1;238s11u0b0x-60c3;28s2u0b0;21s6u2b0x60y0z0c130;29s14u0b0;1s9u-2b0e-30;62s12u0b0x0c1;95s17u2b0x0c1$g\4647\76697\76631,76697,83146\20 _CriticalStrike_@g\5030\95344\\Indomitable@g\4587\76636\76570,76636,83144\20 _CriticalStrike_@e\4823\83765\122388\19 _Strength_, 11 _CriticalStrike_\72163=1,76061=1@e\4913\87585\113047\20 _Strength_, 5 _CriticalStrike_\39354=1,79254=3@e\4432\74721\104419\11 _Strength_\74249=3,74250=1,74247=1@e\4424\74713\104404\12 _CriticalStrike_\74250=1@e\4869\85559\124091\9 _Stamina_\72120=4@e\4427\74716\104408\11 _CriticalStrike_\74249=2,74250=1@e\4445\74727\104440\Colossus\74247=3@e\4415\74704\104390\18 _Strength_\74248=3 
-    
-    local err = AskMrRobot.ImportCharacter(self.importTab:GetImportText())
+    local err = AskMrRobot.ImportCharacter(self.importTab:GetImportText(), AskMrRobot.debug)
     -- goto the summary tab
     self.summaryTab:showImportError(err)
     PanelTemplates_EnableTab(self, 2)
--- a/ui/ItemLinkText.lua	Fri Oct 17 02:44:16 2014 -0700
+++ b/ui/ItemLinkText.lua	Sat Oct 18 10:33:33 2014 -0700
@@ -21,38 +21,49 @@
 	self.formatText = formatText
 end
 
-function AskMrRobot.ItemLinkText:SetItemId(itemId, upgradeId, suffixId)
-	AskMrRobot.ItemTooltipFrame.SetItemLink(self, link)
-	self.itemName = nil
-	if itemId and itemId > 0 then
-		local linkTemplate = "item:%d:0:0:0:0:0:%d:0:%d:0:%d"
-		local itemName, itemLink = GetItemInfo(linkTemplate:format(itemId, suffixId, UnitLevel("player"), upgradeId))
-		self:SetItemLink(itemLink)
-		if itemLink then
-			self.itemName = itemName
-			if self.formatText then
-				self.itemText:SetFormattedText(self.formatText, itemLink:gsub("%[", ""):gsub("%]", ""))
-			else
-				self.itemText:SetText(itemLink:gsub("%[", ""):gsub("%]", ""))
-			end
-		else
-			self.itemText:SetFormattedText("unknown (%d)", itemId)
-			self.itemText:SetTextColor(1,1,1)
-			AskMrRobot.RegisterItemInfoCallback(itemId, function(name, itemLink2)
-				if self.formatText then
-					self.itemText:SetFormattedText(self.formatText, itemLink2:gsub("%[", ""):gsub("%]", ""))
-				else
-					self.itemText:SetText(itemLink2:gsub("%[", ""):gsub("%]", ""))
-				end
-				self:SetItemLink(itemLink2)
-				self.itemName = name
-			end)
-		end
-	else
-		self.itemText:SetText("empty")
+function AskMrRobot.ItemLinkText:SetItem(itemObj)
+    -- blank/nil
+    if itemObj == nil or itemObj.id == nil or itemObj.id == 0 then
+        self.itemText:SetText("empty")
 		self.itemText:SetTextColor(0.5,0.5,0.5)
 		self:SetItemLink(nil)
-	end
+        return
+    end
+    
+    local itemName, itemLink = GetItemInfo(AskMrRobot.createItemLink(itemObj))
+    self:SetItemLink(itemLink)
+    if itemLink then
+        self.itemName = itemName
+        if self.formatText then
+            self.itemText:SetFormattedText(self.formatText, itemLink:gsub("%[", ""):gsub("%]", ""))
+        else
+            self.itemText:SetText(itemLink:gsub("%[", ""):gsub("%]", ""))
+        end
+    else
+        self.itemText:SetFormattedText("unknown (%d)", itemId)
+        self.itemText:SetTextColor(1,1,1)
+        AskMrRobot.RegisterItemInfoCallback(itemId, function(name, itemLink2)
+            if self.formatText then
+                self.itemText:SetFormattedText(self.formatText, itemLink2:gsub("%[", ""):gsub("%]", ""))
+            else
+                self.itemText:SetText(itemLink2:gsub("%[", ""):gsub("%]", ""))
+            end
+            self:SetItemLink(itemLink2)
+            self.itemName = name
+        end)
+    end
+end 
+
+function AskMrRobot.ItemLinkText:SetItemId(itemId)
+
+    self:SetItem({ 
+        id = itemId,
+        enchantId = 0,
+        gemIds = {0,0,0,0},
+        suffixId = 0,
+        upgradeId = 0
+    })
+    
 end
 
 function AskMrRobot.ItemLinkText:SetFontSize(fontSize)
--- a/ui/SummaryTab.lua	Fri Oct 17 02:44:16 2014 -0700
+++ b/ui/SummaryTab.lua	Sat Oct 18 10:33:33 2014 -0700
@@ -196,9 +196,9 @@
 			self.badItemSlots[i]:SetText(AskMrRobot.slotDisplayText[slotId])
 			self.badItemSlots[i]:Show()
 			if badItem.optimized then
-				self.badItemNames[i]:SetItemId(badItem.optimized.id, badItem.optimized.upgradeId, badItem.optimized.suffixId)
+				self.badItemNames[i]:SetItem(badItem.optimized)
 			else
-				self.badItemNames[i]:SetItemId(nil, 0, 0)
+				self.badItemNames[i]:SetItem(nil)
 			end
 			self.badItemNames[i]:Show()
 			i = i + 1
@@ -214,9 +214,9 @@
 			self.upgradeItemSlots[j]:SetText(AskMrRobot.slotDisplayText[slotId])
 			self.upgradeItemSlots[j]:Show()
 			if badItem.optimized then
-				self.upgradeItemNames[j]:SetItemId(badItem.optimized.id, badItem.optimized.upgradeId, badItem.optimized.suffixId)
+				self.upgradeItemNames[j]:SetItem(badItem)
 			else
-				self.upgradeItemNames[j]:SetItemId(nil, 0, 0)
+				self.upgradeItemNames[j]:SetItem(nil)
 			end
 			self.upgradeItemNames[j]:Show()
 			j = j + 1