CopsNRobbers/gamemodes/copsnrobbers/gamemode/cl_selectteam.lua

95 lines
2.1 KiB
Lua
Raw Permalink Normal View History

2023-12-21 20:40:47 -05:00
function GM:ShowTeam()
if IsValid( teampanel ) then teampanel:Remove() return end
local s = ScreenScaleH
teampanel = vgui.Create( "DFrame" )
2023-12-22 09:07:47 -05:00
teampanel:SetSize( s(320), s(240) )
2023-12-21 20:40:47 -05:00
teampanel:Center()
teampanel:MakePopup()
function teampanel:Paint( w, h )
surface.SetDrawColor( color_white )
surface.DrawRect( 0, 0, w, h )
return true
end
2023-12-22 09:07:47 -05:00
-- the ids are undefined pretty early and whatever
local teams = {
{
Name = "Side A",
ID = TEAM_SIDEA,
},
{
Name = "Side B",
ID = TEAM_SIDEB,
},
{
Name = "Spectate",
ID = TEAM_SPECTATOR,
},
{
Name = "Auto-Select",
ID = true,
},
}
2023-12-21 20:40:47 -05:00
for i, v in ipairs( teams ) do
local button = teampanel:Add( "DButton" )
2023-12-22 09:07:47 -05:00
button:SetSize( s(320), s(48) )
2023-12-21 20:40:47 -05:00
button:DockMargin( 0, s(2), 0, 0 )
button:Dock( TOP )
function button:Paint( w, h )
surface.SetDrawColor( color_white )
surface.DrawRect( 0, 0, w, h )
surface.SetDrawColor( color_black )
surface.DrawOutlinedRect( 0, 0, w, h, s(1) )
2024-07-18 17:27:46 -04:00
draw.SimpleText( v.Name, "CNR_HUD_18", s(4), s(4), color_black )
2023-12-22 09:07:47 -05:00
local plys = team.GetPlayers( v.ID )
local mew = { [1] = {} }
local curr = 1
for _, v in ipairs( plys ) do
local concat = ""
local nick = v:Nick()
if #nick > 8 then
nick = nick:Left(8) .. ".."
end
concat = concat .. nick
--if i!= #plys then
-- concat = concat .. ", "
--end
if #mew[curr] > 5 then
curr = curr + 1
end
if !mew[curr] then
mew[curr] = {}
end
table.insert( mew[curr], concat )
end
local bump = 0
for _, row in ipairs( mew ) do
bump = 0
for i, v in ipairs( row ) do
local tada = v .. ((i!=#row) and ", " or "")
2024-07-18 17:27:46 -04:00
draw.SimpleText( tada, "CNR_HUD_10", s(4)+bump, s(4+16 + s((_-1)*4)), color_black )
surface.SetFont( "CNR_HUD_10" )
2023-12-22 09:07:47 -05:00
bump = bump + surface.GetTextSize( tada )
end
end
2023-12-21 20:40:47 -05:00
return true
end
function button:DoClick()
2023-12-22 09:07:47 -05:00
if v.ID == true then
RunConsoleCommand( "changeteam", team.BestAutoJoinTeam() )
else
RunConsoleCommand( "changeteam", v.ID )
end
2023-12-21 20:40:47 -05:00
teampanel:Remove()
end
end
end