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