Dunnit.
#===============================================================================
# Notebook Menu (VXA)
# By Jet10985 (Jet) - converted to VXA by Pacman (21/10/12)
#===============================================================================
# This script will add a Notebook menu to the game, which can be used to add
# entries to the notebook that the player can read.
# This script has: 6 customization options.
#===============================================================================
=begin
To use this script, you need to have a folder in your game directory called
Notebook
This is where your .txt files should be located.
This script runs solely on the .txt files in the folder, and it's where it
grabs the files for the .rvdata2 conversion if used.
--------------------------------------------------------------------------------
To add new entries to the journal, use this in an event "Script..." command
add_entry("filename")
"filename" should be the name of a .txt file in the Notebook folder, excluding
the .txt. So say i have a file called Test.txt: add_entry("Test")
Even if you use the .rvdata file, the filenames stay the same so make sure
you remember your filenames.
--------------------------------------------------------------------------------
You can call the journal scene with this code in an event "Script..." command:
goto_notebook
The journal scene will be inaccessable unless the player has at least 1 entry
--------------------------------------------------------------------------------
If the text entry is too long height-wise to be shown completely, then the
player needs to use (left) to scroll up, or (right) to scroll down.
--------------------------------------------------------------------------------
To force a next line in the text, put \line inside the .txt file where you
want to force text to the next line
=end
module Notebook
# Would you like to convert all .txt files in the "Notebook" folder to a
# .rvdata data file which can be encrpyted with the game, and used with
# the USE_RVDATA_FILE option?
DO_CONVERSION_TO_RVDATA = false
# Would you like to use the Notebook.rvdata file generated with the
# DO_CONVERSION_TO_RVDATA instead of the .txt files in the "Notebook" folder?
USE_RVDATA_FILE = false
# What is the notebook called?
NOTEBOOK_NAME = "Notebook"
# What font does the notebook use? The first item is the primary font you
# want, and it will go through each item if the font doesn't exist
# until it finds a font that does exist.
NOTEBOOK_FONT = ["Verdana", "Arial", "Courier New"]
# What is the font size in the notebook? 20 is default
NOTEBOOK_FONT_SIZE = 20
# How much space will be given for each line? 24 is default
NOTEBOOK_WLH = 24
end
#===============================================================================
# DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
#===============================================================================
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :notebook_entries
#--------------------------------------------------------------------------
# Alias listing
#--------------------------------------------------------------------------
alias jet1835_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args, &block)
@notebook_entries = []
jet1835_initialize(*args, &block)
end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Add Notebook Entry to Database
#--------------------------------------------------------------------------
def add_entry(filename)
unless $game_system.notebook_entries.include?(filename)
$game_system.notebook_entries.push(filename)
end
end
#--------------------------------------------------------------------------
# * Activate Notebook Scene
#--------------------------------------------------------------------------
def goto_notebook
SceneManager.goto(Scene_Notebook)
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs the title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# Alias listing
#--------------------------------------------------------------------------
alias jet1934_initialize initialize unless $@
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args, &block)
convert_txt if Notebook::DO_CONVERSION_TO_RVDATA && $TEST
jet1934_initialize(*args, &block)
end
#--------------------------------------------------------------------------
# * Convert text from .txt to .rvdata2
#--------------------------------------------------------------------------
def convert_txt
file = Dir.entries("Notebook")
file.reverse!
2.times {|i| file.pop }
file.reverse!
if file.empty?
p "No files found in Notebook, aborting conversion process."
end
text_hash = {}
for txt in file
text_hash[txt] = File.open("Notebook/#{txt}", "r") {|a| a.read}
end
b = File.new("Data/Notebook.rvdata2", "wb")
Marshal.dump(text_hash, b)
b.close
p "Notebook file successfully converted."
end
end
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
# The string class. Can handle character sequences of arbitrary lengths.
# See String Literals for more information.
#==============================================================================
class String
#--------------------------------------------------------------------------
# * Split to each word
#--------------------------------------------------------------------------
def each_word
array = self.split(" ")
if block_given?
array.each {|a| yield a }
else
return array
end
end
end
#==============================================================================
# ** Window_Notebook
#------------------------------------------------------------------------------
# This window displays the note currently open.
#==============================================================================
class Window_Notebook < Window_Base
#--------------------------------------------------------------------------
# Include Notebook module
#--------------------------------------------------------------------------
include Notebook
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(filename)
super(160, 56, Graphics.width - 160, Graphics.height - 56)
@filename = filename
refresh(@filename)
end
#--------------------------------------------------------------------------
# * Refresh window
#--------------------------------------------------------------------------
def refresh(filename)
self.oy = 0
form_bitmap_rect(filename)
self.contents.font.name = NOTEBOOK_FONT
self.contents.font.size = NOTEBOOK_FONT_SIZE
wlh = NOTEBOOK_WLH
i = 0
@file_text.each_line {|line|
text = line.gsub(/\r|\n/i, "")
self.contents.draw_text(0, 0 + i * wlh, self.width - 32, wlh, text)
i += 1
}
end
#--------------------------------------------------------------------------
# * Form Contents (or whatever)
#--------------------------------------------------------------------------
def form_bitmap_rect(filename)
if USE_RVDATA_FILE
file = load_data("Data/Notebook.rvdata2")[filename + ".txt"]
else
file = File.open("Notebook/#{filename}.txt", "r") {|a| a.read }
end
new_text = ""
width_taken = 0
height_taken = 0
file.gsub!(/\r\n/i, " ")
file.gsub!(/\\line/i, " \\xjet ")
file.each_word {|word|
width_taken += self.contents.text_size("#{word} ").width
if word == "\\xjet"
width_taken = 0
new_text.concat("\n")
height_taken += NOTEBOOK_WLH
elsif width_taken > self.width - 32
width_taken = 0
new_text.concat("\n#{word} ")
width_taken += self.contents.text_size("#{word} ").width
height_taken += NOTEBOOK_WLH
else
new_text.concat("#{word} ")
end
}
@file_text = new_text
@height_taken = height_taken
self.contents = Bitmap.new(self.width - 32, @height_taken + 32)
end
end
#==============================================================================
# ** Window_NoteCommand
#------------------------------------------------------------------------------
# This window is the selection window for the notebook entries.
#==============================================================================
class Window_NoteCommand < Window_Command
#--------------------------------------------------------------------------
# * Form list of commands
#--------------------------------------------------------------------------
def make_command_list
for entry in $game_system.notebook_entries
add_command(entry, :entry)
end
end
end
#==============================================================================
# ** Window_Entries
#------------------------------------------------------------------------------
# This window displays the number of entries in the notebook database.
#==============================================================================
class Window_Entries < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, Graphics.height - 54, 160, 54)
refresh
end
#--------------------------------------------------------------------------
# * Refresh window
#--------------------------------------------------------------------------
def refresh
contents.clear
contents.font.color = system_color
contents.draw_text(0, 0, 100, 24, "Entries:")
contents.font.color = normal_color
contents.draw_text(104, 0, 40, 24, $game_system.notebook_entries.size, 1)
end
end
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
# This class performs notebook screen processing.
#==============================================================================
class Scene_Notebook < Scene_Base
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
def start
if $game_system.notebook_entries.empty?
return_scene
end
super
@help_window = Window_Help.new
@help_window.set_text(Notebook::NOTEBOOK_NAME)
@command_window = Window_NoteCommand.new(0, 0)
@command_window.height = Graphics.height - 110
@command_window.y = @help_window.height
@entries_window = Window_Entries.new
@notebook_window = Window_Notebook.new($game_system.notebook_entries[0])
@command_window.height = Graphics.height - (@entries_window.height +
@help_window.height)
@notebook_window.y = @command_window.y
@notebook_window.height = Graphics.height - @help_window.height
end
#--------------------------------------------------------------------------
# * Frame update
#--------------------------------------------------------------------------
def update
old_index = @command_window.index
super
if old_index != @command_window.index
@notebook_window.refresh(@command_window.current_data)
end
@notebook_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
SceneManager.goto(Scene_Map)
end
if @notebook_window.contents.height > @notebook_window.height - 32
wlh = Notebook::NOTEBOOK_WLH
if Input.trigger?(Input::RIGHT)
@notebook_window.oy = [@notebook_window.oy + wlh,
@notebook_window.contents.height - @notebook_window.height + 32].min
elsif Input.trigger?(Input::LEFT)
@notebook_window.oy = [@notebook_window.oy - wlh, 0].max
end
end
end
end
#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Let me know if anything's wrong.