View difference between Paste ID: JVNgzAK3 and 86DEBCPx
SHOW: | | - or go back to the newest paste.
1
local mon = peripheral.wrap("left")
2
mon.setTextScale(0.5)
3
mon.setTextColor(colors.white)
4
local button={}
5
mon.setBackgroundColor(colors.black)
6
     
7
function setTable(name, xmin, xmax, ymin, ymax, col)
8
   button[name] = {}
9
   button[name]["active"] = false
10
   button[name]["xmin"] = xmin
11
   button[name]["ymin"] = ymin
12
   button[name]["xmax"] = xmax
13
   button[name]["ymax"] = ymax
14
   button[name]["colour"] = col
15
end
16
       
17
function fillTable()
18
   setTable("Einschalten", 2, 16, 10, 14, colours.blue)
19
   setTable("Ausschalten", 21, 35, 10, 14, colours.red)
20
end    
21
 
22
function fill(text, color, bData)
23
   mon.setBackgroundColor(color)
24
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
25
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
26
   for j = bData["ymin"], bData["ymax"] do
27
      mon.setCursorPos(bData["xmin"], j)
28
      if j == yspot then
29
         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
30
            if k == xspot then
31
               mon.write(text)
32
            else
33
               mon.write(" ")
34
            end
35
         end
36
      else
37
         for i = bData["xmin"], bData["xmax"] do
38
            mon.write(" ")
39
         end
40
      end
41
   end
42
   mon.setBackgroundColor(colors.black)
43
end
44
     
45
function screen()
46
   local currColor
47
   for name,data in pairs(button) do
48
      local on = data["active"]
49
      if on == true then currColor = colors.lime else currColor = colors.lightGray end
50
      fill(name, currColor, data)
51
   end
52
end
53
     
54
function checkxy(x, y)
55
   local new = false
56
   local newname
57
   for name, data in pairs(button) do
58
      data["active"] = false
59
      if y>=data["ymin"] and  y <= data["ymax"] then
60
         if x>=data["xmin"] and x<= data["xmax"] then
61
            rs.setBundledOutput("bottom", data["colour"])
62
            new = true
63
            newname = name
64
         end
65
      end
66
   end
67
   if new then
68
      button[newname]["active"] = true
69
   end
70
end
71
     
72
function heading(text)
73
   w, h = mon.getSize()
74
   mon.setCursorPos((w-string.len(text))/2+1, 1)
75
   mon.write(text)
76
end
77
     
78-
function checkRedstone()
78+
79-
   local c = rs.getBundledInput("back")
79+
80-
   if rs.getBundledOutput("bottom") ~= c then
80+
81-
      rs.setBundledOutput("bottom", 0)
81+
82-
      for name, data in pairs(button) do
82+
83-
         if data["colour"] == c then
83+
84-
            data["active"] = true
84+
85-
         else
85+
86-
            data["active"] = false
86+
87
   end
88
   sleep(.1)
89
end