[XP] Berans' iPod script v1.15-final

Started by Berans, August 08, 2008, 01:06:21 pm

Previous topic - Next topic

Berans

August 08, 2008, 01:06:21 pm Last Edit: February 21, 2009, 05:52:47 am by shdwlink1993
iPod script
Authors: Berans
Version: 1.15-final
Type: Music Player
Key Term: Misc Add-On




Introduction

I made this script as a response to a request on a different forum, and decided it was my first script decent enough to post up here.
It simply displays a nice "iPod" graphic, and lets you pick songs to play from a list.


Features


  • Relatively easy setup
  • IPod Graphic
  • Allows for as many songs as you wish
  • Allows for author and genre names
  • Allows unlockable songs
  • Currently selected song is remembered, and saved in your save game
  • Unlocked songs saved in save game
  • Entirely Lag-free
  • Map as background
  • Option to have the current BGM change with your selected song
  • iPod menu with some for-fun, customizable options
  • NEW: iPod menu now features a "sort-by" option (title, author or genre). Your selected option is saved with your game



Screenshots



If you do not want to download the demo, save the following 2 images to your computer, and import them into your game as outlined in the script
Spoiler: ShowHide







Demo

New Demo:
iPod Demo v1.00-beta

Note: No new demo for v1.12, just paste the new script in the old demo to test functionality.


Script

The script should be placed somewhere above main, and below Scene_Debug
Spoiler: ShowHide

#==============================================================================
#==============================================================================
#Berans' "iPod" script v1.15-final
#Last edited: 12 August 2008
#
#------------------------------------------------------------------------------
#What's new in v1.15
# -Script now automatically adds any songs you have in your project to the
#  PLAYBACK list. An array in the config module allows you to also add any songs
#  from the RTP
# -Minor bugfix regarding the mute function
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.13
# -Major bugfixes and some code improvement
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.12
# -Further code improvements
# -Changed iPod menu options to include "Sorting"
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.01
# -Minor code cleanups
# -Debugging
# -Added "Back" option in the iPod menu
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.00
# -Added a "menu" feature on the ipod with a few small options
# -Code cleaned up
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v0.99
# -Fixed a few small glitches
# -The game now remembers whether or not you were playing a song upon exiting
#  the iPod, to accomodate BGM_CHANGER better.
# -The game now remembers and saves the BGM_CHANGER option, so it can be changed
#  ingame with a new, easy-to-use script command
#------------------------------------------------------------------------------
#
#will allow you to playback songs from a list using a simple window which looks
#like an ipod
#
#feel free to edit and change any names, provided you have changed them in your
#audio/bgm folder(this would let you have custom names drawn in the menu)
#see further instructions below
#
#Credits: Berans    - Making the script
#         Blizzard  - Lessons on scripting and scripting conventions
#         Sniper308 - Requesting the script
#------------------------------------------------------------------------------
#Features
#------------------------------------------------------------------------------
# -Allows for as many songs as you wish
# -Relatively easy setup
# -IPod Graphic
# -Allows for author and genre names
# -Allows unlockable songs
# -Currently selected song is remembered, and saved in your save game
# -Unlocked songs saved in save game
# -Entirely Lag-free
# -Map as background
# -Option to have the current BGM change with your selected song
# -NEW: BGM_CHANGER option now remembered and saved with new easy-to-use command
# -NEW: iPod menu with a few for-fun options
# -NEW: iPod menu now features a "sort" option, standard sorting now set to song
#  title(sort option is saved in save game)
# -NEW: Automatically sets up any custom songs you have to use in the script
#------------------------------------------------------------------------------
#Compatibility
#------------------------------------------------------------------------------
#Should be compatible with most scripts, including the SDK
#Since this is a beta test, please notify me if something's not working
#
#==============================================================================
#Instructions
#==============================================================================
#
#------------------------------------------------------------------------------
#Setup:
#------------------------------------------------------------------------------
#Songs in your project's "Audio/BGM" folder will automatically be setup to be
#used in the script. If you want to use songs from the RTP that aren't in your
#project's "Audio/BGM" folder, add them in the "PLAYBACK1" array in the Config
#section of the script.
#The names must be spelled exactly as in the RTP's "Audio/BGM" folder, enclosed
#in quotation marks, and separated by a comma.
#example:
#PLAYBACK = ["001-Battle01, "002-Battle02", "003-Battle03"]
#In playback initial, add the number of all the songs you want to have initially
#unlocked, separated by comma. The numbers correspond to a list of songs,
#consisting of your custom songs, arranged alphabetically followed by the RTP
#songs in the order you have specified.
#example:
#you have the custom songs "Song1", "Song2" and "Song3" in your "Audio/BGM" folder
#and have specified "001-Battle01" to be included in the list.
#song 1 will then be "Song1", 2 - "Song2" 3 - "Song3" and 4 "001-Battle01"
#The PLAYBACK_AUTHOR and PLAYBACK_GENRE "hashes" respectively hold information on
#the author and genre, of each song.
#To add an author or genre name, simply add "yoursongnumber => description"
#anywhere in the correct hash. The author's/genre's name must be enclosed in
#quotation marks, and the number and name together, separated by a comma
#If a song number is not in there, the author or
#genre are automatically set to "unkown" for that song
#example:
#PLAYBACK_AUTHOR = {20 => "the author of your 20th song",
#                   1 => "the author of your 1st song", 3 => "another author"}
#the same exact same format goes for genre
#If you want all the songs in your PLAYBACK array to be "unlocked" from the
#start, simply set "unlockables" to "false"
#If you want the "IPod" to change the currently playing BGM for a map when a
#song is selected and played, set bgm_changer to "true"
#
#------------------------------------------------------------------------------
#Required Graphics and instructions:
#------------------------------------------------------------------------------
#For this script to work properly, the following files are needed, and have to
#be placed in the "Graphics/Pictures" folder in your game:
#   -IPod.png
#   -IPod2.png
#you'll also need to import the files within your project and set the correct
#transparancies
#Transparancy for IPod.png must be set to white
#Transparancy for IPod2.png must be set to the darker shade of grey, with the
#semi-transparant color set to the lighter grey
#
#------------------------------------------------------------------------------
#Using the script
#------------------------------------------------------------------------------
#To call the script, within an event use the "script" command
#in the script write "$scene = Scene_Playback.new" (without quotation marks)
#If you want the "ipod" to return to menu upon exit, add (true) after
#Scene_Playback.new. This works well in combination with a common event with an
#item.
#
#To "unlock" a song, ensure its name is in the PLAYBACK array in the
#configuration below, then, use the "script" command in an event, and enter the
#following: "unlock_song(your_song_number)"
#The song number directly corresponds to the position in the PLAYBACK array
#example:
#Your PLAYBACK array is ["yoursong-01", "yoursong-02", "someothersong"]
#and you want to unlock "yoursong-02
#simply write "unlock_song(2)" within your script command
#
#To change the BGM_CHANGER option ingame, use the following code in an event,
#within a "script..." command: "bgm_changer(condition)" (without the quotes)
#replace the word condition with either true or false, depending on what you
#would like the option to be
#
#NOTE:
#Long song/author/genre names may look squashed. For optimal looks, try to keep
#names under 15 characters.
#==============================================================================
#==============================================================================


