View difference between Paste ID: 7hV7QRSS and 2TSqWBiS
SHOW: | | - or go back to the newest paste.
1
--[[Edited by Spiker985]]--
2
--[[I have added a 2nd parameter to the setTable function be sure to follow the example]]--
3
--[[If no 2nd parameter is needed leave blank quotation marks ie ""]]--
4
--[[edit]]--
5
local mon = peripheral.wrap("right")
6
mon.setTextColor(colors.white)
7
mon.setBackgroundColor(colors.black)
8
mon.setTextScale(1)
9
10
--[[Examples]]--
11
--function funcName()
12
--  print("You clicked buttonText")
13
--end
14
--function fillTable()
15
-- setTable("ButtonText", funcName, "param1", "param2", 5, 25, 4, 8)
16
--end
17
18
--[[Don't edit anything below this]]--
19
local button={}
20
21
function clearTable()
22
   button = {}
23
end
24
     
25-
function setTable(name, func, param1, param2, active, xmin, xmax, ymin, ymax)
25+
function setTable(name, func, param1, param2, xmin, xmax, ymin, ymax)
26
   button[name] = {}
27
   button[name]["func"] = func
28-
   button[name]["active"] = active
28+
29-
   if active == nil then
29+
30-
     active = false
30+
31
   button[name]["xmin"] = xmin
32
   button[name]["ymin"] = ymin
33
   button[name]["xmax"] = xmax
34
   button[name]["ymax"] = ymax
35
end
36
37
function remTable(name)
38
  button[name] = {}
39
  button[name]["xmin"] = 0
40
  button[name]["ymin"] = 0
41
  button[name]["xmax"] = 0
42
  button[name]["ymax"] = 0
43
end
44
    
45
46
function fill(text, color, bData)
47
   mon.setBackgroundColor(color)
48
	mon.write("ymin = " .. bData["ymin"] .. " xmin= " .. bData["xmin"])
49
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
50
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
51
   for j = bData["ymin"], bData["ymax"] do
52
      mon.setCursorPos(bData["xmin"], j)
53
      if j == yspot then
54
         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
55
            if k == xspot then
56
               mon.write(text)
57
            else
58
               mon.write(" ")
59
            end
60
         end
61
      else
62
         for i = bData["xmin"], bData["xmax"] do
63
            mon.write(" ")
64
         end
65
      end
66
   end
67
   mon.setBackgroundColor(colors.black)
68
end
69
     
70
function screen()
71
   local currColor
72
   for name,data in pairs(button) do
73
--      local on = data["active"]
74
--      if on == true then currColor = colors.lime else currColor = colors.red end
75
--      fill(name, currColor, data)
76-
      local on = data["active"]
76+
77-
      if on == true then currColor = colors.lime else currColor = colors.red end
77+
78-
      fill(name, currColor, data)
78+
79
function toggleButton(name)
80
--   button[name]["active"] = not button[name]["active"]
81
--   screen()
82
end     
83-
   button[name]["active"] = not button[name]["active"]
83+
84
function flash(name)
85
   toggleButton(name)
86
   screen()
87
   sleep(0.15)
88
   toggleButton(name)
89
   screen()
90
end
91
                                             
92
function checkxy(x, y)
93
   for name, data in pairs(button) do
94
      if y>=data["ymin"] and  y <= data["ymax"] then
95
         if x>=data["xmin"] and x<= data["xmax"] then
96
            if data["param1"] == "" then
97
              data["func"]()
98
            else
99
              data["func"](data["param1"], data["param2"])
100
            end
101
	    return true
102
         end
103
      end
104
   end
105
   return false
106
end
107
     
108
function heading(text)
109
   w, h = mon.getSize()
110
   mon.setCursorPos((w-string.len(text))/2+1, 1)
111
   mon.write(text)
112
end
113
     
114
function label(w, h, text)
115
   mon.setCursorPos(w, h)
116
   mon.write(text)
117
end