MRtecno98

OpenComputer TNTLauncher Client [GUI]

Feb 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. API = require("buttonAPI")
  2. local event = require("event")
  3. local computer = require("computer")
  4. local term = require("term")
  5. local component = require("component")
  6. local serialization = require("serialization")
  7. local modem = component.modem
  8. local gpu = component.gpu
  9. local GUI = {}
  10.  
  11. local colors = require("colors")
  12. local side = require("sides")
  13.  
  14. local h, w = gpu.getResolution()
  15.  
  16. PORT = 666
  17.  
  18. KX = h/160
  19. KY = w/50
  20.  
  21. function API.fillTable()
  22.   API.setTable("LAUNCH", launchtnt, math.floor(60*KX),math.floor(100*KX),math.floor(30*KY),math.floor(35*KY))
  23.   API.setTable("Close", close, math.floor(60*KX), math.floor(100xKX), math.floor(38*KY), math.floor(41*KY))
  24.   API.screen()
  25. end
  26.  
  27. function GUI.getClick()
  28.   local _, _, x, y = event.pull(1,touch)
  29.   if x == nil or y == nil then
  30.     local h, w = gpu.getResolution()
  31.     gpu.set(h, w, ".")
  32.     gpu.set(h, w, " ")
  33.   else
  34.     API.checkxy(x,y)
  35.   end
  36. end
  37.  
  38. function launchtnt()
  39.   API.flash("LAUNCH",0.1)
  40.  
  41.   local payload = {}
  42.   payload["type"] = "launch"
  43.   payload["sender"] = modem.address
  44.   payload["id"] = math.random(0,9999)
  45.  
  46.   modem.send(_G.data["serveraddr"], PORT, serialization.serialize(payload))
  47.  
  48. end
  49.  
  50. function disconnect()
  51.   local payload = {}
  52.   payload["type"] = "disconnect"
  53.   payload["sender"] = modem.address
  54.   payload["id"] = math.random(0,9999)
  55.  
  56.   modem.send(_G.data["serveraddr"], PORT, serialization.serialize(payload))  
  57. end
  58.  
  59. function close()
  60.   API.flash("Close", 0.1)
  61.   disconnect()
  62.   os.exit(1)
  63. end  
  64.  
  65. function GUI.mainLoop()
  66.   term.setCursorBlink(false)
  67.   gpu.setResolution(h, w)
  68.   API.clear()
  69.   API.fillTable()
  70.   API.heading("TNT Wireless Launcher V.1.0")
  71.   while true do
  72.     GUI.getClick()
  73.   end
  74. end
  75.  
  76.  
  77. return GUI
  78.  
  79.  
  80. --eof
Add Comment
Please, Sign In to add comment