Files
jailsadventure2/data/textbox.lua

41 lines
1.3 KiB
Lua

keyvalues="000abcdefghijklmnopqrstuvwxyz1234567890"
textbox={
value=nil,
title=nil,
old_update=nil,
return_function=nil,
show=function(title, retfun, default_value)
textbox.title=title
textbox.value=default_value
textbox.old_update=update
update=textbox.update
textbox.return_function=retfun
if textbox.value==nil then textbox.value="" end
end,
update=function()
draw.rectf(20,50, 120, 40,6)
draw.rect(20,50, 120, 40,8)
if textbox.title then draw.text(textbox.title,30,55,8) end
draw.rect(40,70, 80, 11,8)
if textbox.value then
draw.text(textbox.value,43,73,8)
if (math.floor(sys.time()*4)%2)==0 then
draw.text("_",43+#textbox.value*4,73,8)
end
end
local tecla=key.press()
if tecla>=4 and tecla<=39 then
textbox.value=textbox.value..string.sub(keyvalues,tecla,tecla)
elseif tecla==key.PERIOD then
textbox.value=textbox.value.."."
elseif tecla==key.BACKSPACE then
textbox.value=string.sub(textbox.value,1,-2)
elseif tecla==key.RETURN then
update=textbox.old_update
textbox.return_function(textbox.value)
end
end
}