#==============================================================================
#Begin Configuration
#==============================================================================

module Playback
  UNLOCKABLES = true
  BGM_CHANGER = false
  PLAYBACK1 = [ "001-Battle01", "002-Battle02",   "003-Battle03",
               "004-Battle04",   "005-Boss01",     "006-Boss02",
                 "007-Boss03",   "008-Boss04", "009-LastBoss01",
              "035-Dungeon01",   "063-Slow06",]
  PLAYBACK_INITIAL = [3,8]
 
  PLAYBACK_AUTHOR = {1  => "DragonForce", 2  => "Enterbrain", 3 => "Enterbrain",
                     4  => "Enterbrain" , 5  => "Enterbrain", 6 => "Enterbrain",
                     7  => "Enterbrain" , 8  => "Enterbrain", 9 => "Enterbrain",
                     10 => "Enterbrain" , 12 => "Enterbrain", }
 
  PLAYBACK_GENRE = {1 => "Classic"}
 
#==============================================================================
#End Configuration
#==============================================================================

  PLAYBACK2 = Dir.entries("Audio/BGM")
  PLAYBACK2.delete("..")
  PLAYBACK2.delete(".")
  for i in 0...PLAYBACK2.size
    PLAYBACK2[i] = PLAYBACK2[i].gsub(/[.][A-Za-z0-9._,]+/) {nil}
  end
  PLAYBACK = PLAYBACK2.concat(PLAYBACK1)
  PLAYBACK_UNLOCKED = []
  for i in 0...PLAYBACK.size
    PLAYBACK_UNLOCKED.push nil
  end
  unless PLAYBACK_INITIAL.empty?
    for i in 0...PLAYBACK_INITIAL.size
      PLAYBACK_UNLOCKED[PLAYBACK_INITIAL[i] -1] = PLAYBACK[PLAYBACK_INITIAL[i] -1]
    end
  end
  if !UNLOCKABLES
    for i in 0...PLAYBACK.size
      PLAYBACK_UNLOCKED[i] = PLAYBACK[i]
    end
  end
  unless $game_system == nil
    unless $game_system.bgm_changer == nil
      if $game_system.bgm_changer
        BGM_CHANGER = true
      elsif !$game_system.bgm_changer
        BGM_CHANGER = false
      end
    end
  end
  $playback_list = []
  for i in 0...PLAYBACK_UNLOCKED.size
    if PLAYBACK_UNLOCKED[i] != nil
      $playback_list[i] = [Playback::PLAYBACK_UNLOCKED[i],
                           Playback::PLAYBACK_AUTHOR[i+1] == nil ? "Unkown" :
                           Playback::PLAYBACK_AUTHOR[i+1],
                           Playback::PLAYBACK_GENRE[i+1] == nil ? "Unkown" :
                           Playback::PLAYBACK_GENRE[i+1]]
    end
  end
  $playback_list = $playback_list.compact
