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 ""]]-- |
| 3 | + | --[[If no 2nd parameter is needed leave blank quotation marks ie ""]]-- |
| 4 | --[[edit]]-- | |
| 5 | - | local mon = peripheral.find("monitor")
|
| 5 | + | local mon = peripheral.wrap("right")
|
| 6 | - | --[[local mon = term]]-- If you want to use this for pocket computers |
| 6 | + | |
| 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) | |
| 26 | button[name] = {}
| |
| 27 | button[name]["func"] = func | |
| 28 | button[name]["active"] = active | |
| 29 | if active == nil then | |
| 30 | active = false | |
| 31 | end | |
| 32 | button[name]["param1"] = param1 | |
| 33 | button[name]["param2"] = param2 | |
| 34 | button[name]["xmin"] = xmin | |
| 35 | button[name]["ymin"] = ymin | |
| 36 | button[name]["xmax"] = xmax | |
| 37 | button[name]["ymax"] = ymax | |
| 38 | end | |
| 39 | ||
| 40 | function remTable(name) | |
| 41 | button[name] = {}
| |
| 42 | button[name]["xmin"] = 0 | |
| 43 | button[name]["ymin"] = 0 | |
| 44 | button[name]["xmax"] = 0 | |
| 45 | button[name]["ymax"] = 0 | |
| 46 | end | |
| 47 | ||
| 48 | ||
| 49 | function fill(text, color, bData) | |
| 50 | mon.setBackgroundColor(color) | |
| 51 | mon.write("ymin = " .. bData["ymin"] .. " xmin= " .. bData["xmin"])
| |
| 52 | local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2) | |
| 53 | local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1 | |
| 54 | for j = bData["ymin"], bData["ymax"] do | |
| 55 | mon.setCursorPos(bData["xmin"], j) | |
| 56 | if j == yspot then | |
| 57 | for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do | |
| 58 | if k == xspot then | |
| 59 | mon.write(text) | |
| 60 | else | |
| 61 | mon.write(" ")
| |
| 62 | end | |
| 63 | end | |
| 64 | else | |
| 65 | for i = bData["xmin"], bData["xmax"] do | |
| 66 | mon.write(" ")
| |
| 67 | end | |
| 68 | end | |
| 69 | end | |
| 70 | mon.setBackgroundColor(colors.black) | |
| 71 | end | |
| 72 | ||
| 73 | function screen() | |
| 74 | local currColor | |
| 75 | for name,data in pairs(button) do | |
| 76 | local on = data["active"] | |
| 77 | if on == true then currColor = colors.lime else currColor = colors.red end | |
| 78 | fill(name, currColor, data) | |
| 79 | end | |
| 80 | end | |
| 81 | ||
| 82 | function toggleButton(name) | |
| 83 | button[name]["active"] = not button[name]["active"] | |
| 84 | screen() | |
| 85 | end | |
| 86 | ||
| 87 | function flash(name) | |
| 88 | toggleButton(name) | |
| 89 | screen() | |
| 90 | sleep(0.15) | |
| 91 | toggleButton(name) | |
| 92 | screen() | |
| 93 | end | |
| 94 | ||
| 95 | function checkxy(x, y) | |
| 96 | for name, data in pairs(button) do | |
| 97 | if y>=data["ymin"] and y <= data["ymax"] then | |
| 98 | if x>=data["xmin"] and x<= data["xmax"] then | |
| 99 | if data["param1"] == "" then | |
| 100 | data["func"]() | |
| 101 | else | |
| 102 | data["func"](data["param1"], data["param2"]) | |
| 103 | end | |
| 104 | return true | |
| 105 | end | |
| 106 | end | |
| 107 | end | |
| 108 | return false | |
| 109 | end | |
| 110 | ||
| 111 | function heading(text) | |
| 112 | w, h = mon.getSize() | |
| 113 | mon.setCursorPos((w-string.len(text))/2+1, 1) | |
| 114 | mon.write(text) | |
| 115 | end | |
| 116 | ||
| 117 | function label(w, h, text) | |
| 118 | mon.setCursorPos(w, h) | |
| 119 | mon.write(text) | |
| 120 | end |