Advertisement
Guest User

BtnCtrl

a guest
Dec 6th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. print("BtnCtrl Running...")
  2.  
  3. d = peripheral.wrap("top")
  4. r = rednet.open("left")
  5.  
  6. d.setCursorPos(1,1)
  7. d.setTextColor(colors.white)
  8.  
  9. function btnCon(pH1,pH2,pW1,pW2,pTxt,pRNID)
  10.     btn={}
  11.     btn.HBounds={H1=pH1,H2=pH2}
  12.     btn.WBounds={W1=pW1,W2=pW2}
  13.     btn.Txt=pTxt
  14.     btn.RNID=pRNID
  15.     btn.Enabled=false
  16.     return btn
  17. end
  18.  
  19. function draw(pHBounds,pWBounds,pText)
  20.     d.setBackgroundColor(colors.red)
  21.    
  22.     for y=pHBounds.H1,pHBounds.H2 do
  23.         for x=pWBounds.W1,pWBounds.W2 do
  24.             d.setCursorPos(x,y)
  25.             if y==pHBounds.H1+2 and x==pWBounds.W1+5 then
  26.                 d.write(pText)
  27.             else
  28.                 d.write(" ")
  29.             end
  30.         end
  31.     end
  32. end
  33.  
  34. function ClearAndReset()
  35.     d.setCursorPos(1,1)
  36.     d.setBackgroundColor(colors.black)
  37.    
  38.     for x=1,39 do
  39.         for y=1,19 do
  40.             d.setCursorPos(x,y)
  41.             d.write(" ")
  42.             end
  43.         end        
  44.     d.clear()
  45.     d.setCursorPos(37,1)
  46.     d.setBackgroundColor(colors.red)
  47.     d.write("   ")
  48.     d.setCursorPos(37,2)
  49.     d.write(" X ")
  50.     d.setCursorPos(37,3)
  51.     d.write("   ")
  52.     d.setCursorPos(1,1)
  53.  
  54. end    
  55.  
  56. btns={}
  57.  
  58. btns[1]=btnCon(2,6,15,25,"F",2)
  59. btns[2]=btnCon(14,18,15,25,"B",5)
  60. btns[3]=btnCon(8,12,28,38,"R",3)
  61. btns[4]=btnCon(8,12,2,12,"L",4)
  62.  
  63. ClearAndReset()
  64.  
  65. for z=1,4 do
  66.     b=btns[z]
  67.     draw(b.HBounds,b.WBounds,b.Txt)    
  68. end
  69.  
  70. while true do
  71.     input = {os.pullEvent("monitor_touch")}
  72.    
  73.     TX = input[3]
  74.     TY = input[4]
  75.    
  76.     if(TX>=37 and TX<=39) and (TY>=1 and TY<=3) then
  77.         ClearAndReset()
  78.         break
  79.     end
  80.    
  81.     for z=1,4 do
  82.         b=btns[z]
  83.        
  84.         W1 = b.WBounds.W1
  85.         W2 = b.WBounds.W2
  86.         H1 = b.HBounds.H1
  87.         H2 = b.HBounds.H2
  88.        
  89.         if (TX>=W1 and TX<=W2) and (TY>=H1 and TY<=H2) then
  90.             rednet.send(2,b.Txt)
  91.         end
  92.     end
  93. end
  94.  
  95. d.write("BtnCtrl Terminated!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement