adam@0: local _, AskMrRobot = ... adam@0: adam@0: local MAX_GEMS_PER_SLOT = 3 adam@0: adam@0: -- make the JewelPanel inherit from a dummy frame adam@0: AskMrRobot.JewelPanel = AskMrRobot.inheritsFrom(AskMrRobot.Frame) adam@0: adam@0: -- JewelPanel constructor adam@0: function AskMrRobot.JewelPanel:new (name, parent) adam@0: -- create a new frame if one isn't supplied adam@0: local o = AskMrRobot.Frame:new(name, parent) adam@0: adam@0: -- make the object a JewelPanel instanct adam@0: setmetatable(o, { __index = AskMrRobot.JewelPanel}) adam@0: adam@0: -- set the height and border of the newly created jewel frame adam@0: o:SetHeight(95) adam@0: o:SetBackdrop({edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeSize = 16}) adam@0: adam@0: -- setup the slot name adam@0: o._slotName = o:CreateFontString(nil, "ARTWORK", "GameFontWhite") adam@0: o._slotName:SetPoint("TOPLEFT", 11, -10) adam@0: o._slotName:SetWidth(80) adam@0: o._slotName:SetJustifyH("LEFT") adam@0: adam@0: -- setup the item icon frame adam@0: o._itemIcon = AskMrRobot.ItemIcon:new() adam@0: o._itemIcon:SetParent(o) adam@0: o._itemIcon:SetRoundBorder() adam@0: o._itemIcon:SetPoint("TOPLEFT", 9, -32) adam@0: o._itemIcon:SetWidth(48) adam@0: o._itemIcon:SetHeight(48) adam@0: adam@0: -- initialize the current gems array adam@0: o._currentGems = {} adam@0: o._optimizedGemText = {} adam@0: o._optimizedGemIcons = {} adam@0: -- for each row of gems adam@0: for i = 1, MAX_GEMS_PER_SLOT do adam@0: -- create an item icon for the currently equiped gem adam@0: local gemIcon = AskMrRobot.GemIcon:new(nil, o) adam@0: gemIcon:SetPoint("TOPLEFT", 100, 18 - 27 * i) adam@0: gemIcon:SetWidth(24) adam@0: gemIcon:SetHeight(24) adam@0: gemIcon:SetRoundBorder() adam@0: o._currentGems[i] = gemIcon adam@0: adam@0: -- create an item icon for the optimized gem adam@0: gemIcon = AskMrRobot.GemIcon:new(nil, o) adam@0: gemIcon:SetPoint("TOPLEFT", 170, 18 - 27 * i) adam@0: gemIcon:SetWidth(24) adam@0: gemIcon:SetHeight(24) adam@0: gemIcon:SetRoundBorder() adam@0: o._optimizedGemIcons[i] = gemIcon adam@0: adam@0: -- create the optimized gem text adam@0: local gemText = o:CreateFontString(nil, "ARTWORK", "GameFontWhite") adam@0: gemText:SetPoint("TOPLEFT", 200, 12 - 27 * i) adam@0: gemText:SetPoint("RIGHT", -30) adam@0: gemText:SetJustifyH("LEFT") adam@0: o._optimizedGemText[i] = gemText adam@0: end adam@0: adam@0: -- return the JewelPanel instance adam@0: return o adam@0: end adam@0: adam@0: -- set the item link for this JewelPanel adam@0: -- this updates the item icon, the slot name, and the tooltip adam@0: function AskMrRobot.JewelPanel:SetItemLink(slotName, itemLink) adam@0: -- set the item icon and the tooltip adam@0: self._itemIcon:SetItemLink(itemLink) adam@0: adam@0: if itemLink then adam@0: local _, _, rarity = GetItemInfo(itemLink) adam@0: if rarity then adam@0: local r,g,b = GetItemQualityColor(rarity) adam@0: self._itemIcon:SetBackdropBorderColor(r,g,b,1) adam@0: else adam@0: self._itemIcon:SetBackdropBorderColor(1,1,1,1) adam@0: end adam@0: else adam@0: self._itemIcon:SetBackdropBorderColor(1,1,1,1) adam@0: end adam@0: adam@0: -- set the slot name adam@0: self._slotName:SetText(slotName) adam@0: end adam@0: adam@0: -- set the optimized gem information (array of {id, color, enchantId}) adam@0: -- SetItemLink must be called first adam@0: function AskMrRobot.JewelPanel:SetOptimizedGems(optimizedGems, showGems) adam@0: adam@0: -- get the item link adam@0: local itemLink = self._itemIcon.itemLink adam@0: adam@0: if not itemLink then return end adam@0: adam@0: -- for all of the gem rows in this control adam@0: local itemId = AskMrRobot.getItemIdFromLink(itemLink) adam@0: adam@0: local gemCount = 0 adam@0: adam@0: for i = 1, MAX_GEMS_PER_SLOT do adam@0: -- get the optimized text, optimized icon, and current icon for the row adam@0: local text = self._optimizedGemText[i] adam@0: local optimizedIcon = self._optimizedGemIcons[i] adam@0: local currentIcon = self._currentGems[i] adam@0: adam@0: -- get the current gem in the specified slot adam@0: local currentGemLink = select(2, GetItemGem(itemLink, i)) adam@0: adam@0: -- if there is a gem to add (or remove) adam@0: --if i <= #optimizedGems or currentGemLink then adam@0: if i <= #optimizedGems or currentGemLink then adam@0: -- set the current gem icon / tooltip adam@0: currentIcon:SetItemLink(currentGemLink) adam@0: adam@0: local currentGemId = AskMrRobot.getItemIdFromLink(currentGemLink) adam@0: adam@0: local optimizedGemLink = nil adam@0: if i <= #optimizedGems then adam@0: -- make a link for the optimized gem adam@0: optimizedGemLink = select(2, GetItemInfo(optimizedGems[i].id)) adam@0: adam@0: if not optimizedGemLink and optimizedGems[i].id and itemId then adam@0: AskMrRobot.RegisterItemInfoCallback(optimizedGems[i].id, function(name, link) adam@0: optimizedIcon:SetItemLink(link) adam@0: end) adam@0: end adam@0: end adam@0: adam@0: if showGems[i] and optimizedGems[i] and optimizedGems[i].color then adam@0: gemCount = gemCount + 1 adam@0: -- set the optimized gem text adam@0: text:SetTextColor(1,1,1) adam@0: text:SetText(AskMrRobot.alternateGemName[optimizedGems[i].id] or (optimizedGems[i].enchantId ~= 0 and AskMrRobot.getEnchantName(optimizedGems[i].enchantId)) or GetItemInfo(optimizedGems[i].id)) adam@0: currentIcon:Show() adam@0: adam@0: -- load the item image / tooltip adam@0: optimizedIcon:SetItemLink(optimizedGemLink) adam@0: optimizedIcon:Show() adam@0: optimizedIcon:SetBackdropBorderColor(1,1,1) adam@0: currentIcon:SetBackdropBorderColor(1,1,1) adam@0: else adam@0: if optimizedGems[i] and optimizedGems[i].color then adam@0: text:SetText("no change") adam@0: text:SetTextColor(0.5,0.5,0.5) adam@0: currentIcon:Show() adam@0: gemCount = gemCount + 1 adam@0: else adam@0: text:SetText('') adam@0: currentIcon:Hide() adam@0: end adam@0: optimizedIcon:SetItemLink(nil) adam@0: optimizedIcon:Hide() adam@0: end adam@0: adam@0: currentIcon:SetGemColor(optimizedGems[i] and optimizedGems[i].color) adam@0: optimizedIcon:SetGemColor(optimizedGems[i] and optimizedGems[i].color) adam@0: adam@0: -- show the gem row adam@0: text:Show() adam@0: else adam@0: -- hide the gem row adam@0: text:Hide() adam@0: optimizedIcon:Hide() adam@0: currentIcon:Hide() adam@0: end adam@0: end adam@0: adam@0: local y1 = 0 adam@0: local y2 = 0 adam@0: if gemCount == 1 then adam@0: y1 = 27 adam@0: elseif gemCount == 2 then adam@0: y1 = 9 adam@0: y2 = 4 adam@0: end adam@0: adam@0: for i = 1, MAX_GEMS_PER_SLOT do adam@0: self._optimizedGemText[i]:SetPoint("TOPLEFT", 200, 12 - (27 + y2) * i - y1) adam@0: self._optimizedGemIcons[i]:SetPoint("TOPLEFT", 170, 18 - (27 + y2) * i - y1) adam@0: self._currentGems[i]:SetPoint("TOPLEFT", 100, 18 - (27 + y2) * i - y1) adam@0: end adam@0: end