/23d9b358e32f51a2eb
Created 6 months ago...
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
local PANEL = {}
AccessorFunc(PANEL, "m_body", "Body")
XeninUI:CreateFont("XeninUI.SidebarV2.Name", 20)
XeninUI:CreateFont("XeninUI.SidebarV2.Desc", 16)
XeninUI:CreateFont("XeninUI.SidebarV2.DescSmall", 14)
function PANEL:Init()
self.Scroll = self:Add("XeninUI.ScrollPanel")
self.Scroll:Dock(FILL)
self.Scroll.VBar:SetWide(0)
self.Sidebar = {}
self.Panels = {}
end
function PANEL:CreateDivider(startCol, endCol)
startCol = startCol or Color(164, 43, 115)
endCol = endCol or Color(198, 66, 110)
local divider = self.Scroll:Add("DPanel")
divider:Dock(TOP)
divider:SetTall(10)
divider.Paint = function(pnl, w, h)
local aX, aY = pnl:LocalToScreen()
draw.SimpleLinearGradient(aX + 4, aY + 4, w - 8, h - 8, startCol, endCol, true)
end
end
function PANEL:CreatePanel(name, desc, panelClass, icon, tbl)
tbl = tbl or {}
tbl.colors = tbl.colors or {}
local startCol = tbl.colors[1] or Color(158, 53, 210)
local endCol = tbl.colors[2] or Color(109, 77, 213)
local btn = self.Scroll:Add("DButton")
btn:Dock(TOP)
btn.Name = name
btn.Desc = desc or ""
btn.Icon = icon
btn.Tbl = tbl
btn.PanelClass = panelClass
btn:SetTall(tbl.Height or 64)
btn:SetText("")
btn.GradientAlpha = 0
btn.SmallFont = btn.Desc:len() > 20
btn.DescFont = not btn.SmallFont and "XeninUI.SidebarV2.Desc" or "XeninUI.SidebarV2.DescSmall"
XeninUI:DownloadIcon(btn, icon)
btn.Paint = function(pnl, w, h)
XeninUI:Mask(function()
XeninUI:DrawRoundedBox(0, 0, 0, w, h, color_white)
end, function()
local aX, aY = pnl:LocalToScreen()
draw.SimpleLinearGradient(aX, aY, w, h, ColorAlpha(startCol, pnl.GradientAlpha), ColorAlpha(endCol, pnl.GradientAlpha), true)
end)
local x = icon and h or 12
XeninUI:DrawIcon(16, 16, h - 32, h - 32, pnl)
XeninUI:DrawShadowText(name, "XeninUI.SidebarV2.Name", x, h / 2 + (pnl.SmallFont and 1 or 0), color_white, TEXT_ALIGN_LEFT, desc and TEXT_ALIGN_BOTTOM or TEXT_ALIGN_CENTER, 1, 125)
if desc then
XeninUI:DrawShadowText(desc, pnl.DescFont, x, h / 2 + (pnl.SmallFont and 1 or 0), Color(171, 171, 171), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP, 1, 125)
end
end
btn.OnCursorEntered = function(pnl)
if (self.Active == btn.Id) then return end
pnl:Lerp("GradientAlpha", 127.5)
end
btn.OnCursorExited = function(pnl)
if (self.Active == btn.Id) then return end
pnl:Lerp("GradientAlpha", 0)
end
btn.DoClick = function(pnl)
self:SetActive(pnl.Id)
end
local body = self:GetBody()
if not IsValid(body) then
ErrorNoHalt("Failed to find body for panel " .. tostring(panelClass))
return
end
if not vgui.GetControlTable(panelClass) then
ErrorNoHalt("Failed to create panel for " .. tostring(panelClass) .. ": component not registered")
return
end
body = body:Add(panelClass or "DPanel")
if not IsValid(body) then
ErrorNoHalt("Failed to create panel for " .. tostring(panelClass))
return
end
body:Dock(FILL)
body.Data = tbl
body:SetVisible(false)
if body.SetData then
body:SetData(tbl)
end
local bodyId = table.insert(self.Panels, body)
self.Panels[bodyId].Id = bodyId
local id = table.insert(self.Sidebar, btn)
self.Sidebar[id].Id = id
end
function PANEL:SetActive(id)
local active = self.Active
self.Active = id
if IsValid(self.Sidebar[active]) then
self.Sidebar[active]:OnCursorExited()
if IsValid(self.Panels[active]) then
self.Panels[active]:SetVisible(false)
end
end
if IsValid(self.Sidebar[id]) then
self.Sidebar[id]:Lerp("GradientAlpha", 255)
if IsValid(self.Panels[id]) then
if (self.Panels[id].Data.recreateOnSwitch and id ~= active) then
local tempData = self.Panels[id].Data
local tempId = self.Panels[id].Id
self.Panels[id]:Remove()
self.Panels[id] = self:GetBody():Add(self.Sidebar[id].PanelClass or "DPanel")
self.Panels[id]:Dock(FILL)
self.Panels[id].Data = tempData
self.Panels[id].Id = tempId
else
self.Panels[id]:SetVisible(true)
end
if self.Panels[id].OnSwitchedTo then
self.Panels[id]:OnSwitchedTo(self.Panels[id].Data)
end
end
end
end
function PANEL:SetActiveByName(name)
for i, v in ipairs(self.Sidebar) do
if (v.Name == name) then
self:SetActive(i)
break
end
end
end
function PANEL:Paint(w, h)
XeninUI:DrawRoundedBoxEx(6, 0, 0, w, h, XeninUI.Theme.Primary, false, false, true, false)
end
vgui.Register("XeninUI.SidebarV2", PANEL)