mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-16 21:33:46 +03:00
Upload
This commit is contained in:
57
lua/vgui/dmenuoptioncvar.lua
Normal file
57
lua/vgui/dmenuoptioncvar.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
DEFINE_BASECLASS( "DMenuOption" )
|
||||
|
||||
AccessorFunc( PANEL, "m_strConVar", "ConVar" )
|
||||
AccessorFunc( PANEL, "m_strValueOn", "ValueOn" )
|
||||
AccessorFunc( PANEL, "m_strValueOff", "ValueOff" )
|
||||
|
||||
function PANEL:Init()
|
||||
|
||||
self:SetChecked( false )
|
||||
self:SetIsCheckable( true )
|
||||
|
||||
self:SetValueOn( "1" )
|
||||
self:SetValueOff( "0" )
|
||||
self._NextThink = 0
|
||||
|
||||
end
|
||||
|
||||
function PANEL:Think()
|
||||
|
||||
if ( !self.m_strConVar ) then return end
|
||||
if ( self._NextThink > RealTime() ) then return end
|
||||
|
||||
local strValue = GetConVarString( self.m_strConVar )
|
||||
|
||||
self:SetChecked( strValue == self.m_strValueOn )
|
||||
|
||||
end
|
||||
|
||||
function PANEL:OnChecked( b )
|
||||
|
||||
if ( !self.m_strConVar ) then return end
|
||||
|
||||
-- Give time for the cvar to update
|
||||
self._NextThink = RealTime() + 0.1
|
||||
|
||||
if ( b ) then
|
||||
RunConsoleCommand( self.m_strConVar, self.m_strValueOn )
|
||||
else
|
||||
RunConsoleCommand( self.m_strConVar, self.m_strValueOff )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
derma.DefineControl( "DMenuOptionCVar", "", PANEL, "DMenuOption" )
|
||||
Reference in New Issue
Block a user