Advertisement
shadowkat1010

SKS-API Dev

Jul 11th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. maxx, maxy = term.getSize()
  2. function setTitle(title,reverse)
  3.  if reverse then
  4.   term.setBackgroundColour(colours.white)
  5.   term.setTextColour(colours.black)
  6.   term.clearLine()
  7.   term.setCursorPos(1,1)
  8.   print(title)
  9.   term.setBackgroundColour(colours.black)
  10.   term.setTextColour(colours.white)
  11.  elseif not reverse then
  12.   term.setBackgroundColour(colours.black)
  13.   term.setTextColour(colours.white)
  14.   term.clearLine()
  15.   term.setCursorPos(1,1)
  16.   print(title)
  17.   term.setBackgroundColour(colours.white)
  18.   term.setTextColour(colours.black)
  19.  end
  20. end
  21.  
  22. function reverseBW(bool)
  23.  if bool then
  24.   term.setTextColour(colours.white)
  25.   term.setBackgroundColour(colours.black)
  26.  elseif bool == false then
  27.   term.setTextColour(colours.black)
  28.   term.setBackgroundColour(colours.white)
  29.  end
  30. end
  31.  
  32. function createMenu(title,mainTab,modifiers) -- Title is the title and contents is a table containing names of options
  33.  function sortTab(largeTab)
  34.   local lts = #largeTab
  35.   local pages = {}
  36.   if lts > maxx-1 then
  37.    table.insert(pages, largeTab)
  38.    return pages, false
  39.   else
  40.    repeat
  41.     local sTab = {}
  42.     local n = 1
  43.     local oldn = 0
  44.     repeat
  45.      table.insert(sTab, largeTab[n])
  46.      n = n + 1
  47.     until n == maxx-2+oldn or largeTab[n] == nil
  48.     table.insert(pages,sTab)
  49.     oldn = oldn + n
  50.    until largeTab[n] == nil
  51.    return pages, true
  52.   end
  53.  end
  54.  function drawMenu()
  55.   term.clear()
  56.   local num = 1
  57.   repeat
  58.    term.setCursorPos(1,1)
  59.    reverseBW(false)
  60.    term.clearLine()
  61.    print(title)
  62.    reverseBW(true)
  63.    term.setCursorPos(1,num+2)
  64.    if num == selected then
  65.     reverseBW(false)
  66.     term.clearLine()
  67.     print(contents[page][num])
  68.     reverseBW(true)
  69.    else
  70.     print(contents[page][num])
  71.    end
  72.    num = num + 1
  73.   until contents[page][num] == nil
  74.  end
  75.  contents = sortTab(mainTab)
  76.  selected = 1
  77.  page = 1
  78.  drawMenu()
  79.  repeat
  80.   event, param1 = os.pullEvent()
  81.   if keys.getName(param1) == "up" then
  82.    selected = selected - 1
  83.   elseif keys.getName(param1) == "down" then
  84.    selected = selected + 1
  85.   elseif keys.getName(param1) == "left" then
  86.    page = page - 1
  87.   elseif keys.getName(param1) == "right" then
  88.    page = page + 1
  89.   end
  90.   if selected > #contents[page] then
  91.    selected = 1
  92.   elseif selected < 1 then
  93.    selected = #contents[page]
  94.   elseif page > #contents then
  95.    page = 1
  96.   elseif selected < 1 then
  97.    page = #contents
  98.   end
  99.   local n2 = 1
  100.   repeat
  101.    if modifiers[n2] == keys.getName(param1) then press = true end
  102.    n2 = n2 + 1
  103.   until modifiers[n2] == nil
  104.   drawMenu()
  105.  until press == true
  106.  return contents[selected], param1
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement