Spiker985

Enhanced Portals - Dialer

Jul 8th, 2014
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 0 0
  1. local header = "Dialer"
  2. local mon = peripheral.wrap("left")
  3. local controller = peripheral.wrap("right")
  4. local dialer = peripheral.wrap("ep_dialling_device_1")
  5.  
  6. --[[Change nothing below unless you know what you are doing]]--
  7. --[[Unless you want to add more pages]]--
  8.  
  9. local pages = 0
  10. local pageNum = 1
  11. local locNames = {}
  12.  
  13. function APILoader(apiName, apiPastebin)
  14.   os.unloadAPI(apiName)
  15.   if fs.exists(apiName) then
  16.     os.loadAPI(apiName)
  17.   else
  18.     shell.run("pastebin","get",apiPastebin,apiName)
  19.     os.loadAPI(apiName)
  20.   end
  21. end
  22.  
  23. function heading()
  24.   button.heading(header..":")
  25. end
  26.  
  27. function setupNav()
  28.   button.setTable("Prev", prevPage, "", "", false, 1, 6, 18, 20)
  29.   button.setTable("Next", nextPage, "", "", false, 33, 39, 18, 20)
  30.   button.setTable("Refresh", os.reboot, "", "", false, 15, 25, 18, 20)
  31.   button.screen()
  32. end
  33.  
  34. function setupPages()
  35.    mon.clear()
  36.    button.clearTable()
  37.    heading()
  38.    local totalRows = 0
  39.    local rowCount = 0
  40.    local currCount = 0
  41.    local col = 2
  42.    local row = 3
  43.    local npp = 12 --names per page
  44.    for i = 1, dialer.getStoredCount() do
  45.       totalRows = totalRows + 1
  46.    end
  47.    for i = 0, dialer.getStoredCount()-1 do
  48.       locNames[i+1] = dialer.getStoredName(i)
  49.    end
  50.    --[[To add more pages just take add 12 to your last number]]--
  51.    if pageNum == 1 then
  52.      j = 1
  53.    end
  54.    if pageNum == 2 then
  55.      j = 13
  56.    end
  57.    if pageNum == 3 then
  58.      j = 25
  59.    end
  60.    if pageNum == 4 then
  61.      j = 37
  62.    end
  63.    if pageNum == 5 then
  64.      j = 49
  65.    end
  66.    if pageNum == 6 then
  67.      j = 61
  68.    end
  69.    if pageNum == 7 then
  70.      j = 73
  71.    end
  72.    if pageNum == 8 then
  73.      j = 85
  74.    end
  75.    if pageNum == 9 then
  76.      j = 97
  77.    end
  78.    if pageNum == 10 then
  79.      j = 109
  80.    end
  81.    for i = j, #locNames do
  82.      button.setTable(locNames[i], travel, i-1, "", false, col, col+17, row, row)
  83.      row = row + 2
  84.      rowCount = rowCount + 1
  85.      if rowCount == 6 then
  86.        col = col + 19
  87.        row = 3
  88.        rowCount = 0
  89.      end
  90.    end
  91.    pages = math.ceil(totalRows/npp)
  92.    
  93.    button.label(15, 16, "Page "..tostring(pageNum).." of "..tostring(pages))
  94.    setupNav()
  95.    button.screen()
  96. end
  97.  
  98. function checkActive()
  99. if controller.isPortalActive() == true then
  100.   mon.clear()
  101.   button.clearTable()
  102.   button.heading("Portal connection")
  103.   button.label(6, 2, "Portal already connected,")
  104.   button.label(6, 3, "would you like to close it?")
  105.   button.setTable("Yes", confirm, "true", "", false, 6, 18, 4, 6)
  106.   button.setTable("No", confirm, "false", ",, false, 20, 32, 4, 6)
  107.  button.screen()
  108. else
  109.  setupPages()
  110. end
  111. end
  112.  
  113. function confirm(answer)
  114.  if answer == "true" then
  115.     dialer.terminate()
  116.     setupPages()
  117.  end
  118.  if answer == "false" then
  119.     mon.clear()
  120.     button.clearTable()
  121.     button.heading("Beginning restart...")
  122.     sleep(3)
  123.     mon.clear()
  124.     os.reboot()
  125.  end
  126. end
  127.  
  128. function travel(location)
  129.  dialer.dialStored(location)
  130.  mon.clear()
  131.  button.clearTable()
  132.  button.heading("Travelling to "..tostring(locNames[location+1]))
  133.  sleep(5)
  134.  dialer.terminate()
  135.  mon.clear()
  136.  os.reboot()
  137. end
  138.  
  139. function nextPage()
  140.  if pageNum + 1 <= pages then
  141.    pageNum = pageNum + 1
  142.  end
  143.  setupPages()
  144.  button.flash("Next")
  145. end
  146.  
  147. function prevPage()
  148.  if pageNum - 1 >= 1 then
  149.    pageNum = pageNum - 1
  150.  end
  151.    setupPages()
  152.    button.flash("Prev")
  153. end
  154.  
  155. function checkpress()
  156.  event, side, x, y = os.pullEvent("monitor_touch")
  157.  button.checkxy(x,y)
  158. end
  159.  
  160. APILoader("button","S8x0K3ui")
  161. heading()
  162. checkActive()
  163.  
  164. while true do
  165.  checkpress()
  166. end
  167.  
  168. mon.clear()
Advertisement
Add Comment
Please, Sign In to add comment