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