Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --//MultiSign
- --//Returns an empty table. Obviously you can make an empty table of your own directly I added this for sake of completeness. The table is needed to add new signInstructions that can be drawn
- function createSignHolder()
- return {}
- end
- --//Adds a new sign to a sign holder (table created by above method). You need to specify which table you are adding to (signHolder), and the side that the monitor is on. You should need to provide a function to draw the sign as well as any arguments needed (store an arbitrary amount of arguments inside a table and pass it to functionArgs)
- function addNewSign(signHolder, monitorSide, drawFunction, drawFunctionArgs)
- local t = {
- ["monitor"] = monitorSide,
- ["drawFunction"] = drawFunction,
- ["functionArgs"] = drawFunctionArgs,
- }
- table.insert(signHolder, 0, t)
- return t
- end
- --//Wrapper function that can be called to organise all the right parameters to in turn call properly another function (called basicLabel). If you want to call basicLabel to draw your signs, pass this function as the drawFunction parameter in addNewSign
- function basicLabelWrapper(mon, args)
- basicLabel(mon, args["text"], args["background"], args["border"], args["title"], args["subTitle"], args["textSize"])
- end
- --//An automatic way of adding arguments to basicLabelWrapper. title is required. Everything else has defaults or safely defaults to nil. This method returns a table which arranges all the parameters using the correct keys, ensuring fewer errors. It is not strictly necessary as you can make the tables manually. Pass the returned table into drawFunctionArgs in addNewSign()
- function createSignArgsBasicLabel(title, subTitle, textSize, textColor, backGroundColor, borderColor)
- if title == nil then
- error("No title provided")
- end
- local t = {
- ["text"] = textColor or colors.white,
- ["background"] = backGroundColor or colors.black,
- ["border"] = borderColor,
- ["title"] = title,
- ["subTitle"] = subTitle,
- ["textSize"] = textSize or 1,
- }
- return t
- end
- --//Pass a signHolder (containing an arbitrary number of sign tables made with addNewSign()) and drawSigns will loop through it and attempt to draw all your signs to your monitors. Make sure your monitors are connected.
- function drawSigns(signHolder)
- for i,v in pairs(signHolder) do
- local monSide = v["monitor"]
- local func = v["drawFunction"]
- local args = v["functionArgs"]
- local mon = nil
- print(monSide)
- if type(monSide) ~= "string" then
- local str = "Setting Sign at: "
- local isAdjacent = false
- for i,v in pairs(redstone.getSides()) do
- if monSide == v then
- isAdjacent = true
- break
- end
- end
- if isAdjacent == true then
- str = str.."monitor_"..monSide
- else
- str = str..monSide
- end
- print(str)
- end
- mon = peripheral.wrap(monSide)
- print(type(mon))
- if type(mon) == "table" then
- func(mon, args)
- else
- print("No valid monitor provided, skipping this sign. Key = "..i)
- end
- end
- end
- --//This function actually draws the signs. This can't be called directly inside the drawSigns function so don't run it through addNewSign(). Use the basicLabelWrapper instead. Otherwise, feel free to use it.
- function basicLabel(mon, text, background, border, title, subTitle, textSize)
- if textSize == nil then
- textSize = 1
- end
- mon.setTextScale(textSize)
- local x,y = mon.getSize()
- mon.setBackgroundColor(background)
- mon.clear()
- if border ~= nil then
- mon.setBackgroundColor(border)
- for i = 1,x do
- for j = 1,y do
- if (i == 1 or i == x) or (j == 1 or j == y) then
- mon.setCursorPos(i,j)
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(background)
- end
- mon.setTextColor(text)
- local tLength = string.len(title)
- local height = nil
- if subTitle ~= nil then
- if y % 2 == 0 then
- height = 2
- else
- height = 3
- end
- else
- height = 1
- end
- local nX = (x/2)-(tLength/2) + 1
- local nY = (y/2)-(height/2) + 1
- mon.setCursorPos(nX,nY)
- mon.write(title)
- if subTitle ~= nil then
- local sTlength = string.len(subTitle)
- nX = (x/2)-(sTlength/2) + 1
- nY = (y/2)+(height/2)
- mon.setCursorPos(nX,nY)
- mon.write(subTitle)
- end
- end
- local newSignHolder = createSignHolder()
- local temp = nil
- --[[
- --If you wish to test this program yourself, make sure to edit the monitor side names accordingly
- --Remove the long comments (--[[...]]) to allow this code to run.
- temp = createSignArgsBasicLabel("Hello", "World", 2, colors.cyan, colors.black, colors.orange)
- addNewSign(newSignHolder, "monitor_0", basicLabelWrapper, temp)
- temp = createSignArgsBasicLabel("I'm a sign", nil, 1.5, colors.lightBlue, colors.black, colors.purple)
- addNewSign(newSignHolder, "monitor_1", basicLabelWrapper, temp)
- temp = createSignArgsBasicLabel("Borders are", "Optional", 1, colors.red, colors.black, nil)
- addNewSign(newSignHolder, "monitor_2", basicLabelWrapper, temp)
- temp = createSignArgsBasicLabel("Optional", "Subtitles", 2, colors.yellow, colors.black, colors.purple)
- addNewSign(newSignHolder, "monitor_3", basicLabelWrapper, temp)
- drawSigns(newSignHolder)
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement