gravitowl

[gravicard] UI

Jan 11th, 2021 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. -- Load API's
  2. os.loadAPI("touchpoint")
  3. os.loadAPI("bigfont")
  4.  
  5. -- Load monitor and make sure everything gets displayed there
  6. local monitor = peripheral.wrap("back")
  7.  
  8. term.redirect(monitor)
  9. term.setBackgroundColor(colors.black)
  10. term.clear()
  11. local x, y = monitor.getSize()
  12.  
  13. -- Variables
  14. local mainButtonWidth = 20
  15. local mainButtonHeight = 6
  16.  
  17. local screen = "main"
  18.  
  19. -- Create touchpoint and buttons
  20.  
  21. ---- Main
  22. mainT = touchpoint.new("back")
  23.  
  24. mainT:add("DONE", nil, math.ceil((x/2) - (mainButtonWidth/2)), y - (mainButtonHeight/2) - 2, math.ceil((x/2) + (mainButtonWidth/2)), y - 2, colors.white, colors.white, colors.black, colors.black)
  25.  
  26. mainT:add("DEPOSIT", nil, math.ceil((x/2) - (mainButtonWidth/2)), y - (mainButtonHeight/2) - 8, math.ceil((x/2) + (mainButtonWidth/2)), y - 8, colors.green, colors.green, colors.black, colors.black)
  27.  
  28. mainT:add("PAYOUT", nil, math.ceil((x/2) - (mainButtonWidth/2)), y - (mainButtonHeight/2) - 14, math.ceil((x/2) + (mainButtonWidth/2)), y - 14, colors.red, colors.red, colors.black, colors.black)
  29.  
  30. ---- Deposit
  31. depositT = touchpoint.new("back")
  32.  
  33. depositT:add("DONE", nil, math.ceil((x/2) - (mainButtonWidth/2)), y - (mainButtonHeight/2) - 2, math.ceil((x/2) + (mainButtonWidth/2)), y - 2, colors.white, colors.white, colors.black, colors.black)
  34.  
  35. ---- Payout
  36. payoutT = touchpoint.new("back")
  37.  
  38. payoutT:add("DONE", nil, math.ceil((x/2) - (mainButtonWidth/2)), y - (mainButtonHeight/2) - 2, math.ceil((x/2) + (mainButtonWidth/2)), y - 2, colors.white, colors.white, colors.black, colors.black)
  39.  
  40. -- Button Functions
  41. function done()
  42. if screen == "main" then
  43. screen = "start"
  44. else
  45. screen = "main"
  46. mainScreen()
  47. end
  48. end
  49.  
  50. function deposit()
  51. screen = "deposit"
  52. depositScreen()
  53. end
  54.  
  55. function payout()
  56. screen = "payout"
  57. payoutScreen()
  58. end
  59.  
  60. --Screens
  61. function mainScreen()
  62. while screen == "main" do
  63. mainT:draw()
  64. term.setCursorPos(1, 1)
  65. term.setBackgroundColor(colors.black)
  66. term.setTextColor(colors.white)
  67. term.setCursorPos(math.ceil((x/2) - #"WELCOME"), 5)
  68. bigfont.bigWrite("WELCOME")
  69. local event, p1 = mainT:handleEvents(os.pullEvent())
  70. term.setCursorPos(1,1)
  71. term.write(event)
  72. if event == "button_click" then
  73. if p1 == "DONE" then
  74. done()
  75. elseif p1 == "DEPOSIT" then
  76. deposit()
  77. elseif p1 == "PAYOUT" then
  78. payout()
  79. end
  80. end
  81. end
  82. end
  83.  
  84. function depositScreen()
  85. while screen == "deposit" do
  86. depositT:draw()
  87. term.setCursorPos(1, 1)
  88. term.setBackgroundColor(colors.black)
  89. term.setTextColor(colors.white)
  90. term.setCursorPos(math.ceil((x/2) - #"DEPOSIT"), 5)
  91. bigfont.bigWrite("DEPOSIT")
  92. local event, p1 = depositT:handleEvents(os.pullEvent())
  93. if event == "button_click" then
  94. if p1 == "DONE" then
  95. done()
  96. end
  97. end
  98. end
  99. end
  100.  
  101. function payoutScreen()
  102. while screen == "payout" do
  103. payoutT:draw()
  104. term.setCursorPos(1, 1)
  105. term.setBackgroundColor(colors.black)
  106. term.setTextColor(colors.white)
  107. term.setCursorPos(math.ceil((x/2) - #"PAYOUT"), 5)
  108. bigfont.bigWrite("PAYOUT")
  109. local event, p1 = payoutT:handleEvents(os.pullEvent())
  110. if event == "button_click" then
  111. if p1 == "DONE" then
  112. done()
  113. end
  114. end
  115. end
  116. end
Add Comment
Please, Sign In to add comment