Advertisement
theinsekt

arcade

Sep 16th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. --not tested, experimental
  2. --pastebin get XVV4t1dF startup
  3. --will display a clickable list of games
  4.  
  5. os.loadAPI("txUI")
  6.  
  7. --function to set to enable or disable ctrl-t
  8. --http://www.computercraft.info/forums2/index.php?/topic/2732-disable-ctrlt/
  9. local pullEventCopy = os.pullEvent
  10. function setCtrlT(value)
  11.  if value then
  12.   os.pullEvent = pullEventCopy
  13.  else
  14.   os.pullEvent = os.pullEventRaw
  15.  end
  16. end
  17.  
  18.  
  19. function clear()
  20.  term.setCursorPos(1,1)
  21.  term.setBackgroundColor(colors.white)
  22.  term.setBackgroundColor(colors.black)
  23.  term.clear()
  24. end
  25.  
  26. function about()
  27.  clear()
  28.  textutils.slowWrite("At the beginning of time Connor commissioned")
  29.  print()
  30.  textutils.slowWrite("theinsekt to make an arcade program.")
  31.  print()
  32.  sleep(1)
  33.  textutils.slowWrite("After trying to make his own button api he soon gave up (lazy),")
  34.  print()
  35.  textutils.slowWrite("and instead used txUI (by tuogex).")
  36.  print()
  37.  sleep(1)
  38.  textutils.slowWrite("He managed to make version 0.1 dev.")
  39.  print()
  40.  sleep(1)
  41.  textutils.slowWrite("It was not great but it works as a proof of concept.")
  42.  print()
  43.  sleep(1)
  44.  textutils.slowWrite("The End!")
  45.  print()
  46.  sleep(3)
  47. end
  48.  
  49. function history2()
  50.  clear()
  51.  textutils.slowWrite("On the second day theinsekt fixed the flickering problem.")
  52.  print()
  53.  sleep(1)
  54.  textutils.slowWrite("Like the genius he is he redirected the output to a non-visible window,")
  55.  print()
  56.  sleep(1)
  57.  textutils.slowWrite("and after all the drawing was done he turned it visible and used window.redraw().")
  58.  print()
  59.  sleep(1)
  60.  textutils.slowWrite("He truly is a worthy bearer of 'the red belt of destiny'.")
  61.  print()
  62.  sleep(1)
  63.  textutils.slowWrite("Now he only need to add some games.")
  64.  print()
  65.  sleep(1)
  66.  textutils.slowWrite("What man, what a man...")
  67.  print()
  68.  sleep(1)
  69.  textutils.slowWrite("The End!")
  70.  print()
  71.  sleep(3)
  72.  print("lol")
  73.  print()
  74.  sleep(1)
  75. end
  76.  
  77. function getGames(debugLabel)
  78.   local games={
  79.   --{"debug close",function(self) error("Exited") end},
  80.   --add a function to the games list
  81.   {"History of arcade 0.1 dev",about},
  82.   {"History of arcade 0.2 dev (fair and balanced)",history2},
  83.   {"gamename1",function(self) debugLabel.text="gameName1" end},
  84.   {"gamename2",function(self) debugLabel.text="gameName2" end},
  85.   --add a program to the games list
  86.   {"Hello World! - theinsekt",function(self) shell.run("helloworld") end},
  87.   {"errorTest",function(self) error("errorTest") end},
  88.  }
  89.  return games
  90. end
  91.  
  92.  
  93. function arcade()
  94.  --[[
  95. http://www.computercraft.info/forums2/index.php?/topic/19575-txui-elegant-gui-components-with-application-framework-capabilities/
  96. ]]
  97.  
  98.  
  99.  local bg=colors.black
  100.  local bg2=colors.black
  101.  local te=colors.red
  102.  
  103.  local w, h = term.getSize()
  104.  local windowA = txUI.Window:new({w = w; h = h; bgColor = bg; textColor = te;})
  105.  txUI.UIManager:addWindow(windowA)
  106.  txUI.UIManager:setVisibleWindow(windowA)
  107.  
  108.  
  109.  
  110.  windowA:setTitleLabel(txUI.Label:new({text = "Arcade 0.2 dev (powered by txUI)"; bgColor = bg2; textColor = te; w = windowA.w; x = windowA.x; textAlign = "center";}))
  111.  
  112.  
  113.  --debug label under list
  114.  local debugLabel=txUI.Label:new({text="debugLabel";x = 1; y = h; w = w; h = 1; bgColor = bg2; textColor = te;})
  115.  windowA:addComponent(debugLabel)
  116.  
  117.  local games=getGames(debugLabel)
  118.  
  119.  --add label over list
  120.  --windowA:addComponent(txUI.Label:new({text="Applications:";x = 1; y = 2; bgColor = bg; textColor = te;}))
  121.  
  122.  --make a click-able and scrollable list
  123.  local list = txUI.List:new({x = 1; y = 2;h=h-2;w=w;bgColor = bg; textColor = te;bgColorStripe= bg;textColorStripe=te;scrollBarTextColor=te;})
  124.  windowA:addComponent(list)
  125.  for _, game in ipairs(games) do
  126.   local gameName,startFunction=unpack(game)
  127.   list:addComponent(txUI.Button:new({text = gameName; action = startFunction;bgColor = bg; textColor = te;}))
  128.  end
  129.  
  130.  
  131.  
  132.  
  133.  txUI.UIManager.appUpdate = function(self)
  134.   --do nothing
  135.  end
  136.  
  137.  print("starting UI...")
  138.  sleep(1)
  139.  txUI.UIManager:startUpdateCycle()
  140. end
  141.  
  142.  
  143.  
  144.  
  145. --start the arcade program
  146. --setCtrlT(false)
  147. while(true) do
  148.  local ret, err=pcall(arcade)
  149.  clear()
  150.  if not ret then
  151.   print(err)
  152.  end
  153.  print("Arcade is restarting...")
  154.  sleep(4)
  155. end
  156. --setCtrlT(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement