Advertisement
xerpi

Untitled

Apr 11th, 2011
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. seleccion = image.load("imgXkey/cuadrado.png")
  2. tiempo = timer.new()
  3.  
  4. minus = {
  5. {"q","w","e","r","t","y","u","i","o","p"},
  6. {"a","s","d","f","g","h","j","k","l","ñ"},
  7. {"mayus","z","x","c","v","b","n","m","esp","OK"},
  8. img  = image.load("imgXkey/tecladominus.png")
  9. }
  10. mayus= {
  11. {"Q","W","E","R","T","Y","U","I","O","P"},
  12. {"A","S","D","F","G","H","J","K","L","Ñ"},
  13. {"num","Z","X","C","V","B","N","M","esp","OK"},
  14. img = image.load("imgXkey/tecladomayus.png")
  15. }
  16. num= {
  17. {"0","1","2","3","4","5","6","7","8","9"},
  18. {".",",","-","_","(",")","[","]","!","?"},
  19. {"minus","á","é","í","ó","ú","`","´","esp","OK"},
  20. img = image.load("imgXkey/tecladosimb.png")
  21. }
  22. peke= {
  23. {"7","8","9"},
  24. {"4","5","6"},
  25. {"1","2","3"},
  26. {"-","0","."},
  27. img = image.load("imgXkey/tecladopeke.png")
  28. }
  29.  
  30. function xkeyboard(Xteclado,Yteclado,Xtexto,Ytexto,texto,comentario,tipo)
  31. local tmp = screen.toimage()
  32. local x=1
  33. local y=1
  34. local tecladoactual=minus
  35. if tipo == 1 then tecladoactual = peke end
  36. if texto == nil then texto = "" end
  37. if comentario == nil then comentario = "" end
  38. texto = tostring(texto)
  39. local pos = #texto
  40.  
  41. function añadirletra(string,pos,letra)
  42. if pos < #string then return string.sub(string,1,pos)..letra..string.sub(string,pos+1,#string)
  43. elseif pos == #string then return string..letra end
  44. end
  45.  
  46. tiempo:start()
  47. while true do
  48. controls.read()
  49. tmp:blit(0,0)
  50.  
  51. if controls.press("right") then x=x+1 end
  52. if controls.press("left") then x=x-1 end
  53. if controls.press("up") then y=y-1 end
  54. if controls.press("down") then y=y+1 end
  55. if controls.press("r") and pos < #texto then pos = pos + 1 end
  56. if controls.press("l") and pos >0 and #texto >0 then pos = pos - 1 end
  57.  
  58. if tipo == nil then
  59. if y>=4 then y=1 end
  60. if y<=0 then y=3 end
  61. if x>=11 then x=1 end
  62. if x<=0 then x=10 end
  63. elseif tipo == 1 then
  64. if y>=5 then y=1 end
  65. if y<=0 then y=3 end
  66. if x>=4 then x=1 end
  67. if x<=0 then x=1 end
  68. end
  69.  
  70. if controls.press("cross") then
  71.     if tecladoactual[y][x] != "mayus" and tecladoactual[y][x] != "minus" and tecladoactual[y][x] != "num" and
  72.     tecladoactual[y][x] != "esp" and tecladoactual[y][x] != "OK" then
  73.         if tipo == nil then texto = añadirletra(texto,pos,tecladoactual[y][x]); pos = pos+1; end
  74.         if tipo == 1 and tecladoactual[y][x] == "-" and #texto == 0 then texto = "-"; pos = pos+1;
  75.         elseif tipo == 1 and tecladoactual[y][x] != "-" then texto = añadirletra(texto,pos,tecladoactual[y][x]); pos = pos+1;
  76.         elseif tipo == 1 and tecladoactual[y][x] == "." and string.match(texto,".") == nil then añadirletra(texto,pos,".") ; pos = pos+1; end end
  77.     if tecladoactual[y][x] == "mayus" then tecladoactual = num
  78.     elseif tecladoactual[y][x] == "num" then tecladoactual = minus
  79.     elseif tecladoactual[y][x] == "minus" then tecladoactual = mayus
  80.     elseif tecladoactual[y][x] == "OK" then break
  81.     elseif tecladoactual[y][x] == "esp" then añadirletra(texto,pos," "); pos = pos +1 end
  82. end
  83.  
  84. if controls.cross() then screen.print(Xtexto+screen.textwidth(comentario..string.sub(texto,1,pos)),Ytexto-1,"|") end
  85. if controls.press("square") and #texto > 0 and pos >0 then texto = string.sub(texto,1,pos-1)..string.sub(texto,pos+1,#texto); pos = pos -1; end
  86. if controls.press("triangle") and tipo == nil then texto = añadirletra(texto,pos," "); pos = pos +1 end
  87. if controls.press("circle") then texto = "" pos = 0 end
  88. if controls.press("select") then
  89.     if tecladoactual ==  mayus then tecladoactual = num
  90.     elseif tecladoactual == num then tecladoactual = minus
  91.     elseif tecladoactual == minus then tecladoactual = mayus end   
  92. end
  93.  
  94. if math.abs(controls.analogx())>20 then Xteclado = Xteclado + controls.analogx()/15 end
  95. if math.abs(controls.analogy())>20 then Yteclado = Yteclado + controls.analogy()/15 end
  96.  
  97. tecladoactual.img:blit(Xteclado,Yteclado)
  98. seleccion:blit(Xteclado+(21*x)-10,Yteclado+(21*y)-(9+y))
  99. screen.print(Xtexto,Ytexto,comentario..texto)
  100.  
  101. if controls.press("start") then
  102.          tmp:free()
  103.          break       
  104. end
  105.  
  106. if not controls.cross() and tiempo:time() >= 0 and tiempo:time() < 500 then
  107.     screen.print(Xtexto+screen.textwidth(comentario..string.sub(texto,1,pos)),Ytexto-1,"|")
  108. elseif tiempo:time() >= 1000 then tiempo:reset()
  109. end
  110.  
  111. screen.flip()
  112. end
  113. x=nil; y=nil; tecladoactual=nil; pos=nil; tiempo:free();
  114. if tipo == nil then return texto;
  115. elseif tipo == 1 then return tonumber(texto);
  116. end
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement