Advertisement
jamawie

Archivsystem

Aug 7th, 2016
22,744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.55 KB | None | 0 0
  1. --Archiv programm
  2.  
  3. mon = peripheral.wrap("back")
  4. anzahl = 15
  5.  
  6. playernames = {}
  7. scrollnumber = 1
  8. guiname="start"
  9. selected=""
  10. timertime=120
  11.  
  12. colorcodes = {colors.white,colors.blue,colors.lime,colors.red,colors.brown,colors.yellow}
  13.  
  14. function buttondraw(xp1,yp1,xp2,yp2,txt,col)
  15.  if col==nil then
  16.  mon.setBackgroundColor(colors.lime)
  17.  else
  18.  mon.setBackgroundColor(col)
  19.  end
  20.  mon.setCursorPos(xp1,yp1)
  21.  for i=1,(xp2-xp1) do
  22.   mon.write("-")
  23.  end
  24.  mon.setCursorPos(xp1,yp2)
  25.  for i=1,(xp2-xp1) do
  26.   mon.write("-")
  27.  end
  28.  for i=yp1,yp2 do
  29.   mon.setCursorPos(xp1,i)
  30.   mon.write("|")
  31.   mon.setCursorPos(xp2,i)
  32.   mon.write("|")
  33.  end
  34.  for i=(yp1+1),(yp2-1) do
  35.   mon.setCursorPos((xp1+1),i)
  36.   for j=(xp1+1),(xp2-1) do
  37.    mon.write(" ")
  38.    j = j+1
  39.   end
  40.   i = i+1
  41.  end
  42.  if math.floor(((xp2-xp1)-#txt)/2)==0 then
  43.   xp1 = xp1+1
  44.  end
  45.  mon.setCursorPos(math.floor(((xp2-xp1)-#txt)/2)+xp1,math.floor((yp2-yp1)/2)+yp1)
  46.  print(math.floor(((xp2-xp1)-#txt)/2))
  47.  mon.write(txt)
  48. end
  49.  
  50. function bdraw(xP,yP, str, ison)
  51.     mon.setCursorPos(xP, yP)
  52.     if ison then
  53.         mon.setBackgroundColor(colors.lime)
  54.     else
  55.         mon.setBackgroundColor(colors.red)
  56.     end
  57.  
  58.     for i=1,16 do
  59.         mon.write(" ")
  60.     end
  61.  
  62.     mon.setCursorPos(xP+((16-#str)/2),yP)
  63.     mon.write(str)
  64. end
  65.  
  66. function midwrite(txt, yP)
  67.     x,y = mon.getSize()
  68.     xP = (x-#txt)/2
  69.     mon.setCursorPos(xP,yP)
  70.     mon.write(txt)
  71. end
  72.  
  73.  
  74. function checkButtons(xPos, yPos)
  75.     x,y = mon.getSize()
  76.    
  77.     if guiname=="start" then
  78.         if xPos>=1 and xPos<=1
  79.         and yPos>=3 and yPos<=4 then
  80.             if scrollnumber>1 then
  81.                 scrollnumber = scrollnumber-1
  82.             end
  83.         end
  84.         if xPos>=1 and xPos<=1
  85.         and yPos>=y-3 and yPos<=y-2 then
  86.             if scrollnumber+anzahl-1<24 and scrollnumber+anzahl-1<#playernames  then
  87.                 scrollnumber = scrollnumber+1
  88.             end
  89.         end    
  90.  
  91.         if xPos==x and yPos==1 then
  92.             shutdown()
  93.         end
  94.  
  95.         if yPos>=3 and yPos<=2+anzahl
  96.         and xPos>=5 and xPos<=21 then
  97.             selected = playernames[scrollnumber+yPos-3]
  98.         end
  99.  
  100.         if xPos>=25 and xPos<=47
  101.         and yPos>=5 and yPos<=9
  102.         and selected=="" then
  103.             add()
  104.         end
  105.         if xPos>=25 and xPos<=35
  106.         and yPos>=13 and yPos<=17
  107.         and selected~="" then
  108.             guiname="turnoff"
  109.             turnon(selected)
  110.         end
  111.         if xPos>=37 and xPos<=47
  112.         and yPos>=13 and yPos<=17
  113.         and selected~="" then
  114.             --delete(selected)
  115.         end
  116.     end
  117.     if guiname=="turnoff" then
  118.         if xPos>=(x/2)-10 and xPos<=(x/2)+10
  119.         and yPos>=(y/2)-4 and yPos<=(y/2)+4 then
  120.             mon.setBackgroundColor(colors.gray)
  121.             for j=5,y-4 do
  122.                 mon.setCursorPos(5,j)
  123.                 for k=5,x-4 do
  124.                     mon.write(" ")
  125.                 end
  126.             end
  127.             mon.setTextColor(colors.lightGray)
  128.             midwrite("Es wird ausgeschaltet...",y-6)
  129.             mon.setTextColor(colors.gray)
  130.             for i=1,50 do
  131.                 pos = ((x-4-5-2)/100)*i
  132.                 mon.setCursorPos(6,y-5)
  133.                 mon.setBackgroundColor(colors.lime)
  134.                 for j=1,pos do
  135.                     mon.write(" ")
  136.                 end
  137.                 mon.setBackgroundColor(colors.white)
  138.                 mon.setTextColor(colors.lightGray)
  139.                 mon.setBackgroundColor(colors.gray)
  140.                 midwrite(i.."%",y-5)
  141.                 if i==50 then
  142.                     debug(50)
  143.                 end
  144.                 sleep(0.01)
  145.             end
  146.             rs.setBundledOutput("right",0)
  147.             rs.setBundledOutput("bottom",0)
  148.             rs.setBundledOutput("left",0)
  149.             rs.setBundledOutput("top",0)
  150.             scrollnumber = 1
  151.             guiname="start"
  152.             selected=""
  153.         end
  154.     end
  155. end
  156.  
  157. function drawInfo(ln1,ln2,ln3)
  158.   ystart = math.floor((y-4)/2)
  159.  
  160.   mon.setTextColor(1)
  161.   mon.setBackgroundColor(512)
  162.   for i=ystart,ystart+4 do
  163.     mon.setCursorPos(3,i)
  164.     for j=3,x-3 do
  165.       mon.write(" ")
  166.     end
  167.   end
  168.   for i=ystart,ystart+4 do
  169.     mon.setCursorPos(3,i)
  170.     if i==ystart or i==ystart+4 then
  171.       for j=3,x-3 do
  172.         if j==3 or j==x-3 then
  173.           mon.write("+")
  174.         else
  175.           mon.write("-")
  176.         end
  177.       end
  178.     else
  179.       mon.setCursorPos(3,i)
  180.       mon.write("|")
  181.       mon.setCursorPos(x-3,i)
  182.       mon.write("|")
  183.     end
  184.   end
  185.   xstart = math.floor(((x-6)-#ln1)/2)
  186.   mon.setCursorPos(5+xstart,ystart+1)
  187.   mon.write(ln1)
  188.   xstart = math.floor(((x-6)-#ln2)/2)
  189.   mon.setCursorPos(5+xstart,ystart+2)
  190.   mon.write(ln2)
  191.   xstart = math.floor(((x-6)-#ln3)/2)
  192.   mon.setCursorPos(5+xstart,ystart+3)
  193.   mon.write(ln3)
  194. end
  195.  
  196. function logo()
  197.     mon.setTextColor(colors.cyan)
  198.     mon.setBackgroundColor(colors.gray)
  199.     mon.setCursorPos((x-16)/2,1)
  200.     mon.write("Jo")
  201.     mon.setTextColor(colors.orange)
  202.     mon.write("Ja")
  203.     mon.setTextColor(colors.lightGray)
  204.     mon.write(" Productions")
  205. end
  206.  
  207. function gui()
  208.     x,y = mon.getSize()
  209.     mon.setTextColor(colors.black)
  210.     mon.setBackgroundColor(colors.white)
  211.     for i=1,y do
  212.         mon.setCursorPos(1,i)
  213.         for j=1,x do
  214.             mon.write(" ")
  215.         end
  216.     end
  217.     logo()
  218.     loadData()
  219.     if guiname=="start" then
  220.         for i=scrollnumber,scrollnumber+anzahl-1 do
  221.             if playernames[i]~=nil then
  222.                 isselected = false 
  223.                 if playernames[i]==selected then
  224.                     isselected = true
  225.                 end
  226.                 bdraw(5,3+(i-scrollnumber),playernames[i],isselected)
  227.             end
  228.         end
  229.         mon.setTextColor(colors.white)
  230.         if scrollnumber>1 then
  231.             mon.setBackgroundColor(colors.blue)
  232.         else
  233.             mon.setBackgroundColor(colors.gray)
  234.         end
  235.         mon.setCursorPos(1,3)
  236.         mon.write("^")
  237.         mon.setCursorPos(1,4)
  238.         mon.write("|")
  239.        
  240.         if scrollnumber+anzahl-1<24 and scrollnumber+anzahl-1<#playernames then
  241.             mon.setBackgroundColor(colors.blue)
  242.         else
  243.             mon.setBackgroundColor(colors.gray)
  244.         end
  245.         mon.setCursorPos(1,y-3)
  246.         mon.write("|")
  247.         mon.setCursorPos(1,y-2)
  248.         mon.write("v")
  249.  
  250.         mon.setBackgroundColor(colors.red)
  251.         mon.setTextColor(colors.white)
  252.         mon.setCursorPos(x,1)
  253.         mon.write("o")
  254.  
  255.         if selected=="" or selected==nil then
  256.             buttondraw(25,5,47,9,"hinzufuegen",colors.orange)
  257.             buttondraw(25,13,35,17,"aufrufen",colors.gray)
  258.             buttondraw(37,13,47,17,"loeschen",colors.gray)
  259.         else
  260.             str = " Auswahl: "..selected.." "
  261.             mon.setCursorPos(36-(#str/2),3)
  262.             mon.setBackgroundColor(colors.gray)
  263.             mon.setTextColor(colors.white)
  264.             mon.write(str)
  265.             buttondraw(25,5,47,9,"hinzufuegen",colors.gray)
  266.             buttondraw(25,13,35,17,"aufrufen",colors.lime)
  267.             buttondraw(37,13,47,17,"loeschen",colors.red)
  268.         end
  269.     end
  270.     if guiname=="turnoff" then
  271.         buttondraw((x/2)-10,(y/2)-4,(x/2)+10,(y/2)+4,"Ausschalten",colors.red)
  272.     end
  273. end
  274.  
  275. function debug(start)
  276.     if start==nil then
  277.         start=1
  278.     else
  279.         rs.setBundledOutput("right",65535)
  280.         rs.setBundledOutput("bottom",65535)
  281.         rs.setBundledOutput("left",65535)
  282.         rs.setBundledOutput("top",65535)
  283.     end
  284.     mon.setBackgroundColor(colors.gray)
  285.     for j=5,y-4 do
  286.         mon.setCursorPos(5,j)
  287.         for k=5,x-4 do
  288.             mon.write(" ")
  289.         end
  290.     end
  291.     mon.setTextColor(colors.lightGray)
  292.     midwrite("Debug...",y-6)
  293.     mon.setTextColor(colors.gray)
  294.     for i=start,100 do
  295.         pos = ((x-4-5-2)/100)*i
  296.         mon.setCursorPos(6,y-5)
  297.         mon.setBackgroundColor(colors.lime)
  298.         for j=1,pos do
  299.             mon.write(" ")
  300.         end
  301.         mon.setBackgroundColor(colors.white)
  302.         mon.setTextColor(colors.lightGray)
  303.         mon.setBackgroundColor(colors.gray)
  304.         midwrite(i.."%",y-5)
  305.         sleep(0.01)
  306.  
  307.         if i==25 then
  308.             rs.setBundledOutput("right",65535)
  309.             rs.setBundledOutput("bottom",65535)
  310.             rs.setBundledOutput("left",65535)
  311.             rs.setBundledOutput("top",65535)
  312.         end
  313.         if i==75 then
  314.             rs.setBundledOutput("right",0)
  315.             rs.setBundledOutput("bottom",0)
  316.             rs.setBundledOutput("left",0)
  317.             rs.setBundledOutput("top",0)
  318.         end
  319.     end
  320. end
  321.  
  322. function loadData()
  323.     playernames = {}
  324.     if not fs.exists("database.db") then
  325.         file = fs.open("database.db","w")
  326.         file.close()
  327.     end
  328.  
  329.     file = fs.open("database.db","r")
  330.     line = file.readLine()
  331.     while line~=nil do
  332.         playernames[#playernames+1] = line
  333.         line = file.readLine()
  334.     end
  335.     file.close()
  336. end
  337.  
  338. function add()
  339.     rednet.open("front")
  340.     rednet.send(10753,"Tastatur start")
  341.     msgvorher=""
  342.     success=false
  343.     while success~=true do
  344.         id,msg = rednet.receive()
  345.         if msg=="Nachricht wurde uebermittelt" then
  346.             success=true
  347.         else
  348.             msgvorher = msg
  349.         end
  350.         print(id.." "..msg)
  351.     end
  352.     rednet.close("front")
  353.     file = fs.open("database.db","a")
  354.     file.writeLine(msgvorher)
  355.     print("Es wurde "..msgvorher.." geschrieben")
  356.     file.close()
  357.     loadData()
  358.     gui()
  359. end
  360.  
  361. function turnon(name)
  362.     mon.setBackgroundColor(colors.gray)
  363.     for j=5,y-4 do
  364.         mon.setCursorPos(5,j)
  365.         for k=5,x-4 do
  366.             mon.write(" ")
  367.         end
  368.     end
  369.     mon.setTextColor(colors.lightGray)
  370.     midwrite("Es wird "..name.." aufgerufen",y-6)
  371.     mon.setTextColor(colors.gray)
  372.     for i=1,100 do
  373.         pos = ((x-4-5-2)/100)*i
  374.         mon.setCursorPos(6,y-5)
  375.         mon.setBackgroundColor(colors.lime)
  376.         for j=1,pos do
  377.             mon.write(" ")
  378.         end
  379.         mon.setBackgroundColor(colors.white)
  380.         mon.setTextColor(colors.lightGray)
  381.         mon.setBackgroundColor(colors.gray)
  382.         midwrite(i.."%",y-5)
  383.         sleep(0.01)
  384.     end
  385.  
  386.     col=1
  387.     num=0
  388.     for i=1,#playernames do
  389.         if playernames[i]==name then
  390.             num = i
  391.             color=col
  392.             break
  393.         end
  394.         col = col+col
  395.     end
  396.  
  397.     if num>=1 and num<=6 then
  398.         side = "right"
  399.         color = colorcodes[num]
  400.     elseif num>=7 and num<=12 then
  401.         side = "bottom"
  402.         color = colorcodes[num-6]
  403.     elseif num>=13 and num<=18 then
  404.         side = "left"
  405.         color = colorcodes[num-12]
  406.     elseif num>=19 and num<=24 then
  407.         side = "top"
  408.         color = colorcodes[num-18]
  409.     end
  410.     rs.setBundledOutput(side,color)
  411.     sleep(.5)
  412. end
  413.  
  414. function shutdown()
  415.     mon.setBackgroundColor(colors.gray)
  416.     for j=5,y-4 do
  417.         mon.setCursorPos(5,j)
  418.         for k=5,x-4 do
  419.             mon.write(" ")
  420.         end
  421.     end
  422.     mon.setTextColor(colors.lightGray)
  423.     midwrite("Ruhezustand starten...",y-6)
  424.     mon.setTextColor(colors.gray)
  425.     for i=1,50 do
  426.         pos = ((x-4-5-2)/100)*i
  427.         mon.setCursorPos(6,y-5)
  428.         mon.setBackgroundColor(colors.lime)
  429.         for j=1,pos do
  430.             mon.write(" ")
  431.         end
  432.         mon.setBackgroundColor(colors.white)
  433.         mon.setTextColor(colors.lightGray)
  434.         mon.setBackgroundColor(colors.gray)
  435.         midwrite(i.."%",y-5)
  436.         if i==50 then
  437.             debug(50)
  438.         end
  439.         sleep(0.01)
  440.     end
  441.     os.reboot()
  442. end
  443.  
  444. loadData()
  445. debug()
  446. timer = os.startTimer(timertime)
  447. gui()
  448. drawInfo("Bitte denke daran,","dass du nach 120 Sekunden","ausgeloggt wirst.")
  449. while true do
  450.   event=""
  451.   while event~="monitor_touch" do
  452.     event,arg1,xPos,yPos = os.pullEvent()
  453.     if event=="timer" and timer==arg1 then
  454.         shutdown()
  455.     end
  456.   end
  457.   checkButtons(xPos,yPos)
  458.   loadData()
  459.   gui()
  460. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement