Diary

Diary Version: 1.1
By: ForeverZer0

Introduction

This is a basic script that will allow you to keep a "diary" or notepad in your game. It is very simple to use, and uses a simple interface for displaying the notes.

Features
  • Group your notes into "chapters".
  • Automatically formats text to fit on each line in a legible format.
  • Simple script call to add text.
  • Option to define each note in the script editor, then simply use a script call to add it.
  • Option to use the map as the background.

Screenshots

Image

Script

  1. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  2. # Diary Scene
  3. # Author: ForeverZer0
  4. # Version: 1.0
  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
  72.  
  73. Lucca's new invention.'
  74.     when 1 then 'I need to escort Marle around the fair, and maybe play a few games.'
  75.     when 2 then 'Marle was sucked into the vortex. I think it had something to do with
  76.  
  77. that pendant that she was wearing...'
  78.     when 3 then 'This place is very strange, and everyone talks funny. It's all vaguely
  79.  
  80. the same, yet different. Where am I?'
  81.     end
  82.   end
  83.  
  84. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  85. #                           END CONFIGURATION
  86. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  87.   
  88.   def self.add_entry(chapter, text)
  89.     # Add the chapter number if it does not exist.
  90.     if $game_party.diary[chapter] == nil
  91.       $game_party.diary[chapter] = []
  92.     end
  93.     if text.is_a?(String)
  94.       # Add the new entry to the end of the chapter.
  95.       $game_party.diary[chapter].push(text)
  96.     elsif text.is_a?(Integer)
  97.       # Get the defined note if the text is a number.
  98.       $game_party.diary[chapter].push(self.entry(text))
  99.     end
  100.   end
  101. end
  102.  
  103. #===============================================================================
  104. # ** Window_Diary
  105. #===============================================================================
  106.  
  107. class Window_Diary < Window_Base
  108.   
  109.   attr_reader :lines
  110.   
  111.   def initialize
  112.     super(0, 64, 640, 416)
  113.     self.back_opacity = Diary::MAP_BACKGROUND ? 160 : 255
  114.     self.contents = Bitmap.new(width - 32, height - 32)
  115.     @lines = []
  116.   end
  117.   
  118.   def chapter=(chapter)
  119.     # Reset the current entries.
  120.     entries = $game_party.diary[chapter]
  121.     entries = [''] if entries == nil
  122.     # Divide the current entries into lines based off the text size and length.
  123.     @lines = entries.collect {|text| self.contents.slice_text(text, 608) }
  124.     @lines.flatten!
  125.     refresh
  126.   end
  127.   
  128.   def refresh
  129.     # Dispose bitmap, returning if no lines are defined.
  130.     self.contents.clear
  131.     return if @lines.size == 0
  132.     self.contents.dispose
  133.     # Create bitmap to contain the lines.
  134.     self.contents = Bitmap.new(self.width - 32, @lines.size * 32)
  135.     # Draw each line.
  136.     @lines.each_index {|i| self.contents.draw_text(0, i*32, 608, 32, @lines[i])}
  137.   end
  138. end
  139.  
  140. #===============================================================================
  141. # ** Bitmap
  142. #===============================================================================
  143.     
  144. class Bitmap
  145.   
  146.   # Blizzard's slice_text method. This method can be removed if you have another
  147.   # script that already uses it.
  148.   def slice_text(text, width)
  149.     words = text.split(' ')
  150.     return words if words.size == 1
  151.     result, current_text = [], words.shift
  152.     words.each_index {|i|
  153.     if self.text_size("#{current_text} #{words[i]}").width > width
  154.       result.push(current_text)
  155.       current_text = words[i]
  156.     else
  157.       current_text = "#{current_text} #{words[i]}"
  158.     end
  159.     result.push(current_text) if i >= words.size - 1}
  160.     return result
  161.   end
  162. end
  163.  
  164. #===============================================================================
  165. # ** Scene_Diary
  166. #===============================================================================
  167.  
  168. class Scene_Diary
  169.   
  170.   def main
  171.     # Create the windows.
  172.     @sprites = [Window_Help.new, Window_Diary.new]
  173.     if Diary::MAP_BACKGROUND
  174.       @sprites.push(Spriteset_Map.new)
  175.       @sprites[0].back_opacity = 160
  176.     end
  177.     @keys = $game_party.diary.keys.sort
  178.     @names = @keys.collect {|chapter| Diary.chapter_name(chapter) }
  179.     # Find current index, setting to first chapter if undefined.
  180.     @index = @keys.index(Diary.chapter_name(@chapter))
  181.     @index = 0 if @index == nil
  182.     # Set the information for each window.
  183.     @sprites[0].set_text(@names[@index] == nil ? '' : @names[@index])
  184.     @sprites[1].chapter = @keys[@index]
  185.     # Transition Graphics.
  186.     Graphics.transition
  187.     # Main loop.
  188.     loop { Graphics.update; Input.update; update; break if $scene != self }
  189.     # Dispose windows.
  190.     Graphics.freeze
  191.     @sprites.each {|sprite| sprite.dispose }
  192.   end
  193.   
  194.   def update
  195.     # Branch by what input is recieved.
  196.     if Input.repeat?(Input::UP) || Input.trigger?(Input::UP)
  197.       $game_system.se_play($data_system.cursor_se)
  198.       @sprites[1].oy -= 32 if @sprites[1].oy if @sprites[1].oy > 0
  199.     elsif Input.repeat?(Input::DOWN) || Input.trigger?(Input::DOWN)
  200.       $game_system.se_play($data_system.cursor_se)
  201.       @sprites[1].oy += 32 if @sprites[1].oy < (@sprites[1].contents.height-384)
  202.     elsif Input.trigger?(Input::L) || Input.trigger?(Input::R)
  203.       $game_system.se_play($data_system.decision_se)
  204.       # Change the current index.
  205.       @index += Input.trigger?(Input::L) ? -1 : 1
  206.       @index %= @keys.size
  207.       # Display the name of the current chapter in the header.
  208.       @sprites[0].set_text(@names[@index], 1)
  209.       # Change the current chapter.
  210.       @sprites[1].chapter = @keys[@index]
  211.     elsif Input.trigger?(Input::B)
  212.       # Play cancel SE and return to the defined scene.
  213.       $game_system.se_play($data_system.cancel_se)
  214.       args, scene = Diary::SCENE_ARGUMENTS, Diary::RETURN_SCENE
  215.       $scene = (args == []) ? scene.new : scene.new(*args)
  216.     end
  217.   end
  218.   
  219. end
  220.  
  221. #===============================================================================
  222. # ** Game_Party
  223. #===============================================================================
  224.  
  225. class Game_Party
  226.   
  227.   attr_accessor :diary
  228.   
  229.   alias zer0_diary_init initialize
  230.   def initialize
  231.     zer0_diary_init
  232.     @diary = {}
  233.   end
  234. end
Expand to see the code.


Instructions

Place script below default scripts, and above "Main".
Instructions are in the script.

Compatibility

No known issues.

Credits and Thanks

  • ForeverZer0, for the script.
  • Blizzard, for the "slice_text" method I always steal.
  • Lauros, for requesting it.

Author's Notes

Please report any bugs/issues so that they can be resolved. Enjoy!

Terms and Conditions

Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
Content Hidden Spoiler
You are free:

to Share - to copy, distribute and transmit the work
to Remix - to adapt the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Noncommercial. You may not use this work for commercial purposes.

Share alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

- For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.

- Any of the above conditions can be waived if you get permission from the copyright holder.

- Nothing in this license impairs or restricts the author's moral rights.
Wow, looks awesome. I really wish this script existed a few years ago when I first started working on Vacant Sky.
I'll probably look into your script when making my FFXIII Menu script.
Couple questions/suggestions/bugs:
1. How does one use the "arguments" feature?
2. How would one check if a diary entry has been added? (to prevent the same one from being added twice)
3. The chapter title starts out left-justified (uncentered). You need to add ", 1" to line 183.
@sprites[0].set_text(@names[@index] == nil ? '' : @names[@index], 1)

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=74938