I use custom buttons for my quickhud addon, and the only problem is they still activate if they're clicked when they're behind a dframe.
[lua] if CursorPos( ScrW()-124, 1, 100, 17 ) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 255, 255, 255, 60 ) )
if (input.MousePress( MOUSE_LEFT )) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 0, 55, 195, 60 ) )[/lua]
[lua]function CursorPos(x,y,w,h) --used for un parented buttons (original function made by The Maw, variables differ from original)
local cpx,cpy = gui.MousePos()
if (cpx>x)and(cpx<x+w)and(cpy>y)and(cpy<y+h) then return true end
return false
end[/lua]
Is there any way to make it so, if it's behind a dframe, or any derma element, it won't activate the button?
You could check to see if the frame is in focus with an if statement.
[lua]if self:GetParent():HasFocus() then
//Do stuff here
end[/lua]
i don't really know how to use that, would it be like this:
[lua]
if self:GetParent():HasFocus() then
return false
else
if CursorPos( ScrW()-124, 1, 100, 17 ) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 255, 255, 255, 60 ) )
if (input.MousePress( MOUSE_LEFT )) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 0, 55, 195, 60 ) )
--code
end
end
end
[/lua]
?
more like this jova
[lua]
if !self:GetParent():HasFocus() then
if CursorPos( ScrW()-124, 1, 100, 17 ) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 255, 255, 255, 60 ) )
if (input.MousePress( MOUSE_LEFT )) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 0, 55, 195, 60 ) )
--code
end
end
end
[/lua]
or something similar, i would suggest not doing buttons that way though and just use panel:Paintover() and OnCursorEntered, OnCursorExited,
maybe this will help you out
[lua]
function Button(Name, X, Y, W, H, col, Parent)
local Bt = vgui.Create( "Button", Parent )
Bt:SetText( Name )
Bt:SetPos (X, Y )
Bt:SetSize( W, H )
Bt.Paint = function()
draw.RoundedBox(0,0,0,Bt:GetWide(),Bt:GetTall(),col)
end
return Bt
end
[/lua]
also in another file if you went like this
[lua]
clr = Color( 0, 0, 0, 255 )
local KillButton = Button( "Kill", 0, 0, 50, 20, clr, ParentFrame )
KillButton.OnCursorEntered = function() clr = Color( 255, 255, 255, 255 ) end
KillButton.OnCursorExited = function() clr = Color( 0, 0, 0, 255 ) end
[/lua]
etc...may not work perfectly as i did that in the reply box, but good luck, sorry i havent had much time to help lately
[b]Edited:[/b]
Also, a return jumps to the end of the function so you cant have return then else, it will just see the return false and end the function...i believe
[QUOTE=antid2;26675386]more like this jova
[lua]
if !self:GetParent():HasFocus() then
if CursorPos( ScrW()-124, 1, 100, 17 ) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 255, 255, 255, 60 ) )
if (input.MousePress( MOUSE_LEFT )) then
draw.RoundedBox( 0 , ScrW() - 124, 1, 100, 17, Color( 0, 55, 195, 60 ) )
--code
end
end
end
[/lua][/QUOTE]
That's what I was thinking too lol, and I was going to make a custom function for the button sooner or later, :P. Thanks for your help guys
[B]Hook 'Hud' Failed: [autorun\--.lua:204] attempt to index local 'self' (a nil value)[/B]
idk if i need self, but if i change it to pl i get:
[B]
Hook 'Hud' Failed: [autorun\--.lua:203] attempt to call method 'HasFocus' (a nil value)[/B]
I don't know what to do.
Sorry, you need to Log In to post a reply to this thread.