Advertisement
roninator2

Neon Black - Ocarina Instrument

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