View difference between Paste ID: P0qZqPfi and Ng7Bfc9M
SHOW: | | - or go back to the newest paste.
1-
--updated Feb 20, 2013
1+
local bcable = "left"
2-
local bcable = "back"
2+
rs.getBundledInput("left")
3-
local mon = peripheral.wrap("top")
3+
local mon = peripheral.wrap("back")
4
mon.setTextScale(1)
5
mon.setTextColor(colors.white)
6
local button={}
7
mon.setBackgroundColor(colors.black)
8
local off = 0
9-
function setTable(name, bcolor, xmin, xmax, ymin, ymax)
9+
10-
   button[name] = {}
10+
function setTable(name, func, xmin, xmax, ymin, ymax)
11-
   button[name]["active"] = false
11+
    button[name] = {}
12-
   button[name]["bcolor"] = bcolor
12+
    button[name]["func"] = func
13-
   button[name]["xmin"] = xmin
13+
    button[name]["active"] = false
14-
   button[name]["ymin"] = ymin
14+
    button[name]["xmin"] = xmin
15-
   button[name]["xmax"] = xmax
15+
    button[name]["ymin"] = ymin
16-
   button[name]["ymax"] = ymax
16+
    button[name]["xmax"] = xmax
17
    button[name]["ymax"] = ymax
18
    button[name]["colour"] = color
19-
function togglebutton(currentState, cablecolor)
19+
20-
   if (currentState == true) then
20+
21-
      rs.setBundledOutput(bcable, (rs.getBundledOutput(bcable) - cablecolor))
21+
function funcOn()
22-
   else
22+
        off = off + 1
23-
      rs.setBundledOutput(bcable, (rs.getBundledOutput(bcable) + cablecolor))
23+
	if off == 1 then 
24
		rs.setBundledOutput("left", colors.white)
25
	end
26
	if off == 2 then
27
		rs.setBundledOutput("left", colors.black)
28-
   setTable("Blaze Spawner", colors.white, 2, 29, 3, 6)
28+
		off = 0
29-
   setTable("Creeper Spawner", colors.orange, 33, 60, 3, 6)
29+
	end
30-
   setTable("W-Skeleton Spawner", colors.magenta, 2, 29, 8, 11)
30+
		
31
end
32
       
33
function fillTable()
34
    setTable("Boiler ON", funcOn, 3, 15, 5, 7, colours.white)
35
    setTable("Boiler ON", funcOn, 3, 15, 5, 7, colours.white)
36
end    
37
 
38
function fill(text, color, bData)
39
   mon.setBackgroundColor(color)
40
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
41
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
42
   for j = bData["ymin"], bData["ymax"] do
43
      mon.setCursorPos(bData["xmin"], j)
44
      if j == yspot then
45
         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
46
            if k == xspot then
47
               mon.write(text)
48
            else
49
               mon.write(" ")
50
            end
51
         end
52
      else
53
         for i = bData["xmin"], bData["xmax"] do
54
            mon.write(" ")
55
         end
56
      end
57
   end
58
   mon.setBackgroundColor(colors.black)
59
end
60
     
61
function screen()
62
   local currColor
63
   for name,data in pairs(button) do
64
      local on = data["active"]
65
      if on == true then currColor = colors.lime else currColor = colors.red end
66
      fill(name, currColor, data)
67
   end
68
end
69-
            togglebutton(data["active"], data["bcolor"])
69+
70
function checkxy(x, y)
71
   for name, data in pairs(button) do
72
      if y>=data["ymin"] and  y <= data["ymax"] then
73
         if x>=data["xmin"] and x<= data["xmax"] then
74
            data["active"] = not data["active"]
75
	    data["func"]()
76
            print(name)
77
         end
78
      end
79
   end
80
end
81
     
82
function heading(text)
83
   w, h = mon.getSize()
84
   mon.setCursorPos((w-string.len(text))/2+1, 1)
85
   mon.write(text)
86-
   heading("Mead Science Control")
86+
87
     
88
fillTable()
89
while true do
90
   mon.clear()
91
   heading("Boiler Room Control Console")
92
   screen()
93
   local e,side,x,y = os.pullEvent("monitor_touch")
94
   print(x..":"..y)
95
   checkxy(x,y)
96
   sleep(.1)
97
end