dobrograd-13-06-2022/garrysmod/addons/feature-jobs/lua/dbg-jobs/vgui_main.lua
Jonny_Bro (Nikita) e4d5311906 first commit
2023-11-16 15:01:19 +05:00

75 lines
1.8 KiB
Lua

local instance
local PANEL = {}
function PANEL:Init()
-- ALL JOBS
self.available = vgui.Create 'DPanel'
self.available:SetPaintBackground(false)
self:AddSheet('Доступные', self.available, octolib.icons.silk16('world'))
-- MY JOBS
self.active = vgui.Create 'DPanel'
self.active:SetPaintBackground(false)
self:AddSheet('Принятые', self.active, octolib.icons.silk16('tick'))
instance = self
end
function PANEL:AddAvailable(publishData)
if hook.Run('dbg-jobs.canTake', LocalPlayer(), publishData) == false then return end
local button = self.available:Add 'dbg_jobs_button'
button:SetJob(self, publishData)
end
function PANEL:RemoveAvailable(jobID)
for _, button in ipairs(self.available:GetChildren()) do
if button.publishData.id == jobID then
button:Remove()
end
end
end
function PANEL:SetAvailable(publishDatas)
self.available:Clear()
for _, job in pairs(publishDatas) do
self:AddAvailable(job)
end
end
function PANEL:AddActive(job)
local button = self.active:Add 'dbg_jobs_button'
button:SetJob(self, job.publishData, job)
end
function PANEL:SetActive(data)
self.active:Clear()
for _, job in pairs(data or {}) do
self:AddActive(job)
end
end
netstream.Hook('dbg-jobs.syncAvailable', function(publishDatas)
if not IsValid(instance) then return end
instance:SetAvailable(publishDatas)
end)
netstream.Hook('dbg-jobs.syncActive', function(jobs)
if not IsValid(instance) then return end
instance:SetActive(jobs)
end)
netstream.Hook('dbg-jobs.addAvailable', function(publishData)
if not IsValid(instance) then return end
instance:AddAvailable(publishData)
end)
netstream.Hook('dbg-jobs.removeAvailable', function(jobID)
if not IsValid(instance) then return end
instance:RemoveAvailable(jobID)
end)
vgui.Register('dbg_jobs_main', PANEL, 'DPropertySheet')