Advertisement
Guest User

css

a guest
Nov 26th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1.                                             --Attention!!
  2. relativeY = 1
  3. relativeX = 1
  4. stc = term.setTextColor
  5. sbc = term.setBackgroundColor
  6. scp = function(x,y)
  7.  
  8.   term.setCursorPos(x,y)
  9.   sX,sY = term.getCursorPos()
  10.   relativeX = sX
  11.   relativeY = y
  12.  
  13. end
  14. cl = term.clearLine()
  15. clear = term.clear
  16. clearall = function() sbc(colors.black) stc(colors.white) clear() scp(1,1) end
  17. box = paintutils.drawFilledBox
  18. border = paintutils.drawBox
  19. line = paintutils.drawLine
  20. width, height = term.getSize()
  21.  
  22. --]] GUI Simplicity Stuff
  23. function fadeout(time)
  24.   cols = {"lightGray","gray","black"}
  25.   time = time / #cols
  26.   for i = 1, #cols do
  27.     sbc(colors[cols[i]])
  28.     clear()
  29.     sleep(time)
  30.   end
  31. end
  32.  
  33. function fadein(time)
  34.   cols = {"gray","lightGray","white"}
  35.   time = time / #cols
  36.   for i = 1, #cols do
  37.     sbc(colors[cols[i]])
  38.     clear()
  39.     sleep(time)
  40.   end
  41. end
  42.  
  43. function cprint(text, y)
  44.     scp( (width / 2) - #text / 2, y)
  45.     print(text)
  46. end
  47.  
  48. function rprint(text,y)
  49.     scp(relativeX, y)
  50.     print(text)
  51. end
  52.  
  53. function rlprint(text)
  54.   scp(relativeX, relativeY)
  55.   print(text)
  56. end
  57.  
  58. function rcprint(text)
  59. -- why not working?
  60.   scp( (width/2) - #text/2, relativeY+1)
  61.   print(text)
  62. end
  63. --]] Click menu
  64.  
  65. function createMenu(x,y,activecolor,atcolor,adur,bcolor,tcolor,options)
  66.     local menu = {
  67.       opt = options,
  68.       mx = x,
  69.       my = y,
  70.       acolor = activecolor,
  71.       atcol = atcolor,
  72.       aduration = adur,
  73.       bcol = bcolor,
  74.       tcol = tcolor,
  75.       selid = 1,
  76.      
  77.       setBackColor = function(self,color)
  78.         self.bcol = color
  79.       end,
  80.      
  81.       setTextColor = function(self,color)
  82.         self.tcol = color
  83.       end,
  84.      
  85.       setActiveBackColor = function(self,color)
  86.         self.acolor = color
  87.       end,
  88.      
  89.       setActiveTextColor = function(self,color)
  90.         selt.atcol = color
  91.       end,
  92.      
  93.       SwapColors = function(self)
  94.         local ac = self.acolor
  95.         local at = self.atcol
  96.        
  97.         self.acolor = self.bcol
  98.         self.atcol = self.tcol
  99.        
  100.         self.bcol = ac
  101.         self.tcol = at
  102.        
  103.       end,
  104.      
  105.      
  106.            
  107.       draw = function(self)
  108.           for i=1, #self.opt do
  109.               scp(self.mx, self.my + (i-1) )
  110.               stc(self.tcol)
  111.               sbc(self.bcol)
  112.               print(self.opt[i])
  113.           end
  114.       end,
  115.      
  116.       flash = function(self,id)
  117.         scp( self.mx, self.my+(id-1) )
  118.         stc(self.atcol)
  119.         sbc(self.acolor)
  120.         print(self.opt[id])
  121.         sleep(self.aduration)
  122.         sbc(self.bcol)
  123.         stc(self.tcol)
  124.         rlprint(self.opt[id])
  125.       end,
  126.      
  127.       update = function(self,ev)
  128.           if(ev[1] == "mouse_click")then
  129.             mcx = ev[3]
  130.             mcy = ev[4]
  131.             --print(mcx .." | " .. self.mx)
  132.             --print(mcy .. " | " .. self.my)
  133.             for i=1, #self.opt do
  134.               if(mcx >= self.mx and mcx <= self.mx + #self.opt[i]
  135.                  and mcy == self.my + (i-1) )then
  136.                
  137.                  self:flash(i)
  138.                  
  139.                  return self.opt[i]
  140.                  
  141.               end
  142.             end
  143.           end
  144.       end,
  145.    
  146.     }
  147.    
  148.     return menu
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement