Guest User

CCVGUIAPI

a guest
Mar 7th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. function register(name, s, t)
  2.   local out = t
  3.   out[name]={}
  4.   if type(t["names"])~="table" then
  5.     t["names"]={}
  6.   end
  7.   if type(t.side) ~= string then
  8.     t.side = s
  9.   end
  10.   table.insert(t["names"], name)
  11.   return out
  12. end
  13. function center(min_,max_, text)
  14.   local div_int = (max_ - min_)/2
  15.   local mod_int = div_int%2
  16.   local out_temp = div_int+mod_int
  17.   local len_int = string.len(text)
  18.   if len_int > (max_-min_) then
  19.     local out = out_temp-(len_int/2)
  20.     return out
  21.   elseif string.len(text)<1 then
  22.     return out_temp
  23.   else
  24.     return -1
  25.   end
  26. end
  27. peripheral.find = function(returns)
  28.   local _sSides = {
  29.     "front","back",
  30.     "right","left",
  31.     "top", "bottom"
  32.   }
  33.   local _pT = {}
  34.   local _pT.out = {}
  35.   local enable = 1
  36.   local remaining = returns
  37.   for i=1, #_sSides*enable do
  38.     if peripheral.isPresent( _sSides[i] ) then
  39.       local tMethods = peripheral.getMethods( _sSides[i] )
  40.       local tResult = {}
  41.  for n,sMethod in ipairs( tMethods ) do
  42.         tResult[sMethod] = function( ... )
  43.           return peripheral.call( _sSides[i], sMethod, ... )
  44.         end
  45.       end
  46.       if remaining >= 1 then
  47.         _pT.out[sSide[i]].return_s = tResult
  48. local temp = remaining
  49. remaining = temp - 1
  50.       end
  51.       if remaining == 0 then
  52.         enabled = 0
  53.         return _pT
  54.       end
  55.     end
  56.   return nil
  57. end
  58. function table:create(side, name, ...)
  59.   --takes arguments in order:
  60.   --    side, name, xMin, yMin, xMax, yMax,...
  61.   --... text, bC(background color), tC(text color)
  62.   local vguiOut = register(name, side, vguiIn)
  63.   local vguiOut = nil
  64.   if type(...) == "table" then
  65.     vguiOut = ...
  66.   elseif type(...) ~= "table" then
  67.     vguiOut = {...}
  68.   end
  69.   vguiOut[name]["xMin"]=vguiIn[1]
  70.   local xMin = vguiIn[1]
  71.   vguiOut[name]["yMin"]=vguiIn[2]
  72.   local yMin = vguiIn[2]
  73.   vguiOut[name]["xMax"]=vguiIn[3]
  74.   local xMax = vguiIn[3]
  75.   vguiOut[name]["yMax"]=vguiIn[4]
  76.   local yMax = vguiIn[4]
  77.   local text = vguiIn[5]
  78.   local bC = vguiIn[6]
  79.   local tC = vguiIn[7]
  80.   local center = {}
  81.   center.x = center(xMin, xMax, text)
  82.   center.y = center(yMin, yMax, text)
  83.   local drawText = 0
  84.   if not centerX == -1 and not centerY == -1 then
  85.   drawText = 1
  86.   end
  87.   for x = xMin, xMax do
  88.     for y = yMin, yMax do
  89.       self.out[side].setCursorPos(x,y)
  90.       self.out[side].setBackgroundColor(bC)
  91.       self.out[side].setTextColor(tC)
  92.       if drawText then
  93.         if x==centerX and y == centerY then
  94.           self.out[side].write(text)
  95.         elseif x>xMin+string.len(text) then
  96.           self.out[side].write(" ")
  97.         end
  98.       else
  99.         self.out[side].write(" ")
  100.       end
  101.     end
  102.   end
  103.   return vguiOut
  104. end
  105. function checkClk(tbl_)
  106.   local e, b, x, y = os.pullEvent(moniter_touch)
  107.   for i, v in pairs(tbl_) do
  108.     if x >= v["xMin"] and x <= v["xMax"] then
  109.       if y >= v["yMin"] and y < = v["yMax"] then
  110.         return t["names"][i]
  111.       else
  112.         return t["names"][i]
  113.       end
  114.     end
  115.   end
  116. end
  117. function table:fill(name,tbl_,bC)
  118.   tbl_[6]=bC
  119.   local _sCall = tbl_.side
  120.   self.out[_sCall]:create(name, tbl_)
  121. end
Add Comment
Please, Sign In to add comment