SHOW:
|
|
- or go back to the newest paste.
| 1 | local mon = term | |
| 2 | --mon.setTextScale(1) | |
| 3 | mon.setTextColor(colors.white) | |
| 4 | local button={}
| |
| 5 | mon.setBackgroundColor(colors.black) | |
| 6 | ||
| 7 | function clearTable() | |
| 8 | button = {}
| |
| 9 | end | |
| 10 | ||
| 11 | function setButton(name, buttonOn) | |
| 12 | --print(name) | |
| 13 | --print(button[name]["active"]) | |
| 14 | button[name]["active"] = buttonOn | |
| 15 | screen() | |
| 16 | end | |
| 17 | ||
| 18 | function setTable(name, func, param, xmin, xmax, ymin, ymax) | |
| 19 | button[name] = {}
| |
| 20 | button[name]["func"] = func | |
| 21 | button[name]["active"] = false | |
| 22 | button[name]["param"] = param | |
| 23 | button[name]["xmin"] = xmin | |
| 24 | button[name]["ymin"] = ymin | |
| 25 | button[name]["xmax"] = xmax | |
| 26 | button[name]["ymax"] = ymax | |
| 27 | end | |
| 28 | ||
| 29 | function funcName() | |
| 30 | print("You clicked buttonText")
| |
| 31 | end | |
| 32 | ||
| 33 | function fillTable() | |
| 34 | setTable("ButtonText", funcName, 5, 25, 4, 8)
| |
| 35 | end | |
| 36 | ||
| 37 | function fill(text, color, bData) | |
| 38 | mon.setBackgroundColor(color) | |
| 39 | local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2) | |
| 40 | local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1 | |
| 41 | for j = bData["ymin"], bData["ymax"] do | |
| 42 | mon.setCursorPos(bData["xmin"], j) | |
| 43 | if j == yspot then | |
| 44 | for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do | |
| 45 | if k == xspot then | |
| 46 | mon.write(text) | |
| 47 | else | |
| 48 | mon.write(" ")
| |
| 49 | end | |
| 50 | end | |
| 51 | else | |
| 52 | for i = bData["xmin"], bData["xmax"] do | |
| 53 | mon.write(" ")
| |
| 54 | end | |
| 55 | end | |
| 56 | end | |
| 57 | mon.setBackgroundColor(colors.black) | |
| 58 | end | |
| 59 | ||
| 60 | function screen() | |
| 61 | local currColor | |
| 62 | for name,data in pairs(button) do | |
| 63 | local on = data["active"] | |
| 64 | if on == true then currColor = colors.lime else currColor = colors.red end | |
| 65 | fill(name, currColor, data) | |
| 66 | end | |
| 67 | end | |
| 68 | ||
| 69 | function toggleButton(name) | |
| 70 | button[name]["active"] = not button[name]["active"] | |
| 71 | screen() | |
| 72 | end | |
| 73 | ||
| 74 | function flash(name) | |
| 75 | toggleButton(name) | |
| 76 | screen() | |
| 77 | sleep(0.15) | |
| 78 | toggleButton(name) | |
| 79 | screen() | |
| 80 | end | |
| 81 | ||
| 82 | function checkxy(x, y) | |
| 83 | for name, data in pairs(button) do | |
| 84 | if y>=data["ymin"] and y <= data["ymax"] then | |
| 85 | if x>=data["xmin"] and x<= data["xmax"] then | |
| 86 | if data["param"] == "" then | |
| 87 | data["func"]() | |
| 88 | else | |
| 89 | data["func"](data["param"]) | |
| 90 | end | |
| 91 | return true | |
| 92 | --data["active"] = not data["active"] | |
| 93 | --print(name) | |
| 94 | end | |
| 95 | end | |
| 96 | end | |
| 97 | return false | |
| 98 | end | |
| 99 | ||
| 100 | function heading(text) | |
| 101 | w, h = mon.getSize() | |
| 102 | mon.setCursorPos((w-string.len(text))/2+1, 1) | |
| 103 | mon.write(text) | |
| 104 | end | |
| 105 | ||
| 106 | function label(w, h, text) | |
| 107 | mon.setCursorPos(w, h) | |
| 108 | mon.write(text) | |
| 109 | end |