Guest User

TitanOS v1

a guest
Mar 15th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. --Monitor Setup
  2.  
  3. local mon = peripheral.wrap("right")
  4. mon.setTextScale(1)
  5. mon.setTextColor(colors.white)
  6. local button={}
  7. mon.setBackgroundColor(colors.black)
  8.    
  9. --Variable Definition
  10.  
  11. buttonPush = false
  12. option = 0
  13.  
  14.  
  15. --Functions
  16.  
  17. function home()
  18.     shell.run("TitanOS")
  19. end
  20.      
  21. function setTable(name, func, xmin, xmax, ymin, ymax)
  22.    button[name] = {}
  23.    button[name]["func"] = func
  24.    button[name]["active"] = true
  25.    button[name]["xmin"] = xmin
  26.    button[name]["ymin"] = ymin
  27.    button[name]["xmax"] = xmax
  28.    button[name]["ymax"] = ymax
  29. end
  30.    
  31.  
  32. function fill(text, color, bData)
  33.    mon.setBackgroundColor(color)
  34.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  35.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  36.    for j = bData["ymin"], bData["ymax"] do
  37.       mon.setCursorPos(bData["xmin"], j)
  38.       if j == yspot then
  39.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  40.             if k == xspot then
  41.                mon.write(text)
  42.             else
  43.                mon.write(" ")
  44.             end
  45.          end
  46.       else
  47.          for i = bData["xmin"], bData["xmax"] do
  48.             mon.write(" ")
  49.          end
  50.       end
  51.    end
  52.    mon.setBackgroundColor(colors.black)
  53. end
  54.  
  55.      
  56. function screen()
  57.    local currColor
  58.    for name,data in pairs(button) do
  59.       local on = data["active"]
  60.       if on == true then currColor = colors.lime else currColor = colors.red end
  61.       fill(name, currColor, data)
  62.    end
  63. end
  64.  
  65.      
  66. function checkxy(x, y)
  67.    for name, data in pairs(button) do
  68.       if y>=data["ymin"] and  y <= data["ymax"] then
  69.          if x>=data["xmin"] and x<= data["xmax"] then
  70.             data["func"]()
  71.             data["active"] = not data["active"]
  72.             print(name)
  73.          end
  74.       end
  75.    end
  76. end
  77.  
  78.      
  79. function heading(text,a)
  80.    w, h = mon.getSize()
  81.    mon.setCursorPos((w-string.len(text))/2+1,a)
  82.    mon.write(text)
  83. end
  84.  
  85.  
  86. function dummy()
  87.     buttonPush = not buttonPush
  88. end
  89.  
  90. function menu1()
  91.     if buttonPush == true then
  92.         dummy()
  93.     end
  94.     button = {}
  95.     mon.clear()
  96.     sleep(.25)
  97.     sleep(.25)
  98.     heading("Please follow the On Screen Navigation Below",1)
  99.     while buttonPush == false do
  100.         setTable("Option1", one, 5, 15, 3, 5)
  101.         setTable("Option2", two, 5, 15, 7, 9)
  102.         setTable("Option3", three, 5, 15, 11, 13)
  103.         screen()
  104.         local e, side, x,y = os.pullEvent("monitor_touch")
  105.         print(x..":"..y)
  106.         checkxy(x, y)
  107.         sleep(.1)
  108.     end
  109. end
  110.  
  111. function menu2()
  112.     if buttonPush == true do
  113.         dummy()
  114.     end
  115.     button = {}
  116.     mon.clear()
  117.     sleep(.25)
  118.     while buttonPush == false then
  119.         heading("Button ",1)
  120.         mon.write(option.." was pressed.")
  121.         setTable("Back", menu1, 50, 55, 17, 19)
  122.         setTable("Home", home, 2, 6, 16, 18)
  123.         screen()
  124.         local e, side, x, y = os.pullEvent("monitor_touch")
  125.         print(x..":"..y)
  126.         checkxy(x, y)
  127.         sleep(.1)
  128.     end
  129. end
  130.  
  131. function one()
  132.     dummy()
  133.     option = 1
  134.     menu2()
  135. end
  136.  
  137.  
  138. function two()
  139.     dummy()
  140.     option = 2
  141.     menu2()
  142. end
  143.  
  144. function three()
  145.     dummy()
  146.     option = 3
  147.     menu2()
  148. end
  149.  
  150. --ASCII Variables
  151.  
  152. local Logo = {
  153.   [[           _  __                                      _             ___          ]],
  154.   [[   o O O  | |/ /    ___    _ __      _ _   __ _    __| |    ___    / __|    ___  ]],
  155.   [[  o       | ' <    / _ \  | '  \    | '_| / _' |  / _' |   / -_)  ( |__    / _ \ ]],
  156.  [[ TS__[O]  |_|\_\   \___/  |_|_|_|  _|_|_  \__,_|  \__,_|   \___|   \___|   \___/ ]],
  157.  [[{======|__|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| |"""""|_|"""""|]],
  158.  [[/o--000'""'-0-0-'"'-0-0-'"'-0-0-'"'-0-0-'"'-0-0-'"'-0-0-'"'-0-0-'.'-0-0-'"'-0-0-']],
  159. }
  160.  
  161. --Program
  162. --------------
  163.  
  164. --Opening Screen
  165. while buttonPush == false do
  166.     mon.clear()
  167.     mon.setTextScale(1)
  168.     term.redirect(mon)
  169.     term.clear()
  170.     term.setCursorPos(1,1)
  171.     for i = 1, #Logo do
  172.         print(Logo[i])
  173.     end
  174.     heading("Welcome to Titan Tower!",12)
  175.     heading("A Komrade Co. Enterprise.",13)
  176.     term.restore()
  177.   setTable("Press to Begin", dummy, 30, 50, 15, 17)
  178.   screen()
  179.   local e,side,x,y = os.pullEvent("monitor_touch")
  180.   print(x..":"..y)
  181.   checkxy(x,y)
  182.   sleep(.1)
  183. end
  184.  
  185. menu1()
  186.  
  187. menu2()
Advertisement
Add Comment
Please, Sign In to add comment