Skip to content

Commit b306d85

Browse files
committed
Add DIALOG_STYLE_TABLIST and DIALOG_STYLE_TABLIST_HEADER support. Also fix a bug where columns don't get removed at times.
1 parent 5f4c588 commit b306d85

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

amx/client/client.lua

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,8 @@ function createListDialog()
16311631
listGrid = guiCreateGridList(0.0, 0.1, 1.0, 0.8,true,listWindow)
16321632
guiGridListSetSelectionMode(listGrid,2)
16331633
guiGridListSetScrollBars(listGrid, true, true)
1634-
listColumn = guiGridListAddColumn(listGrid, "List", 0.85)
1634+
guiGridListSetSortingEnabled (listGrid, false)
1635+
--listColumn = guiGridListAddColumn(listGrid, "List", 0.85)
16351636
listButton1 = guiCreateButton(10,323,256,20,"",false,listWindow)
16361637
listButton2 = guiCreateButton(281,323,256,20,"",false,listWindow)
16371638
guiSetVisible(listWindow, false)
@@ -1672,15 +1673,27 @@ function InitDialogs()
16721673
createMessageDialog()
16731674
end
16741675

1676+
function clearListItem()
1677+
guiGridListRemoveColumn(listGrid, listColumn) --First remove the default column
1678+
local colAmount = guiGridListGetColumnCount(listGrid)
1679+
for i=1, colAmount do --Column indexes appear to start from 1
1680+
if not guiGridListRemoveColumn(listGrid, i) then --Always clean up all columns
1681+
outputConsole('[AMX:ShowPlayerDialog] Error: Couldn\'t remove column: ' .. 'idx: ' .. i)
1682+
end
1683+
outputConsole('vals: ' .. 'idx: ' .. i)
1684+
end
1685+
guiGridListClear(listGrid)
1686+
end
1687+
16751688
function OnListDialogButton1Click( button, state )
16761689
if button == "left" then
16771690
local row, column = guiGridListGetSelectedItem(listGrid)
16781691
local text = guiGridListGetItemText(listGrid, row, column)
16791692
serverAMXEvent("OnDialogResponse", getElemID(localPlayer), listDialog, 1, row, text);
16801693
guiSetVisible(listWindow, false)
1681-
guiGridListClear(listGrid)
16821694
showCursor(false)
16831695
listDialog = nil
1696+
clearListItem()
16841697
end
16851698
end
16861699

@@ -1690,9 +1703,9 @@ function OnListDialogButton2Click( button, state )
16901703
local text = guiGridListGetItemText(listGrid, row, column)
16911704
serverAMXEvent("OnDialogResponse", getElemID(localPlayer), listDialog, 0, row, text);
16921705
guiSetVisible(listWindow, false)
1693-
guiGridListClear(listGrid)
16941706
showCursor(false)
16951707
listDialog = nil
1708+
clearListItem()
16961709
end
16971710
end
16981711

@@ -1752,18 +1765,57 @@ function ShowPlayerDialog(dialogid, dialogtype, caption, info, button1, button2)
17521765
guiSetVisible(inputWindow, true)
17531766
inputDialog = dialogid
17541767
showCursor(true)
1755-
elseif dialogtype == 2 then
1768+
elseif dialogtype == 2 or dialogtype == 4 or dialogtype == 5 then --DIALOG_STYLE_LIST, DIALOG_STYLE_TABLIST, DIALOG_STYLE_TABLIST_HEADER
1769+
--Setup the UI
17561770
guiSetText(listButton1, button1)
17571771
guiSetText(listButton2, button2)
17581772
guiSetText(listWindow, caption)
17591773
guiSetVisible(listWindow, true)
17601774
listDialog = dialogid
17611775
showCursor(true)
1762-
local items = string.gsub(info, "\t", " ")
1763-
items = string.split(items, "\n")
1764-
for k,v in ipairs(items) do
1765-
local row = guiGridListAddRow ( listGrid )
1766-
guiGridListSetItemText ( listGrid, row, listColumn, v, false, true)
1776+
-- Done
1777+
1778+
--Process each
1779+
--DIALOG_STYLE_LIST
1780+
if dialogtype == 2 then
1781+
local items = string.gsub(info, "\t", " ")
1782+
items = string.split(items, "\n")
1783+
listColumn = guiGridListAddColumn(listGrid, "List", 0.85)
1784+
for k,v in ipairs(items) do
1785+
local row = guiGridListAddRow ( listGrid )
1786+
guiGridListSetItemText ( listGrid, row, listColumn, v, false, true)
1787+
end
1788+
return
1789+
end
1790+
1791+
--DIALOG_STYLE_TABLIST, DIALOG_STYLE_TABLIST_HEADER
1792+
--Add the columns
1793+
local items = string.split(info, "\n") -- Get the first one which is the header
1794+
if #items < 1 then
1795+
outputConsole('Error, your dialog either has no items, its format is wrong or you\'re missing a newline character in the string')
1796+
outputConsole('The raw string was: ' .. info)
1797+
return --Abort if there's no items
1798+
end
1799+
1800+
--Create the header
1801+
local headerCols = string.split(items[1], "\t")
1802+
for k,v in ipairs(headerCols) do
1803+
local colIdx = guiGridListAddColumn( listGrid, (dialogtype == 5 and v or ''), 0.5 ) --If it's the DIALOG_STYLE_TABLIST_HEADER add the name, otherwise leave it blank
1804+
--outputConsole('headerCols - colidx: ' .. colIdx .. 'k: ' .. k .. 'v: ' .. v)
1805+
end
1806+
1807+
if dialogtype == 5 then --Only remove if it's a DIALOG_STYLE_TABLIST_HEADER
1808+
table.remove(items, 1) --remove the first item which is the header
1809+
end
1810+
1811+
--Add the rows ordered under each column
1812+
for k,v in ipairs(items) do --rows
1813+
local row = guiGridListAddRow ( listGrid ) --add the row
1814+
--Now process every individual column (columns are tabulated)
1815+
for hk,hv in ipairs(string.split(v, "\t")) do --header key, header value
1816+
--outputConsole('hk: ' .. hk .. 'hv: ' .. hv)
1817+
guiGridListSetItemText ( listGrid, row, hk, hv, false, true)
1818+
end
17671819
end
17681820
end
17691821
end

0 commit comments

Comments
 (0)