end

#==============================================================================
#**Window_Playback
#------------------------------------------------------------------------------
#This window displays the playback screen
#==============================================================================

class Window_Playback < Window_Selectable
 
  attr_accessor  :playback_bgm
 
  def initialize
    super (212,66,216,170)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 4
    @column_max = 4
    self.z -= 100
    self.index = 0
    self.active = true
    #Get the playback bgm to draw the text right
    get_playback_bgm
    refresh
  end
 
  def refresh
    self.contents.clear
    unless $game_system.playback_list.empty?
      if $game_system.playback_list[@playback_bgm] != nil
        bgm = $game_system.playback_list[@playback_bgm][0]
      else
        @check = 0
        #check all possible songs for an unlocked entry
        loop do
          @check += 1
          @playback_bgm += 1
          @playback_bgm %= $game_system.playback_list.size
          if $game_system.playback_list[@playback_bgm] != nil
            bgm = $game_system.playback_list[@playback_bgm][0]
            break
          end
        end
      end
    else
      bgm = "No Songs Unlocked"
      $nosongs = true
    end
    if !$nosongs
      text = (@playback_bgm + 1).to_s + ": " + bgm
      if $game_system.playback_list[@playback_bgm] != nil
        text2 = "Author: " + $game_system.playback_list[@playback_bgm][1]
      else
        text2 = "Author: Unkown"
      end
      if $game_system.playback_list[@playback_bgm] != nil
        text3 = "Genre: " + $game_system.playback_list[@playback_bgm][2]
      else
        text3 = "Genre: Unkown"
      end
    else
      text = bgm
      text2 = ""
      text3 = ""
    end
    self.contents.draw_text(0,8,self.contents.width,32,text,1)
    self.contents.draw_text(0,40,self.contents.width,32,text2,1)
    self.contents.draw_text(0,72,self.contents.width,32,text3,1)
  end
 
  def update_cursor_rect
    self.cursor_rect.empty
  end
 
  def get_playback_bgm
    if $game_system.playback_bgm == nil
      @playback_bgm = 0
      $game_system.playback_bgm = @playback_bgm
    else
      @playback_bgm = $game_system.playback_bgm
    end
  end
end


#==============================================================================
#**Scene_Playback
#------------------------------------------------------------------------------
#This class handles processing for the playback window
#==============================================================================

