Thread: OnLeave & Frame
View Single Post
01-05-17, 12:22 AM   #4
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Hi,
thanks really so much for the reply and explanation on the differences from : and .

I have tried to implement your suggestion but I have a problem ...
Since I left click in the Data Broker to make the menu appears and it works until I hover the frame but when I touch the buttons it breaks :/

Probably the buttons are not checked as whole frame ?

Here is a gif (in loop) showing the thing:
http://s23.postimg.org/bw238gnjv/test_menu.gif

Surely is a problem of my code because I am really not so skilled in the frame management.
I post the full thing:

Lua Code:
  1. local ADDON = ...
  2.  
  3. local ActiveSpec = GetSpecialization()
  4. local ACTSPEC = {}
  5.  
  6. local fontName, fontHeight, fontFlags = GameFontNormal:GetFont()
  7. local btn = {}
  8.  
  9. local num_lines = 9
  10. local btn_o = 5
  11. local btn_h = fontHeight + 4
  12. local line_v = - btn_h
  13. local line_o = btn_o + 4
  14. local frame_w = 190
  15. local frame_h = abs(num_lines * line_v) + 10
  16. local btn_w = frame_w - btn_o - 2
  17. local line_o2 = frame_w/2
  18.  
  19. local string_format = string.format
  20.  
  21. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  22. local dataobj = ldb:NewDataObject(ADDON, {
  23.     type = "data source",
  24.     icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp",
  25.     text = "None"
  26. })
  27.  
  28. local Menu = CreateFrame('Frame', nil, UIParent)
  29. Menu:SetClampedToScreen(true)
  30. Menu:SetSize(frame_w,frame_h)
  31. Menu:Hide()
  32. Menu:SetScript('OnLeave', Menu.Hide)
  33. Menu:SetBackdrop({
  34.     bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
  35.     edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  36.     tile = true, tileSize = 32, edgeSize = 16,
  37.     insets = { left = 5, right = 5, top = 5, bottom = 5 }
  38. })
  39.  
  40. local talent_desc = Menu:CreateFontString("talent_desc")
  41. talent_desc:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o, line_v)
  42. talent_desc:SetFont(fontName, fontHeight)
  43. talent_desc:SetTextColor(1,0.8,0,1)
  44. talent_desc:SetText("Spec config: ")
  45.  
  46. local talent_value = Menu:CreateFontString("talent_value")
  47. talent_value:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o2, line_v)
  48. talent_value:SetFont(fontName, fontHeight)
  49. talent_value:SetTextColor(0,1,0,1)
  50.  
  51. local lclick_desc = Menu:CreateFontString("lclick_desc")
  52. lclick_desc:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o, 7*line_v)
  53. lclick_desc:SetFont(fontName, fontHeight)
  54. lclick_desc:SetTextColor(1,0.8,0,1)
  55. lclick_desc:SetText("Left Click: ")
  56.  
  57. local lclick_value = Menu:CreateFontString("lclick_value")
  58. lclick_value:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o2, 7*line_v)
  59. lclick_value:SetFont(fontName, fontHeight)
  60. lclick_value:SetTextColor(0,1,0,1)
  61. lclick_value:SetText("Change Spec")
  62.  
  63. local rclick_desc = Menu:CreateFontString("rclick_desc")
  64. rclick_desc:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o, 8*line_v)
  65. rclick_desc:SetFont(fontName, fontHeight)
  66. rclick_desc:SetTextColor(1,0.8,0,1)
  67. rclick_desc:SetText("Right Click: ")
  68.  
  69. local rclick_value = Menu:CreateFontString("rclick_value")
  70. rclick_value:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o2, 8*line_v)
  71. rclick_value:SetFont(fontName, fontHeight)
  72. rclick_value:SetTextColor(0,1,0,1)
  73. rclick_value:SetText("Open Talents")
  74.  
  75.  
  76. local function BuildActiveSpec()
  77.  
  78.     local ptalenttree = {}
  79.  
  80.     local ActiveSpec = GetSpecialization()
  81.     if ActiveSpec then
  82.         local id, name, description, icon, background, role = GetSpecializationInfo(ActiveSpec)
  83.         ACTSPEC = { id = id, name = name, description = description, icon = icon , background = background, role = role }
  84.     end
  85.  
  86.     for i=1, GetMaxTalentTier()  do
  87.        for j=1, 3 do
  88.             if select(4, GetTalentInfo(i,j,1)) == true then
  89.                 ptalenttree[i] = j
  90.             end
  91.        end
  92.     end
  93.  
  94.     ACTSPEC["tree"] = table.concat(ptalenttree,".")
  95. end
  96.  
  97. local function UpdateLDB()
  98.         local currentSpec = GetSpecialization()
  99.         if currentSpec ~= nil then     
  100.             local id, name, description, icon, background, role = GetSpecializationInfo(currentSpec)       
  101.             dataobj.text = name
  102.             dataobj.icon = icon    
  103.         else
  104.             dataobj.icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp"
  105.             dataobj.text = "None"
  106.         end
  107. end
  108.  
  109.  
  110. local function BuildMenu()
  111.  
  112.     for index=1,GetNumSpecializations() do
  113.  
  114.         local id, name, description, icon, background, role = GetSpecializationInfo(index)
  115.        
  116.         btn[index]=CreateFrame("Button", nil, Menu)
  117.         btn[index]:SetPoint("TOP", btn_o, -20 + (index * line_v))
  118.         btn[index]:SetWidth(btn_w)
  119.         btn[index]:SetHeight(btn_h)
  120.         btn[index]:SetNormalFontObject("GameFontNormal")
  121.         btn[index]:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
  122.            
  123.         local text = btn[index]:CreateFontString(ADDON .. "btn_font", nil, "GameFontNormal")
  124.         text:SetAllPoints(true)
  125.         text:SetJustifyH("LEFT")
  126.         text:SetJustifyV("MIDDLE")
  127.         text:SetTextColor(1,1,1,1)
  128.         btn[index]:SetFontString(text);
  129.         btn[index]:SetText(string.format("|T%s:0|t %s",icon,name))
  130.         btn[index]:SetScript("OnClick",  
  131.         function()
  132.             Menu:Hide()
  133.             SetSpecialization(index)
  134.         end)
  135.     end
  136. end
  137.  
  138. local frame = CreateFrame("Frame")
  139. frame:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
  140. frame:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
  141. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  142. frame:SetScript("OnEvent", function(self, event, ...)
  143.  
  144.     BuildActiveSpec()
  145.     UpdateLDB()
  146.        
  147.     if event == "PLAYER_ENTERING_WORLD" then
  148.         BuildMenu()
  149.     end
  150. end
  151. )
  152.  
  153.  
  154. function dataobj.OnClick(self, button)  
  155.  
  156.     if InCombatLockdown() then
  157.         return
  158.     end
  159.  
  160.     if button == "RightButton" then
  161.         ToggleTalentFrame()
  162.     end
  163.  
  164.     if button == "LeftButton" then
  165.  
  166.         if(Menu:IsShown()) then        
  167.    
  168.             Menu:Hide()
  169.  
  170.         else
  171.                    
  172.             talent_value:SetText(ACTSPEC["tree"])
  173.            
  174.             -- position code taken from Broker_Equipment by p3lim
  175.             Menu:ClearAllPoints()
  176.             Menu:SetPoint('TOP', self, 'BOTTOM') -- temporary anchor
  177.  
  178.             local sideAnchor = ''
  179.             if(Menu:GetRight() > GetScreenWidth()) then
  180.                 sideAnchor = 'RIGHT'
  181.             elseif(Menu:GetLeft() <= 0) then
  182.                 sideAnchor = 'LEFT'
  183.             end
  184.  
  185.             Menu:ClearAllPoints()
  186.             if(Menu:GetBottom() <= 0) then
  187.                 Menu:SetPoint('BOTTOM' .. sideAnchor, self, 'TOP' .. sideAnchor)
  188.             else
  189.                 Menu:SetPoint('TOP' .. sideAnchor, self, 'BOTTOM' .. sideAnchor)
  190.             end        
  191.            
  192.             Menu:Show()
  193.         end    
  194.     end
  195. end

Thanks all.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote