View difference between Paste ID: kYfqBhLN and KgBQN1et
SHOW: | | - or go back to the newest paste.
1
-- Header
2
function clear()
3
    term.clear()
4
    term.setCursorPos(1, 1)
5
    term.setBackgroundColour(colours.black)
6
    term.setTextColor(colors.white)
7
end
8
function colore(sfumatura) term.setTextColour(sfumatura) end
9
function fineColore() term.setTextColour(colours.white) end
10
function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
11
function fineSfondo() term.setBackgroundColour(colours.black) end
12
13
-- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
14
local function drawPixelInternal(xPos, yPos)
15
    term.setCursorPos(xPos, yPos)
16
    term.write(" ")
17
end
18
local tColourLookup = {}
19
for n = 1, 16 do
20
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
21
end
22
function drawFilledBox(startX, startY, endX, endY, nColour)
23
    if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
24
        "number" or type(endY) ~= "number" or
25
        (nColour ~= nil and type(nColour) ~= "number") then
26
        error("Expected startX, startY, endX, endY, colour", 2)
27
    end
28
29
    startX = math.floor(startX)
30
    startY = math.floor(startY)
31
    endX = math.floor(endX)
32
    endY = math.floor(endY)
33
34
    if nColour then term.setBackgroundColor(nColour) end
35
    if startX == endX and startY == endY then
36
        drawPixelInternal(startX, startY)
37
        return
38
    end
39
40
    local minX = math.min(startX, endX)
41
    if minX == startX then
42
        minY = startY
43
        maxX = endX
44
        maxY = endY
45
    else
46
        minY = endY
47
        maxX = startX
48
        maxY = startY
49
    end
50
51
    for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
52
end
53
54
function errore(error)
55
    while true do
56
        clear()
57
        colore(colours.red)
58
        sfondo(colours.yellow)
59
        print("Errore!")
60
        fineSfondo()
61
        print("")
62
        print("Errore grave: ")
63
        fineColore()
64
        print(error)
65
      	print("")
66
        print("Premere un tasto per riavviare")
67
        event, key = os.pullEvent("key")
68
        os.reboot()
69
    end
70
end
71
72
if peripheral.getType("top") ~= "NAudio" then
73
	errore("Collegare un NAudioSystem sopra al computer, quindi riavviare il computer")
74
end
75
76
currentStation = "In pausa                                     "
77
volume = 0.3
78
n = peripheral.wrap("top")
79
80
while true do
81
    n.setVolume(volume)
82
    -- Disegna la finestra del pannello utente
83
    sfondo(colours.black)
84
	clear()
85
    term.setCursorPos(1, 19)
86
    colore(colors.lime)
87
    term.write(currentStation)
88
    term.setCursorPos(1, 1)
89
    colore(colours.black)
90
    sfondo(colours.yellow)
91
    print("N Media Player                                    ")
92
    sfondo(colors.red)
93
    colore(colors.white)
94
    term.setCursorPos(51, 1)
95
    term.write("X")
96
    term.setCursorPos(1, 2)
97
    sfondo(colours.black)
98
    colore(colours.white)
99
	print("")
100
	print("")
101
    sfondo(colours.purple)
102
    colore(colours.white)
103
    print("Lynnfield Rock Radio      \n")
104
    print("Voice of New Radeon       \n")
105
    print("RGRadio                   \n")
106
    print("Artemis Radio             \n")
107
108
    term.setCursorPos(1, 17)
109
    sfondo(colours.lightBlue)
110
    term.write("Play/Pausa")
111
112
    term.setCursorPos(12, 17)
113
    sfondo(colours.lightBlue)
114
    term.write("-")
115
116
    term.setCursorPos(14, 17)
117
    sfondo(colours.black)
118
    term.write("Vol")
119
120
    term.setCursorPos(18, 17)
121
    sfondo(colours.lightBlue)
122
    term.write("+")
123
124
    sfondo(colours.black)
125
    colore(colours.lime)
126
    term.setCursorPos(25, 17)
127
    term.write("Volume: " .. volume)
128
129
    sfondo(colours.purple)
130
    colore(colours.white) 
131
    term.setCursorPos(40, 17)
132
    term.write("URL...")
133
134
	os.startTimer(5)
135
    sfondo(colors.black)
136
    event, key, x, y = os.pullEvent()
137
    if event == "mouse_click" and y == 4 then
138
    	n.play("http://alshain.a-centauri.com:8000/lrr.mp3")
139
        currentStation = "In riproduzione: Lynnfield Rock Radio"
140
    elseif event == "mouse_click" and y == 6 then
141
    	n.play("http://alshain.a-centauri.com:8000/vonr.mp3")
142
        currentStation = "In riproduzione: Voice of New Radeon "
143
    elseif event == "mouse_click" and y == 8 then
144
    	n.play("http://alshain.a-centauri.com:8000/rgradio.mp3")
145
        currentStation = "In riproduzione: RGradio                  "
146
    elseif event == "mouse_click" and y == 10 then
147
    	n.play("http://alshain.a-centauri.com:8000/artemis.mp3")
148
        currentStation = "In riproduzione: Artemis Radio            "
149
    elseif event == "mouse_click" and y == 17 and x < 10 then
150
        n.togglePlay()
151
        currentStation = "In pausa                                  "
152
    elseif event == "mouse_click" and y == 17 and x == 12 then
153
        if volume > 0.1 then
154
            volume = volume - 0.1
155
        else
156
            volume = 0.1
157
        end
158
    elseif event == "mouse_click" and y == 17 and x == 18 then
159
        if volume < 1.0 then
160
            volume = volume + 0.1
161
        else
162
            volume = 1.0
163
        end
164
    elseif event == "mouse_click" and y == 17 and x > 40 and x < 46 then
165
        clear()
166
        print("Inserire l'URL personalizzato: ")
167
        print("Esempio: http://coolradio.com/stream.mp3")
168
        local url = read()
169
        n.play(url)
170
        currentStation = "URL personalizzato"        
171
    elseif event == "mouse_click" and x == 51 and y == 1 then
172
        clear()
173
        break
174
    elseif event == "timer" then
175
		n.sendUpdate()
176
	end
177
end