Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local diskSto = peripheral.wrap("top")
- local diskDrive = peripheral.wrap("left")
- local mot = peripheral.wrap("right")
- local motw, moth = mot.getSize() -- monitor width & heigh
- local zoom =2
- local nowEvent = "all"
- local topSlot = 0
- -- local topBar = window.create(mot,1,1,motw,1)
- -- local winMain = window.create(mot,1,2,motw-2,moth-1)
- diskSto.pullItems(peripheral.getName(diskDrive),1)
- local res = diskSto.list()
- local diskSize = table.getn(diskSto.list())
- local musicList = {}
- local nowSlot = nil
- local diskDriveName = peripheral.getName(diskDrive)
- -- get all music
- for i=1,diskSize,1 do
- diskSto.pushItems(diskDriveName,i)
- table.insert(musicList,diskDrive.getAudioTitle())
- print(diskDrive.getAudioTitle())
- diskSto.pullItems(diskDriveName,1)
- end
- local function mainloop()
- while 1 do
- if(nowEvent == "all") then
- nowEvent = nil
- mot.clear()
- mot.setTextScale(1)
- mot.setCursorPos(1,1)
- mot.write("now :")
- mot.setTextColor(colors.red)
- mot.write(diskDrive.getAudioTitle())
- mot.setCursorPos(1,2)
- mot.setTextColor(colors.white)
- -- display
- for i,j in pairs(musicList) do
- -- local y = (i-1)*2 + 1
- if(i > topSlot) then
- local y = (i+1-topSlot)*zoom + 1
- if(y > moth) then
- break
- end
- mot.setCursorPos(1,y)
- mot.write(j)
- end
- end
- end
- os.sleep(3);
- end
- end
- local function clickCatch()
- while 1 do
- local event, side, mx, my = os.pullEvent("monitor_touch")
- if (event ~= nil) then
- -- target
- local chgPageFlag = false
- repeat
- -- page change
- if ( mx < 3) then
- topSlot = topSlot - 1
- chgPageFlag= true
- elseif( mx >(motw - 3)) then
- topSlot = topSlot + 1
- chgPageFlag= true
- end
- if ( chgPageFlag == true) then
- if( topSlot < 0) then
- topSlot = diskSize - 4
- elseif (topSlot > (diskSize - 4)) then
- topSlot = 0
- end
- nowEvent = "all"
- break
- end
- for i=zoom+2,moth,zoom do
- if (my >= i and my < i+zoom) then
- local slot = (i-2)/zoom + topSlot
- if (slot == nil ) then
- nowSlot = slot
- diskSto.pushItems(diskDriveName,nowSlot)
- nowEvent = "all"
- elseif (slot == nowSlot) then
- break
- elseif (slot ~= nowSlot) then
- diskSto.pullItems(diskDriveName,1)
- diskSto.pushItems(diskDriveName,slot)
- nowEvent = "all"
- end
- diskDrive.playAudio()
- break
- end
- end
- until(true)
- end
- end
- end
- parallel.waitForAll(mainloop,clickCatch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement