Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Used to easily create button terminals with functions. Check https://pastebin.com/iNT0XGqc for an example use
- Every time I tried to make this an object things got annoying. Still working on improving this.
- --]]
- function new(xPos, yPos, length, height, text, action)
- button = {
- xStart = 1,
- yStart = 1,
- xEnd = 1,
- yEnd = 1,
- text = "",
- action = nil
- }
- if not length then
- length = 1
- end
- if not height then
- height = 1
- end
- button.xStart = xPos
- button.yStart = yPos
- button.xEnd = xPos + length - 1
- button.yEnd = yPos + height - 1
- if text then
- button.text = text
- end
- if action then
- button.action = action
- end
- return button
- end
- function setText(self, text)
- if text then
- self.text = text
- end
- return self
- end
- function draw(self, colour)
- if colour then
- oldColour = term.getBackgroundColour()
- term.setBackgroundColour(colour)
- end
- paintutils.drawFilledBox(self.xStart,self.yStart,self.xEnd,self.yEnd)
- term.setCursorPos(math.ceil(self.xStart + (self.xEnd-self.xStart)/2 - string.len(self.text)/2), math.floor( self.yStart+(self.yEnd-self.yStart)/2))
- print(self.text)
- if colour then
- term.setBackgroundColour(oldColour)
- end
- end
- function inBounds(self, xPos, yPos)
- return (xPos >= self.xStart and yPos >= self.yStart and xPos <= self.xEnd and yPos <= self.yEnd)
- end
Advertisement
Add Comment
Please, Sign In to add comment