annotate ui/JewelPanel.lua @ 0:ec731d2fe6ba

Version 1.2.12.0
author Adam tegen <adam.tegen@gmail.com>
date Tue, 20 May 2014 21:43:23 -0500
parents
children e77e01abce98
rev   line source
adam@0 1 local _, AskMrRobot = ...
adam@0 2
adam@0 3 local MAX_GEMS_PER_SLOT = 3
adam@0 4
adam@0 5 -- make the JewelPanel inherit from a dummy frame
adam@0 6 AskMrRobot.JewelPanel = AskMrRobot.inheritsFrom(AskMrRobot.Frame)
adam@0 7
adam@0 8 -- JewelPanel constructor
adam@0 9 function AskMrRobot.JewelPanel:new (name, parent)
adam@0 10 -- create a new frame if one isn't supplied
adam@0 11 local o = AskMrRobot.Frame:new(name, parent)
adam@0 12
adam@0 13 -- make the object a JewelPanel instanct
adam@0 14 setmetatable(o, { __index = AskMrRobot.JewelPanel})
adam@0 15
adam@0 16 -- set the height and border of the newly created jewel frame
adam@0 17 o:SetHeight(95)
adam@0 18 o:SetBackdrop({edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeSize = 16})
adam@0 19
adam@0 20 -- setup the slot name
adam@0 21 o._slotName = o:CreateFontString(nil, "ARTWORK", "GameFontWhite")
adam@0 22 o._slotName:SetPoint("TOPLEFT", 11, -10)
adam@0 23 o._slotName:SetWidth(80)
adam@0 24 o._slotName:SetJustifyH("LEFT")
adam@0 25
adam@0 26 -- setup the item icon frame
adam@0 27 o._itemIcon = AskMrRobot.ItemIcon:new()
adam@0 28 o._itemIcon:SetParent(o)
adam@0 29 o._itemIcon:SetRoundBorder()
adam@0 30 o._itemIcon:SetPoint("TOPLEFT", 9, -32)
adam@0 31 o._itemIcon:SetWidth(48)
adam@0 32 o._itemIcon:SetHeight(48)
adam@0 33
adam@0 34 -- initialize the current gems array
adam@0 35 o._currentGems = {}
adam@0 36 o._optimizedGemText = {}
adam@0 37 o._optimizedGemIcons = {}
adam@0 38 -- for each row of gems
adam@0 39 for i = 1, MAX_GEMS_PER_SLOT do
adam@0 40 -- create an item icon for the currently equiped gem
adam@0 41 local gemIcon = AskMrRobot.GemIcon:new(nil, o)
adam@0 42 gemIcon:SetPoint("TOPLEFT", 100, 18 - 27 * i)
adam@0 43 gemIcon:SetWidth(24)
adam@0 44 gemIcon:SetHeight(24)
adam@0 45 gemIcon:SetRoundBorder()
adam@0 46 o._currentGems[i] = gemIcon
adam@0 47
adam@0 48 -- create an item icon for the optimized gem
adam@0 49 gemIcon = AskMrRobot.GemIcon:new(nil, o)
adam@0 50 gemIcon:SetPoint("TOPLEFT", 170, 18 - 27 * i)
adam@0 51 gemIcon:SetWidth(24)
adam@0 52 gemIcon:SetHeight(24)
adam@0 53 gemIcon:SetRoundBorder()
adam@0 54 o._optimizedGemIcons[i] = gemIcon
adam@0 55
adam@0 56 -- create the optimized gem text
adam@0 57 local gemText = o:CreateFontString(nil, "ARTWORK", "GameFontWhite")
adam@0 58 gemText:SetPoint("TOPLEFT", 200, 12 - 27 * i)
adam@0 59 gemText:SetPoint("RIGHT", -30)
adam@0 60 gemText:SetJustifyH("LEFT")
adam@0 61 o._optimizedGemText[i] = gemText
adam@0 62 end
adam@0 63
adam@0 64 -- return the JewelPanel instance
adam@0 65 return o
adam@0 66 end
adam@0 67
adam@0 68 -- set the item link for this JewelPanel
adam@0 69 -- this updates the item icon, the slot name, and the tooltip
adam@0 70 function AskMrRobot.JewelPanel:SetItemLink(slotName, itemLink)
adam@0 71 -- set the item icon and the tooltip
adam@0 72 self._itemIcon:SetItemLink(itemLink)
adam@0 73
adam@0 74 if itemLink then
adam@0 75 local _, _, rarity = GetItemInfo(itemLink)
adam@0 76 if rarity then
adam@0 77 local r,g,b = GetItemQualityColor(rarity)
adam@0 78 self._itemIcon:SetBackdropBorderColor(r,g,b,1)
adam@0 79 else
adam@0 80 self._itemIcon:SetBackdropBorderColor(1,1,1,1)
adam@0 81 end
adam@0 82 else
adam@0 83 self._itemIcon:SetBackdropBorderColor(1,1,1,1)
adam@0 84 end
adam@0 85
adam@0 86 -- set the slot name
adam@0 87 self._slotName:SetText(slotName)
adam@0 88 end
adam@0 89
adam@0 90 -- set the optimized gem information (array of {id, color, enchantId})
adam@0 91 -- SetItemLink must be called first
adam@0 92 function AskMrRobot.JewelPanel:SetOptimizedGems(optimizedGems, showGems)
adam@0 93
adam@0 94 -- get the item link
adam@0 95 local itemLink = self._itemIcon.itemLink
adam@0 96
adam@0 97 if not itemLink then return end
adam@0 98
adam@0 99 -- for all of the gem rows in this control
adam@0 100 local itemId = AskMrRobot.getItemIdFromLink(itemLink)
adam@0 101
adam@0 102 local gemCount = 0
adam@0 103
adam@0 104 for i = 1, MAX_GEMS_PER_SLOT do
adam@0 105 -- get the optimized text, optimized icon, and current icon for the row
adam@0 106 local text = self._optimizedGemText[i]
adam@0 107 local optimizedIcon = self._optimizedGemIcons[i]
adam@0 108 local currentIcon = self._currentGems[i]
adam@0 109
adam@0 110 -- get the current gem in the specified slot
adam@0 111 local currentGemLink = select(2, GetItemGem(itemLink, i))
adam@0 112
adam@0 113 -- if there is a gem to add (or remove)
adam@0 114 --if i <= #optimizedGems or currentGemLink then
adam@0 115 if i <= #optimizedGems or currentGemLink then
adam@0 116 -- set the current gem icon / tooltip
adam@0 117 currentIcon:SetItemLink(currentGemLink)
adam@0 118
adam@0 119 local currentGemId = AskMrRobot.getItemIdFromLink(currentGemLink)
adam@0 120
adam@0 121 local optimizedGemLink = nil
adam@0 122 if i <= #optimizedGems then
adam@0 123 -- make a link for the optimized gem
adam@0 124 optimizedGemLink = select(2, GetItemInfo(optimizedGems[i].id))
adam@0 125
adam@0 126 if not optimizedGemLink and optimizedGems[i].id and itemId then
adam@0 127 AskMrRobot.RegisterItemInfoCallback(optimizedGems[i].id, function(name, link)
adam@0 128 optimizedIcon:SetItemLink(link)
adam@0 129 end)
adam@0 130 end
adam@0 131 end
adam@0 132
adam@0 133 if showGems[i] and optimizedGems[i] and optimizedGems[i].color then
adam@0 134 gemCount = gemCount + 1
adam@0 135 -- set the optimized gem text
adam@0 136 text:SetTextColor(1,1,1)
adam@0 137 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 138 currentIcon:Show()
adam@0 139
adam@0 140 -- load the item image / tooltip
adam@0 141 optimizedIcon:SetItemLink(optimizedGemLink)
adam@0 142 optimizedIcon:Show()
adam@0 143 optimizedIcon:SetBackdropBorderColor(1,1,1)
adam@0 144 currentIcon:SetBackdropBorderColor(1,1,1)
adam@0 145 else
adam@0 146 if optimizedGems[i] and optimizedGems[i].color then
adam@0 147 text:SetText("no change")
adam@0 148 text:SetTextColor(0.5,0.5,0.5)
adam@0 149 currentIcon:Show()
adam@0 150 gemCount = gemCount + 1
adam@0 151 else
adam@0 152 text:SetText('')
adam@0 153 currentIcon:Hide()
adam@0 154 end
adam@0 155 optimizedIcon:SetItemLink(nil)
adam@0 156 optimizedIcon:Hide()
adam@0 157 end
adam@0 158
adam@0 159 currentIcon:SetGemColor(optimizedGems[i] and optimizedGems[i].color)
adam@0 160 optimizedIcon:SetGemColor(optimizedGems[i] and optimizedGems[i].color)
adam@0 161
adam@0 162 -- show the gem row
adam@0 163 text:Show()
adam@0 164 else
adam@0 165 -- hide the gem row
adam@0 166 text:Hide()
adam@0 167 optimizedIcon:Hide()
adam@0 168 currentIcon:Hide()
adam@0 169 end
adam@0 170 end
adam@0 171
adam@0 172 local y1 = 0
adam@0 173 local y2 = 0
adam@0 174 if gemCount == 1 then
adam@0 175 y1 = 27
adam@0 176 elseif gemCount == 2 then
adam@0 177 y1 = 9
adam@0 178 y2 = 4
adam@0 179 end
adam@0 180
adam@0 181 for i = 1, MAX_GEMS_PER_SLOT do
adam@0 182 self._optimizedGemText[i]:SetPoint("TOPLEFT", 200, 12 - (27 + y2) * i - y1)
adam@0 183 self._optimizedGemIcons[i]:SetPoint("TOPLEFT", 170, 18 - (27 + y2) * i - y1)
adam@0 184 self._currentGems[i]:SetPoint("TOPLEFT", 100, 18 - (27 + y2) * i - y1)
adam@0 185 end
adam@0 186 end