Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Program Info
- Stargate Theme player
- v 2.0
- Created by: Fredyman_95 - Only stole others work
- Shickla - Developer, buttons, troubleshooting
- TRC - Developer, troubleshooting, tester
- System requirements:
- Tier 3 GPU
- Tier 3 Screen
- Redstone IO
- Music disc change system requiremets:
- EnderIO
- Extra Utilities 2
- Custom Records - not required (only for custom music discs)
- --]]
- --[[ TO-DO-LIST:
- - line numbers: 261; 393
- - Inspection by TRC, ShicKla or any other Lua expert
- - Logos
- - Graphic for playScreen() => line 366
- - Add colors to logos on play screen
- - Add color to mainHeader on mainScreen
- - troubleshooting => fix of errors caused by Fredyman_95
- - troubleshooting Events
- - Set right values to SGUI => after Fredyman_95 prepare new sound file (MineDragonCZ_ request it)
- - Buttons not in screen functions
- --]]
- --
- local term = require("term")
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local unicode = require("unicode")
- local colors = require("colors")
- local sides = require("sides")
- local gpu = component.gpu
- local screen = component.screen
- local rs = component.redstone
- local creators = [[Augur ShicKla, TheRedCreations, Fredyman_95]]
- local version = [[1.2.0]]
- local redColor = 0xAA0000
- local blueColor = 0x00B6FF
- local whiteColor = 0xFFFFFF
- local greyColor = 0xB4B4B4
- -- Declarations --
- local ActiveButtons = {}
- local buttons = {}
- local User = ""
- local mainScreen = function() end
- local ErrorMessage = ""
- local StopPlaying = false
- -- User settings
- local song1 = sides.north
- local song2 = sides.south
- local song3 = sides.top
- local song4 = sides.west
- local stopSong = sides.bottom
- local logoColor = 0xAA0000 --Default 0xAA0000 Red
- local AdminList = {"Example_Name","Fredyman_95","ShicKla","TheRedCreations","MineDragonCZ_","Matousss"}
- -- Changelog
- local changelog = [[
- version 1.2.0
- - New source code (buttons, functions etc...)
- - Loading screen
- - Selection screen
- - Theme screen with stop button
- - Interuption ban for not authorised persons
- - Added system requirements]]
- -- Header + logo
- -- FYI When using [[]] brackets to declare a string it will also include all leading spaces
- local mainHeader = [[
- ████████╗██╗ ██╗███████╗███╗ ███╗███████╗ ██████╗ ██╗ █████╗ ██╗ ██╗███████╗██████╗
- ╚══██╔══╝██║ ██║██╔════╝████╗ ████║██╔════╝ ██╔══██╗██║ ██╔══██╗╚██╗ ██╔╝██╔════╝██╔══██╗
- ██║ ███████║█████╗ ██╔████╔██║█████╗ ██████╔╝██║ ███████║ ╚████╔╝ █████╗ ██████╔╝
- ██║ ██╔══██║██╔══╝ ██║╚██╔╝██║██╔══╝ ██╔═══╝ ██║ ██╔══██║ ╚██╔╝ ██╔══╝ ██╔══██╗
- ██║ ██║ ██║███████╗██║ ╚═╝ ██║███████╗ ██║ ███████╗██║ ██║ ██║ ███████╗██║ ██║
- ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝]]
- local SGlogo = "WIP"
- --[[
- local logoStargateTheme
- -- add later - WIP
- local logoAtlantisTheme
- -- add later - WIP
- local logoUniverseTheme
- -- add later - WIP
- local logoUniverseOpening
- -- add later - WIP
- --]]
- -- necessary stuff -
- gpu.setResolution(104, 43)
- -- screen.setTouchModeInverted(true) -- Turn on touch screen!
- -- term.setCursorBlink(false) -- You do not have to do this
- local mainloop = true
- -- restart of RedstoneIO -> outputs
- rs.setOutput(song1, 0)
- rs.setOutput(song2, 0)
- rs.setOutput(song3, 0)
- rs.setOutput(song4, 0)
- rs.setOutput(stopSong, 0)
- -- System requirements check ---
- if gpu.maxResolution() < 100 then
- io.stderr:write("Tier 3 GPU and Screen Required")
- computer.beep()
- os.sleep(0.2)
- computer.beep()
- os.exit(1)
- end
- if not component.isAvailable("redstone") then
- io.stderr:write("No RedstoneIO Connected.")
- computer.beep()
- os.sleep(0.2)
- computer.beep()
- os.sleep(0.2)
- computer.beep()
- os.exit(1)
- end
- -- Buttons Objects === by Augur ShicKla ====
- local Button = {}
- Button.__index = Button
- function Button.new(xPos, yPos, width, height, label, func, border)
- local self = setmetatable({}, Button)
- if xPos < 1 or xPos > term.window.width then xPos = 1 end
- if yPos < 1 or yPos > term.window.height then yPos = 1 end
- if (width-2) < unicode.len(label) then width = unicode.len(label)+2 end
- if height < 3 then height = 3 end
- if border == nil then
- self.border = true
- else
- self.border = border
- end
- self.xPos = xPos
- self.yPos = yPos
- self.width = width
- self.height = height
- self.label = label
- self.func = func
- self.visible = false
- self.disabled = false
- return self
- end
- function Button.display(self, x, y)
- table.insert(ActiveButtons, 1, self)
- if (self.width-2) < unicode.len(self.label) then self.width = unicode.len(self.label)+2 end
- if x ~= nil and y ~= nil then
- self.xPos = x
- self.yPos = y
- end
- if self.border then
- gpu.fill(self.xPos+1, self.yPos, self.width-2, 1, "─")
- gpu.fill(self.xPos+1, self.yPos+self.height-1, self.width-2, 1, "─")
- gpu.fill(self.xPos, self.yPos+1, 1, self.height-2, "│")
- gpu.fill(self.xPos+self.width-1, self.yPos+1, 1, self.height-2, "│")
- gpu.set(self.xPos, self.yPos, "┌")
- gpu.set(self.xPos+self.width-1, self.yPos, "┐")
- gpu.set(self.xPos, self.yPos+self.height-1, "└")
- gpu.set(self.xPos+self.width-1, self.yPos+self.height-1, "┘")
- end
- gpu.set(self.xPos+1, self.yPos+1, self.label)
- self.visible = true
- end
- function Button.hide(self)
- self.visible = false
- for i,v in ipairs(ActiveButtons) do
- if v == self then table.remove(ActiveButtons, i) end
- end
- if self.border then
- gpu.fill(self.xPos, self.yPos, self.width, self.height, " ")
- else
- gpu.fill(self.xPos+1, self.yPos+1, self.width-2, 1, " ")
- end
- end
- function Button.disable(self, bool)
- if bool == nil then
- self.disabled = false
- else
- self.disabled = bool
- end
- if self.disabled then gpu.setForeground(0x0F0F0F) end
- if self.visible then self:display() end
- gpu.setForeground(0xFFFFFF)
- end
- function Button.touch(self, x, y)
- local wasTouched = false
- if self.visible and not self.disabled then
- if self.border then
- if x >= self.xPos and x <= (self.xPos+self.width-1) and y >= self.yPos and y <= (self.yPos+self.height-1) then wasTouched = true end
- else
- if x >= self.xPos+1 and x <= (self.xPos+self.width-2) and y >= self.yPos+1 and y <= (self.yPos+self.height-2) then wasTouched = true end
- end
- end
- if wasTouched then
- gpu.setBackground(0x878787)
- gpu.set(self.xPos+1, self.yPos+1, self.label)
- gpu.setBackground(0x000000)
- if self.visible then gpu.set(self.xPos+1, self.yPos+1, self.label) end
- self.func()
- end
- return wasTouched
- end
- function Button.forceTouch(self)
- self:touch(self.xPos+1, self.yPos+1)
- end
- -- End of Button --
- local function isAuthorized(name)
- local authorized = false
- if #AdminList == 0 then
- authorized = true
- else
- for _,v in ipairs(AdminList) do
- if string.lower(v) == string.lower(name) then
- authorized = true
- break
- end
- end
- end
- return authorized
- end
- --Events
- local Events = {}
- Events.key_down = event.listen("key_down", function(_, keyboardAddress, chr, code, playerName)
- User = playerName
- end)
- Events.key_up = event.listen("key_up", function(_, keyboardAddress, chr, code, playerName)
- User = ""
- end)
- Events.interrupted = event.listen("interrupted", function()
- if isAuthorized(User) then
- mainloop = false
- end
- -- local shouldExit = false
- -- for i,v in ipairs(AdminList) do
- -- if v == User then
- -- shouldExit = true
- -- end
- -- end
- -- if shouldExit then
- -- MainLoop = false
- -- end
- end)
- Events.touch = event.listen("touch", function(_, screenAddress, x, y, button, playerName)
- local success, msg = xpcall(function()
- if button == 0 then
- for i,v in ipairs(ActiveButtons) do
- if v:touch(x,y) then break end
- end
- end
- end, debug.traceback)
- if not success then
- ErrorMessage = msg
- mainloop = false
- end
- end)
- -- Functions
- local function screenClear()
- buttons.SG1:hide()
- buttons.SGA:hide()
- buttons.SGUT:hide()
- buttons.SGUO:hide()
- buttons.STOP:hide()
- -- You do not have to disable if the button is hidden
- -- buttons.SG1:disable(true)
- -- buttons.SGA:disable(true)
- -- buttons.SGUT:disable(true)
- -- buttons.SGUO:disable(true)
- -- buttons.STOP:disable(true)
- term.clear()
- end
- local function screenHeader(ScreenLogoColor)
- term.setCursor(1,2)
- gpu.setForeground(ScreenLogoColor)
- print(mainHeader)
- gpu.setForeground(whiteColor)
- -- os.sleep(0.1)
- end
- local function clickPulse(timer)
- local num1 = 0
- while (num1 < timer + 0.1) do
- -- click (touch) event
- os.sleep(0.1)
- num1 = num1 + 0.1
- end
- end
- local function dots(posX, posY)
- term.setCursor(posX, posY)
- print(".")
- posX = posX + 1
- clickPulse(0.5)
- term.setCursor(posX, posY)
- print(".")
- posX = posX + 1
- clickPulse(0.5)
- term.setCursor(posX, posY)
- print(".")
- clickPulse(0.5)
- posX = posX - 2
- term.setCursor(posX, posY)
- print(" ")
- clickPulse(0.5)
- end
- local function removeDisc(pause4)
- rs.setOutput(stopSong, 15)
- os.sleep(pause4)
- rs.setOutput(stopSong, 0)
- end
- local function jukebox(sideDisc, pause, pause2)
- removeDisc(0.5)
- os.sleep(pause)
- rs.setOutput(sideDisc, 15)
- os.sleep(pause2)
- rs.setOutput(sideDisc, 0)
- end
- -- Screens
- local function loadingScreen(bootTime, pause3)
- screenClear()
- screenHeader(logoColor)
- computer.beep()
- -- term.setCursor(45, 8) -- Old
- -- os.sleep(0.5) -- Why?
- -- print("Version:") -- Old
- gpu.set(45, 8, "Version:") -- New
- -- term.setCursor(54, 8) -- Old
- -- print(version)
- gpu.set(54, 8, version) -- New
- -- term.setCursor(15, 2) -- Old
- -- os.sleep(1) -- Why?
- -- print("Created by:") -- Old
- gpu.set(2, 9, "Created by:") -- New
- -- term.setCursor(16, 2) -- Old
- -- os.sleep(0.5) -- Why?
- -- print(creators) -- Old
- gpu.set(2, 10, creators) -- New
- os.sleep(pause3) -- Why?
- -- term.setCursor(20,2) -- Old
- term.setCursor(2, 12) -- New
- print("Changelog:")
- print(changelog)
- local num0 = bootTime - pause3 - 2
- os.sleep(num0)
- end
- function mainScreen()
- screenClear()
- screenHeader(logoColor)
- buttons.SG1:display()
- buttons.SGA:display()
- buttons.SGUT:display()
- buttons.SGUO:display()
- buttons.STOP:display()
- -- You do not have to re-enable the button if you never disable it in the first place ;)
- -- buttons.SG1:disable(false)
- -- buttons.SGA:disable(false)
- -- buttons.SGUT:disable(false)
- -- buttons.SGUO:disable(false)
- -- buttons.STOP:disable(false)
- end
- local function playScreen(line1, line2, duration)
- screenClear()
- screenHeader(greyColor)
- term.setCursor(10, 20) -- need to be set to right position
- print("Now is playing:")
- term.setCursor(10, 22) -- need to be set to right position
- print(SGlogo)
- term.setCursor(10, 23) -- need to be set to right position
- print(line1)
- term.setCursor(10, 24) -- need to be set to right position
- print(line2)
- buttons.STOP:display()
- -- buttons.STOP:disable(false)
- -- local num3 = 0
- -- while (num3 < duration + 1) do
- -- dots("10", "10") --need to be set to right position
- -- num3 = num3 + 1
- -- end
- StopPlaying = false
- for i=0,duration,1 do
- dots(10, 10) --need to be set to right position
- os.sleep(1)
- if StopPlaying then break end
- end
- mainScreen()
- end
- -- buttons (xPos, yPos, width, height, label, func, border)
- buttons = {
- SG1 = Button.new(4, 10, 96, 5, "Stargate SG-1 Theme", function()
- jukebox(song1, 1, 0.5)
- playScreen("Stargate SG-1", "THEME" , 59)
- end),
- SGA = Button.new(4, 16, 96, 5, "Stargate Atlantis Theme", function()
- jukebox(song2, 1, 0.5)
- playScreen("Stargate Atlantis", "THEME" , 61)
- end),
- SGUT = Button.new(4, 22, 96, 5, "Stargate Universe Theme", function()
- jukebox(song3, 1, 0.5)
- playScreen("Stargate Universe", "THEME" , 51)
- end),
- SGUO = Button.new(4, 28, 96, 5, "Stargate Universe - Gauntlet", function()
- jukebox(song4, 1, 0.5)
- playScreen("Stargate Universe", "Gauntlet" , 51)
- end),
- STOP = Button.new(4, 37, 96, 5, "STOP", function()
- removeDisc(0.5)
- StopPlaying = true
- -- mainScreen()
- end),
- }
- -- Program
- loadingScreen(10, 1)
- mainScreen()
- while mainloop do
- -- click (touch) event
- os.sleep(0.1)
- end
- -- maybe all must be in loop ... hmmm
- --[[ Notes
- Old buttons API if Fredymna_95 didn't understand Ausgur's buttons => chances that he will understand 1: 10e99999 xD
- 4, 100, 10, 15
- 4, 100, 19, 24
- 4, 100, 28, 33
- 4, 100, 37, 42
- --]]
- term.clear()
- for k,v in pairs(Events) do
- print("Canceling Event Listener: "..k) -- For debug
- event.cancel(v)
- end
- io.stderr:write(ErrorMessage.."\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement