Advertisement
natie3

MainLoop_Monitor api

Nov 28th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. while state ~= "Ready" do
  2.   clear()
  3.   if(state == "Editing") then
  4.     drawTempButton(tempButtons["Clear"]["x1"],tempButtons["Clear"]["x2"],tempButtons["Clear"]["y1"],tempButtons["Clear"]["y2"],colors.gray,"Clear")
  5.     drawTempButton(tempButtons["Undo"]["x1"],tempButtons["Undo"]["x2"],tempButtons["Undo"]["y1"],tempButtons["Undo"]["y2"],colors.gray,"Undo")
  6.     drawTempButton(tempButtons["Confirm"]["x1"],tempButtons["Confirm"]["x2"],tempButtons["Confirm"]["y1"],tempButtons["Confirm"]["y2"],colors.gray,"Confirm")
  7.     drawCurrentButton()
  8.     drawButtons()
  9.   elseif(state == "Grid") then
  10.     drawGrid()
  11.     drawButtons()
  12.   elseif(state == "Wrong_monitor_size") then
  13.     m.setCursorPos(1,1)
  14.     m.write("This size")
  15.     m.setCursorPos(1,2)
  16.     m.write("isnt supported")
  17.   elseif(state == "Monitor_resize") then
  18.     a,b = m.getSize()
  19.     yspot = math.floor(b/2)
  20.     xspot = math.floor((1 + a - 25)/2) + 1
  21.     m.setCursorPos(xspot,yspot-1)
  22.     m.write("You resized the monitor,")
  23.     m.setCursorPos(xspot,yspot)
  24.     m.write("return to the old size")
  25.     m.setCursorPos(xspot,yspot+1)
  26.     m.write("or restart this program")
  27.   end
  28.   event = { os.pullEvent() }
  29.   if(event[1] == "monitor_resize") then
  30.     a,b = m.getSize()
  31.     if(a == 15 or b == 15) then
  32.       state = "Wrong_monitor_size"
  33.     elseif(a ~= x or b ~= y) then
  34.       state = "Monitor_resize"
  35.     elseif(a == x and b == y) then
  36.       state = "Grid"
  37.     end
  38.   elseif(event[1] == "monitor_touch") then
  39.     if(state == "Grid") then
  40.       if not checkLine(event[3],event[4]) then
  41.         makeCurrentButton()
  42.         state = "Editing"
  43.       end
  44.     elseif(state == "Editing") then
  45.       result = checkxy(event[3], event[4], tempButtons)
  46.       if(result == "Clear") then
  47.         state = "Grid"
  48.       elseif(result == "Undo") then
  49.         copy(last,current)
  50.         drawCurrentButton()
  51.       elseif(result == "Confirm") then
  52.         term.clear()
  53.         clear()
  54.         term.setCursorPos(1,1)
  55.         yspot = math.floor(y/2)
  56.         xspot = math.floor((1 + x - 25)/2) + 1
  57.         m.setCursorPos(15,15)
  58.         m.write("Plz fill the name into the terminal")
  59.         write("Whats the label of the button? ")
  60.         name = io.read()
  61.         makeButton(name)
  62.         term.setCursorPos(1,2)
  63.         write("Do you want to add another button?[Y/n] ")
  64.         another = io.read()
  65.         if(another ~= "n") then
  66.           state = "Grid"
  67.         else
  68.           state = "Ready"
  69.           result = false
  70.           while not result do
  71.             result = finish()
  72.           end
  73.         end
  74.       elseif(result ~= "none") then
  75.         editButton(result)
  76.       end
  77.     end
  78.   end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement