comparison SecureMenu.lua @ 110:d60d6b4cab0c

Tradeskill in external window should now be functional
author contrebasse
date Thu, 02 Jun 2011 18:23:42 +0200
parents 618163a6d970
children af23986010ef
comparison
equal deleted inserted replaced
109:b5fd4a61ee64 110:d60d6b4cab0c
2 2
3 -- Create the menu frame 3 -- Create the menu frame
4 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) 4 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent)
5 MenuFrame:Hide() 5 MenuFrame:Hide()
6 MenuFrame:SetSize(192,256) 6 MenuFrame:SetSize(192,256)
7 MenuFrame:SetFrameStrata("DIALOG") 7 --MenuFrame:SetFrameStrata("DIALOG")
8 MenuFrame:EnableMouse(true) 8 MenuFrame:EnableMouse(true)
9 MenuFrame:SetPoint("CENTER") 9 MenuFrame:SetPoint("CENTER")
10 MenuFrame:SetToplevel(true) -- raised if clicked
10 tinsert(UISpecialFrames,"ReagentMaker_ExternalFrame") -- make it closable with escape 11 tinsert(UISpecialFrames,"ReagentMaker_ExternalFrame") -- make it closable with escape
11 12
12 local SCAN_DELAY = 0.2 13 local SCAN_DELAY = 0.2
13 local t_throttle = SCAN_DELAY 14 local t_throttle = SCAN_DELAY
14 function MenuFrame.throttleUpdateCounts(self, t_elapsed) 15 function MenuFrame.throttleUpdateCounts(self, t_elapsed)
135 local btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") 136 local btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate")
136 table.insert(menuEntries,btn) 137 table.insert(menuEntries,btn)
137 138
138 btn:Hide() 139 btn:Hide()
139 btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT) 140 btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT)
140 btn:SetFrameStrata("DIALOG") 141 --btn:SetFrameStrata("DIALOG")
141 142
142 -- Set its position 143 -- Set its position
143 if #menuEntries>1 then 144 if #menuEntries>1 then
144 btn:SetPoint("TOP",menuEntries[#menuEntries-1],"BOTTOM",0,-2) 145 btn:SetPoint("TOP",menuEntries[#menuEntries-1],"BOTTOM",0,-2)
145 else 146 else
165 btn.itemName = itemName 166 btn.itemName = itemName
166 167
167 local textureHighlight = btn:CreateTexture(nil,"BORDER") 168 local textureHighlight = btn:CreateTexture(nil,"BORDER")
168 textureHighlight:Hide() 169 textureHighlight:Hide()
169 textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight") 170 textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight")
171 --textureHighlight:SetTexture("Interface\\BUTTONS\\ButtonHilight-Square")
170 textureHighlight:SetBlendMode("ADD") 172 textureHighlight:SetBlendMode("ADD")
171 textureHighlight:SetAllPoints(icon) 173 textureHighlight:SetAllPoints(icon)
172 btn.textureHighlight = textureHighlight 174 btn.textureHighlight = textureHighlight
173 175
174 local countDetail = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal") 176 local countDetail = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal")
182 resultNumber:SetJustifyH("LEFT") 184 resultNumber:SetJustifyH("LEFT")
183 resultNumber:SetJustifyV("TOP") 185 resultNumber:SetJustifyV("TOP")
184 resultNumber:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE") 186 resultNumber:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
185 btn.resultNumber = resultNumber 187 btn.resultNumber = resultNumber
186 188
189 -- Used to choose the number of items to make
190 btn.SplitStack = A.SplitStack
191
187 btn:SetScript("OnEnter", btnEntered) 192 btn:SetScript("OnEnter", btnEntered)
188 btn:SetScript("OnLeave", btnLeft) 193 btn:SetScript("OnLeave", btnLeft)
189 194
190 return btn 195 return btn
191 end 196 end
196 else 201 else
197 A.Error(A.L["You do not have enough [%s] to craft [%s]"]:format(btn.itemNameString,TitleText:GetText())) 202 A.Error(A.L["You do not have enough [%s] to craft [%s]"]:format(btn.itemNameString,TitleText:GetText()))
198 end 203 end
199 end 204 end
200 205
206 local function CraftFromExternal(btn)
207 local chooseNumber = IsShiftKeyDown()
208 local numReagentMakable = A.numRecipeMakable(btn.reagentID,btn.reagentsForOneRecipe)
209 local reagentIndex = A.findExactSkillIndex(btn.itemID,btn.itemNameString)
210
211 -- to define
212 local numToMake = 1
213
214 -- Choose number or craft directly
215 if chooseNumber then
216 -- Store info to be able to run the function later
217 btn.ReagentMaker_reagentIndex = reagentIndex
218
219 -- Open dialog
220 OpenStackSplitFrame(numReagentMakable, btn, "BOTTOMRIGHT", "TOP")
221
222 -- Fill in the number to make
223 numToMake = tostring(numToMake)
224 for i = 1,numToMake:len() do
225 StackSplitFrame_OnChar(StackSplitFrame,numToMake:gsub(i,i))
226 end
227 StackSplitFrame.typing = 0 -- reinit the frame so that the entered value will be erased on text entry
228 else
229 DoTradeSkill(reagentIndex,numToMake)
230 end -- if
231 end
232
201 -- Update counts and button actions 233 -- Update counts and button actions
202 function MenuFrame.updateCounts() 234 function MenuFrame.updateCounts()
203 local anyMakable 235 local anyMakable
204 for i=1,numActiveEntries do 236 for i=1,numActiveEntries do
205 btn = menuEntries[i] 237 local btn = menuEntries[i]
206 local itemCount = GetItemCount(btn.reagentID) 238 local itemCount = GetItemCount(btn.reagentID)
207 239
208 local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) 240 local numMakable
209 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) 241 if btn.reagentID then
242 numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1))
243 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1))
244 else
245 for _,reagent in pairs(btn.reagentsForOneRecipe) do
246 itemCount = GetItemCount(reagent[1])
247 if not itemCount then
248 numMakable = 0
249 break
250 end
251 if not numMakable then
252 numMakable = math.floor(itemCount/reagent[2])
253 else
254 numMakable = math.min(numMakable,math.floor(itemCount/reagent[2]))
255 end
256 if numMakable==0 then break end
257 end
258 btn.countDetail:SetText(numMakable)
259 end
210 260
211 if numMakable>0 then 261 if numMakable>0 then
212 -- Set action 262 -- Set action
213 if type(btn.action)=="function" then 263 if type(btn.action)=="function" then
214 btn:SetScript("PreClick",btn.action) 264 btn:SetScript("PreClick",btn.action)
360 -- Special spell 410 -- Special spell
361 existsValidEntries = true 411 existsValidEntries = true
362 noSkipped = menuAddItem(reagent.macro,itemID,reagent) and noSkipped 412 noSkipped = menuAddItem(reagent.macro,itemID,reagent) and noSkipped
363 else 413 else
364 -- Standard tradeskill spell 414 -- Standard tradeskill spell
365 if not reagent.spellName or reagent.spellName == A.currentTradeSkill then 415 if not reagent.tradeskillName or reagent.tradeskillName == A.currentTradeSkill then
366 existsValidEntries = true 416 existsValidEntries = true
367 noSkipped = menuAddItem(A.craft,itemID,reagent) and noSkipped 417 noSkipped = menuAddItem(CraftFromExternal,itemID,reagent) and noSkipped
368 end 418 end
369 end -- if 419 end -- if
370 end -- for 420 end -- for
371 421
372 -- do not show an empty menu 422 -- do not show an empty menu