Nike622000

Me-Uebersicht TRBarney

Jun 13th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. local monSide = "back"
  2. local Bcolor = colors.blue
  3. local senSide = "top"
  4.  
  5.  
  6.  
  7. os.loadAPI("ocs/apis/sensor")
  8. mon = peripheral.wrap(monSide)
  9. sen = sensor.wrap(senSide)
  10.  
  11. local xMax,yMax = mon.getSize()
  12.  
  13. function bdraw(xp1,yp1,xp2,yp2,txt,col)
  14.  if col==nil then
  15.  mon.setBackgroundColor(colors.lime)
  16.  else
  17.  mon.setBackgroundColor(col)
  18.  end
  19.  mon.setCursorPos(xp1,yp1)
  20.  for i=1,(xp2-xp1) do
  21.   mon.write("-")
  22.  end
  23.  mon.setCursorPos(xp1,yp2)
  24.  for i=1,(xp2-xp1) do
  25.   mon.write("-")
  26.  end
  27.  for i=yp1,yp2 do
  28.   mon.setCursorPos(xp1,i)
  29.   mon.write("|")
  30.   mon.setCursorPos(xp2,i)
  31.   mon.write("|")
  32.  end
  33.  for i=(yp1+1),(yp2-1) do
  34.   mon.setCursorPos((xp1+1),i)
  35.   for j=(xp1+1),(xp2-1) do
  36.    mon.write(" ")
  37.    j = j+1
  38.   end
  39.   i = i+1
  40.  end
  41.  if math.floor(((xp2-xp1)-#txt)/2)==0 then
  42.   xp1 = xp1+1
  43.  end
  44.  mon.setCursorPos(math.floor(((xp2-xp1)-#txt)/2)+xp1,math.floor((yp2-yp1)/2)+yp1)
  45.  --print(math.floor(((xp2-xp1)-#txt)/2))
  46.  mon.write(txt)
  47. end
  48.  
  49. function Background()
  50. mon.setBackgroundColor(Bcolor)
  51.   for yPos=1,yMax do
  52.     for xPos=1,xMax do
  53.         mon.setCursorPos(xPos,yPos)
  54.       mon.write(" ")
  55.     end
  56.   end
  57. end
  58. Background()
  59. mon.clear()
  60. Itemname = {}
  61. Itemmenge = {}
  62. while true do
  63. mon.setCursorPos(xMax/2-14,1)
  64. mon.setBackgroundColor(colors.black)
  65. mon.write("ME-Uebersicht made by ")
  66. mon.setBackgroundColor(colors.black)
  67. mon.setTextColor(colors.cyan)
  68. mon.write("Nike622000")
  69. mon.setBackgroundColor(Bcolor)
  70.  
  71. mon.setTextColor(colors.white)
  72. bdraw(xMax-14,yMax-2,xMax,yMax,"Aktualisieren",colors.cyan)
  73. event,_,xPos,yPos = os.pullEvent()
  74. mon.setBackgroundColor(colors.white)
  75.  
  76. if event=="monitor_touch" then
  77.     if xPos>=xMax-14 and xPos<=xMax and yPos>=yMax-2 and yPos<=yMax then
  78. Background()
  79.         for yPos = 2,yMax do
  80.             mon.setBackgroundColor(Bcolor)
  81.             mon.setTextColor(colors.white)
  82.             mon.setCursorPos(xMax/2+5,yPos)
  83.             mon.write("|")
  84.            
  85.             end
  86.             ziele = sen.getTargets()
  87.  
  88.                 for k,v in pairs(ziele) do
  89.                      if v.Name == "ME Wireless Access Point"
  90.                     and v.Position.X==-3
  91.                     and v.Position.Y==-1
  92.                     and v.Position.Z==0
  93.                     then
  94.                     details = sen.getTargetDetails(k)
  95.  
  96.                         for i = 1,#Itemname do
  97.                             mon.setBackgroundColor(Bcolor)
  98.                             mon.setTextColor(colors.white)
  99.                             mon.setCursorPos(27,2+i)
  100.                             --mon.write(Itemname[i])
  101.                             mon.setCursorPos(48,2+i)
  102.                             --mon.write(Itemmenge[i])
  103.                         end
  104.                         if #Itemmenge <= 0 then
  105.                         print("1")
  106.                         d = false
  107.                         end
  108.                        
  109.                         for i = 1,#details.Items do
  110.                             mon.setCursorPos(50,2+i)
  111.                             if d then
  112.                             bilanz = details.Items[i].Size-Itemmenge[i]
  113.                             if bilanz > 0 then
  114.                             mon.setTextColor(colors.lime)
  115.                             end
  116.                             if bilanz < 0 then
  117.                             mon.setTextColor(colors.red)
  118.                             end
  119.                             if bilanz == 0 then
  120.                             mon.setTextColor(colors.yellow)
  121.                             end
  122.                             mon.write(bilanz)
  123.                             end
  124.                             Itemname[i] = details.Items[i].Name
  125.                             Itemmenge[i] = details.Items[i].Size
  126.                             print("2")
  127.                             mon.setTextColor(colors.white)
  128.                             mon.setCursorPos(2,2+i)
  129.                             mon.write(details.Items[i].Name)
  130.                             mon.setCursorPos(27,2+i)
  131.                             mon.write(details.Items[i].Size)
  132.                            
  133.                            
  134.                             end
  135.             d = true
  136.                            
  137.                         end
  138.                     end
  139. d = true
  140.                     end
  141.  
  142.     end
  143. end
Add Comment
Please, Sign In to add comment