LiquidFenrir

my script

Feb 17th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. --attempt at a keyboard in lpp-3ds
  2. --using HBKBLib (by jbr373) keyboard images
  3.  
  4. white = Color.new(255,255,255)
  5.  
  6. function keyboard(question)
  7.   state = 1
  8.   oldstate = 0
  9.   X, Y, line, column = 0, 0, 0, 0
  10.   oldPos = -1
  11.   offX = 32
  12.   offY = 40
  13.   text = ""
  14.   states = { "abc_lower", "abc_upper", "special"}
  15.   numbers = {"1","2","3","4","5","6","7","8","9","0"}
  16.   line2_abc_lower = {"q","w","e","r","t","y","u","i","o","p"}
  17.   line3_abc_lower = {"a","s","d","f","g","h","j","k","l"}
  18.   line4_abc_lower = {"z","x","c","v","b","n","m"}
  19.   line2_abc_upper = {"Q","W","E","R","T","Y","U","I","O","P"}
  20.   line3_abc_upper = {"A","S","D","F","G","H","J","K","L"}
  21.   line4_abc_upper = {"W","X","C","V","B","N","M"}
  22.   line2_special = {"!",'"',"§","$","%","&","/", "(",")","?"}
  23.   line3_special = {"*","'","<",">","+","[","]","{","}"}
  24.   line4_special = {",",";",".",":","-","_","="}
  25.   image = Screen.loadImage(System.currentDirectory().."/hbkb_abc_lower.png")
  26.   Screen.debugPrint(5,5,question,white,TOP_SCREEN)
  27.   while true do
  28.     Screen.waitVblankStart()
  29.     Screen.refresh()
  30.     if oldstate ~= state then
  31.       Screen.freeImage(image)
  32.       oldstate = state
  33.       image = Screen.loadImage(System.currentDirectory().."/hbkb_"..states[state]..".png")
  34.       Screen.clear(BOTTOM_SCREEN)
  35.       Screen.drawImage(0, 0, image, BOTTOM_SCREEN)
  36.     end
  37.     X, Y = Controls.readTouch()
  38.     if X+Y > 0 then
  39.       line = math.floor(Y/offY)+1
  40.       column = math.floor(X/offX)+1
  41.     else
  42.       line = 0
  43.       column = 0
  44.     end
  45.     if oldPos ~= line+column then
  46.       oldPos = line+column
  47.       if line == 1 then
  48.         text = text..numbers[column]
  49.       elseif line == 2 then
  50.         cLine = _G["line2_"..states[state]]
  51.         text = text..cLine[column]
  52.       elseif line == 3 then
  53.         if column == 10 then
  54.           text = string.sub(text,1,-2)
  55.         else
  56.           cLine = _G["line3_"..states[state]]
  57.           text = text..cLine[column]
  58.         end
  59.       elseif line == 4 then
  60.         if column <= 2 then
  61.           if state == 3 then state = 1 else state = 3 end
  62.         elseif column == 10 then
  63.           text = string.sub(text,1,-2)
  64.         else
  65.           cLine = _G["line4_"..states[state]]
  66.           text = text..cLine[column-2]
  67.         end
  68.       elseif line == 5 then
  69.         if column <= 2 then
  70.           if state == 2 then state = 1 else state = 2 end
  71.           caps = true
  72.         elseif column >= 9 then
  73.           if state == 2 then state = 1 else state = 2 end
  74.           caps = false
  75.         else
  76.           text = text.." "
  77.         end
  78.       elseif line == 6 then
  79.         if column > 5 then
  80.           text = "validate"
  81.         else
  82.           text = "cancel"
  83.         end
  84.       end
  85.       Screen.clear(TOP_SCREEN)
  86.       Screen.debugPrint(5,5,question,white,TOP_SCREEN)
  87.       Screen.debugPrint(5,20,text,white,TOP_SCREEN)
  88.     end
  89.     pad = Controls.read()
  90.     if pad ~= oldPad then
  91.       oldPad = pad
  92.       if Controls.check(pad,KEY_START) then
  93.         Screen.freeImage(image)
  94.         System.exit()
  95.       elseif Controls.check(pad, KEY_B) then
  96.         text = string.sub(text, 1, -2)
  97.       elseif Controls.check(pad, KEY_A) then
  98.         Screen.freeImage(image)
  99.         Screen.clear(BOTTOM_SCREEN)
  100.         return text
  101.       end
  102.     end
  103.   end
  104.   Screen.flip()
  105. end
  106.  
  107. Screen.waitVblankStart()
  108. Screen.refresh()
  109. Screen.debugPrint(5,5,"hello !", white, TOP_SCREEN)
  110. while true do
  111.   Screen.waitVblankStart()
  112.   Screen.refresh()
  113.   Screen.debugPrint(5,20,"Press Start to quit, or A for magic!", white, TOP_SCREEN)
  114.   pad = Controls.read()
  115.   if oldPad ~= pad then
  116.     if Controls.check(pad,KEY_START) then
  117.       System.exit()
  118.     elseif Controls.check(pad,KEY_A) then
  119.       Screen.clear(TOP_SCREEN)
  120.       word = keyboard("What's your name?")
  121.       Screen.clear(TOP_SCREEN)
  122.       Screen.debugPrint(5,5,"hello "..word.." !", white, TOP_SCREEN)
  123.     end
  124.   end
  125.   Screen.flip()
  126. end
Advertisement
Add Comment
Please, Sign In to add comment