MindenCucc

ASD-Board QWERTY touchscreen keyboard API

Mar 21st, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.78 KB | None | 0 0
  1.    
  2.  
  3.     -- MindenCucc QWERTZ keyboard API!
  4.     -- For CC 1.51+ MC 1.5+
  5.     -- Version 0.07
  6.      
  7.     -- Declare
  8.     btns={}
  9.     selectedINDEX=nil
  10.     selectedInput="term"
  11.     keyboardInput=""
  12.      
  13.     -- asd Button CLick (BCL) API
  14.     -- REALLY HUGE table with fancy crap :D (smallest adv. button API xD)
  15.     button={
  16.             createINDEX=(
  17.                     function(INDEX)
  18.                         if btns[INDEX]==nil then
  19.                             btns[INDEX]={}
  20.                         end
  21.                     end),
  22.             deleteINDEX=(
  23.                     function(INDEX)
  24.                             if btns[INDEX] ~= nil then -- If exist, delete it
  25.                                     btns[INDEX]=nil
  26.                             end
  27.                     end),
  28.             createButton=(
  29.                     function(INDEX, Ax1, Ax2, Ay1, Ay2, txt, Afunc, Aargs, Atoggle, AtxtColor, Acolor, Aret)
  30.                             btns[INDEX][txt]={}
  31.                             btns[INDEX][txt].x1=Ax1
  32.                             btns[INDEX][txt].x2=Ax2
  33.                             btns[INDEX][txt].y1=Ay1
  34.                             btns[INDEX][txt].y2=Ay2
  35.                             btns[INDEX][txt].debug=txt
  36.                             btns[INDEX][txt].args=Aargs
  37.                             if AtxtColor ~= nil then
  38.                                     btns[INDEX][txt].txtColor = AtxtColor
  39.                             else
  40.                                     btns[INDEX][txt].txtColor = colors.white
  41.                             end
  42.                             btns[INDEX][txt].func=Afunc --Implemented! YAAY! ^^ use funcName, {arg1, arg2...} :D
  43.                             if      Atoggle then
  44.                                     btns[INDEX][txt].ret=Aret or false -- Return state, ignored if toggle is false or nil CURRENTLY UNUSED!
  45.                                     btns[INDEX][txt].color=colors.red
  46.                                     btns[INDEX][txt].state=false
  47.                             else
  48.                                     btns[INDEX][txt].ret=false
  49.                                     btns[INDEX][txt].color=Acolor or colors.gray
  50.                             end
  51.                                     btns[INDEX][txt].tglable=Atoggle or false -- Switch or button?
  52.                     end),
  53.             deleteButton=(
  54.                     function(INDEX, txt)
  55.                             if btns[INDEX][txt] ~= nil then -- If exist, delete it
  56.                                     btns[INDEX][txt]=nil
  57.                                     return true
  58.                             else
  59.                                     return false
  60.                             end
  61.                     end),
  62.             drawButtons=(
  63.                     function(INDEX, bgColor, heading, headingColor)
  64.                             if bgColor == nil then
  65.                                     bgColor = colors.cyan -- Color-Ma-TIC asdboard:65: attempt to perform arithmetic __sub on nil and nil :D
  66.                             end
  67.                             if heading == nil then
  68.                                     heading = ""
  69.                             end
  70.                             termX, termY = term.getSize()
  71.                             for  asdX = 1, termX do
  72.                                     for asdY = 1, termY do
  73.                                             term.setBackgroundColor(bgColor)
  74.                                             term.setCursorPos(asdX, asdY)
  75.                                             term.write(" ")
  76.                                     end
  77.                             end
  78.                             if headingColor == nil then
  79.                                     headingColor = colors.white
  80.                             end
  81.                             term.setTextColor(headingColor)
  82.                             term.setCursorPos(termX/2 - string.len(heading)/2, 1)
  83.                             term.write(heading)
  84.                             for btn, data in pairs(btns[INDEX]) do
  85.                                     for px=btns[INDEX][btn].x1, btns[INDEX][btn].x2 do
  86.                                             for py=btns[INDEX][btn].y1, btns[INDEX][btn].y2 do -- fancy_crap() end
  87.                                                     term.setBackgroundColor(btns[INDEX][btn].color)
  88.                                                     term.setCursorPos(px,py)
  89.                                                     term.write(" ")
  90.                                             end
  91.                                     end
  92.                                     term.setTextColor(btns[INDEX][btn].txtColor)
  93.                                     term.setCursorPos(math.floor(((btns[INDEX][btn].x1+btns[INDEX][btn].x2)/2) - (string.len(btns[INDEX][btn].debug)/2))+1, math.floor(btns[INDEX][btn].y1+btns[INDEX][btn].y2)/2) -- FANCY CRAP!
  94.                                     term.write(btns[INDEX][btn].debug)
  95.                             end
  96.                             term.setTextColor(headingColor)
  97.                     end),
  98.             setState=(
  99.                     function(INDEX, txt, value)
  100.                             btns[INDEX][txt].state=value
  101.                     end),
  102.             doButton=(
  103.                     function(INDEX, mousex, mousey)
  104.                             for btn, btnData in pairs(btns[INDEX]) do
  105.                                     if mousex >= btns[INDEX][btn].x1 and mousex <= btns[INDEX][btn].x2 then
  106.                                             if mousey >= btns[INDEX][btn].y1 and mousey <= btns[INDEX][btn].y2 then
  107.                                                     if btns[INDEX][btn].state == true then
  108.                                                             btns[INDEX][btn].state=false
  109.                                                             btns[INDEX][btn].color=colors.red
  110.                                                     elseif btns[INDEX][btn].state == false then
  111.                                                             btns[INDEX][btn].state=true
  112.                                                             btns[INDEX][btn].color=colors.lime
  113.                                                     end -- FIXED! YAAY!
  114.                                                     if btns[INDEX][btn].args == nil then
  115.                                                             btns[INDEX][btn].func()
  116.                                                     else
  117.                                                             btns[INDEX][btn].func(btns[INDEX][btn].args) --Implemented! :D but buggy :(
  118.                                                     end
  119.                                             end
  120.                                     end
  121.                             end
  122.                     end),
  123.             cleanUp=( -- WARNING! TOO FANCY!
  124.                     function(confirm)
  125.                             if confirm then
  126.                                     btns=nil
  127.                                     button=nil
  128.                                     os.unloadAPI("asdboard")
  129.                             else
  130.                                     error("DAFUQ ARE YOU PLAYING WITH THIS???", 2)
  131.                             end
  132.                     end)
  133.     }
  134.      
  135.      -- END BCL
  136.      
  137.      -- MAIN FUNCTIONS
  138.      
  139.      
  140.      
  141.     function setUp()
  142.             button.createINDEX("startup")
  143.                     button.createButton("startup", 3, 15, 3, 5, "Start", selectGUI, nil, false, colors.gray, colors.cyan, false)
  144.                     button.createButton("startup", 3, 15, 7, 9, "Manual select", selectManual_func, nil, true, colors.gray, nil, false)
  145.                     button.createButton("startup", 3, 15, 11, 13, "List inputs", listInputGUI, nil, false, colors.gray, colors.cyan, false)
  146.                     button.createButton("startup", 3, 15, 17, 19, "Cancel", exitProgram, nil, false, colors.gray, colors.purple, false)
  147.             button.createINDEX("keyboard")
  148.     end
  149.      
  150.     function selectedPeripheral(asd)
  151.             selectedInput=asd
  152.     end
  153.      
  154.     function listInputGUI()
  155.             button.createINDEX("inputgui")
  156.             local mon=listInputs()
  157.             for i=1,#mon do
  158.                     button.createButton("inputgui", 3, 15, i+3, i+3, mon[i], selectedPheripheral, mon[i], false, colors.gray, colors.cyan, false)
  159.             end
  160.             button.createButton("inputgui", 3, 15, #mon+4, #mon+4, "term", selectedPerpiheral, "term", false, colors.black, colors.yellow, false)
  161.             button.drawButtons("inputgui", colors.gray, "Select input device", colors.white)
  162.             local event, asd1, asd2, asd3 = os.pullEvent()
  163.             if event == "monitor_touch" and selectedInput == asd1 then
  164.                     button.doButton(selectedINDEX, asd2, asd3)
  165.             elseif event == "mouse_click" then
  166.                     button.doButton(selectedINDEX, asd2, asd3)
  167.             else
  168.                     write("CRASH!")
  169.                     sleep(.5)
  170.             end
  171.             sleep(.1)
  172.     end
  173.      
  174.     function getTypes(sType)
  175.     local fancyCrap = {}
  176.     local net = {}
  177.     local ret = {}
  178.     if sType == nil or type(sType) ~= "string" then
  179.       error("Cannot parse input.", 1)
  180.     else
  181.       net = peripheral.getNames()
  182.       for asdX, valX in ipairs(net) do
  183.        for netX = 1, #net do
  184.         if peripheral.getType(valX) == sType then
  185.              retval=true
  186.         else
  187.              retval=false
  188.         end
  189.        end
  190.        if retval then
  191.         table.insert(ret, valX)
  192.        end
  193.       end
  194.       return ret
  195.     end
  196.     end
  197.      
  198.     function listInputs()
  199.             local monitors = getTypes("monitor")
  200.             return monitors
  201.     end
  202.      
  203.     function exitProgram()
  204.             startupRunning=false
  205.             term.restore()
  206.     end
  207.      
  208.     function returnText()
  209.             editing=false
  210.             return keyboardInput
  211.     end
  212.      
  213.     function selectManual_func()
  214.             manualSelect=true
  215.             button.setState("startup", "Manual select", true)
  216.             button.drawButtons("startup", colors.gray, "ASD-Board", colors.white)
  217.             term.setCursorPos(3, 10)
  218.             term.write("Click on that screen that you wanna use.")
  219.             term.setBackgroundColor(colors.gray)
  220.             local event, asd1, asd2, asd3 = os.pullEvent()
  221.             if event == "monitor_touch" or event == "mouse_click" and manualSelect == true then
  222.                     if asd1 == 1 or asd1 == 2 or asd1 == 3 then
  223.                     selectedInput = term
  224.                     asdD=term
  225.                     else
  226.                     selectedInput = asd1
  227.                     asdD=peripheral.wrap(asd1)
  228.                     end
  229.                     asd1X, asd1Y=asdD.getSize()
  230.                     for xX=1,asd1X do
  231.                             for xY=1, asd1Y do
  232.                                     asdD.setBackgroundColor(colors.gray)
  233.                                     asdD.setCursorPos(xX, xY)
  234.                                     asdD.write(" ")
  235.                             end
  236.                     end
  237.                     asdD.setCursorPos(2,3)
  238.                     asdD.write("Input selected :D")
  239.                     manualSelect = false
  240.             else
  241.                     write("CRASH!")
  242.                     sleep(.5)
  243.             end
  244.             sleep(.1)
  245.     end
  246.      
  247.     function input(txt)
  248.             keyboardInput=keyboardInput..txt
  249.             if selectedInput ~= "term" then
  250.                     sasd=peripheral.wrap(selectedInput)
  251.             else
  252.                     sasd=term
  253.             end
  254.             sasd.setCursorPos(10,3)
  255.             sasd.write(keyboardInput)
  256.     end
  257.      
  258.     function redrawKeyboard()
  259.             button.drawButtons(selectedINDEX, colors.black, "INPUT KEYBOARD", colors.white)
  260.             term.setCursorPos(10,3)
  261.             term.setTextColor(colors.white)
  262.             term.write(keyboardInput)
  263.     end
  264.     function redrawText()
  265.             term.setCursorPos(10,3)
  266.             term.setTextColor(colors.white)
  267.             term.write(keyboardInput)
  268.     end
  269.     function runKeyBoardLOOP()
  270.             while editing do
  271.                     evt, asd1, asd2, asd3 = os.pullEvent()
  272.                     if evt == "monitor_touch" and selectedInput == asd1 then
  273.                             sleep(.1)
  274.                             button.doButton(selectedINDEX, asd2, asd3)
  275.                             redrawText()
  276.                     elseif evt == "mouse_click" and selectedInput == "term" then
  277.                             sleep(.1)
  278.                             button.doButton(selectedINDEX, asd2, asd3)
  279.                             redrawText()
  280.                     elseif evt == "char" then
  281.                             input(asd1)
  282.                     else
  283.                             peripheral.call(selectedInput, "write", "CRASH")
  284.                             sleep(.5)
  285.                             redrawKeyboard()
  286.                     end
  287.             end
  288.     end
  289.      
  290.     function void()
  291.     write("")
  292.     end
  293.      
  294.     function switchCase(as)
  295.             selectedINDEX=as
  296.             redrawKeyboard()
  297.     end
  298.     function runKeyBoard()
  299.             button.createINDEX("keyboard")
  300.             button.createINDEX("keyboard_shifted")
  301.             button.createButton("keyboard", 2, 4, 5, 7, "1", input, "1", false, colors.white, colors.gray, false)
  302.             button.createButton("keyboard", 6, 8, 5, 7, "2", input, "2", false, colors.white, colors.gray, false)
  303.             button.createButton("keyboard", 10, 12, 5, 7, "3", input, "3", false, colors.white, colors.gray, false)
  304.             button.createButton("keyboard", 14, 16, 5, 7, "4", input, "4", false, colors.white, colors.gray, false)
  305.             button.createButton("keyboard", 18, 20, 5, 7, "5", input, "5", false, colors.white, colors.gray, false)
  306.             button.createButton("keyboard", 22, 24, 5, 7, "6", input, "6", false, colors.white, colors.gray, false)
  307.             button.createButton("keyboard", 26, 28, 5, 7, "7", input, "7", false, colors.white, colors.gray, false)
  308.             button.createButton("keyboard", 30, 32, 5, 7, "8", input, "8", false, colors.white, colors.gray, false)
  309.             button.createButton("keyboard", 34, 36, 5, 7, "9", input, "9", false, colors.white, colors.gray, false)
  310.             button.createButton("keyboard", 38, 40, 5, 7, "0", input, "0", false, colors.white, colors.gray, false)
  311.             button.createButton("keyboard", 42, 44, 5, 7, "-", input, "-", false, colors.white, colors.gray, false)
  312.             button.createButton("keyboard", 46, 48, 5, 7, "=", input, "=", false, colors.white, colors.gray, false)
  313.             button.createButton("keyboard", 2, 4, 9, 11, "q", input, "q", false, colors.white, colors.gray, false)
  314.             button.createButton("keyboard", 6, 8, 9, 11, "w", input, "w", false, colors.white, colors.gray, false)
  315.             button.createButton("keyboard", 10, 12, 9, 11, "e", input, "e", false, colors.white, colors.gray, false)
  316.             button.createButton("keyboard", 14, 16, 9, 11, "r", input, "r", false, colors.white, colors.gray, false)
  317.             button.createButton("keyboard", 18, 20, 9, 11, "t", input, "t", false, colors.white, colors.gray, false)
  318.             button.createButton("keyboard", 22, 24, 9, 11, "y", input, "y", false, colors.white, colors.gray, false)
  319.             button.createButton("keyboard", 26, 28, 9, 11, "u", input, "u", false, colors.white, colors.gray, false)
  320.             button.createButton("keyboard", 30, 32, 9, 11, "i", input, "i", false, colors.white, colors.gray, false)
  321.             button.createButton("keyboard", 34, 36, 9, 11, "o", input, "o", false, colors.white, colors.gray, false)
  322.             button.createButton("keyboard", 38, 40, 9, 11, "p", input, "p", false, colors.white, colors.gray, false)
  323.             button.createButton("keyboard", 42, 44, 9, 11, "[", input, "[", false, colors.white, colors.gray, false)
  324.             button.createButton("keyboard", 46, 48, 9, 11, "]", input, "]", false, colors.white, colors.gray, false)
  325.             button.createButton("keyboard", 2, 4, 13, 15, "a", input, "a", false, colors.gray, colors.white, false)
  326.             button.createButton("keyboard", 6, 8, 13, 15, "s", input, "s", false, colors.gray, colors.white, false)
  327.             button.createButton("keyboard", 10, 12, 13, 15, "d", input, "d", false, colors.gray, colors.white, false)
  328.             button.createButton("keyboard", 14, 16, 13, 15, "f", input, "f", false, colors.white, colors.gray, false)
  329.             button.createButton("keyboard", 18, 20, 13, 15, "g", input, "g", false, colors.white, colors.gray, false)
  330.             button.createButton("keyboard", 22, 24, 13, 15, "h", input, "h", false, colors.white, colors.gray, false)
  331.             button.createButton("keyboard", 26, 28, 13, 15, "j", input, "j", false, colors.white, colors.gray, false)
  332.             button.createButton("keyboard", 30, 32, 13, 15, "k", input, "k", false, colors.white, colors.gray, false)
  333.             button.createButton("keyboard", 34, 36, 13, 15, "l", input, "l", false, colors.white, colors.gray, false)
  334.             button.createButton("keyboard", 38, 40, 13, 15, ";", input, ";", false, colors.white, colors.gray, false)
  335.             button.createButton("keyboard", 42, 44, 13, 15, "'", input, "'", false, colors.white, colors.gray, false)
  336.             button.createButton("keyboard", 46, 48, 13, 15, "\\", input, "\\", false, colors.white, colors.gray, false)
  337.             button.createButton("keyboard", 2, 4, 17, 19, "z", input, "z", false, colors.white, colors.gray, false)
  338.             button.createButton("keyboard", 6, 8, 17, 19, "x", input, "x", false, colors.white, colors.gray, false)
  339.             button.createButton("keyboard", 10, 12, 17, 19, "c", input, "c", false, colors.white, colors.gray, false)
  340.             button.createButton("keyboard", 14, 16, 17, 19, "v", input, "v", false, colors.white, colors.gray, false)
  341.             button.createButton("keyboard", 18, 20, 17, 19, "b", input, "b", false, colors.white, colors.gray, false)
  342.             button.createButton("keyboard", 22, 24, 17, 19, "n", input, "n", false, colors.white, colors.gray, false)
  343.             button.createButton("keyboard", 26, 28, 17, 19, "m", input, "m", false, colors.white, colors.gray, false)
  344.             button.createButton("keyboard", 30, 32, 17, 19, ",", input, ",", false, colors.white, colors.gray, false)
  345.             button.createButton("keyboard", 34, 36, 17, 19, ".", input, ".", false, colors.white, colors.gray, false)
  346.             button.createButton("keyboard", 38, 40, 17, 19, "/", input, "/", false, colors.white, colors.gray, false)
  347.             button.createButton("keyboard", 2, 9, 2, 4, "RETURN", returnText, nil, false, colors.gray, colors.white, false)
  348.             button.createButton("keyboard", 42, 44, 17, 19, "SPC", input, " ", false, colors.gray, colors.white, false)
  349.             button.createButton("keyboard", 46, 48, 17, 19, "^", switchCase, "keyboard_shifted", false, colors.gray, colors.white, false)
  350.             button.createButton("keyboard_shifted", 2, 4, 5, 7, "!", input, "!", false, colors.white, colors.gray, false)
  351.             button.createButton("keyboard_shifted", 6, 8, 5, 7, "@", input, "@", false, colors.white, colors.gray, false)
  352.             button.createButton("keyboard_shifted", 10, 12, 5, 7, "#", input, "#", false, colors.white, colors.gray, false)
  353.             button.createButton("keyboard_shifted", 14, 16, 5, 7, "$", input, "$", false, colors.white, colors.gray, false)
  354.             button.createButton("keyboard_shifted", 18, 20, 5, 7, "%", input, "%", false, colors.white, colors.gray, false)
  355.             button.createButton("keyboard_shifted", 22, 24, 5, 7, " ^ ", input, "^", false, colors.white, colors.gray, false)
  356.             button.createButton("keyboard_shifted", 26, 28, 5, 7, "&", input, "&", false, colors.white, colors.gray, false)
  357.             button.createButton("keyboard_shifted", 30, 32, 5, 7, "*", input, "*", false, colors.white, colors.gray, false)
  358.             button.createButton("keyboard_shifted", 34, 36, 5, 7, "(", input, "(", false, colors.white, colors.gray, false)
  359.             button.createButton("keyboard_shifted", 38, 40, 5, 7, ")", input, ")", false, colors.white, colors.gray, false)
  360.             button.createButton("keyboard_shifted", 42, 44, 5, 7, "_", input, "_", false, colors.white, colors.gray, false)
  361.             button.createButton("keyboard_shifted", 46, 48, 5, 7, "+", input, "+", false, colors.white, colors.gray, false)
  362.             button.createButton("keyboard_shifted", 2, 4, 9, 11, "Q", input, "Q", false, colors.white, colors.gray, false)
  363.             button.createButton("keyboard_shifted", 6, 8, 9, 11, "W", input, "w", false, colors.white, colors.gray, false)
  364.             button.createButton("keyboard_shifted", 10, 12, 9, 11, "E", input, "E", false, colors.white, colors.gray, false)
  365.             button.createButton("keyboard_shifted", 14, 16, 9, 11, "R", input, "R", false, colors.white, colors.gray, false)
  366.             button.createButton("keyboard_shifted", 18, 20, 9, 11, "T", input, "T", false, colors.white, colors.gray, false)
  367.             button.createButton("keyboard_shifted", 22, 24, 9, 11, "Y", input, "Y", false, colors.white, colors.gray, false)
  368.             button.createButton("keyboard_shifted", 26, 28, 9, 11, "U", input, "U", false, colors.white, colors.gray, false)
  369.             button.createButton("keyboard_shifted", 30, 32, 9, 11, "I", input, "I", false, colors.white, colors.gray, false)
  370.             button.createButton("keyboard_shifted", 34, 36, 9, 11, "O", input, "O", false, colors.white, colors.gray, false)
  371.             button.createButton("keyboard_shifted", 38, 40, 9, 11, "P", input, "P", false, colors.white, colors.gray, false)
  372.             button.createButton("keyboard_shifted", 42, 44, 9, 11, "{", input, "{", false, colors.white, colors.gray, false)
  373.             button.createButton("keyboard_shifted", 46, 48, 9, 11, "}", input, "}", false, colors.white, colors.gray, false)
  374.             button.createButton("keyboard_shifted", 2, 4, 13, 15, "A", input, "A", false, colors.gray, colors.white, false)
  375.             button.createButton("keyboard_shifted", 6, 8, 13, 15, "S", input, "S", false, colors.gray, colors.white, false)
  376.             button.createButton("keyboard_shifted", 10, 12, 13, 15, "D", input, "D", false, colors.gray, colors.white, false)
  377.             button.createButton("keyboard_shifted", 14, 16, 13, 15, "F", input, "F", false, colors.white, colors.gray, false)
  378.             button.createButton("keyboard_shifted", 18, 20, 13, 15, "G", input, "G", false, colors.white, colors.gray, false)
  379.             button.createButton("keyboard_shifted", 22, 24, 13, 15, "H", input, "H", false, colors.white, colors.gray, false)
  380.             button.createButton("keyboard_shifted", 26, 28, 13, 15, "J", input, "J", false, colors.white, colors.gray, false)
  381.             button.createButton("keyboard_shifted", 30, 32, 13, 15, "K", input, "K", false, colors.white, colors.gray, false)
  382.             button.createButton("keyboard_shifted", 34, 36, 13, 15, "L", input, "L", false, colors.white, colors.gray, false)
  383.             button.createButton("keyboard_shifted", 38, 40, 13, 15, ":", input, ":", false, colors.white, colors.gray, false)
  384.             button.createButton("keyboard_shifted", 42, 44, 13, 15, "\"", input, "\"", false, colors.white, colors.gray, false)
  385.             button.createButton("keyboard_shifted", 46, 48, 13, 15, "|", input, "|", false, colors.white, colors.gray, false)
  386.             button.createButton("keyboard_shifted", 2, 4, 17, 19, "Z", input, "Z", false, colors.white, colors.gray, false)
  387.             button.createButton("keyboard_shifted", 6, 8, 17, 19, "X", input, "X", false, colors.white, colors.gray, false)
  388.             button.createButton("keyboard_shifted", 10, 12, 17, 19, "C", input, "C", false, colors.white, colors.gray, false)
  389.             button.createButton("keyboard_shifted", 14, 16, 17, 19, "V", input, "V", false, colors.white, colors.gray, false)
  390.             button.createButton("keyboard_shifted", 18, 20, 17, 19, "B", input, "B", false, colors.white, colors.gray, false)
  391.             button.createButton("keyboard_shifted", 22, 24, 17, 19, "N", input, "N", false, colors.white, colors.gray, false)
  392.             button.createButton("keyboard_shifted", 26, 28, 17, 19, "M", input, "M", false, colors.white, colors.gray, false)
  393.             button.createButton("keyboard_shifted", 30, 32, 17, 19, "<", input, "<", false, colors.white, colors.gray, false)
  394.             button.createButton("keyboard_shifted", 34, 36, 17, 19, ">", input, ">", false, colors.white, colors.gray, false)
  395.             button.createButton("keyboard_shifted", 38, 40, 17, 19, "?", input, "?", false, colors.white, colors.gray, false)
  396.             button.createButton("keyboard_shifted", 2, 9, 2, 4, "RETURN", returnText, nil, false, colors.gray, colors.white, false)
  397.             button.createButton("keyboard_shifted", 42, 44, 17, 19, "SPC", input, " ", false, colors.gray, colors.white, false)
  398.             button.createButton("keyboard_shifted", 46, 48, 17, 19, "^", switchCase, "keyboard", false, colors.gray, colors.lightGray, false)
  399.             editing=true
  400.             selectedINDEX="keyboard"
  401.             if selectedInput ~= "term" then
  402.                     local asd=peripheral.wrap(selectedInput)
  403.                     term.redirect(asd)
  404.                     redrawKeyboard()
  405.                     runKeyBoardLOOP()
  406.             else
  407.                     redrawKeyboard()
  408.                     runKeyBoardLOOP()
  409.             end
  410.     end
  411.      
  412.     function startupGUI()
  413.             while startupRunning do
  414.                     term.clear()
  415.                     selectedINDEX="startup"
  416.                     button.drawButtons(selectedINDEX, colors.gray, "ASD-Board", colors.white)
  417.                     term.setCursorPos(3,10)
  418.                     term.setTextColor(colors.white)
  419.                     term.write("Selected input: "..selectedInput)
  420.                     local event, asd1, asd2, asd3 = os.pullEvent()
  421.                     term.setCursorPos(1,2)
  422.                     term.setTextColor(colors.white)
  423.                     term.setBackgroundColor(colors.gray)
  424.                     write(event)  if asd1 ~= nil then write(", ") write(asd1) end if asd2 ~= nil then write(", ") write(asd2) end if asd3 ~=nil then write(", ") write(asd3) end
  425.                     if event == "mouse_click" or event == "monitor_touch" and manualSelect == false then
  426.                             button.doButton(selectedINDEX, asd2, asd3)
  427.                     else
  428.                             write("CRASH!")
  429.                             sleep(.5)
  430.                     end
  431.                     sleep(.1)
  432.             end
  433.     end
  434.      
  435.     function selectGUI(chr)
  436.             startupRunning=false
  437.             selectRunning=true
  438.             if selectedInput ~= nil then
  439.                     ret=runKeyBoard(chr)
  440.                     return ret
  441.             else
  442.                     while selectRunning do
  443.                             term.clear()
  444.                             listInputGUI()
  445.                             selectedINDEX="inputgui"
  446.                             local event asd1, asd2, asd3 = os.pullEvent()
  447.                             if event == "monitor_touch" and selectedInput == asd1 then
  448.                                     button.doButton(selectedINDEX, asd2, asd3)
  449.                             elseif event == "monitor_touch" or event == "mouse_click" and manualSelect == true then
  450.                                     selectedInput = asd1
  451.                                     manualSelect = false
  452.                             elseif event == "mouse_click" then
  453.                                     button.doButton(selectedINDEX, asd2, asd3)
  454.                             else
  455.                                     write("CRASH")
  456.                                     sleep(.5)
  457.                             end
  458.                             sleep(.1)
  459.                     end
  460.             end
  461.     end
  462.      
  463.      -- TEST/DEBUG LINES :D
  464.      
  465.      --[[
  466.      
  467.     function asd()
  468.             button.createINDEX(1)
  469.             button.createButton(1,3,13,5,9,"ASD", print("ASD!"), false, colors.cyan, colors.gray, false)
  470.             button.createButton(1,3,13,10,14,"SUUUT", print("SUUUUUUTTT!!!"), true, colors.green, nil, false)
  471.             button.drawButtons(1, nil, "ASD", nil)
  472.     end
  473.      
  474.     function printButtonConfig(INDEX)
  475.             local dataValue={}
  476.             for btn, data in pairs(btns[INDEX]) do
  477.                     dataValue=data
  478.                     print(" "..btn)
  479.                     for int, val in pairs(dataValue) do
  480.                             write(" -- "..int..", ")
  481.                             print(val)
  482.                     end
  483.             end
  484.     end
  485.      
  486.      
  487.     ]]--
  488.      
  489.     -- EOF TEST/DEBUG LINES :(
  490.      
  491.     -- STARTUP
  492.      
  493.     function readInput(chr)
  494.             keyboardInput=""
  495.             setUp()
  496.             startupRunning=true
  497.             startupGUI()
  498.             input=returnText()
  499.             return input
  500.     end
Advertisement
Add Comment
Please, Sign In to add comment