Mercurial > wow > reagentmaker
comparison SecureMenu.lua @ 3:ed0582126cae
The base features semms to work.
| author | contrebasse |
|---|---|
| date | Sat, 02 Apr 2011 01:49:39 +0200 |
| parents | 04c5b817eead |
| children | cea9633a6d4e |
comparison
equal
deleted
inserted
replaced
| 2:04c5b817eead | 3:ed0582126cae |
|---|---|
| 1 local addonName, A = ... | 1 local addonName, A = ... |
| 2 | 2 |
| 3 -- Create the menu frame | 3 -- Create the menu frame |
| 4 local MenuFrame = CreateFrame("Frame",nil,UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name | 4 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name ? |
| 5 MenuFrame:Hide() | 5 MenuFrame:Hide() |
| 6 MenuFrame:SetBackdrop({ | 6 MenuFrame:SetSize(192,256) |
| 7 bgFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Background", -- path to the background texture | |
| 8 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border", -- path to the border texture | |
| 9 tile = true, -- true to repeat the background texture to fill the frame, false to scale it | |
| 10 tileSize = 32, -- size (width or height) of the square repeating background tiles (in pixels) | |
| 11 edgeSize = 32, -- thickness of edge segments and square size of edge corners (in pixels) | |
| 12 insets = { -- distance from the edges of the frame to those of the background texture (in pixels) | |
| 13 left = 11, | |
| 14 right = 12, | |
| 15 top = 12, | |
| 16 bottom = 11 | |
| 17 } | |
| 18 }) | |
| 19 MenuFrame:SetWidth(170) | |
| 20 MenuFrame:SetFrameStrata("DIALOG") | 7 MenuFrame:SetFrameStrata("DIALOG") |
| 21 | 8 MenuFrame:EnableMouse(true) |
| 22 local MENU_ENTRY_HEIGHT = 12 | 9 MenuFrame:SetPoint("CENTER") |
| 10 tinsert(UISpecialFrames,"ReagentMaker_ExternalFrame") -- make it closable with escape | |
| 11 | |
| 12 MenuFrame:SetScript("OnEvent",function(self,event,...) | |
| 13 if event == "TRADE_SKILL_CLOSE" or event == "PLAYER_REGEN_DISABLED" then | |
| 14 MenuFrame:Hide() | |
| 15 end | |
| 16 end) | |
| 17 MenuFrame:RegisterEvent("TRADE_SKILL_CLOSE") | |
| 18 MenuFrame:RegisterEvent("PLAYER_REGEN_ENABLED") | |
| 19 A.MenuFrame = MenuFrame | |
| 20 | |
| 21 -- Background adaptable vertically | |
| 22 local bg_top = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,0) | |
| 23 bg_top:SetTexture("Interface\\LootFrame\\UI-LootPanel") | |
| 24 bg_top:SetSize(192,80) | |
| 25 bg_top:SetPoint("TOP") | |
| 26 bg_top:SetTexCoord(0,192/256,0,80/256) | |
| 27 local bg_bot = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,0) | |
| 28 bg_bot:SetTexture("Interface\\LootFrame\\UI-LootPanel") | |
| 29 bg_bot:SetSize(192,16) | |
| 30 bg_bot:SetPoint("BOTTOM") | |
| 31 bg_bot:SetTexCoord(0,192/256,240/256,1) | |
| 32 local bg_mid = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,0) | |
| 33 bg_mid:SetTexture("Interface\\LootFrame\\UI-LootPanel") | |
| 34 bg_mid:SetWidth(192) | |
| 35 bg_mid:SetPoint("TOP",bg_top,"BOTTOM") | |
| 36 bg_mid:SetPoint("BOTTOM",bg_bot,"TOP") | |
| 37 bg_mid:SetTexCoord(0,192/256,80/256,240/256) | |
| 38 | |
| 39 -- Bouton de fermeture | |
| 40 local CloseButton = CreateFrame("Button",nil,MenuFrame,"UIPanelCloseButton"); | |
| 41 CloseButton:SetPoint("TOPRIGHT",0,-10) | |
| 42 | |
| 43 -- Main icon | |
| 44 local itemIcon = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,-1) | |
| 45 itemIcon:SetSize(64,64) | |
| 46 itemIcon:SetPoint("TOPLEFT",8,-4) | |
| 47 | |
| 48 -- Title | |
| 49 local TitleText = MenuFrame:CreateFontString(nil,"ARTWORK","GameFontHighlight") | |
| 50 TitleText:SetSize(92,14) | |
| 51 TitleText:SetPoint("RIGHT",CloseButton,"LEFT",4,1) | |
| 52 | |
| 53 local MENU_ENTRY_HEIGHT = 41 | |
| 54 local MENU_ENTRY_WIDTH = 147 | |
| 55 local MENU_ENTRY_ICON_RATIO = 40/48 | |
| 23 | 56 |
| 24 local numActiveEntries = 0 | 57 local numActiveEntries = 0 |
| 25 local menuEntries = {} | 58 local menuEntries = {} |
| 26 local parentBtn -- The button it's associated with | 59 |
| 27 | 60 -- Button hovering |
| 28 function A.menuIsOpen(btn) | 61 local function btnEntered(self) |
| 29 if btn then | 62 --[[ |
| 30 return MenuFrame:IsShown() and (btn==parentBtn) | 63 -- Index of the reagent in the recipe, taken from the button name |
| 31 else | 64 local reagentRecipeIndex = A.buttonNumber(self) |
| 32 return MenuFrame:IsShown() | 65 |
| 33 end | 66 -- ID of the reagent we want to craft |
| 34 end | 67 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex)) |
| 35 function A.menuOpen(parent) | 68 |
| 36 A.DEBUG("menuOpen") | 69 -- Continue only if the reagent is known |
| 37 --if not InCombatLockDown() and numActiveEntries>0 then | 70 if not reagentID or not A.data[reagentID] then return end |
| 38 parentBtn = parent | 71 --]] |
| 39 MenuFrame:ClearAllPoints() | 72 |
| 40 MenuFrame:SetPoint("LEFT",parent,"RIGHT",0,0) | 73 self.textureHighlight:Show() |
| 41 | 74 |
| 42 MenuFrame:SetHeight(240) | 75 --[[ |
| 43 --MenuFrame:SetParent(UIParent) | 76 if #(A.data[reagentID]) == 1 and not A.data[reagentID].spell then |
| 44 | 77 local numMakable = A.numMakable(reagentID) |
| 45 MenuFrame:Show() | 78 self.itemName:SetText(numMakable) |
| 46 --end | 79 if numMakable==0 then |
| 47 end | 80 self.itemName:SetTextColor(1, 0, 0, 1) |
| 48 function A.menuClose() | 81 else |
| 49 MenuFrame:Hide() | 82 self.itemName:SetTextColor(0, 5, 0, 1) |
| 50 MenuFrame:ClearAllPoints() | 83 end |
| 51 | 84 self.itemName:Show() |
| 52 parentBtn = nil | 85 end |
| 86 --]] | |
| 87 end | |
| 88 local function btnLeft(self) | |
| 89 self.textureHighlight:Hide() | |
| 90 --self.itemName:Hide() | |
| 91 end | |
| 92 local function createMenuEntry() | |
| 93 --local btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame, "SecureActionButtonTemplate") | |
| 94 local btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") | |
| 95 table.insert(menuEntries,btn) | |
| 96 | |
| 97 btn:Hide() | |
| 98 btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT) | |
| 99 btn:SetFrameStrata("DIALOG") | |
| 100 | |
| 101 -- Set its position | |
| 102 if #menuEntries>1 then | |
| 103 btn:SetPoint("TOP",menuEntries[#menuEntries-1],"BOTTOM",0,-2) | |
| 104 else | |
| 105 btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",24,-79) | |
| 106 end | |
| 107 | |
| 108 local icon = btn:CreateTexture(nil,"BACKGROUND") | |
| 109 icon:SetPoint("TOPLEFT") | |
| 110 icon:SetSize(39,39) | |
| 111 btn.icon = icon | |
| 112 | |
| 113 local itemNameBG = btn:CreateTexture(nil,"BACKGROUND") | |
| 114 itemNameBG:SetTexture("Interface\\QuestFrame\\UI-QuestItemNameFrame") | |
| 115 itemNameBG:SetSize(128,64) | |
| 116 itemNameBG:SetPoint("LEFT",icon,"RIGHT",-10,0) | |
| 117 | |
| 118 local itemName = btn:CreateFontString(nil,"BACKGROUND","GameFontHighlight") | |
| 119 itemName:SetSize(90,36) | |
| 120 itemName:SetPoint("LEFT",itemNameBG,"LEFT",15,0) | |
| 121 itemName:SetJustifyH("LEFT") | |
| 122 itemName:SetWordWrap(true) | |
| 123 itemName:SetNonSpaceWrap(false) | |
| 124 btn.itemName = itemName | |
| 125 | |
| 126 local textureHighlight = btn:CreateTexture(nil,"BORDER") | |
| 127 textureHighlight:Hide() | |
| 128 textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight") | |
| 129 textureHighlight:SetBlendMode("ADD") | |
| 130 textureHighlight:SetAllPoints(icon) | |
| 131 --textureHighlight:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT) | |
| 132 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 | |
| 144 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) | |
| 147 countDetail:SetJustifyH("RIGHT") | |
| 148 countDetail:SetJustifyV("BOTTOM") | |
| 149 --countDetail:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE") | |
| 150 btn.countDetail = countDetail | |
| 151 return btn | |
| 152 end | |
| 153 | |
| 154 | |
| 155 local function menuCraftItem() | |
| 156 action(itemID,reagentIndex,IsShiftKeyDown()) | |
| 157 end | |
| 158 | |
| 159 local function updateCounts() | |
| 160 local anyMakable | |
| 53 for i=1,numActiveEntries do | 161 for i=1,numActiveEntries do |
| 54 menuEntries[i]:Hide() | 162 btn = menuEntries[i] |
| 55 end | 163 local itemCount = GetItemCount(btn.reagentID) |
| 56 end | 164 |
| 57 | 165 local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) |
| 58 function A.menuAddItem(text,action,itemID) | 166 btn.countTotal:SetText(numMakable) |
| 59 A.DEBUG("menuAddItem "..text) | 167 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) |
| 168 | |
| 169 if numMakable>0 then | |
| 170 anyMakable = true | |
| 171 btn.countTotal:SetTextColor(0, 5, 0, 1) | |
| 172 btn:Enable() | |
| 173 --btn.icon:SetDesaturated(false) | |
| 174 btn.icon:SetVertexColor(1,1,1); | |
| 175 btn.itemName:SetTextColor(1,1,1,1) | |
| 176 else | |
| 177 btn.countTotal:SetTextColor(1, 0, 0, 1) | |
| 178 btn:Disable() | |
| 179 --btn.icon:SetDesaturated(true) | |
| 180 btn.icon:SetVertexColor(0.5, 0.5, 0.5) | |
| 181 btn.itemName:SetTextColor(1,1,1,0.5) | |
| 182 end | |
| 183 end | |
| 184 | |
| 185 if anyMakable then | |
| 186 itemIcon:SetVertexColor(1,1,1) | |
| 187 TitleText:SetTextColor(1,1,1,1) | |
| 188 else | |
| 189 itemIcon:SetVertexColor(0.5, 0.5, 0.5) | |
| 190 TitleText:SetTextColor(1,1,1,0.5) | |
| 191 end | |
| 192 end | |
| 193 | |
| 194 local function menuAddItem(action,itemID,reagentID,reagentsForOneRecipe) | |
| 60 local btn | 195 local btn |
| 61 -- Create a button only if necessary | 196 -- Create a button only if necessary |
| 62 if numActiveEntries >= #menuEntries then | 197 if numActiveEntries >= #menuEntries then |
| 63 btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame) --, "SecureActionButtonTemplate") | 198 btn = createMenuEntry() |
| 64 table.insert(menuEntries,btn) | |
| 65 | |
| 66 btn:SetHeight(MENU_ENTRY_HEIGHT) | |
| 67 btn:SetWidth(160) | |
| 68 | |
| 69 -- Set its position | |
| 70 if #menuEntries==0 then | |
| 71 btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) | |
| 72 else | |
| 73 btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) | |
| 74 end | |
| 75 else | 199 else |
| 76 btn = menuEntries[numActiveEntries+1] | 200 btn = menuEntries[numActiveEntries+1] |
| 77 end | 201 end |
| 78 | 202 |
| 79 -- Set its text | 203 -- Set text and icon |
| 80 btn:SetText(text or "???") | 204 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagentID) |
| 81 | 205 if name then |
| 82 -- Set its action | 206 btn.itemName:SetText(name) |
| 207 else | |
| 208 A.DEBUG("No item name : "..reagentID) | |
| 209 end | |
| 210 | |
| 211 if texture then | |
| 212 btn.icon:SetTexture(texture) | |
| 213 else | |
| 214 A.DEBUG("No item texture : "..reagentID) | |
| 215 end | |
| 216 | |
| 217 -- Save params | |
| 218 btn.itemID = itemID | |
| 219 btn.reagentID = reagentID | |
| 220 btn.reagentsForOneRecipe = reagentsForOneRecipe | |
| 221 | |
| 222 -- Set action | |
| 83 if type(action)=="function" then | 223 if type(action)=="function" then |
| 84 btn:SetScript("OnClick",action) | 224 btn:SetScript("PreClick",action) |
| 85 btn:SetAttribute("type", nil) | 225 btn:SetAttribute("type", nil) |
| 86 btn:SetAttribute("spell", nil) | 226 btn:SetAttribute("spell", nil) |
| 87 btn:SetAttribute("target-item",itemID) | 227 btn:SetAttribute("target-item",nil) |
| 88 elseif type(action)=="string" then | 228 else --if type(action)=="string" then |
| 89 btn:SetScript("OnClick",nil) | 229 btn:SetScript("PreClick",nil) |
| 90 btn:SetAttribute("type", "spell") | 230 btn:SetAttribute("type", "macro") |
| 91 btn:SetAttribute("spell", action) | 231 btn:SetAttribute("macrotext", action..GetItemInfo(reagentID)) |
| 92 btn:SetAttribute("target-item",GetItemInfo(itemID)) | 232 --btn:SetAttribute("type", "macro") |
| 233 --btn:SetAttribute("macrotext1","/cast Mouture\n/use Gangrelette") | |
| 93 end -- if | 234 end -- if |
| 94 | 235 |
| 95 -- Reposition MenuFrame | 236 -- Reposition MenuFrame |
| 96 --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) | 237 --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) |
| 97 MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) | 238 --MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) |
| 239 | |
| 240 btn:Show() | |
| 98 | 241 |
| 99 -- Increase the entry number | 242 -- Increase the entry number |
| 100 numActiveEntries = numActiveEntries + 1 | 243 numActiveEntries = numActiveEntries + 1 |
| 101 A.DEBUG("Item added ") | |
| 102 end -- function | 244 end -- function |
| 245 | |
| 246 -- Fill the window and open it | |
| 247 function A.externalCraftWindow(itemID) | |
| 248 -- Do not open during combat | |
| 249 if InCombatLockdown() then return end | |
| 250 | |
| 251 -- Save the tradeskill | |
| 252 A.currentTradeSkill = GetTradeSkillLine() | |
| 253 | |
| 254 -- Close the previous menu | |
| 255 MenuFrame:Hide() | |
| 256 for i=1,numActiveEntries do | |
| 257 menuEntries[i]:Hide() | |
| 258 end | |
| 259 numActiveEntries = 0 | |
| 260 | |
| 261 -- Fill the info of the reagent to make | |
| 262 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) | |
| 263 SetPortraitToTexture(itemIcon, texture) | |
| 264 TitleText:SetText(name) | |
| 265 | |
| 266 -- Loop over the available recipes | |
| 267 for _,reagent in ipairs(A.data[itemID]) do | |
| 268 if A.data[itemID].spell then | |
| 269 -- Special spell | |
| 270 menuAddItem(A.data[itemID].spell,itemID,reagent[1],reagent[2]) | |
| 271 else | |
| 272 -- Standard tradeskill spell UNTESTED | |
| 273 menuAddItem(A.craft,itemID,reagent[1],reagent[2]) | |
| 274 end -- if | |
| 275 end -- for | |
| 276 | |
| 277 MenuFrame:SetHeight(89 + numActiveEntries*(MENU_ENTRY_HEIGHT+2)) | |
| 278 | |
| 279 MenuFrame:ClearAllPoints() | |
| 280 MenuFrame:SetPoint("TOPLEFT",TradeSkillFrame,"TOPRIGHT",-2,14) | |
| 281 | |
| 282 updateCounts() | |
| 283 | |
| 284 MenuFrame:Show() | |
| 285 end |
