@@ -1631,7 +1631,8 @@ function createListDialog()
1631
1631
listGrid = guiCreateGridList (0.0 , 0.1 , 1.0 , 0.8 ,true ,listWindow )
1632
1632
guiGridListSetSelectionMode (listGrid ,2 )
1633
1633
guiGridListSetScrollBars (listGrid , true , true )
1634
- listColumn = guiGridListAddColumn (listGrid , " List" , 0.85 )
1634
+ guiGridListSetSortingEnabled (listGrid , false )
1635
+ -- listColumn = guiGridListAddColumn(listGrid, "List", 0.85)
1635
1636
listButton1 = guiCreateButton (10 ,323 ,256 ,20 ," " ,false ,listWindow )
1636
1637
listButton2 = guiCreateButton (281 ,323 ,256 ,20 ," " ,false ,listWindow )
1637
1638
guiSetVisible (listWindow , false )
@@ -1672,15 +1673,27 @@ function InitDialogs()
1672
1673
createMessageDialog ()
1673
1674
end
1674
1675
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
+
1675
1688
function OnListDialogButton1Click ( button , state )
1676
1689
if button == " left" then
1677
1690
local row , column = guiGridListGetSelectedItem (listGrid )
1678
1691
local text = guiGridListGetItemText (listGrid , row , column )
1679
1692
serverAMXEvent (" OnDialogResponse" , getElemID (localPlayer ), listDialog , 1 , row , text );
1680
1693
guiSetVisible (listWindow , false )
1681
- guiGridListClear (listGrid )
1682
1694
showCursor (false )
1683
1695
listDialog = nil
1696
+ clearListItem ()
1684
1697
end
1685
1698
end
1686
1699
@@ -1690,9 +1703,9 @@ function OnListDialogButton2Click( button, state )
1690
1703
local text = guiGridListGetItemText (listGrid , row , column )
1691
1704
serverAMXEvent (" OnDialogResponse" , getElemID (localPlayer ), listDialog , 0 , row , text );
1692
1705
guiSetVisible (listWindow , false )
1693
- guiGridListClear (listGrid )
1694
1706
showCursor (false )
1695
1707
listDialog = nil
1708
+ clearListItem ()
1696
1709
end
1697
1710
end
1698
1711
@@ -1752,18 +1765,57 @@ function ShowPlayerDialog(dialogid, dialogtype, caption, info, button1, button2)
1752
1765
guiSetVisible (inputWindow , true )
1753
1766
inputDialog = dialogid
1754
1767
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
1756
1770
guiSetText (listButton1 , button1 )
1757
1771
guiSetText (listButton2 , button2 )
1758
1772
guiSetText (listWindow , caption )
1759
1773
guiSetVisible (listWindow , true )
1760
1774
listDialog = dialogid
1761
1775
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
1767
1819
end
1768
1820
end
1769
1821
end
0 commit comments