lennilenn

cAPI

Jun 26th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. function ejectall()
  2. disk.eject("top")
  3. disk.eject("bottom")
  4. disk.eject("right")
  5. disk.eject("left")
  6. disk.eject("front")
  7. disk.eject("back")
  8. end
  9.  
  10. function menu(...)
  11.  arg = {...}
  12.  headline = #arg
  13.  if arg[headline] == nil then arg[headline] = " " end
  14.  print(arg[headline])
  15.  print(" ")
  16.  x = #arg - 1
  17.  y = 2
  18.   print("["..arg[1].."]")
  19.  while true do
  20.   if y > x then
  21.    break
  22.   end
  23.   print(" "..arg[y].." ")
  24.   y = y + 1
  25.  end
  26.  mPos = 1
  27.  while true do
  28.   event, key = os.pullEvent("key")
  29.   if key == 208 then
  30.    if mPos < x then
  31.     mPos = mPos + 1
  32.    else
  33.    mPos = 1
  34.    end
  35.   end
  36.   if key == 200 then
  37.    if mPos > 1 then
  38.     mPos = mPos - 1
  39.    else
  40.     mPos = x
  41.    end
  42.   end
  43.   if key == 28 then
  44.    break
  45.   end
  46.   y = 1
  47.   term.clear()
  48.   term.setCursorPos(1,1)
  49.    print(arg[headline])
  50.    print(" ")
  51.   while true do
  52.    if y > x then
  53.     break
  54.    end
  55.    if mPos == y then
  56.     print("["..arg[y].."]")
  57.    else
  58.     print(" "..arg[y].." ")
  59.    end
  60.    y = y + 1
  61.   end
  62.  end
  63.  term.clear()
  64.  term.setCursorPos(1,1)
  65.  return mPos
  66. end
  67.  
  68. function percent(...)
  69.  local tArgs = {...}
  70.  x,y = term.getSize()
  71.  term.clear()
  72.  term.setCursorPos(1,1)
  73.  x = x / 4
  74.  y = y / 2
  75.  term.setCursorPos(y,x)
  76.  local p = tArgs[1] * 100 / tArgs[2]
  77.  write(p)
  78.  write(" % step "..tArgs[1].." of "..tArgs[2])
  79.  y = y + 1
  80.  x = x + 1
  81.  term.setCursorPos(y,x)
  82.  if p > 10 or p == 10 then pb = 1 end if p > 20 or p == 20 then pb = 2 end if p > 30 or p == 30 then pb = 3 end if p > 40 or p == 40 then pb = 4 end if p > 50 or p == 50 then pb = 5 end if p > 60 or p == 60 then pb = 6 end if p > 70 or p == 70 then pb = 7 end if p > 80 or p == 80 then pb = 8 end if p > 90 or p == 90 then pb = 9 end if p > 100 or p == 100 then pb = 10 end
  83. if pb == nil then pb = 0 end
  84.  write("[")
  85.  pbx = 1
  86.  while true do
  87.   if pbx > pb then break end
  88.   write("#")
  89.   pbx = pbx + 1
  90.  end
  91.  y = y + 10
  92.  term.setCursorPos(y,x)
  93.  write("]")
  94.  x,y=term.getSize()
  95.  y = y - 1
  96.  term.setCursorPos(1,y)
  97.  if tArgs[3] == nil then
  98.  print("percent monitor is a part of the cAPI by timosmods.yolasite.com")
  99.  end
  100.  term.setCursorPos(1,1)
  101. end
  102.  
  103. function createButton(...)
  104.  local tArgs = {...}
  105.  xPos = tArgs[1]
  106.  yPos = tArgs[2]
  107.  Text = tArgs[3]
  108.  Xcolor = tArgs[4]
  109.  Tcolor = tArgs[5]
  110.  Bcolor = tArgs[6]
  111.  side = tArgs[7]
  112.  if side ~= "intern" then
  113.  m = peripheral.wrap(side)
  114.  else m = term
  115.  end
  116.  m.setBackgroundColor(Bcolor)
  117.  m.setCursorPos(xPos,yPos)
  118.  m.setBackgroundColor(Xcolor)
  119.  m.write("X")
  120.  m.setBackgroundColor(Bcolor)
  121.  m.write(" ")
  122.  m.setBackgroundColor(Tcolor)
  123.  m.write(Text)
  124.  m.setBackgroundColor(Bcolor)
  125. end
  126.  
  127. function runButtonIntern(...)
  128.  local tArgs = {...}
  129.  event,side,xPos,yPos = os.pullEvent("mouse_click")
  130.  b = 1
  131.  x = 1
  132.  while true do
  133.   y = x + 1
  134.   if tArgs[y] == nil then return false end
  135.   if xPos == tArgs[x] then
  136.    if yPos == tArgs[y] then
  137.     return b
  138.    end
  139.   end
  140.   b = b + 1
  141.   x = x + 2
  142.  end
  143. end
  144.  
  145. function runButton(...)
  146.  local tArgs = {...}
  147.  event,button,xPos,yPos = os.pullEvent("monitor_touch")
  148.  b = 1
  149.  x = 1
  150.  while true do
  151.   y = x + 1
  152.   if tArgs[y] == nil then return false end
  153.   if xPos == tArgs[x] then
  154.    if yPos == tArgs[y] then
  155.     return b
  156.    end
  157.   end
  158.   b = b + 1
  159.   x = x + 2
  160.  end
  161. end
  162.  
  163. function eventTimer(...)
  164.  local tArgs = {...}
  165.  if tArgs[1] ~= nil then os.startTimer(tArgs[1]) end
  166.  Tevent,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10 = os.pullEvent(tArgs[2])
  167.  if Tevent[1] == "timer" then Tevent = "timeout" end
  168.  return Tevent,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10
  169. end
Advertisement
Add Comment
Please, Sign In to add comment