View difference between Paste ID: 0tVF927A and YDEnJ78z
SHOW: | | - or go back to the newest paste.
1
------------------------------------------------------------
2
-- Name: RCMaster
3-
-- version: 1.1.3
3+
-- version: 1.1.4
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-
invColor = colors.white
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
141+
ixMin = 1					-- x_min
142-
ixSize = 14
142+
ixSize = 14					-- x_width
143-
ixMax = ixMin + ixSize - 1
143+
ixMax = ixMin + ixSize - 1  -- x_max
144-
iySize = 1
144+
iySize = 1					-- y_height
145
146-
-- i0
146+
-- sets initial inventory button parameters and inserts into global list
147-
i0yMin = 1
147+
function initInventoryButton(button)
148-
i0 = window.create(m,ixMin,i0yMin,ixSize,iySize)
148+
  button.setBackgroundColor(invBackgroundColor)
149-
i0.setTextColor(colors.white)
149+
  button.restoreCursor()
150-
i0.restoreCursor()
150+
  button.setTextColor(invTextColor)
151-
i0.write("Inventory:")
151+
  button.setCursorPos(1,1)
152-
table.insert(invButtons, i0)
152+
  for i = 1, ixSize do
153
    button.write(" ")
154
  end
155
  table.insert(invButtons, button)
156
end
157-
i1.setBackgroundColor(invColor)
157+
158-
i1.setTextColor(invTextColor)
158+
-- invLabel
159-
i1.restoreCursor()
159+
invLabelyMin = 1
160-
i1.write("              ")
160+
invLabel = window.create(m,ixMin,invLabelMin,ixSize,iySize)
161-
table.insert(invButtons, i1)
161+
invLabel.setTextColor(colors.white)
162
invLabel.restoreCursor()
163
invLabel.write("Inventory:")
164
165
-- i1
166-
i2.setBackgroundColor(invColor)
166+
167-
i2.setTextColor(invTextColor)
167+
168-
i2.restoreCursor()
168+
initInventoryButton(i1)
169-
i2.write("              ")
169+
170-
table.insert(invButtons, i2)
170+
171
i2 = window.create(m,ixMin,i2yMin,ixSize,iySize)
172
initInventoryButton(i2)
173
-- i3
174
i3yMin = 4
175-
i3.setBackgroundColor(invColor)
175+
176-
i3.setTextColor(invTextColor)
176+
initInventoryButton(i3)
177-
i3.restoreCursor()
177+
178-
i3.write("              ")
178+
179-
table.insert(invButtons, i3)
179+
180
initInventoryButton(i4)
181
-- i5
182
i5yMin = 6
183
i5 = window.create(m,ixMin,i5yMin,ixSize,iySize)
184-
i4.setBackgroundColor(invColor)
184+
initInventoryButton(i5)
185-
i4.setTextColor(invTextColor)
185+
186-
i4.restoreCursor()
186+
187-
i4.write("              ")
187+
188-
table.insert(invButtons, i4)
188+
initInventoryButton(i6)
189
-- i7
190
i7yMin = 8
191
i7 = window.create(m,ixMin,i7yMin,ixSize,iySize)
192
initInventoryButton(i7)
193-
i5.setBackgroundColor(invColor)
193+
194-
i5.setTextColor(invTextColor)
194+
195-
i5.restoreCursor()
195+
196-
i5.write("              ")
196+
initInventoryButton(i8)
197-
table.insert(invButtons, i5)
197+
198
i9yMin = 10
199
i9 = window.create(m,ixMin,i9yMin,ixSize,iySize)
200
initInventoryButton(i9)
201
-- i10
202-
i6.setBackgroundColor(invColor)
202+
203-
i6.setTextColor(invTextColor)
203+
204-
i6.restoreCursor()
204+
initInventoryButton(i10)
205-
i6.write("              ")
205+
206-
table.insert(invButtons, i6)
206+
207
i11 = window.create(m,ixMin,i11yMin,ixSize,iySize)
208
initInventoryButton(i11)
209
-- i12
210
i12yMin = 13
211-
i7.setBackgroundColor(invColor)
211+
212-
i7.setTextColor(invTextColor)
212+
initInventoryButton(i12)
213-
i7.restoreCursor()
213+
214-
i7.write("              ")
214+
215-
table.insert(invButtons, i7)
215+
216
initInventoryButton(i13)
217
-- i14
218
i14yMin = 15
219
i14 = window.create(m,ixMin,i14yMin,ixSize,iySize)
220-
i8.setBackgroundColor(invColor)
220+
initInventoryButton(i14)
221-
i8.setTextColor(invTextColor)
221+
222-
i8.restoreCursor()
222+
223-
i8.write("              ")
223+
224-
table.insert(invButtons, i8)
224+
initInventoryButton(i15)
225
-- i16
226
i16yMin = 17
227
i16 = window.create(m,ixMin,i16yMin,ixSize,iySize)
228
initInventoryButton(i16)
229-
i9.setBackgroundColor(invColor)
229+
230-
i9.setTextColor(invTextColor)
230+
231-
i9.restoreCursor()
231+
232-
i9.write("              ")
232+
233-
table.insert(invButtons, i9)
233+
234
  result = string.sub( name, start+1, -1 )
