Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------STARTUP----------
- monitor = peripheral.wrap("right")
- term.redirect(monitor)
- term.clear()
- screen = paintutils.loadImage("main.nfp")
- fileR = fs.open("things.lua", "r")
- paintutils.drawImage(screen, 1, 1)
- ------VARIABLES-------------
- tasksB = {}
- mes = ""
- line = ""
- a = ""
- sState = "main"
- currentGoal = "test"
- searchScroll = 1
- x, y = term.getSize()
- cx = x/2
- cy = y/2
- -------Functions----------
- function cMes(inputMes)
- local ret = cx - #inputMes/2
- return ret
- end
- function compareClick(click, minX, maxX, minY, maxY)
- --print(click[1])
- --print(click[2])
- if click[1] > minX and click[1] < maxX then
- if click[2] > minY and click[2] < maxY then
- --print("Success!")
- --sleep(1)
- return true
- else
- --print("Failure")
- --sleep(1)
- return false
- end
- else
- return false
- end
- end
- --- Load Things to "tasksB" list
- function loadS()
- fileR = fs.open("things.lua", "r")
- while true do
- line = fileR.readLine()
- if line == nil then
- break
- else
- --term.setCursorPos(1,1)
- --term.write(line)
- --print("e " .. line)
- --sleep(0.5)
- table.insert(tasksB, line)
- end
- end
- term.setCursorPos(1,y)
- term.write("all loaded")
- end
- -- Creates all the lables
- function labels()
- if sState == "main" then
- mes = "CC"
- term.setCursorPos(cx - #mes/2, cy - 2)
- term.write(mes)
- term.setCursorPos(cMes(currentGoal), cy)
- term.write(currentGoal)
- end
- if sState == "add" then
- end
- if sState == "remove" then
- end
- if sState == "Display" then
- mes = "Your Task Is: "
- term.setCursorPos(cMes(mes), 7)
- term.setBackgroundColor(colors.combine(colors.lightBlue, colors.cyan))
- term.write(mes)
- end
- end
- -- Recreates Base Screen
- function updateScreen()
- drawing = paintutils.loadImage(sState .. ".nfp")
- term.setCursorPos(1, y)
- term.setBackgroundColor(colors.cyan)
- term.write("Drawing " .. sState)
- sleep(1)
- paintutils.drawImage(drawing, 1, 1)
- labels()
- if sState == "remove" then
- updateRemoveScreen(searchScroll)
- end
- if sState == "main" then
- term.setCursorPos(41, 2)
- local dateFile = fs.open("lastUpdate.lua", "r")
- local date = dateFile.readLine()
- term.write(date)
- end
- end
- -- Gets click position
- function getClick()
- local event, side, x, y = os.pullEvent("monitor_touch")
- local lis = {}
- table.insert(lis, x)
- table.insert(lis, y)
- return lis
- end
- -- Finds currGoal
- function findGoal(inputList)
- local theGoal = inputList[1]
- for i = 2, #inputList, 1 do
- local timOne = tonumber(string.sub(theGoal, 1, 2))
- local impOne = tonumber(string.sub(theGoal, 6, 7))
- local timTwo = tonumber(string.sub(inputList[i], 1, 2))
- local impTwo = tonumber(string.sub(inputList[i], 6, 7))
- local vOne = (timOne / 2) - (impOne * 3 )
- local vTwo = (timTwo / 2) - (impTwo * 3 )
- if vOne > vTwo then
- theGoal = inputList[i]
- end
- end
- return theGoal
- end
- -- updates Remove Screen
- function getAfterTen(inputStr)
- local output = string.sub(inputStr, 10, #inputStr)
- return output
- end
- function updateRemoveScreen(searchScrollIn)
- term.setCursorPos(17, 7)
- term.write(getAfterTen(tasksB[searchScrollIn]))
- end
- function timeForward(inputList)
- local outList = {}
- for i = 1, #inputList, 1 do
- local newString = inputList[i]
- local newNum = tonumber(string.sub(newString, 1, 2))
- newNum = newNum - 1
- ----- Formatting
- if newNum < 10 then
- newNum = tostring(newNum)
- newNum = "0" .. newNum
- else
- newNum = tostring(newNum)
- end
- -----
- newNum = newNum .. string.sub(newString, 3, #newString)
- table.insert(outList, newNum)
- end
- return outList
- end
- -- Start Up Code -----------
- loadS()
- -------------------------
- sleep(0.1)
- while true do
- updateScreen()
- --------------MAIN SCREEN------------------------
- if sState == "main" then
- local click = getClick()
- term.setCursorPos(1,1)
- print("CLICK X : " .. click[1])
- print("CLICK Y : " .. click[2])
- ---------- Save And Quit Button ------------------------
- if compareClick(click, 40, 45, 2, 6) then
- sleep(1)
- local b = fs.open("things.lua", "w")
- for i = 1, #tasksB, 1 do
- b.write(tasksB[i] .. "\n")
- --sleep(0.5)
- end
- term.setCursorPos(41, 2)
- term.setBackgroundColor(colors.lightBlue)
- term.write("Done")
- b.close()
- term.clear()
- os.shutdown()
- end
- ----- Add Button ---------
- if compareClick(click, 4, 14, 14, 18) then
- print("heard")
- sState = "add"
- end
- ---- Subtract Button ------
- if compareClick(click, 36, 46, 14, 18) then
- print("heard")
- sState = "remove"
- end
- --- Refresh Button ------
- if compareClick(click, 19, 30, 12, 17) then
- print("heard")
- sState = "Display"
- end
- -- Time Forward Button ------
- if compareClick(click, 3, 7, 3, 6) then
- print("heard")
- tasksB = timeForward(tasksB)
- end
- -------------------
- else
- ------------Adding Screen Logic-------------------------------------
- if sState == "add" then
- updateScreen()
- term.setCursorPos(14, 12)
- term.write("Format: 00 + 00 = 'task'")
- term.setCursorPos(15, 13)
- local new = read()
- print("adding " .. new)
- sleep(2)
- table.insert(tasksB, new)
- sState = "main"
- else
- ------------Removing Screen Logic-------------------------------------
- if sState == "remove" then
- updateScreen()
- local click = getClick()
- ---- Select
- if compareClick(click, 17, 33, 14, 18) then
- table.remove(tasksB, searchScroll)
- searchScroll = 1
- sState = "main"
- end
- ---- Up
- if compareClick(click, 35, 41, 2, 8) then
- if searchScroll < #tasksB then
- searchScroll = searchScroll + 1
- updateRemoveScreen(searchScroll)
- end
- end
- ---- Down
- if compareClick(click, 35, 41, 12, 18) then
- if searchScroll > 1 then
- searchScroll = searchScroll - 1
- updateRemoveScreen(searchScroll)
- end
- end
- ---- Exit
- if compareClick(click, 44, 49, 1, 5) then
- sState = "main"
- searchScroll = 1
- end
- else
- ------------Displaying Screen Logic---------------
- if sState == "Display" then
- updateScreen()
- local currGoal = findGoal(tasksB)
- --print(tasksB[#tasksB])
- --print("numtask " .. #tasksB)
- currGoal = string.sub(currGoal, 11, #currGoal)
- term.setCursorPos(cMes(currGoal), 10)
- term.write(currGoal)
- local click = getClick()
- sState = "main"
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement