comparison SecureMenu.lua @ 5:cea9633a6d4e

Added some tooltips and text color
author contrebasse
date Sat, 02 Apr 2011 17:13:16 +0200
parents ed0582126cae
children b6a5902f376f
comparison
equal deleted inserted replaced
4:3a1997d21468 5:cea9633a6d4e
56 56
57 local numActiveEntries = 0 57 local numActiveEntries = 0
58 local menuEntries = {} 58 local menuEntries = {}
59 59
60 -- Button hovering 60 -- Button hovering
61 local function btnEntered(self) 61 local function btnEntered(btn)
62 --[[ 62 --[[
63 -- Index of the reagent in the recipe, taken from the button name 63 -- Index of the reagent in the recipe, taken from the button name
64 local reagentRecipeIndex = A.buttonNumber(self) 64 local reagentRecipeIndex = A.buttonNumber(btn)
65 65
66 -- ID of the reagent we want to craft 66 -- ID of the reagent we want to craft
67 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex)) 67 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex))
68 68
69 -- Continue only if the reagent is known 69 -- Continue only if the reagent is known
70 if not reagentID or not A.data[reagentID] then return end 70 if not reagentID or not A.data[reagentID] then return end
71 --]] 71 --]]
72 72
73 self.textureHighlight:Show() 73 if btn.numMakable>0 then
74 74 btn.textureHighlight:Show()
75 --[[ 75 end
76 if #(A.data[reagentID]) == 1 and not A.data[reagentID].spell then 76
77 local numMakable = A.numMakable(reagentID) 77 GameTooltip:SetOwner(btn,"ANCHOR_TOPLEFT")
78 self.itemName:SetText(numMakable) 78 GameTooltip:SetHyperlink(btn.reagentLink)
79 if numMakable==0 then 79 GameTooltip:Show()
80 self.itemName:SetTextColor(1, 0, 0, 1) 80 local link, tradeLink = GetSpellLink(btn.spellID)
81 else 81 A.tooltipRecipe:SetOwner(GameTooltip)
82 self.itemName:SetTextColor(0, 5, 0, 1) 82 A.tooltipRecipe:SetHyperlink(link)
83 end 83 A.tooltipRecipe:Show()
84 self.itemName:Show() 84 A.tooltipRecipe:ClearAllPoints()
85 end 85 A.tooltipRecipe:SetPoint("BOTTOMLEFT",GameTooltip,"BOTTOMRIGHT")
86 --]] 86 end
87 end 87 local function btnLeft(btn)
88 local function btnLeft(self) 88 btn.textureHighlight:Hide()
89 self.textureHighlight:Hide() 89 GameTooltip:Hide()
90 --self.itemName:Hide() 90 A.tooltipRecipe:Hide()
91 end 91 end
92 local function createMenuEntry() 92 local function createMenuEntry()
93 --local btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame, "SecureActionButtonTemplate")
94 local btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") 93 local btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate")
95 table.insert(menuEntries,btn) 94 table.insert(menuEntries,btn)
96 95
97 btn:Hide() 96 btn:Hide()
98 btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT) 97 btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT)
126 local textureHighlight = btn:CreateTexture(nil,"BORDER") 125 local textureHighlight = btn:CreateTexture(nil,"BORDER")
127 textureHighlight:Hide() 126 textureHighlight:Hide()
128 textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight") 127 textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight")
129 textureHighlight:SetBlendMode("ADD") 128 textureHighlight:SetBlendMode("ADD")
130 textureHighlight:SetAllPoints(icon) 129 textureHighlight:SetAllPoints(icon)
131 --textureHighlight:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT)
132 btn.textureHighlight = textureHighlight 130 btn.textureHighlight = textureHighlight
133 btn:HookScript("OnEnter", btnEntered)
134 btn:HookScript("OnLeave", btnLeft)
135
136 local countTotal = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal")
137 --countTotal:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT/2)
138 countTotal:SetPoint("TOPLEFT",icon,"TOPLEFT",1,-1)
139 countTotal:SetJustifyH("LEFT")
140 countTotal:SetJustifyV("TOP")
141 --countTotal:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
142 btn.countTotal = countTotal
143 131
144 local countDetail = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal") 132 local countDetail = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal")
145 --countDetail:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT/2)
146 countDetail:SetPoint("BOTTOMRIGHT",icon,"BOTTOMRIGHT",-1,1) 133 countDetail:SetPoint("BOTTOMRIGHT",icon,"BOTTOMRIGHT",-1,1)
147 countDetail:SetJustifyH("RIGHT") 134 countDetail:SetJustifyH("RIGHT")
148 countDetail:SetJustifyV("BOTTOM") 135 countDetail:SetJustifyV("BOTTOM")
149 --countDetail:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
150 btn.countDetail = countDetail 136 btn.countDetail = countDetail
137
138 btn:HookScript("OnEnter", btnEntered)
139 btn:HookScript("OnLeave", btnLeft)
140
151 return btn 141 return btn
152 end 142 end
153 143
154 144
155 local function menuCraftItem() 145 local function menuCraftItem()
161 for i=1,numActiveEntries do 151 for i=1,numActiveEntries do
162 btn = menuEntries[i] 152 btn = menuEntries[i]
163 local itemCount = GetItemCount(btn.reagentID) 153 local itemCount = GetItemCount(btn.reagentID)
164 154
165 local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) 155 local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1))
166 btn.countTotal:SetText(numMakable)
167 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) 156 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1))
168 157
169 if numMakable>0 then 158 if numMakable>0 then
170 anyMakable = true 159 anyMakable = true
171 btn.countTotal:SetTextColor(0, 5, 0, 1) 160 btn.countDetail:SetTextColor(1, 1, 1, 1)
172 btn:Enable()
173 --btn.icon:SetDesaturated(false)
174 btn.icon:SetVertexColor(1,1,1); 161 btn.icon:SetVertexColor(1,1,1);
175 btn.itemName:SetTextColor(1,1,1,1) 162 btn.itemName:SetTextColor(1,1,1,1)
176 else 163 else
177 btn.countTotal:SetTextColor(1, 0, 0, 1) 164 -- Do not disable the button, to be able to show the tooltip
178 btn:Disable() 165 btn.countDetail:SetTextColor(1, 0.1, 0.1, 1)
179 --btn.icon:SetDesaturated(true)
180 btn.icon:SetVertexColor(0.5, 0.5, 0.5) 166 btn.icon:SetVertexColor(0.5, 0.5, 0.5)
181 btn.itemName:SetTextColor(1,1,1,0.5) 167 btn.itemName:SetTextColor(1,1,1,0.5)
182 end 168 end
183 end 169
184 170 btn.numMakable = numMakable
171 end
172
173 local r,g,b = TitleText:GetTextColor()
185 if anyMakable then 174 if anyMakable then
186 itemIcon:SetVertexColor(1,1,1) 175 itemIcon:SetVertexColor(1,1,1)
187 TitleText:SetTextColor(1,1,1,1) 176 TitleText:SetTextColor(r,g,b,1)
188 else 177 else
189 itemIcon:SetVertexColor(0.5, 0.5, 0.5) 178 itemIcon:SetVertexColor(0.5, 0.5, 0.5)
190 TitleText:SetTextColor(1,1,1,0.5) 179 TitleText:SetTextColor(r,g,b,0.7)
191 end 180 end
192 end 181 end
193 182
194 local function menuAddItem(action,itemID,reagentID,reagentsForOneRecipe) 183 local function menuAddItem(action,itemID,reagentID,reagentsForOneRecipe,spellID)
195 local btn 184 local btn
196 -- Create a button only if necessary 185 -- Create a button only if necessary
197 if numActiveEntries >= #menuEntries then 186 if numActiveEntries >= #menuEntries then
198 btn = createMenuEntry() 187 btn = createMenuEntry()
199 else 188 else
204 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagentID) 193 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagentID)
205 if name then 194 if name then
206 btn.itemName:SetText(name) 195 btn.itemName:SetText(name)
207 else 196 else
208 A.DEBUG("No item name : "..reagentID) 197 A.DEBUG("No item name : "..reagentID)
198 return
209 end 199 end
210 200
211 if texture then 201 if texture then
212 btn.icon:SetTexture(texture) 202 btn.icon:SetTexture(texture)
213 else 203 else
214 A.DEBUG("No item texture : "..reagentID) 204 A.DEBUG("No item texture : "..reagentID)
205 return
215 end 206 end
216 207
217 -- Save params 208 -- Save params
218 btn.itemID = itemID 209 btn.itemID = itemID
219 btn.reagentID = reagentID 210 btn.reagentID = reagentID
211 btn.reagentLink = link
220 btn.reagentsForOneRecipe = reagentsForOneRecipe 212 btn.reagentsForOneRecipe = reagentsForOneRecipe
213 btn.spellID = spellID
221 214
222 -- Set action 215 -- Set action
223 if type(action)=="function" then 216 if type(action)=="function" then
224 btn:SetScript("PreClick",action) 217 btn:SetScript("PreClick",action)
225 btn:SetAttribute("type", nil) 218 btn:SetAttribute("type", nil)
226 btn:SetAttribute("spell", nil) 219 btn:SetAttribute("macrotext", nil)
227 btn:SetAttribute("target-item",nil)
228 else --if type(action)=="string" then 220 else --if type(action)=="string" then
229 btn:SetScript("PreClick",nil) 221 btn:SetScript("PreClick",nil)
230 btn:SetAttribute("type", "macro") 222 btn:SetAttribute("type", "macro")
231 btn:SetAttribute("macrotext", action..GetItemInfo(reagentID)) 223 btn:SetAttribute("macrotext", action..name)
232 --btn:SetAttribute("type", "macro")
233 --btn:SetAttribute("macrotext1","/cast Mouture\n/use Gangrelette")
234 end -- if 224 end -- if
235
236 -- Reposition MenuFrame
237 --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0)
238 --MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT)
239 225
240 btn:Show() 226 btn:Show()
241 227
242 -- Increase the entry number 228 -- Increase the entry number
243 numActiveEntries = numActiveEntries + 1 229 numActiveEntries = numActiveEntries + 1
260 246
261 -- Fill the info of the reagent to make 247 -- Fill the info of the reagent to make
262 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) 248 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID)
263 SetPortraitToTexture(itemIcon, texture) 249 SetPortraitToTexture(itemIcon, texture)
264 TitleText:SetText(name) 250 TitleText:SetText(name)
251 local color = ITEM_QUALITY_COLORS[quality]
252 TitleText:SetTextColor(color.r, color.g, color.b)
265 253
266 -- Loop over the available recipes 254 -- Loop over the available recipes
267 for _,reagent in ipairs(A.data[itemID]) do 255 for _,reagent in ipairs(A.data[itemID]) do
268 if A.data[itemID].spell then 256 if A.data[itemID].spell then
269 -- Special spell 257 -- Special spell
270 menuAddItem(A.data[itemID].spell,itemID,reagent[1],reagent[2]) 258 menuAddItem(A.data[itemID].spell,itemID,reagent[1],reagent[2],A.data[itemID].spellID)
271 else 259 else
272 -- Standard tradeskill spell UNTESTED 260 -- Standard tradeskill spell UNTESTED
273 menuAddItem(A.craft,itemID,reagent[1],reagent[2]) 261 menuAddItem(A.craft,itemID,reagent[1],reagent[2])
274 end -- if 262 end -- if
275 end -- for 263 end -- for