Skip to content

Commit e0d1642

Browse files
authored
admin2: fixed various sorting related gridlist issues (#416)
* admin2: fixed spectator player action buttons admin2 : fixed spectator player action GUI buttons which were non-functional due to referring to global variable names from old admin. * admin2: fixed sorting issues in several widget gridlists fixed disappearing text and incorrectly displayed sections for aVehicle aWeapon and aSkin widget gridlists if the user used gridlist sorting; fixed incorrectly set aSetting used to remember 'sort by groups' for aVehicle; unified .Refresh function for aVehicle and aSkin to match aWeapon * admin2: fixed sorting issues in players and resources gridlist fixed disappearing text in players and resources tab gridlist if the user used gridlist sorting and search filter; unified player search to match the filter structure and method used in widgets; fixed selected player being unselected when using search filter * admin2: admin_players.lua whitespace changes changed tabs to 4 spaces to match coding style * admin2: fixed sorting issues in interior and team widget fixed disappearing text in interiors widget gridlist and incorrect team color and team data application in teams widget gridlist when gridlist is user-sorted in conjunction with search-filter * admin2: fixed team widget not closing fixed team widget not closing when assigning a team via double click
1 parent 006eefb commit e0d1642

File tree

7 files changed

+53
-55
lines changed

7 files changed

+53
-55
lines changed

[admin]/admin2/client/main/admin_players.lua

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function aPlayersTab.Create(tab)
113113
addEventHandler("onClientGUIClick", aPlayersTab.Context, aPlayersTab.onContextClick)
114114
addEventHandler("onClientGUIClick", aPlayersTab.InfoContext, aPlayersTab.onContextClick)
115115
addEventHandler("onClientGUIClick", aPlayersTab.Tab, aPlayersTab.onClientClick)
116-
addEventHandler("onClientGUIChanged", aPlayersTab.PlayerListSearch, aPlayersTab.onPlayerListSearch)
116+
addEventHandler("onClientGUIChanged", aPlayersTab.PlayerListSearch, aPlayersTab.onGUIChange)
117117
addEventHandler("onClientPlayerChangeNick", root, aPlayersTab.onClientPlayerChangeNick)
118118
addEventHandler("aClientPlayerJoin", root, aPlayersTab.onClientPlayerJoin)
119119
addEventHandler("onClientPlayerQuit", root, aPlayersTab.onClientPlayerQuit)
@@ -321,23 +321,9 @@ function aPlayersTab.onClientClick(button)
321321
end
322322
end
323323

324-
function aPlayersTab.onPlayerListSearch()
325-
guiGridListClear(aPlayersTab.PlayerList)
326-
local text = guiGetText(source)
327-
if (text == "") then
328-
for id, player in ipairs(getElementsByType("player")) do
329-
local row = guiGridListAddRow(aPlayersTab.PlayerList)
330-
guiGridListSetItemText(aPlayersTab.PlayerList, row, 1, getPlayerName(player), false, false)
331-
guiGridListSetItemData(aPlayersTab.PlayerList, row, 1, player)
332-
end
333-
else
334-
for id, player in ipairs(getElementsByType("player")) do
335-
if (string.find(string.upper(getPlayerName(player)), string.upper(text))) then
336-
local row = guiGridListAddRow(aPlayersTab.PlayerList)
337-
guiGridListSetItemText(aPlayersTab.PlayerList, row, 1, getPlayerName(player), false, false)
338-
guiGridListSetItemData(aPlayersTab.PlayerList, row, 1, player)
339-
end
340-
end
324+
function aPlayersTab.onGUIChange()
325+
if (source == aPlayersTab.PlayerListSearch) then
326+
aPlayersTab.Refresh()
341327
end
342328
end
343329

@@ -386,11 +372,11 @@ end
386372
function aPlayersTab.onClientPlayerJoin(ip, username, serial, unused, country, countryname)
387373
if ip == false and serial == false then
388374
-- Update country only
389-
if aPlayers[source] then
390-
aPlayers[source].country = country
391-
aPlayers[source].countryname = countryname
392-
end
393-
return
375+
if aPlayers[source] then
376+
aPlayers[source].country = country
377+
aPlayers[source].countryname = countryname
378+
end
379+
return
394380
end
395381
aPlayers[source] = {}
396382
aPlayers[source].name = getPlayerName(source)
@@ -551,21 +537,25 @@ end
551537

552538
function aPlayersTab.Refresh()
553539
local selected = getSelectedPlayer()
554-
local list = aPlayersTab.PlayerList
555-
guiGridListClear(list)
556540
local strip = guiCheckBoxGetSelected(aPlayersTab.ColorCodes)
541+
local filter = guiGetText(aPlayersTab.PlayerListSearch):lower()
542+
local sortDirection = guiGetProperty(aPlayersTab.PlayerList, "SortDirection")
543+
guiGridListClear(aPlayersTab.PlayerList)
544+
guiSetProperty(aPlayersTab.PlayerList, "SortDirection", "None")
557545
for id, player in ipairs(getElementsByType("player")) do
558-
local row = guiGridListAddRow(list)
559546
local name = getPlayerName(player)
560-
if (strip) then
561-
name = stripColorCodes(name)
562-
end
563-
guiGridListSetItemText(list, row, 1, name, false, false)
564-
guiGridListSetItemData(list, row, 1, player)
565-
if (player == selected) then
566-
guiGridListSetSelectedItem(list, row, 1)
547+
if name:find(filter) or name:lower():find(filter) then
548+
if (strip) then
549+
name = stripColorCodes(name)
550+
end
551+
local row = guiGridListAddRow(aPlayersTab.PlayerList, name)
552+
guiGridListSetItemData(aPlayersTab.PlayerList, row, 1, player)
553+
if (player == selected) then
554+
guiGridListSetSelectedItem(aPlayersTab.PlayerList, row, 1)
555+
end
567556
end
568557
end
558+
guiSetProperty(aPlayersTab.PlayerList, "SortDirection", sortDirection)
569559
end
570560

571561
function getSelectedPlayer()

[admin]/admin2/client/main/admin_resources.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ function aResourcesTab.listResources(type)
275275
end
276276
for id, resource in ipairs(temp) do
277277
if (filter and resource.name:lower():find(filter:lower())) or (not filter) then
278-
local row = guiGridListAddRow(resources)
279-
guiGridListSetItemText(resources, row, 1, resource.name, false, false)
280-
guiGridListSetItemText(resources, row, 2, resource.state, false, false)
278+
guiGridListAddRow(resources, resource.name, resource.state)
281279
end
282280
end
283281
end

[admin]/admin2/client/widgets/admin_interior.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,15 @@ end
113113

114114
function aInterior.Refresh()
115115
local filter = guiGetText(aInterior.Edit):lower()
116+
local sortDirection = guiGetProperty(aInterior.List, "SortDirection")
116117
guiGridListClear(aInterior.List)
118+
guiSetProperty(aInterior.List, "SortDirection", "None")
117119
for k, v in ipairs(aInterior.interiors) do
118120
if v.world:find(filter) or v.id:lower():find(filter) then
119121
local row = guiGridListAddRow(aInterior.List)
120122
guiGridListSetItemText(aInterior.List, row, 1, v.world, false, true)
121123
guiGridListSetItemText(aInterior.List, row, 2, v.id, false, false)
122124
end
123125
end
126+
guiSetProperty(aInterior.List, "SortDirection", sortDirection)
124127
end

[admin]/admin2/client/widgets/admin_skin.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,13 @@ function aSkin.Load()
145145
end
146146

147147
function aSkin.Refresh()
148-
aSetSetting("skinsGroup", guiCheckBoxGetSelected(aSkin.Groups))
149-
guiGridListClear(aSkin.List)
148+
local groups = guiCheckBoxGetSelected(aSkin.Groups)
150149
local filter = guiGetText(aSkin.Edit):lower()
151-
if (guiCheckBoxGetSelected(aSkin.Groups)) then
150+
local sortDirection = guiGetProperty(aSkin.List, "SortDirection")
151+
aSetSetting("skinsGroup", groups)
152+
guiGridListClear(aSkin.List)
153+
guiSetProperty(aSkin.List, "SortDirection", "None")
154+
if (groups) then
152155
local skins = {}
153156
for name, group in pairs(aSkin.skins) do
154157
for _, skin in ipairs(group) do
@@ -164,9 +167,7 @@ function aSkin.Refresh()
164167
local row = guiGridListAddRow(aSkin.List)
165168
guiGridListSetItemText(aSkin.List, row, 2, name, true, false)
166169
for id, skin in ipairs(group) do
167-
row = guiGridListAddRow(aSkin.List)
168-
guiGridListSetItemText(aSkin.List, row, 1, skin.model, false, true)
169-
guiGridListSetItemText(aSkin.List, row, 2, skin.name, false, false)
170+
guiGridListAddRow(aSkin.List, skin.model, skin.name)
170171
end
171172
end
172173
guiGridListSetSortingEnabled(aSkin.List, false)
@@ -185,5 +186,6 @@ function aSkin.Refresh()
185186
end
186187
end
187188
guiGridListSetSortingEnabled(aSkin.List, true)
189+
guiSetProperty(aSkin.List, "SortDirection", sortDirection)
188190
end
189191
end

[admin]/admin2/client/widgets/admin_team.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function aTeam.onDoubleClick(button)
7070
if (guiGridListGetSelectedItem(aTeam.List) ~= -1) then
7171
local team = guiGridListGetItemText(aTeam.List, guiGridListGetSelectedItem(aTeam.List), 1)
7272
triggerServerEvent("aPlayer", localPlayer, getSelectedPlayer(), "setteam", getTeamFromName(team))
73-
aPlayerTeamClose(false)
73+
aTeam.Close(false)
7474
end
7575
end
7676
end
@@ -147,13 +147,15 @@ end
147147

148148
function aTeam.Refresh()
149149
if (aTeam.List) then
150+
local sortDirection = guiGetProperty(aTeam.List, "SortDirection")
150151
guiGridListClear(aTeam.List)
152+
guiSetProperty(aTeam.List, "SortDirection", "None")
151153
for id, team in ipairs(getElementsByType("team")) do
152-
local row = guiGridListAddRow(aTeam.List)
154+
local row = guiGridListAddRow(aTeam.List, getTeamName(team))
153155
local r, g, b = getTeamColor(team)
154-
guiGridListSetItemText(aTeam.List, row, 1, getTeamName(team), false, false)
155156
guiGridListSetItemColor(aTeam.List, row, 1, r, g, b)
156157
guiGridListSetItemData(aTeam.List, row, 1, team)
157158
end
159+
guiSetProperty(aTeam.List, "SortDirection", sortDirection)
158160
end
159161
end

[admin]/admin2/client/widgets/admin_vehicle.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function aVehicle.Show(player)
2727
guiCreateInnerImage("client\\images\\search.png", aVehicle.Edit)
2828

2929
aVehicle.Groups = guiCreateCheckBox(0.03, 0.90, 0.70, 0.09, "Sort by groups", false, true, aVehicle.Form)
30-
if (aGetSetting("weaponsGroup")) then
30+
if (aGetSetting("vehiclesGroup")) then
3131
guiCheckBoxSetSelected(aVehicle.Groups, true)
3232
end
3333

@@ -141,10 +141,13 @@ function aVehicle.Load()
141141
end
142142

143143
function aVehicle.Refresh()
144-
aSetSetting("weaponsGroup", guiCheckBoxGetSelected(aVehicle.Groups))
145-
guiGridListClear(aVehicle.List)
144+
local groups = guiCheckBoxGetSelected(aVehicle.Groups)
146145
local filter = guiGetText(aVehicle.Edit):lower()
147-
if (guiCheckBoxGetSelected(aVehicle.Groups)) then
146+
local sortDirection = guiGetProperty(aVehicle.List, "SortDirection")
147+
aSetSetting("vehiclesGroup", groups)
148+
guiGridListClear(aVehicle.List)
149+
guiSetProperty(aVehicle.List, "SortDirection", "None")
150+
if (groups) then
148151
local vehicles = {}
149152
for name, group in pairs(aVehicle.vehicles) do
150153
for _, vehicle in ipairs(group) do
@@ -160,9 +163,7 @@ function aVehicle.Refresh()
160163
local row = guiGridListAddRow(aVehicle.List)
161164
guiGridListSetItemText(aVehicle.List, row, 2, name, true, false)
162165
for id, vehicle in ipairs(group) do
163-
row = guiGridListAddRow(aVehicle.List)
164-
guiGridListSetItemText(aVehicle.List, row, 1, vehicle.id, false, true)
165-
guiGridListSetItemText(aVehicle.List, row, 2, vehicle.name, false, false)
166+
guiGridListAddRow(aVehicle.List, vehicle.id, vehicle.name)
166167
end
167168
end
168169
guiGridListSetSortingEnabled(aVehicle.List, false)
@@ -181,5 +182,6 @@ function aVehicle.Refresh()
181182
end
182183
end
183184
guiGridListSetSortingEnabled(aVehicle.List, true)
185+
guiSetProperty(aVehicle.List, "SortDirection", sortDirection)
184186
end
185187
end

[admin]/admin2/client/widgets/admin_weapon.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ end
154154
function aWeapon.Refresh()
155155
local groups = guiCheckBoxGetSelected(aWeapon.Groups)
156156
local filter = guiGetText(aWeapon.Edit):lower()
157+
local sortDirection = guiGetProperty(aWeapon.List, "SortDirection")
157158
aSetSetting("weaponsGroup", groups)
158159
guiGridListClear(aWeapon.List)
160+
guiSetProperty(aWeapon.List, "SortDirection", "None")
159161
if (groups) then
160162
local weapons = {}
161163
for name, group in pairs(aWeapon.weapons) do
@@ -172,9 +174,7 @@ function aWeapon.Refresh()
172174
local row = guiGridListAddRow(aWeapon.List)
173175
guiGridListSetItemText(aWeapon.List, row, 2, name, true, false)
174176
for id, weapon in ipairs(group) do
175-
row = guiGridListAddRow(aWeapon.List)
176-
guiGridListSetItemText(aWeapon.List, row, 1, weapon.id, false, true)
177-
guiGridListSetItemText(aWeapon.List, row, 2, weapon.name, false, false)
177+
guiGridListAddRow(aWeapon.List, weapon.id, weapon.name)
178178
end
179179
end
180180
guiGridListSetSortingEnabled(aWeapon.List, false)
@@ -193,5 +193,6 @@ function aWeapon.Refresh()
193193
end
194194
end
195195
guiGridListSetSortingEnabled(aWeapon.List, true)
196+
guiSetProperty(aWeapon.List, "SortDirection", sortDirection)
196197
end
197198
end

0 commit comments

Comments
 (0)