I can't find any decent script which has a diary like book to write notes on so I started editing foreverzer0's diary script.
I managed to put a picture as background, managed to move some of the font (Can't find which line moves the chapter's line) and managed to lower the font size BUT for some odd reason the font type doesn't want to change nor the font color eventhough the script command is written correct.
Also when I close the window the picture goes as it should but the window with the words, etc stays for a bit longer then goes off.
This is the edited script:
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# 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_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(35, 50, 265, 416) #0, 64, 640, 416
self.opacity = Diary::MAP_BACKGROUND ? 0 : 0
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Zephyr"
self.contents.font.size = 20
self.contents.font.color = Color.new(0, 0, 0, 255)
@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, 80) } #608
@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)
# Draw each line.
@lines.each_index {|i| self.contents.draw_text(0, i*32, 608, 32, @lines[i])}# 0, i*32, 608, 32
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
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
@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)
# 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
end
end
#===============================================================================
# ** Game_Party
#===============================================================================
class Game_Party
attr_accessor :diary
alias zer0_diary_init initialize
def initialize
zer0_diary_init
@diary = {}
end
end
Could anyone help?
Thanks
Also here's a picture of what I'm trying to do:
(http://img152.imageshack.us/img152/6277/diary.png)
The Chapter should be written on the top while the rest of the words under it.
The only flaw I have is that I can only write on the left page of the diary because I resized the window to be able to move it on the left page.
The font doesn't change because the refresh method disposes the bitmap and recreates it. Just move your font change line to after the "self.contents.dispose" line and after it is recreated.
It worked! Tough the chapter line font color is still default.
Been looking at the script for hours it's driving me crazy.
Thanks for the help.
[Edit]
Uploading a picture of my current version and to show you the problem on chapter font not wanting to change color:
(http://img27.imageshack.us/img27/9827/diary2.png)
I tried several things like:
@sprites[0].contents.font.color = Color.new(0,0,0)
Or even adding a new color in window base and try changing it to it but nothing happens on the chapter's color :S.
To be able to change the font and move the chapter I had to put the pieces of coding in scene diary instead of window diary.
Any help?
Also I was thinking on the possibility of having text also on the right side of the diary but I have no idea on how could I do it. I was thinking on maybe having 2 chapters showing, chapter 1 on left page, chapter 2 on right page then you switch to chapter 3,4 etc etc.
Would it be hard to implement?
Thanks
It doesn't change because the scene uses Window_Help, and the "set_text" method in that script sets the color to "normal_color" right before it draws. Here's an extension to Window_Help that will allow you to fix it. Modify the "set_text" method to use a "color" argument that sets the color.
class Window_Help
def set_text(text, align = 0, color = normal_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 = 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
Thanks that worked perfectly!
I added some extra lines to edit the window size too to fit only 1 page.
Would you mind helping me on 1 last tiny thing?
When I test the diary the chapter words show on the far left near the border then when I switch chapter they get aligned to the middle, what do I have to do so that the chapter words doesn't get aligned so I won't have problems with long chapter names in the future if I ever needed it.
Thanks
[Edit]
Meh even on the normal text when I switch page they are getting screwed with the align eventough the window is the size of a page the words keep on going. :/
Here's a pic to show the problem:
(http://img805.imageshack.us/img805/6740/diaryod.png)
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# 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
For what you are doing, it would probably be better to simply avoid using Window_Help, and create a an instance of Window_Base, and simply use #draw_text() so you have better control over the coordinates.
Either way, you are not forced to use the "set_text" method for Window_Help. I suggest leaving its size alone so it doesn't screw up other scenes, and use @sprites[0].draw_text(x, y, width, height, text, alignment) to draw the chapter names.
I managed to stop alignment on chapters now I need to figure out how to stop it on the actual paragraph :P
Ps. For the chapter line to stop being aligned all I had to do is remove the align part from the piece of code you posted.
Now I finally got what you meant with avoiding window_help as it makes the font colour of every window that calls it the same colour of the diary scene but I don't know how to do what you said by scripting.
I tried adding < Window_Base in front of window_help but that did nothing it seems.
Also I can't find a solution for the alignment problem on the actual text page. I managed to solve the align on the chapter from the piece of code you posted of window help by removing the @align part from draw text but have no idea what I have to do on the other part where it shows the text as it keeps on getting aligned when I switch page :/.
Any help on the problem?
No need for exactly foreverzer0 to help me I just can't figure out why the text gets aligned after I switch page but when I enter firstly It doesn't align.
I don't really need the align.
Thanks
Bump
I still can't figure out what to edit to stop the alignment after switching pages please some help.
Please no one can help?
:/
What do you mean by the paragraph is not aligning? Do you mean, in that image you posted, the paragraph/diary entry is being cut off on the edges? If so click below:
Well, from a scripter's point of view, the problem I saw was this:
@sprites = [Window_Help.new, Window_Diary.new]
#further down the script, upon pressing 'L' or 'R'
@sprites[1].chapter = @keys[@index]
These are calling entirely new Window instances every time. Looking back at Window_Diary, 'def chapter=' is also where the "format the line of text into a paragraph" (slice_text) process occurs. Windows default to a font_size of 22. The slice_text method takes this font_size into account. However, you have it where the font_size is 33 when being drawn, thus making the slice_text method useless.
I did something like this:
def chapter=(chapter)
# Reset the current entries.
self.contents.font.name = "Arial"
self.contents.font.size = 33
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
and I wasn't getting any cut-off text. (Side note, I put the font style as Arial because I don't have that long-named font you have)
First of all thank you for the help, now to answer your questions:
What I mean is when I launch the diary scene everything looks fine but when I switch page the text gets aligned differently and some is cut off the page as shown on the picture.
I placed the font name and size near bitmap because if you put them where you placed them the font doesn't change.
Also the font = 32 is for the chapter's name not for the actual paragraph.
------
I just tried your edit and it does indeed stop the font from being realigned when I switch page but it also stop the text from being organised in a way (When a certain word is too long to fit in the line instead of the whole word going on the next line the words that can fit on the first line stay there, the rest go on the 2nd line)
I keep on trying to edit the text slice number from 260 to higher but the problem persists in some way.
Anything can be done?
Thanks
Make me up a quick demo demonstrating the problem and I'll fix it up.
Made a small demo with a box to add pages and the book on the floor to launch the scene then switch chapter with W/D and when you go back to the first page you'll see that the text has changed.
http://www.mediafire.com/?gb74vun20hok1n5
Would it be hard for me to try and have chapter 1 show on the left and chapter 2 on the right and when you switch chapters then 3 on the left and 4 on the right and so on?
I already tried something but have almost 0 clue on what to do as I know nothing about scripting apart of small edits/changes/additions.
Thanks for the help.
def slice_text(text, width)
words = text.split('')
Ummm...why is there no space between the quotes?
Also, if the words are getting cut off, reduce that 260 to a smaller number; making it bigger will only make it worse.
Yeah... um, I wanted to try and make paragraphs into the text but having a space between that line makes it impossible since having a lot of spaces get ignored.
There could be another way on doing it but I couldn't find one when I was fooling around.
I've made an edit for that before. Found it in one of my old scripts:
class Bitmap
def slice_text(text, width)
words = text.split(' ')
return words if words.size == 1
result, current_text = [], words.shift
#loop
words.each_index {|i|
if self.text_size("#{current_text} #{words[i]}").width > width or words[i] == "/n"
#Checks if '/n' is the current word.
if words[i] == "/n"
result.push(current_text)
current_text = ""
else
result.push(current_text)
current_text = words[i]
end
else
# True if the previous word was '/n'
if current_text == ""
current_text = words[i]
else
current_text = "#{current_text} #{words[i]}"
end
end
#Push the last word in
result.push(current_text) if i >= words.size - 1}
#end loop
return result
end
end
Test string on how to use it:
'I Forgot Today was the day of the big fair! /n /n I was supposed to go and see Lucca\'s new invention.'
Worked, thanks!
It's neater this way.
Now if the alignment problem gets fixed I'd be very happy :)
+1 to you people for the help.
Simply change the value of 260 for the slice width to self.contents.width, and add the space back to the slice method. Having no space kinda defeats the purpose of having such a method.
Also, reduce the text size a bit. A text size of 32 or whatever you had, plus using only half the screen looks bad in my opinion.
EDIT:
Forgot to mention that your demo doesn't even include the multipage type of implementation you had. I thought that's what you wanted fixed?
The 32 size is only for the chapter, for the actual text it's like 30 but the font is very small by nature so I have to use bigger numbers.
It looks like this:
(http://img804.imageshack.us/img804/8125/diary3i.png)
(Don't mind the spaces I was just trying KK20's edit)
Also your right, having text only on the left is kinda bad but unless I get help and someone edits the script so 2 chapters show instead of 1 I don't have any other solution apart of editing the picture and placing a pen on the right page or something.
Anyway placing self.contents.width solved text being shown in half but for some reason first time I enter the scene the text is showing different than after I switch page. The script is identical to that of the demo apart of using KK20's edit to let me make paragraphs.
[Edit]
I don't have a multi page edit I was asking if it would be hard to do despite me not knowing anything about scripting apart of simple edits and stuff.
I made 2 edits the demo you supplied that I mentioned above:
Changed 260 to self.contents.width
Changed the slice_text method to split using ' ' instead of ''.
It does not do that.
By slice method you mean this right:
def slice_text(text, width)
words = text.split(' ')
That's how it is in the script plus:
@lines = entries.collect {|text| self.contents.slice_text(text, self.contents.width) }
The text problem can be seen when you enter the first time the text looks like this:
(http://img594.imageshack.us/img594/6732/diaryq.png)
Then when I switch to the next chapter and back to the first chapter (In the demo you can use W) it turns like this:
(http://img577.imageshack.us/img577/4923/diary2z.png)
The same thing happens to the 2nd chapter and I've been trying to solve this problem for ages now.
It appears the width of the bitmap or the window is different from what it was when the window was first created. That's what is causing the varied text width.
Anyways, I added a few lines of code to show you how to make it multipage.
Its not really complete or anything, but is enough to get started on.
https://dl.dropbox.com/u/20787370/Temp/Demo.exe
Only "solution" I found for the text is having this piece:
That creates first bitmap having changed 270 to 640 then no text align problems but well you know the text goes over the 2nd page of the diary's picture. (And if I manage to make 2 chapter show I can't have that either.)
I downloaded the same font as well as copied your diary picture and threw them in my project for the heck of it. By using the 'self.contents.width' when calling 'slice_text' removed your posted issues. When I used a higher value of width, I was getting what you were getting. So, even with the implementation of that, if you are still getting incorrectly spliced text, your script is seriously bugged.
The problem resides with the bitmap because the script creates a bitmap when you enter the scene for the first time and mine has been edited to be half a screen instead of the whole screen but every time you switch chapters a new bitmap is created which for some reason has different width resulting in the text looking different.
Think you can post EXACTLY what you have right now? I cannot, for the life of me, understand why I cannot reproduce your error using the demo you provided.
Sure, here:
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# 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! /n 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, 270, 480) #48, 50, 270, 480
self.opacity = Diary::MAP_BACKGROUND ? 0 : 0
self.contents = Bitmap.new(width - 32, height - 32)
@lines = []
end
def chapter=(chapter)
if chapter == nil
self.contents.clear
return
end
# 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, self.contents.width) }
@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 = 30
self.contents.font.color = diary_color
# Draw each line.
@lines.each_index {|i| self.contents.draw_text(0, i*32, 608, 32, @lines[i])} #i*32, 608, 32
end
end
#===============================================================================
# ** Window_Help
#===============================================================================
class Window_Help < Window_Base
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
def slice_text(text, width)
words = text.split(' ')
return words if words.size == 1
result, current_text = [], words.shift
#loop
words.each_index {|i|
if self.text_size("#{current_text} #{words[i]}").width > width or words[i] == "/n"
#Checks if '/n' is the current word.
if words[i] == "/n"
result.push(current_text)
current_text = ""
else
result.push(current_text)
current_text = words[i]
end
else
# True if the previous word was '/n'
if current_text == ""
current_text = words[i]
else
current_text = "#{current_text} #{words[i]}"
end
end
#Push the last word in
result.push(current_text) if i >= words.size - 1}
#end loop
return result
end
end
#===============================================================================
# ** Scene_Diary
#===============================================================================
class Scene_Diary
FONT_NAME = "where stars shine the brightest"
FONT_SIZE = 32
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.
Graphics.freeze
@sprites.each {|sprite| sprite.dispose }
@diary.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
I simple have no clue but I need it to work soon as I finished mapping the hospital and starting the outside town and when I'm done on mapping I'll start producing some of the story written on said diary.
I don't understand why my first post fix wasn't there, the part where I said in "def chapter=" the method "slice_text" is being called. The first time this happens (when you open the diary/first taken into the Scene_Diary) it uses the font Arial and size 22 to determine how to format the line of text. All other entries will then revert to using your custom font and size 30 to format the text.
Reposting the fix:
def chapter=(chapter)
if chapter == nil
self.contents.clear
return
end
# Reset the current entries.
entries = $game_party.diary[chapter]
entries = [''] if entries == nil
self.contents.font.name = "where stars shine the brightest"
self.contents.font.size = 30
# Divide the current entries into lines based off the text size and length.
@lines = entries.collect {|text|
self.contents.slice_text(text, self.contents.width) }
@lines.flatten!
refresh
end
If that's not the solution, then the problem is outside of the script. I'm getting evenly formatted text here.
Yay! that did the trick!!
Thank you so much :)
And now that problem is finally solved I'll try and find a way to get 2 chapters showing one on the left and the other on the right to make the diary look better or just give up and put a pen on the right page and end it there.