View difference between Paste ID: A6JSDqGL and JaZFcx0T
SHOW: | | - or go back to the newest paste.
1
dial = peripheral.wrap("ep_dialling_device_2")
2
monitor = peripheral.wrap("monitor_1")
3
controller = peripheral.wrap("ep_controller_1")
4
portalActive = false
5
locationCount = 0
6
7
function update()
8
  portalActive = controller.isPortalActive()
9
  locationCount = dial.getStoredCount()
10
end
11
12
function drawScreen()
13
  if portalActive then
14
    monitor.setBackgroundColor(colors.green)
15
    monitor.clear()
16
    monW, monH = monitor.getSize()
17-
    monitor.setCursorPos(monW / 2 - string.len("Terminate") / 2, monH / 2)
17+
    monitor.setCursorPos(monW / 2 - string.len("Closing in...5") / 2, monH / 2)
18-
    monitor.write("Terminate")
18+
    i = 5
19
    while i > 0 do
20
	monitor.clear()
21
	monitor.setCursorPos(monW / 2 - string.len("Closing in...5") / 2, monH / 2)
22
    	monitor.write("Closing in..."..i)
23
	i = i - 1
24
	sleep(1)
25
    end
26
	dial.terminate()
27
	portalActive = false
28
	drawScreen()
29
  else
30
    monitor.setBackgroundColor(colors.black) 
31
    monitor.clear()
32
33
    if (locationCount - 1 > 0) then
34
          for i = 1, locationCount do
35
            monitor.setCursorPos(1, i)
36
        
37
            if (i % 2 == 0) then
38
                  monitor.setBackgroundColor(colors.gray)
39
            else
40
                  monitor.setBackgroundColor(colors.lightGray)
41
            end
42
  
43
            name = dial.getStoredName(i - 1)
44
            monW, monH = monitor.getSize()
45
        
46
            monitor.write(name)  
47
            k = string.len(name)
48
        
49
            while (k < monW) do
50
                  monitor.write(" ")
51
                  k = k + 1
52
            end
53
        
54
          end
55
    else
56
          monitor.setCursorPos(1, 1)
57
          monitor.write("No Entries")
58
    end
59
  end
60
end
61
62
function handleInput()
63
  event, side, posX, posY = os.pullEvent("monitor_touch")
64
65
  if portalActive then
66
    dial.terminate()
67
  else
68
    if (posY <= locationCount) then
69
          dial.dialStored(posY - 1)
70
    end
71
  end
72
end
73
74
while true do
75
  update()
76
  drawScreen()
77
  handleInput()
78
end