Advertisement
xbsktball10x

Untitled

Nov 30th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1.  
  2.  
  3. rednet.open("left")
  4.  
  5. if viewportAPI then os.unloadAPI("viewportAPI") end
  6. os.loadAPI("viewportAPI")
  7. if buttonAPI then os.unloadAPI("buttonAPI") end
  8. os.loadAPI("buttonAPI")
  9. if eventDispatcherAPI then os.unloadAPI("eventDispatcherAPI") end
  10. os.loadAPI("eventDispatcherAPI")
  11.  
  12.  
  13. viewportLeft = viewportAPI.new({term = peripheral.wrap("up")})
  14.  
  15. buttonUp = buttonAPI.new({
  16. text = "up",
  17. x = buttonAPI.anchorLeft,
  18. y = buttonAPI.anchorTop,
  19. isSticky = true,
  20. width = buttonAPI.maxWidth,
  21. height = 1
  22. })
  23. viewportLeft:addElement(buttonUp)
  24.  
  25. buttonDown = buttonAPI.new({
  26. text = "down",
  27. x = buttonAPI.anchorLeft,
  28. y = buttonAPI.anchorBottom,
  29. isSticky = true,
  30. width = buttonAPI.maxWidth,
  31. height = 1
  32. })
  33. viewportLeft:addElement(buttonDown)
  34.  
  35. buttonLeft = buttonAPI.new({
  36. text = "left",
  37. x = buttonAPI.anchorLeft,
  38. y = buttonAPI.anchorTop,
  39. isSticky = true,
  40. width = 1,
  41. height = buttonAPI.maxHeight,
  42. isVertical = true
  43. })
  44.  
  45. viewportLeft:addElement(testbtn)
  46.  
  47. viewportLeft:redraw()
  48.  
  49. handler = function(element, x, y)
  50. dx = 0
  51. dy = 0
  52. if element == buttonUp then
  53. dy = -1
  54. elseif element == buttonDown then
  55. dy = 1
  56. elseif element == buttonLeft then
  57. dx = -1
  58. elseif element == buttonRight then
  59. dx = 1
  60. elseif element == testbtn then
  61. testbtn.backgroundColor = testbtn.backgroundColor == colors.green and colors.red or colors.green
  62. else
  63. error("Unknown Button")
  64. end
  65. viewportLeft:move(dx, dy)
  66. return true -- requests redraw of current viewport
  67. end
  68.  
  69. buttonUp.callback = handler
  70. buttonDown.callback = handler
  71. buttonLeft.callback = handler
  72. buttonRight.callback = handler
  73. testbtn.callback = handler
  74.  
  75. eventDispatcherAPI.addFilteredHandler("monitor_touch", "monitor_0", function(event, side, xPos, yPos)
  76. redraw = viewportLeft:handleClick(xPos, yPos)
  77. if redraw then
  78. viewportRight:redraw()
  79. end
  80. end)
  81.  
  82.  
  83. eventDispatcherAPI.addFilteredHandler("monitor_resize", "monitor_0", function()
  84. viewportLeft:redraw()
  85. end)
  86.  
  87. eventDispatcherAPI.runDispatchLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement