Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
135 changes: 135 additions & 0 deletions [admin]/admin/client/admin_gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
**************************************]]
_guiprotected = {}

local lists = {}

function guiCreateHeader ( x, y, w, h, text, relative, parent )
local header = guiCreateLabel ( x, y, w, h, text, relative, parent )
if ( header ) then
Expand Down Expand Up @@ -51,3 +53,136 @@ function guiCreateButton ( x, y, w, h, text, relative, parent, right )
end
return false
end

function guiCreateList(x, y, w, h, tabHeight, header, relative, parent, right)
local list = guiCreateButton(x, y, w, h, header, relative, parent, right)

local parentWidth, parentHeight = guiGetSize(parent, false)

local absoluteWidth = parentWidth * w
local absoluteHeight = parentHeight * h

local dropDown = guiCreateStaticImage(absoluteWidth - 20, 0, 20, 20, "client\\images\\dropdown.png", false, list)
guiSetProperty(dropDown, 'AlwaysOnTop', 'True')

addEventHandler('onClientGUIClick', dropDown, function()
guiListSetVisible(list, true)
end, false)

local bg = guiCreateButton(x, y, w, tabHeight, '', relative, parent)
guiSetProperty(bg, 'AlwaysOnTop', 'True')
guiSetVisible(bg, false)

local edit = guiCreateEdit(0, 0, absoluteWidth - 20, 20, '', false, bg)
guiSetProperty(edit, 'AlwaysOnTop', 'True')

addEventHandler('onClientGUIChanged', edit, function()
guiListLoadItems(list)
end)

local searchIcon = guiCreateStaticImage(absoluteWidth - 40, 0, 20, 20, "client\\images\\search.png", false, edit)
guiSetEnabled(searchIcon, false)
guiSetProperty(searchIcon, 'AlwaysOnTop', 'True')

local close = guiCreateButton(absoluteWidth-20, 0, 20, 20, 'X', false, bg)
guiSetProperty(close, 'AlwaysOnTop', 'True')
guiSetAlpha(close, 1)

addEventHandler('onClientGUIClick', close, function()
guiListSetVisible(list, false)
end, false)

local gridlist = guiCreateGridList(0, 0, 1, 1, true, bg)

addEventHandler('onClientGUIDoubleClick', gridlist, function()
local callback = lists[list].callback
if (type(callback) == 'function') then
local row = guiGridListGetSelectedItem(gridlist)
local data = guiGridListGetItemData(gridlist, row, 1)
local text = guiGridListGetItemText(gridlist, row, 1)
if (row > -1) then
callback(data, text)
guiListSetVisible(list, false)
end
end
end, false)


lists[list] = {
bg = bg,
edit = edit,
gridlist = gridlist,
items = {},
callback = function() end,
}

return list
end

function guiListSetVisible(list, state)
if lists[list] then
guiSetVisible(lists[list].bg, state)
if state then
guiFocus(lists[list].edit)
end
return true
end
return false
end

function guiListSetItems(list, items)
if lists[list] then
lists[list].items = items
guiListLoadItems(list)
return true
end
return false
end

function guiListSetCallBack(list, callback)
if lists[list] then
lists[list].callback = callback
return true
end
return false
end

function guiListSetColumns(list, columns)
if lists[list] then
for _, v in ipairs(columns) do
guiGridListAddColumn(lists[list].gridlist, v.text, v.width)
end
return true
end
return false
end

function guiListLoadItems(list)
local listData = lists[list]
if listData then
local filter = guiGetText(listData.edit)
guiGridListClear(listData.gridlist)
for k, v in ipairs(listData.items) do
if (v.text:lower():find(filter:lower())) then
local row = guiGridListAddRow(listData.gridlist)
guiGridListSetItemText(listData.gridlist, row, 1, tostring ( v.text ), false, false )
guiGridListSetItemData(listData.gridlist, row, 1, tostring ( v.data ) )
end
end
return true
end
return false
end

addEventHandler('onClientGUIClick', guiRoot, function(button)
if (button == 'left') then
local parent = getElementParent(source)
if parent then
for list in pairs(lists) do
if guiGetVisible(list) and (parent ~= list) and (getElementParent(parent) ~= getElementParent(list)) then
guiListSetVisible(list, false)
end
end
end
end
end)
Loading