Advertisement
Guest User

KekApi

a guest
Jun 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. -- KekApi (1.2)
  2.  
  3.  
  4. function centerText (text)
  5.  local w, h = term.getSize()
  6.  term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5))
  7.  write(text)
  8. end
  9.  
  10. function centerPrint (text)
  11.  local textLen = string.len(text)
  12.  local screenW,_ = term.getSize()
  13.  local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2)))
  14.  local _,termY = term.getCursorPos()
  15.  term.setCursorPos(xCoords,termY)
  16.  print(text)
  17.  return xCoords
  18. end
  19.  
  20. function writeLine ()
  21.  term.write("--------------------------------------------------")
  22. end
  23.  
  24. function slowCenterPrint (text, time)
  25.  local textLen = string.len(text)
  26.  local screenW,_ = term.getSize()
  27.  local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2))) -- Da Ba Dee xD
  28.  local _,termY = term.getCursorPos()
  29.  term.setCursorPos(xCoords,termY)
  30.  textutils.slowWrite(text, time)
  31.  return xCoords
  32. end
  33.  
  34. function drawMenu (tab1, x, y)
  35.  if y == nil or x == nil then
  36.   printError("podaj x i y dla menu!")
  37.  end
  38.  a = 0
  39.  colorOld = term.getBackgroundColor()
  40.  wbr = 1
  41.  while true do
  42.   w,h = term.getSize()
  43.   if #tab1 < 10 then
  44.    for i = 1, #tab1 do
  45.     term.setCursorPos(x,y + i - 1)
  46.     if i == wbr then
  47.      term.setBackgroundColor(colors.gray)
  48.     else
  49.      term.setBackgroundColor(colorOld)
  50.     end
  51.    term.write(tab1[i])
  52.    end
  53.   elseif #tab1 > 10 or #tab1 == 10 then
  54.    for i = 1, 10 do
  55.     if i == wbr then
  56.      term.setBackgroundColor(colors.gray)
  57.     else
  58.      term.setBackgroundColor(colorOld)
  59.     end
  60.     if wbr == 9 or wbr > 9 then
  61.      i = wbr
  62.      i = i - 1
  63.     end
  64.     term.setCursorPos(x,y + i - 1)
  65.     term.clearLine()
  66.     term.write(tab1[i])
  67.    end
  68.   end
  69.   event, key = os.pullEvent("key")
  70.   if key == keys.down and wbr < #tab1 then
  71.    wbr = wbr + 1
  72.   end
  73.   if key == keys.up and wbr > 1 then
  74.    wbr = wbr - 1  
  75.   end
  76.   if key == keys.enter then
  77.    break
  78.   end
  79.  end
  80.  term.setBackgroundColor(colorOld)
  81.  return wbr
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement