init commit

This commit is contained in:
2025-05-31 10:13:27 +02:00
parent 3da26f025c
commit ada9afc48d
30 changed files with 3955 additions and 16 deletions

View File

@@ -0,0 +1,100 @@
local IsValid = IsValid
local Clamp = math.Clamp
local RealTime = RealTime
local FrameTime = FrameTime
local Approach = math.Approach
local SetColor = surface.SetDrawColor
local SetMaterial = surface.SetMaterial
local DrawOutlinedText = draw.SimpleTextOutlined
local DrawTexturedRect = surface.DrawTexturedRect
local DrawRect = surface.DrawRect
local DrawHealthBar = SquadMenu.DrawHealthBar
local matGradient = Material( "vgui/gradient-r" )
local COLORS = {
WHITE = Color( 255, 255, 255, 255 ),
LOW_HEALTH = Color( 250, 20, 20, 255 ),
OUTLINE = Color( 0, 0, 0, 255 )
}
local PANEL = {}
function PANEL:Init()
self.avatar = vgui.Create( "AvatarImage", self )
self:InvalidateLayout()
self:SetPlayer()
end
function PANEL:SetPlayer( id, name, squad )
self.squad = squad
self.playerId = id
self.validateTimer = 0
self.name = SquadMenu.ValidateString( name, "", 20 )
self.health = 1
self.armor = 0
self.alive = true
self.healthAnim = 0
self.armorAnim = 0
end
function PANEL:Think()
if IsValid( self.ply ) then
self.health = Clamp( self.ply:Health() / 100, 0, 1 )
self.armor = Clamp( self.ply:Armor() / 100, 0, 1 )
self.alive = self.ply:Alive()
return
end
-- Keep trying to get the player entity periodically
if RealTime() < self.validateTimer then return end
self.validateTimer = RealTime() + 1
local ply = SquadMenu.FindPlayerById( self.playerId )
if ply then
self.ply = ply
self.name = SquadMenu.ValidateString( ply:Nick(), "", 20 )
self.avatar:SetPlayer( ply, 64 )
end
end
function PANEL:Paint( w, h )
local split = h
if self.squad then
SetColor( self.squad.color:Unpack() )
DrawRect( w - split, 0, split, h )
end
SetColor( 0, 0, 0, 240 )
SetMaterial( matGradient )
DrawTexturedRect( 0, 0, w - split, h )
local dt = FrameTime()
self.healthAnim = Approach( self.healthAnim, self.health, dt * 2 )
self.armorAnim = Approach( self.armorAnim, self.armor, dt )
if self.alive then
local barH = h * 0.2
DrawHealthBar( 2, h - barH - 5, w - split - 6, barH, self.healthAnim, self.armorAnim )
end
DrawOutlinedText( self.name, "SquadMenuInfo", 2, 2 + h * 0.5,
self.alive and COLORS.WHITE or COLORS.LOW_HEALTH, 0, self.alive and 4 or 1, 1, COLORS.OUTLINE )
end
function PANEL:PerformLayout( w, h )
local size = h - 4
self.avatar:SetSize( size, size )
self.avatar:SetPos( w - size - 2, 2 )
end
vgui.Register( "Squad_MemberInfo", PANEL, "DPanel" )

View File

@@ -0,0 +1,199 @@
local L = SquadMenu.GetLanguageText
local ScaleSize = StyledTheme.ScaleSize
local UpdateButton = function( button, text, enabled )
button:SetEnabled( enabled )
button:SetText( L( text ) )
button:SizeToContentsX( ScaleSize( 12 ) )
button:GetParent():InvalidateLayout()
end
local PANEL = {}
local COLOR_BLACK = Color( 0, 0, 0, 255 )
function PANEL:Init()
self.squad = {
id = 0,
name = "-",
leaderName = "-",
color = COLOR_BLACK
}
self:SetCursor( "hand" )
self:SetExpanded( false )
self.animHover = 0
self.collapsedHeight = ScaleSize( 52 )
self.padding = ScaleSize( 6 )
self.iconSize = self.collapsedHeight - self.padding * 2
self.icon = vgui.Create( "DImage", self )
self.icon:SetSize( self.iconSize, self.iconSize )
self.buttonJoin = vgui.Create( "DButton", self )
StyledTheme.Apply( self.buttonJoin )
self.buttonJoin:SetTall( self.collapsedHeight - self.padding * 2 )
self.buttonJoin.DoClick = function()
if self.leaveOnClick then
SquadMenu.LeaveMySquad( self.buttonJoin )
else
UpdateButton( self.buttonJoin, "waiting_response", false )
SquadMenu.StartCommand( SquadMenu.JOIN_SQUAD )
net.WriteUInt( self.squad.id, 16 )
net.SendToServer()
end
end
self.memberCount = vgui.Create( "DPanel", self )
self.memberCount:SetTall( self.collapsedHeight - self.padding * 2 )
self.memberCount:SetPaintBackground( false )
self:SetTall( self.collapsedHeight )
end
function PANEL:PerformLayout( w )
self.icon:SetPos( self.padding, self.padding )
local joinWidth = self.buttonJoin:GetWide()
self.buttonJoin:SetPos( w - joinWidth - self.padding, self.padding )
self.memberCount:SetPos( w - joinWidth - self.memberCount:GetWide() - self.padding * 2, self.padding )
end
local colors = StyledTheme.colors
local DrawRect = StyledTheme.DrawRect
function PANEL:Paint( w, h )
self.animHover = Lerp( FrameTime() * 10, self.animHover, self:IsHovered() and 1 or 0 )
DrawRect( 0, 0, w, h, self.squad.color )
DrawRect( 1, 1, w - 2, h - 2, COLOR_BLACK )
DrawRect( 1, 1, w - 2, h - 2, colors.buttonHover, self.animHover )
local x = self.iconSize + self.padding * 2
local y = self.collapsedHeight * 0.5
draw.SimpleText( self.squad.name, "StyledTheme_Small", x, y, colors.labelText, 0, 4 )
draw.SimpleText( self.squad.leaderName or "<Server>", "StyledTheme_Tiny", x, y, colors.buttonTextDisabled, 0, 3 )
end
function PANEL:OnMousePressed( keyCode )
if keyCode == MOUSE_LEFT then
self:SetExpanded( not self.isExpanded, true )
end
end
--- Set the squad data.
--- `squad` is a table that comes from `squad:GetBasicInfo`.
function PANEL:SetSquad( squad )
squad.color = Color( squad.r, squad.g, squad.b )
self.squad = squad
self.icon:SetImage( squad.icon )
local maxMembers = SquadMenu.GetMemberLimit()
local count = #squad.members
self.leaveOnClick = squad.id == ( SquadMenu.mySquad and SquadMenu.mySquad.id or -1 )
if self.leaveOnClick then
UpdateButton( self.buttonJoin, "leave_squad", true )
elseif count < maxMembers then
UpdateButton( self.buttonJoin, squad.isPublic and "join" or "request_to_join", true )
else
UpdateButton( self.buttonJoin, "full_squad", false )
end
self.memberCount:Clear()
local labelCount = vgui.Create( "DLabel", self.memberCount )
labelCount:SetText( count .. "/" .. maxMembers )
labelCount:SizeToContents()
labelCount:Dock( FILL )
local labelWide = labelCount:GetWide()
local iconCount = vgui.Create( "DImage", self.memberCount )
iconCount:SetImage( "styledstrike/icons/users.png" )
iconCount:SetWide( self.collapsedHeight - self.padding * 4 )
iconCount:Dock( LEFT )
iconCount:DockMargin( 0, self.padding, 0, self.padding )
self.memberCount:SetWide( labelWide + iconCount:GetWide() )
end
function PANEL:SetExpanded( expanded, scroll )
self.isExpanded = expanded
local height = self.collapsedHeight
local memberHeight = ScaleSize( 32 )
if expanded then
height = height + self.padding + memberHeight * math.min( #self.squad.members, 5 )
end
self:SetTall( height )
self:InvalidateLayout()
if expanded and scroll then
self:GetParent():GetParent():ScrollToChild( self )
end
if self.membersScroll then
self.membersScroll:Remove()
self.membersScroll = nil
end
if not expanded then return end
local membersScroll = vgui.Create( "DScrollPanel", self )
membersScroll:Dock( FILL )
membersScroll:DockMargin( 0, self.collapsedHeight, 0, 0 )
membersScroll.pnlCanvas:DockPadding( 0, 0, 0, 0 )
self.membersScroll = membersScroll
local byId = SquadMenu.AllPlayersById()
local separation = ScaleSize( 2 )
local padding = ScaleSize( 4 )
for _, m in ipairs( self.squad.members ) do
local id = m[1]
local row = vgui.Create( "DPanel", membersScroll )
row:SetBackgroundColor( colors.panelBackground )
row:SetTall( memberHeight - separation )
row:Dock( TOP )
row:DockMargin( self.padding, 0, self.padding, separation )
local name = vgui.Create( "DLabel", row )
name:SetText( m[2] )
name:Dock( FILL )
local avatar = vgui.Create( "AvatarImage", row )
avatar:SetWide( memberHeight - padding * 2 )
avatar:Dock( LEFT )
avatar:DockMargin( padding, padding, padding, padding )
if byId[id] then
avatar:SetPlayer( byId[id], 64 )
end
if id == self.squad.leaderId then
row:SetZPos( -1 )
local leaderIcon = vgui.Create( "DImage", row )
leaderIcon:SetWide( memberHeight - padding * 2 )
leaderIcon:SetImage( "icon16/award_star_gold_3.png" )
leaderIcon:Dock( RIGHT )
leaderIcon:DockMargin( 0, padding, padding, padding )
end
end
end
vgui.Register( "Squad_ListRow", PANEL, "DPanel" )