class Scene_Playback
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_reader :mute
 
  def initialize(frommenu = false)
    @animation_flag = false
    @mute = false
    @temp_hash = {}
    @temp_hash2 = {}
    @temp_array = []
    if $game_system.playback_list.empty?
    $game_system.playback_list = $playback_list
    end
    if $game_system.sort_option == nil
      sort(0)
      $game_system.sort_option = 0
    else
      sort($game_system.sort_option)
    end
    for i in 0...$game_system.unlocked_songs.size
      unlock_song($game_system.unlocked_songs[i]+1)
    end
    if $game_temp.mute
      @mute = true
    end
    if $game_system.bgm_changer == nil
      $game_system.bgm_changer = Playback::BGM_CHANGER
    end
    if $game_temp.playing == nil
      @playing = false
    else
      @playing = $game_temp.playing
    end
    @frommenu = frommenu
  end
 
  def main
    #ensure map/menu bgm is kept
    $game_system.bgm_memorize
    @spriteset = Spriteset_Map.new
    @spriteset2 = Spriteset_Ipod.new
    @dummy_window = Ipod_Dummy.new
    @playback_window = Window_Playback.new
    @imenu_window = Window_iMenu.new
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @playback_window.dispose
    @spriteset.dispose
    @spriteset2.dispose
    $nosongs = false
    @dummy_window.dispose
    @imenu_window.dispose
  end
 
  def update
    if @playback_window.active
      update_playback
    end
    if @imenu_window.active
      update_imenu
    end
  end
 
  def update_playback
    if @playback_window.index != @playback_window_check
      @dummy_window.refresh(@playback_window.index)
    end
    if Input.repeat?(Input::RIGHT) && @playback_window.index == 3
      $game_system.se_play($data_system.cursor_se)
      @playback_window.index = 0
      return
    end
    if Input.repeat?(Input::LEFT) && @playback_window.index == 0
      $game_system.se_play($data_system.cursor_se)
      @playback_window.index = 3
      return
    end
    if Input.trigger?(Input::C)
      #Menu
      if @playback_window.index == 0
        $game_system.se_play($data_system.decision_se)
        @playback_window.active = false
        @playback_window.index = -1
        @imenu_window.visible = true
        @imenu_window.active = true
        @imenu_window.index = 0
        @imenu_wait = true
        return
      end
      unless $nosongs
        case @playback_window.index
        #Select next
        when 1
          $game_system.se_play($data_system.decision_se)
          #select the next BGM
          #the loop allows it to skip "nil" entries to aid in unlockables
          loop do
            @playback_window.playback_bgm += 1
            @playback_window.playback_bgm %= $game_system.playback_list.size
            $game_system.playback_bgm = @playback_window.playback_bgm
            if $game_system.playback_list[$game_system.playback_bgm] != nil
              break
            end
          end
          @playback_window.refresh
          #change the currently playing song if one was already playing
          if @playing
            bgm = RPG::AudioFile.new($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)
            $game_system.bgm_play(bgm)
            if @mute != false
              @mute = false
              @imenu_window.refresh
            end
          end
        #Play/Stop
        when 2
          if @init
            @init = false
          end
          if $game_system.playback_bgm != nil
            if !@playing
              $game_system.se_play($data_system.decision_se)
              #create BGM for playing
              bgm = RPG::AudioFile.new($game_system.playback_list[
                                       $game_system.playback_bgm][0],
                                       100,100)
              $game_system.bgm_play(bgm)
              if $game_system.bgm_changer
                $game_system.bgm_memorize
              end
            else
              $game_system.se_play($data_system.cancel_se)
              $game_system.bgm_play(nil)
            end
            if @mute != false
              @mute = false
              @imenu_window.refresh
            end
          end
          case @playing
          when true
            @playing = false
          when false
            @playing = true
          end
        #Select Previous
        when 3
          $game_system.se_play($data_system.decision_se)
          #select the previous BGM
          #the loop allows it to skip "nil" entries to aid in unlockables
          loop do
            @playback_window.playback_bgm += $game_system.playback_list.size - 1
            @playback_window.playback_bgm %= $game_system.playback_list.size
            $game_system.playback_bgm = @playback_window.playback_bgm
            if $game_system.playback_list[$game_system.playback_bgm] != nil
              break
            end
          end
          @playback_window.refresh
          #change the currently playing song if one was already playing
          if @playing
            bgm = RPG::AudioFile.new($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)
            $game_system.bgm_play(bgm)
            if @mute != false
              @mute = false
              @imenu_window.refresh
            end
          end
        end
      else
        $game_system.se_play($data_system.buzzer_se)
      end
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      #get the correct @playing setting for when the iPod is restarted
      if $game_system.bgm_changer
        $game_temp.playing = @playing
      else
        @playing = false
      end
      if !@frommenu
        #restore the map/menu bgm
        if !$game_system.bgm_changer
          if @mute
            $game_map.map.bgm.volume = 0
          else
            $game_map.map.bgm.volume = 100
          end
          $game_system.bgm_play($game_map.map.bgm)
        end
        $scene = Scene_Map.new
        if !@playing && $game_system.bgm_changer
          if $game_system.playing_bgm == $game_map.map.bgm
            return
          end
          $game_system.bgm_play(nil)
        end
      else
        #restore the map/menu bgm
        if !$game_system.bgm_changer
          if @mute
            $game_map.map.bgm.volume = 0
          else
            $game_map.map.bgm.volume = 100
          end
          $game_system.bgm_play($game_map.map.bgm)
        end
        #change this to go to a different menu upon exit
        $scene = Scene_Menu.new
        if !@playing && $game_system.bgm_changer
          if $game_system.playing_bgm == $game_map.map.bgm
            return
          end
          $game_system.bgm_play(nil)
        end
      end
    end
    $game_temp.playing = @playing
    @playback_window_check = @playback_window.index
    @playback_window.update
  end
 
  def update_imenu
    if @imenu_wait
      @imenu_wait = false
      return
    end
    if @imenu_window.index != @imenu_window_check
      @dummy_window.refresh(@imenu_window.index)
    end
    if Input.repeat?(Input::RIGHT)
      if @imenu_window.index == 3
        $game_system.se_play($data_system.cursor_se)
        @imenu_window.index = 0
        return
      end
    end
    if Input.repeat?(Input::LEFT)
      if @imenu_window.index == 0
        $game_system.se_play($data_system.cursor_se)
        @imenu_window.index = 3
        return
      end
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @imenu_window.active = false
      @imenu_window.visible = false
      @playback_window.index = @imenu_window.index
      @imenu_window.index = -1
      @playback_window.active = true
    end
    if Input.trigger?(Input::C)
      case @imenu_window.index
      when 0
        $game_system.se_play($data_system.decision_se)
        if !@mute
          unless $game_system.playing_bgm == nil
            $game_system.playing_bgm.volume = 0
            $game_system.bgm_play($game_system.playing_bgm)
          end
          @mute = true
        elsif @mute
          unless $game_system.playing_bgm == nil
            $game_system.playing_bgm.volume = 100
            $game_system.bgm_play($game_system.playing_bgm)
          end
          @mute = false
        end
        @imenu_window.refresh
        $game_temp.mute = @mute
      when 1
        $game_system.se_play($data_system.cancel_se)
        if $game_system.bgm_changer
            $game_temp.playing = @playing
          else
            @playing = false
          end
          #restore the map/menu bgm
          if !$game_system.bgm_changer
              $game_system.bgm_play($game_map.map.bgm)
            end
          #change menu option 2 here
          $scene = Scene_Map.new
          if !@playing && $game_system.bgm_changer
            if $game_system.playing_bgm == $game_map.map.bgm
              return
            end
            $game_system.bgm_play(nil)
          end
      when 2
        if $nosongs
          $game_system.se_play($data_system.buzzer_se)
          return
        else
          $game_system.se_play($data_system.decision_se)
          $game_system.sort_option += 1
          $game_system.sort_option %= 3
          sort($game_system.sort_option)
          @imenu_window.refresh
          @playback_window.refresh
        end
      when 3
        $game_system.se_play($data_system.cancel_se)
        @imenu_window.active = false
        @imenu_window.visible = false
        @playback_window.index = @imenu_window.index
        @imenu_window.index = -1
        @playback_window.active = true
      end
    end
    @imenu_window.update
  end
end


#==============================================================================
#*unlock_song
#------------------------------------------------------------------------------
#Allows you to unlock songs for the playback window
#==============================================================================
def unlock_song(number)
  if $game_system.playback_list.empty?
    $game_system.playback_list = $playback_list
  end
  unless $game_system.playback_list.include?([
    Playback::PLAYBACK[number - 1], Playback::PLAYBACK_AUTHOR[number] || "Unkown",
    Playback::PLAYBACK_GENRE[number] || "Unkown"])
    for i in 0...Playback::PLAYBACK.size
      if $game_system.playback_list[i] == nil
        $game_system.playback_list[i] = [nil,nil,nil]
        $game_system.playback_list[i][0] = Playback::PLAYBACK[number - 1]
        $game_system.playback_list[i][1] =
        (Playback::PLAYBACK_AUTHOR[number] == nil ?
        "Unkown" : Playback::PLAYBACK_AUTHOR[number])
        $game_system.playback_list[i][2] =
        (Playback::PLAYBACK_GENRE[number] == nil ?
        "Unkown" : Playback::PLAYBACK_GENRE[number])
        $game_system.unlocked_songs.push(number - 1)
        return
      end
    end
  end
end


#==============================================================================
#*bgm_changer
#------------------------------------------------------------------------------
#Changes the BGM_CHANGER option for ingame use
#==============================================================================
def bgm_changer(condition)
  if !condition
    if $game_system.bgm_changer
      $game_system.bgm_changer = condition
    end
  else
    $game_system.bgm_changer = condition
  end
end


#==============================================================================
#**Spriteset_Ipod
#------------------------------------------------------------------------------
#Creates an "Ipod" Image at the centre of the screen
#==============================================================================
class Spriteset_Ipod
  def initialize
    @viewport = Viewport.new(208,53,224,374)
    @viewport.z = 5000
    @sprite = Sprite.new(@viewport)
    @sprite2 = Sprite.new
    @sprite2.bitmap = Bitmap.new(224,374)
    @ipod = RPG::Cache.picture('IPod.png')
    @sprite.bitmap = @ipod
  end

  def dispose
    @viewport.dispose
    @sprite.dispose
    @sprite2.dispose
  end
end


#==============================================================================
#**Ipod_Dummy
#------------------------------------------------------------------------------
#Creates the selection effect over the ipod image
#==============================================================================
class Ipod_Dummy < Window_Base
 
  def initialize
    super(208,53,224,374)
    self.contents = Bitmap.new(width - 32,height - 32)
    self.opacity = 0
    self.z = 9999
    refresh
  end
 
  def refresh(index = 0)
    self.contents.clear
    case index
    when 0
      rect = Rect.new(0,52,98,52)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(47,179,@bitmap,rect)
    when 1
      rect = Rect.new(52,104,52,98)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(113,199,@bitmap,rect)
    when 2
      rect = Rect.new(0,0,98,52)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(47,266,@bitmap,rect)
    when 3
      rect = Rect.new(0,104,52,98)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(26,199,@bitmap,rect)
    end
  end
end


#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles data surrounding the system. Backround music, etc.
#  is managed here as well. Refer to "$game_system" for the instance of
#  this class.
#==============================================================================
class Game_System
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_accessor :playback_bgm
  attr_accessor :unlocked_songs
  attr_accessor :bgm_changer
  attr_accessor :sort_option
  attr_accessor :playback_list
 
  alias initialize_ipod_later initialize
  def initialize
    initialize_ipod_later
    @unlocked_songs = []
    @playback_list = []
  end

end

#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
#  Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_accessor :playing
  attr_accessor :mute
 
end


#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_reader :map
 
end


#==============================================================================
# ** Window_iMenu
#------------------------------------------------------------------------------
#  This class creates a dummy selectable menu to use with the iPod script
#==============================================================================
class Window_iMenu < Window_Selectable
  def initialize
    super(212,66,216,170)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.index = -1
    self.visible = false
    self.active = false
    self.z += 10
    @item_max = 4
    @column_max = 4
    refresh
  end
 
  def refresh
    self.contents.clear
    if $scene.mute
      self.contents.draw_text(0,-5,self.contents.width,32,"Unmute",1)
    else
      self.contents.draw_text(0,-5,self.contents.width,32,"Mute",1)
    end
    #change the bit in quotes below to reflect where your iPod menu's 2nd option
    #exits to i.e. "Exit to Main Menu" or "Exit to Equipment Screen"
    #be wary of long names, as they may look squashed
    self.contents.draw_text(0,27,self.contents.width,32,"Exit to Map",1)
    case $game_system.sort_option
    when 0
      sort = "Title"
    when 1
      sort = "Author"
    when 2
      sort = "Genre"
    end
    self.contents.draw_text(0,59,self.contents.width,32,"Sorted by: " + sort,1)
    self.contents.draw_text(0,91,self.contents.width,32,"Back",1)
  end
 
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      y = -5 + 32*@index
      cursor_rect.set(5,y,self.contents.width - 10,32)
    end
  end
 
end


#==============================================================================
#*Sort
#------------------------------------------------------------------------------
#Method to sort the unlocked songs array for the iPod script
#==============================================================================

def sort(choice)
  $game_system.playback_list =
  $game_system.playback_list.sort {|a, b| a[choice] <=> b[choice]}
  return $game_system.playback_list
end



Instructions

Instructions in the script


Compatibility

Warning, WILL corrupt old savegames.
Otherwise, should be compatible with just about anything, including the SDK


Credits and Thanks


  • Berans - Creating the script
  • Blizzard - Learnt a lot from his scripts in terms of general knowledge and scripting conventions
  • Sniper308 - For requesting the script and suggesting many of the great features
  • LandOfShadows - Use of one of his windowskins in the demo



Author's Notes

Feel free to ask me any questions and PLEASE tell me if you find a bug.
I'm also quite willing to make customizations and such for this, provided they are within reason, and I have the time.

Have fun with it people ^_^

Don't forget to credit me if you use this in your game :P

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Berans

Thanks lol...I need sleep :P
But I want feedback...I'm so conflicted

Fantasist

Wow! Nice! :clap:

I've downloaded the demo, but I'm a bit busy to try it out. I'll post my feedback.

And a power up for you :)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Berans

I guess I'll just go to sleep and patiently await people's responses  :negative:

Juan

Looks good. *Adds to the form script listing*
Dropbox Who need luck when you can make your own.
3ds Friend code: ShowHide
 4468 1422  6617

Berans

*wheee* I'm honoured lol. Once it's not so cold anymore I'll start working on a better demo to display all the features better XD

Diokatsu


Berans

August 08, 2008, 07:35:40 pm #8 Last Edit: August 14, 2008, 10:04:03 pm by Berans
I'm glad people like it. And remember to report any bugs you find :P
Any suggestions for improvement? I'm considering having the "BGM_CHANGER" option also remember the song when you change map, if another option is on, not sure if I can do it though. I'll have to look...breakfast comes first :P

EDIT: After some consideration, I think I'll leave out the option for now. It would complicate an otherwise simplish script a lot.
I may still consider it in the future, but, consider this a final version for now. Still some minor tweaks to go, but the functionality will remain the same unless someone has a good idea for me to add.

UPDATED  to version 0.99-beta, with an extra implemented features and some near-invisible glitches worked out. Please tell me if something's wrong.

UPDATED to version 1.00-beta, another extra feature added and the code cleaned up somewhat. This is the final beta release, and won't be changed unless someone finds bugs. I'll still happily take customization requests though ;)

UPDATED to version 1.12-final. Another new features, song sorting. Allows you to sort your song list by either Title, Author or Genre. Also saves your last selected sort option with your savegame. Enjoy, and please report any bugs you find.

EDIT2: It appears I've left a rather huge bug in the last version of my script. I don't suggest using v1.12 until I've fixed this, as things go haywire when you don't unlock songs in order or have initial songs with gaps in between. I'm about halfway through fixing that up, so please bare with me

EDIT3: Finally, the forum's back up, the script's updated and well and, so far as I can tell, working flawlessly. Thanks for your patience XD

