SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --monitors = {peripheral.find("monitor")}
|
| 1 | + | monitors = {peripheral.find("monitor")}
|
| 2 | - | local mon = peripheral.wrap("top")
|
| 2 | + | local allMon = {}
|
| 3 | - | --local mon = {}
|
| 3 | + | for funcName,_ in pairs(monitors[1]) do |
| 4 | - | --for funcName,_ in pairs(monitors[1]) do |
| 4 | + | allMon[funcName] = function(...) |
| 5 | - | -- mon[funcName] = function(...) |
| 5 | + | for i=1,#monitors-1 do monitors[i][funcName](unpack(arg)) end |
| 6 | - | -- for i=1,#monitors-1 do monitors[i][funcName](unpack(arg)) end |
| 6 | + | return monitors[#monitors][funcName](unpack(arg)) |
| 7 | - | -- return monitors[#monitors][funcName](unpack(arg)) |
| 7 | + | end |
| 8 | - | -- end |
| 8 | + | |
| 9 | - | --end |
| 9 | + | |
| 10 | local sides = {"left", "right", "front", "back", "bottom", "top"}
| |
| 11 | - | mon.setTextScale(1) |
| 11 | + | local monitor = {}
|
| 12 | - | mon.setTextColor(colors.white) |
| 12 | + | |
| 13 | for a,b in pairs(sides) do | |
| 14 | - | mon.setBackgroundColor(colors.black) |
| 14 | + | local monObject = peripheral.wrap(b) |
| 15 | if monObject then | |
| 16 | - | function clearTable() |
| 16 | + | monitor[b] = monObject |
| 17 | end | |
| 18 | end | |
| 19 | ||
| 20 | - | function setButton(name, buttonOn) |
| 20 | + | allMon.setTextScale(1) |
| 21 | - | print(name) |
| 21 | + | allMon.setTextColor(colors.white) |
| 22 | - | print(button[name]["active"]) |
| 22 | + | allMon.setBackgroundColor(colors.black) |
| 23 | - | button[name]["active"] = buttonOn |
| 23 | + | |
| 24 | - | screen() |
| 24 | + | |
| 25 | ||
| 26 | - | |
| 26 | + | function clearAll() |
| 27 | - | function setTable(name, func, param, xmin, xmax, ymin, ymax) |
| 27 | + | |
| 28 | - | button[name] = {}
|
| 28 | + | |
| 29 | - | button[name]["func"] = func |
| 29 | + | |
| 30 | - | button[name]["active"] = "empty" |
| 30 | + | function clearTable(name) |
| 31 | - | button[name]["param"] = param |
| 31 | + | button[name] = {}
|
| 32 | - | button[name]["xmin"] = xmin |
| 32 | + | |
| 33 | - | button[name]["ymin"] = ymin |
| 33 | + | |
| 34 | - | button[name]["xmax"] = xmax |
| 34 | + | function getPlayer(name) |
| 35 | - | button[name]["ymax"] = ymax |
| 35 | + | return button[name]["player"] |
| 36 | end | |
| 37 | ||
| 38 | - | function funcName() |
| 38 | + | function setPlayer(name, player) |
| 39 | - | print("You clicked buttonText")
|
| 39 | + | button[name]["player"] = player |
| 40 | screen() | |
| 41 | - | |
| 41 | + | |
| 42 | - | function fillTable() |
| 42 | + | |
| 43 | - | setTable("ButtonText", funcName, 5, 25, 4, 8)
|
| 43 | + | function getState(name) |
| 44 | return button[name]["active"] | |
| 45 | end | |
| 46 | ||
| 47 | - | mon.setBackgroundColor(color) |
| 47 | + | function setState(name, state) |
| 48 | - | local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2) |
| 48 | + | button[name]["active"] = state |
| 49 | - | local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1 |
| 49 | + | screen() |
| 50 | - | for j = bData["ymin"], bData["ymax"] do |
| 50 | + | |
| 51 | - | mon.setCursorPos(bData["xmin"], j) |
| 51 | + | |
| 52 | - | if j == yspot then |
| 52 | + | -- monSide: "left", "right", "front", "back", "bottom", "top" |
| 53 | - | for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 dofile( |
| 53 | + | function setTable(name, func, param, xmin, xmax, ymin, ymax, monSide) |
| 54 | - | if k == xspot then |
| 54 | + | button[name] = {}
|
| 55 | - | mon.write(text) |
| 55 | + | button[name]["func"] = func |
| 56 | - | else |
| 56 | + | button[name]["active"] = false |
| 57 | - | mon.write(" ")
|
| 57 | + | button[name]["player"] = "empty" |
| 58 | - | end |
| 58 | + | button[name]["param"] = param |
| 59 | - | end |
| 59 | + | button[name]["xmin"] = xmin |
| 60 | - | else |
| 60 | + | button[name]["ymin"] = ymin |
| 61 | - | for i = bData["xmin"], bData["xmax"] do |
| 61 | + | button[name]["xmax"] = xmax |
| 62 | - | mon.write(" ")
|
| 62 | + | button[name]["ymax"] = ymax |
| 63 | - | end |
| 63 | + | if not monitor[monSide] then |
| 64 | - | end |
| 64 | + | print("There is no monitor on the "..monSide.." side! The button named \""..name.."\" won't be displayed.")
|
| 65 | - | end |
| 65 | + | button[name]["mon"] = nil |
| 66 | - | mon.setBackgroundColor(colors.black) |
| 66 | + | else |
| 67 | button[name]["mon"] = monSide | |
| 68 | - | |
| 68 | + | end |
| 69 | end | |
| 70 | - | local currColor |
| 70 | + | |
| 71 | - | local currDisplayName |
| 71 | + | -- returns true if there is a monitor connected at the given side |
| 72 | - | for name,data in pairs(button) do |
| 72 | + | function testForMonitor(monSide) |
| 73 | - | local on = data["active"] |
| 73 | + | if not monSide then |
| 74 | - | if on == "empty" then |
| 74 | + | return false |
| 75 | - | currColor = colors.white |
| 75 | + | end |
| 76 | - | currDisplayName = " " |
| 76 | + | if not monitors[monSide] then |
| 77 | - | elseif on == "x" then |
| 77 | + | return false |
| 78 | - | currColor = colors.lightGray |
| 78 | + | end |
| 79 | - | currDisplayName = on |
| 79 | + | return true |
| 80 | - | elseif on == "o" then |
| 80 | + | |
| 81 | - | currColor = colors.lightGray |
| 81 | + | |
| 82 | - | currDisplayName = on |
| 82 | + | |
| 83 | - | end |
| 83 | + | |
| 84 | - | fill(currDisplayName, currColor, data) |
| 84 | + | if not testForMonitor(bData["mon"]) then |
| 85 | - | end |
| 85 | + | return |
| 86 | end | |
| 87 | local display = monitors[bData["mon"]] | |
| 88 | display.setBackgroundColor(color) | |
| 89 | - | --button[name]["active"] = not button[name]["active"] |
| 89 | + | local on = bData["player"] |
| 90 | - | screen() |
| 90 | + | local xSize = bData["xmax"] - bData["xmin"] |
| 91 | local ySize = bData["ymax"] - bData["ymin"] | |
| 92 | local sizeRel = xSize / ySize | |
| 93 | for j = bData["ymin"], bData["ymax"] do -- draws a rectangle | |
| 94 | - | toggleButton(name) |
| 94 | + | display.setCursorPos(bData["xmin"], j) |
| 95 | - | screen() |
| 95 | + | for i = bData["xmin"], bData["xmax"] do |
| 96 | - | sleep(0.15) |
| 96 | + | display.write(" ")
|
| 97 | - | toggleButton(name) |
| 97 | + | end |
| 98 | - | screen() |
| 98 | + | end |
| 99 | if on == "x" then -- draws a cross on top | |
| 100 | - | |
| 100 | + | local xOffset = 0 |
| 101 | - | function checkxy(x, y) |
| 101 | + | local scaledYOffset = 0 |
| 102 | - | for name, data in pairs(button) do |
| 102 | + | display.setBackgroundColor(colors.red) |
| 103 | - | if y>=data["ymin"] and y <= data["ymax"] then |
| 103 | + | for j = bData["ymin"], bData["ymax"] do |
| 104 | - | if x>=data["xmin"] and x<= data["xmax"] then |
| 104 | + | scaledYOffset = (j - bData["ymin"]) * sizeRel |
| 105 | - | if data["param"] == "" then |
| 105 | + | for i = bData["xmin"], bData["xmax"] do |
| 106 | - | data["func"]() |
| 106 | + | xOffset = i - bData["xmin"] |
| 107 | - | else |
| 107 | + | if (math.floor(math.abs(xOffset - scaledYOffset)-2.2) < 0) or (math.floor(math.abs(xOffset + scaledYOffset - xSize)-2.2) < 0) then |
| 108 | - | data["func"](data["param"]) |
| 108 | + | display.setCursorPos(i, j) |
| 109 | - | end |
| 109 | + | display.write(" ")
|
| 110 | - | return true |
| 110 | + | end |
| 111 | - | --data["active"] = not data["active"] |
| 111 | + | end |
| 112 | - | --print(name) |
| 112 | + | end |
| 113 | - | end |
| 113 | + | elseif on == "o" then -- draws a circle on top |
| 114 | - | end |
| 114 | + | local xOffset = 0 |
| 115 | - | end |
| 115 | + | local scaledYOffset = 0 |
| 116 | - | return false |
| 116 | + | local halfSize = xSize / 2 |
| 117 | display.setBackgroundColor(colors.red) | |
| 118 | - | |
| 118 | + | for j = bData["ymin"], bData["ymax"] do |
| 119 | - | function heading(text) |
| 119 | + | scaledYOffset = math.abs(halfSize - ((j - bData["ymin"]) * sizeRel)) |
| 120 | - | w, h = mon.getSize() |
| 120 | + | for i = bData["xmin"], bData["xmax"] do |
| 121 | - | mon.setCursorPos((w-string.len(text))/2+1, 1) |
| 121 | + | xOffset = math.abs(halfSize - (i - bData["xmin"])) |
| 122 | - | mon.write(text) |
| 122 | + | if math.floor(math.abs(math.sqrt(scaledYOffset^2+xOffset^2) - halfSize)-1.9) < 0 then |
| 123 | display.setCursorPos(i, j) | |
| 124 | - | |
| 124 | + | display.write(" ")
|
| 125 | - | function label(w, h, text) |
| 125 | + | end |
| 126 | - | mon.setCursorPos(w, h) |
| 126 | + | end |
| 127 | - | mon.write(text) |
| 127 | + | end |
| 128 | end | |
| 129 | display.setBackgroundColor(colors.black) | |
| 130 | end | |
| 131 | ||
| 132 | function screen() | |
| 133 | local currColor | |
| 134 | local currDisplayName | |
| 135 | for name,data in pairs(button) do | |
| 136 | local on = data["player"] | |
| 137 | if on == "empty" then | |
| 138 | currDisplayName = " " | |
| 139 | elseif on == "x" then | |
| 140 | currDisplayName = on | |
| 141 | elseif on == "o" then | |
| 142 | currDisplayName = on | |
| 143 | end | |
| 144 | if data["active"] then | |
| 145 | currColor = colors.lime | |
| 146 | else | |
| 147 | if on == "empty" then | |
| 148 | currColor = colors.white | |
| 149 | elseif on == "x" then | |
| 150 | currColor = colors.lightGray | |
| 151 | elseif on == "o" then | |
| 152 | currColor = colors.lightGray | |
| 153 | end | |
| 154 | end | |
| 155 | fill(currDisplayName, currColor, data) | |
| 156 | end | |
| 157 | end | |
| 158 | ||
| 159 | function toggleButton(name) | |
| 160 | button[name]["active"] = not button[name]["active"] | |
| 161 | screen() | |
| 162 | end | |
| 163 | ||
| 164 | function flash(name) | |
| 165 | toggleButton(name) | |
| 166 | screen() | |
| 167 | sleep(0.15) | |
| 168 | toggleButton(name) | |
| 169 | screen() | |
| 170 | end | |
| 171 | ||
| 172 | function checkxy(x, y, side) | |
| 173 | for name, data in pairs(button) do | |
| 174 | if data["mon"] == side then | |
| 175 | if y>=data["ymin"] and y <= data["ymax"] then | |
| 176 | if x>=data["xmin"] and x<= data["xmax"] then | |
| 177 | if data["param"] == "" then | |
| 178 | data["func"]() | |
| 179 | else | |
| 180 | data["func"](data["param"]) | |
| 181 | end | |
| 182 | return true | |
| 183 | --data["active"] = not data["active"] | |
| 184 | --print(name) | |
| 185 | end | |
| 186 | end | |
| 187 | end | |
| 188 | end | |
| 189 | return false | |
| 190 | end | |
| 191 | ||
| 192 | function heading(text, monSide) | |
| 193 | if not testForMonitor(monSide) then | |
| 194 | print("Heading cannot be displayed on "..monSide..".")
| |
| 195 | return | |
| 196 | end | |
| 197 | local display = monitors[bData["mon"]] | |
| 198 | w, h = display.getSize() | |
| 199 | display.setCursorPos((w-string.len(text))/2+1, 1) | |
| 200 | display.write(text) | |
| 201 | end | |
| 202 | ||
| 203 | function label(w, h, text, monSide) | |
| 204 | if not testForMonitor(monSide) then | |
| 205 | print("Heading cannot be displayed on "..monSide..".")
| |
| 206 | return | |
| 207 | end | |
| 208 | local display = monitors[bData["mon"]] | |
| 209 | display.setCursorPos(w, h) | |
| 210 | display.write(text) | |
| 211 | end |