Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://pastebin.com/D8yWJ7rh
- peripheral.wrap("top").setTextScale(3)
- function newManager(side)
- manager = {
- buttons = {},
- labels = {},
- monitor = peripheral.wrap(side),
- newButton = function(self, label)
- print("creating button ''"..label.."''")
- self.labels[#self.labels + 1] = label
- self.buttons[label] = {
- label = label,
- text = "[ ] "..label,
- active = false,
- row = 0
- }
- end,
- draw = function(self)
- print("starting draw()")
- self.monitor.clear()
- print("cleared monitor")
- self.monitor.setCursorPos(1,2)
- print("set cursor position")
- local yPos = 2
- print("starting loop: "..#self.labels)
- print(self.buttons["Iron"].label)
- for i = 1, #self.labels do
- local button = self.buttons[self.labels[i]]
- print("working on button "..button.label)
- self.monitor.write(button.text)
- button.row = yPos
- yPos = yPos + 1
- self.monitor.setCursorPos(1,yPos)
- end
- end,
- run = function(self)
- while true do
- local event, side, x, y = os.pullEvent( "monitor_touch" )
- print(event)
- print(side)
- for i = 1, #self.labels do
- local button = self.buttons[self.labels[i]]
- if button.row == y then
- print("found row!")
- button.active = not button.active
- break
- end
- end
- for i = 1, #self.labels do
- local button = self.buttons[self.labels[i]]
- if button.active then
- button.text = "[X] "..button.label
- else
- button.text = "[ ] "..button.label
- end
- end
- self:draw()
- end
- end
- }
- return manager
- end
- local mgr = newManager("top")
- mgr:newButton("Iron")
- mgr:newButton("Dye")
- mgr:newButton("Coal")
- mgr:draw()
- mgr:run()
Add Comment
Please, Sign In to add comment