Advertisement
GNOOR1S

CC Minecraft - Advanced Monitor Check List

Jul 18th, 2022
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. --[[
  2.  
  3.     Idea from SOLLY
  4.     Created by LostboyDev
  5.     7/18/22
  6.  
  7.     This is for advanced and advanced monitors only
  8.     green button to add a task, red button to close
  9.  
  10. ]]
  11.  
  12. local m = peripheral.find ("monitor")
  13. local width, height = m.getSize()
  14. local running = true
  15.  
  16. local addBtnPos = {x = 1, y = height}
  17. local exitBtnPos = {x = width, y = height}
  18. local tasks = {}
  19. local tasksStartOffset = 3
  20.  
  21. function init()
  22.     m.setBackgroundColor(colors.white)
  23.     m.clear()
  24.     m.setCursorPos(1, 1)
  25.     load()
  26. end
  27.  
  28. -- not finished
  29. function load()
  30.     if not fs.exists("tasks") then
  31.         return
  32.     end
  33.     local file = fs.open("tasks", "r")
  34.     local data = textutils.unserialise(file.readAll())
  35.     tasks = data
  36.     file.close()
  37. end
  38.  
  39. function save()
  40.     local file = fs.open("tasks", "w")
  41.     local data = textutils.serialise(tasks)
  42.     file.write(data)
  43.     file.close()
  44. end
  45.  
  46. function centeredText(str, y)
  47.     local stringWidth = #str
  48.     local newX = math.floor((width - stringWidth) / 2)
  49.     m.setCursorPos(newX, y)
  50.     m.write(str)
  51. end
  52.  
  53. function drawPix(x, y, color)
  54.     m.setCursorPos(x, y)
  55.     m.setBackgroundColor(color)
  56.     m.write(" ")
  57. end
  58.  
  59. function draw()
  60.     drawPix(addBtnPos.x, addBtnPos.y, colors.green)    
  61.     drawPix(exitBtnPos.x, exitBtnPos.y, colors.red)
  62.     m.setTextColor(colors.black)
  63.     m.setBackgroundColor(colors.white)  
  64.     centeredText("Todo List", 2)
  65.     centeredText("LostboyDev", height)
  66.      
  67.    
  68.     for k, v in pairs(tasks) do
  69.         m.setTextColor(colors.cyan)    
  70.         centeredText("[" .. k .. "] " ..v, k + tasksStartOffset)
  71.     end
  72.    
  73. end
  74.  
  75. function update()
  76.     while running  do
  77.         event, side, x, y = os.pullEvent("monitor_touch")
  78.         if x == addBtnPos.x and  y == addBtnPos.y then
  79.             term.setBackgroundColor(colors.white)
  80.             term.clear()
  81.             term.setCursorPos(1, 1)
  82.             term.setTextColor(colors.red)
  83.             term.write("Enter new Task: ")
  84.             m.setBackgroundColor(colors.white)
  85.             centeredText("Please Type Info In Computer", height/2)
  86.             local input = read()
  87.             table.insert(tasks, input)
  88.             term.clear()
  89.             term.setCursorPos(1, 1)
  90.             m.setBackgroundColor(colors.white)
  91.             m.setTextColor(colors.black)
  92.             m.clear()
  93.             save()
  94.             draw()
  95.         elseif x  == exitBtnPos.x and y == exitBtnPos.y then
  96.             term.setBackgroundColor(colors.black )
  97.             term.setTextColor(colors.white)
  98.             term.clear()
  99.             term.setCursorPos(1, 1)
  100.             running = false
  101.         else
  102.             for k, v in pairs(tasks) do
  103.                 if y - tasksStartOffset == k then
  104.                     table.remove(tasks,  k)
  105.                     save()
  106.                     init()
  107.                     draw()  
  108.                 end
  109.             end
  110.         end
  111.     end
  112. end
  113.  
  114. init()
  115. draw()
  116. update()
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement