Skip to content

Commit

Permalink
rewrite vote area (#49)
Browse files Browse the repository at this point in the history
* rewrite vote area

* add disable diagnostic for OnMapClicked

* use Performlayout

* fix padding and margin for avatars and map icons

* make icons smaller

* recalculate avatar positions on perform layout

* remove debug print

* fix linter error
  • Loading branch information
plally authored Jan 30, 2024
1 parent 0d91ae2 commit d8fe617
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 174 deletions.
13 changes: 5 additions & 8 deletions lua/mapvote/client/modules/map_vote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ end
function MapVote.ChangeVote( ply, mapIndex )
if not IsValid( ply ) then return end
if not IsValid( MapVote.Panel ) then return end

local mapData = MapVote.Panel.voteArea:GetMapDataByIndex( mapIndex )
MapVote.Panel.voteArea:SetVote( ply, mapData.map )
MapVote.Panel.voteArea:SetVote( ply, mapIndex )
end

function MapVote.StartVote( maps, endTime )
Expand Down Expand Up @@ -78,19 +76,18 @@ function MapVote.StartVote( maps, endTime )

countdownLabel:SetText( string.FormattedTime( timeLeft or 0, "%02i:%02i" ) )
end )
local voteArea = vgui.Create( "MapVote_Vote", frame ) --[[@as VoteArea]]
local voteArea = vgui.Create( "MapVote_VoteArea", frame )
local margin = 10
voteArea:Dock( FILL )
voteArea:DockMargin( margin, margin, margin, margin )
voteArea:SetMaps( maps )
voteArea:InvalidateLayout( true )
voteArea:InvalidateParent( true )
voteArea:SetMaps( maps )

frame:SetTall( voteArea:GetTotalRowHeight() + infoRow:GetTall() + margin * 2 + 34 )
frame:SetTall( voteArea:GetTotalRowHeight() + infoRow:GetTall() + margin * 3 + 20 )
frame:SetWide( voteArea:GetTotalRowWidth() + margin * 2 + 10 )
voteArea:InvalidateParent( true )
voteArea:InvalidateLayout( true )
frame:Center()
voteArea:UpdateRowPositions()

local lastClicked = CurTime()
---@diagnostic disable-next-line: duplicate-set-field
Expand Down
4 changes: 2 additions & 2 deletions lua/mapvote/client/vgui/map_icon.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@class MapIcon : Panel
---@class MapVote_MapIcon : Panel
local PANEL = {}

function PANEL:Init()
Expand Down Expand Up @@ -30,7 +30,7 @@ function PANEL:SetMap( map )
MapVote.ThumbDownloader:QueueDownload( map, function( filepath )
MapVote.TaskManager.AddFunc( function()
---@diagnostic disable-next-line: missing-parameter
self.button:SetImage( filepath or noIcon )
self.button:SetImage( filepath )
end )
end )
end
Expand Down
Loading

0 comments on commit d8fe617

Please sign in to comment.