Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[------------------------------------------
- TODO LIST
- • Make all Items buyable
- ------------------------------------------]]--
- local PANEL = {}
- local disabledCats = {
- entities = false,
- weapons = false,
- shipments = false,
- ammo = false
- }
- local searchText = nil
- function PANEL:Init()
- self:Dock(FILL)
- self:DockMargin(0, 0, 0, 0)
- self:SetVisible(false)
- -- creates a Scrollbar
- self.itemsPanel = self:Add("VoidF4.ScrollPanel")
- self.itemsPanel:DockMargin(0, 100, 0, 0)
- -- create panels
- self:CreatePanels()
- --[[---------------------------------------------------------------------------
- Settings: Searchbar
- -----------------------------------------------------------------------------]]
- local settingsPanel = self:Add("Panel")
- settingsPanel:DockMargin(0, 50, 0, 0)
- settingsPanel:SetSize(1135, 55)
- settingsPanel:SetPos(30, 20)
- settingsPanel.Paint = function(self, w, h)
- draw.RoundedBox(3, 0, 0, w, h, VoidF4.Colors.Primary)
- end
- local searchBarPanel = settingsPanel:Add("DTextEntry")
- searchBarPanel:SetPos(10, 10)
- searchBarPanel:SetSize(300, 35)
- searchBarPanel:SetValue("Search by name...")
- searchBarPanel.Paint = function(self, w, h)
- draw.RoundedBox(3, 0, 0, w, h, VoidF4.Colors.BackgroundTransparent)
- if (!self:IsEditing() && searchText == nil) then
- draw.SimpleText("Search by name...", "VoidF4.I22", 10, 5, VoidF4.Colors.Gray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- else
- searchText = self:GetText()
- draw.SimpleText(searchText, "VoidF4.R22", 10, 5, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- end
- searchBarPanel.OnEnter = function(self)
- searchBarPanel:SetValue(searchText)
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- end
- searchBarPanel.OnGetFocus = function()
- if (seachText == nil) then
- searchBarPanel:SetValue("")
- end
- end
- --[[---------------------------------------------------------------------------
- Settings: Buttons
- -----------------------------------------------------------------------------]]
- -- entities
- local entitiesPanel = self:Add("Panel")
- entitiesPanel:SetPos(630, 35)
- entitiesPanel:SetSize(100, 25)
- entitiesPanel.Paint = function(w, h)
- draw.SimpleText("ENTITIES", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- local entitiesButton = entitiesPanel:Add("DCheckBox")
- entitiesButton:SetSize(25, 25)
- entitiesButton:SetPos(70, 0)
- entitiesButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- function entitiesButton:OnChange(disabled)
- if (disabled) then
- entitiesButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, true)
- end
- disabledCats.entities = true
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- else
- entitiesButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- disabledCats.entities = false
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- end
- end
- -- weapons
- local weaponsPanel = self:Add("Panel")
- weaponsPanel:SetPos(760, 35)
- weaponsPanel:SetSize(110, 25)
- weaponsPanel.Paint = function(w, h)
- draw.SimpleText("WEAPONS", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- local weaponsButton = weaponsPanel:Add("DCheckBox")
- weaponsButton:SetSize(25, 25)
- weaponsButton:SetPos(85, 0)
- weaponsButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- function weaponsButton:OnChange(disabled)
- if (disabled) then
- weaponsButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, true)
- end
- disabledCats.weapons = true
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- else
- weaponsButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- disabledCats.weapons = false
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- end
- end
- -- shipments
- local shipmentsPanel = self:Add("Panel")
- shipmentsPanel:SetPos(900, 35)
- shipmentsPanel:SetSize(115, 25)
- shipmentsPanel.Paint = function(w, h)
- draw.SimpleText("SHIPMENTS", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- local shipmentsButton = shipmentsPanel:Add("DCheckBox")
- shipmentsButton:SetSize(25, 25)
- shipmentsButton:SetPos(90, 0)
- shipmentsButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- function shipmentsButton:OnChange(disabled)
- if (disabled) then
- shipmentsButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, true)
- end
- disabledCats.shipments = true
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- else
- shipmentsButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- disabledCats.shipments = false
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- end
- end
- -- ammo
- local ammoPanel = self:Add("Panel")
- ammoPanel:SetPos(1050, 35)
- ammoPanel:SetSize(115, 25)
- ammoPanel.Paint = function(w, h)
- draw.SimpleText("AMMO", "VoidF4.R22", 0, 0, VoidF4.Colors.LightGray, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- local ammoButton = ammoPanel:Add("DCheckBox")
- ammoButton:SetSize(25, 25)
- ammoButton:SetPos(55, 0)
- ammoButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- function ammoButton:OnChange(disabled)
- if (disabled) then
- ammoButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, true)
- end
- disabledCats.ammo = true
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- else
- ammoButton.Paint = function(self, w, h)
- VoidF4.PaintCheckBox(w, h, false)
- end
- disabledCats.ammo = false
- local panel = self:GetParent():GetParent()
- panel:CreatePanels()
- end
- end
- end
- function PANEL:CreatePanels()
- self.itemsPanel:Clear()
- local y = 0
- local x = 0
- -- iterate through all types of categories
- for k, v in pairs(DarkRP.getCategories()) do
- local mainCategory = k -- need this later
- if (k != "jobs" && k != "vehicles" && disabledCats[k] == false) then
- local categoriesTable = v
- local categoryTypePanel = self.itemsPanel:Add("Panel")
- categoryTypePanel:SetPos(30, 0 + y)
- categoryTypePanel:SetSize(200, 50)
- categoryTypePanel.Paint = function()
- draw.SimpleText(string.upper(k), "VoidF4.B28", 0, 0, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- -- iterate through all categoires
- for k, v in pairs(categoriesTable) do
- local items = v
- local counter = 1
- local catColor = v.color
- local catName = v.name
- -- add each category
- local categoryPanel = self.itemsPanel:Add("Panel")
- categoryPanel:SetSize(1090, 40)
- categoryPanel:SetPos(50, 50 + y)
- -- draw the category header
- categoryPanel.Paint = function(self, w, h)
- draw.RoundedBoxEx(8, 0, 0, w, h, catColor, true, true, false, false )
- draw.SimpleText(catName, "VoidF4.R28", 20, 5, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- local itemsInPanel = 0
- -- iterate through all items
- for k, v in pairs(items.members) do
- -- if something is typed in searchbar, skip non-matching items
- if searchText != nil then
- local name = string.lower(v.name)
- local searchInput = string.lower(searchText)
- if (!string.match(name, searchInput)) then continue end
- PrintTable(items.members)
- end
- if (counter % 3 == 1) then
- y = y + 70
- x = 0
- end
- local item = v
- local itemName = item.name
- local itemPrice = VoidF4.FormatMoney(item.price)
- local itemModel = item.model
- local itemAmount = nil
- local itemRounds = ""
- local itemCommand = item.cmd
- if mainCategory == "ammo" then
- itemCommand = "buyammo "..item.id
- end
- if (item.amountGiven != nil) then
- itemAmount = item.amountGiven
- itemRounds = tostring(itemAmount).."x "
- end
- -- add each item
- local itemPanel = self.itemsPanel:Add("DButton")
- itemPanel:SetText("")
- itemPanel:SetSize(350, 60)
- itemPanel:SetPos(50 + x, 30 + y)
- -- draw item
- itemPanel.Paint = function(self, w, h)
- draw.RoundedBox(8, 0, 0, w, h, VoidF4.Colors.Primary)
- draw.SimpleText(itemRounds..itemName, "VoidF4.R26", 70, 10, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- draw.SimpleText(itemPrice, "VoidF4.R18", 70, 30, VoidF4.Colors.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
- end
- -- draw model icon
- local modelPanel = itemPanel:Add("SpawnIcon")
- modelPanel:SetPos(10, 5)
- modelPanel:SetSize(50, 50)
- modelPanel:SetModel(itemModel)
- modelPanel:SetEnabled(false)
- modelPanel:SetToolTip(false)
- modelPanel:SetSelectable(false)
- function modelPanel:Paint( w, h ) -- override function so no hover effect anymore :)
- self.OverlayFade = math.Clamp( ( self.OverlayFade or 0 ) - RealFrameTime() * 640 * 2, 0, 255 )
- end
- -- buy item on click
- itemPanel.DoClick = function()
- RunConsoleCommand("say", "/"..itemCommand)
- end
- itemsInPanel = itemsInPanel + 1
- counter = counter + 1
- x = x + 370
- end
- if (itemsInPanel == 0) then
- categoryPanel:Remove()
- else
- y = y + 70
- end
- end
- x = 0
- y = y + 50
- end
- end
- end
- vgui.Register("VoidF4.Items", PANEL, "Panel")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement