Advertisement
CaptainSpaceCat

CC IOS: Message

May 16th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. rednet.open("back") ------ turn off for ios, internet option instead
  2. w, h = term.getSize()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. messages = {}
  6.  
  7. --text formatters--
  8. function partition()
  9.   term.setBackgroundColor(colors.gray)
  10.   term.setTextColor(colors.white)
  11. end
  12.  
  13. function emphasis()
  14.   term.setBackgroundColor(colors.lightGray)
  15.   term.setTextColor(colors.white)
  16. end
  17.  
  18. function background()
  19.   term.setBackgroundColor(colors.white)
  20.   term.setTextColor(colors.black)
  21. end
  22.  
  23. --initialize header--
  24. if h % 3 == 1 then
  25.   inbox = 2
  26. else
  27.   inbox = 1
  28. end
  29.  
  30. --unserialize--
  31. function unserialize(string)
  32.   --print(string)
  33.   local run = loadstring(string)
  34.   --pcall(run())
  35.   run()
  36.   for i, v in pairs(messages) do
  37.     print(i, v)
  38.   end
  39.   --sleep(20)
  40. end
  41.  
  42. --tick--
  43. local day = tostring(os.day())
  44. local time = tostring(os.time())
  45. local updateTick = 0
  46. function update()
  47.   updateTick = updateTick + 1
  48.   if updateTick >= 10 then
  49.     day = tostring(os.day())
  50.     time = tostring(os.time())
  51.     updateTick = 0
  52.   end
  53.   getMsglist()
  54.   os.cancelTimer(timer)
  55.   timer = os.startTimer(.1)
  56. end
  57.  
  58. function getMsglist()
  59.   rednet.broadcast("", "getmsglist")
  60. end
  61.  
  62. --program start--
  63. location = 0
  64. dir = 0
  65. timer = os.startTimer(.1)
  66. while true do
  67.   getMsglist()
  68.   --print("L: " .. location)
  69.   if #messages > 6 then
  70.     if location > -1 * math.abs(1 + #messages - h / 3) and location <= 0 then
  71.       location = location + dir
  72.     end
  73.     if location == 1 then location = 0 end
  74.     if location < -1 * math.abs(1 + #messages - h / 3) then location = location + 1 end
  75.   end
  76.   background()
  77.   term.clear()
  78.   partition()
  79.   term.setCursorPos(1, 2)
  80.   term.clearLine()
  81.   background()
  82.   term.setCursorPos((w / 2 - 5 / 2) + 1, inbox)
  83.   write("Inbox")
  84.   term.setCursorPos(1, 2)
  85.   partition()
  86.   term.write(day .. ":" .. time)
  87.   y = 1
  88.   --if messages then
  89.   for i = 1, #messages do
  90.     if (-1 * tonumber(i) > -1 * (h / 3) + location and -1 * tonumber(i) < location) then
  91.       emphasis()
  92.       term.setCursorPos(1, y * 3)
  93.       print(i .. "| " .. messages[i][2])
  94.       background()
  95.       print(messages[i][1])
  96.       y = y + 1
  97.     end
  98.   end
  99.   --end
  100.   pressed = {}
  101.   dir = 0
  102.   local events = {os.pullEvent()}
  103.   if events[1] == "timer" then
  104.     update()
  105.   elseif events[1] == "mouse_scroll" then
  106.     dir = events[2]
  107.   elseif events[1] == "rednet_message" then
  108.     if events[4] == "sendmsglist" then
  109.       unserialize(events[3])
  110.     end
  111.   end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement