Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local coords1 = {}
- local coords2 = {}
- local text = {}
- local colors1 = {}
- local colors2 = {}
- local textInt, x, y, k, j, i, l
- local event, button, xCoord, yCoord, sSide
- local input
- -- Draws a button on the screen
- function drawButton(coord1, coord2, coord3, coord4, text, color1, color2)
- x = coord3 - coord1 + 2
- y = coord4 - coord2 + 2
- -- Draws the button itself
- term.setBackgroundColor(color1)
- k = 0
- while (k < y) do
- term.setCursorPos(coord1, coord2 + k)
- j = 0
- while (j < x) do
- write(" ")
- j = j + 1
- end
- k = k + 1
- end
- -- Writes the text on the button
- if (string.len(text) % 2 == 0) then
- textInt = string.len(text) / 2
- else
- textInt = (string.len(text) - 1) / 2
- end
- if (x % 2 == 0) then
- if (y % 2 == 0) then
- term.setCursorPos(x / 2 + coord1 - textInt, y / 2 + coord2)
- else
- term.setCursorPos(x / 2 + coord1 - textInt, (y - 1) / 2 + coord2)
- end
- else
- if (y % 2 == 0) then
- term.setCursorPos((x - 1) / 2 + coord1 - textInt, y / 2 + coord2)
- else
- term.setCursorPos((x - 1) / 2 + coord1 - textInt, (y - 1) / 2 + coord2)
- end
- end
- term.setTextColor(color2)
- write(text)
- end
- -- Shows the buttons on the computer
- -- Returns the number of the button
- function showComputer()
- -- Draws the buttons
- i = 1
- l = 1
- while (i < #coords1) do
- drawButton(coords1[i], coords1[i + 1], coords2[i], coords2[i + 1], text[l], colors1[l], colors2[l])
- i = i + 2
- l = l + 1
- end
- -- Waits until there is clicked on one of the buttons
- local bool = true
- l = 0
- while (bool) and (#coords1 ~= 0) do
- event, button, xCoord, yCoord = os.pullEvent("mouse_click")
- if (event == "mouse_click") then
- i = 1
- l = 1
- while (i <= #coords1) do
- if (xCoord >= coords1[i]) and (xCoord <= coords2[i]) and (yCoord >= coords1[i + 1]) and (yCoord <= coords2[i + 1]) then
- bool = false
- break
- end
- i = i + 2
- l = l + 1
- end
- end
- end
- return l
- end
- -- Shows the buttons on a monitor
- -- Returns the number of the button
- function showMonitor(side)
- -- Draws the buttons
- i = 1
- l = 1
- while (i < #coords1) do
- term.redirect(peripheral.wrap(side))
- drawButton(coords1[i], coords1[i + 1], coords2[i], coords2[i + 1], text[l], colors1[l], colors2[l])
- term.restore()
- i = i + 2
- l = l + 1
- end
- -- Waits until there is clicked on one of the buttons
- local bool = true
- l = 0
- while (bool) and (#coords1 ~= 0) do
- event, sSide, xCoord, yCoord = os.pullEvent("monitor_touch")
- if (event == "monitor_touch") then
- if (sSide == side) then
- i = 1
- l = 1
- while (i <= #coords1) do
- if (xCoord >= coords1[i]) and (xCoord <= coords2[i]) and (yCoord >= coords1[i + 1]) and (yCoord <= coords2[i + 1]) then
- bool = false
- break
- end
- i = i + 2
- l = l + 1
- end
- end
- end
- end
- return l
- end
- -- Shows the buttons on the computer
- -- Return on [enter]
- -- Returns the number of the button and the text input
- function showComputerRead(coord1, coord2, color1, color2)
- -- Draws the buttons
- i = 1
- l = 1
- while (i < #coords1) do
- drawButton(coords1[i], coords1[i + 1], coords2[i], coords2[i + 1], text[l], colors1[l], colors2[l])
- i = i + 2
- l = l + 1
- end
- -- Waits until there is clicked on one of the buttons or someone pressed [enter]
- term.setCursorPos(coord1, coord2)
- term.setBackgroundColor(color1)
- term.setTextColor(color2)
- local bool = true
- input = ""
- l = 0
- while (bool) and (#coords1 ~= 0) do
- l = 0
- parallel.waitForAny(function() event, button, xCoord, yCoord = os.pullEvent("mouse_click") end, function() input = read() end)
- if (event == "mouse_click") then
- i = 1
- l = 1
- while (i <= #coords1) do
- if (xCoord >= coords1[i]) and (xCoord <= coords2[i]) and (yCoord >= coords1[i + 1]) and (yCoord <= coords2[i + 1]) then
- bool = false
- break
- end
- i = i + 2
- l = l + 1
- end
- elseif (input ~= "") then
- break
- end
- end
- return l, input
- end
- -- Shows the buttons on a monitor
- -- Return on [enter]
- -- Returns the number of the button and the text input
- function showMonitorRead(coord1, coord2, side, color1, color2)
- -- Draws the buttons on the monitor
- i = 1
- l = 1
- while (i < #coords1) do
- term.redirect(peripheral.wrap(side))
- drawButton(coords1[i], coords1[i + 1], coords2[i], coords2[i + 1], text[l], colors1[l], colors2[l])
- term.restore()
- i = i + 2
- l = l + 1
- end
- -- Waits until there is clicked on one of the buttons or someone pressed [enter]
- term.setCursorPos(coord1, coord2)
- term.setBackgroundColor(color1)
- term.setTextColor(color2)
- local bool = true
- input = ""
- l = 0
- while (bool) and (#coords1 ~= 0) do
- l = 0
- parallel.waitForAny(function() event, sSide, xCoord, yCoord = os.pullEvent("monitor_touch") end, function() input = read() end)
- if (event == "monitor_touch") then
- if (sSide == side) then
- i = 1
- l = 1
- while (i <= #coords1) do
- if (xCoord >= coords1[i]) and (xCoord <= coords2[i]) and (yCoord >= coords1[i + 1]) and (yCoord <= coords2[i + 1]) then
- bool = false
- break
- end
- i = i + 2
- l = l + 1
- end
- end
- elseif (input ~= "") then
- break
- end
- end
- return l, input
- end
- -- Adds a button to the table
- function addButton(coord1, coord2, coord3, coord4, sText, color1, color2)
- table.insert(coords1, coord1)
- table.insert(coords1, coord2)
- table.insert(coords2, coord3)
- table.insert(coords2, coord4)
- table.insert(text, sText)
- table.insert(colors1, color1)
- table.insert(colors2, color2)
- end
- -- Clears the table
- function clearButton()
- coords1 = {}
- coords2 = {}
- text = {}
- colors1 = {}
- colors2 = {}
- end
Add Comment
Please, Sign In to add comment