This commit is contained in:
lifestorm
2024-08-04 22:55:00 +03:00
parent 0e770b2b49
commit 94063e4369
7342 changed files with 1718932 additions and 14 deletions

255
lua/derma/derma.lua Normal file
View File

@@ -0,0 +1,255 @@
--[[
| 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 table = table
local vgui = vgui
local Msg = Msg
local setmetatable = setmetatable
local _G = _G
local gamemode = gamemode
local pairs = pairs
local isfunction = isfunction
module( "derma" )
Controls = {}
SkinList = {}
local DefaultSkin = {}
local SkinMetaTable = {}
local iSkinChangeIndex = 1
SkinMetaTable.__index = function ( self, key )
return DefaultSkin[ key ]
end
local function FindPanelsByClass( SeekingClass )
local outtbl = {}
--
-- Going through the registry is a hacky way to do this.
-- We're only doing it this way because it doesn't matter if it's a
-- bit slow - because this function is only used when reloading.
--
local tbl = vgui.GetAll()
for k, v in pairs( tbl ) do
if ( v.ClassName && v.ClassName == SeekingClass ) then
table.insert( outtbl, v )
end
end
return outtbl
end
--
-- Find all the panels that use this class and
-- if allowed replace the functions with the new ones.
--
local function ReloadClass( classname )
local ctrl = vgui.GetControlTable( classname )
if ( !ctrl ) then return end
local tbl = FindPanelsByClass( classname )
for k, v in pairs ( tbl ) do
if ( !v.AllowAutoRefresh ) then continue end
if ( v.PreAutoRefresh ) then
v:PreAutoRefresh()
end
for name, func in pairs( ctrl ) do
if ( !isfunction( func ) ) then continue end
v[ name ] = func
end
if ( v.PostAutoRefresh ) then
v:PostAutoRefresh()
end
end
end
--[[---------------------------------------------------------
GetControlList
-----------------------------------------------------------]]
function GetControlList()
return Controls
end
--[[---------------------------------------------------------
DefineControl
-----------------------------------------------------------]]
function DefineControl( strName, strDescription, strTable, strBase )
local bReloading = Controls[ strName ] != nil
-- Add Derma table to PANEL table.
strTable.Derma = {
ClassName = strName,
Description = strDescription,
BaseClass = strBase
}
-- Register control with VGUI
vgui.Register( strName, strTable, strBase )
-- Store control
Controls[ strName ] = strTable.Derma
-- Store as a global so controls can 'baseclass' easier
-- TODO: STOP THIS
_G[ strName ] = strTable
if ( bReloading ) then
Msg( "Reloaded Control: ", strName, "\n" )
ReloadClass( strName )
end
return strTable
end
--[[---------------------------------------------------------
DefineSkin
-----------------------------------------------------------]]
function DefineSkin( strName, strDescription, strTable )
strTable.Name = strName
strTable.Description = strDescription
strTable.Base = strTable.Base or "Default"
if ( strName != "Default" ) then
setmetatable( strTable, SkinMetaTable )
else
DefaultSkin = strTable
end
SkinList[ strName ] = strTable
-- Make all panels update their skin
RefreshSkins()
end
--[[---------------------------------------------------------
GetSkin - Returns current skin for panel
-----------------------------------------------------------]]
function GetSkinTable()
return table.Copy( SkinList )
end
--[[---------------------------------------------------------
Returns 'Default' Skin
-----------------------------------------------------------]]
function GetDefaultSkin()
local skin = nil
-- Check gamemode skin preference
if ( gamemode ) then
local skinname = gamemode.Call( "ForceDermaSkin" )
if ( skinname ) then skin = GetNamedSkin( skinname ) end
end
-- default
if ( !skin ) then skin = DefaultSkin end
return skin
end
--[[---------------------------------------------------------
Returns 'Named' Skin
-----------------------------------------------------------]]
function GetNamedSkin( name )
return SkinList[ name ]
end
--[[---------------------------------------------------------
SkinHook( strType, strName, panel )
-----------------------------------------------------------]]
function SkinHook( strType, strName, panel, w, h )
local Skin = panel:GetSkin()
if ( !Skin ) then return end
local func = Skin[ strType .. strName ]
if ( !func ) then return end
return func( Skin, panel, w, h )
end
--[[---------------------------------------------------------
SkinTexture( strName, panel, default )
-----------------------------------------------------------]]
function SkinTexture( strName, panel, default )
local Skin = panel:GetSkin()
if ( !Skin ) then return default end
local Textures = Skin.tex
if ( !Textures ) then return default end
return Textures[ strName ] or default
end
--[[---------------------------------------------------------
Color( strName, panel, default )
-----------------------------------------------------------]]
function Color( strName, panel, default )
local Skin = panel:GetSkin()
if ( !Skin ) then return default end
return Skin[ strName ] or default
end
--[[---------------------------------------------------------
SkinChangeIndex
-----------------------------------------------------------]]
function SkinChangeIndex()
return iSkinChangeIndex
end
--[[---------------------------------------------------------
RefreshSkins - clears all cache'd panels (so they will reassess which skin they should be using)
-----------------------------------------------------------]]
function RefreshSkins()
iSkinChangeIndex = iSkinChangeIndex + 1
end

View File

@@ -0,0 +1,80 @@
--[[
| 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 DermaAnimation = {}
DermaAnimation.__index = DermaAnimation
function DermaAnimation:Run()
if ( !self.Running ) then return end
local time = SysTime()
local delta = ( time - self.StartTime ) / self.Length
delta = delta ^ ( 1.0 - ( delta - 0.5 ) )
-- If we have ended we run once more with the Finished member set
-- This allows us to clean up in the same function..
if ( time > self.EndTime ) then
self.Finished = true
self.Running = nil
delta = 1
end
self.Func( self.Panel, self, delta, self.Data )
self.Started = nil
end
function DermaAnimation:Start( Length, Data )
if ( self.Length == 0 ) then return end
self.Running = true
self.Started = true
self.Finished = nil
self.Length = Length
self.StartTime = SysTime()
self.EndTime = SysTime() + Length
self.Data = Data
end
function DermaAnimation:Stop()
if ( !self.Running ) then return end
self.Finished = true
self.Running = nil
end
function DermaAnimation:Active()
return self.Running
end
function Derma_Anim( name, panel, func )
local anim = {}
anim.Name = name
anim.Panel = panel
anim.Func = func
setmetatable( anim, DermaAnimation )
return anim
end

View File

@@ -0,0 +1,68 @@
--[[
| 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 = {}
function PANEL:Init()
self:SetTitle( "Derma Initiative Control Test" )
self.ContentPanel = vgui.Create( "DPropertySheet", self )
self.ContentPanel:Dock( FILL )
self:InvalidateLayout( true )
local w, h = self:GetSize()
local Controls = table.Copy( derma.GetControlList() )
for key, ctrl in SortedPairs( Controls ) do
local Ctrls = _G[ key ]
if ( Ctrls && Ctrls.GenerateExample ) then
Ctrls:GenerateExample( key, self.ContentPanel, w, h )
end
end
self:SetSize( 600, 450 )
end
function PANEL:SwitchTo( name )
self.ContentPanel:SwitchToName( name )
end
local vguiExampleWindow = vgui.RegisterTable( PANEL, "DFrame" )
--
-- This is all to open the actual window via concommand
--
local DermaExample = nil
local DermaControlsSuffix = ""
if ( MENU_DLL ) then -- Not all controls are available in menu state
DermaControlsSuffix = "_menu"
end
concommand.Add( "derma_controls" .. DermaControlsSuffix, function( player, command, arguments, args )
if ( IsValid( DermaExample ) ) then
DermaExample:Remove()
return end
DermaExample = vgui.CreateFromTable( vguiExampleWindow )
DermaExample:SwitchTo( args )
DermaExample:MakePopup()
DermaExample:Center()
end, nil, "", { FCVAR_DONTRECORD } )

232
lua/derma/derma_gwen.lua Normal file
View File

@@ -0,0 +1,232 @@
--[[
| 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 meta = FindMetaTable( "Panel" )
GWEN = {}
function GWEN.CreateTextureBorder( _xo, _yo, _wo, _ho, l, t, r, b, material_override )
local mat = SKIN && SKIN.GwenTexture || material_override
if ( material_override && !material_override:IsError() ) then mat = material_override end
return function( x, y, w, h, col )
local tex = mat:GetTexture( "$basetexture" )
local _x = _xo / tex:Width()
local _y = _yo / tex:Height()
local _w = _wo / tex:Width()
local _h = _ho / tex:Height()
surface.SetMaterial( mat )
if ( col ) then
surface.SetDrawColor( col )
else
surface.SetDrawColor( 255, 255, 255, 255 )
end
local left = math.min( l, math.ceil( w / 2 ) )
local right = math.min( r, math.floor( w / 2 ) )
local top = math.min( t, math.ceil( h / 2 ) )
local bottom = math.min( b, math.floor( h / 2 ) )
local _l = left / tex:Width()
local _t = top / tex:Height()
local _r = right / tex:Width()
local _b = bottom / tex:Height()
-- top
surface.DrawTexturedRectUV( x, y, left, top, _x, _y, _x + _l, _y + _t )
surface.DrawTexturedRectUV( x + left, y, w - left - right, top, _x + _l, _y, _x + _w - _r, _y + _t )
surface.DrawTexturedRectUV( x + w - right, y, right, top, _x + _w - _r, _y, _x + _w, _y + _t )
-- middle
surface.DrawTexturedRectUV( x, y + top, left, h - top - bottom, _x, _y + _t, _x + _l, _y + _h - _b )
surface.DrawTexturedRectUV( x + left, y + top, w - left - right, h - top - bottom, _x + _l, _y + _t, _x + _w - _r, _y + _h - _b )
surface.DrawTexturedRectUV( x + w - right, y + top, right, h - top - bottom, _x + _w - _r, _y + _t, _x + _w, _y + _h - _b )
-- bottom
surface.DrawTexturedRectUV( x, y + h - bottom, left, bottom, _x, _y + _h - _b, _x + _l, _y + _h )
surface.DrawTexturedRectUV( x + left, y + h - bottom, w - left - right, bottom, _x + _l, _y + _h - _b, _x + _w - _r, _y + _h )
surface.DrawTexturedRectUV( x + w - right, y + h - bottom, right, bottom, _x + _w - _r, _y + _h - _b, _x + _w, _y + _h )
end
end
function GWEN.CreateTextureNormal( _xo, _yo, _wo, _ho, material_override )
local mat = SKIN && SKIN.GwenTexture || material_override
if ( material_override && !material_override:IsError() ) then mat = material_override end
return function( x, y, w, h, col )
local tex = mat:GetTexture( "$basetexture" )
local _x = _xo / tex:Width()
local _y = _yo / tex:Height()
local _w = _wo / tex:Width()
local _h = _ho / tex:Height()
surface.SetMaterial( mat )
if ( col ) then
surface.SetDrawColor( col )
else
surface.SetDrawColor( 255, 255, 255, 255 )
end
surface.DrawTexturedRectUV( x, y, w, h, _x, _y, _x + _w, _y + _h )
end
end
function GWEN.CreateTextureCentered( _xo, _yo, _wo, _ho, material_override )
local mat = SKIN && SKIN.GwenTexture || material_override
if ( material_override && !material_override:IsError() ) then mat = material_override end
return function( x, y, w, h, col )
local tex = mat:GetTexture( "$basetexture" )
local _x = _xo / tex:Width()
local _y = _yo / tex:Height()
local _w = _wo / tex:Width()
local _h = _ho / tex:Height()
x = x + ( w - _wo ) * 0.5
y = y + ( h - _ho ) * 0.5
w = _wo
h = _ho
surface.SetMaterial( mat )
if ( col ) then
surface.SetDrawColor( col )
else
surface.SetDrawColor( 255, 255, 255, 255 )
end
surface.DrawTexturedRectUV( x, y, w, h, _x, _y, _x + _w, _y + _h )
end
end
function GWEN.TextureColor( x, y, material_override )
local mat = SKIN && SKIN.GwenTexture || material_override
if ( material_override && !material_override:IsError() ) then mat = material_override end
return mat:GetColor( x, y )
end
--
-- Loads a .gwen file (created by GWEN Designer)
-- TODO: Cache - but check for file changes?
--
function meta:LoadGWENFile( filename, path )
local contents = file.Read( filename, path || "GAME" )
if ( !contents ) then return end
self:LoadGWENString( contents )
end
--
-- Load from String
--
function meta:LoadGWENString( str )
local tbl = util.JSONToTable( str )
if ( !tbl ) then return end
if ( !tbl.Controls ) then return end
self:ApplyGWEN( tbl.Controls )
end
--
-- Convert GWEN types into Derma Types
--
local GwenTypes = {
Base = "Panel",
Button = "DButton",
Label = "DLabel",
TextBox = "DTextEntry",
TextBoxMultiline = "DTextEntry",
ComboBox = "DComboBox",
HorizontalSlider = "Slider",
ImagePanel = "DImage",
CheckBoxWithLabel = "DCheckBoxLabel"
}
--
-- Apply a GWEN table to the control (should contain Properties and (optionally) Children subtables)
--
function meta:ApplyGWEN( tbl )
if ( tbl.Type == "TextBoxMultiline" ) then self:SetMultiline( true ) end
for k, v in pairs( tbl.Properties ) do
if ( self[ "GWEN_Set" .. k ] ) then
self[ "GWEN_Set" .. k ]( self, v )
end
end
if ( !tbl.Children ) then return end
for k, v in pairs( tbl.Children ) do
local type = GwenTypes[ v.Type ]
if ( type ) then
local pnl = self:Add( type )
pnl:ApplyGWEN( v )
else
MsgN( "Warning: No GWEN Panel Type ", v.Type )
end
end
end
--
-- SET properties
--
function meta:GWEN_SetPosition( tbl ) self:SetPos( tbl.x, tbl.y ) end
function meta:GWEN_SetSize( tbl ) self:SetSize( tbl.w, tbl.h ) end
function meta:GWEN_SetText( tbl ) self:SetText( tbl ) end
function meta:GWEN_SetControlName( tbl ) self:SetName( tbl ) end
function meta:GWEN_SetMargin( tbl ) self:DockMargin( tbl.left, tbl.top, tbl.right, tbl.bottom ) end
function meta:GWEN_SetMin( min ) self:SetMin( tonumber( min ) ) end
function meta:GWEN_SetMax( max ) self:SetMax( tonumber( max ) ) end
function meta:GWEN_SetHorizontalAlign( txt )
if ( txt == "Right" ) then self:SetContentAlignment( 6 ) end
if ( txt == "Center" ) then self:SetContentAlignment( 5 ) end
if ( txt == "Left" ) then self:SetContentAlignment( 4 ) end
end
function meta:GWEN_SetDock( tbl )
if ( tbl == "Right" ) then self:Dock( RIGHT ) end
if ( tbl == "Left" ) then self:Dock( LEFT ) end
if ( tbl == "Bottom" ) then self:Dock( BOTTOM ) end
if ( tbl == "Top" ) then self:Dock( TOP ) end
if ( tbl == "Fill" ) then self:Dock( FILL ) end
end
function meta:GWEN_SetCheckboxText( tbl ) self:SetText( tbl ) end

69
lua/derma/derma_menus.lua Normal file
View File

@@ -0,0 +1,69 @@
--[[
| 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 tblOpenMenus = {}
function RegisterDermaMenuForClose( dmenu )
table.insert( tblOpenMenus, dmenu )
end
function DermaMenu( parentmenu, parent )
if ( !parentmenu ) then CloseDermaMenus() end
local dmenu = vgui.Create( "DMenu", parent )
return dmenu
end
function CloseDermaMenus()
for k, dmenu in pairs( tblOpenMenus ) do
if ( IsValid( dmenu ) ) then
dmenu:SetVisible( false )
if ( dmenu:GetDeleteSelf() ) then
dmenu:Remove()
end
end
end
tblOpenMenus = {}
hook.Run( "CloseDermaMenus" )
end
--
-- Here we detect when the mouse is pressed on another panel
-- This allows us to close the menus.
--
local function DermaDetectMenuFocus( panel, mousecode )
if ( IsValid( panel ) ) then
if ( panel.m_bIsMenuComponent ) then return end
-- Is the parent a menu?
return DermaDetectMenuFocus( panel:GetParent(), mousecode )
end
CloseDermaMenus()
end
hook.Add( "VGUIMousePressed", "DermaDetectMenuFocus", DermaDetectMenuFocus )

274
lua/derma/derma_utils.lua Normal file
View File

@@ -0,0 +1,274 @@
--[[
| 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 matBlurScreen = Material( "pp/blurscreen" )
--[[
This is designed for Paint functions..
--]]
function Derma_DrawBackgroundBlur( panel, starttime )
local Fraction = 1
if ( starttime ) then
Fraction = math.Clamp( ( SysTime() - starttime ) / 1, 0, 1 )
end
local x, y = panel:LocalToScreen( 0, 0 )
local wasEnabled = DisableClipping( true )
-- Menu cannot do blur
if ( !MENU_DLL ) then
surface.SetMaterial( matBlurScreen )
surface.SetDrawColor( 255, 255, 255, 255 )
for i = 0.33, 1, 0.33 do
matBlurScreen:SetFloat( "$blur", Fraction * 5 * i )
matBlurScreen:Recompute()
if ( render ) then render.UpdateScreenEffectTexture() end -- Todo: Make this available to menu Lua
surface.DrawTexturedRect( x * -1, y * -1, ScrW(), ScrH() )
end
end
surface.SetDrawColor( 10, 10, 10, 200 * Fraction )
surface.DrawRect( x * -1, y * -1, ScrW(), ScrH() )
DisableClipping( wasEnabled )
end
--[[
Display a simple message box.
Derma_Message( "Hey Some Text Here!!!", "Message Title (Optional)", "Button Text (Optional)" )
--]]
function Derma_Message( strText, strTitle, strButtonText )
local Window = vgui.Create( "DFrame" )
Window:SetTitle( strTitle or "Message" )
Window:SetDraggable( false )
Window:ShowCloseButton( false )
Window:SetBackgroundBlur( true )
Window:SetDrawOnTop( true )
local InnerPanel = vgui.Create( "Panel", Window )
local Text = vgui.Create( "DLabel", InnerPanel )
Text:SetText( strText or "Message Text" )
Text:SizeToContents()
Text:SetContentAlignment( 5 )
Text:SetTextColor( color_white )
local ButtonPanel = vgui.Create( "DPanel", Window )
ButtonPanel:SetTall( 30 )
ButtonPanel:SetPaintBackground( false )
local Button = vgui.Create( "DButton", ButtonPanel )
Button:SetText( strButtonText or "OK" )
Button:SizeToContents()
Button:SetTall( 20 )
Button:SetWide( Button:GetWide() + 20 )
Button:SetPos( 5, 5 )
Button.DoClick = function() Window:Close() end
ButtonPanel:SetWide( Button:GetWide() + 10 )
local w, h = Text:GetSize()
Window:SetSize( w + 50, h + 25 + 45 + 10 )
Window:Center()
InnerPanel:StretchToParent( 5, 25, 5, 45 )
Text:StretchToParent( 5, 5, 5, 5 )
ButtonPanel:CenterHorizontal()
ButtonPanel:AlignBottom( 8 )
Window:MakePopup()
Window:DoModal()
return Window
end
--[[
Ask a question with multiple answers..
Derma_Query( "Would you like me to punch you right in the face?", "Question!",
"Yesss", function() MsgN( "Pressed YES!") end,
"Nope!", function() MsgN( "Pressed Nope!") end,
"Cancel", function() MsgN( "Cancelled!") end )
--]]
function Derma_Query( strText, strTitle, ... )
local Window = vgui.Create( "DFrame" )
Window:SetTitle( strTitle or "Message Title (First Parameter)" )
Window:SetDraggable( false )
Window:ShowCloseButton( false )
Window:SetBackgroundBlur( true )
Window:SetDrawOnTop( true )
local InnerPanel = vgui.Create( "DPanel", Window )
InnerPanel:SetPaintBackground( false )
local Text = vgui.Create( "DLabel", InnerPanel )
Text:SetText( strText or "Message Text (Second Parameter)" )
Text:SizeToContents()
Text:SetContentAlignment( 5 )
Text:SetTextColor( color_white )
local ButtonPanel = vgui.Create( "DPanel", Window )
ButtonPanel:SetTall( 30 )
ButtonPanel:SetPaintBackground( false )
-- Loop through all the options and create buttons for them.
local NumOptions = 0
local x = 5
for k = 1, 8, 2 do
local txt = select( k, ... )
if ( txt == nil ) then break end
local Func = select( k + 1, ... ) or function() end
local Button = vgui.Create( "DButton", ButtonPanel )
Button:SetText( txt )
Button:SizeToContents()
Button:SetTall( 20 )
Button:SetWide( Button:GetWide() + 20 )
Button.DoClick = function() Window:Close() Func() end
Button:SetPos( x, 5 )
x = x + Button:GetWide() + 5
ButtonPanel:SetWide( x )
NumOptions = NumOptions + 1
end
local w, h = Text:GetSize()
w = math.max( w, ButtonPanel:GetWide() )
Window:SetSize( w + 50, h + 25 + 45 + 10 )
Window:Center()
InnerPanel:StretchToParent( 5, 25, 5, 45 )
Text:StretchToParent( 5, 5, 5, 5 )
ButtonPanel:CenterHorizontal()
ButtonPanel:AlignBottom( 8 )
Window:MakePopup()
Window:DoModal()
if ( NumOptions == 0 ) then
Window:Close()
Error( "Derma_Query: Created Query with no Options!?" )
return nil
end
return Window
end
--[[
Request a string from the user
Derma_StringRequest( "Question",
"What Is Your Favourite Color?",
"Type your answer here!",
function( strTextOut ) Derma_Message( "Your Favourite Color Is: " .. strTextOut ) end,
function( strTextOut ) Derma_Message( "You pressed Cancel!" ) end,
"Okey Dokey",
"Cancel" )
--]]
function Derma_StringRequest( strTitle, strText, strDefaultText, fnEnter, fnCancel, strButtonText, strButtonCancelText )
local Window = vgui.Create( "DFrame" )
Window:SetTitle( strTitle or "Message Title (First Parameter)" )
Window:SetDraggable( false )
Window:ShowCloseButton( false )
Window:SetBackgroundBlur( true )
Window:SetDrawOnTop( true )
local InnerPanel = vgui.Create( "DPanel", Window )
InnerPanel:SetPaintBackground( false )
local Text = vgui.Create( "DLabel", InnerPanel )
Text:SetText( strText or "Message Text (Second Parameter)" )
Text:SizeToContents()
Text:SetContentAlignment( 5 )
Text:SetTextColor( color_white )
local TextEntry = vgui.Create( "DTextEntry", InnerPanel )
TextEntry:SetText( strDefaultText or "" )
TextEntry.OnEnter = function() Window:Close() fnEnter( TextEntry:GetValue() ) end
local ButtonPanel = vgui.Create( "DPanel", Window )
ButtonPanel:SetTall( 30 )
ButtonPanel:SetPaintBackground( false )
local Button = vgui.Create( "DButton", ButtonPanel )
Button:SetText( strButtonText or "OK" )
Button:SizeToContents()
Button:SetTall( 20 )
Button:SetWide( Button:GetWide() + 20 )
Button:SetPos( 5, 5 )
Button.DoClick = function() Window:Close() fnEnter( TextEntry:GetValue() ) end
local ButtonCancel = vgui.Create( "DButton", ButtonPanel )
ButtonCancel:SetText( strButtonCancelText or "Cancel" )
ButtonCancel:SizeToContents()
ButtonCancel:SetTall( 20 )
ButtonCancel:SetWide( Button:GetWide() + 20 )
ButtonCancel:SetPos( 5, 5 )
ButtonCancel.DoClick = function() Window:Close() if ( fnCancel ) then fnCancel( TextEntry:GetValue() ) end end
ButtonCancel:MoveRightOf( Button, 5 )
ButtonPanel:SetWide( Button:GetWide() + 5 + ButtonCancel:GetWide() + 10 )
local w, h = Text:GetSize()
w = math.max( w, 400 )
Window:SetSize( w + 50, h + 25 + 75 + 10 )
Window:Center()
InnerPanel:StretchToParent( 5, 25, 5, 45 )
Text:StretchToParent( 5, 5, 5, 35 )
TextEntry:StretchToParent( 5, nil, 5, nil )
TextEntry:AlignBottom( 5 )
TextEntry:RequestFocus()
TextEntry:SelectAllText( true )
ButtonPanel:CenterHorizontal()
ButtonPanel:AlignBottom( 8 )
Window:MakePopup()
Window:DoModal()
return Window
end

131
lua/derma/init.lua Normal file
View File

@@ -0,0 +1,131 @@
--[[
| 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/
--]]
--
-- The default font used by everything Derma
--
if ( system.IsLinux() ) then
surface.CreateFont( "DermaDefault", {
font = "DejaVu Sans",
size = 14,
weight = 500,
extended = true
} )
surface.CreateFont( "DermaDefaultBold", {
font = "DejaVu Sans",
size = 14,
weight = 800,
extended = true
} )
else
surface.CreateFont( "DermaDefault", {
font = "Tahoma",
size = 13,
weight = 500,
extended = true
} )
surface.CreateFont( "DermaDefaultBold", {
font = "Tahoma",
size = 13,
weight = 800,
extended = true
} )
end
surface.CreateFont( "DermaLarge", {
font = "Roboto",
size = 32,
weight = 500,
extended = true
} )
include( "derma.lua" )
include( "derma_example.lua" )
include( "derma_menus.lua" )
include( "derma_animation.lua" )
include( "derma_utils.lua" )
include( "derma_gwen.lua" )
function Derma_Hook( panel, functionname, hookname, typename )
panel[ functionname ] = function ( self, a, b, c, d )
return derma.SkinHook( hookname, typename, self, a, b, c, d )
end
end
--[[
ConVar Functions
To associate controls with convars. The controls automatically
update from the value of the control, and automatically update
the value of the convar from the control.
Controls must:
Call ConVarStringThink or ConVarNumberThink from the
Think function to get any changes from the ConVars.
Have SetValue( value ) implemented, to receive the
value.
--]]
function Derma_Install_Convar_Functions( PANEL )
function PANEL:SetConVar( strConVar )
self.m_strConVar = strConVar
end
function PANEL:ConVarChanged( strNewValue )
if ( !self.m_strConVar || #self.m_strConVar < 2 ) then return end
RunConsoleCommand( self.m_strConVar, tostring( strNewValue ) )
end
-- Todo: Think only every 0.1 seconds?
function PANEL:ConVarStringThink()
if ( !self.m_strConVar || #self.m_strConVar < 2 ) then return end
local strValue = GetConVarString( self.m_strConVar )
if ( self.m_strConVarValue == strValue ) then return end
self.m_strConVarValue = strValue
self:SetValue( self.m_strConVarValue )
end
function PANEL:ConVarNumberThink()
if ( !self.m_strConVar || #self.m_strConVar < 2 ) then return end
local numValue = GetConVarNumber( self.m_strConVar )
-- In case the convar is a "nan"
if ( numValue != numValue ) then return end
if ( self.m_strConVarValue == numValue ) then return end
self.m_strConVarValue = numValue
self:SetValue( self.m_strConVarValue )
end
end