Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. -- make the grey box
  2.  
  3. local P = {}
  4.     AccessorFunc(P, "m_bkgc", "BackgroundColor")
  5.     AccessorFunc(P, "m_lnc", "LineColor")
  6.     AccessorFunc(P, "m_Border", "BorderSize", FORCE_NUMBER)
  7.     function P:SetTexture(txt)
  8.         if type(txt) == "string" then
  9.             txt = surface.GetTextureID(txt)
  10.         elseif type(txt) ~= "number" then
  11.             txt = -1
  12.         end
  13.         self.m_Texture = txt
  14.     end
  15.     function P:GetTexture() return self.m_Texture end
  16.     AccessorFunc(P, "m_txtc", "TextureColor")
  17.     AccessorFunc(P, "m_btnsp", "ButtonSpacing")
  18.    
  19.     function P:GetButtons()
  20.         return m_btns
  21.     end
  22.    
  23.     function P:Init()
  24.         local W, H = ScrW(), ScrH()
  25.         local w, h = W/3, H/5
  26.         local x, y = W-w, H-h
  27.  
  28.         self.m_btns = {}
  29.         self:SetSize(w, h)
  30.         self:SetPos(x, y)
  31.        
  32.         self:SetBorderSize(0)
  33.         self:SetBackgroundColor(Color(0, 0, 0, 200))
  34.         self:SetLineColor(Color(100, 100, 100, 255))
  35.         self:SetTextureColor(Color(150,150,150, 75))
  36.         self:SetTexture"gui/center_gradient"
  37.        
  38.         self:SetButtonSpacing(20)
  39.     end
  40.  
  41.     function P:Paint()
  42.         local w, h = self:GetSize()
  43.        
  44.         draw.RoundedBox(self:GetBorderSize(), 0, 0, w, h, self:GetBackgroundColor())
  45.         do  local c = self:GetLineColor()
  46.             surface.SetDrawColor(c.r, c.g, c.b, c.a)
  47.         end
  48.         surface.DrawOutlinedRect(0, 0, w, h)
  49.        
  50.         surface.SetTexture(self:GetTexture())
  51.         do  local c = self:GetTextureColor()
  52.             surface.SetDrawColor(c.r, c.g, c.b, c.a)
  53.         end
  54.         surface.DrawTexturedRect(0, 0, w, h)
  55.         return true
  56.     end
  57.    
  58.     function P:AddButton(btn)
  59.         table.insert(self.m_btns, btn)
  60.         btn:SetParent(self)
  61.         self:InvalidateLayout()
  62.     end
  63.    
  64.     function P:PerformLayout()
  65.         local w, h = self:GetSize()
  66.         local space = self:GetButtonSpacing()
  67.  
  68.         local bw = (w - space * (1 + #self.m_btns)) / #self.m_btns
  69.         local bt = h - space * 2
  70.         for i, btn in ipairs(self.m_btns) do
  71.             btn:SetPos(space * i + bw * (i-1), space)
  72.             btn:SetSize(bw, bt)
  73.         end
  74.     end
  75. vgui.Register("sunControlPanel", P, "DPanel")
  76.  
  77. local ButtonInfo = {
  78.     {mat = "VGUI/entities/npc_hunter",      func = function(btn) print"ASD" end},
  79.     {mat = "VGUI/entities/npc_combine_s",   func = function(btn) print"SDS" end},
  80.     {mat = "VGUI/entities/npc_metropolice", func = function(btn) print"FGD" end}
  81. }
  82. hook.Add("InitPostEntity", "sunrisedev", function()
  83.     local basePanel = vgui.Create"sunControlPanel"
  84.  
  85.     for i, bdata in ipairs(ButtonInfo) do
  86.         local btn = vgui.Create("DImageButton")
  87.             btn:SetMaterial(bdata.mat)
  88.             btn.DoClick = bdata.func
  89.         basePanel:AddButton(btn)
  90.     end
  91. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement