Advertisement
jamawie

Farmsteuerung - Klein 2.0

Jul 31st, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. --Portal turtle
  2.  
  3. mon = peripheral.wrap("back")
  4.  
  5. bnames = {"Oak","","","Rubber","","","","","Wheed","Carrot","Potato","","","",""}
  6.  
  7. function bdraw(num, str, ison)
  8.     if num > 0 and num < 5 then
  9.         yP = 3
  10.         xp = 12*(num-0)-10
  11.     elseif num > 4 and num < 9 then
  12.         yP = 6
  13.         xp = 12*(num-4)-10
  14.     elseif num > 8 and num < 13 then
  15.         yP = 9
  16.         xp = 12*(num-8)-10
  17.     elseif num > 12 and num < 17 then
  18.         yP = 12
  19.         xp = 12*(num-12)-10
  20.     else
  21.         return
  22.     end
  23.  
  24.     mon.setCursorPos(xp, yP)
  25.     if ison then
  26.         mon.setBackgroundColor(colors.lime)
  27.     else
  28.         mon.setBackgroundColor(colors.red)
  29.     end
  30.  
  31.     for i=1,10 do
  32.         mon.write(" ")
  33.     end
  34.  
  35.     mon.setCursorPos(xp+((10-#str)/2),yP)
  36.     mon.write(str)
  37. end
  38.  
  39. function midwrite(txt, yP)
  40.     x,y = mon.getSize()
  41.     xP = (x-#txt)/2
  42.     mon.setCursorPos(xP,yP)
  43.     mon.write(txt)
  44. end
  45.  
  46. function execute(nmb)
  47.     bdraw(nmb,bnames[nmb],true)
  48.     rs.setBundledOutput("left",0)
  49.     color = 1
  50.     for i=1,nmb-1 do
  51.         color = color*2
  52.     end
  53.     rs.setBundledOutput("left",color)
  54.         mon.setBackgroundColor(colors.gray)
  55.         for j=5,y-4 do
  56.             mon.setCursorPos(5,j)
  57.             for k=5,x-4 do
  58.                 mon.write(" ")
  59.             end
  60.         end
  61.         mon.setTextColor(colors.lightGray)
  62.         midwrite("Es wird "..bnames[nmb].." angebaut",y-6)
  63.         mon.setTextColor(colors.gray)
  64.     for i=1,100 do
  65.         pos = ((x-4-5-2)/100)*i
  66.         mon.setCursorPos(6,y-5)
  67.         mon.setBackgroundColor(colors.lime)
  68.         for j=1,pos do
  69.             mon.write(" ")
  70.         end
  71.         mon.setBackgroundColor(colors.white)
  72.         mon.setTextColor(colors.lightGray)
  73.         mon.setBackgroundColor(colors.gray)
  74.         midwrite(i.."%",y-5)
  75.         sleep(0.1)
  76.     end
  77.     rs.setBundledOutput("left",colors.black)
  78.     sleep(.5)
  79. end
  80.  
  81. function checkButtons(xPos, yPos)
  82.     if yPos == 3 then
  83.         for num=1,4 do
  84.             if xPos >= (12*(num-0)-10) and xPos <= (12*(num-0)) then
  85.                 execute(num)
  86.             end
  87.         end
  88.     elseif yPos == 6 then
  89.         for num=5,8 do
  90.             if xPos >= (12*(num-4)-10) and xPos <= (12*(num-4)) then
  91.                 execute(num)
  92.             end
  93.         end
  94.     elseif yPos == 9 then
  95.         for num=9,12 do
  96.             if xPos >= (12*(num-8)-10) and xPos <= (12*(num-8)) then
  97.                 execute(num)
  98.             end
  99.         end
  100.     elseif yPos == 12 then
  101.         for num=13,15 do
  102.             if xPos >= (12*(num-12)-10) and xPos <= (12*(num-12)) then
  103.                 execute(num)
  104.             end
  105.         end
  106.     end
  107. end
  108.  
  109. function logo()
  110.     mon.setTextColor(colors.cyan)
  111.     mon.setBackgroundColor(colors.gray)
  112.     mon.setCursorPos((x-16)/2,1)
  113.     mon.write("Jo")
  114.     mon.setTextColor(colors.orange)
  115.     mon.write("Ja")
  116.     mon.setTextColor(colors.lightGray)
  117.     mon.write(" Productions")
  118. end
  119.  
  120. function gui()
  121.     x,y = mon.getSize()
  122.     mon.setTextColor(colors.black)
  123.     mon.setBackgroundColor(colors.white)
  124.     for i=1,y do
  125.         mon.setCursorPos(1,i)
  126.         for j=1,x do
  127.             mon.write(" ")
  128.         end
  129.     end
  130.     logo()
  131.     for i=1,15 do
  132.         bdraw(i,bnames[i],false)
  133.     end
  134. end
  135.  
  136. while true do
  137.   gui()
  138.   event,_,xPos,yPos = os.pullEvent("monitor_touch")
  139.   print("touched!")
  140.   checkButtons(xPos,yPos)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement