Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --config
- local amountOfButtons = 8
- local buttonWidth = 11
- local buttonHeight = 3
- local verticalButtonSpace = 2
- local
- --end of config
- local screenSizeX,screenSizeY = term.getSize()
- local buttons = {}
- for i=1,amountOfButtons do
- buttons[i] = {xPos=0, yPos=0, width=buttonWidth, height=buttonHeight, name="", color=colors.red, action=function()}
- end
- local calculatePositions = function()
- for i=1,math.floor(amountOfButtons/2 + 0.5) do
- if amountOfButtons > 1 then
- buttons[i].xPos = math.floor((screenSizeX - 2 * buttonWidth)/3) + 1
- else
- buttons[i].xPos = math.floor((screenSizeX - buttonWidth)/2) + 1
- end
- buttons[i].yPos = 3 + (i-1) * verticalButtonSpace + (i-1) * buttonHeight
- end
- for i=1,math.floor(amountOfButtons/2) do
- buttons[i + math.floor(amountOfButtons/2)].xPos = math.floor(buttonWidth + 2 * (screenSizeX - 2 * buttonWidth)/3) + 1
- buttons[i + math.floor(amountOfButtons/2)].yPos = 3 + (i-1) * verticalButtonSpace + (i-1) * buttonHeight
- end
- end
- local isClicked = function(button, xClick, yClick)
- if xClick >= buttons.xPos and xClick < buttons.xPos + buttons.width and yClick >= buttons.yPos and yClick < buttons.yPos + buttons.height then
- return true
- else
- return false
- end
- end
- local event,mouseButton,xPos,yPos
- local handleInput = function()
- event,mouseButton,xPos,yPos = os.pullEventRaw()
- if event = "mouse_click" then
- for i=1,amountOfButtons do
- if isClicked(buttons[i],xPos,yPos) then
- buttons[i].action()
- end
- end
- end
- end
- local draw = function()
- for i=1,amountOfButtons do
- term.setBackgroundColor(buttons[i].color)
- for j=1,buttons[i].height do
- for k=1,buttons[i].width do
- term.setCursorPos(buttons[i].xPos + k -1, buttons[i].yPos + j -1)
- term.write(" ")
- end
- end
- term.setCursorPos(buttons[i].xPos + math.floor((buttons[i].width - string.len(buttons[i].name))/2), buttons[i].yPos + math.floor(buttons[i].height/2))
- term.write(buttons[i].name)
- end
- end
- local loop = function()
- while true do
- draw()
- handleInput()
- end
- end
- --actually running the program
- calculatePositions()
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement