ForeverZer0's Diary Script Edit

Started by Vexus, May 18, 2012, 12:54:29 pm

Previous topic - Next topic

Vexus

June 14, 2012, 08:03:44 pm #20 Last Edit: June 14, 2012, 08:05:35 pm by Vexus
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:

Spoiler: ShowHide


(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.
Current Project/s:

ForeverZer0

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.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Vexus

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:

Spoiler: ShowHide


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:

Spoiler: ShowHide


The same thing happens to the 2nd chapter and I've been trying to solve this problem for ages now.
Current Project/s:

ForeverZer0

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
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Vexus

June 14, 2012, 08:56:50 pm #24 Last Edit: June 14, 2012, 08:58:40 pm by Vexus
Only "solution" I found for the text is having this piece:

super(48, 50, 270, 480)


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.)
Current Project/s:

KK20

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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Vexus

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.
Current Project/s:

KK20

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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Vexus

Sure, here:

Spoiler: ShowHide
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# 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.
Current Project/s:

KK20

June 15, 2012, 05:00:53 pm #29 Last Edit: June 15, 2012, 05:02:31 pm by KK20
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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Vexus

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.
Current Project/s: