mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-16 13:23:46 +03:00
Upload
This commit is contained in:
688
lua/slib/sh_util.lua
Normal file
688
lua/slib/sh_util.lua
Normal file
@@ -0,0 +1,688 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
slib = slib or {}
|
||||
slib.panels = slib.panels or {}
|
||||
slib.cachedAvatars = slib.cachedAvatars or {}
|
||||
slib.generalCooldowns = slib.generalCooldowns or {}
|
||||
|
||||
slib.config = {scale = {x = 1, y = 1}}
|
||||
|
||||
slib.getStatement = function(val)
|
||||
if isbool(val) then return "bool" end
|
||||
if isnumber(val) then return "int" end
|
||||
if istable(val) and val.r and val.g and val.b then return "color" end
|
||||
if istable(val) then return "table" end
|
||||
if isfunction(val) then return "function" end
|
||||
if isstring(val) then return "string" end
|
||||
|
||||
return "bool"
|
||||
end
|
||||
|
||||
local callNum = 1
|
||||
local loadedCalls = {}
|
||||
|
||||
local function loadFile(folder, file)
|
||||
if string.StartWith(file, "sv_") or string.find(folder, "server") then
|
||||
if SERVER then
|
||||
include(folder .. file)
|
||||
loaded = true
|
||||
end
|
||||
elseif string.StartWith(file, "sh_") or string.find(folder, "shared") then
|
||||
AddCSLuaFile(folder .. file)
|
||||
include(folder .. file)
|
||||
loaded = true
|
||||
elseif string.StartWith(file, "cl_") or string.find(folder, "client") then
|
||||
AddCSLuaFile(folder .. file)
|
||||
if CLIENT then include(folder .. file) loaded = true end
|
||||
end
|
||||
|
||||
if loaded then
|
||||
print("[slib] Loaded "..folder..file)
|
||||
|
||||
return folder..file
|
||||
end
|
||||
end
|
||||
|
||||
slib.loadFolder = function(folder, subdirectories, firstload, lastload, call)
|
||||
local files, directories = file.Find(folder .. "*", "LUA")
|
||||
loadedCalls[callNum] = loadedCalls[callNum] or {}
|
||||
|
||||
if firstload then
|
||||
for k,v in pairs(firstload) do
|
||||
local result = loadFile(v[1], v[2])
|
||||
if !result then continue end
|
||||
loadedCalls[callNum][result] = true
|
||||
end
|
||||
end
|
||||
|
||||
if lastload then
|
||||
for k,v in pairs(lastload) do
|
||||
loadedCalls[callNum][v[1]..v[2]] = true
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(files) do
|
||||
if loadedCalls[callNum][folder..v] then continue end
|
||||
loadFile(folder, v)
|
||||
end
|
||||
|
||||
if subdirectories then
|
||||
for k,v in pairs(directories) do
|
||||
slib.loadFolder(folder..v.."/", true, nil, nil, call and call or callNum)
|
||||
end
|
||||
end
|
||||
|
||||
if lastload then
|
||||
for k,v in pairs(lastload) do
|
||||
loadFile(v[1], v[2])
|
||||
end
|
||||
end
|
||||
|
||||
if call then return end
|
||||
callNum = callNum + 1
|
||||
end
|
||||
|
||||
slib.getCooldown = function(var)
|
||||
if !slib.generalCooldowns[var] then return true end
|
||||
|
||||
return slib.generalCooldowns[var] and CurTime() >= slib.generalCooldowns[var]
|
||||
end
|
||||
|
||||
slib.getTimeLeft = function(var)
|
||||
return slib.generalCooldowns[var] and slib.generalCooldowns[var] - CurTime() or 0
|
||||
end
|
||||
|
||||
slib.setCooldown = function(var, cd)
|
||||
slib.generalCooldowns[var] = CurTime() + cd
|
||||
end
|
||||
|
||||
slib.oldFunctions = {}
|
||||
|
||||
slib.wrapFunction = function(element, funcname, pre, post, returnresult)
|
||||
if !slib.oldFunctions[funcname.."Old"] then
|
||||
slib.oldFunctions[funcname.."Old"] = element[funcname]
|
||||
end
|
||||
|
||||
element[funcname] = function(...)
|
||||
local result
|
||||
|
||||
if pre then
|
||||
local callback = pre(...)
|
||||
result = returnresult and callback or result
|
||||
end
|
||||
|
||||
if isfunction(slib.oldFunctions[funcname.."Old"]) then
|
||||
result = slib.oldFunctions[funcname.."Old"](...) or result
|
||||
end
|
||||
|
||||
if post then
|
||||
local callback = post(...)
|
||||
result = returnresult and callback or result
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
slib.lang = slib.lang or {}
|
||||
|
||||
slib.setLang = function(addon, lang, id, str)
|
||||
slib.lang[addon] = slib.lang[addon] or {}
|
||||
slib.lang[addon][lang] = slib.lang[addon][lang] or {}
|
||||
|
||||
slib.lang[addon][lang][id] = str
|
||||
end
|
||||
|
||||
slib.getLang = function(addon, lang, id, ...)
|
||||
local args = {...}
|
||||
local unformatted = slib.lang[addon] and slib.lang[addon][lang] and slib.lang[addon][lang][id]
|
||||
|
||||
if !unformatted then unformatted = slib.lang[addon] and slib.lang[addon]["en"] and slib.lang[addon]["en"][id] or id end
|
||||
|
||||
return table.IsEmpty(args) and unformatted or string.format(unformatted, ...)
|
||||
end
|
||||
|
||||
slib.notify = function(str, ply)
|
||||
str = tostring(str)
|
||||
if SERVER then
|
||||
net.Start("slib.msg")
|
||||
net.WriteString(str)
|
||||
net.Send(ply)
|
||||
elseif CLIENT then
|
||||
print(str)
|
||||
notification.AddLegacy(str, 0, 5)
|
||||
end
|
||||
end
|
||||
|
||||
local function differenciate(a, b)
|
||||
if !(isstring(a) == isstring(b)) or isbool(a) or isbool(b) then
|
||||
return tostring(a), tostring(b)
|
||||
end
|
||||
|
||||
return a, b
|
||||
end
|
||||
|
||||
slib.sortAlphabeticallyByKeyValues = function(tbl, ascending)
|
||||
local normaltable = {}
|
||||
local cleantable = {}
|
||||
|
||||
for k,v in pairs(tbl) do
|
||||
table.insert(normaltable, k)
|
||||
end
|
||||
|
||||
if ascending then
|
||||
table.sort(normaltable, function(a, b) a, b = differenciate(a, b) return a < b end)
|
||||
else
|
||||
table.sort(normaltable, function(a, b) a, b = differenciate(a, b) return a > b end)
|
||||
end
|
||||
|
||||
for k,v in pairs(normaltable) do
|
||||
cleantable[v] = k
|
||||
end
|
||||
|
||||
return cleantable
|
||||
end
|
||||
|
||||
slib.sortAlphabeticallyByValue = function(tbl, ascending, keyvalue)
|
||||
if keyvalue then
|
||||
tbl = table.Copy(tbl)
|
||||
end
|
||||
|
||||
if ascending then
|
||||
table.sort(tbl, function(a, b) a, b = differenciate(a, b) return a < b end)
|
||||
else
|
||||
table.sort(tbl, function(a, b) a, b = differenciate(a, b) return a > b end)
|
||||
end
|
||||
|
||||
local cleantable = {}
|
||||
|
||||
for k, v in pairs(tbl) do
|
||||
cleantable[v] = k
|
||||
end
|
||||
|
||||
return keyvalue and cleantable or tbl
|
||||
end
|
||||
|
||||
slib.sid64ToPly = slib.sid64ToPly or {}
|
||||
|
||||
if SERVER then
|
||||
slib.playerCache = slib.playerCache or player.GetAll()
|
||||
|
||||
util.AddNetworkString("slib.msg")
|
||||
|
||||
local punished = {}
|
||||
slib.punish = function(ply, type, msg, duration)
|
||||
local sid = ply:SteamID()
|
||||
|
||||
if punished[sid] then return end
|
||||
punished[sid] = true
|
||||
|
||||
if type == 1 then
|
||||
ply:Kick(msg)
|
||||
elseif type == 2 then
|
||||
if duration == nil then duration = 0 end
|
||||
if sAdmin then
|
||||
RunConsoleCommand("sa","banid", ply:SteamID64(), duration, msg)
|
||||
elseif ULib then
|
||||
ULib.ban(ply, duration, msg)
|
||||
elseif sam then
|
||||
RunConsoleCommand("sam","banid", sid, duration, msg)
|
||||
elseif xAdmin then
|
||||
if xAdmin.Config then
|
||||
if xAdmin.Config.MajorVersion == 1 then
|
||||
RunConsoleCommand("xadmin_ban", sid, duration, msg)
|
||||
else
|
||||
RunConsoleCommand("xadmin","ban", sid, duration, msg)
|
||||
end
|
||||
end
|
||||
elseif SERVERGUARD then
|
||||
RunConsoleCommand("serverguard","ban", sid, duration, msg)
|
||||
else
|
||||
ply:Ban(duration, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
slib.isBanned = function(sid64, callback)
|
||||
local sid32 = util.SteamIDFrom64(sid64)
|
||||
|
||||
if sAdmin and sAdmin.isBanned then
|
||||
return sAdmin.isBanned(sid64)
|
||||
elseif sam and sam.player and sam.player.is_banned then
|
||||
return sam.player.is_banned(sid32, callback)
|
||||
elseif ulx and ULib and ULib.bans then
|
||||
return tobool(ULib.bans[sid32])
|
||||
elseif xAdmin and xAdmin.Admin and xAdmin.Admin.Bans then
|
||||
local data = xAdmin.Admin.Bans[sid64]
|
||||
local endtime = data.StartTime + (data.Length * 60)
|
||||
|
||||
return data and (tonumber(endtime) <= os.time()) or false
|
||||
end
|
||||
end
|
||||
|
||||
slib.setRank = function(ply, rank)
|
||||
local sid64 = ply:SteamID64()
|
||||
|
||||
if sAdmin then
|
||||
RunConsoleCommand("sa", "setrankid", sid64, rank)
|
||||
elseif sam then
|
||||
RunConsoleCommand("sam", "setrankid", sid64, rank)
|
||||
elseif ulx then
|
||||
RunConsoleCommand("ulx", "adduserid", ply:SteamID(), rank)
|
||||
elseif xAdmin then
|
||||
RunConsoleCommand("xadmin", "setgroup", ply:Nick(), rank) -- yes
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add("PlayerInitialSpawn", "slib.reconnected", function(ply)
|
||||
local sid = ply:SteamID()
|
||||
if punished[sid] then
|
||||
punished[sid] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
hook.Add("PlayerInitialSpawn", "slib.FullLoaded", function( ply )
|
||||
table.insert(slib.playerCache, ply)
|
||||
local sid64 = ply:SteamID64()
|
||||
slib.sid64ToPly[sid64] = ply
|
||||
|
||||
local id = sid64.."_slib"
|
||||
hook.Add( "SetupMove", id, function( self, mv, cmd )
|
||||
if self == ply and not cmd:IsForced() then
|
||||
hook.Run("slib.FullLoaded", ply)
|
||||
hook.Remove("SetupMove", id)
|
||||
end
|
||||
end )
|
||||
end)
|
||||
|
||||
hook.Add("PlayerDisconnected", "slib.handleDisconnect", function(ply)
|
||||
table.RemoveByValue(slib.playerCache, ply)
|
||||
end)
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
local blur = Material("pp/blurscreen")
|
||||
|
||||
slib.DrawBlur = function(panel, amount)
|
||||
local x, y = panel:LocalToScreen(0, 0)
|
||||
local scrW, scrH = ScrW(), ScrH()
|
||||
surface.SetDrawColor(255, 255, 255)
|
||||
surface.SetMaterial(blur)
|
||||
for i = 1, 3 do
|
||||
blur:SetFloat("$blur", (i / 3) * (amount or 6))
|
||||
blur:Recompute()
|
||||
render.UpdateScreenEffectTexture()
|
||||
surface.DrawTexturedRect(x * -1, y * -1, scrW, scrH)
|
||||
end
|
||||
end
|
||||
|
||||
slib.getScaledSize = function(num, axis, scale)
|
||||
scale = scale or {x = 1, y = 1}
|
||||
|
||||
if axis == "x" then
|
||||
num = ScrW() * (num/1920)
|
||||
|
||||
num = num * scale.x
|
||||
end
|
||||
|
||||
if axis == "y" or axis == nil then
|
||||
num = ScrH() * (num/1080)
|
||||
|
||||
num = num * scale.y
|
||||
end
|
||||
|
||||
return math.Round(num)
|
||||
end
|
||||
|
||||
slib.cachedFonts = slib.cachedFonts or {}
|
||||
|
||||
slib.createFont = function(fontname, size, thickness, ignorescale)
|
||||
size = size or 13
|
||||
thickness = thickness or 500
|
||||
local identifier = string.gsub(fontname, " ", "_")
|
||||
|
||||
if !fontname or !size or !thickness then return end
|
||||
|
||||
local name = "slib."..identifier..size.."."..thickness
|
||||
|
||||
if ignorescale then name = "real_"..name end
|
||||
|
||||
if slib.cachedFonts[name] then return name end
|
||||
|
||||
surface.CreateFont( name, {
|
||||
font = fontname,
|
||||
size = ignorescale and size or slib.getScaledSize(size, "y"),
|
||||
weight = thickness,
|
||||
})
|
||||
|
||||
slib.cachedFonts[name] = true
|
||||
|
||||
return name
|
||||
end
|
||||
|
||||
slib.colorCached = {}
|
||||
|
||||
slib.lerpColor = function(identifier, wantedcolor, multiplier, nolerp)
|
||||
wantedcolor = table.Copy(wantedcolor)
|
||||
slib.colorCached[identifier] = slib.colorCached[identifier] or wantedcolor
|
||||
multiplier = multiplier or 1
|
||||
local basespeed = (RealFrameTime() * 3)
|
||||
local speed = basespeed * multiplier
|
||||
|
||||
if minspeed then speed = minspeed > speed and minspeed or speed end
|
||||
|
||||
for k,v in pairs(slib.colorCached[identifier]) do
|
||||
local percentageleft = math.abs(wantedcolor[k] - v)
|
||||
|
||||
slib.colorCached[identifier][k] = math.Approach(v, wantedcolor[k], speed * (nolerp and 100 or percentageleft))
|
||||
end
|
||||
|
||||
return slib.colorCached[identifier]
|
||||
end
|
||||
|
||||
slib.numCached = {}
|
||||
slib.lerpNum = function(identifier, wantednum, multiplier, nolerp)
|
||||
slib.numCached[identifier] = slib.numCached[identifier] or wantednum
|
||||
multiplier = multiplier or 1
|
||||
local basespeed = (RealFrameTime() * 3)
|
||||
local speed = basespeed * multiplier
|
||||
|
||||
local percentageleft = math.abs(wantednum - slib.numCached[identifier])
|
||||
|
||||
slib.numCached[identifier] = math.Approach(slib.numCached[identifier], wantednum, speed * (nolerp and 100 or percentageleft))
|
||||
|
||||
return math.Round(slib.numCached[identifier])
|
||||
end
|
||||
|
||||
slib.drawTooltip = function(str, parent, align)
|
||||
local font = slib.createFont("Roboto", 13)
|
||||
local cursortposx, cursortposy = input.GetCursorPos()
|
||||
cursortposx = cursortposx + 15
|
||||
local x, y = cursortposx, cursortposy
|
||||
|
||||
surface.SetFont(font)
|
||||
local strw, strh = surface.GetTextSize(str)
|
||||
|
||||
local w = strw + slib.getScaledSize(6, "x")
|
||||
|
||||
if align == 1 then
|
||||
local parentparent = parent:GetParent()
|
||||
if !IsValid(parentparent) then return end
|
||||
local posx, posy = parent:GetPos()
|
||||
x, y = parentparent:LocalToScreen(posx, posy)
|
||||
y = y + parent:GetTall()
|
||||
|
||||
x = x + parent:GetWide() * .5
|
||||
|
||||
x = x - w * .5
|
||||
end
|
||||
|
||||
local tooltip = vgui.Create("EditablePanel")
|
||||
tooltip:SetMouseInputEnabled(false)
|
||||
tooltip:SetPos(x, y)
|
||||
tooltip:SetSize(w, slib.getScaledSize(22, "y"))
|
||||
tooltip:MakePopup()
|
||||
|
||||
tooltip.Paint = function(s,w,h)
|
||||
if !parent:IsHovered() and !s:IsHovered() or !s:HasFocus() and !parent.clickable then s:Remove() end
|
||||
|
||||
surface.SetDrawColor(slib.getTheme("maincolor", 10))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
surface.SetDrawColor(120, 120, 120, 200)
|
||||
surface.DrawOutlinedRect(0, 0, w, h)
|
||||
|
||||
draw.SimpleText(str, font, slib.getScaledSize(3, "x"), h * .5, slib.getTheme("textcolor"), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
return tooltip
|
||||
end
|
||||
|
||||
slib.createTooltip = function(str, parent)
|
||||
if !str or !parent then return end
|
||||
|
||||
surface.SetFont(parent.font)
|
||||
local textw, texth = surface.GetTextSize(parent.name)
|
||||
|
||||
|
||||
local tooltipbutton = vgui.Create("DButton", parent)
|
||||
tooltipbutton:SetText("")
|
||||
tooltipbutton:Dock(LEFT)
|
||||
tooltipbutton:DockMargin(textw + slib.getScaledSize(6,"x"),slib.getScaledSize(5,"x"),0,slib.getScaledSize(5,"x"))
|
||||
tooltipbutton:SetWide(slib.getScaledSize(25, "y") - (slib.getScaledSize(5,"x") + slib.getScaledSize(5,"x")))
|
||||
tooltipbutton.bg = slib.getTheme("maincolor")
|
||||
|
||||
tooltipbutton.DoClick = function()
|
||||
tooltipbutton.clicked = !tooltipbutton.clicked
|
||||
end
|
||||
|
||||
tooltipbutton.Paint = function(s,w,h)
|
||||
draw.RoundedBox(h * .5, 0, 0, w, h, s.bg)
|
||||
|
||||
draw.SimpleText("?", slib.createFont("Roboto", 14), w * .5, h * .5, slib.getTheme("textcolor", -50), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
|
||||
if s.clickable and !s.clicked and IsValid(s.tooltip) then
|
||||
s.tooltip:Remove()
|
||||
end
|
||||
|
||||
if s:IsHovered() then
|
||||
if IsValid(s.tooltip) then return end
|
||||
s.tooltip = slib.drawTooltip(str, tooltipbutton)
|
||||
else
|
||||
s.clicked = nil
|
||||
end
|
||||
end
|
||||
|
||||
return tooltipbutton
|
||||
end
|
||||
|
||||
slib.theme = slib.theme or {}
|
||||
|
||||
slib.setTheme = function(var, val)
|
||||
slib.theme[var] = val
|
||||
end
|
||||
|
||||
slib.getTheme = function(var, offset)
|
||||
local val = slib.theme[var]
|
||||
|
||||
if istable(val) then
|
||||
val = table.Copy(val)
|
||||
|
||||
if offset then
|
||||
for k,v in pairs(val) do
|
||||
val[k] = v + offset
|
||||
end
|
||||
|
||||
if val.r and val.g and val.b and val.a then
|
||||
for k,v in pairs(val) do
|
||||
val[k] = math.Clamp(v, 0, 255)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return val
|
||||
end
|
||||
|
||||
slib.isValidSID64 = function(sid64)
|
||||
return util.SteamIDFrom64(sid64) != "STEAM_0:0:0"
|
||||
end
|
||||
|
||||
local loading_ico = Material("slib/load.png", "smooth")
|
||||
|
||||
local matCache = {}
|
||||
local fetched = {}
|
||||
|
||||
file.CreateDir("slib")
|
||||
|
||||
local proxy = ""--"https://proxy.duckduckgo.com/iu/?u=" -- Disabled for now, it doesn't work
|
||||
slib.ImgurGetMaterial = function(id) -- RETURN THE LOADING MATERIAL UNTIL IT IS FOUND!!!
|
||||
if !matCache[id] then
|
||||
local link = proxy.."https://i.imgur.com/"..id..".png"
|
||||
|
||||
if file.Exists("slib/"..id..".png", "DATA") then
|
||||
matCache[id] = Material("data/slib/"..id..".png", "noclamp smooth")
|
||||
|
||||
if matCache[id]:IsError() then
|
||||
file.Delete("slib/"..id..".png")
|
||||
|
||||
if !fetched[link] then
|
||||
slib.ImgurGetMaterial(id)
|
||||
end
|
||||
end
|
||||
else
|
||||
if fetched[link] then return loading_ico, true end
|
||||
|
||||
fetched[link] = true
|
||||
|
||||
http.Fetch(link,
|
||||
function(body)
|
||||
file.Write("slib/"..id..".png", body)
|
||||
matCache[id] = Material("data/slib/"..id..".png", "noclamp smooth")
|
||||
end
|
||||
)
|
||||
end
|
||||
else
|
||||
return matCache[id]
|
||||
end
|
||||
|
||||
return loading_ico, true
|
||||
end
|
||||
|
||||
local cachedNames = {}
|
||||
local requestedNames = {}
|
||||
|
||||
slib.findName = function(sid64, rtrn_sid64)
|
||||
if cachedNames[sid64] then return cachedNames[sid64] end
|
||||
|
||||
local servercheck = player.GetBySteamID64(sid64)
|
||||
local steamcheck = false
|
||||
|
||||
if servercheck then
|
||||
cachedNames[sid64] = servercheck:Nick()
|
||||
else
|
||||
if requestedNames[sid64] then return rtrn_sid64 and sid64 end
|
||||
requestedNames[sid64] = true
|
||||
local start = "<title>Steam Community :: "
|
||||
local theEnd = '<link rel="shortcut icon" href="/favicon.ico" type="image/'
|
||||
|
||||
http.Fetch("http://steamcommunity.com/profiles/"..sid64,
|
||||
function(data)
|
||||
local nameStart = select(1, string.find(data, start))
|
||||
local nameEnd = select(1, string.find(data, theEnd))
|
||||
|
||||
if !nameStart or !nameEnd then return end
|
||||
|
||||
nameStart = nameStart + #start
|
||||
nameEnd = nameEnd - 12
|
||||
|
||||
local nick = string.sub(data, nameStart, nameEnd)
|
||||
|
||||
cachedNames[sid64] = nick
|
||||
end
|
||||
)
|
||||
|
||||
if !rtrn_sid64 then
|
||||
cachedNames[sid64] = "N/A"
|
||||
end
|
||||
end
|
||||
|
||||
return rtrn_sid64 and sid64 or cachedNames[sid64]
|
||||
end
|
||||
|
||||
local function saveImageFromURL(url, path, cb)
|
||||
http.Fetch(url, function(data)
|
||||
file.Write(path, data)
|
||||
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local fetchingAvatar = {}
|
||||
local default_ico = Material("slib/default_steam.png", "smooth")
|
||||
|
||||
slib.findAvatar = function(sid64, medium)
|
||||
if !sid64 then return end
|
||||
|
||||
local path = "slib/avatars/"..sid64..(medium and "_medium" or "_full")..".jpg"
|
||||
local size = medium and "medium" or "full"
|
||||
|
||||
slib.cachedAvatars[size] = slib.cachedAvatars[size] or {}
|
||||
|
||||
if !slib.cachedAvatars[size][sid64] or slib.cachedAvatars[size][sid64]:IsError() then
|
||||
if file.Exists(path, "DATA") then
|
||||
slib.cachedAvatars[size][sid64] = Material("data/"..path, "smooth noclamp")
|
||||
|
||||
return slib.cachedAvatars[size][sid64]
|
||||
end
|
||||
|
||||
local start = "https://avatars.akamai.steamstatic.com/"
|
||||
local theEnd = '">'
|
||||
|
||||
if !fetchingAvatar[sid64] then
|
||||
http.Fetch( "http://steamcommunity.com/profiles/"..sid64,
|
||||
function(data)
|
||||
local avatarStart = select(1, string.find(data, start))
|
||||
local avatarEnd = avatarStart + select(1, string.find(string.sub(data, avatarStart, #data), theEnd))
|
||||
|
||||
if !avatarStart or !avatarEnd then return end
|
||||
|
||||
local imgLink = string.sub(data, avatarStart, avatarEnd - 2)
|
||||
|
||||
if medium then
|
||||
imgLink = string.Replace(imgLink, "_full", "_medium")
|
||||
end
|
||||
|
||||
saveImageFromURL(imgLink, path, function()
|
||||
file.CreateDir("slib/avatars/")
|
||||
slib.cachedAvatars[size][sid64] = Material("data/"..path, "smooth noclamp")
|
||||
end)
|
||||
|
||||
cachedNames[sid64] = nick
|
||||
end
|
||||
)
|
||||
|
||||
fetchingAvatar[sid64] = true
|
||||
end
|
||||
|
||||
return default_ico
|
||||
end
|
||||
|
||||
return slib.cachedAvatars[size][sid64]
|
||||
end
|
||||
|
||||
local storedImages = file.Find("slib/avatars/*.jpg", "DATA")
|
||||
|
||||
for k,v in ipairs(storedImages) do
|
||||
if os.time() - file.Time("slib/avatars/"..v, "DATA") >= 259200 then
|
||||
file.Delete("slib/avatars/"..v)
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add("OnEntityCreated", "slib.CacheSid64ToPly", function(ent)
|
||||
if ent:IsPlayer() and !ent:IsBot() then
|
||||
local sid64 = ent:SteamID64()
|
||||
|
||||
if !sid64 then return end
|
||||
|
||||
slib.sid64ToPly[sid64] = ent
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("slib.msg", function(_, ply)
|
||||
slib.notify(net.ReadString())
|
||||
end)
|
||||
end
|
||||
|
||||
hook.Run("slib:loadBase")
|
||||
hook.Run("slib:loadedUtils")
|
||||
141
lua/slib/sv_storage.lua
Normal file
141
lua/slib/sv_storage.lua
Normal file
@@ -0,0 +1,141 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
slib = slib or {}
|
||||
|
||||
local existSQLChecked = {}
|
||||
|
||||
local query, db = sql.Query
|
||||
local dbconnected = false
|
||||
|
||||
local verified = {}
|
||||
|
||||
local function verifySQL(id, type)
|
||||
if verified[id] and verified[id][type] then return end
|
||||
if type == "sql_local" then
|
||||
query("CREATE TABLE IF NOT EXISTS "..id.."_data(id VARCHAR(19), data TEXT)")
|
||||
elseif type == "mysql" then
|
||||
require( "mysqloo" )
|
||||
|
||||
local dbinfo = _G[id].config["mysql_info"]
|
||||
db = mysqloo.connect(dbinfo.host, dbinfo.username, dbinfo.password, dbinfo.database, dbinfo.port)
|
||||
|
||||
function db:onConnected()
|
||||
print("slib: Successfully made SQL Connection for "..id)
|
||||
dbconnected = true
|
||||
hook.Run("slib:MySQLConnected")
|
||||
end
|
||||
|
||||
function db:onConnectionFailed(err)
|
||||
print("slib: Failed to make SQL Connection for "..id)
|
||||
print( "Error:", err )
|
||||
end
|
||||
|
||||
db:query("CREATE TABLE IF NOT EXISTS "..id.."_data(id VARCHAR(19), data TEXT)"):start()
|
||||
|
||||
db:connect()
|
||||
end
|
||||
|
||||
verified[id] = verified[id] or {}
|
||||
verified[id][type] = true
|
||||
end
|
||||
|
||||
slib.syncData = function(id, type, str)
|
||||
verifySQL(id, type)
|
||||
|
||||
local data
|
||||
|
||||
if type == "file" then
|
||||
local sid64
|
||||
if string.find(str, "STEAM") then
|
||||
sid64 = util.SteamIDTo64(str)
|
||||
end
|
||||
|
||||
data = file.Read(id.."/data/"..(sid64 or str)..".json", "DATA")
|
||||
elseif type == "sql_local" then
|
||||
data = query("SELECT data FROM "..id.."_data WHERE id = '"..str.."'")
|
||||
|
||||
if data then
|
||||
data = data[1].data
|
||||
end
|
||||
elseif type == "mysql" then
|
||||
local q = db:query("SELECT data FROM "..id.."_data WHERE id = '"..str.."'")
|
||||
function q:onSuccess(res)
|
||||
if table.IsEmpty(res) then
|
||||
q:onError()
|
||||
else
|
||||
if res[1] then
|
||||
data = res[1].data
|
||||
data = data and util.JSONToTable(data)
|
||||
end
|
||||
|
||||
hook.Run("slib:SyncedData", id, str, data and data or false)
|
||||
end
|
||||
end
|
||||
|
||||
function q:onError(err, sql)
|
||||
hook.Run("slib:SyncedData", id, str, false)
|
||||
end
|
||||
|
||||
q:start()
|
||||
return
|
||||
end
|
||||
|
||||
data = data and util.JSONToTable(data)
|
||||
|
||||
hook.Run("slib:SyncedData", id, str, data and data or false)
|
||||
end
|
||||
|
||||
slib.saveData = function(id, type, str, data)
|
||||
verifySQL(id, type)
|
||||
|
||||
if istable(data) then
|
||||
data = util.TableToJSON(data)
|
||||
end
|
||||
|
||||
if type == "file" then
|
||||
if string.find(str, "STEAM") then
|
||||
str = util.SteamIDTo64(str)
|
||||
end
|
||||
|
||||
file.CreateDir(id.."/data")
|
||||
file.Write(id.."/data/"..str..".json", data)
|
||||
elseif type == "sql_local" then
|
||||
if !existSQLChecked[str] then
|
||||
if !(query("SELECT * FROM "..id.."_data WHERE id = '"..str.."'")) then
|
||||
query("INSERT INTO "..id.."_data (id, data) VALUES('"..str.."','"..data.."')")
|
||||
end
|
||||
existSQLChecked[str] = true
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
query("UPDATE "..id.."_data SET data='"..data.."' WHERE id = '"..str.."'")
|
||||
elseif type == "mysql" then
|
||||
if !dbconnected then return end
|
||||
if !existSQLChecked[str] then
|
||||
local q = db:query("SELECT * FROM "..id.."_data WHERE id = '"..str.."'")
|
||||
function q:onSuccess(res)
|
||||
if !res or !res[1] then
|
||||
local q = db:query("INSERT INTO "..id.."_data (id, data) VALUES('"..str.."','"..data.."')")
|
||||
q:start()
|
||||
return else
|
||||
existSQLChecked[str] = true
|
||||
end
|
||||
end
|
||||
|
||||
q:start()
|
||||
end
|
||||
|
||||
local q = db:query("UPDATE "..id.."_data SET data='"..data.."' WHERE id = '"..str.."'")
|
||||
|
||||
q:start()
|
||||
end
|
||||
end
|
||||
91
lua/slib/vgui/cl_sbutton.lua
Normal file
91
lua/slib/vgui/cl_sbutton.lua
Normal file
@@ -0,0 +1,91 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font = slib.createFont("Roboto", 13)
|
||||
local textcolor, accentcolor, successcolor, failcolor = slib.getTheme("textcolor"), slib.getTheme("accentcolor"), slib.getTheme("successcolor"), slib.getTheme("failcolor")
|
||||
|
||||
function PANEL:Init()
|
||||
self.font = font
|
||||
self:SetText("")
|
||||
self.bg = slib.getTheme("maincolor")
|
||||
self.alignment = TEXT_ALIGN_CENTER
|
||||
self.accentheight = 2
|
||||
self.selCol = accentcolor
|
||||
self.textcolor = textcolor
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockPadding", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetZPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetTall", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetWide", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetSize", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetVisible", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:setTitle(title, alignment, noresize)
|
||||
if self.title == title then return end
|
||||
self.title = title
|
||||
|
||||
if alignment then self.alignment = alignment end
|
||||
|
||||
if !noresize then
|
||||
surface.SetFont(self.font)
|
||||
local w = select(1, surface.GetTextSize(title))
|
||||
|
||||
self:SetWide(w + (slib.getTheme("margin") * 2))
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:getTitle()
|
||||
return self.title
|
||||
end
|
||||
|
||||
function PANEL:SetLinePos(h)
|
||||
self.linepos = h
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:setToggleable(bool)
|
||||
self.toggleable = bool
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
local wantedcolor = self.toggleable and (isfunction(self.toggleCheck) and self.toggleCheck() and istable(self.toggleCheck()) and self.toggleCheck() or self.toggleCheck() and successcolor or failcolor) or self.selCol
|
||||
|
||||
if !self.toggleable then
|
||||
wantedcolor.a = (self:IsHovered() or self.forcehover) and 120 or 20
|
||||
end
|
||||
|
||||
surface.SetDrawColor(self.bg)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(self, wantedcolor))
|
||||
surface.DrawRect(0, self.linepos ~= nil and self.linepos or (h - self.accentheight), w, self.accentheight)
|
||||
local x
|
||||
if self.alignment == TEXT_ALIGN_CENTER then
|
||||
x = w * .5
|
||||
elseif self.alignment == TEXT_ALIGN_RIGHT then
|
||||
x = w - slib.getTheme("margin")
|
||||
elseif self.alignment == TEXT_ALIGN_LEFT then
|
||||
x = slib.getTheme("margin")
|
||||
end
|
||||
|
||||
draw.SimpleText(self.title, self.font, x, h * .5, self.textcolor, self.alignment, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
vgui.Register("SButton", PANEL, "DButton")
|
||||
109
lua/slib/vgui/cl_scollapsiblepanel.lua
Normal file
109
lua/slib/vgui/cl_scollapsiblepanel.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font, font_smaller = slib.createFont("Roboto", 16), slib.createFont("Roboto", 14)
|
||||
local textcolor, textcolor_min55, shade_5, shade_10 = slib.getTheme("textcolor"), slib.getTheme("textcolor", -55), slib.getTheme("maincolor", 5), slib.getTheme("maincolor", 10)
|
||||
local margin = slib.getTheme("margin")
|
||||
|
||||
function PANEL:Init()
|
||||
self.collapsed = true
|
||||
self.defaultH = slib.getScaledSize(24, "y")
|
||||
self.halfTall = slib.getScaledSize(8, "y")
|
||||
self:SetTall(self.defaultH)
|
||||
self:SetText("")
|
||||
|
||||
self.button = vgui.Create("SButton", self)
|
||||
:SetTall(self.defaultH)
|
||||
:Dock(TOP)
|
||||
|
||||
self.button.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(shade_5)
|
||||
surface.DrawRect(0,h - 2,w,2)
|
||||
end
|
||||
|
||||
self.button.DoClick = function()
|
||||
self.collapsed = !self.collapsed
|
||||
|
||||
if self.onClicked then if self.onClicked() == true then return end end
|
||||
self:SizeTo(-1, self:getChildsHeight(), .3)
|
||||
end
|
||||
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetZPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetTall", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetWide", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetPos", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:getChildCount()
|
||||
local count = 0
|
||||
|
||||
for k,v in ipairs(self:GetChildren()) do
|
||||
if v:IsVisible() and v != self.button then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
function PANEL:getChildsHeight()
|
||||
local height = self.defaultH
|
||||
|
||||
if self.collapsed then
|
||||
for k,v in ipairs(self:GetChildren()) do
|
||||
if v == self.button or !v:IsVisible() then continue end
|
||||
local l, t, r, b = v:GetDockMargin()
|
||||
height = height + v:GetTall() + b + t
|
||||
end
|
||||
end
|
||||
|
||||
return height + ((self.collapsed and height > self.defaultH) and margin or 0)
|
||||
end
|
||||
|
||||
function PANEL:setTitle(str)
|
||||
self.title = str
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:ForceSize(add_tall)
|
||||
self:SizeTo(-1, self:getChildsHeight() + (add_tall or 0), .3)
|
||||
end
|
||||
|
||||
function PANEL:forceCollapse()
|
||||
self:InvalidateChildren()
|
||||
self:SetTall(select(2, self:ChildrenSize()) + margin)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:Paint(w, h)
|
||||
surface.SetDrawColor(self.bg or shade_10)
|
||||
surface.DrawRect(0,0,w,h)
|
||||
|
||||
surface.SetDrawColor(shade_10)
|
||||
surface.DrawRect(0,0,w,self.defaultH)
|
||||
surface.DrawRect(w-1,0,1,h)
|
||||
surface.DrawRect(0,0,1,h)
|
||||
|
||||
draw.SimpleText(self.title, font, w * .5, self.defaultH * .5, textcolor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
draw.SimpleText(self.collapsed and "-" or "+", font, w - margin - self.halfTall, self.defaultH * .5, textcolor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
|
||||
if self.collapsed and self:getChildCount() <= 0 then
|
||||
local offset = self:GetTall() - self.defaultH
|
||||
draw.SimpleText(self.emptyMsg or "", font_smaller, w * .5, self.defaultH + offset * .5, textcolor_min55, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
|
||||
vgui.Register("SCollapsiblePanel", PANEL, "EditablePanel")
|
||||
185
lua/slib/vgui/cl_sdropdown.lua
Normal file
185
lua/slib/vgui/cl_sdropdown.lua
Normal file
@@ -0,0 +1,185 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font = slib.createFont("Roboto", 13)
|
||||
local textcolor = slib.getTheme("textcolor")
|
||||
local hovercolor, margin, maincolor_5, maincolor_10 = slib.getTheme("hovercolor"), slib.getTheme("margin"), slib.getTheme("maincolor", 5), slib.getTheme("maincolor", 10)
|
||||
local icon = Material("slib/down-arrow.png", "smooth")
|
||||
|
||||
function PANEL:Init()
|
||||
self:SetTall(slib.getScaledSize(25, "y"))
|
||||
self:setTitle("Select Option", TEXT_ALIGN_LEFT)
|
||||
self.iteration = 0
|
||||
self.options = {}
|
||||
self.maxHeightChilds = 0
|
||||
|
||||
self.close = vgui.Create("DButton")
|
||||
self.close:Dock(FILL)
|
||||
self.close:SetText("")
|
||||
self.close:SetVisible(false)
|
||||
|
||||
self.close.Paint = function() end
|
||||
|
||||
self.close.DoClick = function()
|
||||
self.close:SetVisible(false)
|
||||
if IsValid(self.droppedMenu) then
|
||||
self.droppedMenu:SetVisible(false)
|
||||
end
|
||||
|
||||
if isfunction(self.onClose) then self.onClose(self) end
|
||||
end
|
||||
|
||||
self.droppedMenu = vgui.Create("SScrollPanel")
|
||||
self.droppedMenu:SetWide(self:GetWide())
|
||||
self.droppedMenu:SetVisible(false)
|
||||
self.droppedMenu.scrollbg = Color(42, 42, 42)
|
||||
end
|
||||
|
||||
function PANEL:SetPlaceholder(str)
|
||||
self:setTitle(str, TEXT_ALIGN_LEFT)
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
if IsValid(self.droppedMenu) then self.droppedMenu:Remove() end
|
||||
end
|
||||
|
||||
function PANEL:popupAlone()
|
||||
self:DoClick()
|
||||
|
||||
local x, y = input.GetCursorPos()
|
||||
if !IsValid(self.droppedMenu) then return end
|
||||
self.droppedMenu:SetWide(self:GetWide())
|
||||
self.droppedMenu:SetPos(x, y)
|
||||
self.droppedMenu:MakePopup()
|
||||
self:SetVisible(false)
|
||||
self.poppedOut = true
|
||||
|
||||
self.onClose = function() self:Remove() end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:SizeToChilds()
|
||||
local canvas = self.droppedMenu:GetCanvas()
|
||||
local childsHeight = 0
|
||||
|
||||
for k,v in ipairs(canvas:GetChildren()) do
|
||||
if self.maxHeightChilds > 0 and k > self.maxHeightChilds then
|
||||
break
|
||||
end
|
||||
|
||||
childsHeight = childsHeight + v:GetTall()
|
||||
end
|
||||
|
||||
canvas:InvalidateLayout(true)
|
||||
canvas:SetTall(childsHeight)
|
||||
|
||||
self.droppedMenu:SetHeight(canvas:GetTall())
|
||||
end
|
||||
|
||||
function PANEL:addOption(val)
|
||||
local iteration = self.iteration
|
||||
self.options[iteration] = vgui.Create("SButton", self.droppedMenu)
|
||||
:Dock(TOP)
|
||||
:SetLinePos(0)
|
||||
:SetTall(slib.getScaledSize(25, "y"))
|
||||
|
||||
if self.buttonfont then
|
||||
self.options[iteration].font = self.buttonfont
|
||||
end
|
||||
|
||||
local is_func = isfunction(val)
|
||||
|
||||
self.options[iteration]:setTitle(is_func and val() or val, TEXT_ALIGN_LEFT)
|
||||
|
||||
local wide = self.options[iteration]:GetWide()
|
||||
|
||||
self.options[iteration].accentheight = 1
|
||||
|
||||
self:SizeToChilds()
|
||||
|
||||
self.options[iteration].DoClick = function(called)
|
||||
self.close.DoClick()
|
||||
self:setTitle(is_func and val() or val, TEXT_ALIGN_LEFT, true)
|
||||
self.sel_int = iteration + 1
|
||||
|
||||
if isfunction(self.onValueChange) then
|
||||
self.onValueChange(is_func and val() or val)
|
||||
end
|
||||
end
|
||||
local isFirst = !self.firstchild
|
||||
self.options[iteration].Paint = function(s,w,h)
|
||||
if is_func then self.options[iteration]:setTitle(val(), TEXT_ALIGN_LEFT) end
|
||||
|
||||
surface.SetDrawColor(s:IsHovered() and maincolor_5 or maincolor_10)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
draw.SimpleText(is_func and val() or val, self.buttonfont or self.options[iteration].font, margin, h * .5, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
if iteration == 0 then
|
||||
self.options[iteration].DoClick()
|
||||
end
|
||||
|
||||
if wide > self:GetWide() then
|
||||
self:SetWide(wide)
|
||||
end
|
||||
|
||||
self.iteration = self.iteration + 1
|
||||
|
||||
self.firstchild = self.firstchild or self.options[iteration]
|
||||
self.lastchild = self.options[iteration]
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:SelectOption(int)
|
||||
self.options[int].DoClick(true)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:Reposition()
|
||||
local x, y = self:LocalToScreen(0,self:GetTall())
|
||||
if !IsValid(self.droppedMenu) then return end
|
||||
self.droppedMenu:SetWide(self:GetWide())
|
||||
self.droppedMenu:SetPos(x, y)
|
||||
self.droppedMenu:MakePopup()
|
||||
end
|
||||
|
||||
function PANEL:DoClick()
|
||||
self.close:SetVisible(!self.droppedMenu:IsVisible())
|
||||
self.close:MakePopup()
|
||||
|
||||
self.droppedMenu:SetVisible(!self.droppedMenu:IsVisible())
|
||||
|
||||
self:Reposition()
|
||||
end
|
||||
|
||||
function PANEL:OnSizeChanged()
|
||||
self:Reposition()
|
||||
end
|
||||
|
||||
function PANEL:PaintOver(w,h)
|
||||
local size = math.min(h * .7, slib.getScaledSize(12, "y"))
|
||||
local thickness = slib.getScaledSize(2, "x")
|
||||
|
||||
draw.NoTexture()
|
||||
|
||||
local wantedCol = self:IsHovered() and color_white or hovercolor
|
||||
|
||||
surface.SetDrawColor(wantedCol)
|
||||
surface.SetMaterial(icon)
|
||||
surface.DrawTexturedRect(w - size - margin * 2, h * .5 - size * .5, size, size)
|
||||
end
|
||||
|
||||
vgui.Register("SDropDown", PANEL, "SButton")
|
||||
415
lua/slib/vgui/cl_sframe.lua
Normal file
415
lua/slib/vgui/cl_sframe.lua
Normal file
@@ -0,0 +1,415 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
slib.setTheme("maincolor", Color(36,36,36))
|
||||
slib.setTheme("accentcolor", Color(66,179,245))
|
||||
slib.setTheme("margin", slib.getScaledSize(3, "x"))
|
||||
slib.setTheme("textcolor", Color(255,255,255))
|
||||
slib.setTheme("neutralcolor", Color(0,0,200,40))
|
||||
slib.setTheme("topbarcolor", Color(44,44,44))
|
||||
slib.setTheme("sidebarcolor", Color(34,34,34))
|
||||
slib.setTheme("sidebarbttncolor", Color(39,39,39))
|
||||
slib.setTheme("whitecolor", Color(255,255,255))
|
||||
slib.setTheme("hovercolor", Color(255,255,255,100))
|
||||
slib.setTheme("orangecolor", Color(130, 92, 10))
|
||||
slib.setTheme("successcolor", Color(0,200,0))
|
||||
slib.setTheme("failcolor", Color(200,0,0))
|
||||
slib.setTheme("bgblur", true)
|
||||
|
||||
local topbarcolor, topbarcolor_min10, sidebarcolor, sidebarbttncolor, textcolor, accentcolor, maincolor, maincolor_7, maincolor_15, hovercolor = slib.getTheme("topbarcolor"), slib.getTheme("topbarcolor", -10), slib.getTheme("sidebarcolor"), slib.getTheme("sidebarbttncolor"), slib.getTheme("textcolor"), slib.getTheme("accentcolor"), slib.getTheme("maincolor"), slib.getTheme("maincolor", 7), slib.getTheme("maincolor", 15), slib.getTheme("hovercolor")
|
||||
local accentcol_a100 = slib.getTheme("accentcolor")
|
||||
accentcol_a100.a = 100
|
||||
|
||||
local black_a160 = Color(0,0,0,160)
|
||||
local black_a140 = Color(0,0,0,140)
|
||||
|
||||
function PANEL:Init()
|
||||
self.topbarheight = slib.getScaledSize(30, "y")
|
||||
self.font = slib.createFont("Roboto", 21)
|
||||
self.tab = {}
|
||||
self.iterator = 0
|
||||
|
||||
self.topbar = vgui.Create("EditablePanel", self)
|
||||
self.topbar:SetCursor("sizeall")
|
||||
self.topbar:SetSize(self:GetWide(), self.topbarheight)
|
||||
|
||||
self.topbar.OnSizeChanged = function()
|
||||
if IsValid(self.close) then
|
||||
self.close:SetPos(self.topbar:GetWide() - self.close:GetWide() - slib.getScaledSize(3,"x"), 0)
|
||||
end
|
||||
end
|
||||
|
||||
self.topbar.Paint = function(s, w, h)
|
||||
if !s.Holding and input.IsMouseDown(MOUSE_LEFT) then
|
||||
if s:IsHovered() then
|
||||
s.Move = true
|
||||
end
|
||||
|
||||
s.Holding = true
|
||||
local x, y = gui.MouseX(), gui.MouseY()
|
||||
s.startedx, s.startedy = s:ScreenToLocal(x, y)
|
||||
elseif s.Holding and !input.IsMouseDown(MOUSE_LEFT) then
|
||||
s.Holding = nil
|
||||
s.Move = nil
|
||||
end
|
||||
|
||||
if s.Move then
|
||||
local x, y = gui.MouseX(), gui.MouseY()
|
||||
local offsetx, offsety = s:ScreenToLocal(x, y)
|
||||
|
||||
self:SetPos(x - s.startedx, y - s.startedy)
|
||||
end
|
||||
|
||||
draw.RoundedBoxEx(5, 0, 0, w, h, topbarcolor, true, true)
|
||||
|
||||
surface.SetDrawColor(black_a160)
|
||||
surface.DrawRect(0, h - 1, w, 1)
|
||||
|
||||
surface.SetDrawColor(black_a140)
|
||||
surface.DrawRect(0, h - 2, w, 1)
|
||||
draw.SimpleText(self.title, self.font, slib.getScaledSize(3,"x"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
self.frame = vgui.Create("EditablePanel", self)
|
||||
|
||||
self.frame.Resize = function()
|
||||
local wide = 0
|
||||
|
||||
if self.tabmenu then
|
||||
wide = wide + self.tabmenu:GetWide()
|
||||
end
|
||||
|
||||
self.frame:SetPos(wide,self.topbarheight)
|
||||
self.frame:SetSize(self:GetWide() - wide, self:GetTall() - self.topbarheight)
|
||||
|
||||
for k,v in pairs(self.tab) do
|
||||
self.tab[k]:SetSize(self.frame:GetWide(), self.frame:GetTall())
|
||||
end
|
||||
end
|
||||
|
||||
self.frame.Resize()
|
||||
|
||||
self.MadePanel = SysTime()
|
||||
|
||||
slib.wrapFunction(self, "SetSize", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetWide", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "Center", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "MakePopup", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockPadding", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
if !IsValid(self.bgclose) then return end
|
||||
self.bgclose:Remove()
|
||||
end
|
||||
|
||||
function PANEL:SetBG(bool, close, col, makepopup)
|
||||
if !bool and IsValid(self.bgclose) then
|
||||
self:SetParent()
|
||||
self.bgclose:Remove()
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local parent = self:GetParent()
|
||||
|
||||
local w, h
|
||||
|
||||
if IsValid(parent) then
|
||||
w, h = parent:GetSize()
|
||||
else
|
||||
w, h = ScrW(), ScrH()
|
||||
end
|
||||
|
||||
self.bgclose = vgui.Create("SButton", parent)
|
||||
self.bgclose:SetSize(w, h)
|
||||
|
||||
if makepopup then
|
||||
self.bgclose:MakePopup()
|
||||
else
|
||||
self.bgclose:MoveToFront()
|
||||
end
|
||||
|
||||
self.bgclose.DoClick = function()
|
||||
if !close then return end
|
||||
|
||||
if IsValid(self.bgclose) then
|
||||
self.bgclose:Remove()
|
||||
end
|
||||
|
||||
if IsValid(self) then
|
||||
self:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
self.bgclose.bg = col
|
||||
|
||||
self.bgclose.Paint = function(s,w,h)
|
||||
if !IsValid(self) then s:Remove() end
|
||||
|
||||
if !s.bg then return end
|
||||
surface.SetDrawColor(s.bg)
|
||||
surface.DrawRect(0,0,w,h)
|
||||
end
|
||||
|
||||
self:SetParent(self.bgclose)
|
||||
self:MoveToFront()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:SetDraggable(bool)
|
||||
if IsValid(self.topbar) then
|
||||
self.topbar:SetMouseInputEnabled(bool)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:setTitle(str, font)
|
||||
self.title = str
|
||||
|
||||
if font then
|
||||
self.font = font
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addCloseButton()
|
||||
self.close = vgui.Create("DButton", self)
|
||||
self.close:SetSize(slib.getScaledSize(25, "y"),slib.getScaledSize(25, "y"))
|
||||
self.close:SetMouseInputEnabled(true)
|
||||
self.close:SetPos(self.topbar:GetWide() - self.close:GetWide() - slib.getScaledSize(3,"x"), self.topbarheight * .5 - self.close:GetTall() * .5)
|
||||
self.close:SetText("")
|
||||
|
||||
self.close.DoClick = function()
|
||||
if isfunction(self.onClose) then
|
||||
self.onClose()
|
||||
end
|
||||
|
||||
if self.onlyHide then
|
||||
self:SetVisible(false)
|
||||
return end
|
||||
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
self.close.Paint = function(s,w,h)
|
||||
local width = slib.getScaledSize(2, "X")
|
||||
local height = h * .7
|
||||
|
||||
draw.NoTexture()
|
||||
|
||||
local wantedCol = s:IsHovered() and color_white or hovercolor
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(s, wantedCol))
|
||||
surface.DrawTexturedRectRotated(w - (height * .5), h * .5 - (width * .5), width, height, 45)
|
||||
surface.DrawTexturedRectRotated(w - (height * .5), h * .5 - (width * .5), width, height, -45)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:OnSizeChanged()
|
||||
self.topbar:SetSize(self:GetWide(), self.topbarheight)
|
||||
self.frame.Resize()
|
||||
end
|
||||
|
||||
function PANEL:setBlur(bool)
|
||||
self.blur = bool
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:setDoClick(func)
|
||||
self.DoClick = func
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:Paint(w, h)
|
||||
if slib.getTheme("bgblur") and self.blur then
|
||||
Derma_DrawBackgroundBlur( self, self.MadePanel )
|
||||
end
|
||||
|
||||
draw.RoundedBox(5, 0, 0, w, h, maincolor)
|
||||
end
|
||||
|
||||
function PANEL:addTab(name, icon)
|
||||
if !IsValid(self.tabmenu) then
|
||||
self.tabmenu = vgui.Create("DScrollPanel", self)
|
||||
self.tabmenu:SetTall(self:GetTall() - self.topbarheight)
|
||||
self.tabmenu:SetPos(0, self.topbarheight)
|
||||
self.tabmenu.font = slib.createFont("Roboto", 14)
|
||||
self.tabmenu.Paint = function(s,w,h)
|
||||
draw.RoundedBoxEx(5, 0, 0, w, h, sidebarcolor, false, false, true, false)
|
||||
end
|
||||
|
||||
self.tabmenu.OnSizeChanged = function()
|
||||
self.frame.Resize()
|
||||
end
|
||||
|
||||
self.frame.Resize()
|
||||
end
|
||||
|
||||
self.tab[name] = vgui.Create("EditablePanel", self.frame)
|
||||
self.tab[name]:SetSize(self.frame:GetWide(), self.frame:GetTall())
|
||||
self.tab[name]:SetVisible(false)
|
||||
self.tab[name].addTab = function(tab_name)
|
||||
local w, h, tab_h = self.tab[name]:GetWide(), self.tab[name]:GetTall(), slib.getScaledSize(32, "y")
|
||||
if !IsValid(self.tab[name].topbar) then
|
||||
self.tab[name].topbar = vgui.Create("EditablePanel", self.tab[name])
|
||||
self.tab[name].topbar:Dock(TOP)
|
||||
self.tab[name].topbar:SetTall(tab_h)
|
||||
self.tab[name].topbar.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_7)
|
||||
surface.DrawRect(0,0,w,h)
|
||||
end
|
||||
end
|
||||
|
||||
local frame = vgui.Create("EditablePanel", self.tab[name])
|
||||
frame:SetPos(0, tab_h)
|
||||
frame:SetSize(w, h - tab_h)
|
||||
frame:SetVisible(false)
|
||||
|
||||
local tab_button = vgui.Create("SButton", self.tab[name].topbar)
|
||||
tab_button.font = slib.createFont("Roboto", 16)
|
||||
tab_button.bg = maincolor_7
|
||||
tab_button.tab = frame
|
||||
|
||||
tab_button.DoClick = function()
|
||||
if IsValid(self.tab[name].selTab) and self.tab[name].selTab:IsVisible() then
|
||||
self.tab[name].selTab.tabbttn.forcehover = nil
|
||||
self.tab[name].selTab.tabbttn.bg = maincolor_7
|
||||
self.tab[name].selTab:SetVisible(false)
|
||||
end
|
||||
|
||||
frame:SetVisible(true)
|
||||
self.tab[name].selTab = frame
|
||||
|
||||
tab_button.bg = maincolor_15
|
||||
tab_button.forcehover = true
|
||||
end
|
||||
|
||||
frame.tabbttn = tab_button
|
||||
|
||||
tab_button:setTitle(tab_name)
|
||||
:Dock(LEFT)
|
||||
|
||||
local childs = self.tab[name].topbar:GetChildren()
|
||||
local width = math.ceil(self.frame:GetWide() / #childs)
|
||||
for k,v in ipairs(childs) do
|
||||
v:SetWide(width)
|
||||
end
|
||||
|
||||
if #childs == 1 then
|
||||
tab_button.DoClick()
|
||||
end
|
||||
|
||||
return frame
|
||||
end
|
||||
|
||||
local height = slib.getScaledSize(28, "y")
|
||||
self.iterator = self.iterator + 1
|
||||
local tabbttn = vgui.Create("DButton", self.tabmenu)
|
||||
tabbttn:Dock(TOP)
|
||||
tabbttn:SetZPos(self.iterator)
|
||||
tabbttn:SetTall(height)
|
||||
tabbttn:SetText("")
|
||||
tabbttn.name = name
|
||||
|
||||
tabbttn.getFrame = function()
|
||||
return self.tab[name]
|
||||
end
|
||||
|
||||
if icon then
|
||||
tabbttn.icon = Material(icon, "smooth")
|
||||
end
|
||||
|
||||
local icosize = height * .6
|
||||
local gap = height * .20
|
||||
|
||||
tabbttn.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(sidebarbttncolor)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
local wantedh = self.seltab == name and h or 0
|
||||
local curH = slib.lerpNum(s, wantedh, .9, true)
|
||||
|
||||
if self.seltab == name then
|
||||
surface.SetDrawColor(accentcol_a100)
|
||||
surface.DrawRect(0, h * .5 - curH * .5, w, curH)
|
||||
end
|
||||
|
||||
if s.icon then
|
||||
surface.SetDrawColor(color_white)
|
||||
surface.SetMaterial(s.icon)
|
||||
surface.DrawTexturedRect(gap,gap,icosize,icosize)
|
||||
end
|
||||
|
||||
draw.SimpleText(name, self.tabmenu.font, (s.icon and icosize + gap or 0) + slib.getTheme("margin"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
tabbttn.DoClick = function()
|
||||
self:setActiveTab(name)
|
||||
|
||||
if isfunction(self.changedTab) then
|
||||
self.changedTab(name)
|
||||
end
|
||||
end
|
||||
|
||||
self.tab[name].tabbttn = tabbttn
|
||||
|
||||
surface.SetFont(self.tabmenu.font)
|
||||
local w = select(1, surface.GetTextSize(name)) + (slib.getTheme("margin") * 4) + height
|
||||
|
||||
if w > self.tabmenu:GetWide() then
|
||||
self.tabmenu:SetWide(w)
|
||||
end
|
||||
|
||||
return self, tabbttn
|
||||
end
|
||||
|
||||
function PANEL:setActiveTab(name)
|
||||
if !name then
|
||||
local childs = self.tabmenu:GetCanvas():GetChildren()
|
||||
local lowest, selected = math.huge
|
||||
for k,v in ipairs(childs) do
|
||||
local zpos = v:GetZPos()
|
||||
if zpos < lowest then
|
||||
selected = v.name
|
||||
lowest = zpos
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if selected then
|
||||
self:setActiveTab(selected)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if self.seltab and IsValid(self.tab[self.seltab]) then
|
||||
self.tab[self.seltab]:SetVisible(false)
|
||||
end
|
||||
|
||||
self.seltab = name
|
||||
|
||||
self.tab[name]:SetVisible(true)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
vgui.Register("SFrame", PANEL, "EditablePanel")
|
||||
180
lua/slib/vgui/cl_slistpanel.lua
Normal file
180
lua/slib/vgui/cl_slistpanel.lua
Normal file
@@ -0,0 +1,180 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local font = slib.createFont("Roboto", 14)
|
||||
local textcolor, neutralcolor, successcolor, failcolor, maincolor_7, maincolor_10, maincolor_15, maincolor_25 = slib.getTheme("textcolor"), slib.getTheme("neutralcolor"), slib.getTheme("successcolor"), slib.getTheme("failcolor"), slib.getTheme("maincolor", 7), slib.getTheme("maincolor", 10), slib.getTheme("maincolor", 15), slib.getTheme("maincolor", 25)
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
function PANEL:Init()
|
||||
self:Dock(TOP)
|
||||
self:SetTall(slib.getScaledSize(250, "y"))
|
||||
self:DockMargin(slib.getTheme("margin"),0,slib.getTheme("margin"),slib.getTheme("margin"))
|
||||
|
||||
self.frame = vgui.Create("SScrollPanel", self)
|
||||
self.frame:Dock(FILL)
|
||||
|
||||
self.frame.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_10)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
|
||||
self.selected = false
|
||||
|
||||
slib.wrapFunction(self, "SetZPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetTall", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:addEntry(var, toggleable, tab)
|
||||
title = var
|
||||
if !isstring(var) and IsValid(var) and var:IsPlayer() then title = var:Nick() end
|
||||
|
||||
local selectable = vgui.Create("DButton", self.frame)
|
||||
selectable:SetTall(slib.getScaledSize(25, "y"))
|
||||
selectable:Dock(TOP)
|
||||
selectable:DockMargin(slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"),0)
|
||||
selectable:SetText("")
|
||||
selectable.name = title
|
||||
selectable.tab = tab
|
||||
selectable.toggleable = toggleable
|
||||
|
||||
selectable.Paint = function(s,w,h)
|
||||
if !isstring(var) and !IsValid(var) then s:Remove() return end
|
||||
|
||||
local wantedcolor
|
||||
|
||||
if s.toggleable then
|
||||
if isfunction(s.toggleCheck) then
|
||||
wantedcolor = s.toggleCheck() and successcolor or failcolor
|
||||
end
|
||||
else
|
||||
wantedcolor = neutralcolor
|
||||
end
|
||||
|
||||
wantedcolor.a = 40
|
||||
if !s.toggleable and self.selected ~= var then
|
||||
wantedcolor.a = 0
|
||||
end
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(s, wantedcolor))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
surface.SetDrawColor(maincolor_25)
|
||||
surface.DrawOutlinedRect(0, 0, w, h)
|
||||
|
||||
|
||||
draw.SimpleText(selectable.name, font, 5, h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
selectable.DoClick = function()
|
||||
self.selected = (self.selected ~= var) and var or nil
|
||||
end
|
||||
|
||||
return self, selectable
|
||||
end
|
||||
|
||||
function PANEL:setTitle(title)
|
||||
self.title = title
|
||||
|
||||
if !self.topbar then
|
||||
self.topbar = vgui.Create("EditablePanel", self)
|
||||
self.topbar:SetTall(slib.getScaledSize(25, "y"))
|
||||
self.topbar:Dock(TOP)
|
||||
|
||||
self.topbar.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_7)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
surface.SetDrawColor(maincolor_25)
|
||||
surface.DrawRect(0,h-1,w,1)
|
||||
|
||||
draw.SimpleText(self.title, font, slib.getTheme("margin"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addSearchbar()
|
||||
self.search = vgui.Create("SSearchBar", self.topbar)
|
||||
self.search:Dock(RIGHT)
|
||||
:DockMargin(slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"))
|
||||
|
||||
self.search.entry.bg = maincolor_15
|
||||
self.search.entry.onValueChange = function(newval)
|
||||
for k,v in pairs(self.frame:GetCanvas():GetChildren()) do
|
||||
v:SetVisible(string.find(string.lower(v.name), string.lower(newval)))
|
||||
|
||||
self.frame:GetCanvas():InvalidateLayout(true)
|
||||
end
|
||||
end
|
||||
|
||||
self.topbar.OnSizeChanged = function()
|
||||
self.search:SetWide(self.topbar:GetWide() * .35)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addDropdown()
|
||||
self.dropdown = vgui.Create("SDropDown", self.topbar)
|
||||
self.dropdown:Dock(RIGHT)
|
||||
:DockMargin(slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"))
|
||||
|
||||
self.dropdown.bg = maincolor_15
|
||||
|
||||
self.dropdown.onValueChange = function(newtab)
|
||||
for k,v in pairs(self.frame:GetCanvas():GetChildren()) do
|
||||
v:SetVisible(v.tab == newtab)
|
||||
self.frame:GetCanvas():InvalidateLayout(true)
|
||||
end
|
||||
end
|
||||
|
||||
self.topbar.OnSizeChanged = function()
|
||||
self.dropdown:SetWide(self.topbar:GetWide() * .35)
|
||||
end
|
||||
|
||||
return self.dropdown
|
||||
end
|
||||
|
||||
function PANEL:addButton(title, func, thnk)
|
||||
if !self.bottombar then
|
||||
self.bottombar = vgui.Create("EditablePanel", self)
|
||||
self.bottombar:Dock(BOTTOM)
|
||||
self.bottombar:SetTall(slib.getScaledSize(25,"x"))
|
||||
|
||||
self.bottombar.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_25)
|
||||
surface.DrawRect(0, 0, w, 1)
|
||||
end
|
||||
end
|
||||
|
||||
local bttn = vgui.Create("SButton", self.bottombar)
|
||||
bttn:Dock(LEFT)
|
||||
:setTitle(title)
|
||||
:DockMargin(slib.getTheme("margin"),slib.getTheme("margin"),0,slib.getTheme("margin"))
|
||||
|
||||
bttn.DoClick = function() func(self, bttn) end
|
||||
|
||||
if thnk then
|
||||
bttn.Think = function() thnk(self, bttn) end
|
||||
end
|
||||
|
||||
return self, bttn
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
surface.SetDrawColor(maincolor_10)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
|
||||
vgui.Register("SListPanel", PANEL, "EditablePanel")
|
||||
294
lua/slib/vgui/cl_slistview.lua
Normal file
294
lua/slib/vgui/cl_slistview.lua
Normal file
@@ -0,0 +1,294 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font = slib.createFont("Roboto", 15)
|
||||
local textcolor, maincolor_7, linecol, neutralcolor, margin = slib.getTheme("textcolor"), slib.getTheme("maincolor", 7), Color(24,24,24,160), slib.getTheme("neutralcolor"), slib.getTheme("margin")
|
||||
|
||||
function PANEL:Init()
|
||||
self.Columns = self.Columns or {}
|
||||
self.Lines = self.Lines or {}
|
||||
|
||||
self.columniteration = 0
|
||||
self.lineiteration = 0
|
||||
|
||||
self.assortment = self.assortment or {}
|
||||
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetSize", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "Center", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "MakePopup", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:getColumnPos(col)
|
||||
local result = self.Columns[col]:GetPos()
|
||||
return select(1, result)
|
||||
end
|
||||
|
||||
function PANEL:getColumnWide(col)
|
||||
return self.Columns[col]:GetWide()
|
||||
end
|
||||
|
||||
local function differenciate(a, b)
|
||||
if isfunction(a) then a = a() end
|
||||
if isfunction(b) then b = b() end
|
||||
if isnumber(tonumber(a)) and isnumber(tonumber(b)) then return tonumber(a), tonumber(b) end
|
||||
|
||||
if !(isstring(a) == isstring(b)) or isbool(a) or isbool(b) then
|
||||
return tostring(a), tostring(b)
|
||||
end
|
||||
|
||||
return a, b
|
||||
end
|
||||
|
||||
function PANEL:addColumn(name)
|
||||
if !IsValid(self.topbar) then
|
||||
self.topbar = vgui.Create("EditablePanel", self)
|
||||
self.topbar:Dock(TOP)
|
||||
self.topbar:SetZPos(-32768)
|
||||
self.topbar:SetTall(slib.getScaledSize(25, "y"))
|
||||
|
||||
self.topbar.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_7)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
surface.SetDrawColor(linecol)
|
||||
surface.DrawRect(0, h - 1, w - 1, 1)
|
||||
end
|
||||
end
|
||||
|
||||
self.columniteration = self.columniteration + 1
|
||||
|
||||
local iteration = self.columniteration
|
||||
local ignoreWidth = false
|
||||
|
||||
|
||||
if istable(name) then
|
||||
if name[2] then
|
||||
ignoreWidth = name[2]
|
||||
end
|
||||
name = name[1]
|
||||
end
|
||||
|
||||
self.Columns[iteration] = vgui.Create("DButton", self.topbar)
|
||||
self.Columns[iteration]:Dock(LEFT)
|
||||
self.Columns[iteration]:SetWide(self:GetWide() / #self.Columns)
|
||||
self.Columns[iteration].Width = self:GetWide() / #self.Columns
|
||||
self.Columns[iteration]:SetText("")
|
||||
self.Columns[iteration].name = name
|
||||
self.Columns[iteration].iteration = iteration
|
||||
self.Columns[iteration].ignoreWidth = ignoreWidth
|
||||
|
||||
self.Columns[iteration].DoClick = function()
|
||||
if self.assortment.iteration == iteration then
|
||||
self.assortment.ascending = !self.assortment.ascending
|
||||
else
|
||||
self.assortment.iteration = iteration
|
||||
self.assortment.ascending = true
|
||||
end
|
||||
|
||||
local basictable = {}
|
||||
local cleantable = {}
|
||||
|
||||
for i=1,#self.Lines do
|
||||
local tbl = self.Columns[iteration]["lines"][i]
|
||||
local sortvalue = istable(tbl) and (tbl.sortvalue or tbl.text) or tbl
|
||||
|
||||
table.insert(basictable, sortvalue)
|
||||
end
|
||||
|
||||
if self.assortment.ascending then
|
||||
table.sort(basictable, function(a, b) a, b = differenciate(a, b) return a > b end)
|
||||
else
|
||||
table.sort(basictable, function(a, b) a, b = differenciate(a, b) return a < b end)
|
||||
end
|
||||
|
||||
for i, z in pairs(basictable) do
|
||||
cleantable[z] = i
|
||||
end
|
||||
|
||||
for i=1,#self.Lines do
|
||||
local tbl = self.Columns[iteration]["lines"][i]
|
||||
local final = istable(tbl) and (tbl.sortvalue or tbl.text) or tbl
|
||||
|
||||
if !IsValid(self.Lines[i]) then continue end
|
||||
|
||||
self.Lines[i]:SetZPos(cleantable[final])
|
||||
end
|
||||
end
|
||||
|
||||
self.Columns[iteration].Paint = function(s,w,h)
|
||||
draw.SimpleText(name, font, slib.getTheme("margin"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addColumns(...)
|
||||
local args = {...}
|
||||
|
||||
for k,v in pairs(args) do
|
||||
self:addColumn(v)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addLine(...)
|
||||
local args = {...}
|
||||
if !IsValid(self.frame) then
|
||||
self.frame = vgui.Create("SScrollPanel", self)
|
||||
self.frame:Dock(FILL)
|
||||
self.frame:SetTall(slib.getScaledSize(25, "y"))
|
||||
end
|
||||
|
||||
self.lineiteration = self.lineiteration + 1
|
||||
|
||||
local iteration = self.lineiteration
|
||||
|
||||
for k,v in ipairs(args) do
|
||||
local display = istable(v) and v[1] or v
|
||||
local sortingvalue
|
||||
|
||||
if istable(v) and v[2] then
|
||||
sortingvalue = v[2]
|
||||
end
|
||||
|
||||
self.Columns[k]["lines"] = self.Columns[k]["lines"] or {}
|
||||
self.Columns[k]["lines"][iteration] = self.Columns[k]["lines"][iteration] or {}
|
||||
|
||||
self.Columns[k]["lines"][iteration]["text"] = display
|
||||
|
||||
if sortingvalue then
|
||||
self.Columns[k]["lines"][iteration]["sortvalue"] = sortingvalue
|
||||
end
|
||||
end
|
||||
|
||||
self.Lines[iteration] = vgui.Create("DButton", self)
|
||||
self.Lines[iteration]:Dock(TOP)
|
||||
self.Lines[iteration]:SetTall(slib.getScaledSize(25, "y"))
|
||||
self.Lines[iteration]:SetText("")
|
||||
self.Lines[iteration].InitDoClick = self.Lines[iteration].DoClick
|
||||
|
||||
self.Lines[iteration].Think = function()
|
||||
self.Lines[iteration]:SetMouseInputEnabled(self.Lines[iteration].DoClick ~= self.Lines[iteration].InitDoClick)
|
||||
end
|
||||
|
||||
self.Lines[iteration].Paint = function(s,w,h)
|
||||
local wantedcolor = neutralcolor
|
||||
|
||||
if !s:IsHovered() then
|
||||
wantedcolor = table.Copy(wantedcolor)
|
||||
wantedcolor.a = 0
|
||||
end
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(s, wantedcolor))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
for i = 1,#self.Columns do
|
||||
local display = self.Columns[i]["lines"][iteration].text
|
||||
|
||||
if isfunction(display) then
|
||||
display = display()
|
||||
end
|
||||
|
||||
local x,y = self:getColumnPos(i), h * .5
|
||||
local w = self:getColumnWide(i)
|
||||
|
||||
if w < (self:getTextWidth(display, self.Columns[i].maxTxtLen) + margin * 2) then self:resizeColumns() end
|
||||
if i == 1 then
|
||||
s.name = display
|
||||
end
|
||||
|
||||
if self.Columns[i].ignoreWidth or self.Columns[i].maxTxtLen then
|
||||
surface.SetFont(font)
|
||||
local txt_h = select(2, surface.GetTextSize(display))
|
||||
local screen_x, screen_y = s:LocalToScreen(0,0)
|
||||
|
||||
render.SetScissorRect(screen_x + x, screen_y, screen_x + x + self.Columns[i]:GetWide() - margin, screen_y + h, true)
|
||||
draw.SimpleText(display, font, x + slib.getTheme("margin"), y, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
render.SetScissorRect(0, 0, 0, 0, false)
|
||||
else
|
||||
|
||||
if self.Columns[i].customRender and self.Columns[i].customRender(x, 0, w, h, s) == true then return end
|
||||
|
||||
draw.SimpleText(display, font, x + slib.getTheme("margin"), y, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:resizeColumns()
|
||||
|
||||
return self, self.Lines[iteration]
|
||||
end
|
||||
|
||||
function PANEL:getTextWidth(txt, max)
|
||||
txt = tostring(txt)
|
||||
|
||||
if max then
|
||||
txt = string.sub(txt, 1, max)
|
||||
end
|
||||
|
||||
surface.SetFont(font)
|
||||
|
||||
return surface.GetTextSize(txt)
|
||||
end
|
||||
|
||||
function PANEL:resizeColumns()
|
||||
local columnsizes = {}
|
||||
local fullwidth = self:GetWide()
|
||||
local spaceleft = 0
|
||||
|
||||
for k, v in pairs(self.Columns) do
|
||||
local ignoreWidth = self.Columns[k].ignoreWidth
|
||||
surface.SetFont(font)
|
||||
|
||||
local longest = self:getTextWidth(self.Columns[k].name)
|
||||
if ignoreWidth then columnsizes[k] = isstring(ignoreWidth) and self:getTextWidth(ignoreWidth) or longest continue end
|
||||
if !self.Columns[k]["lines"] then continue end
|
||||
for i, z in pairs(self.Columns[k]["lines"]) do
|
||||
local compare = isfunction(z.text) and z.text() or z.text
|
||||
local width = self:getTextWidth(compare, self.Columns[k].maxTxtLen) + (slib.getTheme("margin") * 10)
|
||||
if longest < width then longest = width end
|
||||
end
|
||||
|
||||
columnsizes[k] = longest
|
||||
end
|
||||
|
||||
local occupiedspace = 0
|
||||
for k,v in pairs(columnsizes) do
|
||||
occupiedspace = occupiedspace + v
|
||||
end
|
||||
|
||||
for k,v in pairs(self.Columns) do
|
||||
local v = columnsizes[k] or 0
|
||||
|
||||
local gapadd = (fullwidth - occupiedspace) / #self.Columns
|
||||
self.Columns[k]:SetWide(v + gapadd)
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:OnSizeChanged()
|
||||
self:resizeColumns()
|
||||
end
|
||||
|
||||
function PANEL:PaintOver(w,h)
|
||||
for k,v in pairs(self.Columns) do
|
||||
if k >= #self.Columns then break end
|
||||
local x,y = self:getColumnPos(k), h * .5
|
||||
local w = self:getColumnWide(k)
|
||||
surface.SetDrawColor(linecol)
|
||||
surface.DrawRect(x + w - 1, 0, 1, h)
|
||||
end
|
||||
end
|
||||
|
||||
vgui.Register("SListView", PANEL, "SScrollPanel")
|
||||
58
lua/slib/vgui/cl_splayerpanel.lua
Normal file
58
lua/slib/vgui/cl_splayerpanel.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font = slib.createFont("Roboto", 15)
|
||||
local textcolor, maincolor_7 = slib.getTheme("textcolor"), slib.getTheme("maincolor", 7)
|
||||
|
||||
function PANEL:Init()
|
||||
local tall = slib.getScaledSize(25, "y")
|
||||
self:SetTall(tall)
|
||||
self:Dock(TOP)
|
||||
|
||||
self.playerImage = vgui.Create("AvatarImage", self)
|
||||
self.playerImage:SetSize(tall, tall)
|
||||
|
||||
self:DockMargin(0, 0, 0, slib.getTheme("margin"))
|
||||
self:GetParent():DockPadding(slib.getTheme("margin"), slib.getTheme("margin"), slib.getTheme("margin"), slib.getTheme("margin"))
|
||||
end
|
||||
|
||||
function PANEL:addButton(title, func)
|
||||
local bttn = vgui.Create("SButton", self)
|
||||
bttn:setTitle(title)
|
||||
:Dock(RIGHT)
|
||||
:DockMargin(0,slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"))
|
||||
|
||||
bttn.DoClick = func
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:setPlayer(ply)
|
||||
self.ply = ply
|
||||
self.name = self.ply:Nick()
|
||||
self.playerImage:SetPlayer(ply, 64)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
if !self.ply then self:Remove() end
|
||||
|
||||
surface.SetDrawColor(maincolor_7)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
if self.ply then
|
||||
draw.SimpleText(self.name, font, slib.getScaledSize(25, "y") + slib.getTheme("margin"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
|
||||
vgui.Register("SPlayerPanel", PANEL, "EditablePanel")
|
||||
382
lua/slib/vgui/cl_splayerselector.lua
Normal file
382
lua/slib/vgui/cl_splayerselector.lua
Normal file
@@ -0,0 +1,382 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
slib.panels = slib.panels or {}
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font, sid_font, empty_font = slib.createFont("Roboto", 13), slib.createFont("Roboto", 11), slib.createFont("Roboto", 15)
|
||||
local textcolor, textcolor_60 = slib.getTheme("textcolor"), slib.getTheme("textcolor", -60)
|
||||
local hovercolor, margin, maincolor_12, maincolor_15 = slib.getTheme("hovercolor"), slib.getTheme("margin"), slib.getTheme("maincolor", 12), slib.getTheme("maincolor", 15)
|
||||
local icon = Material("slib/down-arrow.png", "smooth")
|
||||
local placeholder = "Select Option"
|
||||
|
||||
function PANEL:Init()
|
||||
self:SetTall(slib.getScaledSize(25, "y"))
|
||||
self:setTitle(placeholder, TEXT_ALIGN_LEFT)
|
||||
self.iteration = 0
|
||||
self.options = {}
|
||||
self.option_h = slib.getScaledSize(32, "y")
|
||||
self.titl = ""
|
||||
|
||||
self.close = vgui.Create("DButton")
|
||||
self.close:Dock(FILL)
|
||||
self.close:SetText("")
|
||||
self.close:SetVisible(false)
|
||||
|
||||
self.close.Paint = function() end
|
||||
|
||||
self.close.DoClick = function()
|
||||
self.close:SetVisible(false)
|
||||
if IsValid(self.droppedFrame) then
|
||||
self.droppedFrame:SetVisible(false)
|
||||
end
|
||||
|
||||
if isfunction(self.onClose) then self.onClose(self) end
|
||||
|
||||
self:setTitle(self.titl, TEXT_ALIGN_LEFT, true)
|
||||
|
||||
if !self.ply then
|
||||
self:setTitle(placeholder, TEXT_ALIGN_LEFT)
|
||||
end
|
||||
end
|
||||
|
||||
self.droppedFrame = vgui.Create("EditablePanel")
|
||||
self.droppedFrame:SetWide(self:GetWide())
|
||||
self.droppedFrame:SetVisible(false)
|
||||
|
||||
self.search = vgui.Create("STextEntry", self.droppedFrame)
|
||||
:Dock(TOP)
|
||||
:SetTall(self:GetTall())
|
||||
|
||||
self.search.onValueChange = function(val)
|
||||
for k,v in ipairs(self.droppedMenu:GetCanvas():GetChildren()) do
|
||||
if !v.ply then continue end
|
||||
|
||||
local filtered = false
|
||||
|
||||
if self.filter then
|
||||
if self.filter(v.ply) == false then filtered = true end
|
||||
end
|
||||
|
||||
v:SetVisible((val:Trim() == "" or string.find(v.nick:lower(), val:lower()) or val == v.sid64) and !filtered)
|
||||
end
|
||||
|
||||
self.droppedMenu.SizeToChilds()
|
||||
self.droppedMenu:GetCanvas():InvalidateLayout(true)
|
||||
end
|
||||
|
||||
self.closesearch = vgui.Create("SButton", self.search)
|
||||
self.closesearch:SetSize(self.option_h, self.option_h)
|
||||
self.closesearch.Paint = function(s,w,h) end
|
||||
self.closesearch.DoClick = self.close.DoClick
|
||||
|
||||
self.droppedMenu = vgui.Create("SScrollPanel", self.droppedFrame)
|
||||
self.droppedMenu:SetWide(self:GetWide())
|
||||
self.droppedMenu:SetPos(0, self:GetTall())
|
||||
self.droppedMenu.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_15)
|
||||
surface.DrawRect(0,0,w,h)
|
||||
|
||||
draw.SimpleText("No entries.", empty_font, w * .5, self.option_h * .5, textcolor_60, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
self.droppedMenu.SizeToChilds = function()
|
||||
local childs = self.droppedMenu:GetCanvas():GetChildren()
|
||||
local visible_childs = 0
|
||||
local childs_h = 0
|
||||
|
||||
for k,v in ipairs(childs) do
|
||||
if v:IsVisible() then
|
||||
childs_h = childs_h + v:GetTall()
|
||||
visible_childs = visible_childs + 1
|
||||
end
|
||||
|
||||
if visible_childs >= 5 then break end
|
||||
end
|
||||
|
||||
self.droppedMenu:SetTall(math.max(childs_h, visible_childs <= 0 and self.option_h or 0))
|
||||
self.droppedFrame:SetTall(self.droppedMenu:GetTall() + self.search:GetTall())
|
||||
end
|
||||
|
||||
self.no_player = vgui.Create("SButton", self.droppedMenu)
|
||||
:Dock(TOP)
|
||||
:SetLinePos(0)
|
||||
:SetTall(slib.getScaledSize(24, "y"))
|
||||
:SetZPos(-100)
|
||||
:SetVisible(false)
|
||||
|
||||
self.no_player.skipVisible = true
|
||||
|
||||
local noply_titl = "No Player"
|
||||
|
||||
self.no_player.Paint = function(s,w,h)
|
||||
surface.SetDrawColor(s:IsHovered() and maincolor_12 or maincolor_15)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
draw.SimpleText(noply_titl, self.buttonfont or s.font, margin, h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
self.no_player.DoClick = function()
|
||||
self.titl = noply_titl
|
||||
self.ply = nil
|
||||
|
||||
self.close.DoClick()
|
||||
self:setTitle(noply_titl, TEXT_ALIGN_LEFT, true)
|
||||
|
||||
if isfunction(self.onValueChange) then
|
||||
self.onValueChange(val, ply)
|
||||
end
|
||||
end
|
||||
|
||||
slib.panels["SPlayerSelector"] = slib.panels["SPlayerSelector"] or {}
|
||||
table.insert(slib.panels["SPlayerSelector"], self)
|
||||
|
||||
timer.Simple(0, function()
|
||||
if !IsValid(self) then return end
|
||||
|
||||
for k,v in ipairs(player.GetAll()) do
|
||||
self:addOption(v)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function PANEL:SetScrollBG(col)
|
||||
self.droppedMenu.scrollbg = col
|
||||
end
|
||||
|
||||
function PANEL:FindSelectPlayer(ply)
|
||||
for k,v in ipairs(self.droppedMenu:GetCanvas():GetChildren()) do
|
||||
if v.ply == ply then
|
||||
v.DoClick()
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:SetPlaceholder(str)
|
||||
self:setTitle(str, TEXT_ALIGN_LEFT)
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
if IsValid(self.droppedFrame) then self.droppedFrame:Remove() end
|
||||
end
|
||||
|
||||
function PANEL:popupAlone()
|
||||
self:DoClick()
|
||||
|
||||
local x, y = input.GetCursorPos()
|
||||
if !IsValid(self.droppedFrame) then return end
|
||||
self.droppedFrame:SetWide(self:GetWide())
|
||||
self.droppedFrame:SetPos(x, y)
|
||||
self.droppedFrame:MakePopup()
|
||||
self:SetVisible(false)
|
||||
|
||||
self.droppedMenu:SetWide(self.droppedFrame:GetWide())
|
||||
|
||||
self.onClose = function() self:Remove() end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:updatedFilters()
|
||||
for k, v in ipairs(self.droppedMenu:GetCanvas():GetChildren()) do
|
||||
local result = true
|
||||
|
||||
if v.skipVisible then continue end
|
||||
|
||||
if self.filter then
|
||||
if self.filter(v.ply) == false then result = false end
|
||||
end
|
||||
|
||||
v:SetVisible(result)
|
||||
end
|
||||
|
||||
self:pickFirst()
|
||||
end
|
||||
|
||||
function PANEL:pickFirst()
|
||||
local childs = self.droppedMenu:GetCanvas():GetChildren()
|
||||
|
||||
for k,v in ipairs(childs) do
|
||||
if !v:IsVisible() then continue end
|
||||
|
||||
v.DoClick(true)
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:ScrollToFirst()
|
||||
local childs = self.droppedMenu:GetCanvas():GetChildren()
|
||||
|
||||
for k,v in ipairs(childs) do
|
||||
if !v:IsVisible() then continue end
|
||||
|
||||
self.droppedMenu:ScrollToChild(v)
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:ShowNoPlayer(bool)
|
||||
self.no_player:SetVisible(bool)
|
||||
|
||||
self.droppedMenu:InvalidateLayout(true)
|
||||
self.droppedMenu:SizeToChilds()
|
||||
end
|
||||
|
||||
function PANEL:addOption(ply)
|
||||
self.addedPlys = self.addedPlys or {}
|
||||
|
||||
if self.addedPlys[ply] then return end
|
||||
|
||||
self.addedPlys[ply] = true
|
||||
|
||||
local iteration = self.iteration
|
||||
local nick, sid64 = ply:Nick(), ply:SteamID64()
|
||||
|
||||
self.options[iteration] = vgui.Create("SButton", self.droppedMenu)
|
||||
:Dock(TOP)
|
||||
:SetLinePos(0)
|
||||
:SetTall(self.option_h)
|
||||
|
||||
local visibility = !self.filter or self.filter(ply) != false
|
||||
self.options[iteration]:SetVisible(visibility)
|
||||
|
||||
self.options[iteration].ply = ply
|
||||
self.options[iteration].nick = nick
|
||||
self.options[iteration].sid64 = sid64
|
||||
|
||||
local avatar = vgui.Create("AvatarImage", self.options[iteration])
|
||||
avatar:SetPlayer(ply, 64)
|
||||
avatar:SetSize(self.option_h, self.option_h)
|
||||
avatar:SetMouseInputEnabled(false)
|
||||
|
||||
local wide = self.options[iteration]:GetWide()
|
||||
|
||||
self.options[iteration].accentheight = 1
|
||||
|
||||
self.droppedMenu:InvalidateLayout(true)
|
||||
self.droppedMenu:SizeToChilds()
|
||||
|
||||
self.options[iteration].DoClick = function()
|
||||
self.titl = nick
|
||||
self.ply = ply
|
||||
|
||||
self.close.DoClick()
|
||||
self:setTitle(nick, TEXT_ALIGN_LEFT, true)
|
||||
|
||||
if isfunction(self.onValueChange) then
|
||||
self.onValueChange(val, ply)
|
||||
end
|
||||
end
|
||||
|
||||
self.options[iteration].Paint = function(s,w,h)
|
||||
if !IsValid(ply) then s:Remove() if IsValid(self.droppedMenu) then self.droppedMenu:InvalidateLayout(true) end end
|
||||
|
||||
surface.SetDrawColor(s:IsHovered() and maincolor_12 or maincolor_15)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
draw.SimpleText(nick, self.buttonfont or self.options[iteration].font, self.option_h + margin, h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
|
||||
draw.SimpleText(sid64, sid_font, self.option_h + margin, h * .5, textcolor_60, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
|
||||
end
|
||||
|
||||
if wide > self:GetWide() then
|
||||
self:SetWide(wide)
|
||||
end
|
||||
|
||||
self.iteration = self.iteration + 1
|
||||
|
||||
self.lastchild = self.options[iteration]
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:SelectOption(int)
|
||||
self.options[int].DoClick()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:Reposition()
|
||||
local x, y = self:LocalToScreen(0,0)
|
||||
if !IsValid(self.droppedMenu) then return end
|
||||
self.droppedFrame:SetWide(self:GetWide())
|
||||
self.droppedFrame:SetPos(x, y)
|
||||
self.droppedFrame:MakePopup()
|
||||
|
||||
self.droppedMenu:SetWide(self.droppedFrame:GetWide())
|
||||
self.closesearch:SetPos(self:GetWide() - self.option_h, 0)
|
||||
end
|
||||
|
||||
function PANEL:DoClick()
|
||||
self.close:SetVisible(!self.droppedFrame:IsVisible())
|
||||
self.close:MakePopup()
|
||||
|
||||
local childs = self.droppedMenu:GetCanvas():GetChildren()
|
||||
|
||||
self.droppedFrame:SetVisible(!self.droppedFrame:IsVisible())
|
||||
self.search:SetValue(self.search.placeholder)
|
||||
|
||||
for k, v in ipairs(childs) do
|
||||
local result = true
|
||||
|
||||
if v.skipVisible then continue end
|
||||
|
||||
if self.filter then
|
||||
if self.filter(v.ply) == false then result = false end
|
||||
end
|
||||
|
||||
v:SetVisible(result)
|
||||
end
|
||||
|
||||
self.droppedMenu:GetCanvas():InvalidateLayout()
|
||||
|
||||
self:ScrollToFirst()
|
||||
|
||||
self.droppedMenu.SizeToChilds()
|
||||
|
||||
self:setTitle("")
|
||||
|
||||
self:Reposition()
|
||||
end
|
||||
|
||||
function PANEL:OnSizeChanged()
|
||||
self:Reposition()
|
||||
end
|
||||
|
||||
function PANEL:PaintOver(w,h)
|
||||
local size = math.min(h * .7, slib.getScaledSize(12, "y"))
|
||||
local thickness = slib.getScaledSize(2, "x")
|
||||
|
||||
draw.NoTexture()
|
||||
|
||||
local wantedCol = (self:IsHovered() or (IsValid(self.closesearch) and self.closesearch:IsHovered())) and color_white or hovercolor
|
||||
|
||||
surface.SetDrawColor(wantedCol)
|
||||
surface.SetMaterial(icon)
|
||||
surface.DrawTexturedRect(w - size - margin * 2, h * .5 - size * .5, size, size)
|
||||
end
|
||||
|
||||
hook.Add("OnEntityCreated", "slib:AddNewPlayerSelector", function(ent)
|
||||
timer.Simple(3, function()
|
||||
if IsValid(ent) and slib.panels["SPlayerSelector"] and ent:IsPlayer() then
|
||||
for k,v in ipairs(slib.panels["SPlayerSelector"]) do
|
||||
if !IsValid(v) then continue end
|
||||
|
||||
v:addOption(ent)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
vgui.Register("SPlayerSelector", PANEL, "SButton")
|
||||
123
lua/slib/vgui/cl_spopupbox.lua
Normal file
123
lua/slib/vgui/cl_spopupbox.lua
Normal file
@@ -0,0 +1,123 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font = slib.createFont("Roboto", 13)
|
||||
local textcolor, textcolor_min10, margin, maincolor_10 = slib.getTheme("textcolor"), slib.getTheme("textcolor", -10), slib.getTheme("margin"), slib.getTheme("maincolor", 10)
|
||||
|
||||
function PANEL:Init()
|
||||
self:SetSize(slib.getScaledSize(260, "x"), self.topbarheight)
|
||||
self:Center()
|
||||
self:addCloseButton()
|
||||
self.frame:DockPadding(0,margin,0,0)
|
||||
|
||||
self.bgcloser = vgui.Create("SButton")
|
||||
self.bgcloser:Dock(FILL)
|
||||
self.bgcloser:MakePopup()
|
||||
self.bgcloser.Paint = function() end
|
||||
self.bgcloser.DoClick = function()
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
local buttonsH = slib.getScaledSize(25, "y")
|
||||
self.choises = vgui.Create("EditablePanel", self.frame)
|
||||
self.choises:Dock(BOTTOM)
|
||||
self.choises:SetTall(slib.getScaledSize(25, "y"))
|
||||
self.choises:DockMargin(0,0,0,margin)
|
||||
self.choises:DockPadding(margin,0,margin,0)
|
||||
|
||||
self.choises.ResizeChilds = function()
|
||||
local childs = self.choises:GetChildren()
|
||||
local count = table.Count(childs)
|
||||
local width = self.choises:GetWide()
|
||||
|
||||
for k,v in pairs(childs) do
|
||||
v:SetWide(math.Clamp(width / count, 0, width - (margin * 2)) + (count > 1 and k < 3 and -margin*1.5 or 0))
|
||||
if count > 1 then
|
||||
v:DockMargin(k > 1 and margin * .5 or 0,0,margin * .5,0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.choises.OnSizeChanged = self.choises.ResizeChilds
|
||||
|
||||
self:MakePopup()
|
||||
|
||||
local realh = self.frame:GetTall() - self.choises:GetTall() - margin
|
||||
self.frame.PaintOver = function(s,w,h)
|
||||
if self.parse then
|
||||
self.parse:Draw(w * .5, (h - buttonsH) * .5, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
if IsValid(self.bgcloser) then self.bgcloser:Remove() end
|
||||
end
|
||||
|
||||
function PANEL:setText(str)
|
||||
self.parse = markup.Parse("<colour="..textcolor_min10.r..","..textcolor_min10.g..","..textcolor_min10.b..","..textcolor_min10.a.."><font="..slib.createFont("Roboto", 16)..">"..str.."</font></colour>", self.frame:GetWide() - (margin * 2))
|
||||
local height = self.parse:GetHeight()
|
||||
|
||||
self:SetTall(self:GetTall() + height + (margin * 6))
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
local inputTypes = {
|
||||
["int"] = "STextEntry",
|
||||
["dropdown"] = "SDropDown",
|
||||
["text"] = "STextEntry"
|
||||
}
|
||||
|
||||
function PANEL:addInput(type, placeholder)
|
||||
placeholder = placeholder or ""
|
||||
local element = vgui.Create(inputTypes[type], self.frame)
|
||||
element:Dock(TOP)
|
||||
element:DockMargin(margin, 0, margin, margin)
|
||||
element:SetTall(slib.getScaledSize(25, "y"))
|
||||
element.placeholder = placeholder
|
||||
element.bg = maincolor_10
|
||||
|
||||
if type == "int" then
|
||||
element:SetNumeric(true)
|
||||
element:SetRefreshRate(0)
|
||||
end
|
||||
|
||||
element:SetPlaceholder(placeholder)
|
||||
|
||||
self:SetTall(self:GetTall() + element:GetTall() + margin)
|
||||
|
||||
return element
|
||||
end
|
||||
|
||||
function PANEL:addChoise(title, func)
|
||||
if !self.addedH then
|
||||
self:SetTall(self:GetTall() + self.choises:GetTall() + margin)
|
||||
end
|
||||
|
||||
self.addedH = true
|
||||
|
||||
local choise = vgui.Create("SButton", self.choises)
|
||||
choise:setTitle(title)
|
||||
choise:Dock(LEFT)
|
||||
choise:DockMargin(0,margin,0,0)
|
||||
choise:SetTall(slib.getScaledSize(25, "y"))
|
||||
choise.bg = slib.getTheme("maincolor", 5)
|
||||
|
||||
choise.DoClick = function() if func then func() end self:Remove() end
|
||||
|
||||
self.choises.ResizeChilds()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
vgui.Register("SPopupBox", PANEL, "SFrame")
|
||||
44
lua/slib/vgui/cl_sscrollpanel.lua
Normal file
44
lua/slib/vgui/cl_sscrollpanel.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local elegantcol, maincol, maincol_5 = Color(255,255,255,3), slib.getTheme("maincolor"), slib.getTheme("maincolor", 5)
|
||||
|
||||
function PANEL:Init()
|
||||
local scr = self:GetVBar()
|
||||
scr:SetHideButtons(true)
|
||||
|
||||
scr.Paint = function(_, w, h)
|
||||
surface.SetDrawColor(self.scrollbg or maincol)
|
||||
surface.DrawRect(0,0,w,h)
|
||||
end
|
||||
scr.btnUp.Paint = function(_, w, h)end
|
||||
scr.btnDown.Paint = function(_, w, h)end
|
||||
scr.btnGrip.Paint = function(_, w, h)
|
||||
draw.RoundedBoxEx(h * .5, w * 0.5 - (w * 0.45 / 2), h * 0.03, w * 0.45, h - h * 0.06, elegantcol, true, true, true, true)
|
||||
end
|
||||
|
||||
slib.wrapFunction(self, "SetSize", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "Center", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetTall", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
if self.bg then
|
||||
surface.SetDrawColor(self.bg)
|
||||
surface.DrawRect(0,0,w,h)
|
||||
end
|
||||
end
|
||||
|
||||
vgui.Register("SScrollPanel", PANEL, "DScrollPanel")
|
||||
65
lua/slib/vgui/cl_ssearchbar.lua
Normal file
65
lua/slib/vgui/cl_ssearchbar.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local maincolor_15, accentcolor, margin = slib.getTheme("maincolor", 15), slib.getTheme("accentcolor"), slib.getTheme("margin")
|
||||
|
||||
function PANEL:Init()
|
||||
self:Dock(TOP)
|
||||
self:SetTall(slib.getScaledSize(25, "y"))
|
||||
self.font = slib.createFont("Roboto", 15)
|
||||
self.material = Material("slib/icons/search32.png", "noclamp smooth")
|
||||
self.bg = maincolor_15
|
||||
|
||||
self.entry = vgui.Create( "STextEntry", self )
|
||||
self.entry:Dock(FILL)
|
||||
|
||||
slib.wrapFunction(self, "SetZPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetWide", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:addIcon()
|
||||
self.icon = true
|
||||
self.entry:DockMargin(slib.getScaledSize(25, "y") + margin,0,0,0)
|
||||
self.entry:AccentSideLine(true)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:SetPlaceholder(str)
|
||||
self.entry:SetPlaceholder(str)
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
local size = h * .65
|
||||
local pos = h * .5 - (size * .5)
|
||||
|
||||
if self.bg then
|
||||
surface.SetDrawColor(self.bg)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
|
||||
local wantedcolor = accentcolor
|
||||
wantedcolor.a = self.entry:HasFocus() and 120 or 20
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(self, wantedcolor))
|
||||
surface.DrawRect(h - 1, margin, 1, h - (margin * 2))
|
||||
|
||||
if self.icon then
|
||||
surface.SetDrawColor(color_white)
|
||||
surface.SetMaterial(self.material)
|
||||
surface.DrawTexturedRect(pos, pos, size, size)
|
||||
end
|
||||
end
|
||||
|
||||
vgui.Register("SSearchBar", PANEL, "EditablePanel")
|
||||
219
lua/slib/vgui/cl_sstatement.lua
Normal file
219
lua/slib/vgui/cl_sstatement.lua
Normal file
@@ -0,0 +1,219 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local colorpickerMat, checkmarkMat = Material("slib/icons/color-picker16.png", "noclamp smooth" ), Material("slib/icons/checkmark.png", "noclamp smooth" )
|
||||
|
||||
local textcolor, textcolor_50, maincolor, maincolor_7, maincolor_10, accentcolor, cleanaccentcolor = slib.getTheme("textcolor"), slib.getTheme("textcolor", -50), slib.getTheme("maincolor"), slib.getTheme("maincolor", 7), slib.getTheme("maincolor", 10), slib.getTheme("accentcolor"), slib.getTheme("accentcolor")
|
||||
local margin = slib.getTheme("margin")
|
||||
|
||||
function PANEL:Init()
|
||||
self:Dock(TOP)
|
||||
self:SetTall(slib.getScaledSize(25, "y"))
|
||||
self:DockMargin(margin, 0, margin, margin)
|
||||
self.font = slib.createFont("Roboto", 14)
|
||||
self.bg = maincolor_7
|
||||
self.elemBg = maincolor
|
||||
|
||||
slib.wrapFunction(self, "SetZPos", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
surface.SetDrawColor(self.bg)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
draw.SimpleText(self.name, self.font, self.center and w * .5 - self.xoffset - margin or margin, h * .5, textcolor, self.center and TEXT_ALIGN_CENTER or TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
function PANEL:OnSizeChanged(w, h)
|
||||
if self.center then
|
||||
self:setCenter()
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:setCenter()
|
||||
self.center = true
|
||||
|
||||
self.xoffset = self.element:GetWide() * .5
|
||||
|
||||
surface.SetFont(self.font)
|
||||
local w, h = surface.GetTextSize(self.name)
|
||||
|
||||
local l,t,r,b = self.element:GetDockMargin()
|
||||
self.element:DockMargin(l,t,self:GetWide() * .5 - self.xoffset - (w * .5) - margin,b)
|
||||
end
|
||||
|
||||
function PANEL:addStatement(name, value)
|
||||
self.name = name
|
||||
local statement = slib.getStatement(value)
|
||||
local element
|
||||
|
||||
if statement == "color" then
|
||||
element = vgui.Create("SButton", self)
|
||||
element:SetWide(slib.getScaledSize(25, "y") - slib.getScaledSize(2, "x") - slib.getScaledSize(2, "x"))
|
||||
element.color = value
|
||||
element.old_color = value
|
||||
|
||||
element.Paint = function(s,w,h)
|
||||
draw.RoundedBox(h * .3, 0, 0, w, h, element.color)
|
||||
|
||||
surface.SetDrawColor(textcolor_50)
|
||||
surface.SetMaterial(colorpickerMat)
|
||||
local sizew, sizeh = 16, 16
|
||||
|
||||
surface.DrawTexturedRect( (w * .5) - (sizew * .5), (h * .5) - (sizeh * .5), sizew, sizeh )
|
||||
end
|
||||
|
||||
element.OnRemove = function()
|
||||
if IsValid(element.ColorPicker) then element.ColorPicker:Remove() end
|
||||
end
|
||||
|
||||
element.DoClick = function()
|
||||
if element.ColorPicker and IsValid(element.ColorPicker) then return end
|
||||
|
||||
local posx, posy = self:LocalToScreen( element:GetPos() )
|
||||
|
||||
element.ClosePicker = vgui.Create("SButton")
|
||||
element.ClosePicker:Dock(FILL)
|
||||
element.ClosePicker:MakePopup()
|
||||
element.ClosePicker.DoClick = function()
|
||||
if IsValid(element.ColorPicker) then element.ColorPicker:Remove() end
|
||||
if IsValid(element.ClosePicker) then element.ClosePicker:Remove() end
|
||||
end
|
||||
|
||||
element.ClosePicker.Paint = function() end
|
||||
|
||||
element.ColorPicker = vgui.Create("DColorMixer")
|
||||
element.ColorPicker:SetSize( slib.getScaledSize(200, "x"), slib.getScaledSize(160, "y") )
|
||||
element.ColorPicker:SetPos( posx - element.ColorPicker:GetWide(), posy )
|
||||
element.ColorPicker:SetPalette(false)
|
||||
element.ColorPicker:SetAlphaBar(false)
|
||||
element.ColorPicker:SetAlphaBar( true )
|
||||
element.ColorPicker:SetWangs(false)
|
||||
element.ColorPicker:SetColor(element.color and element.color or Color(255,0,0))
|
||||
element.ColorPicker:MakePopup()
|
||||
|
||||
element.ColorPicker.Think = function()
|
||||
element.color = element.ColorPicker:GetColor()
|
||||
end
|
||||
|
||||
element.ColorPicker.OnRemove = function()
|
||||
element.old_color = element.color
|
||||
|
||||
if isfunction(element.onValueChange) then
|
||||
local result = element.onValueChange(element.color)
|
||||
if result == false then element.color = element.old_color end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif statement == "bool" then
|
||||
element = vgui.Create("SButton", self)
|
||||
element:SetWide(slib.getScaledSize(25, "y") - slib.getScaledSize(2, "x") - slib.getScaledSize(2, "x"))
|
||||
element.basealpha = cleanaccentcolor.a
|
||||
|
||||
element.Paint = function(s,w,h)
|
||||
draw.RoundedBox(h * .3, 0, 0, w, h, self.elemBg)
|
||||
|
||||
local wantedcolor = accentcolor
|
||||
|
||||
wantedcolor.a = s.enabled and element.basealpha or 0
|
||||
|
||||
local ico_size = h * .55
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(s, wantedcolor, 3))
|
||||
surface.SetMaterial(checkmarkMat)
|
||||
surface.DrawTexturedRect(w * .5 - ico_size * .5,h * .5 - ico_size * .5, ico_size, ico_size)
|
||||
end
|
||||
|
||||
element.enabled = value
|
||||
|
||||
element.DoClick = function()
|
||||
element.enabled = !element.enabled
|
||||
|
||||
if isfunction(element.onValueChange) then
|
||||
local result = element.onValueChange(element.enabled)
|
||||
if result == false then element.enabled = !element.enabled end
|
||||
end
|
||||
end
|
||||
elseif statement == "int" then
|
||||
element = vgui.Create("DNumberWang", self)
|
||||
element:SetWide(slib.getScaledSize(50, "x"))
|
||||
element:SetDrawLanguageID(false)
|
||||
element:SetFont(self.font)
|
||||
element:SetMin(0)
|
||||
element:SetMax(2000000)
|
||||
element.oldValue = value
|
||||
|
||||
element.Paint = function(s,w,h)
|
||||
draw.RoundedBox(h * .3, 0, 0, w, h, self.elemBg)
|
||||
|
||||
s:DrawTextEntryText(textcolor, cleanaccentcolor, cleanaccentcolor)
|
||||
end
|
||||
|
||||
element.OnValueChanged = function(ignore)
|
||||
local oldValue = element.oldValue
|
||||
local newValue = element:GetValue()
|
||||
|
||||
timer.Create(tostring(element), .3, 1, function()
|
||||
if isfunction(element.onValueChange) then
|
||||
local result = element.onValueChange(newValue)
|
||||
if result == false then
|
||||
element.oldValue = oldValue
|
||||
element:SetText(oldValue)
|
||||
return end
|
||||
|
||||
element.oldValue = newValue
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
element:SetText(value)
|
||||
elseif statement == "function" or statement == "table" then
|
||||
element = vgui.Create("SButton", self)
|
||||
element:Dock(RIGHT)
|
||||
element:DockMargin(0,slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"))
|
||||
element:setTitle(statement == "function" and "Execute" or "View Table")
|
||||
|
||||
element.DoClick = function()
|
||||
if statement == "function" then
|
||||
value()
|
||||
return end
|
||||
|
||||
local display_data = vgui.Create("STableViewer")
|
||||
display_data:setTable(value)
|
||||
display_data:SetBG(false, true, nil, true)
|
||||
|
||||
if isfunction(element.onElementOpen) then
|
||||
element.onElementOpen(display_data)
|
||||
end
|
||||
end
|
||||
elseif statement == "string" then
|
||||
element = vgui.Create("DTextEntry", self)
|
||||
element:SetWide(slib.getScaledSize(80, "x"))
|
||||
element:SetDrawLanguageID(false)
|
||||
element:SetFont(self.font)
|
||||
element.Paint = function(s,w,h)
|
||||
draw.RoundedBox(h * .3, 0, 0, w, h, self.elemBg)
|
||||
|
||||
s:DrawTextEntryText(textcolor, cleanaccentcolor, cleanaccentcolor)
|
||||
end
|
||||
end
|
||||
|
||||
element:Dock(RIGHT)
|
||||
element:DockMargin(0,slib.getScaledSize(2, "x"),slib.getScaledSize(2, "x"),slib.getScaledSize(2, "x"))
|
||||
|
||||
self.element = element
|
||||
|
||||
return self, element
|
||||
end
|
||||
|
||||
vgui.Register("SStatement", PANEL, "EditablePanel")
|
||||
426
lua/slib/vgui/cl_stableviewer.lua
Normal file
426
lua/slib/vgui/cl_stableviewer.lua
Normal file
@@ -0,0 +1,426 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local font = slib.createFont("Roboto", 15)
|
||||
local neutralcolor, textcolor, successcolor_100, failcolor_100, maincolor_5, maincolor_7, maincolor_10, maincolor_15 = slib.getTheme("neutralcolor"), slib.getTheme("textcolor"), slib.getTheme("successcolor", -100), slib.getTheme("failcolor", -100), slib.getTheme("maincolor", 5), slib.getTheme("maincolor", 7), slib.getTheme("maincolor", 10), slib.getTheme("maincolor", 15)
|
||||
|
||||
function PANEL:Init()
|
||||
self:SetSize(slib.getScaledSize(450, "x"), slib.getScaledSize(330, "y"))
|
||||
:Center()
|
||||
:MakePopup()
|
||||
:addCloseButton()
|
||||
:setTitle("Table Viewer", slib.createFont("Roboto", 17))
|
||||
:setBlur(true)
|
||||
|
||||
self.entryheight = slib.getScaledSize(20, "y")
|
||||
|
||||
self.viewbox = vgui.Create("EditablePanel", self.frame)
|
||||
self.viewbox:Dock(RIGHT)
|
||||
self.viewbox:SetWide(self.frame:GetWide())
|
||||
|
||||
self.viewer = vgui.Create("SScrollPanel", self.viewbox)
|
||||
:Dock(FILL)
|
||||
end
|
||||
|
||||
local function createButton(self, parent, str, val)
|
||||
local istbl = istable(val)
|
||||
local selparent = parent and parent or self.viewer
|
||||
|
||||
local value = vgui.Create("SButton", selparent)
|
||||
:Dock(TOP)
|
||||
:SetZPos(-10)
|
||||
:SetTall(slib.getScaledSize(25, "y"))
|
||||
|
||||
value.title = str
|
||||
value.tbl = istbl and val or parent.tbl
|
||||
|
||||
value.Paint = function(s,w,h)
|
||||
local wantedcolor = selparent == self.suggestions and successcolor_100 or (value.toggleable and selparent.tbl[str] and successcolor_100 or failcolor_100)
|
||||
|
||||
if !value.toggleable and (!s:IsHovered() or self.viewOnly) then
|
||||
wantedcolor = table.Copy(wantedcolor)
|
||||
wantedcolor.a = 0
|
||||
end
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(s, wantedcolor))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
local display = ""
|
||||
|
||||
if !istbl and (isstring(val) or isnumber(val)) then
|
||||
display = ": "..tostring(val)
|
||||
end
|
||||
|
||||
draw.SimpleText(str..display, font, slib.getTheme("margin"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
value.Think = function()
|
||||
if !value.toggleable and self:getRule("toggleables", str) then
|
||||
value.toggleable = true
|
||||
end
|
||||
|
||||
if value:IsHovered() and input.IsKeyDown(KEY_LSHIFT) and input.IsMouseDown(MOUSE_RIGHT) then
|
||||
value:DoClick()
|
||||
end
|
||||
end
|
||||
|
||||
value.DoClick = function()
|
||||
if self.viewOnly then return end
|
||||
|
||||
self.modified = true
|
||||
|
||||
if selparent == self.suggestions then
|
||||
local edit = IsValid(self.selected) and self.selected or self.viewer
|
||||
|
||||
if self.rules and self.rules.onlymodifytable and edit:GetName() == "SScrollPanel" then return end
|
||||
|
||||
if self.customvalues then
|
||||
local popup = vgui.Create("SPopupBox")
|
||||
:setTitle(value.title)
|
||||
|
||||
local entry = popup:addInput("text", self.customvalueplaceholder)
|
||||
|
||||
if self.customnumeric then
|
||||
entry:SetNumeric(true)
|
||||
end
|
||||
|
||||
popup:addChoise(self.customvalues, function()
|
||||
local val = entry:GetValue()
|
||||
self:addValue(editTbl, value.title, val, edit)
|
||||
edit.tbl[value.title] = val
|
||||
|
||||
if edit == self.viewer then
|
||||
self:sortValues(self.viewer)
|
||||
end
|
||||
end)
|
||||
|
||||
return
|
||||
else
|
||||
edit.tbl[value.title] = true
|
||||
self:addValue(editTbl, value.title, true, edit)
|
||||
end
|
||||
|
||||
if edit == self.viewer then
|
||||
self:sortValues(self.viewer)
|
||||
end
|
||||
else
|
||||
if value.toggleable then
|
||||
selparent.tbl[str] = !selparent.tbl[str]
|
||||
return end
|
||||
|
||||
value:Remove()
|
||||
end
|
||||
|
||||
selparent.tbl[str] = nil
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
function PANEL:addValue(panel, str, val, parent)
|
||||
if istable(val) then
|
||||
local selpar = parent or panel
|
||||
parent = vgui.Create("EditablePanel", selpar)
|
||||
parent:Dock(TOP)
|
||||
parent:SetTall(slib.getScaledSize(25, "y"))
|
||||
parent:DockMargin(slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"),slib.getTheme("margin"))
|
||||
parent:DockPadding(0,slib.getScaledSize(25, "y"),0,0)
|
||||
parent.isTblContainer = true
|
||||
parent.tbl = val
|
||||
parent.title = str
|
||||
parent.OnSizeChanged = function(w,h)
|
||||
parent.top:SetWide(parent:GetWide())
|
||||
end
|
||||
|
||||
parent.top = vgui.Create("SButton", parent)
|
||||
parent.top:SetSize(parent:GetWide(), slib.getScaledSize(25, "y"))
|
||||
|
||||
parent.top.DoClick = function()
|
||||
if self.rules and self.rules.tableDeletable and !self:getRule("undeleteableTables", str) then
|
||||
parent:Remove()
|
||||
selpar.tbl[str] = nil
|
||||
self.modified = true
|
||||
return end
|
||||
|
||||
self.selected = self.selected ~= parent and parent or nil
|
||||
end
|
||||
|
||||
parent.top.Paint = function(s,w,h)
|
||||
local wantedcolor = self.rules and self.rules.tableDeletable and !self:getRule("undeleteableTables", str) and failcolor_100 or neutralcolor
|
||||
|
||||
surface.SetDrawColor(maincolor_7)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
surface.SetDrawColor(maincolor_5)
|
||||
surface.DrawRect(0,h-1,w,1)
|
||||
|
||||
if self.rules and self.rules.tableDeletable and !self:getRule("undeleteableTables", str) then
|
||||
if !s:IsHovered() then
|
||||
wantedcolor = table.Copy(wantedcolor)
|
||||
wantedcolor.a = 0
|
||||
end
|
||||
elseif self.selected ~= parent then
|
||||
wantedcolor = table.Copy(wantedcolor)
|
||||
wantedcolor.a = 0
|
||||
end
|
||||
|
||||
|
||||
surface.SetDrawColor(slib.lerpColor(s, wantedcolor))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
draw.SimpleText(str, font, slib.getTheme("margin"), h * .5, textcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
parent.PaintOver = function(s, w, h)
|
||||
surface.SetDrawColor(maincolor_5)
|
||||
surface.DrawOutlinedRect(0, 0, w, h)
|
||||
end
|
||||
|
||||
parent.OnChildAdded = function(child)
|
||||
local addheight = slib.getScaledSize(25, "y")
|
||||
parent:SetTall(parent:GetTall() + addheight)
|
||||
|
||||
local grandparent = parent:GetParent()
|
||||
if !grandparent.isTblContainer then return end
|
||||
grandparent:SetTall(grandparent:GetTall() + addheight)
|
||||
end
|
||||
|
||||
parent.OnChildRemoved = function(child)
|
||||
local addheight = slib.getScaledSize(25, "y")
|
||||
parent:SetTall(parent:GetTall() - addheight)
|
||||
|
||||
local grandparent = parent:GetParent()
|
||||
if !grandparent.isTblContainer then return end
|
||||
grandparent:SetTall(grandparent:GetTall() - addheight)
|
||||
end
|
||||
|
||||
if selpar ~= self.viewer then
|
||||
selpar:SetTall(selpar:GetTall() + (slib.getTheme("margin") * 2))
|
||||
end
|
||||
|
||||
for k,v in pairs(val) do
|
||||
self:addValue(panel, k, v, parent)
|
||||
end
|
||||
return end
|
||||
|
||||
return createButton(self, parent and parent or panel, str, val)
|
||||
end
|
||||
|
||||
local function differenciate(a, b)
|
||||
if !(isstring(a) == isstring(b)) or isbool(a) or isbool(b) then
|
||||
return tostring(a), tostring(b)
|
||||
end
|
||||
|
||||
return a, b
|
||||
end
|
||||
|
||||
function PANEL:setCustomValues(bool, placeholder, numeric)
|
||||
self.customvalues = bool
|
||||
self.customvalueplaceholder = placeholder
|
||||
self.customnumeric = numeric
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:sortValues(panel)
|
||||
if !IsValid(panel) then return self end
|
||||
local basictable = {}
|
||||
local cleantable = {}
|
||||
|
||||
for k,v in pairs(panel.tbl) do
|
||||
table.insert(basictable, k)
|
||||
end
|
||||
|
||||
table.sort(basictable, function(a, b) local a, b = differenciate(a, b) return a < b end)
|
||||
|
||||
for k,v in pairs(basictable) do
|
||||
cleantable[v] = k
|
||||
end
|
||||
|
||||
for k, v in pairs(panel:GetCanvas():GetChildren()) do
|
||||
if !v.title then continue end
|
||||
v:SetZPos(cleantable[v.title])
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addSuggestions(tbl)
|
||||
if !tbl then return self end
|
||||
|
||||
local wide, tall = self.frame:GetWide() * .5, self.frame:GetTall()
|
||||
self.viewer:SetPos(wide, 0)
|
||||
self.viewer:SetWide(wide)
|
||||
|
||||
self.suggestionbox = vgui.Create("EditablePanel", self.frame)
|
||||
self.suggestionbox:Dock(LEFT)
|
||||
self.suggestionbox:SetWide(self.frame:GetWide() * .5)
|
||||
self.viewbox:SetWide(self.frame:GetWide() * .5)
|
||||
|
||||
self.suggestions = vgui.Create("SScrollPanel", self.suggestionbox)
|
||||
self.suggestions:Dock(FILL)
|
||||
self.suggestions.tbl = tbl
|
||||
self.suggestions.hidden = {}
|
||||
|
||||
self.suggestions.PaintOver = function(s,w,h)
|
||||
surface.SetDrawColor(maincolor_10)
|
||||
surface.DrawRect(w - 1, 0, 1, h)
|
||||
end
|
||||
|
||||
self.suggestions.Think = function()
|
||||
local edit = IsValid(self.selected) and self.selected or self.viewer
|
||||
for k, value in pairs(self.suggestions:GetCanvas():GetChildren()) do
|
||||
if value:IsVisible() ~= !edit.tbl[value.title] and !value.searchHidden then
|
||||
value:SetVisible(!edit.tbl[value.title])
|
||||
self.suggestions:GetCanvas():InvalidateLayout(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k,v in pairs(tbl) do
|
||||
self:addValue(self.suggestions, k, v)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:setOnlyModifyTable(bool)
|
||||
self.rules = self.rules or {}
|
||||
self.rules.onlymodifytable = bool
|
||||
end
|
||||
|
||||
function PANEL:setToggleable(module, name, string)
|
||||
self.rules = self.rules or {}
|
||||
self.rules[module] = self.rules[module] or {}
|
||||
self.rules[module][name] = self.rules[module][name] or {}
|
||||
self.rules[module][name].toggleables = self.rules[module][name].toggleables or {}
|
||||
|
||||
self.rules[module][name].toggleables[string] = true
|
||||
end
|
||||
|
||||
function PANEL:setTableDeletable(bool)
|
||||
self.rules = self.rules or {}
|
||||
self.rules.tableDeletable = bool
|
||||
end
|
||||
|
||||
function PANEL:setundeleteableTable(module, name, string)
|
||||
self.rules = self.rules or {}
|
||||
self.rules[module] = self.rules[module] or {}
|
||||
self.rules[module][name] = self.rules[module][name] or {}
|
||||
self.rules[module][name].undeleteableTables = self.rules[module][name].undeleteableTables or {}
|
||||
|
||||
self.rules[module][name].undeleteableTables[string] = true
|
||||
end
|
||||
|
||||
function PANEL:setAddRules(rule)
|
||||
self.rules = self.rules or {}
|
||||
self.rules.addRules = rule
|
||||
end
|
||||
|
||||
function PANEL:getRule(type, str)
|
||||
local returnval = false
|
||||
|
||||
if self.rules and self.rules[self.modulename] and self.rules[self.modulename][self.name] and self.rules[self.modulename][self.name][type] and self.rules[self.modulename][self.name][type][str] then
|
||||
returnval = true
|
||||
end
|
||||
|
||||
return returnval
|
||||
end
|
||||
|
||||
function PANEL:setIdentifiers(module, name)
|
||||
self.modulename, self.name = module, name
|
||||
end
|
||||
|
||||
function PANEL:setTable(tbl)
|
||||
if !tbl or !istable(tbl) then return self end
|
||||
self.viewer.tbl = tbl
|
||||
for k,v in pairs(tbl) do
|
||||
self:addValue(self.viewer, k, v)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addSearch(panel, viewer)
|
||||
if !IsValid(panel) or !IsValid(viewer) then return self end
|
||||
panel.search = vgui.Create("SSearchBar", panel)
|
||||
:addIcon()
|
||||
:SetWide(panel:GetWide())
|
||||
:Dock(TOP)
|
||||
:DockMargin(0,0,0,0)
|
||||
|
||||
panel.search.entry.onValueChange = function(newvalue)
|
||||
for k,v in pairs(viewer:GetCanvas():GetChildren()) do
|
||||
if !v.title then continue end
|
||||
|
||||
v:SetVisible(string.find(string.lower(v.title), string.lower(newvalue)))
|
||||
|
||||
if v:IsVisible() then
|
||||
v.searchHidden = nil
|
||||
else
|
||||
v.searchHidden = true
|
||||
end
|
||||
end
|
||||
|
||||
viewer:GetCanvas():InvalidateLayout(true)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:addEntry()
|
||||
self.addEntryFrame = vgui.Create("EditablePanel", self.viewbox)
|
||||
self.addEntryFrame:Dock(BOTTOM)
|
||||
|
||||
self.addEntryButton = vgui.Create("SButton", self.addEntryFrame)
|
||||
:Dock(RIGHT)
|
||||
:setTitle("Add")
|
||||
|
||||
self.addEntryButton.accentheight = 1
|
||||
self.addEntryButton.bg = maincolor_10
|
||||
|
||||
self.addEntryButton.DoClick = function()
|
||||
local key, edit = self.entry:GetValue(), (IsValid(self.selected) and self.selected or self.viewer)
|
||||
if !key or key == "" or edit.tbl[key] then return end
|
||||
if self.rules and self.rules.onlymodifytable and edit:GetName() == "SScrollPanel" then return end
|
||||
|
||||
local val
|
||||
|
||||
if self.rules and self.rules.addRules and edit:GetName() == "SScrollPanel" then
|
||||
val = table.Copy(self.rules.addRules)
|
||||
end
|
||||
|
||||
if !val then val = key end
|
||||
|
||||
local result = !istable(val) and true or val
|
||||
edit.tbl[key] = result
|
||||
|
||||
self:addValue(edit, key, result, edit)
|
||||
self:sortValues(self.viewer)
|
||||
self.modified = true
|
||||
self.entry:SetValue("")
|
||||
end
|
||||
|
||||
self.entry = vgui.Create("STextEntry", self.addEntryFrame)
|
||||
:Dock(FILL)
|
||||
:SetValue("")
|
||||
|
||||
self.entry.bg = maincolor_10
|
||||
|
||||
self.entry.placeholder = ""
|
||||
|
||||
self.addEntryFrame:SetTall(self.entry:GetTall())
|
||||
self.addEntryButton:SetTall(self.entry:GetTall())
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
vgui.Register("STableViewer", PANEL, "SFrame")
|
||||
100
lua/slib/vgui/cl_stextentry.lua
Normal file
100
lua/slib/vgui/cl_stextentry.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local accentcolor, textcolor, textcolor_30, textcolor_80 = slib.getTheme("accentcolor"), slib.getTheme("textcolor"), slib.getTheme("textcolor", -30), slib.getTheme("textcolor", -80)
|
||||
|
||||
function PANEL:Init()
|
||||
slib.wrapFunction(self, "Dock", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetNumeric", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "DockMargin", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetTextColor", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetDrawLanguageID", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetFont", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetTall", nil, function() return self end, true)
|
||||
slib.wrapFunction(self, "SetValue", nil, function() return self end, true)
|
||||
|
||||
self.font = slib.createFont("Roboto", 15)
|
||||
self.placeholder = "Search..."
|
||||
|
||||
self:SetDrawLanguageID(false)
|
||||
:SetTall(slib.getScaledSize(25, "y"))
|
||||
:SetFont(self.font)
|
||||
:SetTextColor(textcolor_80)
|
||||
:SetValue(self.placeholder)
|
||||
end
|
||||
|
||||
function PANEL:Paint(w,h)
|
||||
local val = self:GetValue()
|
||||
local wantedcolor = accentcolor
|
||||
wantedcolor.a = self:HasFocus() and 120 or 20
|
||||
|
||||
if self.bg then
|
||||
surface.SetDrawColor(self.bg)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
|
||||
if !self.sideline then
|
||||
surface.SetDrawColor(slib.lerpColor(self, wantedcolor))
|
||||
surface.DrawRect(0, !self.accentlinetop and h - 1 or 0, w, 1)
|
||||
end
|
||||
|
||||
self:DrawTextEntryText(val == self.placeholder and textcolor_30 or textcolor, accentcolor, textcolor)
|
||||
end
|
||||
|
||||
function PANEL:OnGetFocus()
|
||||
local val = self:GetValue()
|
||||
if val == self.placeholder then
|
||||
self:SetValue("")
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:AccentLineTop(bool)
|
||||
self.accentlinetop = bool
|
||||
end
|
||||
|
||||
function PANEL:SetRefreshRate(rate)
|
||||
self.refreshrate = rate
|
||||
end
|
||||
|
||||
function PANEL:AccentSideLine(bool)
|
||||
self.sideline = bool
|
||||
end
|
||||
|
||||
function PANEL:OnTextChanged()
|
||||
local newvalue = self:GetValue()
|
||||
|
||||
timer.Create(tostring(self), self.refreshrate or .3, 1, function()
|
||||
if !IsValid(self) then return end
|
||||
if isfunction(self.onValueChange) then
|
||||
self.onValueChange(newvalue)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function PANEL:SetPlaceholder(str)
|
||||
self.placeholder = str
|
||||
self:SetValue(self.placeholder)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PANEL:OnLoseFocus()
|
||||
timer.Simple(.1, function()
|
||||
if !IsValid(self) then return end
|
||||
local val = self:GetValue()
|
||||
if !val or val == "" then
|
||||
self:SetValue(self.placeholder)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
vgui.Register("STextEntry", PANEL, "DTextEntry")
|
||||
Reference in New Issue
Block a user