fileselect={ file_list={}, selected=1, title=nil, old_update=nil, return_function=nil, old_mx=-1, old_my=-1, show=function(title, retfun, extension) fileselect.file_list = {} for dir in io.popen([[ls data | grep ]] .. extension):lines() do fileselect.file_list[#fileselect.file_list+1] = dir end fileselect.selected=1 fileselect.title=title fileselect.old_update=update update=fileselect.update fileselect.return_function=retfun if fileselect.value==nil then fileselect.value="" end end, update=function() draw.rectf(10,10, 140, 120,5) draw.rect(10,10, 140, 120,8) if fileselect.title then draw.text(fileselect.title,20,13,8) end draw.rectf(20,20, 120, 100,6) local i = 22 for k,dir in pairs(fileselect.file_list) do local color=8 if k==fileselect.selected then draw.rectf(20,i-1, 120, 8,11) color=15 end draw.text(dir, 23, i, color) i=i+7 end draw.rect(20,20, 120, 100,8) local mx,my=mouse.pos() if (mx~=fileselect.old_mx or my~=fileselect.old_my) then fileselect.old_mx,fileselect.old_my=mx,my if mx>20 and mx<140 and my>20 and my<120 then local y = math.floor((my-21)/7)+1 if (y<=#fileselect.file_list) then fileselect.selected = y end end end if mouse.press(mouse.LEFT) then if mx>20 and mx<140 and my>20 and my<120 then local y = math.floor((my-21)/7)+1 if (y<=#fileselect.file_list) then fileselect.selected = y update=fileselect.old_update fileselect.return_function(fileselect.file_list[fileselect.selected]) end end end -- if textbox.value then -- draw.text(textbox.value,43,73) -- if (math.floor(time()*4)%2)==0 then -- draw.text("_",43+#textbox.value*4,73) -- end -- end -- local tecla=key.press() if tecla==key.DOWN then if fileselect.selected < #fileselect.file_list then fileselect.selected = fileselect.selected + 1 end elseif tecla==key.UP then if fileselect.selected > 1 then fileselect.selected = fileselect.selected - 1 end -- elseif tecla==KEY_BACKSPACE then -- textbox.value=string.sub(textbox.value,1,-2) elseif tecla==key.RETURN then update=fileselect.old_update fileselect.return_function(fileselect.file_list[fileselect.selected]) end end }