Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DERMA RELATED
- --[[
- Display a simple message box.
- Derma_Message( "Hey Some Text Here!!!", "Message Title (Optional)", "Button Text (Optional)" )
- --]]
- local accent = CreateClientConVar("exhibition_color_accent", "0 190 230")
- function Derma_Message( strText, strTitle, strButtonText )
- local clr = string.Explode(" ", accent:GetString())
- clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
- if (IsValid(DERMA_MENU)) then
- DERMA_MENU:Remove()
- end
- local Window = vgui.Create( "XFrame" )
- Window:SetTitle( strTitle or "Message" )
- Window:SetDraggable( false )
- Window:ShowCloseButton( false )
- Window._titleSize = 20
- Window:SetBackgroundBlur( true )
- Window:SetDrawOnTop( true )
- DERMA_MENU = Window
- local InnerPanel = vgui.Create( "Panel", Window )
- local Text = vgui.Create( "DLabel", InnerPanel )
- Text:SetText( strText or "Message Text" )
- Text:SizeToContents()
- Text:SetFont(ExUI:GetFont(15))
- Text:SetContentAlignment( 5 )
- Text:SetTextColor( color_white )
- local ButtonPanel = vgui.Create( "DPanel", Window )
- ButtonPanel:SetTall( 30 )
- ButtonPanel:SetPaintBackground( false )
- local Button = vgui.Create( "XButton", ButtonPanel )
- Button:SetText( strButtonText or "OK" )
- Button:SizeToContents()
- Button:SetTall( 20 )
- Button:SetWide( Button:GetWide() + 32 )
- Button:SetPos( 5, 5 )
- Button:SetTextSize(18)
- Button:SetColor(clr)
- Button.DoClick = function() Window:Close() end
- ButtonPanel:SetWide( Button:GetWide() + 16 )
- local w, h = Text:GetSize()
- Window:SetSize( w + 72 + 32, h + 25 + 45 + 16 )
- Window:Center()
- InnerPanel:StretchToParent( 5, 26, 5, 42 )
- Text:StretchToParent( 8, 14, 8, 0 )
- 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 clr = string.Explode(" ", accent:GetString())
- clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
- if (IsValid(DERMA_MENU)) then
- DERMA_MENU:Remove()
- end
- local Window = vgui.Create( "XFrame" )
- Window:SetTitle( strTitle or "Message" )
- Window:SetDraggable( false )
- Window:ShowCloseButton( false )
- Window._titleSize = 20
- Window:SetBackgroundBlur( true )
- Window:SetDrawOnTop( true )
- DERMA_MENU = Window
- 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:SetFont(ExUI:GetFont(15))
- 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 Text = select( k, ... )
- if Text == nil then break end
- local Func = select( k+1, ... ) or function() end
- local Button = vgui.Create( "XButton", ButtonPanel )
- Button:SetText( Text )
- Button:SizeToContents()
- Button:SetTall( 20 )
- Button:SetWide( Button:GetWide() + 20 )
- Button:SetTextSize(16)
- Button.DoClick = function() Window:Close() Func() end
- Button:SetColor(clr)
- Button:SetPos( x, 5 )
- x = x + Button:GetWide() + 8
- ButtonPanel:SetWide( x )
- NumOptions = NumOptions + 1
- end
- local w, h = Text:GetSize()
- w = math.max( w, ButtonPanel:GetWide() ) + 64
- Window:SetSize( w + 72, h + 25 + 45 + 16 )
- Window:Center()
- InnerPanel:StretchToParent( 5, 26, 5, 44 )
- Text:StretchToParent( 8, 14, 8, 0 )
- 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 clr = string.Explode(" ", accent:GetString())
- clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
- if (IsValid(DERMA_MENU)) then
- DERMA_MENU:Remove()
- end
- local Window = vgui.Create( "XFrame" )
- Window:SetTitle( strTitle or "Message Title (First Parameter)" )
- Window:SetDraggable( false )
- Window:ShowCloseButton( false )
- Window._titleSize = 20
- Window:SetBackgroundBlur( true )
- Window:SetDrawOnTop( true )
- DERMA_MENU = Window
- 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:SetFont(ExUI:GetFont(15))
- Text:SetTextColor( color_white )
- local TextEntry = vgui.Create( "XTextEntry", 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( "XButton", ButtonPanel )
- Button:SetText( strButtonText or "OK" )
- Button:SizeToContents()
- Button:SetTall( 20 )
- Button:SetColor(Color(75, 175, 25))
- Button:SetTextSize(16)
- Button:SetWide( Button:GetWide() + 20 )
- Button:SetPos( 5, 2 )
- Button.DoClick = function() Window:Close() fnEnter( TextEntry:GetValue() ) end
- local ButtonCancel = vgui.Create( "XButton", ButtonPanel )
- ButtonCancel:SetText( strButtonCancelText or "Cancel" )
- ButtonCancel:SizeToContents()
- ButtonCancel:SetTall( 20 )
- ButtonCancel:SetColor(Color(175, 75, 25))
- ButtonCancel:SetTextSize(16)
- ButtonCancel:SetWide( Button:GetWide() + 20 )
- ButtonCancel:SetPos( 5, 2 )
- 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 ) + 96
- Window:SetSize( w + 72, h + 25 + 75 + 28 )
- Window:Center()
- InnerPanel:StretchToParent( 5, 32, 5, 45 )
- Text:StretchToParent( 5, 5, 5, 35 )
- TextEntry:StretchToParent( 5, 8, 5, 28 )
- TextEntry:AlignBottom( 5 )
- TextEntry:RequestFocus()
- TextEntry:SelectAllText( true )
- ButtonPanel:CenterHorizontal()
- ButtonPanel:AlignBottom( 8 )
- Window:MakePopup()
- Window:DoModal()
- return Window
- end
- -- FONT RELATED
- ExUI.Fonts = {}
- function ExUI:AddFont(size, bold, blur)
- if (self.Fonts[size]) then return end
- local tbl = {
- font = self.Font,
- size = size,
- weight = bold and 600 or 400
- }
- if (blur) then
- tbl.blursize = 4
- surface.CreateFont("ExUI." .. size .. "_blur", tbl)
- tbl.blursize = nil
- surface.CreateFont("ExUI." .. size, tbl)
- else
- surface.CreateFont("ExUI." .. size, tbl)
- end
- self.Fonts[size] = "ExUI." .. size
- end
- function ExUI:GetFont(size)
- if (not self.Fonts[size]) then
- self:AddFont(size)
- end
- return self.Fonts[size]
- end
- function ExUI:DrawText(text, size, x, y, color, align_x, align_y)
- return draw.SimpleText(text, self:GetFont(size), x, y, color, align_x or TEXT_ALIGN_LEFT, align_y or TEXT_ALIGN_TOP)
- end
- function ExUI:DrawBlurText(text, x, y, size, color, align_x, align_y, shadowColor)
- draw.SimpleText(text, self:GetFont(size) .. "_blur", x + 2, y + 2, shadowColor or color_black, align_x or TEXT_ALIGN_LEFT, align_y or TEXT_ALIGN_TOP)
- return self:DrawText(text, x, y, size, color, align_x, align_y)
- end
- -- MENU RELATED
- local accent = CreateClientConVar("exhibition_color_accent", "0 190 230")
- local function Styilize(menu)
- menu.doInit = 0.5
- menu.Paint = function(s, w, h)
- if (IsValid(DERMA_MENU)) then
- s:Remove()
- return
- end
- if (s.doInit < 1) then
- s.doInit = Lerp(FrameTime() * 5, s.doInit, 1.1)
- end
- draw.RoundedBox(8, 0, 0, w - 4, h, ColorAlpha(ExUI.Style.Background, 255 * s.doInit))
- end
- end
- local function StyleOption(option)
- option:SetFont(ExUI:GetFont(16))
- option:SetTextColor(Color(255, 255, 255, 75))
- local clr = string.Explode(" ", accent:GetString())
- clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
- option.Paint = function(s, w, h)
- s.doInit = Lerp(FrameTime() * (s:IsHovered() and 5 or 10), s.doInit or 0, not s:IsHovered() and 0 or 1)
- draw.RoundedBox(8, 2, 2, w - 8, h - 4, ColorAlpha(clr, s.doInit * 25))
- end
- option._OnCursorEntered = option.OnCursorEntered
- option.OnCursorEntered = function(s)
- s:_OnCursorEntered()
- s:SetTextColor(color_white)
- end
- option._OnCursorExited = option.OnCursorExited
- option.OnCursorExited = function(s)
- s:_OnCursorExited()
- s:SetTextColor(Color(255, 255, 255, 100))
- end
- option:SetTextInset(34, 0)
- option.PerformLayout = function(self)
- self:SizeToContents()
- self:SetWide(self:GetWide() + 30)
- local w = math.max(self:GetParent():GetWide(), self:GetWide())
- self:SetSize(w, 30)
- if (self.SubMenuArrow) then
- self.SubMenuArrow:SetSize(15, 15)
- self.SubMenuArrow:CenterVertical()
- self.SubMenuArrow:AlignRight(4)
- end
- DButton.PerformLayout(self)
- if IsValid(self.m_Image) then
- self.m_Image:SetPos(8, (self:GetTall() - self.m_Image:GetTall()) * 0.5)
- end
- end
- end
- function DermaMenu( parentmenu, parent )
- if ( !parentmenu ) then CloseDermaMenus() end
- local dmenu = vgui.Create( "DMenu", parent )
- Styilize(dmenu)
- dmenu.oldAddOption = dmenu.AddOption
- dmenu.AddOption = function(s, text, func)
- local item = s:oldAddOption(text, func)
- StyleOption(item)
- return item
- end
- dmenu.oldAddSubMenu = dmenu.AddSubMenu
- dmenu.AddSubMenu = function(s, text, func)
- local newmenu, item = s:oldAddSubMenu(text, func)
- Styilize(newmenu)
- StyleOption(item)
- return newmenu, item
- end
- return dmenu
- end
- -- PANEL RELATED
- local PANEL = FindMetaTable("Panel")
- function PANEL:Margin(x)
- self:DockMargin(x, x, x, x)
- end
- function PANEL:Padding(x)
- self:DockPadding(x, x, x, x)
- end
- local blur = Material("pp/blurscreen")
- --[[@
- @func DrawBlurPanel()
- @desc Draws a blur on a panel
- @param panel:panel
- @param amount:int
- @param heavyness:int
- ]]--@
- function DrawBlurPanel(panel, amount, heavyness)
- local x, y = panel:LocalToScreen(0, 0)
- local scrW, scrH = ScrW(), ScrH()
- surface.SetDrawColor(255,255,255)
- surface.SetMaterial(blur)
- for i = 1, heavyness do
- blur:SetFloat("$blur", (i / 3) * (amount or 6))
- blur:Recompute()
- render.UpdateScreenEffectTexture()
- surface.DrawTexturedRect(x * -1, y * -1, scrW, scrH)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement