Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Nebulae Interactive API (nInteractive)]]--
- --[[Made by GamerNebulae]]--
- --[[You are allowed to modify the code, as long as I get credit..]]
- --Declaring variables
- --Local variables
- local bInactiveBackground
- local bActiveBackground
- --Global variables
- bData = {}
- pbData = {}
- clickedID = ""
- m = ""
- --Monitor Functions
- function findMonitor()
- local p = peripheral.getNames()
- for k,v in pairs(p) do
- if (v == "top" or v == "bottom" or v == "left" or v == "back" or v == "right" or v == "front") then
- if (string.find(peripheral.getType(v), "monitor")) then
- m = peripheral.wrap(v)
- end
- elseif (string.find(v, "monitor")) then
- m = peripheral.wrap(v)
- end
- end
- end
- function mClear()
- m.clear()
- m.setTextColor(colors.white)
- m.setBackgroundColor(colors["black"])
- end
- function mCreatePage()
- end
- function mHeadline(text)
- local x,y = m.getSize()
- xText = math.floor((x / 2) - (#text / 2) + 1)
- m.setCursorPos(xText, 1)
- m.write(text)
- end
- function mOverrideInactiveBackground(color)
- bInactiveBackground = tostring(color)
- end
- function mOverrideActiveBackground(color)
- bActiveBackground = tostring(color)
- end
- function mCreateButton(ID, text, pX, qX, pY, qY)
- bData[ID] = {}
- bData[ID]["text"] = text
- bData[ID]["pX"] = pX
- bData[ID]["qX"] = qX
- bData[ID]["pY"] = pY
- bData[ID]["qY"] = qY
- bData[ID]["state"] = false
- mDrawButton(ID)
- end
- function mDrawButton(ID)
- if (not bData[ID]["state"] and not bInactiveBackground) then
- m.setBackgroundColor(colors["red"])
- elseif (not bData[ID]["state"]) then
- m.setBackgroundColor(colors[bInactiveBackground])
- elseif (bData[ID]["state"] and not bActiveBackground) then
- m.setBackgroundColor(colors["lime"])
- elseif (bData[ID]["state"]) then
- m.setBackgroundColor(colors[bActiveBackground])
- end
- local yText = math.floor((bData[ID]["pY"] + bData[ID]["qY"]) / 2)
- local xText = math.floor(((bData[ID]["pX"] + bData[ID]["qX"]) / 2) - (#bData[ID]["text"] / 2) + 1)
- for y = bData[ID]["pY"], bData[ID]["qY"] do
- if (y == yText) then
- for x = bData[ID]["pX"], (bData[ID]["pX"] + bData[ID]["qX"]) / 2 do
- m.setCursorPos(x,y)
- m.write(" ")
- end
- m.setCursorPos(xText, y)
- m.write(bData[ID]["text"])
- for x = xText + #bData[ID]["text"], bData[ID]["qX"] do
- m.setCursorPos(x,y)
- m.write(" ")
- end
- else
- for x = bData[ID]["pX"], bData[ID]["qX"] do
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- end
- m.setBackgroundColor(colors["black"])
- end
- function splitText(xText, xSteps, y, text, color)
- local dataText = {}
- for k,v in text:gmatch"." do
- dataText[#dataText + 1] = tostring(k)
- end
- local lettersColored = xSteps - xText + 1
- m.setBackgroundColor(colors[color])
- for x = xText, xText + lettersColored - 1 do
- m.setCursorPos(x, y)
- m.write(dataText[x - (xText - 1)])
- end
- m.setBackgroundColor(colors["black"])
- for x = xText + lettersColored - 1, xText + #text - 1 do
- m.setCursorPos(x, y)
- m.write(dataText[x - (xText - 1)])
- end
- end
- function mDrawProgressBar(ID)
- local xSize, ySize = m.getSize()
- local xTitle = math.floor(((1 + xSize) / 2) - (#pbData[ID]["title"] / 2) + 1)
- m.setCursorPos(xTitle, pbData[ID]["yTitle"])
- m.setTextColor(colors[pbData[ID]["titleColor"]])
- m.write(pbData[ID]["title"])
- local percent = pbData[ID]["value"] / pbData[ID]["maximum"]
- local xSteps = math.floor(xSize * percent)
- local text = pbData[ID]["value"].." / "..pbData[ID]["maximum"]
- local textLength = #(text)
- local xText = math.floor(((1 + xSize) / 2) - (textLength / 2) + 1)
- m.setBackgroundColor(colors[pbData[ID]["barColor"]])
- m.setTextColor(colors["white"])
- if (xSteps < xText) then
- for x = 1, xSteps do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- m.setBackgroundColor(colors["black"])
- m.setCursorPos(xText, pbData[ID]["yBar"])
- m.write(text)
- for x = xText + #text, xSize do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- elseif (xSteps == (xText + #text - 1)) then
- for x = 1, xText - 1 do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- m.write(text)
- m.setBackgroundColor(colors["black"])
- for x = xText + #text, xSize do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- elseif (xSteps >= xText and xSteps < (xText + #text - 1)) then
- for x = 1, xText - 1 do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- splitText(xText, xSteps, pbData[ID]["yBar"], text, pbData[ID]["barColor"])
- m.setBackgroundColor(colors["black"])
- for x = xText + #text, xSize do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- else
- for x = 1, xSteps do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- m.setCursorPos(xText, pbData[ID]["yBar"])
- m.write(text)
- for x = xText + #text, xSteps do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- if xSteps ~= xSize then
- m.setBackgroundColor(colors["black"])
- for x = xSteps + 1, xSize do
- m.setCursorPos(x, pbData[ID]["yBar"])
- m.write(" ")
- end
- end
- end
- m.setBackgroundColor(colors["black"])
- end
- function mCreateProgressBar(ID, title, yTitle, titleColor, value, maximum, yBar, barColor)
- pbData[ID] = {}
- pbData[ID]["title"] = title
- pbData[ID]["yTitle"] = yTitle
- pbData[ID]["titleColor"] = titleColor
- pbData[ID]["value"] = value
- pbData[ID]["maximum"] = maximum
- pbData[ID]["yBar"] = yBar
- pbData[ID]["barColor"] = barColor
- mDrawProgressBar(ID)
- end
- function mButtonListen()
- event, _, x, y = os.pullEvent()
- if (event == "monitor_touch") then
- for key, value in pairs(bData) do
- if (x >= bData[key]["pX"] and x <= bData[key]["qX"] and y >= bData[key]["pY"] and y <= bData[key]["qY"]) then
- clickedID = key
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement