Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("BtnCtrl Running...")
- d = peripheral.wrap("top")
- r = rednet.open("left")
- d.setCursorPos(1,1)
- d.setTextColor(colors.white)
- function btnCon(pH1,pH2,pW1,pW2,pTxt,pRNID)
- btn={}
- btn.HBounds={H1=pH1,H2=pH2}
- btn.WBounds={W1=pW1,W2=pW2}
- btn.Txt=pTxt
- btn.RNID=pRNID
- btn.Enabled=false
- return btn
- end
- function draw(pHBounds,pWBounds,pText)
- d.setBackgroundColor(colors.red)
- for y=pHBounds.H1,pHBounds.H2 do
- for x=pWBounds.W1,pWBounds.W2 do
- d.setCursorPos(x,y)
- if y==pHBounds.H1+2 and x==pWBounds.W1+5 then
- d.write(pText)
- else
- d.write(" ")
- end
- end
- end
- end
- function ClearAndReset()
- d.setCursorPos(1,1)
- d.setBackgroundColor(colors.black)
- for x=1,39 do
- for y=1,19 do
- d.setCursorPos(x,y)
- d.write(" ")
- end
- end
- d.clear()
- d.setCursorPos(37,1)
- d.setBackgroundColor(colors.red)
- d.write(" ")
- d.setCursorPos(37,2)
- d.write(" X ")
- d.setCursorPos(37,3)
- d.write(" ")
- d.setCursorPos(1,1)
- end
- btns={}
- btns[1]=btnCon(2,6,15,25,"F",2)
- btns[2]=btnCon(14,18,15,25,"B",5)
- btns[3]=btnCon(8,12,28,38,"R",3)
- btns[4]=btnCon(8,12,2,12,"L",4)
- ClearAndReset()
- for z=1,4 do
- b=btns[z]
- draw(b.HBounds,b.WBounds,b.Txt)
- end
- while true do
- input = {os.pullEvent("monitor_touch")}
- TX = input[3]
- TY = input[4]
- if(TX>=37 and TX<=39) and (TY>=1 and TY<=3) then
- ClearAndReset()
- break
- end
- for z=1,4 do
- b=btns[z]
- W1 = b.WBounds.W1
- W2 = b.WBounds.W2
- H1 = b.HBounds.H1
- H2 = b.HBounds.H2
- if (TX>=W1 and TX<=W2) and (TY>=H1 and TY<=H2) then
- rednet.send(2,b.Txt)
- end
- end
- end
- d.write("BtnCtrl Terminated!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement