BruceWplays

Untitled

Jun 16th, 2022 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.35 KB | None | 0 0
  1. local isUsing = true
  2. local maxX, maxY = term.getSize()
  3. local color1 = colors.lime
  4. local color2 = colors.white
  5. local disptime = 0
  6. if fs.exists("/.todocfg") then
  7.   local opfile = fs.open("/.todocfg", "r")
  8.   color1 = tonumber(opfile.readLine())
  9.   color2 = tonumber(opfile.readLine())
  10.   opfile.close()
  11. end
  12.  
  13. local colnames = {[0] = "White",
  14.                 [1] = "Orange",
  15.                 [2] = "Magenta",
  16.                 [3] = "Light Blue",
  17.                 [4] = "Yellow",
  18.                 [5] = "Lime",
  19.                 [6] = "Pink",
  20.                 [7] = "Gray",
  21.                 [8] = "Light Gray",
  22.                 [9] = "Cyan",
  23.                 [10] = "Purple",
  24.                 [11] = "Blue",
  25.                 [12] = "Brown",
  26.                 [13] = "Green",
  27.                 [14] = "Red",
  28.                 [15] = "Black"}
  29.                
  30. local numconv = {[0] = colors.white,
  31.                 [1] = colors.orange,
  32.                 [2] = colors.magenta,
  33.                 [3] = colors.lightBlue,
  34.                 [4] = colors.yellow,
  35.                 [5] = colors.lime,
  36.                 [6] = colors.pink,
  37.                 [7] = colors.gray,
  38.                 [8] = colors.lightGray,
  39.                 [9] = colors.cyan,
  40.                 [10] = colors.purple,
  41.                 [11] = colors.blue,
  42.                 [12] = colors.brown,
  43.                 [13] = colors.green,
  44.                 [14] = colors.red,
  45.                 [15] = colors.black}
  46.  
  47. --Maybe need to rewrite this :P
  48. local choice = 0
  49. local choice2 = 0
  50. while numconv[choice] ~= color1 do
  51.     choice=choice+1
  52. end
  53. while numconv[choice2] ~= color2 do
  54.     choice2=choice2+1
  55. end
  56. local taskFile = "/.tasks"
  57. local page = 1
  58. local Options = false
  59.  
  60. local function getTasks()
  61.  if not fs.exists(taskFile) then
  62.   local A = fs.open(taskFile, "w")
  63.   A.write("{}")
  64.   A.close()
  65.   return {}
  66.  else
  67.   local A = fs.open(taskFile, "r")
  68.   local tmp = textutils.unserialize(A.readAll())
  69.   A.close()
  70.   return tmp
  71.  end
  72. end
  73.  
  74. local function redraw(page)
  75.  if isUsing and not Options then
  76.     local tasks = getTasks()
  77.     local nMaxY = maxY - 2
  78.  
  79.     term.clear()
  80.     term.setCursorPos(1,1)
  81.     term.setBackgroundColour(color1)
  82.     if color1 ~= color2 and color1 ~= colors.white then
  83.         term.setTextColour(color2)
  84.     elseif color1 == color2 and color1 ~= colors.white then
  85.         term.setTextColor(colors.white)
  86.     else
  87.         term.setTextColor(colors.black)
  88.     end
  89.     term.clearLine()
  90.     print(" + / -  |")
  91.     term.setCursorPos(maxX-12,1)
  92.     print("Options  Exit")
  93.    
  94.     for i=1, nMaxY do
  95.         if i%2 == 1 and color1 ~= color2 then
  96.             term.setBackgroundColour(color2)
  97.             term.setTextColour(color1)
  98.         elseif color1 ~= color2 then
  99.             term.setBackgroundColour(color1)
  100.             term.setTextColour(color2)
  101.         elseif color1 == colors.white then
  102.             term.setBackgroundColor(color1)
  103.             term.setTextColor(colors.black)
  104.         else
  105.             term.setBackgroundColor(color1)
  106.             term.setTextColor(colors.black)
  107.         end
  108.  
  109.         term.setCursorPos(1,1+i)
  110.         term.clearLine()
  111.  
  112.         local num = i+(nMaxY*(page-1))
  113.  
  114.         if tasks[num] ~= nil then
  115.             write(num..": "..tasks[num])
  116.         else
  117.             write(num..": ")
  118.         end
  119.     end
  120.  
  121.  if maxY%2 == 0 and color1 ~= color2 then
  122.   term.setBackgroundColour(color2)
  123.   term.setTextColour(color1)
  124.  elseif color1 ~= color2 then
  125.   term.setBackgroundColour(color1)
  126.   term.setTextColour(color2)
  127.  elseif color1 == colors.white then
  128.     term.setBackgroundColor(color1)
  129.     term.setTextColor(colors.black)
  130.  else
  131.     term.setBackgroundColor(color1)
  132.     term.setTextColor(colors.white)
  133.  end
  134. term.setCursorPos(2,maxY)
  135.  term.clearLine()
  136.  write("<")
  137.  term.setCursorPos((maxX/2-#tostring(page)/2)+1,maxY)
  138.  write(page)
  139.  term.setCursorPos(maxX-1,maxY)
  140.  write(">")
  141.        
  142.        
  143.        
  144.        
  145.        
  146.         term.setCursorPos(10,1)
  147. print(textutils.formatTime(os.time(), false))
  148.        
  149.        
  150.       local disptime = os.clock()
  151.        
  152.        
  153.  elseif not isUsing and not Options then --Exited program
  154.     term.setBackgroundColor(colors.black)
  155.     term.setTextColor(colors.white)
  156.     term.clear()
  157.     term.setCursorPos(1,1)
  158.     print("Goodbye !")
  159.  elseif isUsing and Options then
  160.     term.setBackgroundColor(colors.gray)
  161.     if color1 ~= colors.white then
  162.         term.setTextColor(colors.white)
  163.     else
  164.         term.setTextColor(colors.black)
  165.     end
  166.     term.clear()
  167.     color1 = numconv[choice]
  168.     color2 = numconv[choice2]
  169.     term.setCursorPos(1,1)
  170.     term.setBackgroundColor(color1)
  171.     term.clearLine()
  172.     term.setCursorPos(maxX-(maxX-2),1)
  173.     print("Options")
  174.     term.setCursorPos(math.ceil(maxX/2)+1,1)
  175.     print("|")
  176.     term.setCursorPos(maxX-6,1)
  177.     print("Return")
  178.     term.setBackgroundColor(colors.gray)
  179.     term.setTextColor(colors.white)
  180.     term.setCursorPos(15,3)
  181.     print("<->")
  182.     paintutils.drawLine(14,4,14+string.len(colnames[choice]),4,numconv[choice])
  183.     term.setCursorPos(3,4)
  184.     if color1 ~= colors.white then
  185.         term.setTextColor(colors.white)
  186.     else
  187.         term.setTextColor(colors.black)
  188.     end
  189.     print("1st color : " .. colnames[choice])
  190.     term.setBackgroundColor(colors.gray)
  191.     paintutils.drawLine(14,6,14+string.len(colnames[choice2]),6,numconv[choice2])
  192.     if color2 ~= colors.white then
  193.         term.setTextColor(colors.white)
  194.     else
  195.         term.setTextColor(colors.black)
  196.     end
  197.     term.setCursorPos(3,6)
  198.     print("2nd color : " .. colnames[choice2])
  199.     term.setBackgroundColor(colors.gray)
  200.     term.setTextColor(colors.white)
  201.     term.setCursorPos(15,7)
  202.     print("<->")
  203.     term.setCursorPos(5,10)
  204.     print("About this program")
  205.     term.setCursorPos(4,12)
  206.     print("HD's Todo list V1.6")
  207.     term.setCursorPos(1,14)
  208.     print("-masterdisasterHD : Orignal program and idea")
  209.     term.setCursorPos(1,17)
  210.     print("-s0r00t : V1.5 enhancements")
  211.    
  212.  end
  213. end
  214.  
  215. local function saveTasks(tbl)
  216.  local A = fs.open(taskFile, "w")
  217.  A.write(textutils.serialize(tbl))
  218.  A.close()
  219. end
  220.  
  221. local function addTask()
  222.  local tasks = getTasks()
  223.  term.setBackgroundColour(colors.black)
  224.  term.setTextColour(colors.white)
  225.  term.clear()
  226.  term.setCursorPos(1,1)
  227.  term.setCursorBlink(true)
  228.  write("Task: ")
  229.  local tsk = read()
  230.  table.insert(tasks, tsk)
  231.  saveTasks(tasks)
  232. end
  233.  
  234. local function delTask()
  235.  local tasks = getTasks()
  236.  term.setBackgroundColour(colors.black)
  237.  term.setTextColour(colors.white)
  238.  term.clear()
  239.  term.setCursorPos(1,1)
  240.  write("Task number: ")
  241.  local tsknmbr = tonumber(read())
  242.  table.remove(tasks, tsknmbr)
  243.  saveTasks(tasks)
  244. end
  245.  
  246. local function showTask(pg, pos, h, w)
  247.  local tasks = getTasks()
  248.  local step1 = (h-2)*(pg-1)
  249.  local step2 = (pos-1)+step1
  250.  term.setBackgroundColour(color2)
  251.  term.setTextColour(color1)
  252.  term.clear()
  253.  term.setCursorPos(1,1)
  254.  if tasks[step2] ~= nil then
  255.   write("Task #"..step2..":")
  256.   local text = tasks[step2]
  257.   local k = 1
  258.   for i=1, h-1 do
  259.    term.setCursorPos(1,i+1)
  260.    for j=1,w do
  261.     write(string.sub(text, k, k))
  262.     k = k + 1
  263.    end
  264.   end
  265.  term.setCursorPos(1,h)
  266.  write("Press any key to continue")
  267.  os.pullEvent("key")
  268.  end
  269. end
  270.  
  271. --Program loop
  272.  redraw(page)
  273. local maxX, maxY = term.getSize()
  274. while isUsing do
  275.  sleep(0)
  276.    if os.clock() - disptime > 0.1 then
  277.     redraw(page)
  278.         end
  279.     redraw(page)
  280.    
  281.    
  282.  
  283.            
  284.        
  285.  ev, b, xPos, yPos = os.pullEvent()
  286.  if ev == "mouse_click" then
  287.   if xPos == 2 and yPos == 1 and not Options then
  288.    addTask()
  289.   elseif xPos == 6 and yPos == 1 and not Options then
  290.    delTask()
  291.   elseif xPos >= maxX-12 and xPos <= maxX-4 and yPos == 1 and not Options then
  292.   Options = true
  293.   elseif xPos >=maxX-3 and xPos <= maxX and yPos == 1 and not Options then
  294.   isUsing = false
  295.   elseif xPos == 2 and yPos == maxY and not Options then
  296.    if page > 1 then
  297.     page = page - 1
  298.    end
  299.   elseif xPos == maxX-1 and yPos == maxY and not Options then
  300.    page = page + 1
  301.   elseif xPos > 1 and yPos < maxY and not Options then
  302.    showTask(page, yPos, maxY, maxX)
  303.   elseif xPos >= maxX-6 and xPos <= maxX-1 and yPos == 1 and Options then
  304.    Options = false
  305.    local opfile = fs.open("/.todocfg", "w")
  306.    opfile.writeLine(color1)
  307.    opfile.write(color2)
  308.    opfile.close()
  309.   elseif xPos == 15 and yPos == 3 and Options then
  310.     if choice-1 ~= -1 then
  311.         choice = choice-1
  312.     else
  313.         choice = 15
  314.     end
  315.     redraw(page)
  316.   elseif xPos == 17 and yPos == 3 and Options then
  317.     if choice+1 ~= 16 then
  318.         choice = choice+1
  319.     else
  320.         choice = 0
  321.     end
  322.     redraw(page)
  323.   elseif xPos == 15 and yPos == 7 and Options then
  324.     if choice2-1 ~= -1 then
  325.         choice2 = choice2-1
  326.     else
  327.         choice2 = 15
  328.     end
  329.     redraw(page)
  330.   elseif xPos == 17 and yPos == 7 and Options then
  331.     if choice2+1 ~= 16 then
  332.         choice2 = choice2+1
  333.     else
  334.         choice2 = 0
  335.     end
  336.     redraw(page)
  337.  
  338.    
  339.  elseif ev == "mouse_scroll" then
  340.   if b == -1 then
  341.    if page > 1 then page = page - 1 end
  342.   elseif b == 1 then
  343.    page = page + 1
  344.   end
  345.  end
  346.         clockTimer = os.startTimer(.1) -- Start the timer for the first time
  347. while true do
  348.         if evt == "timer" then
  349.            
  350.             redraw(page)
  351.            
  352.            
  353.             else
  354.             end
  355.             end    
  356.  redraw(page)
  357. end
  358. end
Add Comment
Please, Sign In to add comment