Advertisement
Redxone

[Armada] GUI

Jul 29th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. os.loadAPI("gpx")
  2. w,h = term.getSize()
  3. sel = 2
  4. gpx.sbc(colors.white)
  5. gpx.clr()
  6. gpx.stc(colors.black)
  7. clk = os.startTimer(0.1)
  8. clks = textutils.formatTime(os.time(),false)
  9. gpx.fadeScreen("in",0.03)
  10. local gameMenu = {
  11.  
  12.     {name="Worm",path="rom/programs/fun/worm",desc="worm.ginfo",top="worm_top.gim",ico="worm_ico.gim"};
  13.       {name="Adventure",path="rom/programs/fun/adventure",desc="adventure.ginfo",top="adventure_top.gim",ico="adventure_ico.gim"};
  14. }
  15.  
  16.  
  17. function disp()
  18. term.current().setVisible(false)
  19. term.setBackgroundColor(colors.white)
  20. gpx.clr()
  21. gpx.stc(colors.black)
  22.      
  23.      -- draw top
  24.      function drawBar()
  25.      gpx.drawImage(gameMenu[sel].top,14,3)
  26.      gpx.scp(1,1)
  27.      gpx.sbc(colors.gray)
  28.      term.clearLine()
  29.      gpx.scp(1,1)
  30.      gpx.stc(colors.white)
  31.      write("Game - "..gameMenu[sel].name)
  32.      gpx.scp(w-#clks,1)
  33.      write(clks)
  34.      end
  35.      drawBar()
  36.        
  37.      for i = 1, #gameMenu do
  38.      
  39.      if(sel == i)then
  40.      -- draw bottom
  41.        gpx.scp((w/2) - #gameMenu[i].name/2, h-(h/2)+3)
  42.        gpx.sbc(colors.gray)
  43.        gpx.stc(colors.white)
  44.        write(gameMenu[i].name)
  45.        gpx.drawImage(gameMenu[i].ico,(w/2)-3, h - (h/2)+4)
  46.      elseif(i == sel-1)then
  47.        gpx.scp(1 + #gameMenu[i].name/2, h-(h/2)+4)
  48.        gpx.stc(colors.lightGray)
  49.        gpx.sbc(colors.white)
  50.        write(gameMenu[i].name)
  51.      end
  52.      if(i == sel+1)then
  53.        gpx.scp((w) - (#gameMenu[i].name)-2, h-(h/2)+4)
  54.        gpx.sbc(colors.white)
  55.        gpx.stc(colors.lightGray)
  56.        write(gameMenu[i].name)
  57.      end
  58.   end
  59.   term.current().setVisible(true)
  60.  
  61.   a = {os.pullEvent()}
  62.  
  63.  
  64.   if(a[1] == "key")then
  65.  
  66.   if(a[2] == keys.left and sel > 1)then sel = sel - 1 end
  67.   if(a[2] == keys.right and sel < #gameMenu)then sel = sel + 1 end
  68.   if(a[2] == keys.enter)then
  69.   function gdesc()
  70.     gpx.sbc(colors.white)
  71.     gpx.clr()
  72.     drawBar()
  73.     gpx.scp(4,3)
  74.     gpx.stc(colors.black)
  75.     -- get teh info frum the json clone
  76.     f = fs.open(gameMenu[sel].desc,"r")
  77.     jsun = textutils.unserialize(f.readAll())
  78.     f.close()
  79.     gpx.sbc(colors.white)
  80.     gpx.clr()
  81.  
  82.     write(jsun.name)
  83.     gpx.scp(gpx.w-(#jsun.author),3)
  84.     write(jsun.author)
  85.     gpx.scp(3,6)
  86.     gpx.stc(colors.lightGray)
  87.     jsun.desc = jsun.desc:gsub("\n","   ")
  88.     write(jsun.desc)
  89.     gpx.scp(1,19)
  90.     gpx.stc(colors.black)
  91.     write("< - [Back] ")
  92.     gpx.scp(gpx.w-10,19)
  93.     write("[Play] - >")
  94.    
  95.     ev = {os.pullEvent()}
  96.    
  97.    if(ev[1] == "key")then
  98.     if(ev[2] == keys.left)then
  99.        clk = os.startTimer(0.01)
  100.     elseif(ev[2] == keys.right)then
  101.         gpx.fadeScreen("out",0.03)
  102.         os.run({},gameMenu[sel].path)
  103.         gpx.stc(colors.white)
  104.         gpx.sbc(colors.black)
  105.         gpx.clr()
  106.         gpx.centerText("Press any key.")
  107.         os.pullEvent("key")
  108.         gpx.fadeScreen("in",0.03)
  109.         clk = os.startTimer(0.01)
  110.         disp()
  111.      else
  112.        gdesc()
  113.     end
  114.     elseif(ev[1] == "timer")then
  115.       clk = os.startTimer(0.01)
  116.       gdesc()
  117.     end
  118.     end
  119.  
  120.     gdesc()
  121.   end
  122.   end
  123.  
  124.   if(a[1] == "timer")then
  125.     clks = textutils.formatTime(os.time(),false)
  126.     gpx.sbc(colors.gray)
  127.     gpx.scp(w-#clks,1)
  128.     gpx.stc(colors.white)
  129.     clk = os.startTimer(0.01)
  130.   end
  131.  
  132. end
  133. clk = os.startTimer(0.01)
  134.     while true do
  135.     disp()
  136.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement