Advertisement
Guest User

lua

a guest
Mar 29th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.70 KB | None | 0 0
  1.  
  2. --[[------------------------------------------
  3.                     TODO LIST
  4.  
  5. • Make all Items buyable
  6. ------------------------------------------]]--
  7.  
  8. local PANEL = {}
  9.  
  10. local disabledCats = {
  11.     entities = false,
  12.     weapons = false,
  13.     shipments = false,
  14.     ammo = false
  15. }
  16.  
  17. local searchText = nil
  18.  
  19. function PANEL:Init()
  20.  
  21.     self:Dock(FILL)
  22.     self:DockMargin(0, 0, 0, 0)
  23.     self:SetVisible(false)
  24.  
  25.     -- creates a Scrollbar
  26.     self.itemsPanel = self:Add("VoidF4.ScrollPanel")
  27.     self.itemsPanel:DockMargin(0, 100, 0, 0)
  28.  
  29.     -- create panels
  30.     self:CreatePanels()
  31.  
  32. --[[---------------------------------------------------------------------------
  33. Settings: Searchbar
  34. -----------------------------------------------------------------------------]]
  35.  
  36.     local settingsPanel = self:Add("Panel")
  37.     settingsPanel:DockMargin(0, 50, 0, 0)
  38.     settingsPanel:SetSize(1135, 55)
  39.     settingsPanel:SetPos(30, 20)
  40.  
  41.     settingsPanel.Paint = function(self, w, h)
  42.         draw.RoundedBox(3, 0, 0, w, h, VoidF4.Colors.Primary)
  43.     end
  44.  
  45.     local searchBarPanel = settingsPanel:Add("DTextEntry")
  46.     searchBarPanel:SetPos(10, 10)
  47.     searchBarPanel:SetSize(300, 35)
  48.     searchBarPanel:SetValue("Search by name...")
  49.  
  50.     searchBarPanel.Paint = function(self, w, h)
  51.         draw.RoundedBox(3, 0, 0, w, h, VoidF4.Colors.BackgroundTransparent)
  52.         if (!self:IsEditing() && searchText == nil) then
  53.             draw.SimpleText("Search by name...", "VoidF4.I22", 10, 5, VoidF4.Colors.Gray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  54.         else
  55.             searchText = self:GetText()
  56.             draw.SimpleText(searchText, "VoidF4.R22", 10, 5, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  57.         end
  58.     end
  59.  
  60.     searchBarPanel.OnEnter = function(self)
  61.         searchBarPanel:SetValue(searchText)
  62.         local panel = self:GetParent():GetParent()
  63.         panel:CreatePanels()
  64.     end
  65.  
  66.     searchBarPanel.OnGetFocus = function()
  67.         if (seachText == nil) then
  68.             searchBarPanel:SetValue("")
  69.         end
  70.     end
  71.  
  72. --[[---------------------------------------------------------------------------
  73. Settings: Buttons
  74. -----------------------------------------------------------------------------]]
  75.  
  76.     -- entities
  77.     local entitiesPanel = self:Add("Panel")
  78.     entitiesPanel:SetPos(630, 35)
  79.     entitiesPanel:SetSize(100, 25)
  80.  
  81.     entitiesPanel.Paint = function(w, h)
  82.         draw.SimpleText("ENTITIES", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  83.     end
  84.  
  85.     local entitiesButton = entitiesPanel:Add("DCheckBox")
  86.     entitiesButton:SetSize(25, 25)
  87.     entitiesButton:SetPos(70, 0)
  88.  
  89.     entitiesButton.Paint = function(self, w, h)
  90.         VoidF4.PaintCheckBox(w, h, false)
  91.     end
  92.  
  93.     function entitiesButton:OnChange(disabled)
  94.         if (disabled) then
  95.             entitiesButton.Paint = function(self, w, h)
  96.                 VoidF4.PaintCheckBox(w, h, true)
  97.             end
  98.             disabledCats.entities = true
  99.             local panel = self:GetParent():GetParent()
  100.             panel:CreatePanels()
  101.         else
  102.             entitiesButton.Paint = function(self, w, h)
  103.                 VoidF4.PaintCheckBox(w, h, false)
  104.             end
  105.             disabledCats.entities = false
  106.             local panel = self:GetParent():GetParent()
  107.             panel:CreatePanels()
  108.         end
  109.     end
  110.  
  111.  
  112.     -- weapons
  113.     local weaponsPanel = self:Add("Panel")
  114.     weaponsPanel:SetPos(760, 35)
  115.     weaponsPanel:SetSize(110, 25)
  116.  
  117.     weaponsPanel.Paint = function(w, h)
  118.         draw.SimpleText("WEAPONS", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  119.     end
  120.  
  121.     local weaponsButton = weaponsPanel:Add("DCheckBox")
  122.     weaponsButton:SetSize(25, 25)
  123.     weaponsButton:SetPos(85, 0)
  124.  
  125.     weaponsButton.Paint = function(self, w, h)
  126.         VoidF4.PaintCheckBox(w, h, false)
  127.     end
  128.  
  129.     function weaponsButton:OnChange(disabled)
  130.         if (disabled) then
  131.             weaponsButton.Paint = function(self, w, h)
  132.                 VoidF4.PaintCheckBox(w, h, true)
  133.             end
  134.             disabledCats.weapons = true
  135.             local panel = self:GetParent():GetParent()
  136.             panel:CreatePanels()
  137.         else
  138.             weaponsButton.Paint = function(self, w, h)
  139.                 VoidF4.PaintCheckBox(w, h, false)
  140.             end
  141.             disabledCats.weapons = false
  142.             local panel = self:GetParent():GetParent()
  143.             panel:CreatePanels()
  144.         end
  145.     end
  146.  
  147.  
  148.     -- shipments
  149.     local shipmentsPanel = self:Add("Panel")
  150.     shipmentsPanel:SetPos(900, 35)
  151.     shipmentsPanel:SetSize(115, 25)
  152.  
  153.     shipmentsPanel.Paint = function(w, h)
  154.         draw.SimpleText("SHIPMENTS", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  155.     end
  156.  
  157.     local shipmentsButton = shipmentsPanel:Add("DCheckBox")
  158.     shipmentsButton:SetSize(25, 25)
  159.     shipmentsButton:SetPos(90, 0)
  160.  
  161.     shipmentsButton.Paint = function(self, w, h)
  162.         VoidF4.PaintCheckBox(w, h, false)
  163.     end
  164.  
  165.     function shipmentsButton:OnChange(disabled)
  166.         if (disabled) then
  167.             shipmentsButton.Paint = function(self, w, h)
  168.                 VoidF4.PaintCheckBox(w, h, true)
  169.             end
  170.             disabledCats.shipments = true
  171.             local panel = self:GetParent():GetParent()
  172.             panel:CreatePanels()
  173.         else
  174.             shipmentsButton.Paint = function(self, w, h)
  175.                 VoidF4.PaintCheckBox(w, h, false)
  176.             end
  177.             disabledCats.shipments = false
  178.             local panel = self:GetParent():GetParent()
  179.             panel:CreatePanels()
  180.         end
  181.     end
  182.  
  183.  
  184.     -- ammo
  185.     local ammoPanel = self:Add("Panel")
  186.     ammoPanel:SetPos(1050, 35)
  187.     ammoPanel:SetSize(115, 25)
  188.  
  189.     ammoPanel.Paint = function(w, h)
  190.         draw.SimpleText("AMMO", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  191.     end
  192.  
  193.     local ammoButton = ammoPanel:Add("DCheckBox")
  194.     ammoButton:SetSize(25, 25)
  195.     ammoButton:SetPos(55, 0)
  196.  
  197.     ammoButton.Paint = function(self, w, h)
  198.         VoidF4.PaintCheckBox(w, h, false)
  199.     end
  200.  
  201.     function ammoButton:OnChange(disabled)
  202.         if (disabled) then
  203.             ammoButton.Paint = function(self, w, h)
  204.                 VoidF4.PaintCheckBox(w, h, true)
  205.             end
  206.             disabledCats.ammo = true
  207.             local panel = self:GetParent():GetParent()
  208.             panel:CreatePanels()
  209.         else
  210.             ammoButton.Paint = function(self, w, h)
  211.                 VoidF4.PaintCheckBox(w, h, false)
  212.             end
  213.             disabledCats.ammo = false
  214.             local panel = self:GetParent():GetParent()
  215.             panel:CreatePanels()
  216.         end
  217.     end
  218. end
  219.  
  220.  
  221.  
  222. function PANEL:CreatePanels()
  223.  
  224.     self.itemsPanel:Clear()
  225.  
  226.     local y = 0
  227.     local x = 0
  228.  
  229.     -- iterate through all types of categories
  230.     for k, v in pairs(DarkRP.getCategories()) do
  231.  
  232.     local mainCategory = k -- need this later
  233.  
  234.         if (k != "jobs" && k != "vehicles" && disabledCats[k] == false) then
  235.  
  236.             local categoriesTable = v
  237.  
  238.             local categoryTypePanel = self.itemsPanel:Add("Panel")
  239.             categoryTypePanel:SetPos(30, 0 + y)
  240.             categoryTypePanel:SetSize(200, 50)
  241.             categoryTypePanel.Paint = function()
  242.                 draw.SimpleText(string.upper(k), "VoidF4.B28", 0, 0, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  243.             end
  244.  
  245.             -- iterate through all categoires
  246.             for k, v in pairs(categoriesTable) do
  247.            
  248.                 local items = v
  249.                 local counter = 1
  250.  
  251.                 local catColor = v.color
  252.                 local catName = v.name
  253.  
  254.                 -- add each category
  255.                 local categoryPanel = self.itemsPanel:Add("Panel")
  256.                 categoryPanel:SetSize(1090, 40)
  257.                 categoryPanel:SetPos(50, 50 + y)
  258.  
  259.                 -- draw the category header
  260.                 categoryPanel.Paint = function(self, w, h)
  261.                     draw.RoundedBoxEx(8, 0, 0, w, h, catColor, true, true, false, false )
  262.                     draw.SimpleText(catName, "VoidF4.R28", 20, 5, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  263.                 end
  264.  
  265.                 local itemsInPanel = 0
  266.  
  267.                 -- iterate through all items
  268.                 for k, v in pairs(items.members) do
  269.  
  270.                     -- if something is typed in searchbar, skip non-matching items
  271.                     if searchText != nil then
  272.                         local name = string.lower(v.name)
  273.                         local searchInput = string.lower(searchText)
  274.  
  275.                         if (!string.match(name, searchInput)) then continue end
  276.                         PrintTable(items.members)
  277.                     end
  278.                    
  279.                     if (counter % 3 == 1) then
  280.                         y = y + 70
  281.                         x = 0
  282.                     end
  283.                
  284.                     local item = v
  285.                     local itemName = item.name
  286.                     local itemPrice = VoidF4.FormatMoney(item.price)
  287.                     local itemModel = item.model
  288.                     local itemAmount = nil
  289.                     local itemRounds = ""
  290.                     local itemCommand = item.cmd
  291.  
  292.                     if mainCategory == "ammo" then
  293.                         itemCommand = "buyammo "..item.id
  294.                     end
  295.  
  296.                    
  297.                     if (item.amountGiven != nil) then
  298.                         itemAmount = item.amountGiven
  299.                         itemRounds = tostring(itemAmount).."x "
  300.                     end
  301.  
  302.                     -- add each item
  303.                     local itemPanel = self.itemsPanel:Add("DButton")
  304.                     itemPanel:SetText("")
  305.                     itemPanel:SetSize(350, 60)
  306.                     itemPanel:SetPos(50 + x, 30 + y)
  307.  
  308.                     -- draw item
  309.                     itemPanel.Paint = function(self, w, h)
  310.                         draw.RoundedBox(8, 0, 0, w, h, VoidF4.Colors.Primary)
  311.                         draw.SimpleText(itemRounds..itemName, "VoidF4.R26", 70, 10, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  312.                         draw.SimpleText(itemPrice, "VoidF4.R18", 70, 30, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  313.                     end
  314.  
  315.                     -- draw model icon
  316.                     local modelPanel = itemPanel:Add("SpawnIcon")
  317.                     modelPanel:SetPos(10, 5)
  318.                     modelPanel:SetSize(50, 50)
  319.                     modelPanel:SetModel(itemModel)
  320.                     modelPanel:SetEnabled(false)
  321.                     modelPanel:SetToolTip(false)
  322.                     modelPanel:SetSelectable(false)
  323.  
  324.                     function modelPanel:Paint( w, h ) -- override function so no hover effect anymore :)
  325.                         self.OverlayFade = math.Clamp( ( self.OverlayFade or 0 ) - RealFrameTime() * 640 * 2, 0, 255 )
  326.                     end
  327.  
  328.                     -- buy item on click
  329.                     itemPanel.DoClick = function()
  330.                         RunConsoleCommand("say", "/"..itemCommand)
  331.                     end  
  332.  
  333.                     itemsInPanel = itemsInPanel + 1
  334.                     counter = counter + 1
  335.                     x = x + 370  
  336.                    
  337.                 end
  338.                
  339.                 if (itemsInPanel == 0) then
  340.                     categoryPanel:Remove()
  341.                 else
  342.                     y = y + 70
  343.                 end
  344.                
  345.             end
  346.              
  347.             x = 0
  348.             y = y + 50
  349.  
  350.         end
  351.    
  352.     end
  353.  
  354. end
  355.  
  356.  
  357. vgui.Register("VoidF4.Items", PANEL, "Panel")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement