BruceWplays

Untitled

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