Skip to content

Commit

Permalink
Rename to PulsarUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Lythium4848 committed Dec 31, 2023
1 parent 8db980d commit 030be73
Show file tree
Hide file tree
Showing 65 changed files with 814 additions and 758 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
PIXEL = PIXEL or {}
PIXEL.UI = PIXEL.UI or {}
PIXEL.UI.Version = "2.0.0"
PIXEL.UI.PulsarFork = true
PulsarUI = PulsarUI or {}
PulsarUI.Version = "2.0.0"

function PIXEL.LoadDirectory(path)
function PulsarUI.LoadDirectory(path)
local files, folders = file.Find(path .. "/*", "LUA")

for _, fileName in ipairs(files) do
Expand All @@ -26,20 +24,20 @@ function PIXEL.LoadDirectory(path)
return files, folders
end

function PIXEL.LoadDirectoryRecursive(basePath, onLoad)
local _, folders = PIXEL.LoadDirectory(basePath)
function PulsarUI.LoadDirectoryRecursive(basePath, onLoad)
local _, folders = PulsarUI.LoadDirectory(basePath)

for _, folderName in ipairs(folders) do
PIXEL.LoadDirectoryRecursive(basePath .. "/" .. folderName)
PulsarUI.LoadDirectoryRecursive(basePath .. "/" .. folderName)
end

if onLoad and isfunction(onLoad) then
onLoad()
end
end

PIXEL.LoadDirectoryRecursive("pixelui")
hook.Run("PIXEL.UI.FullyLoaded")
PulsarUI.LoadDirectoryRecursive("pixelui")
hook.Run("PulsarUI.FullyLoaded")

if CLIENT then return end
resource.AddWorkshop("2825396224")
42 changes: 21 additions & 21 deletions lua/pixelui/core/cl_fonts.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

PIXEL.UI.RegisteredFonts = PIXEL.UI.RegisteredFonts or {}
local registeredFonts = PIXEL.UI.RegisteredFonts
PulsarUI.RegisteredFonts = PulsarUI.RegisteredFonts or {}
local registeredFonts = PulsarUI.RegisteredFonts

do
PIXEL.UI.SharedFonts = PIXEL.UI.SharedFonts or {}
local sharedFonts = PIXEL.UI.SharedFonts
PulsarUI.SharedFonts = PulsarUI.SharedFonts or {}
local sharedFonts = PulsarUI.SharedFonts

function PIXEL.RegisterFontUnscaled(name, font, size, weight)
function PulsarUI.RegisterFontUnscaled(name, font, size, weight)
weight = weight or 500

local identifier = font .. size .. ":" .. weight

local fontName = "PIXEL:" .. identifier
local fontName = "PulsarUI:" .. identifier
registeredFonts[name] = fontName

if sharedFonts[identifier] then return end
Expand All @@ -28,41 +28,41 @@ do
end

do
PIXEL.UI.ScaledFonts = PIXEL.UI.ScaledFonts or {}
local scaledFonts = PIXEL.UI.ScaledFonts
PulsarUI.ScaledFonts = PulsarUI.ScaledFonts or {}
local scaledFonts = PulsarUI.ScaledFonts

function PIXEL.RegisterFont(name, font, size, weight)
function PulsarUI.RegisterFont(name, font, size, weight)
scaledFonts[name] = {
font = font,
size = size,
weight = weight
}

PIXEL.RegisterFontUnscaled(name, font, PIXEL.Scale(size), weight)
PulsarUI.RegisterFontUnscaled(name, font, PulsarUI.Scale(size), weight)
end

function PIXEL.GenerateFont(size, weight, font, name)
function PulsarUI.GenerateFont(size, weight, font, name)
weight = weight or 700
PIXEL.Fonts = PIXEL.Fonts or {}
fontName = name or "PIXEL.Font.Size" .. size
PulsarUI.Fonts = PulsarUI.Fonts or {}
fontName = name or "PulsarUI.Font.Size" .. size
font = font or "Rubik"

if !PIXEL.Fonts[fontName] or PIXEL.Fonts[fontName].size != size or PIXEL.Fonts[fontName].weight != weight then
PIXEL.Fonts[fontName] = {
if !PulsarUI.Fonts[fontName] or PulsarUI.Fonts[fontName].size != size or PulsarUI.Fonts[fontName].weight != weight then
PulsarUI.Fonts[fontName] = {
name = fontName,
size = size,
weight = weight
}
PIXEL.RegisterFont(fontName, font, size, weight)
PulsarUI.RegisterFont(fontName, font, size, weight)
return fontName
end

return fontName
end

hook.Add("OnScreenSizeChanged", "PIXEL.UI.ReRegisterFonts", function()
hook.Add("OnScreenSizeChanged", "PulsarUI.ReRegisterFonts", function()
for k,v in pairs(scaledFonts) do
PIXEL.RegisterFont(k, v.font, v.size, v.weight)
PulsarUI.RegisterFont(k, v.font, v.size, v.weight)
end
end)
end
Expand All @@ -79,15 +79,15 @@ do
setFont(font)
end

PIXEL.SetFont = setPixelFont
PulsarUI.SetFont = setPixelFont

local getTextSize = surface.GetTextSize
function PIXEL.GetTextSize(text, font)
function PulsarUI.GetTextSize(text, font)
if font then setPixelFont(font) end
return getTextSize(text)
end

function PIXEL.GetRealFont(font)
function PulsarUI.GetRealFont(font)
return registeredFonts[font]
end
end
16 changes: 8 additions & 8 deletions lua/pixelui/core/cl_images.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local queue = {}

local useProxy = false

file.CreateDir(PIXEL.DownloadPath)
file.CreateDir(PulsarUI.DownloadPath)

local function endsWithExtension(str)
local fileName = str:match(".+/(.-)$")
Expand All @@ -23,7 +23,7 @@ local function processQueue()

http.Fetch((useProxy and ("https://proxy.duckduckgo.com/iu/?u=" .. url)) or url,
function(body, len, headers, code)
if len > 2097152 then
if len > 2097152 or code ~= 200 then
materials[filePath] = Material("nil")
else
local writeFilePath = filePath
Expand All @@ -50,11 +50,11 @@ local function processQueue()
end
end

function PIXEL.GetImage(url, callback, matSettings)
function PulsarUI.GetImage(url, callback, matSettings)
local protocol = url:match("^([%a]+://)")
local urlWithoutProtocol = url
if not protocol then
print("[PIXEL UI] Trying to run PIXEL.GetImage without URL protocol.")
print("[PulsarUI UI] Trying to run PulsarUI.GetImage without URL protocol.")
else
urlWithoutProtocol = string.gsub(url, protocol, "")
end
Expand All @@ -66,8 +66,8 @@ function PIXEL.GetImage(url, callback, matSettings)

local urlWithoutFileName = url:sub(protocol:len() + 1, fileNameStart - 1)

local dirPath = PIXEL.DownloadPath .. urlWithoutFileName
local filePath = PIXEL.DownloadPath .. urlWithoutProtocol
local dirPath = PulsarUI.DownloadPath .. urlWithoutFileName
local filePath = PulsarUI.DownloadPath .. urlWithoutProtocol

file.CreateDir(dirPath)

Expand Down Expand Up @@ -99,7 +99,7 @@ function PIXEL.GetImage(url, callback, matSettings)
end
end

function PIXEL.GetImgur(id, callback, _, matSettings)
function PulsarUI.GetImgur(id, callback, _, matSettings)
local url = "i.imgur.com/" .. id .. ".png"
PIXEL.GetImage(url, callback, matSettings)
PulsarUI.GetImage(url, callback, matSettings)
end
10 changes: 5 additions & 5 deletions lua/pixelui/core/cl_overrides.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@


PIXEL.UI.Overrides = PIXEL.UI.Overrides or {}
PulsarUI.Overrides = PulsarUI.Overrides or {}

function PIXEL.UI.CreateToggleableOverride(method, override, toggleGetter)
function PulsarUI.CreateToggleableOverride(method, override, toggleGetter)
return function(...)
return toggleGetter(...) and override(...) or method(...)
end
end

local overridePopupsCvar = CreateClientConVar("pixel_ui_override_popups", (PIXEL.OverrideDermaMenus > 1) and "1" or "0", true, false, "Should the default derma popups be restyled with PIXEL UI?", 0, 1)
function PIXEL.UI.ShouldOverrideDermaPopups()
local overrideSetting = PIXEL.OverrideDermaMenus
local overridePopupsCvar = CreateClientConVar("pixel_ui_override_popups", (PulsarUI.OverrideDermaMenus > 1) and "1" or "0", true, false, "Should the default derma popups be restyled with PulsarUI UI?", 0, 1)
function PulsarUI.ShouldOverrideDermaPopups()
local overrideSetting = PulsarUI.OverrideDermaMenus

if not overrideSetting or overrideSetting == 0 then return false end
if overrideSetting == 3 then return true end
Expand Down
14 changes: 7 additions & 7 deletions lua/pixelui/core/cl_scaling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

local scrH = ScrH
local max = math.max
function PIXEL.Scale(value)
function PulsarUI.Scale(value)
return max(value * (scrH() / 1080), 1)
end

function PIXEL.Scale1440(value)
function PulsarUI.Scale1440(value)
return max(value * (scrH() / 1440), 1)
end

local constants = {}
local scaledConstants = {}
function PIXEL.RegisterScaledConstant(varName, size)
function PulsarUI.RegisterScaledConstant(varName, size)
constants[varName] = size
scaledConstants[varName] = PIXEL.Scale(size)
scaledConstants[varName] = PulsarUI.Scale(size)
end

function PIXEL.GetScaledConstant(varName)
function PulsarUI.GetScaledConstant(varName)
return scaledConstants[varName]
end

hook.Add("OnScreenSizeChanged", "PIXEL.UI.UpdateScaledConstants", function()
hook.Add("OnScreenSizeChanged", "PulsarUI.UpdateScaledConstants", function()
for varName, size in pairs(constants) do
scaledConstants[varName] = PIXEL.Scale(size)
scaledConstants[varName] = PulsarUI.Scale(size)
end
scrH = ScrH()
end)
Loading

0 comments on commit 030be73

Please sign in to comment.