Advertisement
wifiboost

exui

Mar 12th, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.69 KB | None | 0 0
  1. -- DERMA RELATED
  2. --[[
  3. Display a simple message box.
  4.  
  5. Derma_Message( "Hey Some Text Here!!!", "Message Title (Optional)", "Button Text (Optional)" )
  6. --]]
  7. local accent = CreateClientConVar("exhibition_color_accent", "0 190 230")
  8.  
  9. function Derma_Message( strText, strTitle, strButtonText )
  10.  
  11. local clr = string.Explode(" ", accent:GetString())
  12. clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
  13.  
  14. if (IsValid(DERMA_MENU)) then
  15. DERMA_MENU:Remove()
  16. end
  17.  
  18. local Window = vgui.Create( "XFrame" )
  19. Window:SetTitle( strTitle or "Message" )
  20. Window:SetDraggable( false )
  21. Window:ShowCloseButton( false )
  22. Window._titleSize = 20
  23. Window:SetBackgroundBlur( true )
  24. Window:SetDrawOnTop( true )
  25.  
  26. DERMA_MENU = Window
  27.  
  28. local InnerPanel = vgui.Create( "Panel", Window )
  29.  
  30. local Text = vgui.Create( "DLabel", InnerPanel )
  31. Text:SetText( strText or "Message Text" )
  32. Text:SizeToContents()
  33. Text:SetFont(ExUI:GetFont(15))
  34. Text:SetContentAlignment( 5 )
  35. Text:SetTextColor( color_white )
  36.  
  37. local ButtonPanel = vgui.Create( "DPanel", Window )
  38. ButtonPanel:SetTall( 30 )
  39. ButtonPanel:SetPaintBackground( false )
  40.  
  41. local Button = vgui.Create( "XButton", ButtonPanel )
  42. Button:SetText( strButtonText or "OK" )
  43. Button:SizeToContents()
  44. Button:SetTall( 20 )
  45. Button:SetWide( Button:GetWide() + 32 )
  46. Button:SetPos( 5, 5 )
  47. Button:SetTextSize(18)
  48. Button:SetColor(clr)
  49. Button.DoClick = function() Window:Close() end
  50.  
  51. ButtonPanel:SetWide( Button:GetWide() + 16 )
  52.  
  53. local w, h = Text:GetSize()
  54.  
  55. Window:SetSize( w + 72 + 32, h + 25 + 45 + 16 )
  56. Window:Center()
  57.  
  58. InnerPanel:StretchToParent( 5, 26, 5, 42 )
  59.  
  60. Text:StretchToParent( 8, 14, 8, 0 )
  61.  
  62. ButtonPanel:CenterHorizontal()
  63. ButtonPanel:AlignBottom( 8 )
  64.  
  65. Window:MakePopup()
  66. Window:DoModal()
  67. return Window
  68.  
  69. end
  70.  
  71. --[[
  72. Ask a question with multiple answers..
  73.  
  74. Derma_Query( "Would you like me to punch you right in the face?", "Question!",
  75. "Yesss", function() MsgN( "Pressed YES!") end,
  76. "Nope!", function() MsgN( "Pressed Nope!") end,
  77. "Cancel", function() MsgN( "Cancelled!") end )
  78.  
  79. --]]
  80.  
  81. function Derma_Query( strText, strTitle, ... )
  82.  
  83. local clr = string.Explode(" ", accent:GetString())
  84. clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
  85.  
  86. if (IsValid(DERMA_MENU)) then
  87. DERMA_MENU:Remove()
  88. end
  89.  
  90. local Window = vgui.Create( "XFrame" )
  91. Window:SetTitle( strTitle or "Message" )
  92. Window:SetDraggable( false )
  93. Window:ShowCloseButton( false )
  94. Window._titleSize = 20
  95. Window:SetBackgroundBlur( true )
  96. Window:SetDrawOnTop( true )
  97.  
  98. DERMA_MENU = Window
  99.  
  100. local InnerPanel = vgui.Create( "DPanel", Window )
  101. InnerPanel:SetPaintBackground( false )
  102.  
  103. local Text = vgui.Create( "DLabel", InnerPanel )
  104. Text:SetText( strText or "Message Text (Second Parameter)" )
  105. Text:SizeToContents()
  106. Text:SetContentAlignment( 5 )
  107. Text:SetFont(ExUI:GetFont(15))
  108. Text:SetTextColor( color_white )
  109.  
  110. local ButtonPanel = vgui.Create( "DPanel", Window )
  111. ButtonPanel:SetTall( 30 )
  112. ButtonPanel:SetPaintBackground( false )
  113.  
  114. -- Loop through all the options and create buttons for them.
  115. local NumOptions = 0
  116. local x = 5
  117.  
  118. for k=1, 8, 2 do
  119.  
  120. local Text = select( k, ... )
  121. if Text == nil then break end
  122.  
  123. local Func = select( k+1, ... ) or function() end
  124.  
  125. local Button = vgui.Create( "XButton", ButtonPanel )
  126. Button:SetText( Text )
  127. Button:SizeToContents()
  128. Button:SetTall( 20 )
  129. Button:SetWide( Button:GetWide() + 20 )
  130. Button:SetTextSize(16)
  131. Button.DoClick = function() Window:Close() Func() end
  132. Button:SetColor(clr)
  133. Button:SetPos( x, 5 )
  134.  
  135. x = x + Button:GetWide() + 8
  136.  
  137. ButtonPanel:SetWide( x )
  138. NumOptions = NumOptions + 1
  139.  
  140. end
  141.  
  142. local w, h = Text:GetSize()
  143.  
  144. w = math.max( w, ButtonPanel:GetWide() ) + 64
  145.  
  146. Window:SetSize( w + 72, h + 25 + 45 + 16 )
  147. Window:Center()
  148.  
  149. InnerPanel:StretchToParent( 5, 26, 5, 44 )
  150.  
  151. Text:StretchToParent( 8, 14, 8, 0 )
  152.  
  153. ButtonPanel:CenterHorizontal()
  154. ButtonPanel:AlignBottom( 8 )
  155.  
  156. Window:MakePopup()
  157. Window:DoModal()
  158.  
  159. if ( NumOptions == 0 ) then
  160.  
  161. Window:Close()
  162. Error( "Derma_Query: Created Query with no Options!?" )
  163. return nil
  164.  
  165. end
  166.  
  167. return Window
  168.  
  169. end
  170.  
  171. --[[
  172. Request a string from the user
  173.  
  174. Derma_StringRequest( "Question",
  175. "What Is Your Favourite Color?",
  176. "Type your answer here!",
  177. function( strTextOut ) Derma_Message( "Your Favourite Color Is: " .. strTextOut ) end,
  178. function( strTextOut ) Derma_Message( "You pressed Cancel!" ) end,
  179. "Okey Dokey",
  180. "Cancel" )
  181.  
  182. --]]
  183.  
  184. function Derma_StringRequest( strTitle, strText, strDefaultText, fnEnter, fnCancel, strButtonText, strButtonCancelText )
  185.  
  186. local clr = string.Explode(" ", accent:GetString())
  187. clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
  188.  
  189. if (IsValid(DERMA_MENU)) then
  190. DERMA_MENU:Remove()
  191. end
  192. local Window = vgui.Create( "XFrame" )
  193. Window:SetTitle( strTitle or "Message Title (First Parameter)" )
  194. Window:SetDraggable( false )
  195. Window:ShowCloseButton( false )
  196. Window._titleSize = 20
  197. Window:SetBackgroundBlur( true )
  198. Window:SetDrawOnTop( true )
  199.  
  200. DERMA_MENU = Window
  201.  
  202. local InnerPanel = vgui.Create( "DPanel", Window )
  203. InnerPanel:SetPaintBackground( false )
  204.  
  205. local Text = vgui.Create( "DLabel", InnerPanel )
  206. Text:SetText( strText or "Message Text (Second Parameter)" )
  207. Text:SizeToContents()
  208. Text:SetContentAlignment( 5 )
  209. Text:SetFont(ExUI:GetFont(15))
  210. Text:SetTextColor( color_white )
  211.  
  212. local TextEntry = vgui.Create( "XTextEntry", InnerPanel )
  213. TextEntry:SetText( strDefaultText or "" )
  214. TextEntry.OnEnter = function() Window:Close() fnEnter( TextEntry:GetValue() ) end
  215.  
  216. local ButtonPanel = vgui.Create( "DPanel", Window )
  217. ButtonPanel:SetTall( 30 )
  218. ButtonPanel:SetPaintBackground( false )
  219.  
  220. local Button = vgui.Create( "XButton", ButtonPanel )
  221. Button:SetText( strButtonText or "OK" )
  222. Button:SizeToContents()
  223. Button:SetTall( 20 )
  224. Button:SetColor(Color(75, 175, 25))
  225. Button:SetTextSize(16)
  226. Button:SetWide( Button:GetWide() + 20 )
  227. Button:SetPos( 5, 2 )
  228. Button.DoClick = function() Window:Close() fnEnter( TextEntry:GetValue() ) end
  229.  
  230. local ButtonCancel = vgui.Create( "XButton", ButtonPanel )
  231. ButtonCancel:SetText( strButtonCancelText or "Cancel" )
  232. ButtonCancel:SizeToContents()
  233. ButtonCancel:SetTall( 20 )
  234. ButtonCancel:SetColor(Color(175, 75, 25))
  235. ButtonCancel:SetTextSize(16)
  236. ButtonCancel:SetWide( Button:GetWide() + 20 )
  237. ButtonCancel:SetPos( 5, 2 )
  238. ButtonCancel.DoClick = function() Window:Close() if ( fnCancel ) then fnCancel( TextEntry:GetValue() ) end end
  239. ButtonCancel:MoveRightOf( Button, 5 )
  240.  
  241. ButtonPanel:SetWide( Button:GetWide() + 5 + ButtonCancel:GetWide() + 10 )
  242.  
  243. local w, h = Text:GetSize()
  244. w = math.max( w, 400 ) + 96
  245.  
  246. Window:SetSize( w + 72, h + 25 + 75 + 28 )
  247. Window:Center()
  248.  
  249. InnerPanel:StretchToParent( 5, 32, 5, 45 )
  250.  
  251. Text:StretchToParent( 5, 5, 5, 35 )
  252.  
  253. TextEntry:StretchToParent( 5, 8, 5, 28 )
  254. TextEntry:AlignBottom( 5 )
  255.  
  256. TextEntry:RequestFocus()
  257. TextEntry:SelectAllText( true )
  258.  
  259. ButtonPanel:CenterHorizontal()
  260. ButtonPanel:AlignBottom( 8 )
  261.  
  262. Window:MakePopup()
  263. Window:DoModal()
  264.  
  265. return Window
  266.  
  267. end
  268.  
  269.  
  270. -- FONT RELATED
  271. ExUI.Fonts = {}
  272.  
  273. function ExUI:AddFont(size, bold, blur)
  274. if (self.Fonts[size]) then return end
  275.  
  276. local tbl = {
  277. font = self.Font,
  278. size = size,
  279. weight = bold and 600 or 400
  280. }
  281.  
  282. if (blur) then
  283. tbl.blursize = 4
  284. surface.CreateFont("ExUI." .. size .. "_blur", tbl)
  285. tbl.blursize = nil
  286. surface.CreateFont("ExUI." .. size, tbl)
  287. else
  288. surface.CreateFont("ExUI." .. size, tbl)
  289. end
  290.  
  291. self.Fonts[size] = "ExUI." .. size
  292. end
  293.  
  294. function ExUI:GetFont(size)
  295. if (not self.Fonts[size]) then
  296. self:AddFont(size)
  297. end
  298.  
  299. return self.Fonts[size]
  300. end
  301.  
  302. function ExUI:DrawText(text, size, x, y, color, align_x, align_y)
  303. return draw.SimpleText(text, self:GetFont(size), x, y, color, align_x or TEXT_ALIGN_LEFT, align_y or TEXT_ALIGN_TOP)
  304. end
  305.  
  306. function ExUI:DrawBlurText(text, x, y, size, color, align_x, align_y, shadowColor)
  307. 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)
  308.  
  309. return self:DrawText(text, x, y, size, color, align_x, align_y)
  310. end
  311. -- MENU RELATED
  312.  
  313. local accent = CreateClientConVar("exhibition_color_accent", "0 190 230")
  314.  
  315. local function Styilize(menu)
  316. menu.doInit = 0.5
  317.  
  318. menu.Paint = function(s, w, h)
  319. if (IsValid(DERMA_MENU)) then
  320. s:Remove()
  321.  
  322. return
  323. end
  324.  
  325. if (s.doInit < 1) then
  326. s.doInit = Lerp(FrameTime() * 5, s.doInit, 1.1)
  327. end
  328.  
  329. draw.RoundedBox(8, 0, 0, w - 4, h, ColorAlpha(ExUI.Style.Background, 255 * s.doInit))
  330. end
  331. end
  332.  
  333. local function StyleOption(option)
  334. option:SetFont(ExUI:GetFont(16))
  335. option:SetTextColor(Color(255, 255, 255, 75))
  336.  
  337. local clr = string.Explode(" ", accent:GetString())
  338. clr = Color(tonumber(clr[1]), tonumber(clr[2]), tonumber(clr[3]))
  339.  
  340. option.Paint = function(s, w, h)
  341. s.doInit = Lerp(FrameTime() * (s:IsHovered() and 5 or 10), s.doInit or 0, not s:IsHovered() and 0 or 1)
  342. draw.RoundedBox(8, 2, 2, w - 8, h - 4, ColorAlpha(clr, s.doInit * 25))
  343. end
  344.  
  345. option._OnCursorEntered = option.OnCursorEntered
  346. option.OnCursorEntered = function(s)
  347. s:_OnCursorEntered()
  348. s:SetTextColor(color_white)
  349. end
  350.  
  351. option._OnCursorExited = option.OnCursorExited
  352. option.OnCursorExited = function(s)
  353. s:_OnCursorExited()
  354. s:SetTextColor(Color(255, 255, 255, 100))
  355. end
  356.  
  357. option:SetTextInset(34, 0)
  358.  
  359. option.PerformLayout = function(self)
  360. self:SizeToContents()
  361. self:SetWide(self:GetWide() + 30)
  362. local w = math.max(self:GetParent():GetWide(), self:GetWide())
  363. self:SetSize(w, 30)
  364.  
  365. if (self.SubMenuArrow) then
  366. self.SubMenuArrow:SetSize(15, 15)
  367. self.SubMenuArrow:CenterVertical()
  368. self.SubMenuArrow:AlignRight(4)
  369. end
  370.  
  371. DButton.PerformLayout(self)
  372. if IsValid(self.m_Image) then
  373. self.m_Image:SetPos(8, (self:GetTall() - self.m_Image:GetTall()) * 0.5)
  374. end
  375. end
  376. end
  377.  
  378. function DermaMenu( parentmenu, parent )
  379.  
  380. if ( !parentmenu ) then CloseDermaMenus() end
  381.  
  382. local dmenu = vgui.Create( "DMenu", parent )
  383. Styilize(dmenu)
  384. dmenu.oldAddOption = dmenu.AddOption
  385. dmenu.AddOption = function(s, text, func)
  386. local item = s:oldAddOption(text, func)
  387. StyleOption(item)
  388. return item
  389. end
  390.  
  391. dmenu.oldAddSubMenu = dmenu.AddSubMenu
  392. dmenu.AddSubMenu = function(s, text, func)
  393. local newmenu, item = s:oldAddSubMenu(text, func)
  394. Styilize(newmenu)
  395. StyleOption(item)
  396.  
  397. return newmenu, item
  398. end
  399. return dmenu
  400.  
  401. end
  402.  
  403. -- PANEL RELATED
  404.  
  405. local PANEL = FindMetaTable("Panel")
  406.  
  407. function PANEL:Margin(x)
  408. self:DockMargin(x, x, x, x)
  409. end
  410.  
  411. function PANEL:Padding(x)
  412. self:DockPadding(x, x, x, x)
  413. end
  414.  
  415. local blur = Material("pp/blurscreen")
  416.  
  417. --[[@
  418. @func DrawBlurPanel()
  419. @desc Draws a blur on a panel
  420. @param panel:panel
  421. @param amount:int
  422. @param heavyness:int
  423. ]]--@
  424. function DrawBlurPanel(panel, amount, heavyness)
  425. local x, y = panel:LocalToScreen(0, 0)
  426. local scrW, scrH = ScrW(), ScrH()
  427.  
  428. surface.SetDrawColor(255,255,255)
  429. surface.SetMaterial(blur)
  430.  
  431. for i = 1, heavyness do
  432. blur:SetFloat("$blur", (i / 3) * (amount or 6))
  433. blur:Recompute()
  434.  
  435. render.UpdateScreenEffectTexture()
  436. surface.DrawTexturedRect(x * -1, y * -1, scrW, scrH)
  437. end
  438. end
  439.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement