Everything is working fine except the cButton:DoClick() function. Any ideas?
[lua]
cButton = {};
function cButton:Init()
self.Text = "Click Me!"; -- For a button, we may as well have a different text.
end
function cButton:Paint()
surface.SetDrawColor( BtnBackground )
surface.DrawRect( 0, 0, btnWidth, btnHeight)
surface.SetDrawColor( foreground )
surface.DrawOutlinedRect( 0, 0, btnWidth, btnHeight )
surface.DrawOutlinedRect( 1, 1, btnWidth-2, btnHeight-2 )
surface.DrawOutlinedRect( 2, 2, btnWidth-4, btnHeight-4 )
-- This is where we do all the painting.
if ( self.TextAlign == 1 ) then
x = self:GetWide() / 2;
y = self:GetTall() / 4 - 1;
else
x = 0;
y = 0;
end
-- Arguments: Text, Font, X Pos, Y Pos, Color, Text Alignment
draw.DrawText( self.Text, self.Font, x, y, self.Color, self.TextAlign );
return true;
end
function cButton:OnCursorEntered(m)
--DButton:SetColor( textHoverColor )
surface.PlaySound( "/UI/buttonrollover.wav" )
end
function cButton:DoClick(m)
print("FML")
end
vgui.Register( "cButton", cButton, "cLabel" );
[/lua]
DoClick is not a base method and is only available to all panels that are derived from DLabel or its derivatives.
[URL]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dlabel.lua#L205[/URL]
[QUOTE=Robotboy655;45255863] snip ][/QUOTE]
Thanks once again Robotboy! Also how would I do this without overriding the cButtons OnCursorEntered function?
[lua]
button_spec = vgui.Create( "cButton", Frame )
function button_spec:OnCursorEntered()
-print("asdasa")
end
[/lua]
button_spec = vgui.Create( "cButton", Frame )
local old = button_spec.OnCursorEntered
function button_spec:OnCursorEntered()
old( self )
print("asdasa")
end
Your programming knowledge is off the charts, thanks again Robotboy!
Sorry, you need to Log In to post a reply to this thread.