Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local colors = require("colors")
- local event = require("event")
- local button = require("C/b")
- local term = require("term")
- local function findComps(type)
- local comps = {}
- local compNames = {}
- for cAddress,cType in component.list(type) do
- -- Insert proxy methods table into comps table
- table.insert(comps, component.proxy(cAddress))
- -- Insert component type into compNames table
- table.insert(compNames, cType)
- end
- return comps, compNames
- end
- local function toggleMachine(cButton, argsT)
- local cbutton = button.toggle(cButton)
- local str = 0
- if argsT.alt then
- if cButton.state then str = 0 else str = 250 end
- else
- if cButton.state then str = 250 else str = 0 end
- end
- rs.setBundledOutput(argsT.side, argsT.machineList[cButton.label], str) -- side, color, strength
- return cbutton
- end
- local function reboot(cButton, argsT)
- if not computer then computer = require("computer") end
- computer.shutdown(true)
- end
- local function setAllChannels(side, state)
- local strength = 0
- if state then strength = 250 end
- for i=0, 15 do
- rs.setBundledOutput(side, i, strength)
- end
- end
- local machineList =
- {
- Witch = colors.white,
- Maze_Slime = colors.orange,
- Enderman = colors.magenta,
- Blue_Slime = colors.lightblue,
- Blaze = colors.yellow,
- Cow = colors.lime,
- }
- -- Button properties
- local buttonList = {}
- local action = toggleMachine
- local actionArgT = {side=5, machineList=machineList}
- local width = 30
- local height = 7
- local padding = "1:0:0:1"
- local col = "0x00AA00:0xAA0000"
- -- Buttons are rendered in the order they are generated in
- -- Since tables are not ordered, machineList buttons will not be in order on the screen
- -- Generate machine toggle buttons from machineList
- for k,v in pairs(machineList) do
- table.insert(buttonList, button.newButton(buttonList, k, action, actionArgT, width, height, padding, col, false))
- end
- -- Alternate button generation list for special buttons
- local cMList = { Slaughterhouse = colors.red, Grinders = colors.green, Killer_Joe = colors.black, MFR_1 = colors.brown, MFR_2 = colors.blue, }
- -- MFR
- table.insert(buttonList, button.newButton(buttonList, "MFR_1", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", false))
- table.insert(buttonList, button.newButton(buttonList, "MFR_2", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", false))
- -- Slaughterhouse control
- table.insert(buttonList, button.newButton(buttonList, "Slaughterhouse", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", false))
- -- Main grinder control
- table.insert(buttonList, button.newButton(buttonList, "Grinders", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", true))
- -- Killer Joe control
- table.insert(buttonList, button.newButton(buttonList, "Killer_Joe", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", true))
- -- Reboot button
- table.insert(buttonList, button.newButton(buttonList, "REBOOT", reboot, {}, width, height, padding, "0x5555FF:0x5555FF", false))
- -- Retrieve redstone component
- comps, compNames = findComps("redstone")
- rs = comps[1]
- -- Default states for these buttons
- rs.setBundledOutput(actionArgT.side, cMList.Slaughterhouse, 250)
- rs.setBundledOutput(actionArgT.side, cMList.MFR_1, 250)
- rs.setBundledOutput(actionArgT.side, cMList.MFR_2, 250)
- button.renderAll(buttonList)
- while true do
- local x, y
- if event then
- _, _, x, y = event.pull("touch")
- else
- xMax,xMin,yMax,yMin = os.pullEvent("monitor_touch")
- end
- local buttonList, pressed, onButton = button.checkTouch(buttonList, x, y)
- if onButton then button.render(pressed) else button.renderAll(buttonList) end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement