Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.90 KB | None | 0 0
  1. -- Written by Team Ulysses, http://ulyssesmod.net/
  2. module( "Utime", package.seeall )
  3. if not CLIENT then return end
  4.  
  5. local gpanel
  6.  
  7. --Now convars!
  8. local utime_enable = CreateClientConVar( "utime_enable", "1.0", true, false )
  9. local utime_outsidecolor_r = CreateClientConVar( "utime_outsidecolor_r", "256.0", true, false )
  10. local utime_outsidecolor_g = CreateClientConVar( "utime_outsidecolor_g", "256.0", true, false )
  11. local utime_outsidecolor_b = CreateClientConVar( "utime_outsidecolor_b", "256.0", true, false )
  12. local utime_outsidetext_r = CreateClientConVar( "utime_outsidetext_r", "0.0", true, false )
  13. local utime_outsidetext_g = CreateClientConVar( "utime_outsidetext_g", "0.0", true, false )
  14. local utime_outsidetext_b = CreateClientConVar( "utime_outsidetext_b", "0.0", true, false )
  15.  
  16. local utime_insidecolor_r = CreateClientConVar( "utime_insidecolor_r", "256.0", true, false )
  17. local utime_insidecolor_g = CreateClientConVar( "utime_insidecolor_g", "256.0", true, false )
  18. local utime_insidecolor_b = CreateClientConVar( "utime_insidecolor_b", "256.0", true, false )
  19. local utime_insidetext_r = CreateClientConVar( "utime_insidetext_r", "0", true, false )
  20. local utime_insidetext_g = CreateClientConVar( "utime_insidetext_g", "0", true, false )
  21. local utime_insidetext_b = CreateClientConVar( "utime_insidetext_b", "0", true, false )
  22.  
  23. local utime_pos_x = CreateClientConVar( "utime_pos_x", "0.0", true, false )
  24. local utime_pos_y = CreateClientConVar( "utime_pos_y", "0.0", true, false )
  25.  
  26. local PANEL = {}
  27. PANEL.Small = 40
  28. PANEL.TargetSize = PANEL.Small
  29. PANEL.Large = 100
  30. PANEL.Wide = 160
  31.  
  32. function initialize()
  33.     gpanel = vgui.Create( "UTimeMain" )
  34.     gpanel:SetSize( gpanel.Wide, gpanel.Small )
  35.     hook.Remove( "OnEntityCreated", "UtimeInitialize" )
  36. end
  37. hook.Add( "InitPostEntity", "UtimeInitialize", initialize )
  38.  
  39. function think()
  40.     if not LocalPlayer():IsValid() or gpanel == nil then return end
  41.  
  42.     if not utime_enable:GetBool() or not IsValid( LocalPlayer() ) or
  43.             (IsValid( LocalPlayer():GetActiveWeapon() ) and LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera") then
  44.         gpanel:SetVisible( false )
  45.     else
  46.         gpanel:SetVisible( true )
  47.     end
  48.  
  49.     --gpanel:SetPos( ScrW() - gpanel:GetWide() - 20, 20 )
  50.     gpanel:SetPos( (ScrW() - gpanel:GetWide()) * utime_pos_x:GetFloat() / 100, (ScrH() - gpanel.Large) * utime_pos_y:GetFloat() / 100 )
  51.  
  52.     local textColor = Color( utime_outsidetext_r:GetInt(), utime_outsidetext_g:GetInt(), utime_outsidetext_b:GetInt(), 255 )
  53.     gpanel.lblTotalTime:SetTextColor( textColor )
  54.     gpanel.lblSessionTime:SetTextColor( textColor )
  55.     gpanel.total:SetTextColor( textColor )
  56.     gpanel.session:SetTextColor( textColor )
  57.  
  58.     local insideTextColor = Color( utime_insidetext_r:GetInt(), utime_insidetext_g:GetInt(), utime_insidetext_b:GetInt(), 255 )
  59.     gpanel.playerInfo.lblTotalTime:SetTextColor( insideTextColor )
  60.     gpanel.playerInfo.lblSessionTime:SetTextColor( insideTextColor )
  61.     gpanel.playerInfo.lblNick:SetTextColor( insideTextColor )
  62.     gpanel.playerInfo.total:SetTextColor( insideTextColor )
  63.     gpanel.playerInfo.session:SetTextColor( insideTextColor )
  64.     gpanel.playerInfo.nick:SetTextColor( insideTextColor )
  65. end
  66. timer.Create( "UTimeThink", 0.6, 0, think )
  67.  
  68. local texGradient = surface.GetTextureID( "gui/center_gradient" )
  69.  
  70. --PANEL.InnerColor = Color( 250, 250, 245, 255 )
  71. --PANEL.OuterColor = Color( 0, 150, 245, 200 )
  72.  
  73. -----------------------------------------------------------
  74. --   Name: Paint
  75. -----------------------------------------------------------
  76. function PANEL:Paint(w,h)
  77.         local wide = self:GetWide()
  78.         local tall = self:GetTall()
  79.  
  80.         local outerColor = Color( utime_outsidecolor_r:GetInt(), utime_outsidecolor_g:GetInt(), utime_outsidecolor_b:GetInt(), 200 )
  81.         draw.RoundedBox( 4, 0, 0, wide, tall, outerColor ) -- Draw our base
  82.  
  83.         surface.SetTexture( texGradient )
  84.         surface.SetDrawColor( 255, 255, 255, 50 )
  85.         surface.SetDrawColor( outerColor )
  86.         surface.DrawTexturedRect( 0, 0, wide, tall )  -- Draw gradient overlay
  87.  
  88.         if self:GetTall() > self.Small + 4 then -- Draw the white background for another player's info
  89.                 local innerColor = Color( utime_insidecolor_r:GetInt(), utime_insidecolor_g:GetInt(), utime_insidecolor_b:GetInt(), 255 )
  90.                 draw.RoundedBox( 4, 2, self.Small, wide - 4, tall - self.Small - 2, innerColor )
  91.  
  92.                 surface.SetTexture( texGradient )
  93.                 surface.SetDrawColor( color_white )
  94.                 surface.SetDrawColor( innerColor )
  95.                 surface.DrawTexturedRect( 2, self.Small, wide - 4, tall - self.Small - 2 ) -- Gradient overlay
  96.         end
  97.  
  98.         return true
  99. end
  100.  
  101. -----------------------------------------------------------
  102. --   Name: Init
  103. -----------------------------------------------------------
  104. function PANEL:Init()
  105.         self.Size = self.Small
  106.  
  107.         self.playerInfo         = vgui.Create( "UTimePlayerInfo", self )
  108.  
  109.         self.lblTotalTime       = vgui.Create( "DLabel", self )
  110.         self.lblSessionTime     = vgui.Create( "DLabel", self )
  111.  
  112.         self.total              = vgui.Create( "DLabel", self )
  113.         self.session            = vgui.Create( "DLabel", self )
  114. end
  115.  
  116. -----------------------------------------------------------
  117. --   Name: ApplySchemeSettings
  118. -----------------------------------------------------------
  119. function PANEL:ApplySchemeSettings()
  120.         self.lblTotalTime:SetFont( "DermaDefault" )
  121.         self.lblSessionTime:SetFont( "DermaDefault" )
  122.         self.total:SetFont( "DermaDefault" )
  123.         self.session:SetFont( "DermaDefault" )
  124.  
  125.         self.lblTotalTime:SetTextColor( color_black )
  126.         self.lblSessionTime:SetTextColor( color_black )
  127.         self.total:SetTextColor( color_black )
  128.         self.session:SetTextColor( color_black )
  129. end
  130.  
  131. -----------------------------------------------------------
  132. --   Name: ShouldRevealPlayer
  133. -----------------------------------------------------------
  134. function PANEL:ShouldRevealPlayer( ply )
  135.     if ply:GetNWBool("disguised", false) then -- TTT disguiser
  136.         return false
  137.     end
  138.  
  139.     if engine.ActiveGamemode() == "murder" and not LocalPlayer():IsAdmin() then
  140.         return false
  141.     end
  142.  
  143.     return true
  144. end
  145.  
  146. -----------------------------------------------------------
  147. --   Name: Think
  148. -----------------------------------------------------------
  149. local locktime = 0
  150. function PANEL:Think()
  151.     if self.Size == self.Small then
  152.         self.playerInfo:SetVisible( false )
  153.     else
  154.         self.playerInfo:SetVisible( true )
  155.     end
  156.  
  157.     if not IsValid( LocalPlayer() ) then return end
  158.  
  159.     -- local tr = util.GetPlayerTrace( LocalPlayer(), LocalPlayer():GetAimVector() )
  160.     -- local trace = util.TraceLine( tr )
  161.     -- local ply = trace.Entity
  162.     -- if ply and ply:IsValid() and ply:IsPlayer() and self:ShouldRevealPlayer(ply) then
  163.     if false then
  164.         self.TargetSize = self.Large
  165.         self.playerInfo:SetPlayer( trace.Entity )
  166.         locktime = CurTime()
  167.     end
  168.  
  169.     if locktime + 2 < CurTime() then
  170.         self.TargetSize = self.Small
  171.     end
  172.  
  173.     if self.Size ~= self.TargetSize then
  174.         self.Size = math.Approach( self.Size, self.TargetSize, (math.abs( self.Size - self.TargetSize ) + 1) * 8 * FrameTime() )
  175.         self:PerformLayout()
  176.     end
  177.  
  178.     self.total:SetText( timeToStr( LocalPlayer():GetUTimeTotalTime() ) )
  179.     self.session:SetText( timeToStr( LocalPlayer():GetUTimeSessionTime() ) )
  180. end
  181.  
  182. -----------------------------------------------------------
  183. --   Name: PerformLayout
  184. -----------------------------------------------------------
  185. function PANEL:PerformLayout()
  186.     self:SetSize( self:GetWide(), self.Size )
  187.  
  188.     self.lblTotalTime:SetSize( 52, 18 )
  189.     self.lblTotalTime:SetPos( 8, 2 )
  190.     self.lblTotalTime:SetText( "Total: " )
  191.  
  192.     self.lblSessionTime:SetSize( 52, 18 )
  193.     self.lblSessionTime:SetPos( 8, 20 )
  194.     self.lblSessionTime:SetText( "Session: " )
  195.  
  196.     self.total:SetSize( self:GetWide() - 52, 18 )
  197.     self.total:SetPos( 52, 2 )
  198.  
  199.     self.session:SetSize( self:GetWide() - 52, 18 )
  200.     self.session:SetPos( 52, 20 )
  201.  
  202.     self.playerInfo:SetPos( 0, 42 )
  203.     self.playerInfo:SetSize( self:GetWide() - 8, self:GetTall() - 42 )
  204. end
  205.  
  206. vgui.Register( "UTimeMain", PANEL, "Panel" )
  207.  
  208. local INFOPANEL = {}
  209.  
  210. -----------------------------------------------------------
  211. --   Name: Init
  212. -----------------------------------------------------------
  213. function INFOPANEL:Init()
  214.     self.lblTotalTime       = vgui.Create( "DLabel", self )
  215.     self.lblSessionTime     = vgui.Create( "DLabel", self )
  216.     self.lblNick            = vgui.Create( "DLabel", self )
  217.  
  218.     self.total              = vgui.Create( "DLabel", self )
  219.     self.session            = vgui.Create( "DLabel", self )
  220.     self.nick               = vgui.Create( "DLabel", self )
  221. end
  222.  
  223. -----------------------------------------------------------
  224. --   Name: SetPlayer
  225. -----------------------------------------------------------
  226. function INFOPANEL:SetPlayer( ply )
  227.         self.Player = ply
  228. end
  229.  
  230. -----------------------------------------------------------
  231. --   Name: ApplySchemeSettings
  232. -----------------------------------------------------------
  233. function INFOPANEL:ApplySchemeSettings()
  234.         self.lblTotalTime:SetFont( "DermaDefault" )
  235.         self.lblSessionTime:SetFont( "DermaDefault" )
  236.         self.lblNick:SetFont( "DermaDefault" )
  237.         self.total:SetFont( "DermaDefault" )
  238.         self.session:SetFont( "DermaDefault" )
  239.         self.nick:SetFont( "DermaDefault" )
  240.  
  241.         self.lblTotalTime:SetTextColor( color_black )
  242.         self.lblSessionTime:SetTextColor( color_black )
  243.         self.lblNick:SetTextColor( color_black )
  244.         self.total:SetTextColor( color_black )
  245.         self.session:SetTextColor( color_black )
  246.         self.nick:SetTextColor( color_black )
  247. end
  248.  
  249. -----------------------------------------------------------
  250. --   Name: Think
  251. -----------------------------------------------------------
  252. function INFOPANEL:Think()
  253.         local ply = self.Player
  254.         if not ply or not ply:IsValid() or not ply:IsPlayer() then -- Disconnected
  255.                 self:GetParent().TargetSize = self:GetParent().Small
  256.                 return
  257.         end
  258.  
  259.         self.total:SetText( timeToStr( ply:GetUTime() + CurTime() - ply:GetUTimeStart() ) )
  260.         self.session:SetText( timeToStr( CurTime() - ply:GetUTimeStart() ) )
  261.         self.nick:SetText( ply:Nick() )
  262. end
  263.  
  264. -----------------------------------------------------------
  265. --   Name: PerformLayout
  266. -----------------------------------------------------------
  267. function INFOPANEL:PerformLayout()
  268.         self.lblNick:SetSize( 52, 18 )
  269.         self.lblNick:SetPos( 8, 0 )
  270.         self.lblNick:SetText( "Nick: " )
  271.  
  272.         self.lblTotalTime:SetSize( 52, 18 )
  273.         self.lblTotalTime:SetPos( 8, 18 )
  274.         self.lblTotalTime:SetText( "Total: " )
  275.  
  276.         self.lblSessionTime:SetSize( 52, 18 )
  277.         self.lblSessionTime:SetPos( 8, 36 )
  278.         self.lblSessionTime:SetText( "Session: " )
  279.  
  280.         self.nick:SetSize( self:GetWide() - 52, 18 )
  281.         self.nick:SetPos( 52, 0 )
  282.  
  283.         self.total:SetSize( self:GetWide() - 52, 18 )
  284.         self.total:SetPos( 52, 18 )
  285.  
  286.         self.session:SetSize( self:GetWide() - 52, 18 )
  287.         self.session:SetPos( 52, 36 )
  288. end
  289.  
  290. -----------------------------------------------------------
  291. --   Name: Paint
  292. -----------------------------------------------------------
  293. function INFOPANEL:Paint()
  294.         return true
  295. end
  296.  
  297. vgui.Register( "UTimePlayerInfo", INFOPANEL, "Panel" )
  298.  
  299.  
  300.  
  301. ----------------------------------------------------------------------------------------------------------
  302. -- Now for the control panels!
  303. ----------------------------------------------------------------------------------------------------------
  304.  
  305. function resetCvars()
  306.         RunConsoleCommand( "utime_outsidecolor_r", "0" )
  307.         RunConsoleCommand( "utime_outsidecolor_g", "150" )
  308.         RunConsoleCommand( "utime_outsidecolor_b", "245" )
  309.  
  310.         RunConsoleCommand( "utime_outsidetext_r", "255" )
  311.         RunConsoleCommand( "utime_outsidetext_g", "255" )
  312.         RunConsoleCommand( "utime_outsidetext_b", "255" )
  313.  
  314.         RunConsoleCommand( "utime_insidecolor_r", "250" )
  315.         RunConsoleCommand( "utime_insidecolor_g", "250" )
  316.         RunConsoleCommand( "utime_insidecolor_b", "245" )
  317.  
  318.         RunConsoleCommand( "utime_insidetext_r", "0" )
  319.         RunConsoleCommand( "utime_insidetext_g", "0" )
  320.         RunConsoleCommand( "utime_insidetext_b", "0" )
  321.  
  322.         RunConsoleCommand( "utime_pos_x", "98" )
  323.         RunConsoleCommand( "utime_pos_y", "8" )
  324.         buildCP( controlpanel.Get( "Utime" ) )
  325. end
  326. concommand.Add( "utime_reset", resetCvars )
  327.  
  328. function buildCP( cpanel )
  329.         if not cpanel then return end
  330.         cpanel:ClearControls()
  331.         cpanel:AddControl( "Header", { Text = "UTime by Megiddo (Team Ulysses)" } )
  332.         cpanel:AddControl( "Checkbox", { Label = "Enable", Command = "utime_enable" }  )
  333.         cpanel:AddControl( "Slider", { Label = "Position X", Command = "utime_pos_x", Type = "Float", Min = "0", Max = "100" }  )
  334.         cpanel:AddControl( "Slider", { Label = "Position Y", Command = "utime_pos_y", Type = "Float", Min = "0", Max = "100" }  )
  335.         cpanel:AddControl( "Color", { Label = "Outside Color", Red = "utime_outsidecolor_r", Green = "utime_outsidecolor_g", Blue = "utime_outsidecolor_b", ShowAlpha = "0", ShowHSV = "1", ShowRGB = "1", Multiplier = "255" }  )
  336.         cpanel:AddControl( "Color", { Label = "Outside Text Color", Red = "utime_outsidetext_r", Green = "utime_outsidetext_g", Blue = "utime_outsidetext_b", ShowAlpha = "0", ShowHSV = "1", ShowRGB = "1", Multiplier = "255" }  )
  337.         cpanel:AddControl( "Color", { Label = "Inside Color", Red = "utime_insidecolor_r", Green = "utime_insidecolor_g", Blue = "utime_insidecolor_b", ShowAlpha = "0", ShowHSV = "1", ShowRGB = "1", Multiplier = "255" }  )
  338.         cpanel:AddControl( "Color", { Label = "Inside Text Color", Red = "utime_insidetext_r", Green = "utime_insidetext_g", Blue = "utime_insidetext_b", ShowAlpha = "0", ShowHSV = "1", ShowRGB = "1", Multiplier = "255" }  )
  339.         cpanel:AddControl( "Button", { Text = "Reset", Label = "Reset colors and position", Command = "utime_reset" } )
  340. end
  341.  
  342. function spawnMenuOpen()
  343.         buildCP( controlpanel.Get( "Utime" ) )
  344. end
  345. hook.Add( "SpawnMenuOpen", "UtimeSpawnMenuOpen", spawnMenuOpen )
  346.  
  347. function popToolMenu()
  348.         spawnmenu.AddToolMenuOption( "Utilities", "Utime Controls", "Utime", "Utime", "", "", buildCP )
  349. end
  350. hook.Add( "PopulateToolMenu", "UtimePopulateTools", popToolMenu )
  351.  
  352. function onEntCreated( ent )
  353.         if LocalPlayer():IsValid() then -- LocalPlayer was created and is valid now
  354.                 if utime_outsidecolor_r:GetInt() == 256 then resetCvars() end
  355.         end
  356. end
  357. hook.Add( "OnEntityCreated", "UTimeLocalPlayerCheck", onEntCreated ) -- Flag server when we created LocalPlayer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement