Skip to content

Improving the problems menu #2261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions garrysmod/lua/menu/problems/problem_lua.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local realmColors = {}
realmColors[ "menu" ] = Color( 121, 221, 100 )
realmColors[ "client" ] = Color( 255, 222, 102 )
Expand Down Expand Up @@ -77,8 +76,6 @@ function PANEL:Paint( w, h )
if ( count > 0 ) then
local txt = "x" .. count
surface.SetFont( "DermaMedium" )
local tW, tH = surface.GetTextSize( txt )
tW = tW

draw.SimpleText( txt, "DermaMedium", w - 16 - 16, h / 2, clr, draw.TEXT_ALIGN_RIGHT, draw.TEXT_ALIGN_CENTER )
end
Expand Down Expand Up @@ -269,15 +266,23 @@ function PANEL:ReceivedError( uid, err )
pnl:Setup( err )

if ( shouldSort ) then
local sorted = {}
for gid, epnl in pairs( self.ErrorPanels ) do
sorted[ epnl.Problem.firstOccurence ] = epnl
local sortedPanels = {}
local count = 0

for _, panel in pairs( self.ErrorPanels ) do
count = count + 1
sortedPanels[ count ] = {
time = panel.Problem.firstOccurence,
panel = panel
}
end

local z = 0
for sort, spnl in SortedPairs( sorted ) do
spnl:SetZPos( z )
z = z + 1
table.sort( sortedPanels, function( a, b )
return a.time < b.time
end )

for i = 1, count do
sortedPanels[ i ].panel:SetZPos( i - 1 )
end
end

Expand Down
40 changes: 23 additions & 17 deletions garrysmod/lua/menu/problems/problems.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

include( "problems_pnl.lua" )

local ProblemsPanel
Expand All @@ -9,26 +8,33 @@ local MenuUpdated = false
Problems = Problems or {}
ErrorLog = ErrorLog or {}

local function RefreshGenericProblemList()
if ( IsValid( ProblemsPanel ) ) then
ProblemsPanel.ProblemsList:Clear()
ProblemsPanel.ProblemPanels = {}
for id, prob in pairs( Problems ) do
ProblemsPanel:ReceivedProblem( id, prob )
end
ProblemsPanel:InvalidateLayout()
local function RefreshList( listPanel, itemsTable, panels, receiver )
if ( !IsValid( ProblemsPanel ) ) then return end

listPanel:Clear()
panels = {}
for id, item in pairs( itemsTable ) do
receiver( id, item )
end
ProblemsPanel:InvalidateLayout()
end

local function RefreshGenericProblemList()
RefreshList(
ProblemsPanel.ProblemsList,
Problems,
ProblemsPanel.ProblemPanels,
ProblemsPanel.ReceivedProblem
)
end

local function RefreshLuaErrorList()
if ( IsValid( ProblemsPanel ) ) then
ProblemsPanel.LuaErrorList:Clear()
ProblemsPanel.ErrorPanels = {}
for id, err in pairs( ErrorLog ) do
ProblemsPanel:ReceivedError( id, err )
end
ProblemsPanel:InvalidateLayout()
end
RefreshList(
ProblemsPanel.LuaErrorList,
ErrorLog,
ProblemsPanel.ErrorPanels,
ProblemsPanel.ReceivedError
)
end

local function CountProblem( severity )
Expand Down
12 changes: 11 additions & 1 deletion garrysmod/lua/menu/problems/problems_pnl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ function PANEL:Init()

end

function PANEL:Think()

if ( input.IsKeyDown( KEY_ESCAPE ) ) then
self:Remove()
end

end

function PANEL:AddEmptyWarning( txt, parent )

local lab = parent:Add( "DLabel" )
Expand All @@ -66,9 +74,11 @@ function PANEL:AddEmptyWarning( txt, parent )

end

local color_background = Color( 0, 0, 0, 240 )

function PANEL:Paint( w, h )

draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 240 ) )
draw.RoundedBox( 0, 0, 0, w, h, color_background )

end

Expand Down