#==============================================================================
# ** Window_CharInfo
#------------------------------------------------------------------------------
# This window displays information about a character.
#
# Modify the @desc hash to include your names & descriptions
# don't forget the commas. (every line except the last)
#
# use $scene = Scene_CharInfo.new("name") to call from map event
#
# For the sprite area, it looks in Graphics/Characters for <name>.png
# if it doesn't find it, it leaves this area blank
#
# For the name area, it looks in Graphics/Pictures for <name>.png
# if it doesn't find it, it prints the name in larger text.
#
# Credits: Brewmeister, Trickster (draw_wrap_text)
#==============================================================================
class Window_CharInfo < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(character)
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
@character = character
#------------------------------------------------
# create a hash with the descriptions
# enter a lower case 'p' by itself for a line break
#------------------------------------------------
@desc = {
"name 1" => "Description for name 1.",
"name 2" => "one. p Two",
"name 3" => "Thank you, Trickster."
}
#------------------------------------------------
# create a hash with the descriptions
#------------------------------------------------
@desc.default = "I couldn't find a description for that name"
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Draw the seperators
black = Color.new(0,0,127,255)
self.contents.fill_rect(95, 0, 1, 96, black)
self.contents.fill_rect(96, 0, 1, 96, normal_color)
self.contents.fill_rect(0, 95, 608, 1, black)
self.contents.fill_rect(0, 96, 608, 1, normal_color)
# Draw the character sprite
if FileTest.exist?("Graphics/Characters/" + @character + ".png")
cbm = RPG::Cache.character(@character, 0)
cw = cbm.width / 4
ch = cbm.height / 4
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt((88 - cw) / 2, (88 - ch) / 2, cbm, src_rect)
end
# Draw the name (picture or text)
if FileTest.exist?("Graphics/Pictures/" + @character + ".png")
nbm = RPG::Cache.picture(@character)
src_rect = Rect.new(0, 0, nbm.width, nbm.height)
self.contents.blt(348 - nbm.width / 2, (88 - nbm.height) / 2, nbm, src_rect)
else
self.contents.font.size = 44
self.contents.draw_text(100, 12, 504, 64, @character, 1)
end
# Draw the description
text = @desc[@character]
self.contents.font.size = 22
self.contents.draw_wrap_text(4, 100, 600, 28, text)
end
end
#==============================================================================
# ** Scene_CharInfo
#------------------------------------------------------------------------------
# This class calls the Character Info Window
#==============================================================================
class Scene_CharInfo
def initialize(character, callback = 0)
@character = character
@callback = callback
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make info window
@info_window = Window_CharInfo.new(@character)
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame Update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of window
@info_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# If B button was pressed
if Input.trigger?(Input::B) || Input.trigger?(Input::C)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch back to calling scene
if @callback
$scene = Scene_Menu.new(4)
else
$scene = Scene_Map.new
end
return
end
end
end
#==============================================================================
# ** Bitmap Class Add-ons from MACL 2.1
# NOTE: If you have the MACL, don't delete this.
# Make sure this is below the MACL
#------------------------------------------------------------------------------
class Bitmap
#--------------------------------------------------------------------------
# * Dummy Bitmap
#--------------------------------------------------------------------------
@@dummy = Bitmap.new(32, 32)
attr_accessor :dummy
#--------------------------------------------------------------------------
# Name : Text Size
# Info : Gets text size based off dummy bitmap
# Author : SephirothSpawn
# Call Info : One Argument, a String
#--------------------------------------------------------------------------
def Bitmap.text_size(text)
return @@dummy.text_size(text)
end
#-------------------------------------------------------------------------
# Name : Draw Wrapped Text
# Info : Draws Text with Text Wrap
# Author : Trickster
# Call Info : Five Arguments
# Integer X and Y, Define Position
# Integer Width, defines the width of the text rectangle
# Integer Height, defines the height of the text
# String Text, Text to be drawn
# Modified : Brew. Add 'p' for line breaks
#-------------------------------------------------------------------------
def draw_wrap_text(x, y, width, height, text)
# Get Array of Text
strings = text.split
# Run Through Array of Strings
strings.each do |string|
# Get Word
word = string + ' '
# If p, move to next line
if string == "p"
x = 0
y += height
next
end
# Get Word Width
word_width = text_size(word).width
# If Can't Fit on Line move to next one
x, y = 0, y + height if x + word_width > width
# Draw Text Memory
self.draw_text(x, y, word_width, height, word)
# Add To X
x += word_width
end
end
end