01-04-17, 06:43 PM | #1 |
OnLeave & Frame
Hi,
I was rewriting one of my addons trying to implement a custom frame instead of the standard LDB. Everything works just fine but I was wondering if it is possible to use an onLeave codition to close it. The skeleton code is something like this (shorter than the full code): Lua Code:
I thought a simple: Lua Code:
was ok to hide the frame when not hovering on it, but I was wrong So now I ask: Is there a simple way to accomplish this and prevent the fact the frame remains open until someone clicks the bar again ? Thanks very much for your input. P.s. Actually the Tooltip is this:
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot. |
|
01-04-17, 07:25 PM | #2 |
Menu:SetScript('OnLeave', Menu.Hide)
|
|
01-04-17, 08:45 PM | #3 | |
Why this works and what it does:
You're setting the frame handler to be the :Hide() metamethod. As this isn't a function call, just passing a function pointer, it loses the internal self argument. Frames just happen to push themselves as the first argument to their handlers, so everything works out anyway.
__________________
WoWInterface AddOns
|
||
01-05-17, 12:22 AM | #4 |
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:
Thanks all.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot. |
|
01-07-17, 04:41 AM | #5 | |
From what I can tell, Menu is firing OnLeave you mouseover the spec buttons. You might want to have a custom handler check for that before hiding itself. You're also recreating them at every loading screen instead of just at login. You should either unregister PLAYER_ENTERING_WORLD when done or use PLAYER_LOGIN instead.
__________________
WoWInterface AddOns
|
||
01-07-17, 11:02 AM | #6 | ||
About the second part of the problems I have changed in this way (I realized that it should be broken because sometime the buttons fonts were mangled). I used a mix of your tips using event "PLAYER_LOGIN" and then unregister once fired. Lua Code:
This works but is so ugly ? Lua Code:
The problem is when I hovering the buttons the "name" var is something like: table:00000149a7cf46e0 or if I exit from the frame values I get are: WorldFrame ChocolateBar1 etc etc ... Thanks anyway for your suggestions.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot. |
|||
01-07-17, 02:40 PM | #7 |
Here is a modified version of your code with the OnLeave script fixed. I also changed it to behave and look more like other LDB plugins I've seen.
Code:
local ADDON = ... local fontName, fontHeight, fontFlags = GameFontNormal:GetFont() local BUTTON_HEIGHT = fontHeight + 4 local BUTTON_SPACING = 0 local MENU_BUFFER = 10 local MENU_SPACING = 1 local MENU_WIDTH = 190 local Menu = CreateFrame('Frame', nil, UIParent) Menu:SetFrameStrata('TOOLTIP') Menu:SetClampedToScreen(true) Menu:SetBackdrop({ bgFile = "Interface/DialogFrame/UI-DialogBox-Background", edgeFile = "Interface/Tooltips/UI-Tooltip-Border", tile = true, tileSize = 32, edgeSize = 16, insets = { left = 5, right = 5, top = 5, bottom = 5 } }) Menu:Hide() local function Menu_OnLeave() local focus = GetMouseFocus() or WorldFrame if focus ~= Menu and focus:GetParent() ~= Menu then Menu:Hide() end end Menu:SetScript('OnLeave', Menu_OnLeave) local talent_desc = Menu:CreateFontString() talent_desc:SetPoint("TOPLEFT", Menu, "TOPLEFT", MENU_BUFFER, -MENU_BUFFER) talent_desc:SetFont(fontName, fontHeight) talent_desc:SetTextColor(1, 1, 1, 1) talent_desc:SetText("Spec config:") local talent_value = Menu:CreateFontString() talent_value:SetPoint("TOPRIGHT", Menu, "TOPRIGHT", -MENU_BUFFER, -MENU_BUFFER) talent_value:SetFont(fontName, fontHeight) talent_value:SetTextColor(1, 1, 1, 1) local rclick_desc = Menu:CreateFontString() rclick_desc:SetPoint("BOTTOMLEFT", Menu, "BOTTOMLEFT", MENU_BUFFER, MENU_BUFFER) rclick_desc:SetFont(fontName, fontHeight) rclick_desc:SetTextColor(0, 1, 0, 1) rclick_desc:SetText("Right-Click") local rclick_value = Menu:CreateFontString() rclick_value:SetPoint("BOTTOMRIGHT", Menu, "BOTTOMRIGHT", -MENU_BUFFER, MENU_BUFFER) rclick_value:SetFont(fontName, fontHeight) rclick_value:SetTextColor(1, 0.8, 0, 1) rclick_value:SetText("Toggle Talents") local lclick_desc = Menu:CreateFontString() lclick_desc:SetPoint("BOTTOMLEFT", rclick_desc, "TOPLEFT", 0, MENU_SPACING) lclick_desc:SetFont(fontName, fontHeight) lclick_desc:SetTextColor(0, 1, 0, 1) lclick_desc:SetText("Left-Click") local lclick_value = Menu:CreateFontString() lclick_value:SetPoint("BOTTOMRIGHT", rclick_value, "TOPRIGHT", 0, MENU_SPACING) lclick_value:SetFont(fontName, fontHeight) lclick_value:SetTextColor(1, 0.8, 0, 1) lclick_value:SetText("Toggle Menu") local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(ADDON, { type = "data source", icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp", text = "None", OnClick = function(self, button) if button == "LeftButton" then Menu:SetShown(not Menu:IsShown()) elseif button == "RightButton" then ToggleTalentFrame() end end, OnEnter = function(self) if not Menu:IsShown() then local _, selfCenter = self:GetCenter() local _, uiCenter = UIParent:GetCenter() Menu:ClearAllPoints() if selfCenter >= uiCenter then Menu:SetPoint('TOP', self, 'BOTTOM') else Menu:SetPoint('BOTTOM', self, 'TOP') end Menu:Show() end end, OnLeave = Menu_OnLeave }) local function EventHandler() local activeSpec = GetSpecialization() if activeSpec then local id, name, description, icon = GetSpecializationInfo(activeSpec) dataobj.text = name dataobj.icon = icon else dataobj.icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp" dataobj.text = "None" end local talents = "" for tier = 1, GetMaxTalentTier() do local talentTier = "x" for column = 1, 3 do local talentID, name, texture, selected = GetTalentInfo(tier, column, 1) if selected then talentTier = column break end end if talents ~= "" then talents = talents .. "." .. talentTier else talents = talentTier end end talent_value:SetText(talents) end local function Button_OnClick(self) Menu:Hide() if not InCombatLockdown() and GetSpecialization() ~= self.index then SetSpecialization(self.index) end end Menu:RegisterEvent('PLAYER_LOGIN') Menu:SetScript('OnEvent', function(self, event) Menu:UnregisterEvent(event) Menu:SetScript('OnEvent', EventHandler) local numButtons = GetNumSpecializations() for index = 1, numButtons do local id, name, description, icon, background, role = GetSpecializationInfo(index) local button = CreateFrame("Button", nil, Menu) if index ~= 1 then button:SetPoint("TOPLEFT", Menu[index - 1], "BOTTOMLEFT", 0, -BUTTON_SPACING) else button:SetPoint("TOPLEFT", talent_desc, "BOTTOMLEFT", 0, -MENU_BUFFER) end button:SetPoint("RIGHT", -MENU_BUFFER, 0) button:SetHeight(BUTTON_HEIGHT) button:SetNormalFontObject("GameFontNormal") button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") button.index = index button:SetScript("OnClick", Button_OnClick) button:SetScript("OnLeave", Menu_OnLeave) Menu[index] = button local text = button:CreateFontString(ADDON .. "btn_font", nil, "GameFontNormal") text:SetAllPoints() text:SetJustifyH("LEFT") text:SetJustifyV("MIDDLE") text:SetTextColor(1, 1, 1, 1) button:SetFontString(text) button:SetText(("|T%s:0|t %s"):format(icon, name)) end Menu:SetSize(MENU_WIDTH, (MENU_BUFFER * 4) + (fontHeight * 3) + MENU_SPACING + ((BUTTON_HEIGHT + BUTTON_SPACING) * numButtons - BUTTON_SPACING)) EventHandler() Menu:RegisterEvent('PLAYER_ENTERING_WORLD') Menu:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED') Menu:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED') end) |
|
01-07-17, 05:25 PM | #8 |
Thanks Vrul,
your code is awesome and work like a charm I am studying it Thanks again. It is much appreciated.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot. |
|
WoWInterface » Developer Discussions » Lua/XML Help » OnLeave & Frame |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|