diff --git a/lua/pixelui/core/cl_images.lua b/lua/pixelui/core/cl_images.lua index 912b046..2441139 100644 --- a/lua/pixelui/core/cl_images.lua +++ b/lua/pixelui/core/cl_images.lua @@ -22,6 +22,16 @@ local useProxy = false file.CreateDir(PIXEL.DownloadPath) +local function endsWithExtension(str) + local fileName = str:match(".+/(.-)$") + if not fileName then + return false + end + local extractedExtension = fileName and fileName:match("^.+(%..+)$") + + return extractedExtension and string.sub(str, -#extractedExtension) == extractedExtension or false +end + local function processQueue() if queue[1] then local url, filePath, matSettings, callback = unpack(queue[1]) @@ -31,8 +41,13 @@ local function processQueue() if len > 2097152 then materials[filePath] = Material("nil") else - file.Write(filePath, body) - materials[filePath] = Material("../data/" .. filePath, matSettings or "noclamp smooth mips") + local writeFilePath = filePath + if not endsWithExtension(filePath) then + writeFilePath = filePath .. ".png" + end + + file.Write(writeFilePath, body) + materials[filePath] = Material("../data/" .. writeFilePath, matSettings or "noclamp smooth mips") end callback(materials[filePath]) @@ -52,7 +67,12 @@ end function PIXEL.GetImage(url, callback, matSettings) local protocol = url:match("^([%a]+://)") - local urlWithoutProtocol = string.gsub(url, protocol, "") + local urlWithoutProtocol = url + if not protocol then + protocol = "http://" + else + urlWithoutProtocol = string.gsub(url, protocol, "") + end local fileNameStart = url:find("[^/]+$") if not fileNameStart then @@ -66,10 +86,15 @@ function PIXEL.GetImage(url, callback, matSettings) file.CreateDir(dirPath) + local readFilePath = filePath + if not endsWithExtension(filePath) and file.Exists(filePath .. ".png", "DATA") then + readFilePath = filePath .. ".png" + end + if materials[filePath] then callback(materials[filePath]) - elseif file.Exists(filePath, "DATA") then - materials[filePath] = Material("../data/" .. filePath, matSettings or "noclamp smooth mips") + elseif file.Exists(readFilePath, "DATA") then + materials[filePath] = Material("../data/" .. readFilePath, matSettings or "noclamp smooth mips") callback(materials[filePath]) else table.insert(queue, { @@ -91,6 +116,6 @@ end function PIXEL.GetImgur(id, callback, _, matSettings) - local url = "i.imgur.com/" .. id .. ".png" + local url = "https://i.imgur.com/" .. id .. ".png" PIXEL.GetImage(url, callback, matSettings) -end \ No newline at end of file +end diff --git a/lua/pixelui/drawing/cl_circle.lua b/lua/pixelui/drawing/cl_circle.lua index d13059a..6c5324d 100644 --- a/lua/pixelui/drawing/cl_circle.lua +++ b/lua/pixelui/drawing/cl_circle.lua @@ -17,15 +17,15 @@ do local materials = { - "4c5f5nk", --8 - "mONPuyy", --16 - "icx1Qbq", --32 - "TpwrpKe", --64 - "E8QbV5i", --128 - "wAr5H1x", --256 - "g52zxtK", --512 - "9tHAUp6", --1024 - "XAYX2uH" --2048 + "https://pixel-cdn.lythium.dev/i/srlt7tk7m", --8 + "https://pixel-cdn.lythium.dev/i/l2km82zi", --16 + "https://pixel-cdn.lythium.dev/i/5mqrguuxd", --32 + "https://pixel-cdn.lythium.dev/i/yxh641f2a", --64 + "https://pixel-cdn.lythium.dev/i/yz2n2neu", --128 + "https://pixel-cdn.lythium.dev/i/v4sxyjdd8", --256 + "https://pixel-cdn.lythium.dev/i/nmp8368j", --512 + "https://pixel-cdn.lythium.dev/i/e425w7lrj", --1024 + "https://pixel-cdn.lythium.dev/i/iinrlgj5b" --2048 } local max = math.max @@ -40,7 +40,7 @@ do curSize = curSize + curSize end - PIXEL.DrawImgur(x, y, w, h, id, col) + PIXEL.DrawImage(x, y, w, h, id, col) end end diff --git a/lua/pixelui/drawing/cl_images.lua b/lua/pixelui/drawing/cl_images.lua index 7c8c673..4f1e97a 100644 --- a/lua/pixelui/drawing/cl_images.lua +++ b/lua/pixelui/drawing/cl_images.lua @@ -39,7 +39,7 @@ local materials = {} local grabbingMaterials = {} local getImage = PIXEL.GetImage -PIXEL.GetImgur(PIXEL.ProgressImageID, function(mat) +getImage(PIXEL.ProgressImageURL, function(mat) progressMat = mat end) @@ -86,11 +86,11 @@ function PIXEL.DrawImageRotated(x, y, w, h, rot, url, col) end function PIXEL.DrawImgur(x, y, w, h, imgurId, col) - local url = "i.imgur.com/" .. id .. ".png" + local url = "https://i.imgur.com/" .. imgurId .. ".png" PIXEL.DrawImage(x, y, w, h, url, col) end function PIXEL.DrawImgurRotated(x, y, w, h, rot, imgurId, col) - local url = "i.imgur.com/" .. id .. ".png" + local url = "https://i.imgur.com/" .. imgurId .. ".png" PIXEL.DrawImageRotated(x, y, w, h, rot, url, col) end \ No newline at end of file diff --git a/lua/pixelui/drawing/cl_overheads.lua b/lua/pixelui/drawing/cl_overheads.lua index a0c83f8..13f7ecb 100644 --- a/lua/pixelui/drawing/cl_overheads.lua +++ b/lua/pixelui/drawing/cl_overheads.lua @@ -53,7 +53,7 @@ local function drawOverhead(ent, pos, text, ang, scale) PIXEL.DrawRoundedBox(12, x, y, h, h, PIXEL.Colors.Primary) PIXEL.DrawRoundedBoxEx(12, x + (h - 12), y + h - 20, w + 15, 20, PIXEL.Colors.Primary, false, false, false, true) PIXEL.DrawText(text, "UI.Overhead", x + h + 15, y + 8, PIXEL.Colors.PrimaryText) - PIXEL.DrawImgur(x + 10, y + 10, h - 20, h - 20, Icon, color_white) + PIXEL.DrawImage(x + 10, y + 10, h - 20, h - 20, Icon, color_white) end end3d2d() @@ -95,6 +95,10 @@ end function PIXEL.EnableIconOverheads(new) local oldIcon = Icon + local imgurMatch = (new or ""):match("^[a-zA-Z0-9]+$") + if imgurMatch then + new = "https://i.imgur.com/" .. new .. ".png" + end Icon = new return oldIcon end \ No newline at end of file diff --git a/lua/pixelui/elements/cl_category.lua b/lua/pixelui/elements/cl_category.lua index cea69d6..166725f 100644 --- a/lua/pixelui/elements/cl_category.lua +++ b/lua/pixelui/elements/cl_category.lua @@ -39,7 +39,7 @@ function PANEL:Paint(w, h) self.ArrowRotation = lerp(FrameTime() * 10, self.ArrowRotation, self:GetParent():GetExpanded() and 0 or 90) local arrowSize = h * .45 - PIXEL.DrawImgurRotated(w - h * .3 - PIXEL.Scale(4), h / 2, arrowSize, arrowSize, self.ArrowRotation, "30Bvuwi", PIXEL.Colors.PrimaryText) + PIXEL.DrawImageRotated(w - h * .3 - PIXEL.Scale(4), h / 2, arrowSize, arrowSize, self.ArrowRotation, "https://pixel-cdn.lythium.dev/i/5r7ovslav", PIXEL.Colors.PrimaryText) end vgui.Register("PIXEL.CategoryHeader", PANEL, "PIXEL.Button") diff --git a/lua/pixelui/elements/cl_check_box.lua b/lua/pixelui/elements/cl_check_box.lua index 2c87f37..87cdcc2 100644 --- a/lua/pixelui/elements/cl_check_box.lua +++ b/lua/pixelui/elements/cl_check_box.lua @@ -23,7 +23,7 @@ function PANEL:Init() local boxSize = PIXEL.Scale(20) self:SetSize(boxSize, boxSize) - self:SetImgurID("YvG7VI6") + self:SetImageURL("https://pixel-cdn.lythium.dev/i/7u6uph3x6g") self:SetNormalColor(PIXEL.Colors.Transparent) self:SetHoverColor(PIXEL.Colors.PrimaryText) @@ -54,4 +54,4 @@ function PANEL:PaintBackground(w, h) PIXEL.DrawRoundedBox(PIXEL.Scale(4), 0, 0, w, h, self.BackgroundCol) end -vgui.Register("PIXEL.Checkbox", PANEL, "PIXEL.ImgurButton") \ No newline at end of file +vgui.Register("PIXEL.Checkbox", PANEL, "PIXEL.ImageButton") \ No newline at end of file diff --git a/lua/pixelui/elements/cl_color_picker.lua b/lua/pixelui/elements/cl_color_picker.lua index dab9d43..d7ebdde 100644 --- a/lua/pixelui/elements/cl_color_picker.lua +++ b/lua/pixelui/elements/cl_color_picker.lua @@ -18,17 +18,17 @@ local PANEL = {} local gradientMat = Material("nil") -PIXEL.GetImgur("i0xcO1R", function(mat) +PIXEL.GetImage("https://pixel-cdn.lythium.dev/i/zxlflz5vp", function(mat) gradientMat = mat end) local colorWheelMat = Material("nil") -PIXEL.GetImgur("k5mtok6", function(mat) +PIXEL.GetImage("https://pixel-cdn.lythium.dev/i/4lsnfph3b", function(mat) colorWheelMat = mat end) local pickerMat = Material("nil") -PIXEL.GetImgur("t0k86qy", function(mat) +PIXEL.GetImage("https://pixel-cdn.lythium.dev/i/rhz6llj2", function(mat) pickerMat = mat end) diff --git a/lua/pixelui/elements/cl_combo_box.lua b/lua/pixelui/elements/cl_combo_box.lua index 0ff09f5..c0f4300 100644 --- a/lua/pixelui/elements/cl_combo_box.lua +++ b/lua/pixelui/elements/cl_combo_box.lua @@ -205,7 +205,7 @@ end function PANEL:PaintOver(w, h) local dropBtnSize = PIXEL.Scale(8) - PIXEL.DrawImgur(w - dropBtnSize - PIXEL.Scale(8), h / 2 - dropBtnSize / 2, dropBtnSize, dropBtnSize, "30Bvuwi", PIXEL.Colors.PrimaryText) + PIXEL.DrawImage(w - dropBtnSize - PIXEL.Scale(8), h / 2 - dropBtnSize / 2, dropBtnSize, dropBtnSize, "https://pixel-cdn.lythium.dev/i/5r7ovslav", PIXEL.Colors.PrimaryText) end vgui.Register("PIXEL.ComboBox", PANEL, "PIXEL.TextButton") \ No newline at end of file diff --git a/lua/pixelui/elements/cl_frame.lua b/lua/pixelui/elements/cl_frame.lua index ec4738d..ee3a747 100644 --- a/lua/pixelui/elements/cl_frame.lua +++ b/lua/pixelui/elements/cl_frame.lua @@ -25,13 +25,23 @@ AccessorFunc(PANEL, "ScreenLock", "ScreenLock", FORCE_BOOL) AccessorFunc(PANEL, "RemoveOnClose", "RemoveOnClose", FORCE_BOOL) AccessorFunc(PANEL, "Title", "Title", FORCE_STRING) -AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) +AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) -- Deprecated +AccessorFunc(PANEL, "ImageURL", "ImageURL", FORCE_STRING) + +function PANEL:SetImgurID(id) + self:SetImageURL("https://i.imgur.com/" .. id .. ".png") + self.ImgurID = id +end + +function PANEL:GetImgurID() + return self:GetImageURL():match("https://i.imgur.com/(.-).png") +end PIXEL.RegisterFont("UI.FrameTitle", "Open Sans Bold", 22) function PANEL:Init() - self.CloseButton = vgui.Create("PIXEL.ImgurButton", self) - self.CloseButton:SetImgurID("z1uAU0b") + self.CloseButton = vgui.Create("PIXEL.ImageButton", self) + self.CloseButton:SetImageURL("https://pixel-cdn.lythium.dev/i/fh640z2o") self.CloseButton:SetNormalColor(PIXEL.Colors.PrimaryText) self.CloseButton:SetHoverColor(PIXEL.Colors.Negative) self.CloseButton:SetClickColor(PIXEL.Colors.Negative) @@ -142,7 +152,7 @@ function PANEL:OnMouseReleased() self:MouseCapture(false) end -function PANEL:CreateSidebar(defaultItem, imgurID, imgurScale, imgurYOffset, buttonYOffset) +function PANEL:CreateSidebar(defaultItem, imageURL, imageScale, imageYOffset, buttonYOffset) if IsValid(self.SideBar) then return end self.SideBar = vgui.Create("PIXEL.Sidebar", self) @@ -153,9 +163,17 @@ function PANEL:CreateSidebar(defaultItem, imgurID, imgurScale, imgurYOffset, but end) end - if imgurID then self.SideBar:SetImgurID(imgurID) end - if imgurScale then self.SideBar:SetImgurScale(imgurScale) end - if imgurYOffset then self.SideBar:SetImgurOffset(imgurYOffset) end + if imageURL then + local imgurMatch = (imageURL or ""):match("^[a-zA-Z0-9]+$") + if imgurMatch then + imageURL = "https://i.imgur.com/" .. imageURL .. ".png" + end + + self.SideBar:SetImageURL(imageURL) + end + + if imageScale then self.SideBar:SetImageScale(imageScale) end + if imageYOffset then self.SideBar:SetImageOffset(imageYOffset) end if buttonYOffset then self.SideBar:SetButtonOffset(buttonYOffset) end return self.SideBar @@ -219,10 +237,10 @@ function PANEL:OnClose() end function PANEL:PaintHeader(x, y, w, h) PIXEL.DrawRoundedBoxEx(PIXEL.Scale(6), x, y, w, h, PIXEL.Colors.Header, true, true) - local imgurID = self:GetImgurID() - if imgurID then + local imageURL = self:GetImageURL() + if imageURL then local iconSize = h * .6 - PIXEL.DrawImgur(PIXEL.Scale(6), x + (h - iconSize) / 2, y + iconSize, iconSize, imgurID, color_white) + PIXEL.DrawImage(PIXEL.Scale(6), x + (h - iconSize) / 2, y + iconSize, iconSize, imageURL, color_white) PIXEL.DrawSimpleText(self:GetTitle(), "UI.FrameTitle", x + PIXEL.Scale(12) + iconSize, y + h / 2, PIXEL.Colors.PrimaryText, nil, TEXT_ALIGN_CENTER) return end diff --git a/lua/pixelui/elements/cl_image_button.lua b/lua/pixelui/elements/cl_image_button.lua new file mode 100644 index 0000000..b953efa --- /dev/null +++ b/lua/pixelui/elements/cl_image_button.lua @@ -0,0 +1,67 @@ +--[[ + PIXEL UI - Copyright Notice + © 2023 Thomas O'Sullivan - All rights reserved + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +--]] + +local PANEL = {} + +AccessorFunc(PANEL, "ImageURL", "ImageURL", FORCE_STRING) +AccessorFunc(PANEL, "ImageSize", "ImageSize", FORCE_NUMBER) +AccessorFunc(PANEL, "NormalColor", "NormalColor") +AccessorFunc(PANEL, "HoverColor", "HoverColor") +AccessorFunc(PANEL, "ClickColor", "ClickColor") +AccessorFunc(PANEL, "DisabledColor", "DisabledColor") + +function PANEL:Init() + self.ImageCol = PIXEL.CopyColor(color_white) + self:SetImageURL(PIXEL.ProgressImageURL) + + self:SetNormalColor(color_white) + self:SetHoverColor(color_white) + self:SetClickColor(color_white) + self:SetDisabledColor(color_white) + + self:SetImageSize(1) +end + +function PANEL:PaintBackground(w, h) end + +function PANEL:Paint(w, h) + self:PaintBackground(w, h) + + local imageSize = h * self:GetImageSize() + local imageOffset = (h - imageSize) / 2 + + if not self:IsEnabled() then + PIXEL.DrawImage(imageOffset, imageOffset, imageSize, imageSize, self:GetImageURL(), self:GetDisabledColor()) + return + end + + local col = self:GetNormalColor() + + if self:IsHovered() then + col = self:GetHoverColor() + end + + if self:IsDown() or self:GetToggle() then + col = self:GetClickColor() + end + + self.ImageCol = PIXEL.LerpColor(FrameTime() * 12, self.ImageCol, col) + + PIXEL.DrawImage(imageOffset, imageOffset, imageSize, imageSize, self:GetImageURL(), self.ImageCol) +end + +vgui.Register("PIXEL.ImageButton", PANEL, "PIXEL.Button") \ No newline at end of file diff --git a/lua/pixelui/elements/cl_imgur_button.lua b/lua/pixelui/elements/cl_imgur_button.lua index a193d56..c120235 100644 --- a/lua/pixelui/elements/cl_imgur_button.lua +++ b/lua/pixelui/elements/cl_imgur_button.lua @@ -18,50 +18,27 @@ local PANEL = {} AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) -AccessorFunc(PANEL, "ImageSize", "ImageSize", FORCE_NUMBER) -AccessorFunc(PANEL, "NormalColor", "NormalColor") -AccessorFunc(PANEL, "HoverColor", "HoverColor") -AccessorFunc(PANEL, "ClickColor", "ClickColor") -AccessorFunc(PANEL, "DisabledColor", "DisabledColor") +AccessorFunc(PANEL, "ImgurSize", "ImgurSize", FORCE_NUMBER) -function PANEL:Init() - self.ImageCol = PIXEL.CopyColor(color_white) - self:SetImgurID("635PPvg") - - self:SetNormalColor(color_white) - self:SetHoverColor(color_white) - self:SetClickColor(color_white) - self:SetDisabledColor(color_white) - - self:SetImageSize(1) +function PANEL:SetImgurID(id) + self.ImgurID = id + self:SetImageURL("https://i.imgur.com/" .. id .. ".png") end -function PANEL:PaintBackground(w, h) end - -function PANEL:Paint(w, h) - self:PaintBackground(w, h) - - local imageSize = h * self:GetImageSize() - local imageOffset = (h - imageSize) / 2 - - if not self:IsEnabled() then - PIXEL.DrawImgur(imageOffset, imageOffset, imageSize, imageSize, self:GetImgurID(), self:GetDisabledColor()) - return - end - - local col = self:GetNormalColor() - - if self:IsHovered() then - col = self:GetHoverColor() - end +function PANEL:GetImgurID() + return (self:GetImageURL() or ""):match("https://i.imgur.com/(.*).png") +end - if self:IsDown() or self:GetToggle() then - col = self:GetClickColor() - end +function PANEL:SetImgurSize(size) + self.ImgurSize = size + self:SetImageSize(size, size) +end - self.ImageCol = PIXEL.LerpColor(FrameTime() * 12, self.ImageCol, col) +function PANEL:GetImgurSize() + return self:GetImageSize() +end - PIXEL.DrawImgur(imageOffset, imageOffset, imageSize, imageSize, self:GetImgurID(), self.ImageCol) +function PANEL:Init() end -vgui.Register("PIXEL.ImgurButton", PANEL, "PIXEL.Button") \ No newline at end of file +vgui.Register("PIXEL.ImgurButton", PANEL, "PIXEL.ImageButton") \ No newline at end of file diff --git a/lua/pixelui/elements/cl_menu_option.lua b/lua/pixelui/elements/cl_menu_option.lua index 5daa00d..d41f486 100644 --- a/lua/pixelui/elements/cl_menu_option.lua +++ b/lua/pixelui/elements/cl_menu_option.lua @@ -74,7 +74,7 @@ function PANEL:Paint(w, h) if not self.SubMenu then return end local dropBtnSize = PIXEL.Scale(8) - PIXEL.DrawImgur(w - dropBtnSize - PIXEL.Scale(6), h / 2 - dropBtnSize / 2, dropBtnSize, dropBtnSize, "gXg3U6X", PIXEL.Colors.PrimaryText) + PIXEL.DrawImage(w - dropBtnSize - PIXEL.Scale(6), h / 2 - dropBtnSize / 2, dropBtnSize, dropBtnSize, "https://pixel-cdn.lythium.dev/i/ce2kyfb88", PIXEL.Colors.PrimaryText) end function PANEL:OnPressed(mousecode) diff --git a/lua/pixelui/elements/cl_sidebar.lua b/lua/pixelui/elements/cl_sidebar.lua index 7cf2984..e1c9bc0 100644 --- a/lua/pixelui/elements/cl_sidebar.lua +++ b/lua/pixelui/elements/cl_sidebar.lua @@ -18,142 +18,190 @@ local PANEL = {} AccessorFunc(PANEL, "Name", "Name", FORCE_STRING) -AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) +AccessorFunc(PANEL, "ImageURL", "ImageURL", FORCE_STRING) AccessorFunc(PANEL, "DrawOutline", "DrawOutline", FORCE_BOOL) +AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) -- Deprecated + +function PANEL:SetImgurID(id) + self:SetImageURL("https://i.imgur.com/" .. id .. ".png") + self.ImgurID = id +end + +function PANEL:GetImgurID() + return self:GetImageURL():match("https://i.imgur.com/(.-).png") +end PIXEL.RegisterFont("SidebarItem", "Open Sans Bold", 19) function PANEL:Init() - self:SetName("N/A") - self:SetDrawOutline(true) + self:SetName("N/A") + self:SetDrawOutline(true) - self.TextCol = PIXEL.CopyColor(PIXEL.Colors.SecondaryText) - self.BackgroundCol = PIXEL.CopyColor(PIXEL.Colors.Transparent) - self.BackgroundHoverCol = ColorAlpha(PIXEL.Colors.Scroller, 80) + self.TextCol = PIXEL.CopyColor(PIXEL.Colors.SecondaryText) + self.BackgroundCol = PIXEL.CopyColor(PIXEL.Colors.Transparent) + self.BackgroundHoverCol = ColorAlpha(PIXEL.Colors.Scroller, 80) end function PANEL:Paint(w, h) - local textCol = PIXEL.Colors.SecondaryText - local backgroundCol = PIXEL.Colors.Transparent - - if self:IsHovered() then - textCol = PIXEL.Colors.PrimaryText - backgroundCol = self.BackgroundHoverCol - end + local textCol = PIXEL.Colors.SecondaryText + local backgroundCol = PIXEL.Colors.Transparent + + if self:IsHovered() then + textCol = PIXEL.Colors.PrimaryText + backgroundCol = self.BackgroundHoverCol + end + + if self:IsDown() or self:GetToggle() then + textCol = PIXEL.Colors.PrimaryText + backgroundCol = self.BackgroundHoverCol + end + + local animTime = FrameTime() * 12 + self.TextCol = PIXEL.LerpColor(animTime, self.TextCol, textCol) + self.BackgroundCol = PIXEL.LerpColor(animTime, self.BackgroundCol, backgroundCol) + + if self:GetDrawOutline() then PIXEL.DrawRoundedBox(PIXEL.Scale(4), 0, 0, w, h, self.BackgroundCol, PIXEL.Scale(1)) end + + local imageURL = self:GetImageURL() + if imageURL then + local iconSize = h * .65 + PIXEL.DrawImage(PIXEL.Scale(10), (h - iconSize) / 2, iconSize, iconSize, imageURL, self.TextCol) + PIXEL.DrawSimpleText(self:GetName(), "SidebarItem", PIXEL.Scale(20) + iconSize, h / 2, self.TextCol, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER) + return + end + + PIXEL.DrawSimpleText(self:GetName(), "SidebarItem", PIXEL.Scale(10), h / 2, self.TextCol, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER) +end - if self:IsDown() or self:GetToggle() then - textCol = PIXEL.Colors.PrimaryText - backgroundCol = self.BackgroundHoverCol - end +vgui.Register("PIXEL.SidebarItem", PANEL, "PIXEL.Button") - local animTime = FrameTime() * 12 - self.TextCol = PIXEL.LerpColor(animTime, self.TextCol, textCol) - self.BackgroundCol = PIXEL.LerpColor(animTime, self.BackgroundCol, backgroundCol) +PANEL = {} - if self:GetDrawOutline() then PIXEL.DrawRoundedBox(PIXEL.Scale(4), 0, 0, w, h, self.BackgroundCol, PIXEL.Scale(1)) end +AccessorFunc(PANEL, "ImageURL", "ImageURL", FORCE_STRING) +AccessorFunc(PANEL, "ImageScale", "ImageScale", FORCE_NUMBER) +AccessorFunc(PANEL, "ImageOffset", "ImageOffset", FORCE_NUMBER) +AccessorFunc(PANEL, "ButtonOffset", "ButtonOffset", FORCE_NUMBER) - local imgurID = self:GetImgurID() - if imgurID then - local iconSize = h * .65 - PIXEL.DrawImgur(PIXEL.Scale(10), (h - iconSize) / 2, iconSize, iconSize, imgurID, self.TextCol) - PIXEL.DrawSimpleText(self:GetName(), "SidebarItem", PIXEL.Scale(20) + iconSize, h / 2, self.TextCol, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER) - return - end +AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) -- Deprecated +AccessorFunc(PANEL, "ImgurScale", "ImgurScale", FORCE_NUMBER) -- Deprecated +AccessorFunc(PANEL, "ImgurOffset", "ImgurOffset", FORCE_NUMBER) -- Deprecated - PIXEL.DrawSimpleText(self:GetName(), "SidebarItem", PIXEL.Scale(10), h / 2, self.TextCol, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER) +function PANEL:SetImgurID(id) + self:SetImageURL("https://i.imgur.com/" .. id .. ".png") + self.ImgurID = id end -vgui.Register("PIXEL.SidebarItem", PANEL, "PIXEL.Button") - -PANEL = {} +function PANEL:GetImgurID() + return self:GetImageURL():match("https://i.imgur.com/(.-).png") +end -AccessorFunc(PANEL, "ImgurID", "ImgurID", FORCE_STRING) -AccessorFunc(PANEL, "ImgurScale", "ImgurScale", FORCE_NUMBER) -AccessorFunc(PANEL, "ImgurOffset", "ImgurOffset", FORCE_NUMBER) -AccessorFunc(PANEL, "ButtonOffset", "ButtonOffset", FORCE_NUMBER) +function PANEL:SetImgurScale(scale) + self:SetImageScale(scale) + self.ImgurScale = scale +end -function PANEL:Init() - self.Items = {} +function PANEL:GetImgurScale() + return self:GetImageScale() +end - self.Scroller = vgui.Create("PIXEL.ScrollPanel", self) - self.Scroller:SetBarDockShouldOffset(true) - self.Scroller.LayoutContent = function(s, w, h) - local spacing = PIXEL.Scale(8) - local height = PIXEL.Scale(35) - for k,v in pairs(self.Items) do - v:SetTall(height) - v:Dock(TOP) - v:DockMargin(0, 0, 0, spacing) - end - end +function PANEL:SetImgurOffset(offset) + self:SetImageOffset(offset) + self.ImgurOffset = offset +end - self:SetImgurScale(.6) - self:SetImgurOffset(0) - self:SetButtonOffset(0) +function PANEL:GetImgurOffset() + return self:GetImageOffset() +end - self.BackgroundCol = PIXEL.CopyColor(PIXEL.Colors.Header) +function PANEL:Init() + self.Items = {} + + self.Scroller = vgui.Create("PIXEL.ScrollPanel", self) + self.Scroller:SetBarDockShouldOffset(true) + self.Scroller.LayoutContent = function(s, w, h) + local spacing = PIXEL.Scale(8) + local height = PIXEL.Scale(35) + for k,v in pairs(self.Items) do + v:SetTall(height) + v:Dock(TOP) + v:DockMargin(0, 0, 0, spacing) + end + end + + self:SetImageScale(.6) + self:SetImageOffset(0) + self:SetButtonOffset(0) + + self.BackgroundCol = PIXEL.CopyColor(PIXEL.Colors.Header) end -function PANEL:AddItem(id, name, imgurID, doClick, order) - local btn = vgui.Create("PIXEL.SidebarItem", self.Scroller) +function PANEL:AddItem(id, name, imageURL, doClick, order) + local btn = vgui.Create("PIXEL.SidebarItem", self.Scroller) + + btn:SetZPos(order or table.Count(self.Items) + 1) + btn:SetName(name) + if imageURL then + local imgurMatch = (imageURL or ""):match("^[a-zA-Z0-9]+$") + if imgurMatch then + imageURL = "https://i.imgur.com/" .. imageURL .. ".png" + end - btn:SetZPos(order or table.Count(self.Items) + 1) - btn:SetName(name) - if imgurID then btn:SetImgurID(imgurID) end - btn.Function = doClick + btn:SetImageURL(imageURL) + end + btn.Function = doClick - btn.DoClick = function(s) - self:SelectItem(id) - end + btn.DoClick = function(s) + self:SelectItem(id) + end - self.Items[id] = btn + self.Items[id] = btn - return btn + return btn end function PANEL:RemoveItem(id) - local item = self.Items[id] - if not item then return end + local item = self.Items[id] + if not item then return end - item:Remove() - self.Items[id] = nil + item:Remove() + self.Items[id] = nil - if self.SelectedItem != id then return end - self:SelectItem(next(self.Items)) + if self.SelectedItem != id then return end + self:SelectItem(next(self.Items)) end function PANEL:SelectItem(id) - local item = self.Items[id] - if not item then return end + local item = self.Items[id] + if not item then return end - if self.SelectedItem and self.SelectedItem == id then return end - self.SelectedItem = id + if self.SelectedItem and self.SelectedItem == id then return end + self.SelectedItem = id - for k,v in pairs(self.Items) do - v:SetToggle(false) - end + for k,v in pairs(self.Items) do + v:SetToggle(false) + end - item:SetToggle(true) - item.Function(item) + item:SetToggle(true) + item.Function(item) end function PANEL:PerformLayout(w, h) - local sideSpacing = PIXEL.Scale(7) - local topSpacing = PIXEL.Scale(7) - self:DockPadding(sideSpacing, self:GetImgurID() and w * self:GetImgurScale() + self:GetImgurOffset() + self:GetButtonOffset() + topSpacing * 2 or topSpacing, sideSpacing, topSpacing) + local sideSpacing = PIXEL.Scale(7) + local topSpacing = PIXEL.Scale(7) + self:DockPadding(sideSpacing, self:GetImageURL() and w * self:GetImageScale() + self:GetImageOffset() + self:GetButtonOffset() + topSpacing * 2 or topSpacing, sideSpacing, topSpacing) - self.Scroller:Dock(FILL) - self.Scroller:GetCanvas():DockPadding(0, 0, self.Scroller.VBar.Enabled and sideSpacing or 0, 0) + self.Scroller:Dock(FILL) + self.Scroller:GetCanvas():DockPadding(0, 0, self.Scroller.VBar.Enabled and sideSpacing or 0, 0) end function PANEL:Paint(w, h) - PIXEL.DrawRoundedBoxEx(PIXEL.Scale(6), 0, 0, w, h, self.BackgroundCol, false, false, true) + PIXEL.DrawRoundedBoxEx(PIXEL.Scale(6), 0, 0, w, h, self.BackgroundCol, false, false, true) - local imgurID = self:GetImgurID() - if imgurID then - local imageSize = w * self:GetImgurScale() - PIXEL.DrawImgur((w - imageSize) / 2, self:GetImgurOffset() + PIXEL.Scale(15), imageSize, imageSize, imgurID, color_white) - end + local imageURL = self:GetImageURL() + if imageURL then + local imageSize = w * self:GetImageScale() + PIXEL.DrawImage((w - imageSize) / 2, self:GetImageOffset() + PIXEL.Scale(15), imageSize, imageSize, imageURL, color_white) + end end vgui.Register("PIXEL.Sidebar", PANEL, "Panel") \ No newline at end of file diff --git a/lua/pixelui/elements/cl_slider.lua b/lua/pixelui/elements/cl_slider.lua index 360cab6..3eedb0b 100644 --- a/lua/pixelui/elements/cl_slider.lua +++ b/lua/pixelui/elements/cl_slider.lua @@ -20,10 +20,10 @@ local PANEL = {} function PANEL:Init() self.Fraction = 0 - self.Grip = vgui.Create("PIXEL.ImgurButton", self) + self.Grip = vgui.Create("PIXEL.ImageButton", self) self.Grip:NoClipping(true) - self.Grip:SetImgurID("E8QbV5i") + self.Grip:SetImageURL("https://pixel-cdn.lythium.dev/i/g6e8z4pz") self.Grip:SetNormalColor(PIXEL.CopyColor(PIXEL.Colors.Primary)) self.Grip:SetHoverColor(PIXEL.OffsetColor(PIXEL.Colors.Primary, -15)) self.Grip:SetClickColor(PIXEL.OffsetColor(PIXEL.Colors.Primary, 15)) diff --git a/lua/pixelui/libraries/cl_ui3d2d.lua b/lua/pixelui/libraries/cl_ui3d2d.lua index 28bd4ad..cb3d791 100644 --- a/lua/pixelui/libraries/cl_ui3d2d.lua +++ b/lua/pixelui/libraries/cl_ui3d2d.lua @@ -142,8 +142,8 @@ do --Rendering context creation and mouse position getters local cursorMat local cursorHoverMat - PIXEL.GetImgur("ZcfUhAr", function(mat) cursorMat = mat end) - PIXEL.GetImgur("xo6gm7z", function(mat) cursorHoverMat = mat end) + PIXEL.GetImage("https://pixel-cdn.lythium.dev/i/cyf6d6gzf", function(mat) cursorMat = mat end) + PIXEL.GetImage("https://pixel-cdn.lythium.dev/i/m3m6x59yb", function(mat) cursorHoverMat = mat end) function ui3d2d.drawCursor(x, y, w, h, size) size = size or 20 diff --git a/lua/pixelui/sh_config.lua b/lua/pixelui/sh_config.lua index c5c79d4..b85c86e 100644 --- a/lua/pixelui/sh_config.lua +++ b/lua/pixelui/sh_config.lua @@ -25,9 +25,9 @@ PIXEL.OverrideDermaMenus = 0 --[[ - The Imgur ID of the progress image you want to appear when Imgur content is loading. + The Image URL of the progress image you want to appear when image content is loading. ]] -PIXEL.ProgressImageID = "635PPvg" +PIXEL.ProgressImageURL = "https://pixel-cdn.lythium.dev/i/47qh6kjjh" --[[ The location at which downloaded assets should be stored (relative to the data folder).