- [NEW] Ara es pot seleccionar el mapa a editar de un llistat, en compte de tindre que escriure el nom de l'arxiu a mà
- [WRK] Treballant en La Vella
This commit is contained in:
78
data/fileselect.lua
Normal file
78
data/fileselect.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
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()
|
||||
rectfill(10,10, 150, 130,5)
|
||||
rect(10,10, 150, 130,8)
|
||||
if fileselect.title then prnt(fileselect.title,20,13) end
|
||||
rectfill(20,20, 140, 120,6)
|
||||
local i = 22
|
||||
for k,dir in pairs(fileselect.file_list) do
|
||||
color(8)
|
||||
if k==fileselect.selected then
|
||||
rectfill(20,i-2, 140, i+6,11)
|
||||
color(15)
|
||||
end
|
||||
prnt(dir, 23, i)
|
||||
i=i+7
|
||||
end
|
||||
rect(20,20, 140, 120,8)
|
||||
|
||||
local mx,my=mouse()
|
||||
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 mbtnp(1) 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
|
||||
-- prnt(textbox.value,43,73)
|
||||
-- if (math.floor(time()*4)%2)==0 then
|
||||
-- prnt("_",43+#textbox.value*4,73)
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
local tecla=btnp()
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user