akihex

enhPortalDial

Mar 15th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. local ctrl = peripheral.wrap("Portal Controller_0")
  3. local dial = peripheral.wrap("right")
  4.  
  5. local countTargets = dial.getStoredCount()
  6.  
  7. function padStr(str, len)
  8.   if #str > len then do return string.sub(str,1,len) end
  9.   else do return str .. string.rep(' ', len - #str) end
  10.   end
  11. end
  12.  
  13. function drawUI()
  14.   local monX, monY = mon.getSize()
  15.   mon.setBackgroundColor(colors.blue)  
  16.   mon.clear()
  17.   mon.setCursorPos(1,1)
  18.   mon.write("Please choose your")
  19.   mon.setCursorPos(1,2)
  20.   mon.write("destination")
  21.   countTargets = dial.getStoredCount()
  22.   if (countTargets > 0) then
  23.     for i = 1, countTargets do
  24.       mon.setCursorPos(1, i + 3)
  25.       if (i % 2 == 0) then
  26.         mon.setBackgroundColor(colors.lightBlue)
  27.       else
  28.         mon.setBackgroundColor(colors.blue)
  29.       end
  30.       name = padStr(dial.getStoredName(i - 1),monX)
  31.       mon.write(name)        
  32.     end
  33.   else
  34.     mon.setCursorPos(1, 4)
  35.     mon.write("No Entries")
  36.   end
  37. end
  38.  
  39. function waitForInput()
  40.   event, _, posX, posY = os.pullEvent("monitor_touch")
  41.   if ctrl.isPortalActive() then dial.terminate() end
  42.   if countTargets > 0 and (posY-3 > 0) and (posY-3 <= countTargets) then
  43.     dial.dialStored(posY - 4)
  44.   end
  45. end
  46.  
  47. while true do
  48.   drawUI()
  49.   waitForInput()
  50. end
Advertisement
Add Comment
Please, Sign In to add comment