Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {}
- local buttonProperties = {"x", "y", "width", "height", "text", "textColor", "color", "click"}
- function newButton(_x, _y, _w, _h, _t, _tc, _c, _cl)
- local args = {_x, _y, _w, _h, _t, _tc, _c, _cl,}
- buttons[#buttons+1] = {}
- for _, key in pairs(buttonProperties) do
- buttons[#buttons][key] = args[_]
- end
- buttons[#buttons].enabled = true
- local _buttonObj = {
- id = #buttons,
- set = function(self, key, value)
- buttons[self.id][key] = value
- end,
- get = function(self, key)
- return buttons[self.id][key]
- end
- }
- return _buttonObj
- end
- function drawButtons(monitor)
- if not monitor == "t" then
- term.redirect(monitor)
- end
- for _, button in pairs(buttons) do
- if button.enabled then
- paintutils.drawFilledBox(button.x, button.y, (button.x + button.width - 1), (button.y + button.height - 1), button.color)
- term.setCursorPos(math.floor(button.x + (button.width / 2) - (#button.text / 2)),math.floor(button.y + (button.height / 2)))
- term.setTextColor(button.textColor)
- term.setBackgroundColor(button.color)
- term.write(button.text)
- --term.blit(button.text, button.textColor, button.color)
- end
- end
- if not monitor == "t" then
- term.native()
- end
- end
- function drawDummyButtons(monitor)
- if not monitor == "t" then
- term.redirect(monitor)
- end
- for _, button in pairs(buttons) do
- if button.enabled then
- term.setCursorPos(button.x, button.y)
- term.blit(button.text, button.textColor, button.color)
- end
- end
- end
- function checkDummy(_x, _y)
- for _, button in pairs(buttons) do
- if button.enabled then
- if _y == button.y then
- if _x >= button.x and _x <= (button.x + #button.text) then
- return button.click
- end
- end
- end
- end
- end
- function checkButtons(_x, _y)
- for _, button in pairs(buttons) do
- if button.enabled then
- if _x >= button.x and _x <= (button.x + button.width) then
- if _y >= button.y and _y <= (button.y + button.height) then
- return button.click
- end
- end
- end
- end
- return nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement