craniumkid22

Processing

Feb 15th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.46 KB | None | 0 0
  1. local shutterState = false
  2. local entranceState = false
  3. local processingState = false
  4. local alarmState = false
  5. local x,y = term.getSize()
  6.  
  7. local statusLights = {
  8.     shutter = {
  9.         light = {"[--------------]"},
  10.         color = shutterState and colors.black or colors.white,
  11.         BGcolor = shutterState and colors.red or colors.lime,
  12.         action = function(self)
  13.                 if shutterState then
  14.                     shutterState = false
  15.                     if colors.test(rs.getBundledOutput("bottom"), colors.brown) then
  16.                         rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") - colors.brown)
  17.                         rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.green)
  18.                     else
  19.                         rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.green)
  20.                     end
  21.                 else
  22.                     shutterState = true
  23.                     if colors.test(rs.getBundledOutput("bottom"), colors.green) then
  24.                         rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") - colors.green)
  25.                         rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.brown)
  26.                     else
  27.                         rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.brown)
  28.                     end
  29.                 end
  30.                 self.BGcolor = shutterState and colors.red or colors.lime
  31.                 self.Color = shutterState and colors.black or colors.white
  32.             end,
  33.         x1 = 5,
  34.         x2 = 20,
  35.         y1 = 2,
  36.         y2 = 2},
  37.     entrance = {
  38.         light = {"\\====/"},
  39.         color = entranceState and colors.black or colors.white,
  40.         BGcolor = entranceState and colors.red or colors.lime,
  41.         action = function(self)
  42.                 if entranceState then
  43.                     entranceState = false
  44.                     rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") - colors.purple)
  45.                 else
  46.                     entranceState = true
  47.                     rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.purple)
  48.                 end
  49.                 self.BGcolor = entranceState and colors.red or colors.lime
  50.                 self.Color = entranceState and colors.black or colors.white
  51.             end,
  52.         x1 = 10,
  53.         x2 = 15,
  54.         y1 = 3,
  55.         y2 = 3},
  56.     processing = {
  57.         light = {"|====|"},
  58.         color = processingState and colors.black or colors.white,
  59.         BGcolor = processingState and colors.red or colors.lime,
  60.         action = function(self)
  61.                 if processingState then
  62.                     processingState = false
  63.                     rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") - colors.cyan)
  64.                 else
  65.                     processingState = true
  66.                     rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.cyan)
  67.                 end
  68.                 self.BGcolor = processingState and colors.red or colors.lime
  69.                 self.Color = processingState and colors.black or colors.white
  70.             end,
  71.         x1 = 10,
  72.         x2 = 15,
  73.         y1 = 18,
  74.         y2 = 18},
  75.     alarm = {
  76.         light = {"+--------+",
  77.             "|        |",
  78.             "| ALARM! |",
  79.             "|        |",
  80.             "+--------+"},
  81.         color = alarmState and colors.black or colors.white,
  82.         BGcolor = alarmState and colors.red or colors.lime,
  83.         action = function(self)
  84.                 if alarmState then
  85.                     alarmState = false
  86.                     rs.setBundledOutput("bottom", rs.getBundledInput("bottom") - colors.red)
  87.                 else
  88.                     alarmState = true
  89.                     processingState = false
  90.                     entranceState = false
  91.                     shutterState = false
  92.                     rs.setBundledOutput("bottom", colors.red)
  93.                 end
  94.                 self.BGcolor = alarmState and colors.red or colors.lime
  95.                 self.Color = alarmState and colors.black or colors.white
  96.             end,
  97.         x1 = 35,
  98.         x2 = 43,
  99.         y1 = 14,
  100.         y2 = 18}
  101.     }
  102.  
  103. local function drawBG()
  104.     term.clear()
  105.     for i = 1, 19 do
  106.         paintutils.drawLine(1, i, 24, i, colors.white)
  107.         paintutils.drawLine(28, i, 51, i, colors.white)
  108.         term.setBackgroundColor(colors.red)
  109.         term.setCursorPos(25, i)
  110.         write("[")
  111.         term.setBackgroundColor(colors.blue)
  112.         term.setCursorPos(26, i)
  113.         write("X")
  114.         term.setBackgroundColor(colors.red)
  115.         term.setCursorPos(27, i)
  116.         write("]")
  117.     end
  118.     for i = 2, 18 do
  119.         paintutils.drawLine(2, i, 23, i, colors.lightGray)
  120.         term.setBackgroundColor(colors.gray)
  121.         term.setCursorPos(23, i)
  122.         write("|")
  123.         term.setCursorPos(2, i)
  124.         write(i == 2 and ".--------------------." or
  125.             i == 18 and "'--------------------'" or
  126.             "|")
  127.     end
  128. end
  129.  
  130. local function drawGUI()
  131.     for _,v in pairs(statusLights) do
  132.         for i = 1, #v.light do
  133.             term.setBackgroundColor(v.BGcolor)
  134.             term.setTextColor(v.color)
  135.             term.setCursorPos(v.x1, v.y1 + (i - 1))
  136.             write(v.light[i])
  137.         end
  138.     end
  139.     term.setBackgroundColor(colors.white)
  140.     term.setTextColor(colors.black)
  141.     term.setCursorPos(29, 3)
  142.     write("Shutter: ")
  143.     term.setTextColor(shutterState and colors.red or colors.lime)
  144.     write(shutterState and "OPEN  " or "CLOSED")
  145.     term.setTextColor(colors.black)
  146.     term.setCursorPos(29, 4)
  147.     write("Entrance: ")
  148.     term.setTextColor(entranceState and colors.red or colors.lime)
  149.     write(entranceState and "OPEN  " or "CLOSED")
  150.     term.setTextColor(colors.black)
  151.     term.setCursorPos(29, 5)
  152.     write("Processing: ")
  153.     term.setTextColor(processingState and colors.red or colors.lime)
  154.     write(processingState and "OPEN  " or "CLOSED")
  155. end
  156.  
  157. drawBG()
  158. drawGUI()
  159. while true do
  160.     local events = {os.pullEvent()}
  161.     if events[1] == "mouse_click" and events[2] == 1 then
  162.         for _,v in pairs(statusLights) do
  163.             if events[3] >= v.x1 and events[3] <= v.x2 and events[4] >= v.y1 and events[4] <= v.y2 then
  164.                 --v.BGcolor = v.BGcolor == colors.lime and colors.red or colors.lime
  165.                 v:action()
  166.                 drawGUI()
  167.             end
  168.         end
  169.     end
  170. end
  171. term.setCursorPos(1, y)
Advertisement
Add Comment
Please, Sign In to add comment