neonblack

Ocarina Script v2.0b

Apr 16th, 2012
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###--------------------------------------------------------------------------###
  2. #  Ocarina script                                                              #
  3. #  Version 2.0                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neonblack                                                 #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V.Alpha - 3.5.2012                                                          #
  22. #   Wrote main script                                                          #
  23. #  V1.0 - 3.11.2012                                                            #
  24. #   Debbugged, polished, and documented script                                 #
  25. #  V2.0 - 4.15.2012                                                            #
  26. #   Added menu option for songs                                                #
  27. #   Added 2 new script calls for the ocarina                                   #
  28. #   Added note sprite sheet support                                            #
  29. ###--------------------------------------------------------------------------###
  30.  
  31. ###--------------------------------------------------------------------------###
  32. #      Compatibility:                                                          #
  33. #  New Scene entirely; should run with just about everything.                  #
  34. ###--------------------------------------------------------------------------###
  35.  
  36. ###--------------------------------------------------------------------------###
  37. #      Instructions:                                                           #
  38. #  Place this script in the "Materials" section of the scripts above main.     #
  39. #  This script is NOT plug and play and requires additional graphics and       #
  40. #  several setting changes to work properly.  Please be sure you have          #
  41. #  imported the required graphics before continuing.                           #
  42. #                                                                              #
  43. #  To use, place a script call in an event and use one of the following three  #
  44. #  script calls:                                                               #
  45. #    ocarina or play_oc - Calls the instrument input screen for the player.    #
  46. #    song(x)            - Plays song "x" to teach the player a new song.       #
  47. #    give_song(x)       - Gives the player song "x" without teaching it.       #
  48. #                                                                              #
  49. #  It is important to note that the player must have a song learned in order   #
  50. #  for it to be played.  In other words, even if a player properly plays a     #
  51. #  song, if the player has not learned the song yet it will not count as the   #
  52. #  song played.                                                                #
  53. #                                                                              #
  54. ###-----                                                                -----###
  55. #      Menu Usage:                                                             #
  56. #  A page has been added that shows a list of all songs, what songs are        #
  57. #  unlocked, and the notes required to play the songs.  This list can be       #
  58. #  pulled up using the commands "$scene = Scene_Songs.new(x)"  The "x" is not  #
  59. #  required, and is the index in the menu which the cursor will return to.     #
  60. #  In other words, by simply using "$scene = Scene_Songs.new" in a script      #
  61. #  call, the song list will pop up and when exited will return the character   #
  62. #  to the map, while you can use "$scene = Scene_Songs.new(7)" in the menu to  #
  63. #  open the song list and then return to item 7 in the menu when exiting the   #
  64. #  song list.                                                                  #
  65. ###--------------------------------------------------------------------------###
  66.  
  67. ###--------------------------------------------------------------------------###
  68. #      Config:                                                                 #
  69. #  These are the default values used by several of the functions in the        #
  70. #  script.  You may change these values as you find your game requires in      #
  71. #  order to give the player a better playing experience based on your game.    #
  72. #                                                                              #
  73. module CP          #  Do not edit                                              #
  74. module OCARINA     #   these two lines                                         #
  75. module SETTINGS    #  or this one either                                       #
  76. #                                                                              #
  77. ###-----                                                                -----###
  78. # The main game settings are below.  These include most of the sound effects   #
  79. # and variable settings in the script.                                         #
  80. #                                                                              #
  81. # The ID number of the variable to be used by the script.  When a song is      #
  82. # played, that song's value is sent to the variable.  When playing is          #
  83. # cancelled, a value of 0 is returned.                                         #
  84. VARIABLE = 2 # Default = 2                                                     #
  85. #                                                                              #
  86. # The settings for successful and failed song play sound effects.  When a song #
  87. # is played successfully, the first sound is played.  When it is failed, the   #
  88. # second is played.  Volume and pitch of both are controlled here.             #
  89. PLAYED_SONG = "Decision2" # Default = "Decision2"                              #
  90. PLAYED_WRONG = "Buzzer1"  # Default = "Buzzer1"                                #
  91. PLAYED_VOLUME = 80        # Default = 80                                       #
  92. PLAYED_PITCH = 100        # Default = 100                                      #
  93. #                                                                              #
  94. ###-----                                                                -----###
  95. # The sound settings are contained below.  These include the ocorina sound     #
  96. # sound effect, beats, and certain text options.                               #
  97. #                                                                              #
  98. # The main name of the sound effect to be used by the script.  The script      #
  99. # calls on 8 different sound effects defined by the name here with 8 different #
  100. # suffixes.  By default, the lowest note in the octave should be named         #
  101. # "Ocarina_MC".  The suffixes in order from lowest note to highest are:        #
  102. #   _MC, _D, _E, _F, _G, _A, _B, _C.                                           #
  103. # Name, volume, and pitch are defined here, though I don't know why you would  #
  104. # need to change the pitch.                                                    #
  105. OCARINA_SOUND = "Ocarina" # Default = "Ocarina"                                #
  106. OCARINA_VOLUME = 100      # Default = 100                                      #
  107. OCARINA_PITCH = 100       # Default = 100                                      #
  108. #                                                                              #
  109. # The number of beats used in a song.  Having more or less beats per song may  #
  110. # cause bugs (it's effects have not been tested or calculated).  The player    #
  111. # must play this number of notes for the script to continue.                   #
  112. BEATS = 8 # Default = 8                                                        #
  113. #                                                                              #
  114. # The messages that display when you play or listen to a certain song.         #
  115. PLAYED_MESSAGE = "You have played"   # Default = "You have played"             #
  116. LEARNED_MESSAGE = "You have learned" # Default = "You have learned"            #
  117. #                                                                              #
  118. ###-----                                                                -----###
  119. # The song arrays are contained below.  This is the most difficult section of  #
  120. # the settings are require a small amount of extra explaining to understand.   #
  121. #                                                                              #
  122. # This is the song array.  The song arrays can consist of as many "notes" as   #
  123. # you have defined in the "BEATS" setting above, and any number of "rests".    #
  124. # These notes and rests are defined here as numbers, from 0 to 8 where 0 is a  #
  125. # rest and 1 through 8 are notes ranging from lowest to highest.  The rests do #
  126. # not matter when the player is attempting to play a song and are not counted. #
  127. # Rests only matter during playback as they rest for a single beat, or simply  #
  128. # leave a period of silence.                                                   #
  129. # To iterate:                                                                  #
  130. #   0 = Rest, 1 = Middle C (_MC suffix sfx), 2 = D, 3 = E, etc.                #
  131. # All songs must be in square brackets and must be followed by a comma (,) or  #
  132. # you will get a syntax error.  The first song in the list has song ID 1 in    #
  133. # order for the script to work properly, so don't worry about errors in that   #
  134. # respect.  I've at least planned that far ahead.                              #
  135. #                                                                              #
  136. SONGS =[ # Do not edit this line.                                              #
  137.                                                                                #
  138.   [3, 0, 2, 3, 4, 3, 2, 1, 2], # This is song ID number 1                      #
  139.   [5, 5, 0, 8, 0, 7, 0, 6, 5, 0, 4, 0, 5], # this song demonstrates rests      #
  140.   [2, 5, 6, 2, 8, 0, 7, 6, 5], # and this is just a third song for pretties    #
  141.                                                                                #
  142. ] # Leave this line alone.                                                     #
  143. #                                                                              #
  144. # This array contains song names.  The song names here are in the same order   #
  145. # as the songs above, so order them accordingly.                               #
  146. NAMES =[ # This line should not be touched.                                    #
  147.                                                                                #
  148.   "Mother Earth",   #  Kudos to you if you                                     #
  149.   "Rigid Paradise", #   know the games any                                     #
  150.   "Overature",      #    of these came from.                                   #
  151. ] # Don't touch this line.                                                     #
  152. #                                                                              #
  153. # This final array contains descriptions of the songs.  These display in the   #
  154. # help box when the song is viewed from the menu.  Once again, they are in     #
  155. # the same order as the songs above.                                           #
  156. DESCS =[ # Don't edit this line....                                            #
  157.                                                                                #
  158.   "A song for new beginnings",                                                 #
  159.   "A song that gives a particular feeling of a jiang-shi",                     #
  160.   "A heroic sounding song you feel you've heard before",                       #
  161. ] # This line should not be touched.                                           #
  162. #                                                                              #
  163. # This is the text and description to be displayed in the menu for a song      #
  164. # that has not been learned.                                                   #
  165. NO_SONG = "???" # Default = "???"                                              #
  166. NO_DESC = "This song has not been learned yet"                                 #
  167. #                 Default = "This song has not been learned yet"               #
  168. #                                                                              #
  169. ###-----                                                                -----###
  170. # Graphical settings are contained below.  These are the clef that the notes   #
  171. # go on as well as the notes themselves.                                       #
  172. #                                                                              #
  173. # The file for the clef and the X and Y offset of it from the middle of the    #
  174. # screen.  Keep in mind that the dialogue box for songs displays just above    #
  175. # the center of the screen, so you will need to move this image down.          #
  176. STAFF_GFX = "Staff" # Default = "Staff"                                        #
  177. STAFF_X = 0         # Default = 0                                              #
  178. STAFF_Y = 100       # Default = 100                                            #
  179. #                                                                              #
  180. # The settings for the note graphics.  The X and Y settings are the location   #
  181. # the first note assuming it is middle C from the upper left most corner of    #
  182. # the image above.  All other note locations will be determined based on this  #
  183. # one location.  Finally, "NOTE_STEET" determines if a sprite sheet is used.   #
  184. # If this is set to true, the graphic file is considered a sprite sheet with   #
  185. # a graphic for each note in it.  The notes are from middle C to high C from   #
  186. # left to right.                                                               #
  187. NOTE_GFX = "NoteSheet" # Default = "NoteSheet"                                 #
  188. NOTE_X = 68            # Default = 68                                          #
  189. NOTE_Y = 64            # Default = 64                                          #
  190. NOTE_SHEET = true      # Default = true                                        #
  191. #                                                                              #
  192. # The X and Y offset of subsequent notes.  X offset defines the distance       #
  193. # between each note played, while Y offset defines the locations of all keys   #
  194. # played.                                                                      #
  195. X_OFFSET = 40 # Default = 40                                                   #
  196. Y_OFFSET = -8 # Default = -8                                                   #
  197. #                                                                              #
  198. end # SETTINGS   These lines are not for touching.                             #
  199. end # OCARINA          Trust me, they bite.                                    #
  200. end # CP                                                                       #
  201. ###--------------------------------------------------------------------------###
  202.  
  203.  
  204. ###--------------------------------------------------------------------------###
  205. #  The following lines are the actual core code of the script.  While you are  #
  206. #  certainly invited to look, modifying it may result in undesirable results.  #
  207. #  Modify at your own risk!                                                    #
  208. ###--------------------------------------------------------------------------###
  209.  
  210. $imported = {} if $imported == nil
  211. $imported["CP_OCARINA"] = true
  212.  
  213. ##-----
  214. ## Makes stuff work for people who aren't me.
  215. ##-----
  216. class Game_Interpreter
  217.   def play_oc
  218.     ocarina
  219.   end
  220.  
  221.   def ocarina
  222.     $scene = Scene_Ocarina.new(0)    ## Calls the scene.
  223.     @wait_count = 1                  ## Gives time for the script to process.
  224.   end
  225.  
  226.   def song(song)
  227.     $scene = Scene_Ocarina.new(song, true)
  228.     @wait_count = 1
  229.   end
  230.  
  231.   def give_song(song)
  232.     song -= 1
  233.     $data_songs[song][0] = CP::OCARINA::SETTINGS::NAMES[song]
  234.     $data_songs[song][1] = CP::OCARINA::SETTINGS::DESCS[song]
  235.     $data_songs[song][2] = true
  236.   end
  237. end
  238.  
  239. ##-----
  240. ## The message box that pops up.  Hidden by default.
  241. ##-----
  242. class Window_Ocarina_Message < Window_Base
  243.   def initialize
  244.     super(144, 128, 256, 80)
  245.     self.visible = false
  246.   end
  247.  
  248.   def draw_song(song, learning = false)
  249.     dialogue = CP::OCARINA::SETTINGS::PLAYED_MESSAGE  ## Picks a message here.
  250.     dialogue = CP::OCARINA::SETTINGS::LEARNED_MESSAGE if learning
  251.     name = CP::OCARINA::SETTINGS::NAMES[song]  ## Name of the song.
  252.     wd = self.width
  253.     self.contents.font.color = system_color
  254.     self.contents.draw_text(0, 0, wd - 32, WLH, dialogue, 1)
  255.     self.contents.font.color = normal_color
  256.     self.contents.draw_text(0, 24, wd - 32, WLH, name, 1)
  257.     self.visible = true  ## Makes itself seen.
  258.   end
  259. end
  260.  
  261. ##-----
  262. ## The bread and butter of the script.
  263. ##-----
  264. class Scene_Ocarina < Scene_Base
  265.   def initialize(song, teach = false)
  266.     @play_song = song -1  ## -1 here so it calls the proper song.
  267.     @max_note = CP::OCARINA::SETTINGS::BEATS
  268.     @note = teach ? @max_note : 0
  269.     @play_notes = []
  270.     @teach = teach
  271.     @t_song = song - 1
  272.     @taught = false
  273.   end
  274.  
  275.   def start
  276.     super
  277.     create_menu_background
  278.     @message_window = Window_Ocarina_Message.new
  279.     create_clef
  280.     note_sprite
  281.   end
  282.  
  283.   def terminate
  284.     super
  285.     dispose_menu_background
  286.     @message_window.dispose
  287.     @clef_sprite.dispose
  288.     @note_sprites.dispose
  289.   end
  290.  
  291.   def update
  292.     super
  293.     if @teach     ## Several checks here for it to run properly.
  294.       play_song if @note == @max_note
  295.       update_note_input
  296.       compare_songs if @note == @max_note
  297.     else
  298.       update_note_input
  299.       compare_songs if @note == @max_note
  300.       play_song if @note == @max_note
  301.     end
  302.   end
  303.  
  304. ##-----
  305. ## Draws the clef for later use.
  306. ##-----
  307.   def create_clef
  308.     @clef_sprite = Sprite.new(@viewport1)
  309.     @clef_sprite.bitmap = Cache.picture(CP::OCARINA::SETTINGS::STAFF_GFX)
  310.     @clef_sprite.ox = @clef_sprite.width/2
  311.     @clef_sprite.oy = @clef_sprite.height/2
  312.     @clef_sprite.x = Graphics.width/2 + CP::OCARINA::SETTINGS::STAFF_X
  313.     @clef_sprite.y = Graphics.height/2 + CP::OCARINA::SETTINGS::STAFF_Y
  314.     @clef_sprite.z = 1
  315.   end
  316.  
  317. ##-----
  318. ## Misleading name.  Only makes the bitmap notes will be drawn on.
  319. ##-----
  320.   def note_sprite
  321.     @note_sprites = Sprite.new(@viewport1)
  322.     @note_sprites.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  323.     xo = CP::OCARINA::SETTINGS::NOTE_X + CP::OCARINA::SETTINGS::STAFF_X
  324.     yo = CP::OCARINA::SETTINGS::NOTE_Y + CP::OCARINA::SETTINGS::STAFF_Y
  325.     @first_note_x = Graphics.width/2 - @clef_sprite.width/2 + xo
  326.     @first_note_y = Graphics.height/2 - @clef_sprite.height/2 + yo
  327.     @note_sprites.z = 3
  328.     unless @t_song == -1
  329.       tn = @note
  330.       @note = 0
  331.       for i in 0...CP::OCARINA::SETTINGS::SONGS[@t_song].size
  332.         note = CP::OCARINA::SETTINGS::SONGS[@t_song][i]
  333.         unless note == 0
  334.           add_note(note, true)
  335.           @note += 1
  336.         end
  337.       end
  338.       @note = tn
  339.     end
  340.   end
  341.  
  342. ##-----
  343. ## Makes wait work.
  344. ##-----
  345.   def update_basic
  346.     Graphics.update
  347.     Input.update
  348.   end
  349.   def wait(dur)
  350.     for i in 0...dur
  351.       update_basic
  352.     end
  353.   end
  354.  
  355. ##-----
  356. ## Adds a note to the already drawn bitmap.
  357. ##-----
  358.   def add_note(note, back = false)
  359.     temp_note = Cache.picture(CP::OCARINA::SETTINGS::NOTE_GFX)
  360.     nwi = temp_note.width
  361.     nhe = temp_note.height
  362.     if CP::OCARINA::SETTINGS::NOTE_SHEET
  363.       rect = Rect.new(nwi / 8 * (note - 1), 0, nwi / 8, nhe)
  364.     else
  365.       rect = Rect.new(0, 0, nwi, nhe)
  366.     end
  367.     xa = CP::OCARINA::SETTINGS::X_OFFSET * @note
  368.     ya = CP::OCARINA::SETTINGS::Y_OFFSET * (note - 1)
  369.     xa -= rect.width/2
  370.     ya -= rect.height/2
  371.     xn = @first_note_x + xa
  372.     yn = @first_note_y + ya
  373.     unless back
  374.       @note_sprites.bitmap.blt(xn, yn, temp_note, rect)
  375.     else
  376.       @note_sprites.bitmap.blt(xn, yn, temp_note, rect, 128)
  377.     end
  378.   end  
  379.  
  380. ##-----
  381. ## Plays the sound effects of the instrument.
  382. ##-----
  383.   def play_sound(note)
  384.     se = CP::OCARINA::SETTINGS::OCARINA_SOUND
  385.     sv = CP::OCARINA::SETTINGS::OCARINA_VOLUME
  386.     sp = CP::OCARINA::SETTINGS::OCARINA_PITCH
  387.     ss = "_MC" if note == 1
  388.     ss = "_D" if note == 2
  389.     ss = "_E" if note == 3
  390.     ss = "_F" if note == 4
  391.     ss = "_G" if note == 5
  392.     ss = "_A" if note == 6
  393.     ss = "_B" if note == 7
  394.     ss = "_C" if note == 8
  395.     note_se = RPG::SE.new(se + ss, sv, sp)
  396.     note_se.play
  397.   end
  398.  
  399. ##-----
  400. ## The input section.  Probably could have made this easier.
  401. ##-----
  402.   def update_note_input
  403.     if Input.trigger?(Input::DOWN)
  404.       note = 1
  405.     elsif Input.trigger?(Input::LEFT)
  406.       note = 2
  407.     elsif Input.trigger?(Input::UP)
  408.       note = 3
  409.     elsif Input.trigger?(Input::RIGHT)
  410.       note = 4
  411.     elsif Input.trigger?(Input::C)
  412.       note = 5
  413.     elsif Input.trigger?(Input::B)
  414.       note = 6
  415.     elsif Input.trigger?(Input::X)
  416.       note = 7
  417.     elsif Input.trigger?(Input::Y)
  418.       note = 8
  419.     elsif Input.trigger?(Input::A) and @teach == false
  420.       Sound.play_cancel
  421.       quit
  422.     end
  423.     unless note == nil
  424.       play_sound(note)
  425.       add_note(note)
  426.       @play_notes.push note
  427.       @note += 1
  428.     end
  429.   end
  430.  
  431.   def quit
  432.     variable = CP::OCARINA::SETTINGS::VARIABLE
  433.     $game_variables[variable] = @play_song + 1
  434.     ocarina_end
  435.   end
  436.  
  437.   def ocarina_end
  438.     $scene = Scene_Map.new
  439.   end
  440.  
  441. ##-----
  442. ## This plays the song if you input a correct song or if you are teaching
  443. ## a new song to the player.  Should be cleaned up later.
  444. ##-----
  445.   def play_song
  446.     wait(5)
  447.     se = CP::OCARINA::SETTINGS::PLAYED_SONG
  448.     se = CP::OCARINA::SETTINGS::PLAYED_WRONG if @play_song == -1
  449.     sv = CP::OCARINA::SETTINGS::PLAYED_VOLUME
  450.     sp = CP::OCARINA::SETTINGS::PLAYED_PITCH
  451.     song_play = RPG::SE.new(se, sv, sp) unless se == nil
  452.     song_play.play
  453.     @message_window.draw_song(@play_song, @teach) unless @play_song == -1 or (@teach != @taught)
  454.     wait(30)
  455.     @note_sprites.dispose
  456.     note_sprite
  457.     @note = 0
  458.     @play_notes = []
  459.     return if @play_song == -1
  460.     for i in 0...CP::OCARINA::SETTINGS::SONGS[@play_song].size
  461.       note = CP::OCARINA::SETTINGS::SONGS[@play_song][i]
  462.       unless note == 0
  463.         play_sound(note)
  464.         add_note(note)
  465.         @note += 1
  466.       end
  467.       wait(20)
  468.     end
  469.     wait(60)
  470.     quit if (@teach == @taught)
  471.     @note = 0
  472.     @play_song = -1
  473.     @note_sprites.dispose
  474.     note_sprite
  475.   end
  476.  
  477. ##-----
  478. ## Compares the song played to songs from the array.  There's probably an
  479. ## easier way to do this, but I prefer to show my work in this case.
  480. ##-----
  481.   def compare_songs
  482.     for i1 in 0...CP::OCARINA::SETTINGS::SONGS.size
  483.       cur_note = 0
  484.       note_same = 0
  485.       for i2 in 0...CP::OCARINA::SETTINGS::SONGS[i1].size
  486.         unless CP::OCARINA::SETTINGS::SONGS[i1][i2] == 0
  487.           note_same += 1 if CP::OCARINA::SETTINGS::SONGS[i1][i2] == @play_notes[cur_note]
  488.           cur_note += 1
  489.         end
  490.       end
  491.       @play_song = i1 if note_same == @max_note and ($data_songs[i1][2] or @teach)
  492.       @taught = true if @play_song == @t_song and @teach
  493.     end
  494.     @play_song = -1 if @teach and @taught == false
  495.     if @taught
  496.       $data_songs[@t_song][0] = CP::OCARINA::SETTINGS::NAMES[@t_song]
  497.       $data_songs[@t_song][1] = CP::OCARINA::SETTINGS::DESCS[@t_song]
  498.       $data_songs[@t_song][2] = true
  499.     end
  500.   end
  501.  
  502. end
  503.  
  504.  
  505. ##-----
  506. ## Handles the clef section of the song window in the menu.
  507. ##-----
  508. class Window_SongClef < Window_Base
  509.   def initialize
  510.     super(0, WLH + 16, Graphics.width, WLH + 32)
  511.     refresh
  512.     self.opacity = 0
  513.   end
  514.  
  515.   def refresh(song = -1)
  516.     self.contents.clear
  517.     bitmap = Cache.picture(CP::OCARINA::SETTINGS::STAFF_GFX)
  518.     bw = bitmap.width
  519.     bh = bitmap.height
  520.     self.height = bh + WLH + 64
  521.     create_contents
  522.     bx = (self.contents.width - bw) / 2
  523.     self.contents.blt(bx, WLH / 2 + 16, bitmap, bitmap.rect)
  524.     unless song == -1
  525.       @note = 0
  526.       for i in 0...CP::OCARINA::SETTINGS::SONGS[song].size
  527.         note = CP::OCARINA::SETTINGS::SONGS[song][i]
  528.         unless note == 0
  529.           add_note(bx, note)
  530.           @note += 1
  531.         end
  532.       end
  533.     end
  534.   end
  535.  
  536.   def add_note(x, note)
  537.     temp_note = Cache.picture(CP::OCARINA::SETTINGS::NOTE_GFX)
  538.     nwi = temp_note.width
  539.     nhe = temp_note.height
  540.     if CP::OCARINA::SETTINGS::NOTE_SHEET
  541.       rect = Rect.new(nwi / 8 * (note - 1), 0, nwi / 8, nhe)
  542.     else
  543.       rect = Rect.new(0, 0, nwi, nhe)
  544.     end
  545.     xa = CP::OCARINA::SETTINGS::NOTE_X + CP::OCARINA::SETTINGS::X_OFFSET * @note
  546.     ya = CP::OCARINA::SETTINGS::NOTE_Y + CP::OCARINA::SETTINGS::Y_OFFSET * (note - 1)
  547.     xa -= rect.width/2
  548.     ya -= rect.height/2
  549.     xn = x + xa
  550.     yn = WLH / 2 + ya + 16
  551.     self.contents.blt(xn, yn, temp_note, rect)
  552.   end
  553. end
  554.  
  555. ##-----
  556. ## Handles the song list in the song menu.
  557. ##-----
  558. class Window_Songs < Window_Selectable
  559.   attr_reader   :clef_window
  560.  
  561.   def initialize(x, y, width, height)
  562.     super(x, y, width, height)
  563.     @column_max = 2
  564.     self.index = 0
  565.     refresh
  566.   end
  567.  
  568.   def songs
  569.     return @data[self.index]
  570.   end
  571.  
  572.   def refresh
  573.     @data = []
  574.     for song in $data_songs
  575.       @data.push(song)
  576.     end
  577.     @item_max = @data.size
  578.     create_contents
  579.     for i in 0...@item_max
  580.       draw_item(i)
  581.     end
  582.   end
  583.  
  584.   def draw_item(index)
  585.     rect = item_rect(index)
  586.     self.contents.clear_rect(rect)
  587.     song = @data[index]
  588.     if song != nil
  589.       rect.width -= 4
  590.       enabled = song[2]
  591.       draw_song_name(song[0], rect.x, rect.y, enabled)
  592.     end
  593.   end
  594.  
  595.   def draw_song_name(item, x, y, enabled = true)
  596.     if item != nil
  597.       self.contents.font.color = normal_color
  598.       self.contents.font.color.alpha = enabled ? 255 : 128
  599.       self.contents.draw_text(x, y, 172, WLH, item)
  600.     end
  601.   end
  602.  
  603.   def clef_window=(cw)
  604.     @clef_window = cw
  605.     call_update_clef
  606.   end
  607.  
  608.   def update_help
  609.     @help_window.set_text(songs == nil ? "" : songs[1])
  610.     call_update_clef
  611.   end
  612.  
  613.   def call_update_clef
  614.     if self.active and @clef_window != nil
  615.        update_clef
  616.     end
  617.   end
  618.  
  619.   def update_clef
  620.     @clef_window.refresh(songs[2] ? self.index : -1)
  621.   end
  622. end
  623.  
  624. ##-----
  625. ## The scene that shows the songs and info on them in the menu.
  626. ##-----
  627. class Scene_Songs < Scene_Base
  628.   def initialize(goback = nil)
  629.     @goback = goback
  630.   end
  631.  
  632.   def start
  633.     super
  634.     create_menu_background
  635.     @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  636.     @help_window = Window_Help.new
  637.     @clef_window = Window_SongClef.new
  638.     sy = @clef_window.height + @help_window.height - 32
  639.     @song_window = Window_Songs.new(0, sy, Graphics.width, Graphics.height - sy)
  640.     @song_window.help_window = @help_window
  641.     @song_window.clef_window = @clef_window
  642.   end
  643.  
  644.   def terminate
  645.     super
  646.     dispose_menu_background
  647.     @help_window.dispose
  648.     @clef_window.dispose
  649.     @song_window.dispose
  650.   end
  651.  
  652.   def return_scene
  653.     return $scene = Scene_Menu.new(@goback) unless @goback == nil
  654.     return $scene = Scene_Map.new
  655.   end
  656.  
  657.   def update
  658.     super
  659.     update_menu_background
  660.     @help_window.update
  661.     @clef_window.update
  662.     @song_window.update
  663.     update_song_selection
  664.   end
  665.  
  666.   def update_song_selection
  667.     if Input.trigger?(Input::B)
  668.       Sound.play_cancel
  669.       return_scene
  670.     end
  671.   end
  672.  
  673. end
  674.  
  675. class Scene_Title < Scene_Base
  676.   alias cp_oc_create_game_objects create_game_objects unless $@
  677.   def create_game_objects
  678.     cp_oc_create_game_objects
  679.     create_song_list
  680.   end
  681.  
  682.   def create_song_list
  683.     $data_songs = []
  684.     no_song = CP::OCARINA::SETTINGS::NO_SONG
  685.     no_desc = CP::OCARINA::SETTINGS::NO_DESC
  686.     for i in 0...CP::OCARINA::SETTINGS::SONGS.size
  687.       $data_songs.push [no_song, no_desc, false]
  688.     end
  689.   end
  690. end
  691.  
  692. ##----------------------------------------------------------------------------##
  693. ##  END OF SCRIPT                                                             ##
  694. ##----------------------------------------------------------------------------##
RAW Paste Data