Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- easyMenu by pingoleon60
- -- split function by Egor Skriptunoff
- function split(str, max_line_length)
- local lines = { }
- local line
- str:gsub('(%s*)(%S+)',
- function(spc, word)
- if not line or string.len(line) + string.len(spc) + string.len(word) > max_line_length then
- table.insert(lines, line)
- line = word
- else
- line = line..spc..word
- end
- end
- )
- table.insert(lines, line)
- return lines
- end
- renderBox = function(x, y, x2, name, text)
- term.setCursorPos(x, y)
- write("+-"..name)
- for i = 1, x2 - x - 2 - string.len(name) do
- write("-")
- end
- write("+")
- term.setCursorPos(x, y+1)
- term.write("|")
- term.setCursorPos(x2-1, y+1)
- term.write("|")
- local nowY = y + 2
- for _, line in ipairs(split(text, x2 - x - 4)) do
- term.setCursorPos(x, nowY)
- write("| ")
- write(line)
- term.setCursorPos(x2-1, nowY)
- write("|")
- nowY = nowY + 1
- end
- term.setCursorPos(x, nowY)
- term.write("|")
- term.setCursorPos(x2-1, nowY)
- term.write("|")
- nowY = nowY + 1
- term.setCursorPos(x, nowY)
- term.write("+")
- for i = 1, x2 - x - 1 do
- term.write("-")
- end
- term.write("+")
- end
- --Objects
- _easyMenuObjectDontTouch = { }
- _easyMenuObjectDontTouch.x = 1
- _easyMenuObjectDontTouch.y = 1
- _easyMenuObjectDontTouch.weight = 20
- _easyMenuObjectDontTouch.name = "easyMenu"
- _easyMenuObjectDontTouch.message = "Customize the message with easyMenu.setMessage !"
- _easyMenuObjectDontTouch.render = false
- function setMessage(message)
- _easyMenuObjectDontTouch.message = message
- renderBoxObject()
- end
- function setCoords(x, y)
- _easyMenuObjectDontTouch.x = x
- _easyMenuObjectDontTouch.y = y
- renderBoxObject()
- end
- function setWeight(weight)
- _easyMenuObjectDontTouch.weight = weight
- renderBoxObject()
- end
- function setName(name)
- _easyMenuObjectDontTouch.name = name
- renderBoxObject()
- end
- function setRender(boolean)
- if type(boolean) == "boolean" then
- _easyMenuObjectDontTouch.render = boolean
- renderBoxObject()
- end
- end
- function renderBoxObject()
- if _easyMenuObjectDontTouch.render then
- renderBox(_easyMenuObjectDontTouch.x, _easyMenuObjectDontTouch.y, _easyMenuObjectDontTouch.x + _easyMenuObjectDontTouch.weight, _easyMenuObjectDontTouch.name, _easyMenuObjectDontTouch.message)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement