PaffcioStudio

Kompter - Lista zadan

Feb 4th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1, 1)
  3.  
  4. local side = nil
  5. for _, s in pairs(rs.getSides()) do
  6.   if peripheral.getType(s) == "monitor" then
  7.     side = s
  8.   end
  9. end
  10.  
  11. m = peripheral.wrap(side)
  12.  
  13. local x
  14. local y
  15. x, y = m.getSize()
  16. local page = 1
  17. m = peripheral.wrap("right")
  18.  
  19. local things = {""}
  20.  
  21. function saveAll()
  22.   local file = fs.open("tasks", "w")
  23.   file.write(textutils.serialize(things))
  24.   file.close()
  25. end
  26.  
  27. function loadAll()
  28.   local file = fs.open("tasks", "r")
  29.   local data = file.readAll()
  30.   file.close()
  31.   data = textutils.unserialize(data)
  32.   for i = 1, #data do
  33.     things[i] = data[i]
  34.   end
  35. end
  36.  
  37. function mainLoop()
  38.   loadAll()
  39.   m.clear()
  40.   printTop()
  41.   for i = 1, y-2 do
  42.     printLine(i)
  43.   end
  44.   printButtons()
  45.   term.clear()
  46.   term.setCursorPos(1, 1)
  47.   term.setTextColor(colors.white)
  48.   print("Chcesz dodac czy usunac notatke?")
  49.   term.setTextColor(colors.lime)
  50.   term.write("  Dodaj")
  51.   term.setTextColor(colors.red)
  52.   print("       Usun")
  53.   term.setTextColor(colors.white)
  54.  
  55.   event, a, b, c = os.pullEvent()
  56.   if event == "mouse_click" then
  57.     if c == 2 then
  58.       if (b == 3) or (b >= 4) and (b <= 7) then
  59.         print("")
  60.         print("Co chcesz zrobic?")
  61.         task = read()
  62.         things[#things+1] = task
  63.         saveAll()
  64.         sleep(0.2)
  65.         print("Zadanie dodane!")
  66.         sleep(0.5)
  67.       elseif (c == 13) or (b >= 13) and (b <= 25) then
  68.         print("")
  69.         print("Ktore zadanie chcesz usunac? (Podaj liczbe)")
  70.         task = read()
  71.         print("Na pewno? (t/n)")
  72.         answ = read()
  73.         if (answ == "t") or (answ == "T") then
  74.           print("Usunieto " ..task)
  75.           for i = task, #things - 1 do
  76.             things[i] = things[i+1]
  77.           end
  78.           things[#things] = nil
  79.           saveAll()
  80.           sleep(0.2)
  81.           print("Notatka usunieta!")
  82.           sleep(0.5)
  83.         end
  84.       end
  85.     end
  86.   end
  87.    
  88.   if event == "monitor_touch" then
  89.     if c == y then
  90.       if (b == 2) or (b == 3) or (b == 4) or (b ==5) then
  91.         if page > 1 then
  92.           page = page-1
  93.         end
  94.       elseif (b == x-4) or (b == x-3) or (b == x-2) or (b == x-1) then
  95.         page = page+1
  96.       end
  97.     end
  98.   end
  99.   mainLoop()  
  100. end
  101.  
  102.  
  103. function printButtons()
  104.   m.setCursorPos(2, y)
  105.   if page == 1 then
  106.     m.setTextColor(colors.lightGray)
  107.   else
  108.     m.setTextColor(colors.black)
  109.   end
  110.   m.setBackgroundColor(colors.white)
  111.   m.write("Wstecz")
  112.  
  113.   m.setTextColor(colors.black)
  114.   m.setCursorPos(x/2, y)
  115.   m.write("" ..page)
  116.   m.setCursorPos(x-4, y)
  117.   m.write("Dalej")
  118. end
  119.  
  120. function printTop()
  121.   m.setBackgroundColor(colors.white)
  122.   m.setTextColor(colors.black)
  123.   m.setCursorPos(x/2-5, 1)
  124.   m.write("Do zrobienia:")
  125. end
  126.  
  127. function printLine(num)
  128.   if num % 2 == 0 then
  129.     m.setBackgroundColor(colors.gray)
  130.   else
  131.     m.setBackgroundColor(colors.lightGray)
  132.   end
  133.   m.setCursorPos(1, num+1)
  134.   if page > 1 then
  135.     num = num+(x*(page-1))
  136.   end
  137.   m.write("" ..num)
  138.   m.write(": ")
  139.  
  140.   if things[num] ~= nil then
  141.     m.write("" ..things[num])
  142.     m.write("                                                                                           ")
  143.   else
  144.     m.write("                                                                                           ")
  145.   end
  146. end
  147.  
  148. mainLoop()
Add Comment
Please, Sign In to add comment