Nike622000

ME Reader

Feb 13th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.83 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. --Monitor
  4. --width  = 5 Blocks
  5. --height = 4 Blocks
  6.  
  7. --peripherals
  8. local monSide = "back"
  9. local senSide = "right"
  10.  
  11. --sensor coords
  12. local senX    = -2
  13. local senY    =  0
  14. local senZ    =  0
  15.  
  16. --customization Options
  17. local Bcol = colors.lightGray
  18.  
  19. --customized Screen Options (Max: 16)
  20. Items = {"Glass","UU-Matter","Cobblestone"}
  21.  
  22. mon = peripheral.wrap(monSide)
  23. sen = sensor.wrap(senSide)
  24.  
  25. local xMax,yMax = mon.getSize()
  26.  
  27. if #Items > 16 then
  28.   print("zu viele Items im customized Screen!")
  29. end
  30.  
  31. Item  = {}
  32. for i = 1,#Items do
  33.   Item[i] = {"_","_",Items[i]}
  34. end
  35.  
  36. function Bg(xP1,yP1,xP2,yP2,col)
  37.   mon.setBackgroundColor(col)
  38.   for xPos = xP1,xP2 do
  39.     for yPos = yP1,yP2 do
  40.       mon.setCursorPos(xPos,yPos)
  41.       mon.write(" ")
  42.     end
  43.   end
  44. end
  45.  
  46. function JoJa(xP,yP)
  47.   mon.setCursorPos(xP,yP)
  48.   mon.setBackgroundColor(colors.gray)
  49.   mon.setTextColor(colors.cyan)
  50.   mon.write("Jo")
  51.   mon.setTextColor(colors.orange)
  52.   mon.write("Ja ")
  53.   mon.setTextColor(colors.lightGray)
  54.   mon.write("Productions")
  55.   mon.setBackgroundColor(colors.black)
  56.   mon.setTextColor(colors.white)
  57. end
  58.  
  59. function Bstart()
  60.   Bg(1,1,xMax,yMax,colors.lightGray)
  61.   Bg(xMax/2-9,5,xMax/2+8,7,colors.gray)
  62.   JoJa(xMax/2-8,6)
  63.   mon.setCursorPos(xMax/2-7,10)
  64.   mon.setTextColor(colors.white)
  65.   Bg(xMax/2-9,9,xMax/2+8,11,colors.cyan)
  66.   mon.setCursorPos(xMax/2-8,10)
  67.   mon.write("ME-System Reader")
  68.   mon.setBackgroundColor(colors.lightGray)
  69.   mon.setCursorPos(2,yMax-2)
  70.   mon.write("Bildschirmgroesse:")
  71.   mon.setCursorPos(2,yMax-1)
  72.   mon.write("-Breite: 5 Bloecke")
  73.   mon.setCursorPos(2,yMax)
  74.   mon.write("-Hoehe:  4 Bloecke")
  75.   Bg(8,14,xMax-9,17,colors.red)
  76.   mon.setCursorPos(9,15)
  77.   mon.write("Copyright by JoJa Productions")
  78.   mon.setCursorPos(9,16)
  79.   mon.write("Weitergabe nicht gestattet!")
  80.   mon.setBackgroundColor(colors.gray)
  81.   mon.setCursorPos(12,19)
  82.   mon.write("Klicke um fortzufahren...")
  83.   event = os.pullEvent("monitor_touch")
  84. end
  85.  
  86. function drawB(xP1,yP1,xP2,yP2,col,txt)
  87.   mon.setBackgroundColor(col)
  88.   for xPos = xP1,xP2 do
  89.     for yPos = yP1,yP2-1 do
  90.       mon.setCursorPos(xPos,yPos)
  91.       mon.write(" ")
  92.     end
  93.   end
  94.   mon.setCursorPos((xP1+xP2)/2-#txt/2,(yP1+yP2)/2)
  95.   mon.write(txt)
  96. end
  97.  
  98. function getDataMenue()
  99.   ziele = sen.getTargets()
  100.  
  101.   for k,v in pairs(ziele) do
  102.     if  v.Name == "ME Wireless Access Point"
  103.     and v.Position.X == senX
  104.     and v.Position.Y == senY
  105.     and v.Position.Z == senZ  
  106.     then
  107.       details        = sen.getTargetDetails(k)
  108.       bItemarten     = details.UsedTypes
  109.       fItemarten     = details.FreeTypes
  110.       fSpeicherplatz = details.FreeCount*(-1)
  111.     end
  112.   end    
  113. end
  114.  
  115. function Menue()
  116.   Bg(1,1,xMax,yMax,Bcol)
  117.   Bg(2,3,xMax-1,7,colors.gray)
  118.   JoJa(xMax/2-8,1)
  119.   mon.setBackgroundColor(colors.gray)
  120.   mon.setCursorPos(3,4)
  121.   mon.write("Benutzte Itemarten: "..bItemarten.." Arten")
  122.   mon.setCursorPos(3,5)
  123.   mon.write("Freie Itemarten: "..fItemarten.." Arten")
  124.   mon.setCursorPos(3,6)
  125.   mon.write("Freier Speicherplatz: "..fSpeicherplatz.." Items")
  126.   Bg(2,9,xMax-1,13,colors.gray)
  127.   drawB(3,10,xMax/2-1,13,colors.lime,"ShowAllItems")
  128.   drawB(xMax/2+1,10,xMax-2,13,colors.red,"CustomItems")
  129.   Bg(2,15,xMax-1,17,colors.gray)
  130.   mon.setTextColor(colors.white)
  131.   mon.setCursorPos(3,16)
  132.   mon.write("Klicke auf den Monitor um zu aktualiesieren...")
  133. end
  134.  
  135. function ShowAllItems()
  136.   while true do
  137.     Bg(1,1,xMax,yMax,Bcol)
  138.     Bg(2,2,xMax-1,yMax-7,colors.gray)
  139.     Bg(2,yMax-5,xMax-1,yMax-1,colors.gray)
  140.     drawB(3,yMax-4,17,yMax-1,colors.blue," Seite zurueck")
  141.     drawB(xMax-17,yMax-4,xMax-2,yMax-1,colors.blue," naechste Seite")
  142.     drawB(19,yMax-4,xMax-19,yMax-1,colors.red," Hauptmenue")
  143.     ziele = sen.getTargets()
  144.     for k,v in pairs(ziele) do
  145.       if v.Name == "ME Wireless Access Point"
  146.       and v.Position.X == senX
  147.       and v.Position.Y == senY
  148.       and v.Position.Z == senZ
  149.       then
  150.         details = sen.getTargetDetails(k)
  151.         MaxP= math.ceil(details.UsedTypes/16)
  152.         zP1 = cP*16-15
  153.         zP2 = cP*16
  154.         if zP2 > details.UsedTypes then
  155.           zP2 = details.UsedTypes
  156.         end
  157.         b = 0
  158.         mon.setBackgroundColor(colors.gray)
  159.         for i = zP1,zP2 do
  160.           mon.setCursorPos(3,3+b)
  161.           mon.write(i.." "..details.Items[i].Name)
  162.           mon.setCursorPos(30,3+b)
  163.           mon.write("Anzahl: "..details.Items[i].Size)
  164.           b=b+1
  165.         end
  166.       end
  167.     end
  168.     event,_,xPos,yPos = os.pullEvent("monitor_touch")
  169.     if xPos >= 3 and xPos <= 17 and yPos >= yMax-4 and yPos <= yMax-1 then
  170.       cP = cP-1
  171.     end
  172.     if xPos >= xMax-17 and xPos <= xMax-2 and yPos >= yMax-4 and yPos <= yMax-1 then
  173.       cP = cP+1
  174.     end
  175.     if cP > MaxP then
  176.       cP = 1
  177.     elseif cP < 1 then
  178.       cP = MaxP
  179.     end
  180.     if xPos >= 19 and xPos <= xMax-19 and yPos >= yMax-4 and yPos <= yMax -1 then
  181.       break
  182.     end  
  183.   end
  184. end
  185.  
  186. function customItems()
  187.   while true do
  188.     Bg(1,1,xMax,yMax,Bcol)
  189.     Bg(2,2,35,3+#Item,colors.gray)
  190.     Bg(40,2,47,3+#Item,colors.gray)
  191.     Bg(18,yMax-5,xMax-18,yMax-1,colors.gray)
  192.     drawB(19,yMax-4,xMax-19,yMax-1,colors.red," Hauptmenue")
  193.     ziele = sen.getTargets()
  194.     for k,v in pairs(ziele) do
  195.       if v.Name == "ME Wireless Access Point"
  196.       and v.Position.X == senX
  197.       and v.Position.Y == senY
  198.       and v.Position.Z == senZ
  199.       then  
  200.         details = sen.getTargetDetails(k)
  201.         for i = 1,details.UsedTypes do
  202.           for b = 1,#Item do
  203.             if details.Items[i].Name == Item[b][3] then
  204.               if Item[b][1] ~= "_" then
  205.                 Item[b][2] = Item[b][1]
  206.               end
  207.             Item[b][1] = details.Items[i].Size
  208.             end
  209.           end  
  210.         end
  211.         mon.setBackgroundColor(colors.gray)
  212.         for i = 1,#Item do
  213.           mon.setCursorPos(3,2+i)
  214.           mon.write(i.." "..Item[i][3])
  215.           mon.setCursorPos(18,2+i)
  216.           mon.write("Anzahl: "..Item[i][1])
  217.           if Item[i][2] ~= "_" then
  218.             mon.setCursorPos(41,2+i)
  219.             mon.write(Item[i][1]-Item[i][2])
  220.           else
  221.             mon.setCursorPos(46,2+i)
  222.             mon.write("_")
  223.           end
  224.         end
  225.       end
  226.     end
  227.     event,_,xPos,yPos = os.pullEvent("monitor_touch")
  228.     if xPos >= 19 and xPos <= xMax-19 and yPos >= yMax-4 and yPos <= yMax-1 then
  229.       break
  230.     end
  231.   end
  232. end
  233.  
  234. Bstart()
  235.  
  236. while true do
  237.   getDataMenue()
  238.   Menue()
  239.   event,_,xPos,yPos = os.pullEvent("monitor_touch")
  240.   if xPos >= 3 and xPos <= xMax/2-1 and yPos >= 10 and yPos <= 13 then
  241.     drawB(3,10,xMax/2-1,13,colors.green,"ShowAllItems")
  242.     sleep(.1)
  243.     cP = 1
  244.     ShowAllItems()
  245.   elseif xPos >= xMax/2+1 and xPos <= xMax-2 and yPos >= 10 and yPos <= 13 then
  246.     drawB(xMax/2+1,10,xMax-2,13,colors.magenta,"CustomItems")
  247.     sleep(.1)
  248.     customItems()
  249.   end
  250. end
Advertisement
Add Comment
Please, Sign In to add comment