SHARE
TWEET

[RMXP] Diary 1.2

ForeverZer0 May 21st, 2011 241 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  2. # Diary Scene
  3. # Author: ForeverZer0
  4. # Version: 1.2
  5. # Date: 12.18.2010
  6. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  7. #
  8. # Introduction:
  9. #
  10. #   This is a basic script that will allow you to keep a "diary" or notepad in
  11. #   your game. It is very simple to use, and uses a simple interface for
  12. #   displaying the notes.
  13. #
  14. # Features:
  15. #
  16. #   - Group your notes into "chapters".  
  17. #   - Automatically formats text to fit on each line in a legible format.
  18. #   - Simple script call to add text.
  19. #   - Option to define each note in the script editor, then simply use a script
  20. #     call to add it.
  21. #   - Option to use the map as the background.
  22. #
  23. # Instructions:
  24. #
  25. #   - Place script above main, and below default scripts.
  26. #   - Make configurations below.
  27. #   - To call the scene, use this syntax:  $scene = Scene_Diary.new
  28. #   - To add an entry, use this syntax:
  29. #
  30. #     Diary.add_entry(CHAPTER, TEXT)
  31. #      
  32. #     CHAPTER: An arbitrary integer to define what group to add the note to.
  33. #     TEXT: Either a string which will be the text added to the diary, or an
  34. #           integer which will return the string defined in the configuration
  35. #           below. The second method will make it easier to make long notes
  36. #           without filling up the little script call box.
  37. #
  38. # Author's Notes:
  39. #
  40. #  - Please be sure to report any bugs/issues with the script. Enjoy!
  41. #
  42. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  43.  
  44. module Diary
  45. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  46. #                         BEGIN CONFIGURATION
  47. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  48.  
  49.   MAP_BACKGROUND = true
  50.   # Set to true if you would like the map to show behind the window.
  51.   RETURN_SCENE = Scene_Map
  52.   # The scene that the game returns to when you exit the diary.
  53.   SCENE_ARGUMENTS = []
  54.   # Define any arguments that may need called with scene if need be. Place them
  55.   # in the array in the order in which they are normally called.
  56.  
  57.   def self.chapter_name(chapter)
  58.     # Define the names of the "chapters".
  59.     # when CHAPTER then "CHAPTER_NAME"
  60.     return case chapter
  61.     when 1 then 'Millenium Fair'
  62.     when 2 then 'What Happened to Marle?'
  63.     end
  64.   end
  65.  
  66.   def self.entry(index)
  67.     # Define the strings that correspond with each index. The index can be called
  68.     # instead of actual text to add an entry.
  69.     # when INDEX then "TEXT"
  70.     return case index
  71.     when 0 then 'I forgot today was the day of the big fair! I was supposed to go and see Lucca\'s new invention.'
  72.     when 1 then 'I need to escort Marle around the fair, and maybe play a few games.'
  73.     when 2 then 'Marle was sucked into the vortex. I think it had something to do with that pendant that she was wearing...'
  74.     when 3 then 'This place is very strange, and everyone talks funny. It\'s all vaguely the same, yet different. Where am I?'
  75.     end
  76.   end
  77.  
  78. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  79. #                           END CONFIGURATION
  80. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  81.  
  82.   def self.add_entry(chapter, text)
  83.     # Add the chapter number if it does not exist.
  84.     if $game_party.diary[chapter] == nil
  85.       $game_party.diary[chapter] = []
  86.     end
  87.     if text.is_a?(String)
  88.       # Add the new entry to the end of the chapter.
  89.       $game_party.diary[chapter].push(text)
  90.     elsif text.is_a?(Integer)
  91.       # Get the defined note if the text is a number.
  92.       $game_party.diary[chapter].push(self.entry(text))
  93.     end
  94.   end
  95. end
  96.  
  97. #===============================================================================
  98. # ** Window_Diary
  99. #===============================================================================
  100.  
  101. class Window_Diary < Window_Base
  102.  
  103.   attr_reader :lines
  104.  
  105.   def initialize
  106.     super(0, 64, 640, 416)
  107.     self.back_opacity = Diary::MAP_BACKGROUND ? 160 : 255
  108.     self.contents = Bitmap.new(width - 32, height - 32)
  109.     @lines = []
  110.   end
  111.  
  112.   def chapter=(chapter)
  113.     # Reset the current entries.
  114.     entries = $game_party.diary[chapter]
  115.     entries = [''] if entries == nil
  116.     # Divide the current entries into lines based off the text size and length.
  117.     @lines = entries.collect {|text| self.contents.slice_text(text, 608) }
  118.     @lines.flatten!
  119.     refresh
  120.   end
  121.  
  122.   def refresh
  123.     # Dispose bitmap, returning if no lines are defined.
  124.     self.contents.clear
  125.     return if @lines.size == 0
  126.     self.contents.dispose
  127.     # Create bitmap to contain the lines.
  128.     self.contents = Bitmap.new(self.width - 32, @lines.size * 32)
  129.     # Draw each line.
  130.     @lines.each_index {|i| self.contents.draw_text(0, i*32, 608, 32, @lines[i])}
  131.   end
  132. end
  133.  
  134. #===============================================================================
  135. # ** Bitmap
  136. #===============================================================================
  137.    
  138. class Bitmap
  139.  
  140.   # Blizzard's slice_text method. This method can be removed if you have another
  141.   # script that already uses it.
  142.   def slice_text(text, width)
  143.     return '' if text == nil
  144.     words = text.split(' ')
  145.     return words if words.size == 1
  146.     result, current_text = [], words.shift
  147.     words.each_index {|i|
  148.     if self.text_size("#{current_text} #{words[i]}").width > width
  149.       result.push(current_text)
  150.       current_text = words[i]
  151.     else
  152.       current_text = "#{current_text} #{words[i]}"
  153.     end
  154.     result.push(current_text) if i >= words.size - 1}
  155.     return result
  156.   end
  157. end
  158.  
  159. #===============================================================================
  160. # ** Scene_Diary
  161. #===============================================================================
  162.  
  163. class Scene_Diary
  164.  
  165.   def main
  166.     # Create the windows.
  167.     @sprites = [Window_Help.new, Window_Diary.new]
  168.     if Diary::MAP_BACKGROUND
  169.       @sprites.push(Spriteset_Map.new)
  170.       @sprites[0].back_opacity = 160
  171.     end
  172.     @keys = $game_party.diary.keys.sort
  173.     @names = @keys.collect {|chapter| Diary.chapter_name(chapter) }
  174.     # Find current index, setting to first chapter if undefined.
  175.     @index = @keys.index(Diary.chapter_name(@chapter))
  176.     @index = 0 if @index == nil
  177.     # Set the information for each window.
  178.     @sprites[0].set_text(@names[@index] == nil ? '' : @names[@index])
  179.     @sprites[1].chapter = @keys[@index]
  180.     # Transition Graphics.
  181.     Graphics.transition
  182.     # Main loop.
  183.     loop { Graphics.update; Input.update; update; break if $scene != self }
  184.     # Dispose windows.
  185.     Graphics.freeze
  186.     @sprites.each {|sprite| sprite.dispose }
  187.   end
  188.  
  189.   def update
  190.     # Branch by what input is recieved.
  191.     if Input.repeat?(Input::UP) || Input.trigger?(Input::UP)
  192.       $game_system.se_play($data_system.cursor_se)
  193.       @sprites[1].oy -= 32 if @sprites[1].oy if @sprites[1].oy > 0
  194.     elsif Input.repeat?(Input::DOWN) || Input.trigger?(Input::DOWN)
  195.       $game_system.se_play($data_system.cursor_se)
  196.       @sprites[1].oy += 32 if @sprites[1].oy < (@sprites[1].contents.height-384)
  197.     elsif Input.trigger?(Input::L) || Input.trigger?(Input::R)
  198.       $game_system.se_play($data_system.decision_se)
  199.       # Change the current index.
  200.       @index += Input.trigger?(Input::L) ? -1 : 1
  201.       @index %= @keys.size
  202.       # Display the name of the current chapter in the header.
  203.       @sprites[0].set_text(@names[@index], 1)
  204.       # Change the current chapter.
  205.       @sprites[1].chapter = @keys[@index]
  206.     elsif Input.trigger?(Input::B)
  207.       # Play cancel SE and return to the defined scene.
  208.       $game_system.se_play($data_system.cancel_se)
  209.       args, scene = Diary::SCENE_ARGUMENTS, Diary::RETURN_SCENE
  210.       $scene = (args == []) ? scene.new : scene.new(*args)
  211.     end
  212.   end
  213.  
  214. end
  215.  
  216. #===============================================================================
  217. # ** Game_Party
  218. #===============================================================================
  219.  
  220. class Game_Party
  221.  
  222.   attr_accessor :diary
  223.  
  224.   alias zer0_diary_init initialize
  225.   def initialize
  226.     zer0_diary_init
  227.     @diary = {}
  228.   end
  229. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top