Guest User

BtnCtrl

a guest
Dec 6th, 2019
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(1,1)
  46. end    
  47.  
  48. btns={}
  49.  
  50. btns[1]=btnCon(2,6,15,25,"F",2)
  51. btns[2]=btnCon(14,18,15,25,"B",5)
  52. btns[3]=btnCon(8,12,28,38,"R",3)
  53. btns[4]=btnCon(8,12,2,12,"L",4)
  54.  
  55. ClearAndReset()
  56.  
  57. for z=1,4 do
  58.     b=btns[z]
  59.     draw(b.HBounds,b.WBounds,b.Txt)    
  60. end
  61.  
  62. while true do
  63.     input = {os.pullEvent("monitor_touch")}
  64.     --print("Miss")
  65.     for z=1,4 do
  66.         b=btns[z]
  67.        
  68.         W1 = b.WBounds.W1
  69.         W2 = b.WBounds.W2
  70.         H1 = b.HBounds.H1
  71.         H2 = b.HBounds.H2
  72.        
  73.         TX = input[3]
  74.         TY = input[4]
  75.        
  76.         if (TX>W1 and TX<W2) and (TY>H1 and TY<H2) then
  77.             rednet.send(2,b.Txt)
  78.             --print("Touch")
  79.         end
  80.     end
  81. end
RAW Paste Data