Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function class(tInput)
- local tClass = tInput
- local mt = {
- __index = tClass
- }
- tClass.new = function(o)
- local tObj = o or {}
- setmetatable(tObj,mt)
- return tObj
- end
- return tClass
- end
- local screen = class {
- screen = {},
- realX = 30,
- realY = 10,
- posX = 1,
- posY = 1,
- isBlink = false,
- screenTX = colors.white,
- screenBC = colors.black,
- --[[
- scp = function(...) pcall(term.native.setCursorPos,...) end,
- scb = function(...) pcall(term.native.setCursorBlink,...) end,
- stc = function(...) pcall(term.native.setTextColor,...) end,
- sbc = function(...) pcall(term.native.setBackgroundColor,...) end,
- wrt = function(...) pcall(term.native.write,...) end,
- ]]--
- scp = term.native.setCursorPos,
- scb = term.native.setCursorBlink,
- stc = term.native.setTextColor,
- sbc = term.native.setBackgroundColor,
- wrt = term.native.write,
- drawFlag,
- speed = 0.01,
- offX = 0,
- offY = 0,
- triger = function(s)
- s.drawFlag = true
- end,
- clearDrawFlag = function(s)
- s.drawFlag = false
- end,
- getDrawFlag = function(s)
- return s.drawFlag
- end,
- resize = function(s,width,hight) -- probble could be cleaner
- local difX = s.realX - width
- local difY = s.realY - hight
- if difY ~= 0 then
- if difY < 0 then
- for y = s.realY,hight do
- s.screen[y] = {}
- for x = 1,width do
- s.screen[y][x] = {s.screenBC,s.screenTX," "}
- end
- end
- else
- for y = s.realY + difY,s.realY do
- s.screen[y] = nil
- end
- end
- end
- if difX ~= 0 then
- if difX < 0 then
- for y = 1,hight do
- for x = s.realX,width do -- dont know
- if not s.screen[y][x] then
- s.screen[y][x] = {s.screenBC,s.screenTX," "}
- end
- end
- end
- else
- for y = 1,hight do
- for x = s.realX,s.realX + difX do -- keep an eye on this
- s.screen[y][x] = nil
- end
- end
- end
- end
- s.realX = width
- s.realY = hight
- end,
- setPos = function(s,x,y)
- s.offX = x
- s.offY = y
- end,
- newLine = function(s)
- local tab = {}
- for x = 1,s.realX do
- tab[x] = {s.screenBC,s.screenTX," "}
- end
- return tab
- end,
- slowDraw = function(s)
- s.drawFlag = false
- s.scb(false)
- for y = 1,s.realY do
- s.scp(1 + s.offX,y + s.offY)
- for x = 1,s.realX do
- s.sbc(s.screen[y][x][1])
- s.stc(s.screen[y][x][2])
- s.wrt(s.screen[y][x][3])
- end
- end
- if s.isBlink then
- s.scp(s.posX + s.offX,s.posY + s.offY)
- s.scb(s.isBlink)
- else
- s.scb(s.isBlink)
- end
- end,
- draw = function(s) -- faster
- --pcall(function() -- test
- s.drawFlag = false
- s.scb(false)
- for y = 1,s.realY do
- s.scp(1 + s.offX,y + s.offY)
- local lastTC
- local lastBC
- local TX = {}
- for x = 1,s.realX do
- local tempBC = s.screen[y][x][1]
- local tempTC = s.screen[y][x][2]
- if lastTC == tempTC and lastBC == tempBC then
- TX[#TX + 1] = s.screen[y][x][3]
- elseif lastBC then
- s.sbc(lastBC or tempBC)
- s.stc(lastTC or tempTC)
- s.wrt(table.concat(TX,""))
- TX = {}
- lastTC = tempTC
- lastBC = tempBC
- TX[#TX + 1] = s.screen[y][x][3]
- else
- lastTC = tempTC
- lastBC = tempBC
- TX[#TX + 1] = s.screen[y][x][3]
- end
- end
- s.sbc(lastBC)
- s.stc(lastTC)
- s.wrt(table.concat(TX,""))
- end
- if s.isBlink then
- s.scp(s.posX + s.offX,s.posY + s.offY)
- s.scb(s.isBlink)
- else
- s.scb(s.isBlink)
- end
- --end) -- test
- end,
- isOverlap = function(s,inX,inY,w,h)
- if inX and inY and w and h then
- local rX1 = s.offX + (s.realX / 2) + 1
- local rY1 = s.offY + (s.realY / 2) + 1
- local rX2 = inX + (w/2)
- local rY2 = inY + (h/2)
- if math.abs(rX1 - rX2) <= ((s.realX / 2) + (w/2)) and math.abs(rY1 - rY2) <= ((s.realY / 2) + (h/2)) then
- return true
- end
- return false
- else
- return error("not correct values")
- end
- end,
- isColor = function(s)
- return true
- end,
- isColour = function(s)
- return true
- end,
- setTextColor = function(s,color)
- s.screenTX = color
- end,
- setTextColour = function(s,color)
- s.screenTX = color
- end,
- setBackgroundColor = function(s,color)
- s.screenBC = color
- end,
- setBackgroundColour = function(s,color)
- s.screenBC = color
- end,
- getSize = function(s)
- return s.realX,s.realY
- end,
- clearLine = function(s)
- s.screen[s.posY] = s:newLine()
- s:triger()
- end,
- setCursorBlink = function(s,bool)
- s.isBlink = bool
- s:triger()
- end,
- getCursorPos = function(s)
- return s.posX,s.posY
- end,
- clear = function(s)
- s.screen = {}
- for y = 1,s.realY do
- s.screen[y] = {}
- for x = 1,s.realX do
- s.screen[y][x] = {s.screenBC,s.screenTX," "}
- end
- end
- s:triger()
- end,
- scroll = function(s,n)
- for i = 1,n do
- table.remove(s.screen,1)
- table.insert(s.screen,s:newLine())
- end
- s:triger()
- end,
- setCursorPos = function(s,x,y)
- s.posX = math.floor(x)
- s.posY = math.floor(y)
- s:triger()
- end,
- write = function(s,line)
- if line and type(line) == "string" then
- for i = 0,#line - 1 do
- if s.screen[s.posY] and s.screen[s.posY][s.posX + i] then
- s.screen[s.posY][s.posX + i] = {s.screenBC,s.screenTX,string.sub(line,i + 1,i + 1)}
- end
- end
- s.posX = s.posX + #line
- end
- s:triger()
- end,
- getRedirect = function(s)
- local list = {
- "isColor","isColour","setTextColor","setTextColour","setBackgroundColor","setBackgroundColour","getSize",
- "clearLine","setCursorBlink","getCursorPos","clear","scroll","setCursorPos","write",
- }
- local fakeTerm = {}
- local screen = s
- for i = 1,#list do
- fakeTerm[list[i]] = function(...)
- --return select(2,pcall(screen[list[i]],screen,...))
- return screen[list[i]](screen,...)
- end
- end
- return fakeTerm
- end,
- setOutput = function(s,input)
- if type(input) == "table" then
- local req = {"scp","scb","stc","sbc","wrt"}
- local install = true
- for i = 1,#req do
- if not input[req[i]] then
- install = false
- error("missing "..tostring(req[i]))
- end
- end
- if install then
- for i = 1,#req do
- s[req[i]] = input[req[i]]
- end
- end
- end
- end,
- }
- local function findDevice(sType)
- for _,sSide in pairs(peripheral.getNames()) do
- if peripheral.isPresent(sSide) and peripheral.getType(sSide) == sType then
- return sSide,peripheral.wrap(sSide)
- end
- end
- end
- local id,glass = findDevice("terminal_glasses_bridge")
- local fakeX,fakeY = 51,19
- local grid = {}
- local col = {
- 15790320,
- 15435844,
- 12801229,
- 6719955,
- 14605932,
- 4312372,
- 14188952,
- 4408131,
- 10066329,
- 2651799,
- 8073150,
- 2437522,
- 5320730,
- 3887386,
- 11743532,
- 0,
- }
- local change = {}
- for i = 1,16 do
- change[2^(i-1)] = col[i]
- end
- local glasses = screen.new()
- local offsetX,offsetY = 0,0
- if id then
- glass.clear()
- for y = 1,fakeY do
- grid[y] = {}
- for x = 1,fakeX do
- grid[y][x] = {
- back = glass.addBox((x*6) - 6 + offsetX, (y*9) - 9 + offsetY,6,9, 0x000000, 1),
- text = glass.addText((x*6) - 6 + offsetX, (y*9) - 9 + offsetY, "@", 0xCC0000)
- }
- grid[y][x].text.setZIndex(2)
- end
- end
- else
- error("can't find glasses")
- end
- local scp = term.native.setCursorPos
- local scb = term.native.setCursorBlink
- local stc = term.native.setTextColor
- local sbc = term.native.setBackgroundColor
- local wrt = term.native.write
- local curX,curY = 1,1
- local textCol = 0
- local backCol = 0
- local newMon = {
- scp = function(x,y)
- if x and y then
- curX,curY = x,y
- scp(x,y)
- end
- end,
- scb = function(input)
- -- unneeded for now
- scb(input)
- end,
- stc = function(col)
- if change[col] then
- textCol = change[col]
- stc(col)
- else
- error("not color "..tostring(col))
- end
- end,
- sbc = function(col)
- if change[col] then
- backCol = change[col]
- sbc(col)
- else
- error("not color "..tostring(col))
- end
- end,
- wrt = function(text)
- for i = 1,#text do
- if grid[curY] and grid[curY][curX + i - 1] then
- grid[curY][curX + i - 1].text.setColor(textCol)
- grid[curY][curX + i - 1].text.setText(text:sub(i,i))
- grid[curY][curX + i - 1].back.setColor(backCol)
- end
- end
- curX = curX + #text
- wrt(text)
- end
- }
- sleep(0.01)
- glasses:clear()
- glasses:resize(51,19)
- glasses:setOutput(newMon)
- sleep(0.01)
- term.redirect(glasses:getRedirect())
- sleep(0.01)
- local oldRaw = os.pullEventRaw
- os.pullEventRaw = function()
- if glasses:getDrawFlag() then
- glasses:draw()
- end
- return oldRaw()
- end
- --[[
- glasses:clear()
- glasses:resize(51,19)
- term.redirect(glasses:getRedirect())
- ]]--
- --[[
- glasses:clear()
- glasses:resize(51,19)
- glasses:setOutput(newMon)
- glasses:setCursorPos(1,1)
- glasses:write("&")
- glasses:setCursorPos(4,4)
- glasses:setBackgroundColor(colors.red)
- glasses:setTextColor(colors.blue)
- glasses:write("+")
- glasses:draw()
- --{"scp","scb","stc","sbc","wrt"}
- ]]--
- --[==[
- for i = 1,#colors do
- grid[1][i].back.setColor(colors[i])
- grid[1][i].back.setAlpha(1)
- end
- --[[
- for y = 1,termY do
- for x = 1,termX do
- print("BACK : ",grid[y][x].back.getZIndex()," TEXT : ",grid[y][x].text.getZIndex())
- sleep(0.5)
- end
- end
- ]]--
- print(#colors)
- os.pullEvent()
- ]==]--
- --[[
- for i = 1,0xff do
- grid[8][25].back.setColor(i)
- sleep(0.1)
- end
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement