Mercurial > wow > reagentmaker
diff 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 |
line wrap: on
line diff
--- a/SecureMenu.lua Tue Mar 29 22:06:36 2011 +0200 +++ b/SecureMenu.lua Sat Apr 02 01:49:39 2011 +0200 @@ -1,102 +1,285 @@ local addonName, A = ... -- Create the menu frame -local MenuFrame = CreateFrame("Frame",nil,UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name +local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name ? MenuFrame:Hide() -MenuFrame:SetBackdrop({ - bgFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Background", -- path to the background texture - edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border", -- path to the border texture - tile = true, -- true to repeat the background texture to fill the frame, false to scale it - tileSize = 32, -- size (width or height) of the square repeating background tiles (in pixels) - edgeSize = 32, -- thickness of edge segments and square size of edge corners (in pixels) - insets = { -- distance from the edges of the frame to those of the background texture (in pixels) - left = 11, - right = 12, - top = 12, - bottom = 11 - } -}) -MenuFrame:SetWidth(170) +MenuFrame:SetSize(192,256) MenuFrame:SetFrameStrata("DIALOG") +MenuFrame:EnableMouse(true) +MenuFrame:SetPoint("CENTER") +tinsert(UISpecialFrames,"ReagentMaker_ExternalFrame") -- make it closable with escape -local MENU_ENTRY_HEIGHT = 12 +MenuFrame:SetScript("OnEvent",function(self,event,...) + if event == "TRADE_SKILL_CLOSE" or event == "PLAYER_REGEN_DISABLED" then + MenuFrame:Hide() + end +end) +MenuFrame:RegisterEvent("TRADE_SKILL_CLOSE") +MenuFrame:RegisterEvent("PLAYER_REGEN_ENABLED") +A.MenuFrame = MenuFrame + +-- Background adaptable vertically +local bg_top = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,0) +bg_top:SetTexture("Interface\\LootFrame\\UI-LootPanel") +bg_top:SetSize(192,80) +bg_top:SetPoint("TOP") +bg_top:SetTexCoord(0,192/256,0,80/256) +local bg_bot = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,0) +bg_bot:SetTexture("Interface\\LootFrame\\UI-LootPanel") +bg_bot:SetSize(192,16) +bg_bot:SetPoint("BOTTOM") +bg_bot:SetTexCoord(0,192/256,240/256,1) +local bg_mid = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,0) +bg_mid:SetTexture("Interface\\LootFrame\\UI-LootPanel") +bg_mid:SetWidth(192) +bg_mid:SetPoint("TOP",bg_top,"BOTTOM") +bg_mid:SetPoint("BOTTOM",bg_bot,"TOP") +bg_mid:SetTexCoord(0,192/256,80/256,240/256) + +-- Bouton de fermeture +local CloseButton = CreateFrame("Button",nil,MenuFrame,"UIPanelCloseButton"); +CloseButton:SetPoint("TOPRIGHT",0,-10) + +-- Main icon +local itemIcon = MenuFrame:CreateTexture(nil,"BACKGROUND",nil,-1) +itemIcon:SetSize(64,64) +itemIcon:SetPoint("TOPLEFT",8,-4) + +-- Title +local TitleText = MenuFrame:CreateFontString(nil,"ARTWORK","GameFontHighlight") +TitleText:SetSize(92,14) +TitleText:SetPoint("RIGHT",CloseButton,"LEFT",4,1) + +local MENU_ENTRY_HEIGHT = 41 +local MENU_ENTRY_WIDTH = 147 +local MENU_ENTRY_ICON_RATIO = 40/48 local numActiveEntries = 0 local menuEntries = {} -local parentBtn -- The button it's associated with -function A.menuIsOpen(btn) - if btn then - return MenuFrame:IsShown() and (btn==parentBtn) +-- Button hovering +local function btnEntered(self) + --[[ + -- Index of the reagent in the recipe, taken from the button name + local reagentRecipeIndex = A.buttonNumber(self) + + -- ID of the reagent we want to craft + local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex)) + + -- Continue only if the reagent is known + if not reagentID or not A.data[reagentID] then return end + --]] + + self.textureHighlight:Show() + + --[[ + if #(A.data[reagentID]) == 1 and not A.data[reagentID].spell then + local numMakable = A.numMakable(reagentID) + self.itemName:SetText(numMakable) + if numMakable==0 then + self.itemName:SetTextColor(1, 0, 0, 1) + else + self.itemName:SetTextColor(0, 5, 0, 1) + end + self.itemName:Show() + end + --]] +end +local function btnLeft(self) + self.textureHighlight:Hide() + --self.itemName:Hide() +end +local function createMenuEntry() + --local btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame, "SecureActionButtonTemplate") + local btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") + table.insert(menuEntries,btn) + + btn:Hide() + btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT) + btn:SetFrameStrata("DIALOG") + + -- Set its position + if #menuEntries>1 then + btn:SetPoint("TOP",menuEntries[#menuEntries-1],"BOTTOM",0,-2) else - return MenuFrame:IsShown() + btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",24,-79) end + + local icon = btn:CreateTexture(nil,"BACKGROUND") + icon:SetPoint("TOPLEFT") + icon:SetSize(39,39) + btn.icon = icon + + local itemNameBG = btn:CreateTexture(nil,"BACKGROUND") + itemNameBG:SetTexture("Interface\\QuestFrame\\UI-QuestItemNameFrame") + itemNameBG:SetSize(128,64) + itemNameBG:SetPoint("LEFT",icon,"RIGHT",-10,0) + + local itemName = btn:CreateFontString(nil,"BACKGROUND","GameFontHighlight") + itemName:SetSize(90,36) + itemName:SetPoint("LEFT",itemNameBG,"LEFT",15,0) + itemName:SetJustifyH("LEFT") + itemName:SetWordWrap(true) + itemName:SetNonSpaceWrap(false) + btn.itemName = itemName + + local textureHighlight = btn:CreateTexture(nil,"BORDER") + textureHighlight:Hide() + textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight") + textureHighlight:SetBlendMode("ADD") + textureHighlight:SetAllPoints(icon) + --textureHighlight:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT) + btn.textureHighlight = textureHighlight + btn:HookScript("OnEnter", btnEntered) + btn:HookScript("OnLeave", btnLeft) + + local countTotal = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal") + --countTotal:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT/2) + countTotal:SetPoint("TOPLEFT",icon,"TOPLEFT",1,-1) + countTotal:SetJustifyH("LEFT") + countTotal:SetJustifyV("TOP") + --countTotal:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE") + btn.countTotal = countTotal + + local countDetail = btn:CreateFontString(nil,"ARTWORK","NumberFontNormal") + --countDetail:SetSize(MENU_ENTRY_HEIGHT,MENU_ENTRY_HEIGHT/2) + countDetail:SetPoint("BOTTOMRIGHT",icon,"BOTTOMRIGHT",-1,1) + countDetail:SetJustifyH("RIGHT") + countDetail:SetJustifyV("BOTTOM") + --countDetail:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE") + btn.countDetail = countDetail + return btn end -function A.menuOpen(parent) - A.DEBUG("menuOpen") - --if not InCombatLockDown() and numActiveEntries>0 then - parentBtn = parent - MenuFrame:ClearAllPoints() - MenuFrame:SetPoint("LEFT",parent,"RIGHT",0,0) - MenuFrame:SetHeight(240) - --MenuFrame:SetParent(UIParent) - MenuFrame:Show() - --end +local function menuCraftItem() + action(itemID,reagentIndex,IsShiftKeyDown()) end -function A.menuClose() - MenuFrame:Hide() - MenuFrame:ClearAllPoints() - parentBtn = nil +local function updateCounts() + local anyMakable for i=1,numActiveEntries do - menuEntries[i]:Hide() + btn = menuEntries[i] + local itemCount = GetItemCount(btn.reagentID) + + local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) + btn.countTotal:SetText(numMakable) + btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) + + if numMakable>0 then + anyMakable = true + btn.countTotal:SetTextColor(0, 5, 0, 1) + btn:Enable() + --btn.icon:SetDesaturated(false) + btn.icon:SetVertexColor(1,1,1); + btn.itemName:SetTextColor(1,1,1,1) + else + btn.countTotal:SetTextColor(1, 0, 0, 1) + btn:Disable() + --btn.icon:SetDesaturated(true) + btn.icon:SetVertexColor(0.5, 0.5, 0.5) + btn.itemName:SetTextColor(1,1,1,0.5) + end + end + + if anyMakable then + itemIcon:SetVertexColor(1,1,1) + TitleText:SetTextColor(1,1,1,1) + else + itemIcon:SetVertexColor(0.5, 0.5, 0.5) + TitleText:SetTextColor(1,1,1,0.5) end end -function A.menuAddItem(text,action,itemID) - A.DEBUG("menuAddItem "..text) +local function menuAddItem(action,itemID,reagentID,reagentsForOneRecipe) local btn -- Create a button only if necessary if numActiveEntries >= #menuEntries then - btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame) --, "SecureActionButtonTemplate") - table.insert(menuEntries,btn) - - btn:SetHeight(MENU_ENTRY_HEIGHT) - btn:SetWidth(160) - - -- Set its position - if #menuEntries==0 then - btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) - else - btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) - end + btn = createMenuEntry() else btn = menuEntries[numActiveEntries+1] end - -- Set its text - btn:SetText(text or "???") + -- Set text and icon + local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagentID) + if name then + btn.itemName:SetText(name) + else + A.DEBUG("No item name : "..reagentID) + end - -- Set its action + if texture then + btn.icon:SetTexture(texture) + else + A.DEBUG("No item texture : "..reagentID) + end + + -- Save params + btn.itemID = itemID + btn.reagentID = reagentID + btn.reagentsForOneRecipe = reagentsForOneRecipe + + -- Set action if type(action)=="function" then - btn:SetScript("OnClick",action) + btn:SetScript("PreClick",action) btn:SetAttribute("type", nil) btn:SetAttribute("spell", nil) - btn:SetAttribute("target-item",itemID) - elseif type(action)=="string" then - btn:SetScript("OnClick",nil) - btn:SetAttribute("type", "spell") - btn:SetAttribute("spell", action) - btn:SetAttribute("target-item",GetItemInfo(itemID)) + btn:SetAttribute("target-item",nil) + else --if type(action)=="string" then + btn:SetScript("PreClick",nil) + btn:SetAttribute("type", "macro") + btn:SetAttribute("macrotext", action..GetItemInfo(reagentID)) + --btn:SetAttribute("type", "macro") + --btn:SetAttribute("macrotext1","/cast Mouture\n/use Gangrelette") end -- if -- Reposition MenuFrame --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) - MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) + --MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) + + btn:Show() -- Increase the entry number numActiveEntries = numActiveEntries + 1 - A.DEBUG("Item added ") end -- function + +-- Fill the window and open it +function A.externalCraftWindow(itemID) + -- Do not open during combat + if InCombatLockdown() then return end + + -- Save the tradeskill + A.currentTradeSkill = GetTradeSkillLine() + + -- Close the previous menu + MenuFrame:Hide() + for i=1,numActiveEntries do + menuEntries[i]:Hide() + end + numActiveEntries = 0 + + -- Fill the info of the reagent to make + local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) + SetPortraitToTexture(itemIcon, texture) + TitleText:SetText(name) + + -- Loop over the available recipes + for _,reagent in ipairs(A.data[itemID]) do + if A.data[itemID].spell then + -- Special spell + menuAddItem(A.data[itemID].spell,itemID,reagent[1],reagent[2]) + else + -- Standard tradeskill spell UNTESTED + menuAddItem(A.craft,itemID,reagent[1],reagent[2]) + end -- if + end -- for + + MenuFrame:SetHeight(89 + numActiveEntries*(MENU_ENTRY_HEIGHT+2)) + + MenuFrame:ClearAllPoints() + MenuFrame:SetPoint("TOPLEFT",TradeSkillFrame,"TOPRIGHT",-2,14) + + updateCounts() + + MenuFrame:Show() +end