Advertisement
Greenstar12345

start.lua

Feb 2nd, 2023 (edited)
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------STARTUP----------
  2. monitor = peripheral.wrap("right")
  3. term.redirect(monitor)
  4. term.clear()
  5. screen = paintutils.loadImage("main.nfp")
  6. fileR = fs.open("things.lua", "r")
  7.  
  8.  
  9. paintutils.drawImage(screen, 1, 1)
  10.  
  11. ------VARIABLES-------------
  12. tasksB = {}
  13. mes = ""
  14. line = ""
  15. a = ""
  16. sState = "main"
  17. currentGoal = "test"
  18. searchScroll = 1
  19. x, y = term.getSize()
  20. cx = x/2
  21. cy = y/2
  22.  
  23. -------Functions----------
  24. function cMes(inputMes)
  25.     local ret = cx - #inputMes/2
  26.     return ret    
  27.  
  28. end
  29. function compareClick(click, minX, maxX, minY, maxY)
  30.     --print(click[1])
  31.     --print(click[2])
  32.     if click[1] > minX and click[1] < maxX then
  33.         if click[2] > minY and click[2] < maxY then
  34.             --print("Success!")
  35.             --sleep(1)
  36.             return true
  37.         else
  38.             --print("Failure")
  39.             --sleep(1)
  40.             return false
  41.         end
  42.     else
  43.     return false
  44.     end
  45. end
  46. --- Load Things to "tasksB" list
  47. function loadS()
  48.     fileR = fs.open("things.lua", "r")
  49.     while true do
  50.         line = fileR.readLine()
  51.         if line == nil then
  52.             break
  53.         else
  54.         --term.setCursorPos(1,1)
  55.         --term.write(line)
  56.         --print("e " .. line)
  57.         --sleep(0.5)
  58.         table.insert(tasksB, line)
  59.         end
  60.     end
  61.     term.setCursorPos(1,y)
  62.     term.write("all loaded")
  63. end
  64.  
  65. -- Creates all the lables
  66. function labels()
  67.     if sState == "main" then
  68.         mes = "CC"
  69.         term.setCursorPos(cx - #mes/2, cy - 2)
  70.         term.write(mes)
  71.         term.setCursorPos(cMes(currentGoal), cy)
  72.         term.write(currentGoal)
  73.     end
  74.     if sState == "add" then
  75.        
  76.     end
  77.     if sState == "remove" then
  78.    
  79.     end
  80.     if sState == "Display" then
  81.         mes = "Your Task Is: "
  82.         term.setCursorPos(cMes(mes), 7)
  83.         term.setBackgroundColor(colors.combine(colors.lightBlue, colors.cyan))
  84.         term.write(mes)
  85.     end
  86. end
  87.  
  88. -- Recreates Base Screen
  89. function updateScreen()
  90.     drawing = paintutils.loadImage(sState .. ".nfp")
  91.     term.setCursorPos(1, y)
  92.     term.setBackgroundColor(colors.cyan)
  93.     term.write("Drawing " .. sState)
  94.     sleep(1)
  95.     paintutils.drawImage(drawing, 1, 1)
  96.     labels()
  97.     if sState == "remove" then
  98.     updateRemoveScreen(searchScroll)
  99.     end
  100.     if sState == "main" then
  101.         term.setCursorPos(41, 2)
  102.         local dateFile = fs.open("lastUpdate.lua", "r")
  103.         local date = dateFile.readLine()
  104.         term.write(date)
  105.     end
  106. end
  107.  
  108. -- Gets click position
  109. function getClick()
  110.     local event, side, x, y = os.pullEvent("monitor_touch")
  111.     local lis = {}
  112.     table.insert(lis, x)
  113.     table.insert(lis, y)
  114.     return lis
  115. end
  116.  
  117. -- Finds currGoal
  118. function findGoal(inputList)
  119.     local theGoal = inputList[1]
  120.     for i = 2, #inputList, 1 do
  121.  
  122.         local timOne = tonumber(string.sub(theGoal, 1, 2))
  123.         local impOne = tonumber(string.sub(theGoal, 6, 7))
  124.  
  125.         local timTwo = tonumber(string.sub(inputList[i], 1, 2))
  126.         local impTwo = tonumber(string.sub(inputList[i], 6, 7))
  127.  
  128.         local vOne = (timOne / 2) - (impOne * 3 )
  129.         local vTwo = (timTwo / 2) - (impTwo * 3 )
  130.  
  131.         if vOne > vTwo then
  132.             theGoal = inputList[i]
  133.         end
  134.     end
  135.  
  136.     return theGoal
  137. end
  138.  
  139. -- updates Remove Screen
  140. function getAfterTen(inputStr)
  141.     local output = string.sub(inputStr, 10, #inputStr)
  142.     return output    
  143. end
  144.  
  145. function updateRemoveScreen(searchScrollIn)
  146.     term.setCursorPos(17, 7)    
  147.     term.write(getAfterTen(tasksB[searchScrollIn]))
  148. end
  149.  
  150. function timeForward(inputList)
  151.     local outList = {}
  152.     for i = 1, #inputList, 1 do
  153.        local newString = inputList[i]
  154.        local newNum = tonumber(string.sub(newString, 1, 2))
  155.        newNum = newNum - 1
  156.        ----- Formatting
  157.        if newNum < 10 then
  158.             newNum = tostring(newNum)
  159.             newNum = "0" .. newNum
  160.        else
  161.             newNum = tostring(newNum)
  162.        end
  163.        -----
  164.        newNum = newNum .. string.sub(newString, 3, #newString)
  165.        table.insert(outList, newNum)
  166.     end
  167.     return outList
  168. end
  169.  
  170. -- Start Up Code -----------
  171. loadS()
  172.  
  173. -------------------------
  174.  
  175. sleep(0.1)
  176. while true do
  177.     updateScreen()
  178.  
  179.     --------------MAIN SCREEN------------------------
  180.  
  181.     if sState == "main" then
  182.         local click = getClick()
  183.         term.setCursorPos(1,1)
  184.         print("CLICK X : " .. click[1])
  185.         print("CLICK Y : " .. click[2])
  186.         ---------- Save And Quit Button ------------------------
  187.         if compareClick(click, 40, 45, 2, 6) then
  188.             sleep(1)
  189.             local b = fs.open("things.lua", "w")
  190.             for i = 1, #tasksB, 1 do
  191.  
  192.             b.write(tasksB[i] .. "\n")
  193.             --sleep(0.5)
  194.             end
  195.             term.setCursorPos(41, 2)
  196.             term.setBackgroundColor(colors.lightBlue)
  197.             term.write("Done")
  198.             b.close()
  199.             term.clear()
  200.             os.shutdown()
  201.         end
  202.  
  203.         ----- Add Button ---------
  204.  
  205.         if compareClick(click, 4, 14, 14, 18) then
  206.             print("heard")
  207.             sState = "add"
  208.         end
  209.  
  210.         ----  Subtract Button ------
  211.  
  212.         if compareClick(click, 36, 46, 14, 18) then
  213.             print("heard")
  214.             sState = "remove"
  215.         end
  216.  
  217.         ---  Refresh Button ------
  218.         if compareClick(click, 19, 30, 12, 17) then
  219.             print("heard")
  220.             sState = "Display"
  221.         end
  222.  
  223.         -- Time Forward Button ------
  224.         if compareClick(click, 3, 7, 3, 6) then
  225.             print("heard")
  226.             tasksB = timeForward(tasksB)
  227.         end
  228.  
  229.         -------------------
  230.     else
  231.         ------------Adding Screen Logic-------------------------------------
  232.         if sState == "add" then
  233.            
  234.             updateScreen()
  235.             term.setCursorPos(14, 12)
  236.             term.write("Format: 00 + 00 = 'task'")
  237.             term.setCursorPos(15, 13)
  238.             local new = read()
  239.             print("adding " .. new)
  240.             sleep(2)
  241.             table.insert(tasksB, new)
  242.             sState = "main"
  243.  
  244.  
  245.  
  246.  
  247.         else
  248.             ------------Removing Screen Logic-------------------------------------
  249.             if sState == "remove" then
  250.                 updateScreen()
  251.                
  252.  
  253.                 local click = getClick()
  254.                 ---- Select
  255.                 if compareClick(click, 17, 33, 14, 18) then
  256.                     table.remove(tasksB, searchScroll)
  257.                     searchScroll = 1
  258.                     sState = "main"
  259.                 end
  260.                 ---- Up
  261.                 if compareClick(click, 35, 41, 2, 8) then
  262.                     if searchScroll < #tasksB then
  263.                         searchScroll = searchScroll + 1
  264.                         updateRemoveScreen(searchScroll)
  265.                     end
  266.                 end
  267.                 ---- Down
  268.                 if compareClick(click, 35, 41, 12, 18) then
  269.                     if searchScroll > 1 then
  270.                         searchScroll = searchScroll - 1
  271.                         updateRemoveScreen(searchScroll)
  272.                     end
  273.                 end
  274.                 ---- Exit
  275.                 if compareClick(click, 44, 49, 1, 5) then
  276.                     sState = "main"
  277.                     searchScroll = 1
  278.                 end
  279.  
  280.  
  281.  
  282.             else
  283.                 ------------Displaying Screen Logic---------------
  284.                 if sState == "Display" then
  285.                     updateScreen()
  286.                     local currGoal = findGoal(tasksB)
  287.                     --print(tasksB[#tasksB])
  288.                     --print("numtask " .. #tasksB)
  289.                     currGoal = string.sub(currGoal, 11, #currGoal)
  290.                     term.setCursorPos(cMes(currGoal), 10)
  291.                     term.write(currGoal)
  292.                    
  293.                     local click = getClick()
  294.                     sState = "main"
  295.                 end
  296.             end
  297.         end
  298.     end
  299.  
  300. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement