Guest User

Untitled

a guest
Jan 9th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. --Testing Objects--
  2.  
  3. function maxFinder(myTable, kind)
  4.     local maxTable = { }
  5.     if kind == "string" then
  6.         for i=1,#myTable do
  7.             maxTable[i] = #myTable[i]
  8.         end
  9.         table.sort(maxTable)
  10.         return maxTable[#maxTable]
  11.     elseif kind == "number" then
  12.         table.sort(myTable)
  13.         return myTable[#myTable]
  14.     end
  15. end
  16.  
  17. local SubMenu = {
  18.    
  19.     Draw = function(self)
  20.         local xlength = maxFinder(self.stringTable, "string")
  21.         local ylength = #self.stringTable
  22.         term.setBackgroundColor(self.colorTable[1])
  23.         for i=self.xOrigin, self.xOrigin+xlength+1 do
  24.             for b=self.yOrigin, self.yOrigin+ylength+1 do
  25.                 term.setCursorPos(i,b)
  26.                 write(" ")
  27.             end
  28.         end
  29.         term.setBackgroundColor(self.colorTable[2])
  30.         for i=self.xOrigin+1,self.xOrigin+xlength do
  31.             for b=self.yOrigin+1, self.yOrigin+ylength do
  32.                 term.setCursorPos(i,b)
  33.                 write(" ")
  34.             end
  35.         end
  36.         for i=1,#self.stringTable do
  37.             term.setCursorPos(self.xOrigin+1,self.yOrigin+i)
  38.             write(self.stringTable[i])
  39.         end
  40.     end,
  41.  
  42.     Input = function(self,xClick,yClick)
  43.         local xlength = maxFinder(self.stringTable, "string")
  44.         local ylength = #self.stringTable
  45.         local xOrigin = self.xOrigin+1
  46.         local yOrigin = self.yOrigin+1
  47.         local selection = 1
  48.         for i=1,#self.stringTable do
  49.             if xOrigin <= xClick and xClick <= xOrigin+xlength then
  50.                 if yClick == yOrigin+i-1 then
  51.                     return selection
  52.                 end
  53.             end
  54.             selection = selection + 1
  55.         end
  56.         return false
  57.     end
  58.  
  59. }
  60.  
  61. local SubMenu_mt = {
  62.     __index = SubMenu
  63. }
  64.  
  65. function SubMenu.new(xOrigin, yOrigin, stringTable, colorTable)
  66.     local SubMenuObject = {
  67.         xOrigin = xOrigin or 0,
  68.         yOrigin = yOrigin or 0,
  69.         stringTable = stringTable or { },
  70.         colorTable = colorTable or { }
  71.     }
  72.     setmetatable(SubMenuObject, SubMenu_mt)
  73.     return SubMenuObject
  74. end
  75.  
  76. term.clear()
  77.  
  78. local list = {"NPaintPro","FireWolf","Taco"}
  79. local list2 = {"Herp","Derping","Rainbow"}
  80. local standard = {colors.gray,colors.lightBlue}
  81.  
  82. AppSubMenu = SubMenu.new(3,3,list,standard)
  83. HerpMenu = SubMenu.new(15,3,list2,standard)
  84. AppSubMenu:Draw()
  85. HerpMenu:Draw()
  86.  
  87. term.setCursorPos(1,1)
  88. term.setBackgroundColor(colors.black)
  89. term.setTextColor(1)
Advertisement
Add Comment
Please, Sign In to add comment