Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MCjPAhyz
- local p = peripheral.wrap("back")
- p.clear()
- local mon = {}
- mon.minY = 8 * 9
- mon.maxY = 24 * 9 + 4
- mon.minX = 0 * 6
- mon.maxX = 68 * 6 + 4
- mon.rows = math.floor((mon.maxY - mon.minY) / 9)
- mon.cols = math.floor((mon.maxX - mon.minX) / 6)
- mon.lines = {}
- mon.mtrx = {}
- for i = 1, mon.rows do
- mon.mtrx[i] = {}
- end
- mon.scale = 1
- mon.curr = 1
- mon.curc = 1
- mon.cur = p.addText(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2, math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2, " ", 0)
- mon.colors = {[1] = 0xffffff, [2] = 0xffc125, [4] = 0xff3e96, [8] = 0x836fff, [16] = 0xffff00, [32] = 0x00ff00, [64] = 0xff82ab, [128] = 0x444444, [256] = 0x999999, [512] = 0x009acd, [1024] = 0x9400d3, [2048] = 0x0000ff, [4096] = 0x8b5a2b, [8192] = 0x458b00, [16384] = 0xff0000, [32768] = 0}
- mon.bgColor = 0
- mon.color = 0xffffff
- mon.box = p.addBox(mon.minX, mon.minY, mon.maxX - mon.minX + 1, mon.maxY - mon.minY + 1, mon.bgColor, 0)
- mon.box.setZIndex(-1)
- mon.write = function(s)
- for i = 1, #s do
- local x = math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2
- local y = math.floor((mon.curr - 1) * 9 * mon.scale) + mon.minY + 2
- local j = 1
- local t = mon.mtrx[mon.curr][mon.curc]
- if t then
- t.delete()
- end
- t = p.addText(x, y, s:sub(i,i), mon.color)
- mon.mtrx[mon.curr][mon.curc] = t
- mon.lines[#mon.lines + 1] = t
- mon.curc = mon.curc + 1
- if mon.curc > mon.cols then
- mon.curc = 1
- if mon.curr == mon.rows then
- return
- else
- mon.curr = mon.curr + 1
- end
- end
- end
- mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
- mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
- end
- mon.clear = function()
- for i = 1, #mon.lines do
- mon.lines[i].delete()
- mon.lines[i] = nil
- end
- end
- mon.clearLine = function(n)
- local y = math.floor(((n or mon.curr) - 1) * 9 * mon.scale) + mon.minY + 2
- local i = 1
- while i <= #mon.lines do
- if not mon.lines[i].getY() or mon.lines[i].getY() == y then
- mon.lines[i].delete()
- mon.lines[i] = mon.lines[#mon.lines]
- mon.lines[#mon.lines] = nil
- else
- i = i + 1
- end
- end
- end
- mon.scroll = function()
- mon.clearLine(1)
- local i = 1
- while i <= #mon.lines do
- if not mon.lines[i].getY() then
- mon.lines[i].delete()
- mon.lines[i] = mon.lines[#mon.lines]
- mon.lines[#mon.lines] = nil
- else
- mon.lines[i].setY(mon.lines[i].getY() - (9 * mon.scale))
- i = i + 1
- end
- end
- for i = 1, mon.rows - 1 do
- mon.mtrx[i] = mon.mtrx[i + 1]
- end
- mon.mtrx[mon.rows] = {}
- end
- mon.setBackgroundColor = function(n)
- if mon.colors[n] then
- n = mon.colors[n]
- end
- mon.bgColor = n
- mon.box.setColor(n)
- mon.box.setOpacity(n == 0 and 0 or 0.40)
- end
- mon.setBackgroundColour = mon.setBackgroundColor
- mon.setTextColor = function(n)
- if mon.colors[n] then
- n = mon.colors[n]
- end
- mon.color = n
- mon.cur.setColor(n)
- end
- mon.setTextColour = mon.setTextColor
- mon.setTextScale = function(n)
- mon.rows = math.floor((mon.maxY - mon.minY - 4)/(9 * n))
- mon.cols = math.floor((mon.maxX - mon.minX - 4)/(6 * n))
- local y = nil
- local x = nil
- if n > mon.scale then
- y = math.floor((mon.rows + 1) * 9 * mon.scale) + mon.minY + 2
- x = math.floor((mon.cols + 1) * 6 * mon.scale) + mon.minX + 2
- end
- local i = 1
- while i < #mon.lines do
- if not mon.lines.getY() or y and (mon.lines[i].getY() >= y or mon.lines[i].getX() >= x) then
- mon.lines[i].delete()
- mon.lines[i] = mon.lines[#mon.lines]
- mon.lines[#mon.lines] = nil
- else
- local ny = (mon.lines[i].getY() - mon.minY - 2) / mon.scale * n
- local nx = (mon.lines[i].getX() - mon.minX - 2) / mon.scale * n
- mon.lines[i].setY(ny)
- mon.lines[i].setX(nx)
- mon.lines[i].setScale(n)
- i = i + 1
- end
- end
- for i = 1, mon.rows do
- if not mon.mtrx[i] then
- mon.mtrx[i] = {}
- end
- end
- mon.scale = n
- mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
- mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
- end
- mon.setCursorPos = function(x,y)
- mon.curc = x
- mon.curr = y
- mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
- mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
- end
- mon.getCursorPos = function()
- return mon.curc, mon.curr
- end
- mon.getSize = function()
- return mon.cols, mon.rows
- end
- local blink = true
- local blinkstate = false
- local nextBlink = os.startTimer(0.3)
- mon.setCursorBlink = function(b)
- blink = b
- end
- local function doBlink()
- blinkstate = not blinkstate
- mon.cur.setText(blinkstate and blink and "_" or " ")
- nextBlink = os.startTimer(0.3)
- end
- mon.isColor = function() return true end
- mon.isColour = function() return true end
- local pullEvent = os.pullEvent
- local charQueue = ""
- os.pullEvent = function(...)
- while true do
- if charQueue ~= "" then
- local c = charQueue:sub(1,1)
- charQueue = charQueue:sub(2)
- if c == "\\" then
- c = charQueue:sub(1,1)
- charQueue = charQueue:sub(2)
- if c == "\\" then
- return "char",c
- elseif c == "n" then
- return "key",28
- elseif c == "b" then
- return "key",14
- elseif c == "t" then
- error("Terminated")
- elseif c == "r" then
- os.reboot()
- elseif c == "s" then
- os.shutdown()
- end
- end
- return "char",c
- end
- local t = {pullEvent(...)}
- if t[1] == "chat_command" then
- charQueue = charQueue..t[2]
- local c = charQueue:sub(1,1)
- charQueue = charQueue:sub(2)
- if c == "\\" then
- charQueue = c..charQueue
- else
- return "char",c
- end
- elseif t[1] == "timer" and t[2] == nextBlink then
- doBlink()
- else
- return unpack(t)
- end
- end
- end
- local reboot = os.reboot
- os.reboot = function()
- p.clear()
- mon.box.delete()
- mon.cur.delete()
- reboot()
- end
- local shutdown = os.shutdown
- os.shutdown = function()
- p.clear()
- shutdown()
- end
- term.redirect(mon)
- print("Welcome to CcGlasses!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement