Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Made By HDR - @MartinRefseth #--
- --# Version 2.1 #--
- --# Thanks to Lyqyd for his Button API http://www.computercraft.info/forums2/index.php?/topic/14784-touchpoint-api/ #--
- os.loadAPI("touchpoint")
- for a,b in pairs(rs.getSides()) do
- if peripheral.getType(b) == 'monitor' then
- mon = peripheral.wrap(b)
- t = touchpoint.new(b)
- break
- end
- end
- --# Functions
- function play()
- peripheral.find("drive", disk.stopAudio)
- peripheral.find( "drive", function( name )
- if disk.hasAudio( name ) and disk.getAudioTitle( name ) == title then
- print("Now Playing"," ",( title) )
- disk.playAudio( name )
- end
- end )
- end
- function Thir()
- t:flash("13")
- title = "C418 - 13"
- play()
- end
- function Cat()
- t:flash("Cat")
- title = "C418 - cat"
- play()
- end
- function Blocks()
- t:flash("Blocks")
- title = "C418 - blocks"
- play()
- end
- function Chirp()
- t:flash("Chirp")
- title = "C418 - chirp"
- play()
- end
- function Far()
- t:flash("Far")
- title = "C418 - far"
- play()
- end
- function Mall()
- t:flash("Mall")
- title = "C418 - mall"
- play()
- end
- function Mellohi()
- t:flash("Mellohi")
- title = "C418 - mellohi"
- play()
- end
- function Stal()
- t:flash("Stal")
- title = "C418 - stal"
- play()
- end
- function Strad()
- t:flash("Strad")
- title = "C418 - strad"
- play()
- end
- function Ward()
- t:flash("Ward")
- title = "C418 - ward"
- play()
- end
- function Elev()
- t:flash("11")
- title = "C418 - 11"
- play()
- end
- function Wait()
- t:flash("Wait")
- title = "C418 - wait"
- play()
- end
- function Question()
- t:flash("???")
- title = "corruption"
- play()
- end
- function GaiaOne()
- t:flash("Gaia 1")
- title = "botania:gaia1"
- play()
- end
- function GaiaTwo()
- t:flash("Gaia 2")
- title = "botania:gaia2"
- play()
- end
- function Roop()
- t:flash("R-Loop")
- title = "portalgun:records.radioloop"
- play()
- end
- function Slive()
- t:flash("S-Alive")
- title = "portalgun:records.stillalive"
- play()
- end
- function WYG()
- t:flash("WYG")
- title = "portalgun:records.wantyougone"
- play()
- end
- function WDR()
- t:flash("Wanderer")
- title = "wanderer"
- play()
- end
- --#Stops All Music
- function Stop()
- t:flash("Stop")
- print("Stopping Disk")
- peripheral.find("drive", disk.stopAudio)
- end
- function Reboot()
- t:flash("Reboot")
- print("Rebooting")
- peripheral.find("drive", disk.stopAudio)
- mon.clear()
- os.reboot()
- end
- -- A list of all possible songs
- local Songs = {
- Thir, Cat, Blocks, Chirp, Far, Mall, Mellohi, Stal, Strad, Ward,
- Elev, Wait, Question, GaiaOne, GaiaTwo, Roop, Slive, WYG, Wander
- }
- function Random()
- t:flash("Random")
- peripheral.find("drive", disk.stopAudio)
- local maxSongs = #Songs -- the "#" gets the length of the list
- local randomNumber = math.random( maxSongs )
- Songs[randomNumber]() -- call the choosen song directly out of the list
- end
- --#OverWrites Part Of Touchpoint API#--
- t.draw = function(self)
- local old = term.redirect(self.mon)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- term.clear()
- term.setCursorPos(20,1)
- term.setTextColor(colors.orange)
- term.write("HDR's Music System 2.1")
- for name, buttonData in pairs(self.buttonList) do
- if buttonData.active then
- term.setBackgroundColor(buttonData.activeColor)
- term.setTextColor(buttonData.activeText)
- else
- term.setBackgroundColor(buttonData.inactiveColor)
- term.setTextColor(buttonData.inactiveText)
- end
- for i = buttonData.yMin, buttonData.yMax do
- term.setCursorPos(buttonData.xMin, i)
- term.write(buttonData.label[i - buttonData.yMin + 1])
- end
- end
- if old then
- term.redirect(old)
- else
- term.restore()
- end
- end
- add = function(self, name, func, xMin, yMin, xMax, yMax, inactiveColor, activeColor, inactiveText, activeText)
- local label, name = setupLabel(xMax - xMin + 1, yMin, yMax, name)
- if self.buttonList[name] then error("button already exists", 2) end
- local x, y = self.mon.getSize()
- if xMin < 1 or yMin < 1 or xMax > x or yMax > y then error("button out of bounds", 2) end
- self.buttonList[name] = {
- func = func,
- xMin = xMin,
- yMin = yMin,
- xMax = xMax,
- yMax = yMax,
- active = false,
- inactiveColor = inactiveColor or colors.red,
- activeColor = activeColor or colors.lime,
- inactiveText = inactiveText or colors.white,
- activeText = activeText or colors.white,
- label = label,
- }
- for i = xMin, xMax do
- for j = yMin, yMax do
- if self.clickMap[i][j] ~= nil then
- --undo changes
- for k = xMin, xMax do
- for l = yMin, yMax do
- if self.clickMap[k][l] == name then
- self.clickMap[k][l] = nil
- end
- end
- end
- self.buttonList[name] = nil
- error("overlapping button", 2)
- end
- self.clickMap[i][j] = name
- end
- end
- end
- remove = function(self, name)
- if self.buttonList[name] then
- local button = self.buttonList[name]
- for i = button.xMin, button.xMax do
- for j = button.yMin, button.yMax do
- self.clickMap[i][j] = nil
- end
- end
- self.buttonList[name] = nil
- end
- end
- run = function(self)
- while true do
- self:draw()
- local event = {self:handleEvents(os.pullEvent(self.side == "term" and "mouse_click" or "monitor_touch"))}
- if event[1] == "button_click" then
- self.buttonList[event[2]].func()
- end
- end
- end
- handleEvents = function(self, ...)
- local event = {...}
- if #event == 0 then event = {os.pullEvent()} end
- if (self.side == "term" and event[1] == "mouse_click") or (self.side ~= "term" and event[1] == "monitor_touch" and event[2] == self.side) then
- local clicked = self.clickMap[event[3]][event[4]]
- if clicked and self.buttonList[clicked] then
- return "button_click", clicked
- end
- end
- return unpack(event)
- end
- toggleButton = function(self, name, noDraw)
- self.buttonList[name].active = not self.buttonList[name].active
- if not noDraw then self:draw() end
- end
- flash = function(self, name, duration)
- self:toggleButton(name)
- sleep(tonumber(duration) or 0.15)
- self:toggleButton(name)
- end
- rename = function(self, name, newName)
- self.buttonList[name].label, newName = setupLabel(self.buttonList[name].xMax - self.buttonList[name].xMin + 1, self.buttonList[name].yMin, self.buttonList[name].yMax, newName)
- if not self.buttonList[name] then error("no such button", 2) end
- if name ~= newName then
- self.buttonList[newName] = self.buttonList[name]
- self.buttonList[name] = nil
- for i = self.buttonList[newName].xMin, self.buttonList[newName].xMax do
- for j = self.buttonList[newName].yMin, self.buttonList[newName].yMax do
- self.clickMap[i][j] = newName
- end
- end
- end
- self:draw()
- end
- --# Buttons in the following format "Name-Function-X1-Y1-X2-Y2-ButtonColor1-ButtonColor2-TextColor1-TextColor2"
- t:add("13", Thir, 2,3,12,5, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Cat", Cat, 14,3,24,5, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Blocks", Blocks, 26,3,36,5, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Chirp", Chirp, 38,3,48,5, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Far", Far, 50,3,60,5, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Mall", Mall, 2,7,12,9, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Mellohi", Mellohi, 14,7,24,9, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Stal", Stal, 26,7,36,9, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Strad", Strad, 38,7,48,9, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Ward", Ward, 50,7,60,9, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("11", Elev, 2,11,12,13, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Wait", Wait, 14,11,24,13, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("???", Question, 26,11,36,13, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Gaia 1", GaiaOne, 38,11,48,13, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Gaia 2", GaiaTwo, 50,11,60,13, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("R-Loop", Roop, 8,15,18,17, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("S-Alive", Slive, 20,15,30,17, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("WYG", WYG, 32,15,42,17, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Wanderer", WDR, 44,15,54,17, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Stop", Stop, 26,19,36,19, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Reboot", Reboot, 38,19,48,19, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:add("Random", Random, 14,19,24,19, colors.cyan, colors.lime, colors.orange, colors.orange)
- t:run()
Advertisement
Add Comment
Please, Sign In to add comment