EDIT4: Made a quick bugfix involving unlocking songs before the iPod's been opened at least once. Since all it was, was relocating 3 lines of code, it wasn't worthy of its own version number

UPDATED with another minute fix for my own stupidity

Starrodkirby86

I taken a gander at the Ipod script. I love the overlays, and I thought that was quite interesting. Now, if you're going to be playing a game that Ipods weren't created or aren't in the correct generation, it would turn into a sound test or something. Would the coordinates required for a graphic change and all, can they be edited via Spriteset_Ipod and Ipod_Dummy, or am I just being a total idiot and getting it off the mark?  :???:

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Berans

you're correct. Spriteset_iPod actuallly draws the iPod graphics, Ipod_Dummy draws the cursor graphic on the iPod. if you change the script around a bit, you can remove those altogether if you want just a plain window

Starrodkirby86

Hmmm...How hard would it be to have some sort of add-on like pop-up showing an album/genre cover? Sort of like a picture overlay, except it'll change depending on the song you are playing? It's going to require a lot of text depending on the overall song count and you need to supply enough album art, but how difficult would that be? (And it might be non-Ipod ethical, I don't have one so I don't know...)

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Fantasist

Making that popup system is possible, even if you don't have the album art. What does media player do? It uses a default image if no album art is used ;)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Berans

if you could give me a mockup picture of what you're after I might give it a go

Starrodkirby86

Sorry it doesn't follow the Ipod format. However, you can simply have some pop-up to the "right" or "left" of the machine to make it look nice. I'm never one that is good with mock-ups.
Spoiler: ShowHide

This can even be a whole completely new layout request. 0_0 By the way, I gave up at the end, and then just ripped the Windows Media Player skin. It's meant to be the whole play stuff, so exclude any foreign features.

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Berans

hmmm....I could probably cook up something like that...Wouldn't even be THAT much work...I think. But not for today, I'm flooded with work for university and need to help get the house ready for inspection by the owner....loads to do, little time :P

Starrodkirby86

There's no particular deadline, okay Berans? So finish all you can. Just don't start making it like five months after this post was created. XD That would be a travesty. Godspeed Berans, godspeed. :P

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Hellfire Dragon

This script is awesome! However...it worked fine in the dmeo but when i put into my project and added my own songs, authors etc,. I get this

:???: :(

Berans

hmmm.....could you tell me exactly when the error happened, and could you also paste a copy of your  "config" section of the script, AND a copy of line 228+ (probably 3-4 lines after 228 will do) since my script has been changed so much that I'm very unsure what line 228 is with you. That would help a lot. It might just be that you set up your songs wrong. Or maybe it's something different.

PS: I'm updating my script shortly after I post this to make setup easier on people, v1.15 will include a tiny bugfix to do with the mute function and will have an all-new way to set up your songs. Quick explanation:
Any songs in your project's "Audio/BGM" folder, will automatically be included in the list of unlockable/playable songs. Any songs from the RTP you want to be played can be added in 2 ways
a) simply copy them to your "Audio/BGM" folder to have them automatically added, or,
b) Put their exact name in the "PLAYBACK1" array, as you would have with all your songs before.
The order of the songs for when you want to set up initial songs/author/genre etc. will be all the songs in your "Audio/BGM" folder arranged in alphabetical order (easy enough to see if you simply arrange that folder alphabetically) followed by any songs you've specified from the RTP in the order you've put them. This is just a testing fase for that system, and I can easily convert it back again if it's not well-liked XD, I just thought that most people probably want all their custom songs to be available anyway, so I'd save them the trouble of setting each and every one of them up correctly.

Hellfire Dragon

August 19, 2008, 05:48:42 am #19 Last Edit: August 19, 2008, 06:13:16 am by Hellfire Dragon
Alright here's the config section

#==============================================================================
#Begin Configuration
#==============================================================================

module Playback
  UNLOCKABLES = true
  BGM_CHANGER = true
  PLAYBACK = [ "Asterisk", "D-technolife",   "Ichirin no Hana",
               "Tonight, Tonight, Tonight",   "Rolling Star",     "ALONES",
                 "After Dark",   "", "",
              "",   ""]
 
  PLAYBACK_INITIAL = []
 
  PLAYBACK_AUTHOR = {1  => "Orange Range", 2  => "UVERworld", 3 => "Unknown",
                     4  => "Unknown", 5  => "Unknown", 6 => "Aqua Timez",
                     7  => "", 8  => "Unknown", 9 => "Unknown",
                     10 => "Unknown", 12 => "Unknown"}
 
  PLAYBACK_GENRE = {1 => ""}, {2 => ""}, {3 => ""}, {4 => ""}, {5 => ""},
  {6 => ""}, {7 => ""},
 
#==============================================================================
#End Configuration
#==============================================================================

And line 288 + 4 lines after it

288        Playback::PLAYBACK[$game_system.unlocked_songs[i]]
289      end
290    end
291  end
292 

I using unlock songs. If there is no unlocked when I use the call script to bring up the Ipod i works, but when there is songs unlocked I get the error.

EDIT: I tried again, I only get the error when I use my own songs. The RTP songs work fine :huh:

Berans

hmmm....few things. Firstly, if you want an Author to show up as unkown you don't have to enter "Unkown" you just don't put that song number in there at all. as for the genre, I take it you just want that to show up empty? You could even find the lines that say

if $game_system.playback_list[@playback_bgm] != nil
  text3 = "Genre: " + $game_system.playback_list[@playback_bgm][2]
else
  text3 = "Genre: Unkown"
end

and

self.contents.draw_text(0,72,self.contents.width,32,text3,1)

and take them out IF you do not want the word "Genre" to display at all.
thirdly, what version of my script are you using? Strangely enough I can't actually seem to find the line you posted in my script o.O leading me to believe the script is probably an old version, perhaps from the demo?

Anyway, you might want to just make a back-up, and try using script v1.15 instead (which is in the spoiler tags in my first post). You won't need to set up the actual song-names for any custom songs you have, just the songs from the RTP if you wish to use them. The author and genre's still need to be set up in the old way though, keeping in mind that the order of songs is -> your custom songs (arranged alphabetically) followed by the RTP songs you've specified (arranged in the order you specified)
Hope it helps.

Hellfire Dragon

I was using the version in the demo yeah. Well I'm using theV1.15 now and it works fine. Also thanks for letting me know how to take the genre out :)

Berans

No problems, feel free to ask for any customizations and I'll see what I can do. I'm not always good on time (which is why I've made little progress on the album cover thing) but I'm usually more than willing to listen and put in on my to-do list

Hellfire Dragon

I'm having another little problem. I don't have unlockables enabled. When I open the 'ipod' the rtp songs are there, so I deleted them from the script, and now there's just blank spaces there and my songs don't show up until number 10 or so :???:

Berans

August 21, 2008, 07:14:30 pm #24 Last Edit: August 21, 2008, 07:17:30 pm by Berans
Hmm...this is strange, I'll try to simulate the bug you're getting to see if I can come up with a solution
EDIT: I THINK I may know what your problem is
Does your PLAYBACK1 array look like this?

PLAYBACK1 = ["","","",""] etc...

because if you want to really remove the songs, don't put in anything, just leave the quotes out completely and only leave in commas if you have more than 1 song you need to separate.
Basiclly, with no RTP songs, it should look like

PLAYBACK1 = []

Hellfire Dragon

Ah that's it! :^_^': Thanks, now I can finally get to using this script properly lol :D

Hellfire Dragon

September 28, 2008, 05:52:10 am #26 Last Edit: September 28, 2008, 05:53:11 am by Hellfire Dragon
Is there a way I set this up so, say I put a folder in the BGM or Audio so it would be Audio/BGM/Ipod or Audio/Ipod, so only the songs in there would be played through the Ipod? I'm not using unlockables or anything either.

I tried just changing line 181 to
  PLAYBACK2 = Dir.entries("Audio/Ipod")


But I just get an errorr saying it couldn't find the song in Audio/BGM

Reno-s--Joker

:haha: Nice work Berans - I think I'll be using this in my game. <3 I like the unlockable song option and the iPod graphic... :xD:
I'll make sure I credit you! :P

rgangsta

April 13, 2009, 01:02:40 pm #28 Last Edit: April 13, 2009, 01:07:22 pm by rgangsta
Nice script. I just have one problem. I want to change the directory of only where the iPod songs come from i.e "Audio\MP3". How can I do that? I've tried changing line 492:
bgm = RPG::AudioFile.new($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)

an canged it to
bgm = "Audio\MP3"($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)

(notice I do not know what I am doing.)
Can you help me please?  :'(

.:EDIT:. I figure it out. Because I picked to change the BGM, the songs also have to be in the BGM folder too.

Reno-s--Joker

Quote from: rgangsta on April 13, 2009, 01:02:40 pm
.:EDIT:. I figure it out. Because I picked to change the BGM, the songs also have to be in the BGM folder too.

You could always just find the line that says:
  PLAYBACK2 = Dir.entries("Audio/BGM")

and change it to something like
  PLAYBACK2 = Dir.entries("Audio/BGM/MP3")
(nothing that MP3 is still inside the BGM folder. Actually you could try putting it outside. Haven't tested it, but it has a fair chance of working. <3

Quote from: rgangsta on April 13, 2009, 01:02:40 pm
bgm = "Audio\MP3"($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)


Lol awesome. :xD:

fugibo

Something tells me that's not gonna work.

rgangsta

It doesn't. That was the first one I ever tried. Nvm. I got it to work anyway. Thanks for your help. But, if there's another way, please let me know.


rgangsta