SHOW:
|
|
- or go back to the newest paste.
| 1 | ------------------------------------------------------------ | |
| 2 | -- Name: RCMaster | |
| 3 | - | -- version: 1.1.4 |
| 3 | + | -- version: 1.1.5 |
| 4 | -- Author: Dustin Rosebery | |
| 5 | -- Description: Program that provides touchscreen turtle | |
| 6 | -- operation including movement, inventory, | |
| 7 | -- placing, and mining. | |
| 8 | -- setup: 4x4 advanced monitors with an advanced computer | |
| 9 | -- on the bottom of the monitors with a wireless | |
| 10 | -- modem on the right side. Also requires an | |
| 11 | -- advanced turtle with RCreceive installed | |
| 12 | -- and a wireless modem on the left side. | |
| 13 | ------------------------------------------------------------ | |
| 14 | ||
| 15 | m = peripheral.wrap("top")
| |
| 16 | modem = peripheral.wrap("right")
| |
| 17 | m.clear() | |
| 18 | buttons = {}
| |
| 19 | ||
| 20 | -------------------------------------------------- | |
| 21 | -- button creation | |
| 22 | -------------------------------------------------- | |
| 23 | ||
| 24 | -- Directional button background color | |
| 25 | dirColor = colors.red | |
| 26 | -- Inventory button background color | |
| 27 | invBackgroundColor = colors.white | |
| 28 | -- Inventory button text color | |
| 29 | invTextColor = colors.black | |
| 30 | --------------------------------- | |
| 31 | --Directional buttons | |
| 32 | --------------------------------- | |
| 33 | ||
| 34 | -- fbut (forward) | |
| 35 | fxMin = 23 | |
| 36 | fxSize = 7 | |
| 37 | fxMax = fxMin + fxSize - 1 | |
| 38 | ||
| 39 | fyMin = 6 | |
| 40 | fySize = 4 | |
| 41 | fyMax = fyMin + fySize - 1 | |
| 42 | ||
| 43 | fbut = window.create(m,fxMin,fyMin,fxSize,fySize) | |
| 44 | fbut.setBackgroundColor(dirColor) | |
| 45 | fbut.restoreCursor() | |
| 46 | fbut.redraw() | |
| 47 | fbut.setCursorPos(1,2) | |
| 48 | fbut.write("forward")
| |
| 49 | ||
| 50 | -- bbut (backwards) | |
| 51 | bxMin = 23 | |
| 52 | bxSize = 7 | |
| 53 | bxMax = bxMin + bxSize - 1 | |
| 54 | ||
| 55 | byMin = 12 | |
| 56 | bySize = 4 | |
| 57 | byMax = byMin + bySize - 1 | |
| 58 | ||
| 59 | bbut = window.create(m,bxMin,byMin,bxSize,bySize) | |
| 60 | bbut.setBackgroundColor(dirColor) | |
| 61 | bbut.redraw() | |
| 62 | bbut.restoreCursor() | |
| 63 | bbut.setCursorPos(1,2) | |
| 64 | bbut.write(" back ")
| |
| 65 | bbut.redraw() | |
| 66 | ||
| 67 | -- lbut (left) | |
| 68 | lxMin = 19 | |
| 69 | lxSize = 7 | |
| 70 | lxMax = lxMin + lxSize - 1 | |
| 71 | ||
| 72 | lyMin = 9 | |
| 73 | lySize = 4 | |
| 74 | lyMax = lyMin + lySize - 1 | |
| 75 | ||
| 76 | lbut = window.create(m,lxMin,lyMin,lxSize,lySize) | |
| 77 | lbut.setBackgroundColor(dirColor) | |
| 78 | lbut.redraw() | |
| 79 | lbut.setCursorPos(1,2) | |
| 80 | lbut.write(" left ")
| |
| 81 | ||
| 82 | -- rbut (right) | |
| 83 | rxMin = 27 | |
| 84 | rxSize = 7 | |
| 85 | rxMax = rxMin + rxSize - 1 | |
| 86 | ||
| 87 | ryMin = 9 | |
| 88 | rySize = 4 | |
| 89 | ryMax = ryMin + rySize - 1 | |
| 90 | ||
| 91 | rbut = window.create(m,rxMin,ryMin,rxSize,rySize) | |
| 92 | rbut.setBackgroundColor(dirColor) | |
| 93 | rbut.redraw() | |
| 94 | rbut.setCursorPos(1,2) | |
| 95 | rbut.write(" right ")
| |
| 96 | ||
| 97 | -- ubut (up) | |
| 98 | uxMin = 36 | |
| 99 | uxSize = 2 | |
| 100 | uxMax = uxMin + uxSize - 1 | |
| 101 | ||
| 102 | uyMin = 7 | |
| 103 | uySize = 3 | |
| 104 | uyMax = uyMin + uySize - 1 | |
| 105 | ||
| 106 | ubut = window.create(m,uxMin,uyMin,uxSize,uySize) | |
| 107 | ubut.setBackgroundColor(dirColor) | |
| 108 | ubut.restoreCursor() | |
| 109 | for i = 1, uySize do | |
| 110 | ubut.setCursorPos(1,i) | |
| 111 | ubut.write(" ")
| |
| 112 | end | |
| 113 | m.setCursorPos(36,6) | |
| 114 | m.write("up")
| |
| 115 | ||
| 116 | -- dbut (down) | |
| 117 | dxMin = 36 | |
| 118 | dxSize = 2 | |
| 119 | dxMax = dxMin + dxSize - 1 | |
| 120 | ||
| 121 | dyMin = 11 | |
| 122 | dySize = 3 | |
| 123 | dyMax = dyMin + dySize - 1 | |
| 124 | ||
| 125 | dbut = window.create(m,dxMin,dyMin,dxSize,dySize) | |
| 126 | dbut.setBackgroundColor(dirColor) | |
| 127 | dbut.restoreCursor() | |
| 128 | for i = 1, dySize do | |
| 129 | dbut.setCursorPos(1,i) | |
| 130 | dbut.write(" ")
| |
| 131 | end | |
| 132 | m.setCursorPos(35,14) | |
| 133 | m.write("down")
| |
| 134 | ||
| 135 | ---------------------------- | |
| 136 | --Inventory Buttons | |
| 137 | ---------------------------- | |
| 138 | ||
| 139 | invButtons = {}
| |
| 140 | ||
| 141 | ixMin = 1 -- x_min | |
| 142 | ixSize = 14 -- x_width | |
| 143 | ixMax = ixMin + ixSize - 1 -- x_max | |
| 144 | iySize = 1 -- y_height | |
| 145 | ||
| 146 | -- sets initial inventory button parameters and inserts into global list | |
| 147 | function initInventoryButton(button) | |
| 148 | button.setBackgroundColor(invBackgroundColor) | |
| 149 | button.restoreCursor() | |
| 150 | button.setTextColor(invTextColor) | |
| 151 | button.setCursorPos(1,1) | |
| 152 | for i = 1, ixSize do | |
| 153 | button.write(" ")
| |
| 154 | end | |
| 155 | table.insert(invButtons, button) | |
| 156 | end | |
| 157 | ||
| 158 | -- invLabel | |
| 159 | invLabelyMin = 1 | |
| 160 | invLabel = window.create(m,ixMin,invLabelMin,ixSize,iySize) | |
| 161 | invLabel.setTextColor(colors.white) | |
| 162 | invLabel.restoreCursor() | |
| 163 | invLabel.write("Inventory:")
| |
| 164 | ||
| 165 | -- i1 | |
| 166 | i1yMin = 2 | |
| 167 | i1 = window.create(m,ixMin,i1yMin,ixSize,iySize) | |
| 168 | initInventoryButton(i1) | |
| 169 | -- i2 | |
| 170 | i2yMin = 3 | |
| 171 | i2 = window.create(m,ixMin,i2yMin,ixSize,iySize) | |
| 172 | initInventoryButton(i2) | |
| 173 | -- i3 | |
| 174 | i3yMin = 4 | |
| 175 | i3 = window.create(m,ixMin,i3yMin,ixSize,iySize) | |
| 176 | initInventoryButton(i3) | |
| 177 | -- i4 | |
| 178 | i4yMin = 5 | |
| 179 | i4 = window.create(m,ixMin,i4yMin,ixSize,iySize) | |
| 180 | initInventoryButton(i4) | |
| 181 | -- i5 | |
| 182 | i5yMin = 6 | |
| 183 | i5 = window.create(m,ixMin,i5yMin,ixSize,iySize) | |
| 184 | initInventoryButton(i5) | |
| 185 | -- i6 | |
| 186 | i6yMin = 7 | |
| 187 | i6 = window.create(m,ixMin,i6yMin,ixSize,iySize) | |
| 188 | initInventoryButton(i6) | |
| 189 | -- i7 | |
| 190 | i7yMin = 8 | |
| 191 | i7 = window.create(m,ixMin,i7yMin,ixSize,iySize) | |
| 192 | initInventoryButton(i7) | |
| 193 | -- i8 | |
| 194 | i8yMin = 9 | |
| 195 | i8 = window.create(m,ixMin,i8yMin,ixSize,iySize) | |
| 196 | initInventoryButton(i8) | |
| 197 | -- i9 | |
| 198 | i9yMin = 10 | |
| 199 | i9 = window.create(m,ixMin,i9yMin,ixSize,iySize) | |
| 200 | initInventoryButton(i9) | |
| 201 | -- i10 | |
| 202 | i10yMin = 11 | |
| 203 | i10 = window.create(m,ixMin,i10yMin,ixSize,iySize) | |
| 204 | initInventoryButton(i10) | |
| 205 | -- i11 | |
| 206 | i11yMin = 12 | |
| 207 | i11 = window.create(m,ixMin,i11yMin,ixSize,iySize) | |
| 208 | initInventoryButton(i11) | |
| 209 | -- i12 | |
| 210 | i12yMin = 13 | |
| 211 | i12 = window.create(m,ixMin,i12yMin,ixSize,iySize) | |
| 212 | initInventoryButton(i12) | |
| 213 | -- i13 | |
| 214 | i13yMin = 14 | |
| 215 | i13 = window.create(m,ixMin,i13yMin,ixSize,iySize) | |
| 216 | initInventoryButton(i13) | |
| 217 | -- i14 | |
| 218 | i14yMin = 15 | |
| 219 | i14 = window.create(m,ixMin,i14yMin,ixSize,iySize) | |
| 220 | initInventoryButton(i14) | |
| 221 | -- i15 | |
| 222 | i15yMin = 16 | |
| 223 | i15 = window.create(m,ixMin,i15yMin,ixSize,iySize) | |
| 224 | initInventoryButton(i15) | |
| 225 | -- i16 | |
| 226 | i16yMin = 17 | |
| 227 | i16 = window.create(m,ixMin,i16yMin,ixSize,iySize) | |
| 228 | initInventoryButton(i16) | |
| 229 | ||
| 230 | ||
| 231 | -- cleans item names by removing modID: | |
| 232 | function split(name) | |
| 233 | start, stop = string.find( name, ":" ) | |
| 234 | result = string.sub( name, start+1, -1 ) | |
| 235 | return result | |
| 236 | end | |
| 237 | ||
| 238 | ||
| 239 | -- initial inventory button display | |
| 240 | function initInventory() | |
| 241 | for i = 1, 16 do | |
| 242 | rednet.broadcast(i) | |
| 243 | senderID, message, protocol = rednet.receive() | |
| 244 | if message == "empty" then | |
| 245 | invButtons[i].restoreCursor() | |
| 246 | invButtons[i].setCursorPos(1,1) | |
| 247 | invButtons[i].write("<empty>")
| |
| 248 | else | |
| 249 | output = split(message) | |
| 250 | invButtons[i].restoreCursor() | |
| 251 | invButtons[i].setCursorPos(1,1) | |
| 252 | - | |
| 252 | + | |
| 253 | end | |
| 254 | end | |
| 255 | end | |
| 256 | ||
| 257 | ||
| 258 | -- updates inventory on inventory button click | |
| 259 | function updateInventory(index) | |
| 260 | senderID, message, protocol = rednet.receive() | |
| 261 | invButtons[index].clear() | |
| 262 | invButtons[index].redraw() | |
| 263 | invButtons[index].restoreCursor() | |
| 264 | invButtons[index].setCursorPos(1,1) | |
| 265 | if not message == "empty" then | |
| 266 | output = split(message) | |
| 267 | else | |
| 268 | output = ("<empty>")
| |
| 269 | end | |
| 270 | invButtons[index].write(output) | |
| 271 | end | |
| 272 | ||
| 273 | ||
| 274 | ---------------------------------------------------------------------- | |
| 275 | -- Input listener | |
| 276 | ---------------------------------------------------------------------- | |
| 277 | while(true) do | |
| 278 | ||
| 279 | rednet.open("right")
| |
| 280 | initInventory() | |
| 281 | ||
| 282 | event, side, xpos, ypos = os.pullEvent("monitor_touch")
| |
| 283 | write(xpos .. ", " .. ypos.."\n") -- show touch location | |
| 284 | ||
| 285 | -- directional control | |
| 286 | if ( xpos >= fxMin and xpos <= fxMax and | |
| 287 | ypos >= fyMin and ypos <= fyMax )then | |
| 288 | rednet.broadcast("forward")
| |
| 289 | ||
| 290 | elseif ( xpos >= bxMin and xpos <= bxMax and | |
| 291 | ypos >= byMin and ypos <= byMax )then | |
| 292 | rednet.broadcast("back")
| |
| 293 | ||
| 294 | elseif ( xpos >= lxMin and xpos <= lxMax and | |
| 295 | ypos >= lyMin and ypos <= lyMax )then | |
| 296 | rednet.broadcast("left")
| |
| 297 | ||
| 298 | elseif ( xpos >= rxMin and xpos <= rxMax and | |
| 299 | ypos >= ryMin and ypos <= ryMax )then | |
| 300 | rednet.broadcast("right")
| |
| 301 | ||
| 302 | elseif ( xpos >= uxMin and xpos <= uxMax and | |
| 303 | ypos >= uyMin and ypos <= uyMax )then | |
| 304 | rednet.broadcast("up")
| |
| 305 | ||
| 306 | elseif ( xpos >= dxMin and xpos <= dxMax and | |
| 307 | ypos >= dyMin and ypos <= dyMax )then | |
| 308 | rednet.broadcast("down")
| |
| 309 | ||
| 310 | -- inventory control | |
| 311 | elseif ( xpos >= ixMin and xpos <= ixMax )then | |
| 312 | ||
| 313 | if ( ypos == i1yMin ) then | |
| 314 | rednet.broadcast(ypos) | |
| 315 | updateInventory(ypos) | |
| 316 | ||
| 317 | elseif( ypos == i2yMin ) then | |
| 318 | rednet.broadcast(ypos) | |
| 319 | updateInventory(ypos) | |
| 320 | ||
| 321 | elseif( ypos == i3yMin ) then | |
| 322 | rednet.broadcast(ypos) | |
| 323 | updateInventory(ypos) | |
| 324 | ||
| 325 | elseif( ypos == i4yMin ) then | |
| 326 | rednet.broadcast(ypos) | |
| 327 | updateInventory(ypos) | |
| 328 | ||
| 329 | elseif( ypos == i5yMin ) then | |
| 330 | rednet.broadcast(ypos) | |
| 331 | updateInventory(ypos) | |
| 332 | ||
| 333 | elseif( ypos == i6yMin ) then | |
| 334 | rednet.broadcast(ypos) | |
| 335 | updateInventory(ypos) | |
| 336 | ||
| 337 | elseif( ypos == i7yMin ) then | |
| 338 | rednet.broadcast(ypos) | |
| 339 | updateInventory(ypos) | |
| 340 | ||
| 341 | elseif( ypos == i8yMin ) then | |
| 342 | rednet.broadcast(ypos) | |
| 343 | updateInventory(ypos) | |
| 344 | ||
| 345 | elseif( ypos == i9yMin ) then | |
| 346 | rednet.broadcast(ypos) | |
| 347 | updateInventory(ypos) | |
| 348 | ||
| 349 | elseif( ypos == i10yMin ) then | |
| 350 | rednet.broadcast(ypos) | |
| 351 | updateInventory(ypos) | |
| 352 | ||
| 353 | elseif( ypos == i11yMin ) then | |
| 354 | rednet.broadcast(ypos) | |
| 355 | updateInventory(ypos) | |
| 356 | ||
| 357 | elseif( ypos == i12yMin ) then | |
| 358 | rednet.broadcast(ypos) | |
| 359 | updateInventory(ypos) | |
| 360 | ||
| 361 | elseif( ypos == i13yMin ) then | |
| 362 | rednet.broadcast(ypos) | |
| 363 | updateInventory(ypos) | |
| 364 | ||
| 365 | elseif( ypos == i14yMin ) then | |
| 366 | rednet.broadcast(ypos) | |
| 367 | updateInventory(ypos) | |
| 368 | ||
| 369 | elseif( ypos == i15yMin ) then | |
| 370 | rednet.broadcast(ypos) | |
| 371 | updateInventory(ypos) | |
| 372 | ||
| 373 | elseif( ypos == i16yMin ) then | |
| 374 | rednet.broadcast(ypos) | |
| 375 | updateInventory(ypos) | |
| 376 | ||
| 377 | end | |
| 378 | end | |
| 379 | end |