Advertisement
FrenchLyfe

Buttons Experimental

Feb 8th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. function load()
  2.   os.loadAPI("touchpoint")
  3.   os.loadAPI("bundleAPI")
  4.   pa1 = touchpoint.new("left")
  5.   pa2 = touchpoint.new("left")
  6.   color = {}
  7.   monitor = {}
  8. end
  9.  
  10. function setMonitors()
  11.   p1S = true
  12.   p2S = false
  13.   p3S = false
  14. end
  15.  
  16. function getColor(name)
  17.   return color[name]
  18. end
  19.  
  20. function getMonitor(name)
  21.   return monitor[name]
  22. end
  23.  
  24. function loadButtons()
  25.   -- Line 1 --
  26.   pa1:add("Netherstar Gen", nil, 2, 2, 20, 4, colors.red, colors.lime)
  27.   NG = "Netherstar Gen"
  28.   color[NG] = "lime"
  29.   monitor[NG] = "pa1"
  30.  
  31.   pa1:add("Wither Spawner", nil, 22, 2, 40, 4, colors.lime, colors.red)
  32.   WS = "Wither Spawner"
  33.   color[WS] = "cyan"
  34.   monitor[WS] = "pa1"
  35.  
  36.   pa1:add("Mana C Spawner", nil, 42, 2, 60, 4, colors.red, colors.lime)
  37.   MCS = "Mana C Spawner"
  38.   color[MCS] = "white"
  39.   monitor[MCS] = "pa1"
  40.  
  41.   -- Line 2 --
  42.   pa1:add("Obsidian Prod", nil, 2 , 6, 20, 8, colors.red, colors.lime)
  43.   OP = "Obsidian Prod"
  44.   color[OP] = "orange"
  45.   monitor[OP] = "pa1"
  46.  
  47.   pa1:add("Lava Production", nil, 22, 6, 40, 8, colors.lime, colors.red)
  48.   LP = "Lava Production"
  49.   color[LP] = "blue"
  50.   monitor[LP] = "pa1"
  51.  
  52.   pa1:add("Test Button", nil, 42, 6, 60, 8, colors.red, colors.lime)
  53.   TB = "Test Button"
  54.   color[TB] = "purple"
  55.   monitor[TB] = "pa1"
  56.  
  57.   -- Line 3 --
  58.   pa1:add("Previous", nil, 2, 10, 15, 12, colors.gray, colors.gray)
  59.   pa1:add("Next", nil, 45, 10, 60, 12, colors.gray, colors.gray)
  60. end
  61.  
  62. function buttonPress()
  63.   local event, p1 = pa1:handleEvents(os.pullEvent())
  64.     if event == "button_click" then
  65.       pa1:toggleButton(p1)
  66.       if not p1 == "Previous" or "Next" then
  67.         bundleAPI.toggle("back", getColor(p1))
  68.       else
  69.         print("Button not yet added")
  70.       end
  71.     end
  72. end
  73.  
  74. function toggleOn(name)
  75.   bundleAPI.on("back", getColor(name))
  76. end
  77.  
  78. function toggleOff(name)
  79.   bundleAPI.off("back", getColor(name))
  80. end
  81.  
  82. function getStates()
  83.   c = bundleAPI.getInput("top", "cyan")
  84.   l = bundleAPI.getInput("top", "lime")
  85.   w = bundleAPI.getInput("top", "white")
  86.   o = bundleAPI.getInput("top", "orange")
  87.   b = bundleAPI.getInput("top", "blue")
  88.   p = bundleAPI.getInput("top", "purple")
  89.   print("Current states:" .. tostring(c) .. tostring(l) .. tostring(w) .. tostring(o) .. tostring(b) .. tostring(p))
  90.   print("cyan, lime, white, orange, blue, purple")
  91. end
  92.  
  93. function setStates()
  94.   if c == true then
  95.     toggleOn("Wither Spawner")
  96.     pa1:setOn("Wither Spawner")
  97.   else
  98.     toggleOff("Wither Spawner")
  99.     pa1:setOff("Wither Spawner")
  100.   end
  101.   if l == true then
  102.     toggleOn("Netherstar Gen")
  103.     pa1:setOn("Netherstar Gen")
  104.   else
  105.     toggleOff("Netherstar Gen")
  106.     pa1:setOff("Netherstar Gen")
  107.   end
  108.   if w == true then
  109.     toggleOn("Mana C Spawner")
  110.     pa1:setOn("Mana C Spawner")
  111.   else
  112.     toggleOff("Mana C Spawner")
  113.     pa1:setOff("Mana C Spawner")
  114.   end
  115.   if o == true then
  116.     toggleOn("Obsidian Prod")
  117.     pa1:setOn("Obsidian Prod")
  118.   else
  119.     toggleOff("Obsidian Prod")
  120.     pa1:setOff("Obsidian Prod")
  121.   end
  122.   if b == true then
  123.     toggleOn("Lava Production")
  124.     pa1:setOn("Lava Production")
  125.   else
  126.     toggleOff("Lava Production")
  127.     pa1:setOff("Lava Production")
  128.   end
  129.   if p == true then
  130.     toggleOn("Test Button")
  131.     pa1:setOn("Test Button")
  132.   else
  133.     toggleOff("Test Button")
  134.     pa1:setOff("Test Button")
  135.   end
  136. end
  137.  
  138. function render()
  139.   if p1S == true then
  140.     pa1:draw()
  141.   elseif p2S == true then
  142.     pa2:draw()
  143.   end
  144. end
  145.  
  146. function run()
  147.   while true do
  148.     buttonPress()
  149.     render()
  150.   end
  151. end
  152.  
  153. function startup()
  154.   load()
  155.   setMonitors()
  156.   loadButtons()
  157.   getStates()
  158.   setStates()
  159. end
  160.  
  161. -- Actual Program --
  162. startup()
  163. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement