Advertisement
Guest User

startup

a guest
Mar 29th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.73 KB | None | 0 0
  1. local chat = peripheral.wrap("top")
  2. local mon = peripheral.wrap("monitor_0")
  3. local sg = peripheral.wrap("stargate_0")
  4. local buttonTable = {}
  5. local buttonName
  6.  
  7. mon.setBackgroundColor(colors.black)
  8. mon.clear()
  9. chat.capture("^SG")
  10.  
  11. function catchEntry()
  12.     local _, message, pattern, player, uuid = os.pullEvent("chat_capture")
  13.     if pattern == "^SG" then
  14.         cutSG = string.gsub(message, "SG", "")
  15.         chat.tell("[Stargate] Starting 'Stargate Protocol'!")
  16.     end
  17. end
  18.  
  19.  
  20.  
  21. function createButton(btnName, PosX, PosY, SizeX, SizeY, Name, Address, bkCol)
  22.     buttonTable[btnName] = {}
  23.     buttonTable[btnName]["rectangle"] = {}
  24.     buttonTable[btnName]["PosX"] = PosX
  25.     buttonTable[btnName]["PosY"] = PosY
  26.     buttonTable[btnName]["SizeX"] = SizeX
  27.     buttonTable[btnName]["SizeY"] = SizeY
  28.     buttonTable[btnName]["Name"] = Name
  29.     buttonTable[btnName]["Address"] = Address
  30.     buttonTable[btnName]["bkCol"] = bkCol
  31.    
  32. end
  33.  
  34. local function drawButton(btnName)
  35.     i = 1
  36.     str = string.len(buttonTable[btnName]["Name"])
  37.     for y = 1,buttonTable[btnName]["SizeY"] do
  38.         for x = 1, buttonTable[btnName]["SizeX"] do
  39.             --print(x..","..y.." : "..buttonTable[btnName]["PosX"]+x-1)
  40.             --print(x..","..y.." : "..buttonTable[btnName]["PosY"]+y-1)
  41.             mon.setBackgroundColor(buttonTable[btnName]["bkCol"])
  42.             mon.setCursorPos(buttonTable[btnName]["PosX"]+x-1, buttonTable[btnName]["PosY"]+y-1)
  43.             mon.write(" ")
  44.            
  45.             --mon.setBackgroundColor(colors.gray)
  46.             buttonTable[btnName]["rectangle"][x..":"..y] = {}
  47.             buttonTable[btnName]["rectangle"][x..":"..y] = buttonTable[btnName]["PosX"]+x-1 ..":"..buttonTable[btnName]["PosY"]+y-1
  48.             if y == buttonTable[btnName]["SizeY"] then
  49.                 textPosiX = buttonTable[btnName]["SizeX"]-str
  50.                 textPosX = textPosiX/2
  51.                 if y ~= 1 and y ~= 2 then
  52.         mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"]+y/(buttonTable[btnName]["SizeY"]))
  53.                 elseif y == 1 or y == 2 then
  54.         mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"])
  55.     end
  56.         mon.write(buttonTable[btnName]["Name"])
  57.            
  58.    end
  59.             i = i+1
  60.         end
  61.     end
  62.     --print(str)
  63. end
  64.  
  65. local function drawButtonPress(btnName)
  66.     if btnName ~= nil then
  67.         str = string.len(buttonTable[btnName]["Name"])
  68.         for y = 1,buttonTable[btnName]["SizeY"] do
  69.             for x = 1, buttonTable[btnName]["SizeX"] do
  70.                 --print(x..","..y.." : "..buttonTable[btnName]["PosX"]+x-1)
  71.                 --print(x..","..y.." : "..buttonTable[btnName]["PosY"]+y-1)
  72.                 mon.setBackgroundColor(colors.red)
  73.                 mon.setCursorPos(buttonTable[btnName]["PosX"]+x-1, buttonTable[btnName]["PosY"]+y-1)
  74.                 mon.write(" ")
  75.                
  76.                 --mon.setBackgroundColor(colors.gray)
  77.                 if y == buttonTable[btnName]["SizeY"] then
  78.                     textPosiX = buttonTable[btnName]["SizeX"]-str
  79.                     textPosX = textPosiX/2
  80.                     if y ~= 1 and y ~= 2 then
  81.          mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, math.floor(buttonTable[btnName]["PosY"]+y/buttonTable[btnName]["SizeY"]))
  82.                     elseif y == 1 or y == 2 then
  83.          mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"])
  84.      end
  85.      mon.write(buttonTable[btnName]["Name"])
  86.  
  87.                 end
  88.                 i = i+1
  89.             end
  90.         end
  91.     else
  92.         print("Looks like the button you requested is not available")
  93.     end
  94. end
  95.  
  96. local function testButtonPress(tPosX, tPosY)
  97.     for k,v in pairs(buttonTable) do
  98.         for a,b in pairs(buttonTable[k]["rectangle"]) do
  99.             if b == tPosX..":"..tPosY then
  100.                 return k
  101.             end
  102.         end
  103.     end
  104. end
  105.  
  106. --createButton(registryName, Xmin, Ymin, Xmax, Ymax, displayName, stargate, color)
  107.  
  108. createButton("Nether", 1,1,10,2, "Nether", "PFER-7QN-9R", colors.orange)
  109. createButton("Moon", 1,11,10,3,"Moon", "1FYB-81J-KE", colors.lightGray)
  110. createButton("End", 11,1,10,2,"End", "I454-OTE-QX", colors.purple)
  111. createButton("Mesa", 1,3,10,1,"Mesa", "TAGJ-YB8-GC", colors.yellow)
  112. createButton("Mars", 11,11,10,3, "Mars", "PFS5-21P-6H", colors.orange)
  113.  
  114.  
  115. createButton("disconnect", 1, 17, 39,1, "Disconnect", "", colors.gray)
  116. createButton("iris", 1,18,39,1, "", "", colors.lime)
  117. createButton("status", 1,19,39,1, "","",colors.lime)
  118.  
  119.  
  120. local function autoDrawBtn()
  121.     for k,v in pairs(buttonTable) do
  122.         drawButton(k)
  123.     end
  124. end
  125.  
  126. local function monitor_touch_event()
  127.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  128.     if event == "monitor_touch" then
  129.         buttonName = testButtonPress(xPos, yPos)
  130.         drawButtonPress(buttonName)
  131.         print(xPos, yPos)
  132.         if buttonName == "disconnect" then
  133.             print("Disconnecting")
  134.             sg.disconnect()
  135.             sleep(1)
  136.             autoDrawBtn()
  137.         elseif buttonName ~= nil then
  138.             sg.dial(buttonTable[buttonName]["Address"])
  139.             sleep(1)
  140.             autoDrawBtn()
  141.         end
  142.     end
  143. end
  144.  
  145. autoDrawBtn()
  146.  
  147. while true do
  148.     monitor_touch_event()
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement