Somepotato

Star Wars

Jul 11th, 2012
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.58 KB | None | 0 0
  1. local fontdata={}
  2. local meta={}
  3. function meta:SetFont(newfont)
  4.     if(fontdata[newfont]) then
  5.         self.Font=newfont
  6.         local font=fontdata[newfont]
  7.         self.FontW=font.w
  8.         self.FontH=font.h
  9.         return
  10.     end
  11.     local maxw,maxh=0,0
  12.     surface.SetFont(newfont)
  13.     for i=16,127 do--Todo: UNICODE
  14.         local w,h=surface.GetTextSize(string.char(i))
  15.         if(w>maxw) then
  16.             maxw=w
  17.         end
  18.         if(h>maxh) then
  19.             maxh=h
  20.         end
  21.     end
  22.     local font={w=maxw,h=maxh}
  23.     fontdata[newfont]=font
  24.     self.Font=newfont
  25.     self.FontW=maxw
  26.     self.FontH=maxh
  27. end
  28. function meta:Draw(xpos,ypos)
  29.     local width,height=self.W,self.H
  30.     local cursor=self.Cursor
  31.     if(cursor and math.floor(CurTime()*4)%2==1) then
  32.         surface.SetDrawColor(200,200,200)
  33.         surface.DrawRect(cursor.x*self.FontW+xpos,cursor.y*self.FontH+ypos+(cursor.size*self.FontH),self.FontW,self.FontH*cursor.size)
  34.     end
  35.     surface.SetFont(self.Font)
  36.     local curcol=color_white
  37.     surface.SetTextColor(255,255,255)--TODO: Customizable character colors
  38.     for y=0,height-1 do
  39.         for x=0,width-1 do
  40.             local charcol=self.CharCols[x][y]
  41.             surface.SetTextColor(charcol)
  42.             surface.SetTextPos(xpos+x*self.FontW,y*self.FontH+ypos)
  43.             local char=self.Chars[x][y]
  44.             if(char~="") then
  45.                 surface.DrawText(char)
  46.                 surface.SetTextColor(curcol)
  47.             end
  48.         end
  49.     end
  50.    
  51.    
  52. end
  53. function meta:SetChar(x,y,char, col)
  54.     if(self.Chars[x] and self.Chars[x][y]) then
  55.         self.Chars[x][y]=char
  56.         if(col) then
  57.             self.CharCols[x][y]=col
  58.         end
  59.     end
  60. end
  61. function meta:SetCursorScale(scale)
  62.     if(self.Cursor) then
  63.         self.Cursor.size=scale
  64.     end
  65. end
  66. function meta:SetCursor(x,y)
  67.     self.Cursor={x=x,y=y,size=0.5}
  68. end
  69. --v1: SetSize clears screen!
  70. function meta:Clear()
  71.     local w,h=self.W,self.H
  72.     local chars={}
  73.     local charcols={}
  74.     for x=0,w-1 do
  75.         for y=0,h-1 do
  76.             chars[x]=chars[x] or {}
  77.             chars[x][y]=""
  78.             charcols[x]=charcols[x] or {}
  79.             charcols[x][y]=color_white
  80.            
  81.         end
  82.     end
  83.     self.Chars=chars
  84.     self.CharCols=charcols
  85. end
  86. function meta:SetSize(w,h)
  87.     self.W=w
  88.     self.H=h
  89.     local chars={}
  90.     local charcols={}
  91.     for x=0,w-1 do
  92.         for y=0,h-1 do
  93.             chars[x]=chars[x] or {}
  94.             chars[x][y]=""
  95.             charcols[x]=charcols[x] or {}
  96.             charcols[x][y]=color_white
  97.            
  98.         end
  99.     end
  100.     self.Chars=chars
  101.     self.CharCols=charcols
  102. end
  103. meta.__index=meta
  104. display={}
  105. function display.Create(initialWidth,initialHeight)
  106.     local display=setmetatable({},meta)
  107.     display:SetSize(initialWidth or 67, initialHeight or 13)
  108.     display:SetFont("ConsoleText")
  109.     return display
  110. end
  111. local PANEL={}
  112. function PANEL:Init()
  113.     local display=display.Create()
  114.     self:SetSize(display.W*display.FontW,display.H*display.FontH)
  115. end
  116. local frame=vgui.Create("DFrame")
  117. local display=display.Create()
  118. frame:SetSize(display.W*display.FontW,display.H*display.FontH+22)
  119. local str="Loading..."
  120. for i=1,#str do
  121.     display:SetChar(i-1,0,str[i])
  122. end
  123. local filmText
  124. local loaded=false
  125. local last=CurTime()
  126. local lines={}
  127. local lineidx=0
  128. local finished=false
  129. http.Get("http://dl.dropbox.com/u/4992578/starwars.txt","",function(content)
  130.     filmText=content:gsub("\\n","\n")
  131.     for line in string.gmatch( filmText, "([^\n]*)\n") do
  132.         table.insert(lines,line)
  133.     end
  134.     loaded=true
  135. end)
  136. function frame:PaintOver()
  137.     if(last>CurTime() or finished or not loaded) then
  138.         display:Draw(0,22)
  139.         return
  140.     end
  141.     -- Get this every frame incase the monitor resizes 
  142.     local w,h = display.W,display.H
  143.     local startX = math.floor( (w - 68) / 2 )
  144.     local startY = math.floor( (h - 14) / 2 )
  145.  
  146.     -- Print the frame
  147.     display:Clear()
  148.     local holdLine=lines[lineidx+1]
  149.     lineidx=lineidx+1
  150.     for n=1,13 do
  151.         local line = lines[lineidx+n]
  152.         if line then
  153.             for i=1,#line-1 do
  154.                 display:SetChar(startX+i, startY + n, line[i])
  155.             end
  156.         else
  157.             finished = true
  158.             return
  159.         end
  160.     end
  161.     lineidx=lineidx+13
  162.     -- Hold the frame
  163.     local hold = tonumber(holdLine) or 1
  164.     local delay = (hold * 0.05)-0.01
  165.     last=CurTime()+delay
  166.     display:Draw(0,22)
  167. end
  168. --[=[
  169. local str="Hello world"
  170.  
  171. local chars={" ", "x", "X", " "}
  172. concommand.Add("chars",function(_,_,args) chars=args end)
  173. local lines={"+---------------------------------------+","|Please log in                          |","|User:__________________________________|","|Pass:__________________________________|","+---------------------------------------+"}
  174. local lineNum=0                                                                                     ---------------------------------------
  175. local lineIdx=1
  176. local asciiart=
  177. string.Explode("\n",[[                .88888888:.
  178.                88888888.88888.
  179.              .8888888888888888.
  180.              888888888888888888
  181.              88' _`88'_  `88888
  182.              88 88 88 88  88888
  183.              88_88_::_88_:88888
  184.              88:::,::,:::::8888
  185.              88`:::::::::'`8888
  186.             .88  `::::'    8:88.
  187.            8888            `8:888.
  188.          .8888'             `888888.
  189.         .8888:..  .::.  ...:'8888888:.
  190.        .8888.'     :'     `'::`88:88888
  191.       .8888        '         `.888:8888.
  192.      888:8         .           888:88888
  193.    .888:88        .:           888:88888:
  194.    8888888.       ::           88:888888
  195.    `.::.888.      ::          .88888888
  196.   .::::::.888.    ::         :::`8888'.:.
  197.  ::::::::::.888   '         .::::::::::::
  198.  ::::::::::::.8    '      .:8::::::::::::.
  199. .::::::::::::::.        .:888:::::::::::::
  200. :::::::::::::::88:.__..:88888:::::::::::'
  201.  `'.:::::::::::88888888888.88:::::::::'
  202.        `':::_:' -- '' -'-' `':_::::'` ]])
  203. local map={["8"]=Color(50,50,50),[":"]=Color(255,255,0),[","]=Color(150,150,0),["."]=Color(100,100,100)}
  204. for k,line in pairs(asciiart) do
  205.     for i=1,#line do
  206.         display:SetChar(56+i,k,line[i],map[line[i]])
  207.     end
  208. end
  209. local lastTick=CurTime()
  210. function frame:PaintOver()
  211.     for i=0,45 do
  212.         for amt=16,256,8 do
  213.             local x,y=math.Rad2Deg(math.sin(i*(amt/45)+(CurTime())%45)),math.Rad2Deg(math.cos(i*(amt/45)+(CurTime())%45))
  214.             display:SetChar(math.floor(x/360*amt)+16,math.floor(y/360*amt)+16,chars[(i%#chars+1)],Color(i*4,i*2,255))
  215.             --local x,y=math.Rad2Deg(math.sin(i*(amt/45)+(CurTime())%45)),math.Rad2Deg(math.cos(i*(amt/45)+(CurTime())%45))
  216.         end
  217.         --display:SetChar(math.floor(x/360*32)+16,math.floor(y/360*32)+16,i%2==1 and "B" or "N")
  218.     end
  219.     if(CurTime()>lastTick and lineNum<=#lines) then
  220.         local line=lines[lineNum]
  221.         if not line or #line<lineIdx then
  222.             lineIdx=1
  223.             lineNum=lineNum+1
  224.             line=lines[lineNum]
  225.         end
  226.         if not line then
  227.             lineNum=lineNum+1
  228.             display:SetCursor(48+7,3+39)
  229.             return
  230.         end
  231.         display:SetChar(48+lineIdx,lineNum+39,line[lineIdx])
  232.         display:SetCursor(48+lineIdx,lineNum+39)
  233.         lineIdx=lineIdx+1
  234.         lastTick=CurTime()+0
  235.     end
  236.     display:Draw(0,22)
  237. end]=]
Advertisement
Add Comment
Please, Sign In to add comment