235
  return result 
236
end
237
238-
i10.setBackgroundColor(invColor)
238+
239-
i10.setTextColor(invTextColor)
239+
240-
i10.restoreCursor()
240+
241-
i10.write("              ")
241+
242-
table.insert(invButtons, i10)
242+
243
    senderID, message, protocol = rednet.receive()
244
    if message == "empty" then
245
      invButtons[i].setCursorPos(1,1)
246
      invButtons[i].write("<empty>")
247-
i11.setBackgroundColor(invColor)
247+
248-
i11.setTextColor(invTextColor)
248+
249-
i11.restoreCursor()
249+
250-
i11.write("              ")
250+
251-
table.insert(invButtons, i11)
251+
252
      
253
    end
254
  end
255
end
256-
i12.setBackgroundColor(invColor)
256+
257-
i12.setTextColor(invTextColor)
257+
258-
i12.restoreCursor()
258+
259-
i12.write("              ")
259+
260-
table.insert(invButtons, i12)
260+
261
  invButtons[index].clear()
262
  invButtons[index].redraw()
263
  invButtons[index].restoreCursor()
264
  invButtons[index].setCursorPos(1,1)
265-
i13.setBackgroundColor(invColor)
265+
266-
i13.setTextColor(invTextColor)
266+
267-
i13.restoreCursor()
267+
268-
i13.write("              ")
268+
269-
table.insert(invButtons, i13)
269+
270
  invButtons[index].write(output)
271
end
272
273
274-
i14.setBackgroundColor(invColor)
274+
275-
i14.setTextColor(invTextColor)
275+
276-
i14.restoreCursor()
276+
277-
i14.write("              ")
277+
278-
table.insert(invButtons, i14)
278+
279
  rednet.open("right")
280
  initInventory()
281
282
  event, side, xpos, ypos = os.pullEvent("monitor_touch")
283-
i15.setBackgroundColor(invColor)
283+
284-
i15.setTextColor(invTextColor)
284+
285-
i15.restoreCursor()
285+
286-
i15.write("              ")
286+
287-
table.insert(invButtons, i15)
287+
288
    rednet.broadcast("forward")
289
290
  elseif ( xpos >= bxMin and xpos <= bxMax and
291
           ypos >= byMin and ypos <= byMax )then
292-
i16.setBackgroundColor(invColor)
292+
293-
i16.setTextColor(invTextColor)
293+
294-
i16.restoreCursor()
294+
295-
i16.write("              ")
295+
296-
table.insert(invButtons, i16)
296+
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