Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Idea from SOLLY
- Created by LostboyDev
- 7/18/22
- This is for advanced and advanced monitors only
- green button to add a task, red button to close
- ]]
- local m = peripheral.find ("monitor")
- local width, height = m.getSize()
- local running = true
- local addBtnPos = {x = 1, y = height}
- local exitBtnPos = {x = width, y = height}
- local tasks = {}
- local tasksStartOffset = 3
- function init()
- m.setBackgroundColor(colors.white)
- m.clear()
- m.setCursorPos(1, 1)
- load()
- end
- -- not finished
- function load()
- if not fs.exists("tasks") then
- return
- end
- local file = fs.open("tasks", "r")
- local data = textutils.unserialise(file.readAll())
- tasks = data
- file.close()
- end
- function save()
- local file = fs.open("tasks", "w")
- local data = textutils.serialise(tasks)
- file.write(data)
- file.close()
- end
- function centeredText(str, y)
- local stringWidth = #str
- local newX = math.floor((width - stringWidth) / 2)
- m.setCursorPos(newX, y)
- m.write(str)
- end
- function drawPix(x, y, color)
- m.setCursorPos(x, y)
- m.setBackgroundColor(color)
- m.write(" ")
- end
- function draw()
- drawPix(addBtnPos.x, addBtnPos.y, colors.green)
- drawPix(exitBtnPos.x, exitBtnPos.y, colors.red)
- m.setTextColor(colors.black)
- m.setBackgroundColor(colors.white)
- centeredText("Todo List", 2)
- centeredText("LostboyDev", height)
- for k, v in pairs(tasks) do
- m.setTextColor(colors.cyan)
- centeredText("[" .. k .. "] " ..v, k + tasksStartOffset)
- end
- end
- function update()
- while running do
- event, side, x, y = os.pullEvent("monitor_touch")
- if x == addBtnPos.x and y == addBtnPos.y then
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- term.write("Enter new Task: ")
- m.setBackgroundColor(colors.white)
- centeredText("Please Type Info In Computer", height/2)
- local input = read()
- table.insert(tasks, input)
- term.clear()
- term.setCursorPos(1, 1)
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.black)
- m.clear()
- save()
- draw()
- elseif x == exitBtnPos.x and y == exitBtnPos.y then
- term.setBackgroundColor(colors.black )
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- running = false
- else
- for k, v in pairs(tasks) do
- if y - tasksStartOffset == k then
- table.remove(tasks, k)
- save()
- init()
- draw()
- end
- end
- end
- end
- end
- init()
- draw()
- update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement