annotate ui/JewelPanel.lua @ 17:e77e01abce98

Warlords of Draenor pre-patch
author Adam tegen <adam.tegen@gmail.com>
date Mon, 13 Oct 2014 21:28:32 -0500
parents ec731d2fe6ba
children 4317e56e0a91
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@17 116 local optimizedGemId = 0
adam@17 117 if optimizedGems[i] > 0 then
adam@17 118 optimizedGemId = AskMrRobot.ExtraGemData[optimizedGems[i]].id
adam@17 119 end
adam@17 120 --local currentGemId = AskMrRobot.ExtraGemData[showGems[i]].id
adam@17 121
adam@0 122 -- set the current gem icon / tooltip
adam@0 123 currentIcon:SetItemLink(currentGemLink)
adam@0 124
adam@0 125 local currentGemId = AskMrRobot.getItemIdFromLink(currentGemLink)
adam@0 126
adam@0 127 local optimizedGemLink = nil
adam@0 128 if i <= #optimizedGems then
adam@0 129 -- make a link for the optimized gem
adam@17 130 optimizedGemLink = select(2, GetItemInfo(optimizedGemId))
adam@0 131
adam@17 132 if not optimizedGemLink and optimizedGemId and itemId then
adam@17 133 AskMrRobot.RegisterItemInfoCallback(optimizedGemId, function(name, link)
adam@0 134 optimizedIcon:SetItemLink(link)
adam@0 135 end)
adam@0 136 end
adam@0 137 end
adam@0 138
adam@17 139
adam@17 140 local mismatched = not AskMrRobot.AreGemsCompatible(optimizedGems[i], showGems[i])
adam@17 141
adam@17 142 --if showGems[i] and optimizedGems[i] and optimizedGems[i].color then
adam@17 143 --if test and optimizedGems[i] and optimizedGems[i].color then
adam@17 144 if mismatched and optimizedGems[i] > 0 then
adam@0 145 gemCount = gemCount + 1
adam@0 146 -- set the optimized gem text
adam@0 147 text:SetTextColor(1,1,1)
adam@17 148 --text:SetText(AskMrRobot.alternateGemName[optimizedGemId] or (optimizedGems[i] ~= 0 and AskMrRobot.getEnchantName(optimizedGems[i])) or GetItemInfo(optimizedGemId))
adam@17 149
adam@17 150 text:SetText(AskMrRobot.ExtraGemData[optimizedGems[i]].text)
adam@17 151
adam@0 152 currentIcon:Show()
adam@0 153
adam@0 154 -- load the item image / tooltip
adam@0 155 optimizedIcon:SetItemLink(optimizedGemLink)
adam@0 156 optimizedIcon:Show()
adam@0 157 optimizedIcon:SetBackdropBorderColor(1,1,1)
adam@0 158 currentIcon:SetBackdropBorderColor(1,1,1)
adam@0 159 else
adam@17 160 --if optimizedGems[i] and optimizedGems[i].color then
adam@17 161 if optimizedGems[i] then
adam@0 162 text:SetText("no change")
adam@0 163 text:SetTextColor(0.5,0.5,0.5)
adam@0 164 currentIcon:Show()
adam@0 165 gemCount = gemCount + 1
adam@0 166 else
adam@0 167 text:SetText('')
adam@0 168 currentIcon:Hide()
adam@0 169 end
adam@0 170 optimizedIcon:SetItemLink(nil)
adam@0 171 optimizedIcon:Hide()
adam@0 172 end
adam@0 173
adam@17 174 -- TODO highlight the socket color
adam@17 175 local socketColorId = AskMrRobot.ExtraItemData[itemId].socketColors[i]
adam@17 176 local socketName = AskMrRobot.socketColorIds[socketColorId];
adam@17 177 currentIcon:SetGemColor(optimizedGems[i] and socketName)
adam@17 178 optimizedIcon:SetGemColor(optimizedGems[i] and socketName)
adam@0 179
adam@0 180 -- show the gem row
adam@0 181 text:Show()
adam@0 182 else
adam@0 183 -- hide the gem row
adam@0 184 text:Hide()
adam@0 185 optimizedIcon:Hide()
adam@0 186 currentIcon:Hide()
adam@0 187 end
adam@0 188 end
adam@0 189
adam@0 190 local y1 = 0
adam@0 191 local y2 = 0
adam@0 192 if gemCount == 1 then
adam@0 193 y1 = 27
adam@0 194 elseif gemCount == 2 then
adam@0 195 y1 = 9
adam@0 196 y2 = 4
adam@0 197 end
adam@0 198
adam@0 199 for i = 1, MAX_GEMS_PER_SLOT do
adam@0 200 self._optimizedGemText[i]:SetPoint("TOPLEFT", 200, 12 - (27 + y2) * i - y1)
adam@0 201 self._optimizedGemIcons[i]:SetPoint("TOPLEFT", 170, 18 - (27 + y2) * i - y1)
adam@0 202 self._currentGems[i]:SetPoint("TOPLEFT", 100, 18 - (27 + y2) * i - y1)
adam@0 203 end
adam@0 204 end