Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buttonList = {}
- Buttons = {}
- Buttons.__index = Buttons
- function createButton( name, func )
- button = {}
- setmetatable(button,Buttons)
- button.name = name
- button.action = func
- return button
- end
- function Buttons:toggle( newColor,sec )
- self:draw( self.x,self.y,self.width,newColor,self.tcolor)
- if sec ~= nil then
- sleep(sec)
- self:draw( self.x,self.y,self.width,self.color,self.tcolor )
- end
- end
- function Buttons:draw( x,y,width,color,tcolor )
- table.insert(buttonList,{self.name,x,y,width,self.action})
- self.x = x
- self.y = y
- self.width = width
- if self.tcolor == nil then
- self.color = color
- end
- self.tcolor = tcolor
- for i = 1,width do
- paintutils.drawLine(x, y + i, x + #self.name + 1, y + i, color)
- end
- term.setCursorPos(x,y + math.ceil(width/2))
- term.setTextColor(tcolor)
- term.setBackgroundColor(color)
- term.write(" "..self.name.." ")
- end
- function Buttons:trigger()
- buttonList[i][5]()
- end
- function Buttons:remove()
- for i = 1,#buttonList do
- if self.name == buttonList[i][1] then
- table.remove(buttonList,i)
- end
- end
- self = nil
- end
- function detect( x,y,trigger )
- for i = 1,#buttonList do
- if x >= buttonList[i][2] and x <= buttonList[i][2] + #buttonList[i][1] and y >= buttonList[i][3] and y <= buttonList[i][3] + buttonList[i][4] then
- if trigger == true then
- buttonList[i][5]()
- end
- return buttonList[i][1]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment