Advertisement
CyborgSquirrel

startup(stargate)

Apr 28th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --Functions
  2. --Button functions
  3. function dial()
  4.     button.flash("Dial")
  5.     setButtonGroup("dial")
  6.     local addresses = fs.open("stargate/addresses", "r")
  7.     while addresses.readLine() do
  8.        
  9.     end
  10. end
  11.  
  12. function add()
  13.     button.flash("Add")
  14. end
  15.  
  16. function connect()
  17.     button.flash("Connect")
  18. end
  19.  
  20. function acceptAddressRequest(recieverID)
  21.     button.flash("Accept")
  22.     rednet.send(recieverID, sgate.localAddress())
  23. end
  24.  
  25. function declineAddressRequest(receiverID)
  26.     button.flash("Decline")
  27.     rednet.send(receiverID, "REQUEST_DECLINE")
  28. end
  29.  
  30. function requestAddress(ID)
  31.     rednet.send(ID, "ADDRESS_REQUEST")
  32.     event, senderID, message, distance = os.pullEvent("rednet_message")
  33. end
  34.  
  35. --Button groups
  36. function setButtonGroup(group, ...)
  37.     local arg = {...}
  38.    
  39.     button.remTable("Dial")
  40.     button.remTable("Accept")
  41.     button.remTable("Decline")
  42.     button.remTable("Add")
  43.     button.remTable("Remove")
  44.     button.remTable("Connect")
  45.     button.remTable("<")
  46.     button.remTable(">")
  47.    
  48.     if group == "addressRequest" then
  49.         button.setTable("Accept", acceptAddressRequest, arg[1], "", false, 6, 13, 6, 8)
  50.         button.setTable("Decline", declineAddressRequest, arg[1], "", false, 16, 24, 6, 8)
  51.        
  52.         button.heading("Stargate Controller", colors.blue)
  53.        
  54.         term.redirect(mon)
  55.         paintutils.drawFilledBox(5, 3, 25, 9, colors.yellow)
  56.         term.native()
  57.        
  58.         button.label(6, 4, "Stargate ID Request", colors.yellow, colors.black)
  59.        
  60.         mon.setTextColor(colors.white)
  61.     elseif group == "mainMenu" then
  62.         mon.setBackgroundColor(colors.blue)
  63.         mon.clear()
  64.        
  65.         button.setTable("Dial", dial, "", "", false, 2, 7, 3, 5)
  66.        
  67.         button.heading("Stargate Controller", colors.blue)
  68.     elseif group == "dial" then
  69.         mon.setBackgroundColor(colors.blue)
  70.         mon.clear()
  71.        
  72.         term.redirect(mon)
  73.         paintutils.drawFilledBox(0, 10, 30, 12, colors.yellow)
  74.         term.native()
  75.        
  76.         button.setTable("Add", add, "", "", false, 2, 6, 3, 5)
  77.         button.setTable("Remove", remove, "", "", false, 8, 15, 3, 5)
  78.         button.setTable("Connect", connect, "", "", false, 17, 25, 3, 5)
  79.         button.setTable("<", left, "", "", false, 1, 3, 10, 12)
  80.         button.setTable(">", right, "", "", false, 27, 29, 10, 12)
  81.         --button.setTable("/\\", up, "", "", false, 1, 1, 1, 1)
  82.         --button.setTable("\\/", down, "", false, 1, 1, 1, 1)
  83.        
  84.         button.heading("Dial", colors.blue)
  85.     end
  86.     button.screen()
  87. end
  88.  
  89. --Listener functions
  90. local function rednetListen()
  91.     local event, senderID, message, distance = os.pullEvent("rednet_message")
  92.     if message == "ADDRESS_REQUEST" then
  93.         setButtonGroup("addressRequest", senderID)
  94.         while true do
  95.             local event, side, x, y = os.pullEvent("monitor_touch")
  96.             if button.checkxy(x, y) then
  97.                 break
  98.             end
  99.         end
  100.         setButtonGroup("mainMenu")
  101.     end
  102. end
  103.  
  104. local function monitorListen()
  105.     event, side, x, y = os.pullEvent("monitor_touch")
  106.     button.checkxy(x, y)
  107. end
  108.  
  109. --Code
  110. rednet.open("left")
  111.  
  112. sgate = peripheral.find("stargate")
  113.  
  114.  
  115.  
  116. mon = peripheral.find("monitor")
  117.  
  118. os.loadAPI("button")
  119.  
  120. setButtonGroup("mainMenu")
  121.  
  122. while true do
  123.     parallel.waitForAny(rednetListen, monitorListen)
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement