#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# Diary Scene
# Author: ForeverZer0
# Version: 1.0
# Date: 12.18.2010
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
#
# 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.
#
# Instructions:
#
# - Place script above main, and below default scripts.
# - Make configurations below.
# - To call the scene, use this syntax: $scene = Scene_Diary.new
# - To add an entry, use this syntax:
#
# Diary.add_entry(CHAPTER, TEXT)
#
# CHAPTER: An arbitrary integer to define what group to add the note to.
# TEXT: Either a string which will be the text added to the diary, or an
# integer which will return the string defined in the configuration
# below. The second method will make it easier to make long notes
# without filling up the little script call box.
#
# Author's Notes:
#
# - Please be sure to report any bugs/issues with the script. Enjoy!
#
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
module Diary
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# BEGIN CONFIGURATION
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MAP_BACKGROUND = false
# Set to true if you would like the map to show behind the window.
RETURN_SCENE = Scene_Menu.new(2)#Scene_Map
# The scene that the game returns to when you exit the diary.
SCENE_ARGUMENTS = []
# Define any arguments that may need called with scene if need be. Place them
# in the array in the order in which they are normally called.
def self.chapter_name(chapter)
# Define the names of the "chapters".
# when CHAPTER then "CHAPTER_NAME"
return case chapter
when 1 then 'Millenium Fair'
when 2 then 'What Happened to Marle?'
end
end
def self.entry(index)
# Define the strings that correspond with each index. The index can be called
# instead of actual text to add an entry.
# when INDEX then "TEXT"
return case index
when 0 then 'I Forgot Today was the day of the big fair! I was supposed to go and see Lucca\'s new invention.'
when 1 then 'I need to escort Marle around the fair, and maybe play a few games.'
when 2 then 'Marle was sucked into the vortex. I think it had something to do with that pendant that she was wearing...'
when 3 then 'This place is very strange, and everyone talks funny. It\'s all vaguely the same, yet different. Where am I?'
end
end
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END CONFIGURATION
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
def self.add_entry(chapter, text)
# Add the chapter number if it does not exist.
if $game_party.diary[chapter] == nil
$game_party.diary[chapter] = []
end
if text.is_a?(String)
# Add the new entry to the end of the chapter.
$game_party.diary[chapter].push(text)
elsif text.is_a?(Integer)
# Get the defined note if the text is a number.
$game_party.diary[chapter].push(self.entry(text))
end
end
end
#===============================================================================
# ** Window_Diary
#===============================================================================
class Window_Diary < Window_Base
attr_reader :lines
def initialize
super(48, 50, 265, 480) #0, 64, 640, 416
self.opacity = Diary::MAP_BACKGROUND ? 0 : 0
self.contents = Bitmap.new(width - 32, height - 32)
@lines = []
end
def chapter=(chapter)
# Reset the current entries.
entries = $game_party.diary[chapter]
entries = [''] if entries == nil
# Divide the current entries into lines based off the text size and length.
@lines = entries.collect {|text| self.contents.slice_text(text, 260) } #260
@lines.flatten!
refresh
end
def refresh
# Dispose bitmap, returning if no lines are defined.
self.contents.clear
return if @lines.size == 0
self.contents.dispose
# Create bitmap to contain the lines.
self.contents = Bitmap.new(self.width - 32, @lines.size * 32)
self.contents.font.name = "where stars shine the brightest"
self.contents.font.size = 33
self.contents.font.color = diary_color
# Draw each line.
@lines.each_index {|i| self.contents.draw_text(0, i*32, 608, 32, @lines[i])}
end
end
#===============================================================================
# ** Window_Help
#===============================================================================
class Window_Help
def initialize
super(48, 0, 200, 60) #0, 64, 640, 416
self.contents = Bitmap.new(width - 32, height - 32)
end
def set_text(text, align = 0, color = diary_color)
# If at least one part of text and alignment differ from last time
if text != @text or align != @align
# Redraw text
self.contents.clear
self.contents.font.color = diary_color
self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
@text = text
@align = align
@actor = nil
end
self.visible = true
end
end
#===============================================================================
# ** Bitmap
#===============================================================================
class Bitmap
# Blizzard's slice_text method. This method can be removed if you have another
# script that already uses it.
def slice_text(text, width)
words = text.split(' ')
return words if words.size == 1
result, current_text = [], words.shift
words.each_index {|i|
if self.text_size("#{current_text} #{words[i]}").width > width
result.push(current_text)
current_text = words[i]
else
current_text = "#{current_text} #{words[i]}"
end
result.push(current_text) if i >= words.size - 1}
return result
end
end
#===============================================================================
# ** Scene_Diary
#===============================================================================
class Scene_Diary
FONT_NAME = "where stars shine the brightest"
FONT_SIZE = 34
def main
@diary = Sprite.new
@diary.bitmap = RPG::Cache.picture("Diary.png") #rescue nil
# Create the windows.
@sprites = [Window_Help.new, Window_Diary.new]
if Diary::MAP_BACKGROUND
@sprites.push(Spriteset_Map.new)
@sprites[0].opacity = 0 #160
end
@sprites[0].opacity = 0 #160
#@sprites[0].x = 45
@sprites[0].contents.font.name = FONT_NAME
@sprites[0].contents.font.size = FONT_SIZE
@keys = $game_party.diary.keys.sort
@names = @keys.collect {|chapter| Diary.chapter_name(chapter) }
# Find current index, setting to first chapter if undefined.
@index = @keys.index(Diary.chapter_name(@chapter))
@index = 0 if @index == nil
# Set the information for each window.
@sprites[0].set_text(@names[@index] == nil ? '' : @names[@index])
@sprites[1].chapter = @keys[@index]
# Transition Graphics.
Graphics.transition
# Main loop.
loop { Graphics.update; Input.update; update; break if $scene != self }
# Dispose windows.
@diary.dispose
Graphics.freeze
@sprites.each {|sprite| sprite.dispose }
end
def update
# Branch by what input is recieved.
if Input.repeat?(Input::UP) || Input.trigger?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@sprites[1].oy -= 32 if @sprites[1].oy if @sprites[1].oy > 0
elsif Input.repeat?(Input::DOWN) || Input.trigger?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
@sprites[1].oy += 32 if @sprites[1].oy < (@sprites[1].contents.height-384)
elsif Input.trigger?(Input::L) || Input.trigger?(Input::R)
#$game_system.se_play($data_system.decision_se)
Audio.se_play('Audio/SE/046-Book01', volume = 80, pitch = 100)
# Change the current index.
@index += Input.trigger?(Input::L) ? -1 : 1
@index %= @keys.size
# Display the name of the current chapter in the header.
@sprites[0].set_text(@names[@index], 1)
# Change the current chapter.
@sprites[1].chapter = @keys[@index]
elsif Input.trigger?(Input::B)
# Play cancel SE and return to the defined scene.
#$game_system.se_play($data_system.cancel_se)
#args, scene = Diary::SCENE_ARGUMENTS, Diary::RETURN_SCENE
#$scene = (args == []) ? scene.new : scene.new(*args)
#end
# Play cancel SE
#$game_system.se_play($data_system.cancel_se)
Audio.se_play('Audio/SE/047-Book02', volume = 90, pitch = 100)
# Switch to menu screen
$scene = Scene_Menu.new(2)
return
end
end
end
#===============================================================================
# ** Game_Party
#===============================================================================
class Game_Party
attr_accessor :diary
alias zer0_diary_init initialize
def initialize
zer0_diary_init
@diary = {}
end
end