Advertisement
Redxone

[GameFusion] - brew Menu

Aug 2nd, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. -- (C) Copyright - Redxone and GameFusion Staff --
  2. local w, h = term.getSize()
  3.  games = {}
  4. local inProgram = true
  5. local mIndex = 1
  6. local sel = 1
  7. local inc = 2
  8. local page = 1
  9. local inProgram = true
  10. local maxSel = 0
  11. function drawMain()
  12.       term.setBackgroundColor(colors.lightBlue)
  13.       term.clear()
  14.      local bg = paintutils.loadImage(shell.resolve(".background"))
  15.      paintutils.drawImage(bg,2,1)      
  16. end
  17.  
  18.  
  19. function initItems()
  20.   --local rootdir = "Rogue/Hackbrew/Apps"
  21.   local rootdir = "rom/programs/"
  22.    for k, v in pairs(fs.list(rootdir))do
  23.        if(not fs.isDir(rootdir..v))then
  24.         table.insert(games,v)
  25.        end
  26.    end
  27.    
  28. end
  29.  
  30. function checkPage(ind)
  31.   local ok = false
  32.   ind = (ind*inc)-1
  33.   for i = ind, #games do
  34.       if(games[i] ~= "")then ok = true end  
  35.   end
  36.   return ok
  37. end
  38.  
  39. function makeMenu(ind)
  40.   drawMain()
  41.  local ri = 1
  42.  maxSel = 0
  43.  ind = (ind*inc)-1
  44.     for i = ind, #games do
  45.     if(ri <= inc)then
  46.         if( ri == sel )then
  47.             drawOption(games[i],ri,colors.lightBlue)
  48.         else
  49.             drawOption(games[i],ri,colors.gray)
  50.         end
  51.       ri = ri + 1
  52.       maxSel = maxSel + 1
  53.     end
  54.     end
  55. end
  56.  
  57. function drawOption(text,hi,color)
  58. -- math thinking out..
  59. -- menu size be ??? 10?
  60. -- soz divide 10 / 2 = 5 make w / 2 - 5
  61. -- even menu out
  62. -- height will be based on given index
  63. -- multiplyed by height constant
  64. -- now for teh text
  65. local mh = 2
  66. local hs = tonumber(4)+tonumber(mh)
  67. local mw = 15
  68. local sw = (w/2) - mw
  69. local sh = hs*hi
  70. local ew = (w/2) + mw
  71. local eh = sh + mh
  72.     paintutils.drawFilledBox(sw,sh,ew,eh,color)
  73.     if(#text > tonumber(32))then text = text:sub(1,31) end
  74.     term.setCursorPos((w/2)-#text/2,(hs*hi) + 1)
  75.     term.setTextColor(colors.white)
  76.     write(text)
  77. end
  78. drawMain()
  79. initItems()
  80. makeMenu(page)
  81.  
  82. while inProgram do
  83.     a = {os.pullEvent("key")}
  84.     term.current().setVisible(false)
  85.     if(a[2] == keys.up and sel > 1)then sel = sel - 1 end
  86.     if(a[2] == keys.down and sel < maxSel)then sel = sel + 1 end
  87.     if(a[2] == keys.left and page > 1)then sel = 1 page = page - 1 end
  88.     if(a[2] == keys.right and checkPage(page+1))then sel = 1 page = page + 1 end
  89.      makeMenu(page)
  90.     term.current().setVisible(true)
  91. end
  92. term.setCursorPos(1,15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement