Guest User

frame2

a guest
Apr 25th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. rednet.open("back")
  2. os.loadAPI("button")
  3. local m = term
  4. local menuType = "mainMenu"
  5.  
  6. local mainCompID = 0
  7. local frameCompID = 6
  8.  
  9. local cycleIteration = 0
  10.  
  11. local frameCoords = {}
  12. frameCoords["x"] = 0
  13. frameCoords["y"] = 0
  14. frameCoords["z"] = 0
  15.  
  16. function sendMessage(message)
  17.     rednet.send(mainCompID, message)
  18. end
  19.  
  20. function mainMenu()
  21.     m.clear()
  22.     button.clearTable()
  23. --  button.setTable("Up", frameMove, "Up", 3, 13, 1, 1)
  24. --  button.setTable("Down", frameMove, "Down", 15, 25, 1, 1)
  25.     button.setTable("Forward", frameMove, "Forward", 3, 13, 3, 3)
  26. --  button.setTable("Backward", frameMove, "Backward", 15, 25, 3, 3)
  27. --  button.setTable("Bedrock", textMessage, "Bedrock", 3, 13, 5, 5)
  28. --  button.setTable("SeaLevel", textMessage, "SeaLevel", 15, 25, 5, 5)
  29.     button.setTable("Cycle x5", cycleX, 5, 15, 25, 5, 5)
  30.     button.setTable("Cycle x10", cycleX, 10, 15, 25, 7, 7)
  31.     button.setTable("Cycle x20", cycleX, 20, 15, 25, 9, 9)
  32.     button.setTable("Cycle x40", cycleX, 40, 15, 25, 11, 11)
  33.     button.setTable("SendItems", textMessage, "SendItems", 3, 13, 7, 7)
  34.     button.setTable("Power", textMessage, "Power", 3, 13, 5, 5)
  35. --  button.setTable("Dome", textMessage, "Dome", 15, 25, 7, 7)
  36.     button.setTable("Cycle", textMessage, "Cycle", 15, 25, 3, 3)
  37. --  button.setTable("NextCycle", textMessage, "NextCycle", 15, 25, 9, 9)
  38. --  button.setTable("AutoMode", textMessage, "AutoMode", 3, 13, 13, 13)
  39.     button.setTable("STOP", textMessage, "STOP", 15, 25, 13, 13)
  40.     if cycleIteration ~= 0 then
  41.         button.label(1,15,"Cycles Remaining: "..cycleIteration)
  42.     end
  43.     button.setTable("Refresh Coords", setFrameCoords, "", 3, 25, 17, 17)
  44.     button.label(1,20,"Frame Coords: "..frameCoords["x"]..","..frameCoords["y"]..","..frameCoords["z"])
  45.     checkCurrentFunction()
  46.     button.screen()
  47. end
  48.  
  49. function getFrameLoc()
  50.     local data = {}
  51.     local id,msg,proto
  52.     repeat
  53.         rednet.send(frameCompID, "GPS")
  54.         id,msg,proto = rednet.receive(0.1)
  55.     until id == frameCompID
  56.     data = textutils.unserialize(msg)
  57.     return data["x"], data["y"], data["z"]
  58. end
  59.  
  60. function setFrameCoords()
  61.     button.toggleButton("Refresh Coords")
  62.     frameCoords["x"], frameCoords["y"], frameCoords["z"] = getFrameLoc()
  63.     button.toggleButton("Refresh Coords")
  64. end
  65.  
  66. function frameMove(message)
  67.     --button.toggleButton(message)
  68.     local data = {}
  69.     data[0] = "moveFrame"
  70.     data[1] = message
  71.     sendMessage(textutils.serialize(data))
  72.     --waitComplete()
  73.     --button.toggleButton(message)
  74. end
  75.  
  76. function cycleX(message)
  77.     --button.toggleButton(message)
  78.     local data = {}
  79.     data[0] = "cycleX"
  80.     data[1] = message
  81.     sendMessage(textutils.serialize(data))
  82.     --waitComplete()
  83.     --button.toggleButton(message)
  84. end
  85.  
  86. function textMessage(message)
  87.     local data = {}
  88.     data[0] = message
  89.     sendMessage(textutils.serialize(data))
  90. end
  91.  
  92. function checkCurrentFunction()
  93.     local id,msg,proto
  94.     repeat
  95.         textMessage("CurrentFunction")
  96.         id,msg,proto = rednet.receive(0.1)
  97.     until msg
  98.     data = textutils.unserialize(msg)
  99.     if data[0] ~= "" then
  100.         button.setButton(data[0], true)
  101.     end
  102. --  button.setButton("AutoMode", data[1])
  103.     button.setButton("Cycle", data[2])
  104.     button.setButton("Power", data[3])
  105.     cycleIteration = data[4]
  106. end
  107.  
  108. function displayScreen()
  109. --  setFrameCoords()
  110.     mainMenu()
  111.     local timerCode = 0
  112.     timerCode = os.startTimer(1)
  113.     local event,side, x, y
  114.     repeat
  115.     --  event, side, x, y = os.pullEvent("mouse_click")
  116.     event, side, x, y = os.pullEvent()
  117.     --  print(event)
  118.     --  sleep(0.2)
  119.     --  print(event..":"..side)
  120.        
  121.     until side == timerCode or event=="mouse_click" or event == "mouse_drag"
  122.     if event == "mouse_click" or event == "mouse_drag" then
  123.         os.cancelTimer(timerCode)
  124.         button.checkxy(x,y)
  125.     end
  126. end
  127.  
  128. while true do
  129.     displayScreen()
  130. end
Advertisement
Add Comment
Please, Sign In to add comment