Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Farmsteuerung
- local monitorSide = "back"
- local bundledSide = "right"
- local bundledSide1 = "front"
- local bundledSide2 = "left"
- --bitte nichts mehr aendern
- local jwood,nwarts,rgblumen,flax,kakao,kartoffeln,karotten,weizen = 0
- local mon = peripheral.wrap(monitorSide)
- local x,y = mon.getSize()
- local gui = 1
- local buttonUI = 1
- --useful functions
- function bdraw(xp1,yp1,xp2,yp2,txt,col)
- if col==nil then
- mon.setBackgroundColor(colors.lime)
- else
- mon.setBackgroundColor(col)
- end
- mon.setCursorPos(xp1,yp1)
- for i=1,(xp2-xp1) do
- mon.write("-")
- end
- mon.setCursorPos(xp1,yp2)
- for i=1,(xp2-xp1) do
- mon.write("-")
- end
- for i=yp1,yp2 do
- mon.setCursorPos(xp1,i)
- mon.write("|")
- mon.setCursorPos(xp2,i)
- mon.write("|")
- end
- if yp1 == yp2 then
- yp1 = yp1-1
- yp2 = yp2+1
- end
- for i=(yp1+1),(yp2-1) do
- mon.setCursorPos((xp1+1),i)
- for j=(xp1+1),(xp2-1) do
- mon.write(" ")
- j = j+1
- end
- i = i+1
- end
- if math.floor(((xp2-xp1)-#txt)/2)==0 then
- xp1 = xp1+1
- end
- mon.setCursorPos(math.floor(((xp2-xp1)-#txt)/2)+xp1,math.floor((yp2-yp1)/2)+yp1)
- --print(math.floor(((xp2-xp1)-#txt)/2))
- mon.write(txt)
- end
- function bdrawnb(x1,y1,x2,y2,text,color,tcol)
- mon.setBackgroundColor(color)
- for i=y1,y2 do
- mon.setCursorPos(x1,i)
- for j=x1,x2 do
- mon.write(" ")
- end
- end
- if (x2-x1)<=#text then
- mon.setCursorPos(x1,math.floor((y2-y1)/2)+y1)
- else
- mon.setCursorPos(math.floor(((x2-x1)-#text)/2)+x1,math.floor((y2-y1)/2)+y1)
- end
- if tcol==nil then
- mon.setTextColor(colors.gray)
- else
- mon.setTextColor(tcol)
- end
- mon.write(text)
- mon.setTextColor(colors.gray)
- end
- function sdraw(x1,y1,x2,y2,text,status,status2)
- if not status then
- mon.setBackgroundColor(colors.lime)
- elseif status2 then
- mon.setBackgroundColor(colors.orange)
- else
- mon.setBackgroundColor(colors.red)
- end
- for i=y1,y2 do
- mon.setCursorPos(x1,i)
- for j=x1,x2 do
- mon.write(" ")
- end
- end
- if (x2-x1)<=#text then
- mon.setCursorPos(x1,math.floor((y2-y1)/2)+y1)
- else
- mon.setCursorPos(math.floor(((x2-x1)-#text)/2)+x1,math.floor((y2-y1)/2)+y1)
- end
- mon.setTextColor(colors.gray)
- mon.write(text)
- end
- function checkb(xPos,yPos,x1,y1,x2,y2,text)
- if xPos>=x1 and xPos<=x2 and yPos>=y1 and yPos<=y2 then
- bdrawnb(x1,y1,x2,y2,text,colors.lightGray)
- sleep(0.25)
- return true
- else
- return false
- end
- end
- function impuls(color, side)
- rs.setBundledOutput(side,rs.getBundledOutput("front")+color)
- sleep(0.25)
- rs.setBundledOutput(side,rs.getBundledOutput("front")-color)
- end
- function log(text)
- if not fs.exists("error.log") then
- filee = fs.open("error.log","w")
- filee.write(" ")
- filee.close()
- end
- file = fs.open("error.log","r")
- line = file.readLine()
- file.close()
- if not string.match(line,text) then
- if line == " " then
- filew = fs.open("error.log","w")
- else
- filew = fs.open("error.log","a")
- end
- filew.write(text .. "\n")
- filew.close()
- end
- end
- --program
- function drawGUI1()
- for i=1,y do
- mon.setCursorPos(1,i)
- mon.setBackgroundColor(colors.yellow)
- for j=1,x do
- mon.write(" ")
- end
- end
- mon.setTextColor(colors.gray)
- mon.setCursorPos(math.floor((x-22)/2),1)
- mon.write("Farmsteuerung - Status")
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- sdraw(pos1,y-13,pos2,y-13,"Junglewood",rs.testBundledInput(bundledSide,colors.white))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-13,pos2,y-13,"Nether Warts",rs.testBundledInput(bundledSide,colors.orange))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-13,pos2,y-13,"R/Y Blumen",rs.testBundledInput(bundledSide,colors.magenta),rs.testBundledInput("left",colors.magenta))
- if rs.testBundledInput("left",colors.magenta) then
- log("Bonemeal is empty.")
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-13,pos2,y-13,"Flax",rs.testBundledInput(bundledSide,colors.lightBlue))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- sdraw(pos1,y-11,pos2,y-11,"Kakao",rs.testBundledInput(bundledSide,colors.yellow))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-11,pos2,y-11,"Kartoffeln",rs.testBundledInput(bundledSide,colors.lime))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-11,pos2,y-11,"Weizen",rs.testBundledInput(bundledSide,colors.pink))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-11,pos2,y-11,"Karotten",rs.testBundledInput(bundledSide,colors.gray))
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- sdraw(pos1,y-9,pos2,y-9,"",rs.testBundledInput(bundledSide,colors.lightGray))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-9,pos2,y-9,"",rs.testBundledInput(bundledSide,colors.cyan))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-9,pos2,y-9,"",rs.testBundledInput(bundledSide,colors.purple))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-9,pos2,y-9,"",rs.testBundledInput(bundledSide,colors.blue))
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- sdraw(pos1,y-7,pos2,y-7,"",rs.testBundledInput(bundledSide,colors.brown))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-7,pos2,y-7,"",rs.testBundledInput(bundledSide,colors.green))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-7,pos2,y-7,"",rs.testBundledInput(bundledSide,colors.red))
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- sdraw(pos1,y-7,pos2,y-7,"",rs.testBundledInput(bundledSide,colors.black))
- bdraw(2,y-3,18,y-1,"Menu",colors.cyan)
- bdraw(20,y-3,x-21,y-1,"Not-Aus",colors.red)
- bdraw(x-19,y-3,x-1,y-1,"Update",colors.lightGray)
- end
- function drawGUI2()
- for i=1,y do
- mon.setCursorPos(1,i)
- mon.setBackgroundColor(colors.yellow)
- for j=1,x do
- mon.write(" ")
- end
- end
- mon.setTextColor(colors.gray)
- mon.setCursorPos(math.floor((x-20)/2),1)
- mon.write("Farmsteuerung - Steuerung")
- mon.setTextColor(colors.gray)
- mon.setCursorPos(2,4)
- mon.write("Klicke auf die Farm, deren Status du umschalten moechtest.")
- bdrawnb(x-10,3,x-3,3,"error.log",colors.lightGray)
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- bdrawnb(pos1,y-13,pos2,y-13,"Junglewood",colors.white)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-13,pos2,y-13,"Nether Warts",colors.orange)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-13,pos2,y-13,"R/Y Blumen",colors.magenta)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-13,pos2,y-13,"Flax",colors.lightBlue)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- bdrawnb(pos1,y-11,pos2,y-11,"Kakao",colors.red)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-11,pos2,y-11,"Kartoffeln",colors.lime)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-11,pos2,y-11,"Weizen",colors.pink)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-11,pos2,y-11,"Karotten",colors.gray,colors.lightGray)
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- bdrawnb(pos1,y-9,pos2,y-9,"",colors.lightGray)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-9,pos2,y-9,"",colors.cyan)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-9,pos2,y-9,"",colors.purple)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-9,pos2,y-9,"",colors.blue)
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- bdrawnb(pos1,y-7,pos2,y-7,"",colors.brown)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-7,pos2,y-7,"",colors.green)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-7,pos2,y-7,"",colors.red)
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- bdrawnb(pos1,y-7,pos2,y-7,"",colors.black)
- bdraw(x-5,y-2,x,y,"Back",colors.red)
- end
- function drawGUI3()
- for i=1,y do
- mon.setCursorPos(1,i)
- mon.setBackgroundColor(colors.yellow)
- for j=1,x do
- mon.write(" ")
- end
- end
- mon.setTextColor(colors.gray)
- mon.setCursorPos(math.floor((x-20)/2),1)
- mon.write("Farmsteuerung - error.log")
- bdraw(x-5,y-2,x,y,"Back",colors.red)
- if not fs.exists("error.log") then
- filee = fs.open("error.log","w")
- filee.write(" ")
- filee.close()
- end
- file = fs.open("error.log","r")
- lines = {}
- line = " "
- while not line==nil do
- line = file.readLine()
- lines[#lines+1] = line
- end
- file.close()
- mon.setTextColor(colors.gray)
- mon.setBackgroundColor(colors.yellow)
- if #lines>10 then
- pos = 6
- for i=#lines-10,#lines do
- mon.setCursorPos(4,pos)
- pos = pos+1
- mon.write(lines[i])
- end
- else
- for i=1,#lines do
- mon.setCursorPos(4,3+i)
- mon.write(lines[i])
- end
- end
- end
- function checkButtons(xPos, yPos)
- if buttonUI==1 then
- if not event=="monitor_touch" then
- return
- end
- if xPos>=2 and xPos<=18 and yPos>=y-3 and yPos<=y-1 then
- bdraw(2,y-3,18,y-1,"Menu",colors.magenta)
- sleep(0.25)
- gui = 2
- buttonUI=2
- end
- if xPos>=20 and xPos<=x-21 and yPos>=y-3 and yPos<=y-1 then
- bdraw(20,y-3,x-21,y-1,"Not-Aus",colors.magenta)
- defcolors = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
- rs.setBundledOutput("front",0)
- for i=1,#defcolors do
- if not colors.test(rs.getBundledInput("right"),defcolors[i]) then
- rs.setBundledOutput("front",rs.getBundledOutput("front")+defcolors[i])
- end
- end
- sleep(0.25)
- rs.setBundledOutput("front",0)
- end
- if xPos>=x-19 and xPos<=x-1 and yPos>=y-3 and yPos<=y-1 then
- mon.setTextColor(colors.lightGray)
- bdraw(x-19,y-3,x-1,y-1,"Update",colors.gray)
- mon.setTextColor(colors.gray)
- sleep(0.25)
- os.reboot()
- end
- elseif buttonUI==2 then
- if checkb(xPos,yPos,x-10,3,x-3,3,"error.log") then
- gui = 3
- buttonUI = 3
- end
- if xPos>=x-5 and xPos<=x and y>=y-2 and y<=y then
- bdraw(x-5,y-2,x,y,"Back",colors.lightGray)
- sleep(0.25)
- gui = 1
- buttonUI = 1
- end
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- if checkb(xPos,yPos,pos1,y-13,pos2,y-13,"Junglewood") then
- impuls(colors.white,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- if checkb(xPos,yPos,pos1,y-13,pos2,y-13,"Nether Warts") then
- impuls(colors.orange,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- if checkb(xPos,yPos,pos1,y-13,pos2,y-13,"R/Y Blumen") then
- impuls(colors.magenta,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- if checkb(xPos,yPos,pos1,y-13,pos2,y-13,"Flax") then
- impuls(colors.lightBlue,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- local abstand = 2
- local breite = 12
- local pos1 = 2+abstand
- local pos2 = 2+abstand+breite
- if checkb(xPos,yPos,pos1,y-11,pos2,y-11,"Kakao") then
- impuls(colors.yellow,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- if checkb(xPos,yPos,pos1,y-11,pos2,y-11,"Kartoffeln") then
- impuls(colors.lime,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- if checkb(xPos,yPos,pos1,y-11,pos2,y-11,"Weizen") then
- impuls(colors.pink,"front")
- gui = 1
- buttonUI=1
- end
- local pos1 = pos1+abstand+breite
- local pos2 = pos2+abstand+breite
- if checkb(xPos,yPos,pos1,y-11,pos2,y-11,"Karotten") then
- impuls(colors.gray,"front")
- gui = 1
- buttonUI=1
- end
- elseif buttonUI==3 then
- if xPos>=x-5 and xPos<=x and y>=y-2 and y<=y then
- bdraw(x-5,y-2,x,y,"Back",colors.red)
- sleep(0.25)
- gui = 1
- buttonUI = 1
- end
- else
- print("ERROR: wrong UI")
- end
- end
- --main program
- while true do
- if gui==1 then
- drawGUI1()
- elseif gui==2 then
- drawGUI2()
- elseif gui==3 then
- drawGUI3()
- else
- print("ERROR: wrong GUI")
- end
- event, side, xPos, yPos = os.pullEvent()
- if event=="monitor_touch" then
- checkButtons(xPos, yPos)
- print("X: " .. xPos .. ",Y: " .. yPos .. ",GUI: " .. gui .. ",BUI: " .. buttonUI)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement