Fixed Lua Errors, clean up and added a GUI skin

- Fixed Lua errors:
  - `lua/streamradio_core/tool.lua:480: attempt to call method 'GetMode' (a nil value)`
  - `lua/entities/base_streamradio.lua:486: attempt to index upvalue 'LIBUtil' (a nil value)`
- Fixed global scope pollution
- Some code clean up and new glualint config
- Added a new GUI skin preset called "Stream Original"
This commit is contained in:
Grocel 2023-11-09 03:52:37 +01:00
parent 7959186671
commit f46b5c1e55
56 changed files with 1226 additions and 1167 deletions

View File

@ -1,6 +1,8 @@
{
"recommendations": [
"venner.vscode-glua-enhanced",
"goz3rr.vscode-glualint"
"goz3rr.vscode-glualint",
"stefan-h-at.source-engine-support"
]
}
}

View File

@ -23,4 +23,5 @@
"LICENSE",
"git-*"
]
}
}

View File

@ -1,29 +1,50 @@
{
"lint_maxScopeDepth": 7,
"lint_syntaxErrors": true,
"lint_syntaxInconsistencies": true,
"lint_deprecated": true,
"lint_trailingWhitespace": true,
"lint_whitespaceStyle": true,
"lint_beginnerMistakes": true,
"lint_emptyBlocks": true,
"lint_shadowing": false,
"lint_gotos": true,
"lint_doubleNegations": true,
"lint_redundantIfStatements": false,
"lint_redundantParentheses": true,
"lint_duplicateTableKeys": true,
"lint_profanity": true,
"lint_unusedVars": true,
"lint_unusedParameters": false,
"lint_unusedLoopVars": false,
"lint_maxScopeDepth": 7,
"lint_syntaxErrors": true,
"lint_syntaxInconsistencies": true,
"lint_deprecated": true,
"lint_trailingWhitespace": true,
"lint_whitespaceStyle": true,
"lint_beginnerMistakes": true,
"lint_emptyBlocks": true,
"lint_shadowing": false,
"lint_gotos": true,
"lint_goto_identifier": true,
"lint_doubleNegations": true,
"lint_redundantIfStatements": false,
"lint_redundantParentheses": true,
"lint_duplicateTableKeys": true,
"lint_profanity": true,
"lint_unusedVars": true,
"lint_unusedParameters": false,
"lint_unusedLoopVars": false,
"lint_inconsistentVariableStyle": false,
"lint_spaceBetweenParens": false,
"lint_spaceBetweenBrackets": false,
"lint_spaceBetweenBraces": false,
"lint_ignoreFiles": [
"lua/streamradio_core/external/*.lua"
],
"lint_spaceBeforeComma": false,
"lint_spaceAfterComma": true,
"lint_maxLineLength": 0,
"prettyprint_spaceBetweenParens": false,
"prettyprint_spaceBetweenBrackets": false,
"prettyprint_spaceBetweenBraces": false,
"prettyprint_spaceEmptyParens": false,
"prettyprint_spaceEmptyBraces": false,
"prettyprint_spaceAfterLabel": false,
"prettyprint_spaceBeforeComma": false,
"prettyprint_spaceAfterComma": true,
"prettyprint_semicolons": false,
"prettyprint_cStyle": false,
"prettyprint_removeRedundantParens": true,
"prettyprint_minimizeParens": true,
"prettyprint_assumeOperatorAssociativity": true,
"prettyprint_rejectInvalidCode": false,
"prettyprint_indentation": "\t",
"log_format": "auto"
}
"prettyprint_spaceAfterParens": false,
"prettyprint_spaceAfterBrackets": false,
"prettyprint_spaceAfterBraces": false,
"prettyprint_spaceBeforeComma": false,
"prettyprint_spaceAfterComma": true,
"prettyprint_semicolons": false,
"prettyprint_cStyle": false,
"prettyprint_indentation": "\t"
}

View File

@ -481,10 +481,10 @@ function ENT:OnRemove()
if g_isLoaded then
StreamRadioLib.UnregisterRadio(creationID)
end
LIBUtil.EmptyTableSafe(classobjs_data)
LIBUtil.EmptyTableSafe(classobjs_nw_register)
LIBUtil.EmptyTableSafe(classobjs_data)
LIBUtil.EmptyTableSafe(classobjs_nw_register)
end
end)
if SERVER then

View File

@ -345,7 +345,7 @@ function ENT:GetWallVolumeFactorSmoothed()
end
function ENT:IsMuted()
ply = LocalPlayer()
local ply = LocalPlayer()
if not IsValid(ply) then return true end
if not ply:IsPlayer() then return true end

View File

@ -2,7 +2,6 @@ AddCSLuaFile()
DEFINE_BASECLASS( "base_streamradio_gui" )
local StreamRadioLib = StreamRadioLib
local LIBNetwork = StreamRadioLib.Network
local LIBWire = StreamRadioLib.Wire
local g_isLoaded = StreamRadioLib and StreamRadioLib.Loaded
@ -134,7 +133,7 @@ function ENT:SetupDataTables( )
self._radio_EditValue = self._radio_EditValue or self.EditValue
self.EditValue = function(this, variable, value)
// This workaround allows for clientonly traffic on those data table vars.
-- This workaround allows for clientonly traffic on those data table vars.
if variable == "CLMute" then
if SERVER then

View File

@ -32,8 +32,6 @@ local g_cvar_cl_bass3_enable = nil
local g_cvar_sv_bass3_enable = nil
local g_cvar_sv_bass3_allow_client = nil
local g_cvar_sv_bass3_installed = nil
local function resetCache(...)
g_bass_loaded = nil
g_bass_can_loaded = nil
@ -48,22 +46,16 @@ if CLIENT then
cvars.AddChangeCallback("sv_streamradio_bass3_allow_client", resetCache, "streamradio_bass3_callback")
end
local g_colDefault = Color(255,255,255)
local g_colOk = Color(100,200,100)
local g_colCL = Color(255,222,137)
local g_colSV = Color(137,222,255)
local g_colDefault = Color(255, 255, 255)
local g_colOk = Color(100, 200, 100)
local g_colCL = Color(255, 222, 137)
local g_colSV = Color(137, 222, 255)
local function printBass3Info()
if g_bass_info_shown then
return
end
local realmname = "CLIENT"
if SERVER then
realmname = "SERVER"
end
g_bass_info_shown = true
local baseString = string.format(

View File

@ -409,12 +409,10 @@ function LIB.Download(url, callback, saveAsUrl)
end
function LIB.Load()
if StreamRadioLib.DataDirectory then
local cacheRealm = SERVER and "sv" or "cl"
local cacheRealm = SERVER and "sv" or "cl"
g_mainDir = string.format("%s/cache-%s", StreamRadioLib.DataDirectory, cacheRealm)
g_mainDirLegacy = string.format("%s/cache", StreamRadioLib.DataDirectory)
end
g_mainDir = LIBUtil.GetMainDirectory(string.format("cache-%s", cacheRealm))
g_mainDirLegacy = LIBUtil.GetMainDirectory("cache")
LIBUtil.DeleteFolder(g_mainDirLegacy)
Cache_Cleanup(true)

View File

@ -55,7 +55,7 @@ local function CreateClass( classname, baseClass )
function new_class:new(useproxy)
local newinst = {}
for k,v in pairs(metamethods) do
for k, v in pairs(metamethods) do
if rawget(class_mt, v) then continue end
class_mt[v] = self[v]
end

View File

@ -144,9 +144,9 @@ local function getTrace(level, maxcount)
return trace
end
local color1 = Color(60, 200, 60);
local color2 = Color(120,200,120);
local color3 = Color(240,120,60);
local color1 = Color(60, 200, 60)
local color2 = Color(120, 200, 120)
local color3 = Color(240, 120, 60)
function CLASS:Print(...)
local trace = getTrace(3)

View File

@ -575,7 +575,7 @@ function CLASS:AssignToListenGroupInternal()
return
end
listengroupid = self:AssignToListenGroup()
local listengroupid = self:AssignToListenGroup()
listengroupid = tonumber(listengroupid)
if not listengroupid then

View File

@ -94,7 +94,7 @@ function CLASS:Create()
end
local ResizeRT = function()
local x, y = self:GetPos()
local x = self:GetPos()
local w, h = self:GetSize()
self._RT:SetPos(x, x)
@ -242,7 +242,7 @@ function CLASS:PosTooltipToCursor(force)
local x, y = self:GetPos()
local cx, cy = self:GetCursor()
local cw, ch = self:GetCursorSize()
local _, ch = self:GetCursorSize()
local pw, ph = self:GetClientSize()
local tw, th = self.Tooltip:GetSize()
@ -389,7 +389,7 @@ function CLASS:DrawCursor()
if not self:GetAllowCursor() then return end
if not self:IsCursorInBounds() then return end
local ax1, ay1, ax2, ay2 = self:GetArea()
local _, _, ax2, ay2 = self:GetArea()
local cx, cy = self:GetCursor()
local cw, ch = self:GetCursorSize()

View File

@ -365,7 +365,6 @@ function CLASS:Clear()
if self:IsDisabled() then return end
local rt = self._RT
local mat = rt.mat
local tex = rt.tex
render.PushRenderTarget( tex )

View File

@ -7,17 +7,12 @@ end
local tostring = tostring
local tonumber = tonumber
local type = type
local isfunction = isfunction
local IsValid = IsValid
local Vector = Vector
local setmetatable = setmetatable
local sound = sound
local util = util
local string = string
local math = math
local hook = hook
local SERVER = SERVER
local CLIENT = CLIENT
@ -33,7 +28,7 @@ local LIBUrl = StreamRadioLib.Url
local LIBStream = StreamRadioLib.Stream
local BASE = CLASS:GetBaseClass()
local g_maxSongLenForCache = 60 * 60 * 1.5 // 1.5 Hours
local g_maxSongLenForCache = 60 * 60 * 1.5 -- 1.5 Hours
local function LoadBass()
local hasBass = LIBBass.LoadDLL()
@ -142,7 +137,7 @@ function CLASS:Create()
v = LIBUrl.SanitizeUrl(v)
if rawv ~= v then
// avoid calling it twice on unclean input
-- avoid calling it twice on unclean input
self.URL.external = v
return
end
@ -223,7 +218,7 @@ function CLASS:Create()
self.StateTable_r = {}
for i,v in ipairs(self.StateTable) do
for i, v in ipairs(self.StateTable) do
self.StateTable_r[v] = i
end

View File

@ -416,7 +416,7 @@ end
function CLASS:_PerformButtonLayout(buttonx, buttony)
if not self.SideButtons then return end
local w, h = self:GetClientSize()
local _, h = self:GetClientSize()
local buttonw = 0
for k, v in ipairs(self.SideButtons) do

View File

@ -226,7 +226,7 @@ end
function CLASS:_PerformButtonLayout(buttonx, buttony)
if not self.SideButtons then return end
local w, h = self:GetClientSize()
local _, h = self:GetClientSize()
local buttonw = 0
for k, v in ipairs(self.SideButtons) do

View File

@ -65,7 +65,7 @@ function CLASS:Create()
self.StreamOBJ:SetVolume(v)
end
self.VolumeBar:SetSize(1,1)
self.VolumeBar:SetSize(1, 1)
self.ControlPanel = self:AddPanelByClassname("radio/gui_player_controls", true)
self.ControlPanel:SetSize(1, 1)

View File

@ -114,7 +114,7 @@ function CLASS:Create()
end
local isPlayMode = stream:IsPlayMode()
if isPlayMode then
self:CallHook("OnPause")
stream:Pause()
@ -320,7 +320,7 @@ function CLASS:Create()
self:UpdatePlaybackLoopMode()
self:UpdatePlayBar()
self.PlayBar:SetSize(1,1)
self.PlayBar:SetSize(1, 1)
if CLIENT then
self:StartFastThink()

View File

@ -49,7 +49,7 @@ function CLASS:Create()
self:QueueCall("BuildLines")
end
self.Colors.Main = Color(0,0,0)
self.Colors.Main = Color(0, 0, 0)
end
self:SetSkinAble(false)
@ -72,7 +72,7 @@ function CLASS:BuildLines(force)
local font = self.TextData.Font
local text = self.TextData.Text
local w, h = self:GetSize()
local w = self:GetSize()
self:GetWidth()
@ -80,13 +80,12 @@ function CLASS:BuildLines(force)
local line = {}
local linew = 0
local linehend = false
surface.SetFont( font )
local checksize = {"W", "M", "L", "I", "i", "l", ".", "g", "|", "_"}
for k, v in ipairs(checksize) do
local tsw, tsh = surface.GetTextSize(v)
local tsw = surface.GetTextSize(v)
if tsw >= w then
self:InvalidateLayout()
@ -121,12 +120,12 @@ function CLASS:BuildLines(force)
return
end
local tsw, tsh = surface.GetTextSize( text )
local tsw = surface.GetTextSize( text )
local newlinew = linew + tsw
-- Word to long, seperate it
if tsw > w then
for i=1, #text do
for i = 1, #text do
addtoline(text[i])
end
@ -188,22 +187,20 @@ function CLASS:Render()
local x, y = self:GetRenderPos()
local w, h = self:GetSize()
local xalign, yalign = self.TextData.AlignX, self.TextData.AlignY
local col = self.Colors.Main or color_black
local font = self.TextData.Font
surface.SetFont( font )
surface.SetTextColor( col:Unpack() )
local lines = self:GetVisibleLines()
local textw, texth = self:GetTextSize()
local _, texth = self:GetTextSize()
for i, v in ipairs(lines) do
local text = v.text
local ox = v.x
local oy = v.y
local ow = v.w
local oh = v.h
self:DrawText(text, x + ox, y + oy, w, h, ow, texth)
end
@ -253,11 +250,11 @@ function CLASS:GetTotalTextSize()
end
function CLASS:FitToText(minw, maxw)
self:SetWidth(maxw)
self:BuildLines()
self:SetWidth(maxw)
self:BuildLines()
local w, h = self:GetTotalTextSize()
w = math.Clamp(w, minw, maxw)
local w, h = self:GetTotalTextSize()
w = math.Clamp(w, minw, maxw)
self:SetSize(w, h)
end
@ -312,9 +309,8 @@ function CLASS:GetVisibleLines()
if chlines then return chlines end
local liney = 0
local textw, texth = self:GetTextSize()
local _, texth = self:GetTextSize()
local count = self:GetLineCount()
local startline = self:GetStartLine()
local lines = {}

View File

@ -1,44 +1,5 @@
-- ////////////////////////////////////
-- Stream Radio Lip
-- ////////////////////////////////////
local IsValid = IsValid
local tonumber = tonumber
local tostring = tostring
local Color = Color
local LocalPlayer = LocalPlayer
local concommand = concommand
local hook = hook
local math = math
local string = string
local net = net
local LIBNet = StreamRadioLib.Net
local LIBError = StreamRadioLib.Error
LIBNet.Receive("PlaylistMenu", function( length )
if ( not istable( StreamRadioLib ) ) then return end
if ( not StreamRadioLib.NetReceiveFileEntry ) then return end
local entity, name, type, x, y = StreamRadioLib.NetReceiveFileEntry( )
if ( not IsValid( entity ) ) then return end
if ( not entity.PlaylistMenu ) then return end
local fileinfo = {}
fileinfo.filename = name
fileinfo.filetype = type
entity.PlaylistMenu[x] = entity.PlaylistMenu[x] or {}
entity.PlaylistMenu[x][y] = fileinfo
end)
LIBNet.Receive("Playlist", function( length )
if ( not istable( StreamRadioLib ) ) then return end
if ( not StreamRadioLib.NetReceivePlaylistEntry ) then return end
local entity, name, x, y = StreamRadioLib.NetReceivePlaylistEntry( )
if ( not IsValid( entity ) ) then return end
if ( not entity.Playlist ) then return end
local fileinfo = {}
fileinfo.filename = name
entity.Playlist[x] = entity.Playlist[x] or {}
entity.Playlist[x][y] = fileinfo
end)
local g_camPos = nil
local g_inRenderScene = false
@ -222,43 +183,17 @@ end
function StreamRadioLib.CalcDistanceVolume( distance, max )
distance = distance or 0
local threshold = 0.25
max = math.min( max or 0, StreamRadioLib.GetMuteDistance( ) )
local min = ( max or 0 ) / 3
max = math.min(max or 0, StreamRadioLib.GetMuteDistance())
local min = (max or 0) / 3
local fullmin = min / 4
if ( min <= 0 ) then return 0 end
if ( max <= 0 ) then return 0 end
if ( distance > max ) then return 0 end
if ( distance <= 0 ) then return 1 end
if ( distance <= fullmin ) then return 1 end
if ( distance <= min ) then return Lerp( ( distance - fullmin ) / ( min - fullmin ), 1, threshold ) end
if min <= 0 then return 0 end
if max <= 0 then return 0 end
if distance > max then return 0 end
if distance <= 0 then return 1 end
if distance <= fullmin then return 1 end
if distance <= min then return Lerp((distance - fullmin) / (min - fullmin), 1, threshold) end
return Lerp( ( distance - min ) / ( max - min ), threshold, 0 )
end
local oldfloat = 0
function StreamRadioLib.PrintFloat( float, len, ... )
local float = math.Clamp( float, 0, 1 )
local str = ""
if ( float >= oldfloat ) then
oldfloat = float
end
local bar = math.Round( float * len )
local space = len - math.Round( float * len )
local space1 = math.Round( ( oldfloat - float ) * len )
local space2 = space - space1 - 1
str = string.rep( "#", bar ) .. string.rep( " ", space1 ) .. ( math.Round( oldfloat * len ) < len and "|" or "" ) .. string.rep( " ", space2 )
MsgC( Color( 510 * float, 510 * ( 1 - float ), 0, 255 ), str, " ", string.format( "% 7.2f%%\t", float * 100 ), ..., "\n" )
if ( float < oldfloat ) then
oldfloat = oldfloat - 0.5 * RealFrameTime( )
end
oldvar = float
return str
return Lerp((distance - min) / (max - min), threshold, 0)
end
return true

View File

@ -210,8 +210,19 @@ function LIB.GetWarnLabel(text)
return label
end
function LIB.GetImportantLabel(text)
local label = LIB.GetLabel(text)
local skindata = label:GetSkin()
label:SetTextColor(skindata.Colours.Tree.Hover)
return label
end
function LIB.GetWhitelistEnabledLabel(text)
local label = LIB.GetWarnLabel(text)
local label = LIB.GetImportantLabel(text)
local function handleWhitelistEnabled(this)
local lastisUrlWhitelistEnabled = this._isUrlWhitelistEnabled

View File

@ -7,29 +7,20 @@ table.Empty(LIB)
local LIBNet = StreamRadioLib.Net
local pairs = pairs
local type = type
local IsValid = IsValid
local file = file
local table = table
local string = string
local util = util
local player = player
local ents = ents
local net = net
local ListenPath = ""
local CallbackFunc = nil
local CallbackArgs = {}
local CallbackSelf = nil
local g_listenPath = ""
local g_callbackFunc = nil
local g_callbackArgs = {}
local g_callbackObj = nil
function LIB.ListenToPath( path )
ListenPath = tostring( path or "" )
g_listenPath = tostring( path or "" )
return ListenPath
return g_listenPath
end
function LIB.GetListenPath( )
return ListenPath
return g_listenPath
end
function LIB.CreateDir( path )
@ -149,50 +140,50 @@ function LIB.Rename(path_old, path_new)
return true
end
function LIB.SetCallback(func, self, ...)
function LIB.SetCallback(func, this, ...)
if not isfunction(func) then
CallbackFunc = nil
CallbackArgs = {}
CallbackSelf = nil
g_callbackFunc = nil
g_callbackArgs = {}
g_callbackObj = nil
return
end
CallbackFunc = func
CallbackArgs = {...}
CallbackSelf = self
g_callbackFunc = func
g_callbackArgs = {...}
g_callbackObj = this
end
LIBNet.Receive("Editor_Return_Files", function( length )
local path, name, type, filepath = StreamRadioLib.NetReceiveFileEditor( )
if not isfunction(CallbackFunc) then return end
if not isfunction(g_callbackFunc) then return end
if CallbackSelf then
CallbackFunc( CallbackSelf, "files", path, name, filepath, type, unpack( CallbackArgs or {} ) )
if g_callbackObj then
g_callbackFunc( g_callbackObj, "files", path, name, filepath, type, unpack( g_callbackArgs or {} ) )
else
CallbackFunc( "files", path, name, filepath, type, unpack( CallbackArgs or {} ) )
g_callbackFunc( "files", path, name, filepath, type, unpack( g_callbackArgs or {} ) )
end
end)
LIBNet.Receive("Editor_Return_Playlist", function( length )
local url, name, filepath = StreamRadioLib.NetReceivePlaylistEditor( )
if not isfunction(CallbackFunc) then return end
if not isfunction(g_callbackFunc) then return end
if CallbackSelf then
CallbackFunc( CallbackSelf, "playlist", url, name, filepath, unpack( CallbackArgs or {} ) )
if g_callbackObj then
g_callbackFunc( g_callbackObj, "playlist", url, name, filepath, unpack( g_callbackArgs or {} ) )
else
CallbackFunc( "playlist", url, name, filepath, unpack( CallbackArgs or {} ) )
g_callbackFunc( "playlist", url, name, filepath, unpack( g_callbackArgs or {} ) )
end
end)
LIBNet.Receive("Editor_Error", function( length )
local path, code = StreamRadioLib.NetReceiveEditorError( )
if not isfunction(CallbackFunc) then return end
if not isfunction(g_callbackFunc) then return end
if CallbackSelf then
CallbackFunc( CallbackSelf, "error", path, code, unpack( CallbackArgs or {} ) )
if g_callbackObj then
g_callbackFunc( g_callbackObj, "error", path, code, unpack( g_callbackArgs or {} ) )
else
CallbackFunc( "error", path, code, unpack( CallbackArgs or {} ) )
g_callbackFunc( "error", path, code, unpack( g_callbackArgs or {} ) )
end
end)

File diff suppressed because it is too large Load Diff

View File

@ -3,18 +3,10 @@ local StreamRadioLib = StreamRadioLib
StreamRadioLib.Skin = StreamRadioLib.Skin or {}
local LIB = StreamRadioLib.Skin
local MainPath = StreamRadioLib.DataDirectory .. "/skin"
local function CreateDirForFile(filename)
local folder = string.GetPathFromFilename(filename) or ""
if folder == "" then return true end
local LIBUtil = StreamRadioLib.Util
if not file.IsDir(folder, "DATA") then
file.CreateDir(folder)
end
return file.IsDir(folder, "DATA")
end
local g_mainPath = LIBUtil.GetMainDirectory("skin")
local function IsValidFile(filename)
return not file.IsDir(filename, "DATA") and file.Exists(filename, "DATA")
@ -36,10 +28,10 @@ function LIB.GetPath(name)
name = tostring(name or "")
if name == "" then
return MainPath .. "/"
return g_mainPath .. "/"
end
local filepath = MainPath .. "/" .. name .. ".txt"
local filepath = g_mainPath .. "/" .. name .. ".txt"
return filepath
end
@ -64,7 +56,7 @@ function LIB.Open(name)
if not skindata then return end
skindata.name = name
return skindata
return skindata
end
local filepath = LIB.GetPath(name)
@ -77,7 +69,7 @@ function LIB.Open(name)
local skindata = StreamRadioLib.JSON.Decode(skinjson)
if not skindata then return end
skindata.name = name
return skindata
end
@ -98,7 +90,7 @@ function LIB.Save(name, skindata)
local skinjson = StreamRadioLib.JSON.Encode(skindata, true) or ""
local filepath = LIB.GetPath(name)
if not CreateDirForFile(filepath) then return false end
if not LIBUtil.CreateDirectoryForFile(filepath) then return false end
file.Write(filepath, skinjson)
return IsValidFile(filepath)
@ -121,7 +113,7 @@ function LIB.Delete(name)
end
function LIB.GetList()
local files = file.Find(MainPath .. "/*.txt", "DATA", "nameasc")
local files = file.Find(g_mainPath .. "/*.txt", "DATA", "nameasc")
table.insert(files, 1, "default.txt")

View File

@ -5,17 +5,6 @@ StreamRadioLib.Surface = StreamRadioLib.Surface or {}
local LIB = StreamRadioLib.Surface
table.Empty(LIB)
local cam = cam
local surface = surface
local string = string
local math = math
local draw = draw
local render = render
local ipairs = ipairs
local pairs = pairs
local tonumber = tonumber
local Color = Color
local g_font_template = {
font = "Arial",
size = 0,

View File

@ -67,32 +67,30 @@ local RENAME_ERRORS = {
[StreamRadioLib.EDITOR_ERROR_RENAME_READ] = true,
}
local Disabled_Gray = Color( 140, 140, 140, 255 )
local function ShowError( errorheader, errortext, self, func, ... )
if not IsValid(self) then return false end
if not self:IsVisible() then return false end
local function ShowError( errorheader, errortext, this, func, ... )
if not IsValid(this) then return false end
if not this:IsVisible() then return false end
local args = {...}
Derma_Query( errortext, errorheader, "OK", function( )
if not IsValid(self) then return end
if self:IsLoading() then return end
if not IsValid(this) then return end
if this:IsLoading() then return end
if not func then return end
func(self, unpack(args))
func(this, unpack(args))
end)
return true
end
--Ask for save: Opens a confirmation box.
local function AsForSave( self, func, ... )
if not IsValid(self) then return false end
if not self:IsVisible() then return false end
local function AsForSave( this, func, ... )
if not IsValid(this) then return false end
if not this:IsVisible() then return false end
if not func then return false end
if not self.m_bUnsaved then
func( self, ... )
if not this.m_bUnsaved then
func( this, ... )
return true
end
@ -100,11 +98,11 @@ local function AsForSave( self, func, ... )
Derma_Query("Are you sure to discard the changes?", "Unsaved playlist!", "Yes", function()
-- Discard the changes.
if not IsValid(self) then return end
if self:IsLoading() then return end
if not IsValid(this) then return end
if this:IsLoading() then return end
self:RemoveNewFile()
func( self, unpack( args ) )
this:RemoveNewFile()
func( this, unpack( args ) )
end, "No")
-- Don't discard the changes.
@ -455,44 +453,6 @@ local function FileMenu(self, item, path, name, filetype, parentpath)
MenuItem:SetImage("icon16/folder_add.png")
-- Copy/Paste -- @TODO
--[[
if (filetype ~= StreamRadioLib.TYPE_FOLDER and not newfile) then
MenuItem = Menu:AddOption("Copy", function()
if ( not IsValid( self ) ) then return end
if ( self:IsLoading() ) then return end
self.Clipboard = path
end)
MenuItem:SetImage("icon16/page_paste.png")
MenuItem = Menu:AddOption("Paste", function()
if ( not IsValid( self ) ) then return end
if ( self:IsLoading() ) then return end
StreamRadioLib.Editor.Copy( self.Clipboard, path )
end)
MenuItem:SetImage("icon16/page_paste.png")
if ( not self.Clipboard or self.Clipboard == "" ) then
MenuItem:SetTextColor( Disabled_Gray ) -- custom disabling
MenuItem.DoClick = function() end
end
MenuItem = Menu:AddOption("Cut", function()
if ( not IsValid( self ) ) then return end
if ( self:IsLoading() ) then return end
StreamRadioLib.Editor.Rename( self.Clipboard, path )
self.Clipboard = nil
end)
MenuItem:SetImage("icon16/page_paste.png")
if ( not self.Clipboard or self.Clipboard == "" ) then
MenuItem:SetTextColor( Disabled_Gray ) -- custom disabling
MenuItem.DoClick = function() end
end
end
]]
--Delete
if StreamRadioLib.Filesystem.CanDeleteFormat(filetype) and not StreamRadioLib.String.IsVirtualPath(path) then
Menu:AddSpacer( )
@ -668,7 +628,7 @@ function PANEL:Init( )
if self:IsLoading( ) then return end
local url = line.streamradio_url
local name = line.streamradio_name
local id = line.streamradio_id
PlaylistMenu( self, line, url, name, self.PlaylistItems["parentpath"] )
self:SelectPlaylistItem( line )
end
@ -1129,7 +1089,7 @@ function PANEL:BuildPlaylistFromTextPanel()
return
end
lines = self.PlaylistText:GetText()
local lines = self.PlaylistText:GetText()
lines = StreamRadioLib.String.NormalizeNewlines(lines, '\n')
lines = string.Explode("\n", lines, false) or {}
@ -1689,8 +1649,6 @@ function PANEL:RemovePlaylistItem(item)
if not self.PlaylistItems then return false end
if self:IsLoading() then return false end
local url = item.streamradio_url
local name = item.streamradio_name
local id = item.streamradio_id
self.PlaylistItems[id] = nil

View File

@ -13,9 +13,11 @@ LIB.g_CV_List["admin"] = {}
local function AddDangerMenuPanel(CPanel)
local subpanel = vgui.Create("DForm")
subpanel:SetName("Playlists rebuild setting")
CPanel:AddPanel(subpanel)
subpanel:SetCookieName("streamradio_admin_playlists_rebuild")
subpanel:AddItem(LIBMenu.GetWarnLabel("CAUTION: Be careful what you in this section!\nUnanticipated loss of CUSTOM playlist files can be caused by mistakes!"))
@ -99,9 +101,11 @@ end
local function AddSecurityMenuPanel(CPanel)
local subpanel = vgui.Create("DForm")
subpanel:SetName("Security Options")
CPanel:AddPanel(subpanel)
subpanel:SetCookieName("streamradio_admin_playlists_rebuild")
subpanel:AddItem(LIBMenu.GetWarnLabel("CAUTION: This affects the server security of this addon.\nOnly disable the whitelist if you know what you are doing!\nBetter you never turn this off!"))
@ -153,9 +157,11 @@ end
local function AddBassMenuPanel(CPanel)
local subpanel = vgui.Create("DForm")
subpanel:SetName("GM_BASS3 Options")
CPanel:AddPanel(subpanel)
subpanel:SetCookieName("streamradio_admin_bass3")
local hasBass = StreamRadioLib.Bass.IsInstalledOnServer()

View File

@ -5,11 +5,11 @@ StreamRadioLib.Filesystem = StreamRadioLib.Filesystem or {}
local LIB = StreamRadioLib.Filesystem
table.Empty(LIB)
local LIBString = StreamRadioLib.String
local LIBUtil = StreamRadioLib.Util
local g_playlistdir = ( StreamRadioLib.DataDirectory or "" ) .. "/playlists"
local LuaFilesystemDirectory = "streamradio_core/filesystem"
local g_playlistdir = LIBUtil.GetMainDirectory("playlists")
local g_luaFilesystemDirectory = "streamradio_core/filesystem"
local g_Filesystem = {}
local g_FilesystemBlacklist = {}
@ -79,15 +79,8 @@ local function AddCommonFunctions(fs)
return true
end
function fs:CreateDirForFile(globalpath)
local folder = string.GetPathFromFilename(globalpath) or ""
if folder == "" then return true end
if not file.IsDir(folder, "DATA") then
file.CreateDir(folder)
end
return file.IsDir(folder, "DATA")
function fs:CreateDirectoryForFile(globalpath)
return LIBUtil.CreateDirectoryForFile(globalpath)
end
function fs:IsType(globalpath, vpath)
@ -141,7 +134,7 @@ local function loadFilesystem(script)
script = script or ""
if script == "" then return nil end
local scriptpath = LuaFilesystemDirectory .. "/"
local scriptpath = g_luaFilesystemDirectory .. "/"
local scriptfile = scriptpath .. script
if not file.Exists(scriptfile, "LUA") then return nil end
@ -280,7 +273,7 @@ local function SanitizeData(data)
end
function LIB.Load()
local files = file.Find(LuaFilesystemDirectory .. "/*", "LUA")
local files = file.Find(g_luaFilesystemDirectory .. "/*", "LUA")
local filesystems = {};

View File

@ -162,7 +162,7 @@ end
function RADIOFS:Write(globalpath, vpath, data, callback)
globalpath = self._filepath
if not self:CreateDirForFile(globalpath) then
if not self:CreateDirectoryForFile(globalpath) then
callback(false)
return false
end

View File

@ -160,7 +160,7 @@ end
function RADIOFS:Write(globalpath, vpath, data, callback)
globalpath = self._filepath
if not self:CreateDirForFile(globalpath) then
if not self:CreateDirectoryForFile(globalpath) then
callback(false)
return false
end

View File

@ -34,7 +34,7 @@ function RADIOFS:Read(globalpath, vpath, callback)
end
function RADIOFS:Write(globalpath, vpath, data, callback)
if not self:CreateDirForFile(globalpath) then
if not self:CreateDirectoryForFile(globalpath) then
callback(false)
return false
end

View File

@ -15,7 +15,7 @@ RADIOFS.loadToWhitelist = true
local function decodeM3U(RawPlaylist)
local RawPlaylistTab = string.Split( RawPlaylist, "\n" )
local AdvancedM3U = string.lower( string.Trim( RawPlaylistTab[1] or "" ) ) == '#extm3u'
local AdvancedM3U = string.lower( string.Trim( RawPlaylistTab[1] or "" ) ) == "#extm3u"
local Playlist = {}
if not AdvancedM3U then
@ -91,7 +91,7 @@ function RADIOFS:Read(globalpath, vpath, callback)
end
function RADIOFS:Write(globalpath, vpath, data, callback)
if not self:CreateDirForFile(globalpath) then
if not self:CreateDirectoryForFile(globalpath) then
callback(false)
return false
end

View File

@ -27,7 +27,7 @@ local function decodePLS(RawPlaylist)
end
local CountHeader = string.lower( string.Trim( RawPlaylistTab[2] or "" ) )
local Count = tonumber(string.match(CountHeader, '%s*numberofentries%s*=%s*([0-9]+)')) or 0
local Count = tonumber(string.match(CountHeader, "%s*numberofentries%s*=%s*([0-9]+)")) or 0
local Playlist = {}
@ -36,7 +36,7 @@ local function decodePLS(RawPlaylist)
end
for i = 1, Count do
line = i * 3
local line = i * 3
local UrlLine = RawPlaylistTab[line] or ""
local NameLine = RawPlaylistTab[line + 1] or ""
@ -89,7 +89,7 @@ function RADIOFS:Read(globalpath, vpath, callback)
end
function RADIOFS:Write(globalpath, vpath, data, callback)
if not self:CreateDirForFile(globalpath) then
if not self:CreateDirectoryForFile(globalpath) then
callback(false)
return false
end

View File

@ -34,7 +34,7 @@ function RADIOFS:Read(globalpath, vpath, callback)
end
function RADIOFS:Write(globalpath, vpath, data, callback)
if not self:CreateDirForFile(globalpath) then
if not self:CreateDirectoryForFile(globalpath) then
callback(false)
return false
end

View File

@ -10,7 +10,7 @@ local g_hooks = {}
local g_orderCounter = 0
function LIB.GetMainHookIdentifier(eventName)
identifier = g_nameprefix .. tostring(eventName or "")
local identifier = g_nameprefix .. tostring(eventName or "")
return identifier
end
@ -151,7 +151,7 @@ function LIB.Remove(eventName, identifier)
end
function LIB.GetBenchmark(eventName)
identifier = tostring(identifier or "")
eventName = tostring(eventName or "")
local hookData = g_hooks[eventName]
if not hookData then

View File

@ -63,13 +63,22 @@ end
LIB.DataDirectory = "streamradio"
local _, NetURL = LIB.LoadSH("streamradio_core/neturl.lua")
LIB.NetURL = NetURL
do
local status, lib = LIBLoadSH("streamradio_core/external/neturl.lua")
LIB.NetURL = nil
if not status then
g_ok = false
else
LIB.NetURL = lib
end
end
loadSH("streamradio_core/api.lua")
loadSH("streamradio_core/util.lua")
loadSH("streamradio_core/string.lua")
loadSH("streamradio_core/string_accents.lua")
loadSH("streamradio_core/util.lua")
loadSH("streamradio_core/url.lua")
loadSH("streamradio_core/hook.lua")
loadSH("streamradio_core/timedpairs.lua")

View File

@ -32,12 +32,12 @@ function LIB.Decode(json)
json = string.gsub(json, "//.-\n" , "\n") -- singleline comment
json = string.gsub(json, "/%*.-%*/" , "\n") -- multiline comment
json = string.gsub(json, ",([%s]*)([%]%}])","%1%2") -- trailing comma of arrays/objects
json = string.gsub(json, ",([%s]*)([%]%}])", "%1%2") -- trailing comma of arrays/objects
json = string.gsub(json, "\n[%s]*","\n") -- remove all spaces at the start of lines
json = string.gsub(json, "[%s\n]*\n","\n") -- remove all empty lines and all spaces at the end of lines
json = string.gsub(json, "^\n","") -- remove first empty new line
json = string.gsub(json, "\n$","") -- remove last empty new line
json = string.gsub(json, "\n[%s]*", "\n") -- remove all spaces at the start of lines
json = string.gsub(json, "[%s\n]*\n", "\n") -- remove all empty lines and all spaces at the end of lines
json = string.gsub(json, "^\n", "") -- remove first empty new line
json = string.gsub(json, "\n$", "") -- remove last empty new line
json = string.Trim(json)

View File

@ -42,7 +42,7 @@ function LIB.Translate(identifier, defaultEnglishText)
defaultEnglishText = tostring(defaultEnglishText or "")
if #defaultEnglishText >= 1024 then
// Limit by GMod: https://github.com/Facepunch/garrysmod-issues/issues/5524
-- Limit by GMod: https://github.com/Facepunch/garrysmod-issues/issues/5524
error("defaultEnglishText is too long (length >= 1024)")
end

View File

@ -11,6 +11,8 @@ local CLIENT = CLIENT
local StreamRadioLib = StreamRadioLib
local catchAndErrorNoHaltWithStack = StreamRadioLib.Util.CatchAndErrorNoHaltWithStack
function StreamRadioLib.IsGUIHidden(ply)
if not IsValid(ply) and CLIENT then
ply = LocalPlayer()
@ -142,6 +144,8 @@ function StreamRadioLib.GetControlPosDir(ent)
if not IsValid(ent) then return nil end
if not IsValid(camera) then return nil end
local pos, dir
if camera:IsPlayer() then
pos = camera:EyePos()
dir = camera:GetAimVector()
@ -158,7 +162,9 @@ end
local g_PlayerTraceCache = {}
local g_PlayerTraceCacheCount = 0
local g_PlayerTrace = {}
g_PlayerTrace.filter = {}
function StreamRadioLib.Trace(ent)
if not IsValid(ent) and CLIENT then
@ -212,7 +218,8 @@ function StreamRadioLib.Trace(ent)
tmp[entVehicle] = entVehicle
tmp[cameraVehicle] = cameraVehicle
filter = {}
local filter = g_PlayerTrace.filter
table.Empty(filter)
for _, filterEnt in pairs(tmp) do
if not IsValid(filterEnt) then continue end
@ -435,8 +442,6 @@ local function ClearCheckPropProtectionCache()
g_checkPropProtectionCacheExpire = nil
end
catchAndErrorNoHaltWithStack = StreamRadioLib.Util.CatchAndErrorNoHaltWithStack
function StreamRadioLib.CheckPropProtectionAgainstUse(ent, ply)
if not IsValid( ent ) then return false end
if not IsValid( ply ) then return false end

View File

@ -272,11 +272,11 @@ local function loadAddon()
LIB.Loading = nil
end
local g_colDefault = Color(255,255,255)
local g_colError = Color(255,128,128)
local g_colOk = Color(100,200,100)
local g_colCL = Color(255,222,137)
local g_colSV = Color(137,222,255)
local g_colDefault = Color(255, 255, 255)
local g_colError = Color(255, 128, 128)
local g_colOk = Color(100, 200, 100)
local g_colCL = Color(255, 222, 137)
local g_colSV = Color(137, 222, 255)
local function printAddon()
local errors = LIB.Errors

View File

@ -13,7 +13,7 @@ RADIOMDL.SpawnFlatOnWall = true
RADIOMDL.SoundPosOffset = Vector(0, 0, 5)
RADIOMDL.SoundAngOffset = Angle(0, 0, 0)
RADIOMDL.DisplayAngles = Angle(0, 89.5, 1,5)
RADIOMDL.DisplayAngles = Angle(0, 89.5, 1, 5)
-- F, R, U
RADIOMDL.DisplayOffset = Vector(-4.20, -7.60, 9.38) -- Top Left

View File

@ -126,8 +126,8 @@ function RADIOMDL:_StateCloseWings(ent)
local RightWing = ent:LookupBone( "RT_Wing" ) or 0
local LeftWing = ent:LookupBone( "LFT_Wing" ) or 0
local RPos = math.Clamp( ( self.RightWing or 0 ), 0, 1 )
local LPos = math.Clamp( ( self.LeftWing or 0 ), 0, 1 )
local RPos = math.Clamp(self.RightWing or 0, 0, 1)
local LPos = math.Clamp(self.LeftWing or 0, 0, 1)
if RPos <= 0 and LPos <= 0 then
self.WingOpened = false
@ -147,8 +147,8 @@ function RADIOMDL:_StateOpenWings(ent)
local RightWing = ent:LookupBone( "RT_Wing" ) or 0
local LeftWing = ent:LookupBone( "LFT_Wing" ) or 0
local RPos = math.Clamp( ( self.RightWing or 0 ), 0, 0.5 )
local LPos = math.Clamp( ( self.LeftWing or 0 ), 0, 0.5 )
local RPos = math.Clamp(self.RightWing or 0, 0, 0.5)
local LPos = math.Clamp(self.LeftWing or 0, 0, 0.5)
if RPos >= 0.5 and LPos >= 0.5 then
self.WingClosed = false
@ -328,8 +328,8 @@ function RADIOMDL:Speaker(ent, speakerlevel)
local RightWing = ent:LookupBone( "RT_Wing" ) or 0
local LeftWing = ent:LookupBone( "LFT_Wing" ) or 0
local RPos = math.Clamp( ( self.RightWing or 0 ), 0.25, 1 )
local LPos = math.Clamp( ( self.LeftWing or 0 ), 0.25, 1 )
local RPos = math.Clamp(self.RightWing or 0, 0.25, 1)
local LPos = math.Clamp(self.LeftWing or 0, 0.25, 1)
ent:ManipulateBonePosition( RightWing, Vector( RPos * self.WingSpan, 0, 0 ) )
ent:ManipulateBonePosition( LeftWing, Vector( -LPos * self.WingSpan, 0, 0 ) )

View File

@ -9,8 +9,6 @@ local LIBNetwork = StreamRadioLib.Network
LIBNetwork.AddNetworkString("StaticState")
LIBNetwork.AddNetworkString("Control")
LIBNetwork.AddNetworkString("PlaylistMenu")
LIBNetwork.AddNetworkString("Playlist")
LIBNetwork.AddNetworkString("Editor_Return_Files")
LIBNetwork.AddNetworkString("Editor_Return_Playlist")
@ -182,59 +180,6 @@ function StreamRadioLib.NetReceivePlaylistEditor( )
return url, name, parentpath
end
function StreamRadioLib.NetSendFileEntry( ent, name, format, x, y )
if ( not IsValid( ent ) ) then return end
if ( not ent.__IsRadio ) then return end
if ( not name ) then return end
if ( not format ) then return end
if ( not x ) then return end
if ( not y ) then return end
net.WriteEntity( ent )
net.WriteString( name )
net.WriteUInt( format, 8 )
net.WriteUInt( x, 4 )
net.WriteUInt( y, 4 )
end
function StreamRadioLib.NetReceiveFileEntry( )
local ent = net.ReadEntity( )
if ( not IsValid( ent ) ) then return end
if ( not ent.__IsRadio ) then return end
local name = net.ReadString( ) or ""
local format = net.ReadUInt( 8 ) or StreamRadioLib.TYPE_FOLDER
local x = net.ReadUInt( 4 ) or 1
local y = net.ReadUInt( 4 ) or 1
return ent, name, format, x, y
end
function StreamRadioLib.NetSendPlaylistEntry( ent, name, x, y )
if ( not IsValid( ent ) ) then return end
if ( not ent.__IsRadio ) then return end
if ( not name ) then return end
if ( not x ) then return end
if ( not y ) then return end
net.WriteEntity( ent )
net.WriteString( name )
net.WriteUInt( x, 4 )
net.WriteUInt( y, 4 )
end
function StreamRadioLib.NetReceivePlaylistEntry( )
local ent = net.ReadEntity( )
if ( not IsValid( ent ) ) then return end
if ( not ent.__IsRadio ) then return end
local name = net.ReadString( ) or ""
local x = net.ReadUInt( 4 ) or 1
local y = net.ReadUInt( 4 ) or 1
return ent, name, x, y
end
local function networkStaticAddonStates()
if SERVER then
StreamRadioLib.Hook.Add("PlayerInitialSpawn", "StaticState", function(ply)

View File

@ -78,10 +78,10 @@ function LIB.GetPlayerString(ply)
return playerStr
end
local g_colorSeparator = Color(255,255,255)
local g_colorDateTime = Color(180,180,180)
local g_colorAddonName = Color(0,200,0)
local g_colorPlayer = Color(200,200,0)
local g_colorSeparator = Color(255, 255, 255)
local g_colorDateTime = Color(180, 180, 180)
local g_colorAddonName = Color(0, 200, 0)
local g_colorPlayer = Color(200, 200, 0)
function LIB.Log(ply, format, ...)
local msgstring = LIB.Format(format, ...)
@ -113,5 +113,30 @@ function LIB.Log(ply, format, ...)
MsgN(msgstring)
end
local g_oldfloat = 0
function LIB.PrintFloatBar( float, len, ... )
local float = math.Clamp( float, 0, 1 )
local str = ""
if float >= g_oldfloat then
g_oldfloat = float
end
local bar = math.Round(float * len)
local space = len - math.Round(float * len)
local space1 = math.Round((g_oldfloat - float) * len)
local space2 = space - space1 - 1
str = string.rep("#", bar) .. string.rep(" ", space1) .. (math.Round(g_oldfloat * len) < len and "|" or "") .. string.rep(" ", space2)
MsgC(Color(510 * float, 510 * (1 - float), 0, 255), str, " ", string.format("% 7.2f%%\t", float * 100), ..., "\n")
if float < g_oldfloat then
g_oldfloat = g_oldfloat - 0.5 * RealFrameTime()
end
return str
end
return true

View File

@ -7,7 +7,6 @@ local LIB = StreamRadioLib.properties
table.Empty(LIB)
local LIBNet = StreamRadioLib.Net
local LIBNetwork = StreamRadioLib.Network
local LIBError = StreamRadioLib.Error
local LIBUtil = StreamRadioLib.Util
@ -236,7 +235,7 @@ local g_VolumeMenuOpen = function( self, optionPanel, ent )
optionPanel.DoClickInternal = g_emptyFunction
optionPanel:SetTextInset(10, 0)
optionPanel:DockPadding(5,5,5,5)
optionPanel:DockPadding(5, 5, 5, 5)
local ply = LocalPlayer()
@ -246,7 +245,7 @@ local g_VolumeMenuOpen = function( self, optionPanel, ent )
upButton:Dock(RIGHT)
upButton:SetImage(StreamRadioLib.GetPNGIconPath("sound_add"))
upButton:SetText("")
upButton:DockMargin(5,0,0,0)
upButton:DockMargin(5, 0, 0, 0)
upButton:SetTooltip("Increase volume")
upButton.DoClick = function(panel)
@ -268,7 +267,7 @@ local g_VolumeMenuOpen = function( self, optionPanel, ent )
downButton:Dock(RIGHT)
downButton:SetImage(StreamRadioLib.GetPNGIconPath("sound_delete"))
downButton:SetText("")
downButton:DockMargin(5,0,0,0)
downButton:DockMargin(5, 0, 0, 0)
downButton:SetTooltip("Decrease volume")
downButton.DoClick = function(panel)
@ -290,7 +289,7 @@ local g_VolumeMenuOpen = function( self, optionPanel, ent )
muteButton:Dock(RIGHT)
muteButton:SetImage(StreamRadioLib.GetPNGIconPath("sound_mute"))
muteButton:SetText("")
muteButton:DockMargin(0,0,0,0)
muteButton:DockMargin(0, 0, 0, 0)
muteButton:SetTooltip("Mute")
muteButton.DoClick = function(panel)
@ -312,7 +311,7 @@ local g_VolumeMenuOpen = function( self, optionPanel, ent )
unmuteButton:Dock(RIGHT)
unmuteButton:SetImage(StreamRadioLib.GetPNGIconPath("sound"))
unmuteButton:SetText("")
unmuteButton:DockMargin(0,0,0,0)
unmuteButton:DockMargin(0, 0, 0, 0)
unmuteButton:SetTooltip("Unmute")
unmuteButton.DoClick = function(panel)
@ -350,7 +349,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
optionPanel.DoClickInternal = g_emptyFunction
optionPanel:SetTextInset(5, 0)
optionPanel:DockPadding(5,5,5,5)
optionPanel:DockPadding(5, 5, 5, 5)
local ply = LocalPlayer()
@ -360,7 +359,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
playButton:Dock(LEFT)
playButton:SetImage(StreamRadioLib.GetPNGIconPath("control_play"))
playButton:SetText("")
playButton:DockMargin(0,0,0,0)
playButton:DockMargin(0, 0, 0, 0)
playButton:SetTooltip("Play")
playButton.DoClick = function(panel)
@ -382,7 +381,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
pauseButton:Dock(LEFT)
pauseButton:SetImage(StreamRadioLib.GetPNGIconPath("control_pause"))
pauseButton:SetText("")
pauseButton:DockMargin(0,0,0,0)
pauseButton:DockMargin(0, 0, 0, 0)
pauseButton:SetTooltip("Pause")
pauseButton.DoClick = function(panel)
@ -404,7 +403,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
stopButton:Dock(LEFT)
stopButton:SetImage(StreamRadioLib.GetPNGIconPath("control_stop"))
stopButton:SetText("")
stopButton:DockMargin(5,0,0,0)
stopButton:DockMargin(5, 0, 0, 0)
stopButton:SetTooltip("Stop")
stopButton.DoClick = function(panel)
@ -426,7 +425,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
previousTrackButton:Dock(LEFT)
previousTrackButton:SetImage(StreamRadioLib.GetPNGIconPath("control_start"))
previousTrackButton:SetText("")
previousTrackButton:DockMargin(5,0,0,0)
previousTrackButton:DockMargin(5, 0, 0, 0)
previousTrackButton:SetTooltip("Previous track")
previousTrackButton.DoClick = function(panel)
@ -448,7 +447,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
nextTrackButton:Dock(LEFT)
nextTrackButton:SetImage(StreamRadioLib.GetPNGIconPath("control_end"))
nextTrackButton:SetText("")
nextTrackButton:DockMargin(5,0,0,0)
nextTrackButton:DockMargin(5, 0, 0, 0)
nextTrackButton:SetTooltip("Next track")
nextTrackButton.DoClick = function(panel)
@ -470,7 +469,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
rewindButton:Dock(LEFT)
rewindButton:SetImage(StreamRadioLib.GetPNGIconPath("control_rewind"))
rewindButton:SetText("")
rewindButton:DockMargin(5,0,0,0)
rewindButton:DockMargin(5, 0, 0, 0)
rewindButton:SetTooltip("Rewind 10 seconds")
rewindButton.DoClick = function(panel)
@ -492,7 +491,7 @@ local g_PlaylistControlsMenuOpen = function( self, optionPanel, ent )
fastForwardButton:Dock(LEFT)
fastForwardButton:SetImage(StreamRadioLib.GetPNGIconPath("control_fastforward"))
fastForwardButton:SetText("")
fastForwardButton:DockMargin(5,0,0,0)
fastForwardButton:DockMargin(5, 0, 0, 0)
fastForwardButton:SetTooltip("Fast forward 10 seconds")
fastForwardButton.DoClick = function(panel)

View File

@ -8,25 +8,29 @@ table.Empty(LIB)
local LIBNetwork = StreamRadioLib.Network
local LIBNet = StreamRadioLib.Net
function LIB.GetTool(ply)
function LIB.GetTool(ply, toolmode)
if not IsValid(ply) then
if SERVER then return end
if SERVER then
return nil
end
ply = LocalPlayer()
end
if not IsValid(ply) then return end
if not IsValid(ply) then
return nil
end
local tool = ply:GetWeapon("gmod_tool")
if not IsValid(tool) then return end
local toolobj = ply:GetTool(toolmode)
if not toolobj then
return nil
end
if not tool.GetToolObject then return end
if not tool.GetMode then return end
if toolobj.Mode ~= toolmode then
return nil
end
local toolobj = tool:GetToolObject()
if not toolobj then return end
if toolobj.Mode ~= tool:GetMode() then return end
return toolobj, tool
return toolobj
end
local g_locale_specialcases = {
@ -189,9 +193,9 @@ function LIB.Setup(toolobj)
end
var = tostring(var)
var = string.Replace(var, '"', "")
var = string.Replace(var, "\"", "")
ply:ConCommand(self.Mode .. "_" .. name .. ' "' .. var .. '"')
ply:ConCommand(self.Mode .. "_" .. name .. " \"" .. var .. "\"")
end
function toolobj:SetClientNumber(name, var)
@ -236,9 +240,11 @@ function LIB.Setup(toolobj)
function toolobj:AddReadOnlyTextBox( panel, name )
local boxPanel = vgui.Create("DForm")
boxPanel:SetName(StreamRadioLib.Tool.GetLocale(self, name))
panel:AddPanel(boxPanel)
boxPanel:SetCookieName(name)
local label = vgui.Create( "Streamradio_VGUI_ReadOnlyTextEntry" )
boxPanel:AddItem( label )
@ -263,6 +269,17 @@ function LIB.Setup(toolobj)
return label
end
function toolobj:AddImportantLabel( panel, name, descbool )
local label = StreamRadioLib.Menu.GetImportantLabel(StreamRadioLib.Tool.GetLocale(self, name))
panel:AddPanel( label )
if descbool then
label:SetTooltip(StreamRadioLib.Tool.GetLocale(self, name .. ".desc"))
end
return label
end
function toolobj:AddButton( panel, name, descbool )
local button = vgui.Create( "DButton" )
panel:AddPanel( button )
@ -386,16 +403,15 @@ function LIB.Setup(toolobj)
end
StreamRadioLib.Timer.Until("ToolReload_" .. _toolmode, 0.1, function()
local this = LIB.GetTool()
local ply = LocalPlayer()
local this = LIB.GetTool(ply, _toolmode)
if not this then return end
if this.Mode ~= _toolmode then return end
local CPanel = g_reloadpanels[_toolmode]
if not IsValid(CPanel) then return end
if not this.BuildToolPanel then return end
CPanel._toolobj = this
this.ToolPanel = CPanel
local toolpresets = this.Presets or {}
@ -403,7 +419,7 @@ function LIB.Setup(toolobj)
local CVars = toolpresets.CVars or {}
if #CVars <= 0 then
for k,v in pairs(this.ClientConVar or {}) do
for k, v in pairs(this.ClientConVar or {}) do
table.insert(CVars, this.Mode .. "_" .. k)
end
end
@ -474,15 +490,8 @@ function LIB.RegisterClientToolHook(tool, toolhook)
local nwtoolname = net.ReadString()
local bwhook = net.ReadString()
local tool = ply:GetWeapon("gmod_tool")
if not IsValid(tool) then return end
if tool:GetMode() ~= nwtoolname then return end
local toolobj = tool:GetToolObject()
local toolobj = LIB.GetTool(ply, nwtoolname)
if not toolobj then return end
if toolobj.Mode ~= nwtoolname then return end
local func = toolobj[bwhook .. "Client"]
if not func then return end

View File

@ -13,8 +13,6 @@ local g_sanitizeOnlineUrlCache = LIBUtil.CreateCacheArray(2048)
local g_sanitizeOfflineUrlCache = LIBUtil.CreateCacheArray(2048)
local g_isOfflineURLCache = LIBUtil.CreateCacheArray(2048)
local g_customProtocols = {}
local function GetProtocol(url)
url = tostring(url or "")

View File

@ -5,6 +5,8 @@ StreamRadioLib.Util = StreamRadioLib.Util or {}
local LIB = StreamRadioLib.Util
table.Empty(LIB)
local LIBString = StreamRadioLib.String
local g_debug = false
local g_debug_nextcheck = 0
@ -172,6 +174,49 @@ function LIB.EmptyTableSafe(tab)
table.Empty(tab)
end
function LIB.GetMainDirectory(directory)
local baseDirectory = StreamRadioLib.DataDirectory or ""
if baseDirectory == "" then
error("StreamRadioLib.DataDirectory is empty")
return
end
directory = tostring(directory or "")
local mainPath = baseDirectory .. "/" .. directory
mainPath = LIBString.NormalizeSlashes(mainPath)
return mainPath
end
function LIB.CreateDirectoryForFile(path)
local baseDirectory = StreamRadioLib.DataDirectory or ""
if baseDirectory == "" then
return false
end
path = tostring(path or "")
if path == "" then
return false
end
if not string.StartsWith(path, baseDirectory) then
return false
end
local directory = string.GetPathFromFilename(path) or ""
if directory == "" then return true end
if not file.IsDir(directory, "DATA") then
file.CreateDir(directory)
end
return file.IsDir(directory, "DATA")
end
function LIB.DeleteFolder(path)
local baseDirectory = StreamRadioLib.DataDirectory or ""

View File

@ -163,7 +163,9 @@ end
local g_PlayerHandTraceCache = nil
local g_PlayerHandTrace = {}
g_PlayerHandTrace.output = {}
g_PlayerHandTrace.filter = {}
function LIB.TraceHand()
if not CLIENT then
@ -205,12 +207,12 @@ function LIB.TraceHand()
tmp[ply] = ply
tmp[plyVehicle] = plyVehicle
filter = {}
local filter = g_PlayerHandTrace.filter
table.Empty(filter)
for _, filterEnt in pairs(tmp) do
if not IsValid(filterEnt) then continue end
filter[#filter + 1] = filterEnt
table.insert(filter, filterEnt)
end
g_PlayerHandTrace.filter = filter

View File

@ -141,7 +141,9 @@ function LIB.GetUserPos(ent)
return nil
end
pos = ent:GetPos()
local pos = ent:GetPos()
return pos
end
function LIB.GetUserPosDir(ent)

View File

@ -85,7 +85,7 @@ if StreamRadioLib and StreamRadioLib.Loaded then
StreamRadioLib.Tool.AddLocale(TOOL, "mute_volume_info", "NOTE: These are entity options too. So they only affect the radio they are applied on. The global settings for your client are at 'General Settings'.")
StreamRadioLib.Tool.AddLocale(TOOL, "mute_volume_info.desc", "NOTE: These are entity options too. So they only affect the radio they are applied on. The global settings for your client are at 'General Settings'.")
StreamRadioLib.Tool.AddLocale(TOOL, "streamurl_whitelist_info", "Whitelist protected server: Only approved Stream URLs will work on this server!")
StreamRadioLib.Tool.AddLocale(TOOL, "streamurl_whitelist_info", "Whitelist protected server:\nOnly approved Stream URLs will work on this server!")
StreamRadioLib.Tool.Setup(TOOL)
else
@ -154,7 +154,7 @@ function TOOL:BuildToolPanel(CPanel)
CPanel:AddPanel(StreamRadioLib.Menu.GetSpacerLine())
self:AddLabel( CPanel, "mute_volume_info", true )
self:AddImportantLabel( CPanel, "mute_volume_info", true )
CPanel:AddPanel(StreamRadioLib.Menu.GetSpacer())

View File

@ -380,7 +380,7 @@ function TOOL:AddModeList( panel )
listpanel:SetMultiSelect(false)
local col1 = listpanel:AddColumn("No.")
local col2 = listpanel:AddColumn("Item")
listpanel:AddColumn("Item")
local col3 = listpanel:AddColumn("Color")
local col4 = listpanel:AddColumn("Active")
@ -400,8 +400,8 @@ function TOOL:AddModeList( panel )
local data = self:GetColors(true)
local changed = false
if ( input.IsMouseDown( MOUSE_LEFT ) ) then return end
if ( listpanel.NextConVarCheck > RealTime() ) then return end
if input.IsMouseDown(MOUSE_LEFT) then return end
if listpanel.NextConVarCheck > RealTime() then return end
listpanel.NextConVarCheck = RealTime() + 0.2
@ -535,7 +535,6 @@ function TOOL:GetAimedGui(trace)
if not trace.Hit then return end
local ent = trace.Entity
local owner = self:GetOwner()
if not self:IsValidGUIRadio(ent) then return end
@ -548,7 +547,7 @@ end
function TOOL:LeftClick(trace)
if not self.ToolLibLoaded then return end
local entgui, ent = self:GetAimedGui(trace)
local entgui = self:GetAimedGui(trace)
if not IsValid(entgui) then return false end
if CLIENT then return true end
@ -560,7 +559,7 @@ end
function TOOL:RightClick(trace)
if not self.ToolLibLoaded then return end
local entgui, ent = self:GetAimedGui(trace)
local entgui = self:GetAimedGui(trace)
if not IsValid(entgui) then return false end
if CLIENT then return true end
@ -572,7 +571,7 @@ end
function TOOL:LeftClickClient()
if not self.ToolLibLoaded then return end
local entgui, ent = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return end
local data = self:GetColors()
@ -591,7 +590,7 @@ end
function TOOL:RightClickClient()
if not self.ToolLibLoaded then return end
local entgui, ent = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return end
local skindata = {}
@ -599,6 +598,7 @@ function TOOL:RightClickClient()
for varname, skinvar in pairs(self.SkinVars) do
local hierarchies = skinvar.hierarchies or {}
local hrvarname = skinvar.name
local value = nil
for _, skinhierarchy in pairs(hierarchies) do
local panels = entgui:GetPanelsBySkinIdentifyer(skinhierarchy)
@ -622,7 +622,7 @@ end
function TOOL:Reload(trace)
if not self.ToolLibLoaded then return end
local entgui, ent = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return false end
if CLIENT then return true end
@ -634,7 +634,7 @@ end
function TOOL:ReloadClient()
if not self.ToolLibLoaded then return end
local entgui, ent = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return end
entgui:SetSkinOnServer(StreamRadioLib.Skin.GetDefaultSkin(), false)

View File

@ -28,7 +28,7 @@ TOOL.SkinVars = {
},
color_hover = {
default = Color(192,192,192, 255),
default = Color(192, 192, 192, 255),
order = 5,
},
@ -43,7 +43,7 @@ TOOL.SkinVars = {
},
color_disabled = {
default = Color(128,128,128, 255),
default = Color(128, 128, 128, 255),
order = 8,
},
@ -178,7 +178,7 @@ function TOOL:AddModeList( panel )
listpanel:SetMultiSelect(false)
local col1 = listpanel:AddColumn("No.")
local col2 = listpanel:AddColumn("Item")
listpanel:AddColumn("Item")
local col3 = listpanel:AddColumn("Color")
local col4 = listpanel:AddColumn("Active")
@ -410,7 +410,7 @@ end
function TOOL:LeftClick(trace)
if not self.ToolLibLoaded then return end
local aimedpanel, entgui, ent = self:GetAimedObject(trace)
local aimedpanel = self:GetAimedObject(trace)
if not IsValid(aimedpanel) then return false end
if CLIENT then return true end
@ -421,7 +421,7 @@ end
function TOOL:RightClick(trace)
if not self.ToolLibLoaded then return end
local aimedpanel, entgui, ent = self:GetAimedObject(trace)
local aimedpanel = self:GetAimedObject(trace)
if not IsValid(aimedpanel) then return false end
if CLIENT then return true end
@ -432,7 +432,7 @@ end
function TOOL:LeftClickClient()
if not self.ToolLibLoaded then return end
local aimedpanel, entgui, ent = self:GetAimedObject()
local aimedpanel, entgui = self:GetAimedObject()
if not IsValid(aimedpanel) then return end
local skinhierarchy = aimedpanel:GetSkinIdentifyerHierarchy()
@ -454,7 +454,7 @@ end
function TOOL:RightClickClient()
if not self.ToolLibLoaded then return end
local aimedpanel, entgui, ent = self:GetAimedObject()
local aimedpanel, entgui = self:GetAimedObject()
if not IsValid(aimedpanel) then return end
local skindata = aimedpanel:GetSkinValues() or {}
@ -489,7 +489,7 @@ function TOOL:Think()
if not self.ToolLibLoaded then return end
if SERVER then return end
local aimedpanel, entgui, ent = self:GetAimedObject()
local aimedpanel, entgui = self:GetAimedObject()
if not IsValid(aimedpanel) then
if IsValid(self.highlighter_hover) then
self.highlighter_hover:Remove()

View File

@ -99,7 +99,7 @@ function TOOL:AddSkinList( panel )
listpanel:SetMultiSelect(false)
local col1 = listpanel:AddColumn("No.")
local col2 = listpanel:AddColumn("Name")
listpanel:AddColumn("Name")
local col3 = listpanel:AddColumn("Open")
col1:SetFixedWidth(30)
@ -265,8 +265,6 @@ function TOOL:AddFileControlPanel( panel )
local name = bgpanel:GetFile()
checkfile(name)
local filepath = StreamRadioLib.Skin.GetPath(name)
Derma_Query(
StreamRadioLib.Tool.GetLocaleTranslation(self, "file.delete.desc"),
StreamRadioLib.Tool.GetLocaleTranslation(self, "file.delete"),
@ -487,19 +485,18 @@ function TOOL:GetAimedGui(trace)
if not trace.Hit then return end
local ent = trace.Entity
local owner = self:GetOwner()
if not self:IsValidGUIRadio(ent) then return end
local entgui = ent:GetGUI()
if not IsValid(entgui) then return end
return ent, entgui
return entgui, ent
end
function TOOL:LeftClick(trace)
if not self.ToolLibLoaded then return end
local ent, entgui = self:GetAimedGui(trace)
local entgui = self:GetAimedGui(trace)
if not IsValid(entgui) then return false end
if CLIENT then return true end
@ -510,7 +507,7 @@ end
function TOOL:LeftClickClient()
if not self.ToolLibLoaded then return end
local ent, entgui = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return false end
entgui:SetSkinOnServer(self:GetSkin(), false)
@ -518,7 +515,7 @@ end
function TOOL:RightClick(trace)
if not self.ToolLibLoaded then return end
local ent, entgui = self:GetAimedGui(trace)
local entgui = self:GetAimedGui(trace)
if not IsValid(entgui) then return false end
if CLIENT then return true end
@ -529,7 +526,7 @@ end
function TOOL:RightClickClient()
if not self.ToolLibLoaded then return end
local ent, entgui = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return false end
self:SetSkin(entgui:GetSkin())
@ -537,7 +534,7 @@ end
function TOOL:Reload(trace)
if not self.ToolLibLoaded then return end
local ent, entgui = self:GetAimedGui(trace)
local entgui = self:GetAimedGui(trace)
if not IsValid(entgui) then return false end
if CLIENT then return true end
@ -548,7 +545,7 @@ end
function TOOL:ReloadClient()
if not self.ToolLibLoaded then return end
local ent, entgui = self:GetAimedGui()
local entgui = self:GetAimedGui()
if not IsValid(entgui) then return false end
entgui:SetSkinOnServer(StreamRadioLib.Skin.GetDefaultSkin(), false)

View File

@ -1,2 +1,2 @@
435
1698622804
436
1699498359