SHOW:
|
|
- or go back to the newest paste.
| 1 | m = peripheral.wrap("top")
| |
| 2 | x,y = m.getSize() | |
| 3 | rednet.open("bottom")
| |
| 4 | ||
| 5 | --Table to hold turtle information | |
| 6 | -- Label = id, xmin, xmax, ymin, ymax, page, active | |
| 7 | local turtle = {
| |
| 8 | ["Quarry 1"] = { id = 19, xmin = 2, xmax = 11, ymin = 4, ymax = 5, page = 1, active = false },
| |
| 9 | ["Quarry 2"] = { id = 18, xmin = 2, xmax = 11, ymin = 6, ymax = 7, page = 1, active = false },
| |
| 10 | ["Branch 1"] = { id = 22, xmin = 2, xmax = 11, ymin = 8, ymax = 9, page = 1, active = false },
| |
| 11 | ["Branch 2"] = { id = 20, xmin = 2, xmax = 11, ymin = 10, ymax = 11, page = 1, active = false },
| |
| 12 | ["Branch 3"] = { id = 29, xmin = 2, xmax = 11, ymin = 4, ymax = 5, page = 2, active = false },
| |
| 13 | ["Branch 4"] = { id = 30, xmin = 2, xmax = 11, ymin = 6, ymax = 7, page = 2, active = false },
| |
| 14 | ["Branch 5"] = { id = 31, xmin = 2, xmax = 11, ymin = 8, ymax = 9, page = 2, active = false },
| |
| 15 | ["Branch 6"] = { id = 32, xmin = 2, xmax = 11, ymin = 10, ymax = 11, page = 2, active = false },
| |
| 16 | ||
| 17 | } | |
| 18 | ||
| 19 | --Table to hold GUI. (Buttons) | |
| 20 | local menu = {
| |
| 21 | -- Name, xmin, xmax, ymin, ymax, active | |
| 22 | ["Prev"] = { xmin = 1, xmax = 5, ymin = 12, ymax = 13, active = false },
| |
| 23 | ["Next"] = { xmin = 9, xmax = 13, ymin = 12, ymax = 13, active = false },
| |
| 24 | ||
| 25 | } | |
| 26 | ||
| 27 | -- Function to write to specified points | |
| 28 | -- using arguments. | |
| 29 | function writeTo(x,y,bColor,tColor,text) | |
| 30 | local bColor = bColor or colors.black | |
| 31 | local tColor = tColor or colors.white | |
| 32 | m.setCursorPos(x,y) | |
| 33 | m.setBackgroundColor(bColor) | |
| 34 | m.setTextColor(tColor) | |
| 35 | m.write(text) | |
| 36 | m.setTextColor(colors.white) | |
| 37 | m.setBackgroundColor(colors.black) | |
| 38 | end | |
| 39 | ||
| 40 | -- Centers text on y line. | |
| 41 | function centerPrint(text, tColor, bColor, y) | |
| 42 | local mx,my = m.getSize() | |
| 43 | local xPos = math.floor((mx/2) - (#text/2)) | |
| 44 | local tColor = tColor or colors.white | |
| 45 | local bColor = bColor or colors.black | |
| 46 | m.setTextColor(tColor) | |
| 47 | m.setBackgroundColor(bColor) | |
| 48 | m.setCursorPos(xPos,y) | |
| 49 | m.write(text) | |
| 50 | m.setBackgroundColor(colors.black) | |
| 51 | m.setTextColor(colors.white) | |
| 52 | m.setCursorPos(1,y+1) | |
| 53 | end | |
| 54 | ||
| 55 | -- Determines if rednet is enabled or not. | |
| 56 | function rEnabled() | |
| 57 | local rColor | |
| 58 | if rednet.isOpen("bottom") then
| |
| 59 | rColor = colors.lime | |
| 60 | else | |
| 61 | rColor = colors.red | |
| 62 | rednet.open("bottom")
| |
| 63 | end | |
| 64 | writeTo(24,12,rColor,colors.white,"Rednet") | |
| 65 | end | |
| 66 | ||
| 67 | ||
| 68 | -- Draws main menu. | |
| 69 | function drawMain() | |
| 70 | m.clear() | |
| 71 | local mx,my = m.getSize() | |
| 72 | centerPrint("Random List", colors.lime, colors.black, 1)
| |
| 73 | centerPrint(string.rep("=",x+2), colors.lime, colors.black,2)
| |
| 74 | writeTo(13,4,colors.black,colors.lime,"+") | |
| 75 | m.write(string.rep("-",15))
| |
| 76 | writeTo(x,4,colors.black,colors.lime,"+") | |
| 77 | m.setCursorPos(13,5) | |
| 78 | for i = 5,10 do | |
| 79 | m.write("|"..string.rep(" ",15).."|")
| |
| 80 | m.setCursorPos(13,i) | |
| 81 | end | |
| 82 | writeTo(13,10,colors.black,colors.lime,"+") | |
| 83 | m.write(string.rep("-",15))
| |
| 84 | writeTo(x,10,colors.black,colors.lime,"+") | |
| 85 | writeTo(14,5,colors.black,colors.lime,"Fuel:") | |
| 86 | writeTo(14,6,colors.black,colors.gray, string.rep("-",15))
| |
| 87 | writeTo(14,7,colors.black,colors.lime,"Status:") | |
| 88 | writeTo(14,8,colors.black,colors.gray, string.rep("-",15))
| |
| 89 | writeTo(14,9,colors.black,colors.lime,"ID:") | |
| 90 | rEnabled() | |
| 91 | for k,v in pairs(menu) do | |
| 92 | writeTo(v.xmin, v.ymin, colors.black, colors.lime,k) | |
| 93 | end | |
| 94 | end | |
| 95 | ||
| 96 | -- Draws the buttons for turtles and the buttons | |
| 97 | function pageOne() | |
| 98 | m.clear() | |
| 99 | drawMain() | |
| 100 | for k,v in pairs(turtle) do | |
| 101 | if v.page == 1 then | |
| 102 | writeTo(v.xmin,v.ymin,colors.black,colors.purple,k) | |
| 103 | end | |
| 104 | end | |
| 105 | end | |
| 106 | ||
| 107 | --Draws page 2 of turtle info | |
| 108 | function pageTwo() | |
| 109 | m.clear() | |
| 110 | drawMain() | |
| 111 | for k,v in pairs(turtle) do | |
| 112 | if v.page == 2 then | |
| 113 | writeTo(v.xmin, v.ymin, colors.black, colors.purple,k) | |
| 114 | end | |
| 115 | end | |
| 116 | end | |
| 117 | ||
| 118 | ||
| 119 | --Check for valid click | |
| 120 | function checkTouch() | |
| 121 | local e,side,x,y = os.pullEvent("monitor_touch")
| |
| 122 | for k,v in pairs(turtle) do | |
| 123 | if y<=v.ymax and y>=v.ymin and x<=v.xmax and x>=v.xmin then | |
| 124 | for i = 1,2 do | |
| 125 | v.active = not v.active | |
| 126 | toggleButton() | |
| 127 | sleep(0.2) | |
| 128 | end | |
| 129 | print(k) | |
| 130 | print(x..":"..y) | |
| 131 | end | |
| 132 | end | |
| 133 | --determines where you clicked for next/prev menu | |
| 134 | for k,v in pairs(menu) do | |
| 135 | if y<=v.ymax and y>=v.ymin and x<=v.xmax and x>=v.xmin then | |
| 136 | for i = 1,2 do | |
| 137 | v.active = not v.active | |
| 138 | toggleButton() | |
| 139 | sleep(0.2) | |
| 140 | end | |
| 141 | print(k) | |
| 142 | print(x..":"..y) | |
| 143 | if k == "Next" then | |
| 144 | pageTwo() | |
| 145 | print(k) | |
| 146 | elseif k == "Prev" then | |
| 147 | pageOne() | |
| 148 | print(k) | |
| 149 | end | |
| 150 | end | |
| 151 | end | |
| 152 | end | |
| 153 | ||
| 154 | --Toggles button colors | |
| 155 | function toggleButton() | |
| 156 | local bColor | |
| 157 | local tColor | |
| 158 | for k,v in pairs(turtle) do | |
| 159 | local on = v.active | |
| 160 | if on then | |
| 161 | bColor = colors.purple | |
| 162 | tColor = colors.lime | |
| 163 | else | |
| 164 | bColor = colors.black | |
| 165 | tColor = colors.purple | |
| 166 | end | |
| 167 | writeTo(v.xmin,v.ymin,bColor,tColor,k) | |
| 168 | end | |
| 169 | for k,v in pairs(menu) do | |
| 170 | local on = v.active | |
| 171 | if on then | |
| 172 | bColor = colors.lime | |
| 173 | tColor = colors.purple | |
| 174 | else | |
| 175 | bColor = colors.black | |
| 176 | tColor = colors.lime | |
| 177 | end | |
| 178 | writeTo(v.xmin,v.ymin,bColor,tColor,k) | |
| 179 | end | |
| 180 | end | |
| 181 | ||
| 182 | while true do | |
| 183 | drawMain() | |
| 184 | - | screen() |
| 184 | + | pageOne() |
| 185 | checkTouch() | |
| 186 | end |