Advertisement
jamawie

ReaktorSteuerung TL 2.0

May 1st, 2016
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 KB | None | 0 0
  1. --Reaktorsteuerung
  2. local OPDInSide = "top"
  3. local monitorSide = "back"
  4. local bundledSide = "front"
  5.  
  6. --bitte nichts mehr aendern
  7. local energy, breeder, st1, st2, st3 = 0
  8. local mon = peripheral.wrap(monitorSide)
  9. local x,y = mon.getSize()
  10.  
  11. --useful functions
  12. function bdraw(xp1,yp1,xp2,yp2,txt,col)
  13.  if col==nil then
  14.  mon.setBackgroundColor(colors.lime)
  15.  else
  16.  mon.setBackgroundColor(col)
  17.  end
  18.  mon.setCursorPos(xp1,yp1)
  19.  for i=1,(xp2-xp1) do
  20.   mon.write("-")
  21.  end
  22.  mon.setCursorPos(xp1,yp2)
  23.  for i=1,(xp2-xp1) do
  24.   mon.write("-")
  25.  end
  26.  for i=yp1,yp2 do
  27.   mon.setCursorPos(xp1,i)
  28.   mon.write("|")
  29.   mon.setCursorPos(xp2,i)
  30.   mon.write("|")
  31.  end
  32.  for i=(yp1+1),(yp2-1) do
  33.   mon.setCursorPos((xp1+1),i)
  34.   for j=(xp1+1),(xp2-1) do
  35.    mon.write(" ")
  36.    j = j+1
  37.   end
  38.   i = i+1
  39.  end
  40.  if math.floor(((xp2-xp1)-#txt)/2)==0 then
  41.   xp1 = xp1+1
  42.  end
  43.  mon.setCursorPos(math.floor(((xp2-xp1)-#txt)/2)+xp1,math.floor((yp2-yp1)/2)+yp1)
  44.  print(math.floor(((xp2-xp1)-#txt)/2))
  45.  mon.write(txt)
  46. end
  47.  
  48. function sdraw(x1,y1,x2,y2,text,status,status2)
  49.     if status then
  50.         mon.setBackgroundColor(colors.lime)
  51.     elseif status2 then
  52.         mon.setBackgroundColor(colors.orange)
  53.     else
  54.         mon.setBackgroundColor(colors.red)
  55.     end
  56.  
  57.     for i=y1,y2 do
  58.         mon.setCursorPos(x1,i)
  59.         for j=x1,x2 do
  60.             mon.write(" ")
  61.         end
  62.     end
  63.  
  64.     if (x2-x1)<=#text then
  65.         mon.setCursorPos(x1,math.floor((y2-y1)/2)+y1)
  66.     else
  67.         mon.setCursorPos(math.floor(((x2-x1)-#text)/2)+x1,math.floor((y2-y1)/2)+y1)
  68.     end
  69.     mon.setTextColor(colors.gray)
  70.     mon.write(text)
  71. end
  72.  
  73. --program
  74. function drawGUI()
  75.     for i=1,y do
  76.         mon.setCursorPos(1,i)
  77.         mon.setBackgroundColor(colors.yellow)
  78.         for j=1,x do
  79.             mon.write(" ")
  80.         end
  81.     end
  82.  
  83.     mon.setTextColor(colors.gray)
  84.     mon.setCursorPos(math.floor((x-21)/2),1)
  85.     mon.write("Reaktor-Steuerung 2.0")
  86.  
  87.     local abstand = 1
  88.     local breite = 6
  89.     local pos1 = abstand
  90.     local pos2 = abstand+breite
  91.     sdraw(pos1,y-13,pos2,y-11,"Output",rs.testBundledInput(bundledSide,colors.green),false)
  92.     local pos1 = pos1+abstand+breite+1
  93.     local pos2 = pos2+abstand+breite+1
  94.     sdraw(pos1,y-13,pos2,y-11,"Breeder",rs.testBundledInput(bundledSide,colors.blue),rs.testBundledInput(bundledSide,colors.lightGray))
  95.     local pos1 = pos1+abstand+breite
  96.     local pos2 = pos2+abstand+breite
  97.     sdraw(pos1,y-13,pos2,y-11,"Stufe 1",rs.testBundledInput(bundledSide,colors.yellow))
  98.     local pos1 = pos1+abstand+breite
  99.     local pos2 = pos2+abstand+breite
  100.     sdraw(pos1,y-13,pos2,y-11,"Stufe 2",rs.testBundledInput(bundledSide,colors.orange))
  101.     local pos1 = pos1+abstand+breite
  102.     local pos2 = pos2+abstand+breite
  103.     sdraw(pos1,y-13,pos2,y-11,"Stufe 3",rs.testBundledInput(bundledSide,colors.red))
  104.     local pos1 = pos1+abstand+breite
  105.     local pos2 = pos2+abstand+breite
  106.     sdraw(pos1,y-13,pos2,y-11,"Stufe 4",rs.testBundledInput(bundledSide,colors.purple))
  107.     local pos1 = pos1+abstand+breite
  108.     local pos2 = pos2+abstand+breite
  109.     sdraw(pos1,y-13,pos2,y-11,"AUTO",rs.testBundledInput(bundledSide,colors.magenta),true)
  110.    
  111.     bdraw(2,y-7,18,y-5,"Reaktorstufe +1",colors.lightGreen)
  112.     bdraw(2,y-3,18,y-1,"Reaktorstufe -4",colors.red)
  113.     bdraw(x-19,y-7,x-1,y-5,"Breeder",colors.cyan)
  114.     bdraw(x-19,y-3,x-1,y-1,"Update",colors.lightGray)
  115. end
  116.  
  117. function checkButtons(xPos, yPos)
  118.     if not event=="monitor_touch" then
  119.         print("other event")
  120.         return
  121.     end
  122.     if xPos>=2 and xPos<=18 and yPos>=y-7 and yPos<=y-5 then
  123.         rs.setBundledOutput("front",rs.getBundledOutput("front")+colors.pink)
  124.         bdraw(2,y-7,18,y-5,"Reaktorstufe +1",colors.green)
  125.         sleep(0.25)
  126.         rs.setBundledOutput("front",rs.getBundledOutput("front")-colors.pink)
  127.     end
  128.     if xPos>=2 and xPos<=18 and yPos>=y-3 and yPos<=y-1 then
  129.         rs.setBundledOutput("front",rs.getBundledOutput("front")+colors.cyan)
  130.         bdraw(2,y-3,18,y-1,"Reaktorstufe -4",colors.magenta)
  131.         sleep(0.25)
  132.         rs.setBundledOutput("front",rs.getBundledOutput("front")-colors.cyan)  
  133.     end
  134.     if xPos>=x-19 and xPos<=x-1 and yPos>=y-7 and yPos<=y-5 then
  135.         rs.setBundledOutput("front",rs.getBundledOutput("front")+colors.gray)
  136.         bdraw(x-19,y-7,x-1,y-5,"Breeder",colors.blue)
  137.         sleep(0.25)
  138.         rs.setBundledOutput("front",rs.getBundledOutput("front")-colors.gray)
  139.     end
  140.     if xPos>=x-19 and xPos<=x-1 and yPos>=y-3 and yPos<=y-1 then
  141.         bdraw(x-19,y-3,x-1,y-1,"Update",colors.gray)
  142.         sleep(0.25)
  143.         os.reboot()
  144.     end
  145. end
  146.  
  147.  
  148. --main program
  149. while true do
  150.     drawGUI()
  151.     event, side, xPos, yPos = os.pullEvent()
  152.     if event=="monitor_touch" then
  153.         checkButtons(xPos, yPos)
  154.     end
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement