Advertisement
DerMarten

sw

Nov 15th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local p = peripheral.wrap("right")
  2. p.clear()
  3. local mon = {}
  4.  
  5. mon.minY = 8 * 9
  6. mon.maxY = 24 * 9 + 4
  7. mon.minX = 0 * 6
  8. mon.maxX = 68 * 6 + 4
  9. mon.rows = math.floor((mon.maxY - mon.minY) / 9)
  10. mon.cols = math.floor((mon.maxX - mon.minX) / 6)
  11. mon.lines = {}
  12. mon.mtrx = {}
  13. for i = 1, mon.rows do
  14.  mon.mtrx[i] = {}
  15. end
  16. mon.scale = 1
  17. mon.curr = 1
  18. mon.curc = 1
  19. 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)
  20. 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}
  21.  
  22. mon.bgColor = 0
  23. mon.color = 0xffffff
  24. mon.box = p.addBox(mon.minX, mon.minY, mon.maxX - mon.minX + 1, mon.maxY - mon.minY + 1, mon.bgColor, 0)
  25. mon.box.setZIndex(-1)
  26.  
  27. mon.write = function(s)
  28.  for i = 1, #s do
  29.   local x = math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2
  30.   local y = math.floor((mon.curr - 1) * 9 * mon.scale) + mon.minY + 2
  31.   local j = 1
  32.   local t = mon.mtrx[mon.curr][mon.curc]
  33.   if t then
  34.    t.delete()
  35.   end
  36.   t = p.addText(x, y, s:sub(i,i), mon.color)
  37.   mon.mtrx[mon.curr][mon.curc] = t
  38.   mon.lines[#mon.lines + 1] = t
  39.   mon.curc = mon.curc + 1
  40.   if mon.curc > mon.cols then
  41.    mon.curc = 1
  42.    if mon.curr == mon.rows then
  43.     return
  44.    else
  45.     mon.curr = mon.curr + 1
  46.    end
  47.   end
  48.  end
  49.  mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
  50.  mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
  51. end
  52.  
  53. mon.clear = function()
  54.  for i = 1, #mon.lines do
  55.   mon.lines[i].delete()
  56.   mon.lines[i] = nil
  57.  end
  58. end
  59.  
  60. mon.clearLine = function(n)
  61.  local y = math.floor(((n or mon.curr) - 1) * 9 * mon.scale) + mon.minY + 2
  62.  local i = 1
  63.  while i <= #mon.lines do
  64.   if not mon.lines[i].getY() or mon.lines[i].getY() == y then
  65.    mon.lines[i].delete()
  66.    mon.lines[i] = mon.lines[#mon.lines]
  67.    mon.lines[#mon.lines] = nil
  68.   else
  69.    i = i + 1
  70.   end
  71.  end
  72. end
  73.  
  74. mon.scroll = function()
  75.  mon.clearLine(1)
  76.  local i = 1
  77.  while i <= #mon.lines do
  78.   if not mon.lines[i].getY() then
  79.    mon.lines[i].delete()
  80.    mon.lines[i] = mon.lines[#mon.lines]
  81.    mon.lines[#mon.lines] = nil
  82.   else
  83.    mon.lines[i].setY(mon.lines[i].getY() - (9 * mon.scale))
  84.    i = i + 1
  85.   end
  86.  end
  87.  for i = 1, mon.rows - 1 do
  88.   mon.mtrx[i] = mon.mtrx[i + 1]
  89.  end
  90.  mon.mtrx[mon.rows] = {}
  91. end
  92.  
  93. mon.setBackgroundColor = function(n)
  94.  if mon.colors[n] then
  95.   n = mon.colors[n]
  96.  end
  97.  mon.bgColor = n
  98.  mon.box.setColor(n)
  99.  mon.box.setOpacity(n == 0 and 0 or 0.40)
  100. end
  101.  
  102. mon.setBackgroundColour = mon.setBackgroundColor
  103.  
  104. mon.setTextColor = function(n)
  105.  if mon.colors[n] then
  106.   n = mon.colors[n]
  107.  end
  108.  mon.color = n
  109.  mon.cur.setColor(n)
  110. end
  111.  
  112. mon.setTextColour = mon.setTextColor
  113.  
  114. mon.setTextScale = function(n)
  115.  mon.rows = math.floor((mon.maxY - mon.minY - 4)/(9 * n))
  116.  mon.cols = math.floor((mon.maxX - mon.minX - 4)/(6 * n))
  117.  local y = nil
  118.  local x = nil
  119.  if n > mon.scale then
  120.   y = math.floor((mon.rows + 1) * 9 * mon.scale) + mon.minY + 2
  121.   x = math.floor((mon.cols + 1) * 6 * mon.scale) + mon.minX + 2
  122.  end
  123.  local i = 1
  124.  while i < #mon.lines do
  125.   if not mon.lines.getY() or y and (mon.lines[i].getY() >= y or mon.lines[i].getX() >= x) then
  126.    mon.lines[i].delete()
  127.    mon.lines[i] = mon.lines[#mon.lines]
  128.    mon.lines[#mon.lines] = nil
  129.   else
  130.    local ny = (mon.lines[i].getY() - mon.minY - 2) / mon.scale * n
  131.    local nx = (mon.lines[i].getX() - mon.minX - 2) / mon.scale * n
  132.    mon.lines[i].setY(ny)
  133.    mon.lines[i].setX(nx)
  134.    mon.lines[i].setScale(n)
  135.    i = i + 1
  136.   end
  137.  end
  138.  for i = 1, mon.rows do
  139.   if not mon.mtrx[i] then
  140.    mon.mtrx[i] = {}
  141.   end
  142.  end
  143.  mon.scale = n
  144.  mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
  145.  mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
  146. end
  147.  
  148. mon.setCursorPos = function(x,y)
  149.  mon.curc = x
  150.  mon.curr = y
  151.  mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
  152.  mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
  153. end
  154.  
  155. mon.getCursorPos = function()
  156.  return mon.curc, mon.curr
  157. end
  158.  
  159. mon.getSize = function()
  160.  return mon.cols, mon.rows
  161. end
  162.  
  163. local blink = true
  164. local blinkstate = false
  165. local nextBlink = os.startTimer(0.3)
  166. mon.setCursorBlink = function(b)
  167.  blink = b
  168. end
  169.  
  170. local function doBlink()
  171.  blinkstate = not blinkstate
  172.  mon.cur.setText(blinkstate and blink and "_" or " ")
  173.  nextBlink = os.startTimer(0.3)
  174. end
  175.  
  176. mon.isColor = function() return true end
  177. mon.isColour = function() return true end
  178.  
  179. local pullEvent = os.pullEvent
  180. local charQueue = ""
  181. os.pullEvent = function(...)
  182.  while true do
  183.   if charQueue ~= "" then
  184.    local c = charQueue:sub(1,1)
  185.    charQueue = charQueue:sub(2)
  186.    if c == "\\" then
  187.     c = charQueue:sub(1,1)
  188.     charQueue = charQueue:sub(2)
  189.     if c == "\\" then
  190.      return "char",c
  191.     elseif c == "n" then
  192.      return "key",28
  193.     elseif c == "b" then
  194.      return "key",14
  195.     elseif c == "t" then
  196.      error("Terminated")
  197.     elseif c == "r" then
  198.      os.reboot()
  199.     elseif c == "s" then
  200.      os.shutdown()
  201.     end
  202.    end
  203.    return "char",c
  204.   end
  205.   local t = {pullEvent(...)}
  206.   if t[1] == "chat_command" then
  207.    charQueue = charQueue..t[2]
  208.    local c = charQueue:sub(1,1)
  209.    charQueue = charQueue:sub(2)
  210.    if c == "\\" then
  211.     charQueue = c..charQueue
  212.    else
  213.     return "char",c
  214.    end
  215.   elseif t[1] == "timer" and t[2] == nextBlink then
  216.    doBlink()
  217.   else
  218.    return unpack(t)
  219.   end
  220.  end
  221. end
  222.  
  223. local reboot = os.reboot
  224. os.reboot = function()
  225.  p.clear()
  226.  mon.box.delete()
  227.  mon.cur.delete()
  228.  reboot()
  229. end
  230.  
  231. local shutdown = os.shutdown
  232. os.shutdown = function()
  233.  p.clear()
  234.  shutdown()
  235. end
  236.  
  237. term.redirect(mon)
  238.  
  239. print("Welcome to CcGlasses!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement