Advertisement
Guest User

dasdasd

a guest
Dec 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.84 KB | None | 0 0
  1. --
  2. -- 3D2D Escape Menu by thelastpenguin aka Gareth
  3. -- The author of this script takes no responsability for damages incured in it's use including loss or disruption of service or otherwise.
  4. -- All derivitave scripts must keep this credit banner to the author and must credit the author thelastpenguin in any releases
  5. -- other than that you can do whatever the fvck you want with it :)
  6. --
  7.  
  8. include 'vgui_3d2d.lua'
  9.  
  10. esc = esc or {}
  11.  
  12. local panel
  13. hook.Add('PreRender', 'esc menu', function()
  14. if input.IsKeyDown(KEY_ESCAPE) and gui.IsGameUIVisible() then
  15. if ValidPanel(panel) then
  16. gui.HideGameUI()
  17. panel:Remove()
  18. else
  19. gui.HideGameUI()
  20. esc.openMenu()
  21. end
  22. end
  23. end)
  24.  
  25. local render, surface = _G.render, _G.surface
  26.  
  27. local blur = Material('pp/blurscreen')
  28. local function panelPaintBlur(w,h)
  29. render.SetStencilEnable(true)
  30.  
  31. render.ClearStencil()
  32.  
  33. render.SetStencilWriteMask( 1 )
  34. render.SetStencilTestMask( 1 )
  35. render.SetStencilReferenceValue( 1 )
  36.  
  37. render.SetStencilCompareFunction( STENCIL_ALWAYS )
  38. render.SetStencilPassOperation( STENCIL_REPLACE )
  39. render.SetStencilFailOperation( STENCIL_KEEP )
  40. render.SetStencilZFailOperation( STENCIL_KEEP )
  41.  
  42. surface.SetDrawColor(0,0,0,1)
  43. surface.DrawRect(0,0,w,h)
  44.  
  45. render.SetStencilCompareFunction( STENCIL_EQUAL )
  46. render.SetStencilPassOperation( STENCIL_KEEP )
  47. render.SetStencilFailOperation( STENCIL_KEEP )
  48. render.SetStencilZFailOperation( STENCIL_KEEP )
  49.  
  50. cam.Start2D()
  51. local scrW, scrH = ScrW(), ScrH()
  52. surface.SetDrawColor(255, 255, 255)
  53. surface.SetMaterial(blur)
  54. for i = 1, 4 do
  55. blur:SetFloat('$blur', (i / 4) * (10))
  56. blur:Recompute()
  57. render.UpdateScreenEffectTexture()
  58. surface.DrawTexturedRect(0, 0, scrW, scrH)
  59. end
  60. cam.End2D()
  61.  
  62. render.SetStencilEnable(false)
  63. end
  64.  
  65.  
  66. --
  67. -- CUSTOM AVATAR PANEL
  68. --
  69. local PANEL = {}
  70. function PANEL:Init()
  71. self.avatarImage = vgui.Create('AvatarImage', self)
  72. self.avatarImage:SetPaintedManually(true)
  73. self:PerformLayout()
  74. end
  75. function PANEL:SetPlayer(pl, size)
  76. self.avatarImage:SetPlayer(pl, size)
  77. end
  78. function PANEL:PerformLayout()
  79. local w, h = self:GetSize()
  80. self.avatarImage:SetSize(w,h)
  81.  
  82. self.circle = {}
  83. local wedges = 36
  84. local wedge_angle = math.pi*2/wedges
  85. local r = w * 0.5
  86. for i = 1, wedges do
  87. table.insert(self.circle, {
  88. x = math.cos(i*wedge_angle) * r + r,
  89. y = math.sin(i*wedge_angle) * r + r,
  90. })
  91. end
  92. end
  93.  
  94. function PANEL:Paint(w,h)
  95.  
  96. render.SetStencilEnable(true)
  97.  
  98. render.ClearStencil()
  99.  
  100. render.SetStencilWriteMask( 1 )
  101. render.SetStencilTestMask( 1 )
  102. render.SetStencilReferenceValue( 1 )
  103.  
  104. render.SetStencilCompareFunction( STENCIL_ALWAYS )
  105. render.SetStencilPassOperation( STENCIL_REPLACE )
  106. render.SetStencilFailOperation( STENCIL_KEEP )
  107. render.SetStencilZFailOperation( STENCIL_KEEP )
  108.  
  109. surface.SetDrawColor(0,0,0,255)
  110. draw.NoTexture()
  111. surface.DrawPoly(self.circle)
  112.  
  113. render.SetStencilCompareFunction( STENCIL_EQUAL )
  114. render.SetStencilPassOperation( STENCIL_KEEP )
  115. render.SetStencilFailOperation( STENCIL_KEEP )
  116. render.SetStencilZFailOperation( STENCIL_KEEP )
  117.  
  118. self.avatarImage:SetPaintedManually(false)
  119. self.avatarImage:PaintManual()
  120. self.avatarImage:SetPaintedManually(true)
  121.  
  122. render.SetStencilEnable(false)
  123. end
  124. vgui.Register('esc_menu_avatarimage', PANEL)
  125.  
  126.  
  127.  
  128. surface.CreateFont('esc_btn_font', {
  129. font = 'Roboto',
  130. size = 18*1.5,
  131. weight = 1000,
  132. })
  133.  
  134. surface.CreateFont('esc_name_font', {
  135. font = 'Roboto',
  136. size = 22*1.5,
  137. weight = 1000,
  138. })
  139.  
  140.  
  141. esc.openMenu = function()
  142. gui.EnableScreenClicker(true)
  143.  
  144. panel = vgui.Create('DPanel')
  145. panel.CalcLocation = function(vOrigin, vAngles)
  146. local pos, ang, scale
  147. pos = LocalPlayer():GetPos()
  148. ang = LocalPlayer():EyeAngles()
  149. ang.p = 0
  150. ang.r = 0
  151. ang:RotateAroundAxis(ang:Up(), 120)
  152. ang:RotateAroundAxis(ang:Right(), 90)
  153. ang:RotateAroundAxis(ang:Up(), -90)
  154.  
  155. scale = 0.125
  156.  
  157. pos = pos + ang:Forward() * 50
  158. pos = pos - ang:Right() * 40
  159. pos = pos - ang:Up() * 30
  160. return pos, ang, scale
  161. end
  162.  
  163. panel:SetSize(600, 600);
  164. function panel:OnRemove()
  165. gui.EnableScreenClicker(false)
  166. hook.Remove('CalcView', 'hookname')
  167. end
  168.  
  169. vgui.make3d( panel );
  170.  
  171. hook.Add('CalcView', 'hookname', function(pl, pos, ang, fov, nearz, farz)
  172. ang.p = 0
  173. ang:RotateAroundAxis(ang:Up(),130)
  174.  
  175. pos = pos - ang:Forward() * 50*1.25 + ang:Right() * 30*1.25
  176. pos.z = pos.z - 20
  177. vgui.set3d2dOrigin(pos, ang)
  178. return {
  179. origin = pos,
  180. angles = ang,
  181. fov = fov,
  182. drawviewer = true
  183. }
  184. end)
  185.  
  186. local w, h = panel:GetSize()
  187. function panel:Paint(w,h) end
  188.  
  189. local header = vgui.Create('DPanel', panel)
  190. header.Paint = function(_, w, h)
  191. panelPaintBlur(w,h)
  192. surface.SetDrawColor(20,20,20,220)
  193. surface.DrawRect(0,0,w,h)
  194. surface.SetDrawColor(0,0,0,255)
  195. surface.DrawOutlinedRect(0,0,w,h)
  196. end
  197. header:SetSize(w, 64+8)
  198.  
  199.  
  200. local btnClose = vgui.Create('DButton', header)
  201. btnClose:SetFont('esc_name_font')
  202. btnClose:SetTextColor(color_white)
  203. btnClose:SetText('X')
  204. btnClose:SetSize(45,45)
  205. btnClose:SetPos(header:GetWide() - btnClose:GetWide(),0)
  206. btnClose.Paint = xfn.noop
  207. btnClose.DoClick = function() panel:Remove() end
  208.  
  209. local avatarImage = vgui.Create('esc_menu_avatarimage', panel)
  210. avatarImage:SetPos(4,4)
  211. avatarImage:SetSize(64, 64)
  212. avatarImage:SetPlayer(LocalPlayer(), 64)
  213.  
  214. local lblName = Label(LocalPlayer():Name(), header)
  215. lblName:SetFont('esc_name_font')
  216. lblName:SizeToContents()
  217. lblName:Center()
  218.  
  219. local body = vgui.Create('DPanel', panel)
  220. body:SetPos(0, header:GetTall() + 4)
  221. body:SetSize(w, h - header:GetTall() - 8)
  222.  
  223. function body:Paint(w,h)
  224. panelPaintBlur(w,h)
  225. surface.SetDrawColor(0,0,0, 50)
  226. surface.DrawRect(0,0,w,h)
  227.  
  228. surface.SetDrawColor(0,0,0)
  229. surface.DrawOutlinedRect(0,0,w,h)
  230. end
  231.  
  232. local function addButton(parent, text, action)
  233. local btn = vgui.Create('DButton', parent)
  234. btn:SetSize(parent:GetWide(), 33)
  235. btn:SetFont 'esc_btn_font'
  236. btn:SetTextColor(color_white)
  237. btn:SetText(text)
  238. btn:DockMargin(4,2,4,2)
  239. btn:Dock(TOP)
  240. function btn:OnCursorEntered()
  241. self:SetTextColor(color_black)
  242. end
  243. function btn:OnCursorExited()
  244. self:SetTextColor(color_white)
  245. end
  246. function btn:Paint(w,h)
  247. if self:IsHovered() then
  248. surface.SetDrawColor(200,200,200,110)
  249. surface.DrawRect(0,0,w,h)
  250. else
  251. surface.SetDrawColor(0,0,0,150)
  252. surface.DrawRect(0,0,w,h)
  253. end
  254. end
  255. btn.DoClick = action
  256. return btn
  257. end
  258. local function addAltText(btn, alt)
  259. local original = btn:GetText()
  260. btn.OnCursorEntered = function(self)
  261. self:SetText(alt)
  262. self:SetTextColor(color_black)
  263. end
  264. btn.OnCursorExited = function(self)
  265. self:SetText(original)
  266. self:SetTextColor(color_white)
  267. end
  268. return btn
  269. end
  270.  
  271. local function addConfirm(btn)
  272. local onCursorEntered = btn.OnCursorEntered
  273. local onCursorExited = btn.OnCursorExited
  274. local doClick = btn.DoClick
  275. local defaultText = btn:GetText()
  276.  
  277. btn.DoClick = xfn.noop
  278.  
  279. local function clickOverride()
  280. btn:SetText('[click to confirm]')
  281. btn:SetTextColor(color_black)
  282.  
  283. local function reset()
  284. btn:SetText(defaultText)
  285. btn:SetTextColor(color_white)
  286. btn.OnMouseReleased = clickOverride
  287. btn.OnMousePressed = xfn.noop
  288. btn.onCursorExited = onCursorExited
  289. end
  290.  
  291. btn.OnCursorExited = function(...)
  292. onCursorExited(...)
  293. reset()
  294. end
  295.  
  296. btn.OnMousePressed = function(...)
  297. doClick(...)
  298. reset()
  299. end
  300. end
  301.  
  302. btn.OnMouseReleased = clickOverride
  303. end
  304.  
  305. local function addSection(parent, title)
  306. local panel = vgui.Create('DPanel', parent)
  307. panel:SetWide(parent:GetWide())
  308. panel:DockMargin(5,2,5,2)
  309. panel:Dock(TOP)
  310. panel:DockPadding(0,18*1.5,0,0)
  311.  
  312. local label = Label(title, panel)
  313. label:SetFont('esc_btn_font')
  314. label:SizeToContents()
  315. label:CenterHorizontal()
  316.  
  317. function panel:Paint(w,h)
  318. surface.SetDrawColor(200,200,200,255)
  319.  
  320. surface.DrawLine(0,15,w*0.5-label:GetWide()*0.5,15)
  321. surface.DrawLine(0,16,w*0.5-label:GetWide()*0.5,16)
  322.  
  323. surface.DrawLine(w*0.5+label:GetWide()*0.5+10,15,w,15)
  324. surface.DrawLine(w*0.5+label:GetWide()*0.5+10,16,w,16)
  325.  
  326. surface.DrawLine(0,15,0,h)
  327. surface.DrawLine(1,15,1,h)
  328.  
  329. surface.DrawLine(w,15,w,h)
  330. surface.DrawLine(w-1,15,w-1,h)
  331.  
  332. surface.DrawLine(0,h,w,h)
  333. surface.DrawLine(0,h-1,w,h-1)
  334. end
  335.  
  336. function panel:PerformLayout()
  337. local h = 0
  338. for k,v in pairs(self:GetChildren())do
  339. local x, y = v:GetPos()
  340. if y + v:GetTall() > h then h = y + v:GetTall() end
  341. end
  342. self:SetTall(h+4)
  343. end
  344.  
  345. return panel
  346. end
  347.  
  348. local serverList = addSection(body, 'SERVERS')
  349. local function addServerButton(name, ip)
  350. addConfirm(addAltText(addButton(serverList, name, function()
  351. LocalPlayer():ConCommand('connect '..ip..'\n')
  352. end), '[CLICK TO JOIN]'))
  353. end
  354. addServerButton('DARKRP', '103.62.51.13:27430')
  355. local webList = addSection(body, 'EASE OF USE')
  356. addAltText(addButton(webList, 'FORUMS', function()
  357. gui.OpenURL('http://www.ranchaustralia.org')
  358. end), 'CLICK TO OPEN')
  359. addAltText(addButton(webList, 'DONATE', function()
  360. gui.OpenURL('http://www.ranchaustralia.net/swdonate/')
  361. end), 'CLICK TO OPEN')
  362. addAltText(addButton(webList, 'CRATES', function()
  363. LocalPlayer():ConCommand('prz_open')
  364. end), 'CLICK TO OPEN')
  365. addAltText(addButton(webList, 'WHITELIST', function()
  366. LocalPlayer():ConCommand('openmenu')
  367. end), 'CLICK TO OPEN')
  368. addAltText(addButton(webList, 'THIRD PERSON', function()
  369. LocalPlayer():ConCommand('simple_thirdperson_enable_toggle')
  370. end), 'DOUBLE CLICK IT')
  371. addAltText(addButton(webList, 'CONVERT POINTS', function()
  372. LocalPlayer():ConCommand('say !convert')
  373. end), 'CLICK TO OPEN')
  374.  
  375.  
  376. addButton(body, 'DISCONNECT', function() LocalPlayer():ConCommand('disconnect\n') end):Dock(BOTTOM)
  377. addButton(body, 'OPTIONS', function() gui.ActivateGameUI() panel:Remove() end):Dock(BOTTOM)
  378. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement