Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Sprite_Picture
- #------------------------------------------------------------------------------
- # This sprite is used to display pictures. It observes an instance of the
- # Game_Picture class and automatically changes sprite states.
- #==============================================================================
- class Sprite_Face < Sprite
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :face_name
- attr_reader :face_index
- #--------------------------------------------------------------------------
- # * Object Initialization
- # picture : Game_Picture
- #--------------------------------------------------------------------------
- def initialize(viewport, face_name = nil, face_index = 0)
- super(viewport)
- @face_name = face_name
- @face_index = face_index
- update
- end
- #--------------------------------------------------------------------------
- # * Set Face
- #--------------------------------------------------------------------------
- def set_face(face_name, face_index)
- @face_name = face_name
- @face_index = face_index
- update
- end
- #--------------------------------------------------------------------------
- # * Free
- #--------------------------------------------------------------------------
- def dispose
- bitmap.dispose if bitmap
- super
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- update_bitmap
- end
- #--------------------------------------------------------------------------
- # * Update Transfer Origin Bitmap
- #--------------------------------------------------------------------------
- def update_bitmap
- if @face_name == nil
- self.bitmap = nil
- else
- self.bitmap = Cache.face(@face_name)
- w = self.bitmap.width
- h = self.bitmap.height
- rect = Rect.new(@face_index % 4 * w/4, @face_index / 4 * h/2, w/4, h/2)
- self.src_rect = rect
- end
- end
- end
- #==============================================================================
- # ** Game_Message
- #------------------------------------------------------------------------------
- # This class handles the state of the message window that displays text or
- # selections, etc. The instance of this class is referenced by $game_message.
- #==============================================================================
- class Game_Message
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :shortcuts
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- alias :pre_me_initialize :initialize unless $@
- def initialize
- @shortcuts = {}
- pre_me_initialize # original function
- end
- #--------------------------------------------------------------------------
- # * Shortcuts getter
- #--------------------------------------------------------------------------
- def shortcuts; return @shortcuts; end
- #--------------------------------------------------------------------------
- # * Add a Shortcut
- #--------------------------------------------------------------------------
- def add_shortcut(symbol, text)
- text.gsub!(/\\/) { "\e" }
- text.gsub!(/\e\e/) { "\\" }
- shortcuts[symbol] = text if !shortcuts.include?(symbol)
- end
- #--------------------------------------------------------------------------
- # * Apply Shortcuts
- #--------------------------------------------------------------------------
- def apply_shortcuts(source)
- shortcuts.each { |symbol, text| source.gsub!(symbol) { text } }
- return source
- end
- end
- #==============================================================================
- # ** Window_Base
- #------------------------------------------------------------------------------
- # This is a super class of all windows within the game.
- #==============================================================================
- class Window_Base < Window
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :skip_new_lines
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias :pre_me_initialize :initialize unless $@
- def initialize(x, y, width, height)
- @skip_new_lines = 0
- pre_me_initialize(x, y, width, height) # original function
- end
- #--------------------------------------------------------------------------
- # * Character Processing
- # c : Characters
- # text : A character string buffer in drawing processing (destructive)
- # pos : Draw position {:x, :y, :new_x, :height}
- #--------------------------------------------------------------------------
- alias :pre_me_process_character :process_character unless $@
- def process_character(c, text, pos)
- case c
- when "\x10" # \ignr
- @skip_new_lines += 1
- when "\n" # New line
- process_new_line(text, pos) if @skip_new_lines <= 0
- @skip_new_lines -= 1 if @skip_new_lines > 0
- when "\f" # New page
- process_new_page(text, pos)
- when "\e" # Control character
- process_escape_character(obtain_escape_code(text), text, pos)
- else # Normal character
- process_normal_character(c, pos)
- end
- end
- #--------------------------------------------------------------------------
- # * Preconvert Control Characters
- # As a rule, replace only what will be changed into text strings before
- # starting actual drawing. The character "\" is replaced with the escape
- # character (\e).
- #--------------------------------------------------------------------------
- alias :pre_me_convert_escape_characters :convert_escape_characters unless $@
- def convert_escape_characters(text)
- # Create the result string
- result = text.to_s.clone
- # Add in shortcut codes
- result = $game_message.apply_shortcuts(result)
- # Run the normal conversion
- result.gsub!(/\\/) { "\e" }
- result.gsub!(/\e\e/) { "\\" }
- result.gsub!(/\e[Ii][Gg][Nn][Rr]/i) { "\x10" }
- result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
- result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
- result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
- result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
- result.gsub!(/\eG/i) { Vocab::currency_unit }
- # Custom
- result.gsub!(/\e[Nn][Mm]\[(.*?)\]/i) { @name_window.set($1) }
- result.gsub!(/\e[Nn][Cc]\[([0123456789abcdef]+)\]/i) {
- color_code = $1
- r = ("0x" + color_code.slice(0..1)).hex
- g = ("0x" + color_code.slice(2..3)).hex
- b = ("0x" + color_code.slice(4..5)).hex
- @name_window.font_color = Color.new(r, g, b)
- @name_window.refresh
- }
- # Return the result
- result
- end
- #--------------------------------------------------------------------------
- # * Preconvert Control Characters
- # As a rule, replace only what will be changed into text strings before
- # starting actual drawing. The character "\" is replaced with the escape
- # character (\e).
- #--------------------------------------------------------------------------
- alias :pre_me_convert_escape_characters :convert_escape_characters unless $@
- def convert_escape_characters_spec(text)
- # Create the result string
- result = text.to_s.clone
- # Add in shortcut codes
- result = $game_message.apply_shortcuts(result)
- # Run the normal conversion
- result.gsub!(/\\/) { "\e" }
- result.gsub!(/\e\e/) { "\\" }
- result.gsub!(/\e[Ii][Gg][Nn][Rr]/i) { "\x10" }
- result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
- result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
- result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
- result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
- result.gsub!(/\eG/i) { Vocab::currency_unit }
- # Custom
- result.gsub!(/\e[Nn][Mm]\[(.*?)\]/i) { @name_window.set($1) }
- result.gsub!(/\e[Nn][Cc]\[([0123456789abcdef]+)\]/i) {
- color_code = $1
- r = ("0x" + color_code.slice(0..1)).hex
- g = ("0x" + color_code.slice(2..3)).hex
- b = ("0x" + color_code.slice(4..5)).hex
- @name_window.font_color = Color.new(r, g, b)
- @name_window.refresh
- }
- result.gsub!(/\e./) { "" }
- result.gsub!(/\e|/) { "" }
- result.gsub!(/\e>/) { "" }
- result.gsub!(/\e$/) { "" }
- result.gsub!(/\e!/) { "" }
- result.gsub!(/\e</) { "" }
- result.gsub!(/\e^/) { "" }
- # Return the result
- result
- end
- end
- #==============================================================================
- # ** Window_Message
- #------------------------------------------------------------------------------
- # This message window is used to display text.
- #==============================================================================
- class Window_Message < Window_Base
- #--------------------------------------------------------------------------
- # * Public instance variables
- #--------------------------------------------------------------------------
- attr_reader :face_sprite
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias :pre_me_window_message_initialize :initialize unless $@
- def initialize
- $game_system.init_shortcuts # init
- pre_me_window_message_initialize # original function
- # Custom Settings for this game
- self.windowskin = Cache.system("MessageBox")
- self.back_opacity = 255
- contents.font.out_color = Color.new(0,0,0,16)
- end
- #--------------------------------------------------------------------------
- # * Draw Face Graphic
- # enabled : Enabled flag. When false, draw semi-transparently.
- #--------------------------------------------------------------------------
- def draw_face(face_name, face_index, x, y, enabled = true)
- @face_sprite.set_face(face_name, face_index)
- @face_sprite.x = self.x + x + 5
- @face_sprite.y = self.y + self.height + y - @face_sprite.height - 5
- @face_sprite.visible = true
- end
- #--------------------------------------------------------------------------
- # * Create All Windows
- #--------------------------------------------------------------------------
- alias :pre_me_create_all_windows :create_all_windows unless $@
- def create_all_windows
- # Original function
- pre_me_create_all_windows
- # New 'face' sprite
- @face_sprite = Sprite_Face.new(self.viewport)
- @face_sprite.z = self.z + 100
- # New 'name' window
- @name_window = Window_MiniText.new(0, 0, "", "Forte")
- @name_window.visible = false
- @name_window.z = self.z + 200
- @name_window.font_name = "Forte"
- @name_window.refresh
- @name_window.close
- end
- #--------------------------------------------------------------------------
- # * Update All Windows
- #--------------------------------------------------------------------------
- alias :pre_me_update_all_windows :update_all_windows unless $@
- def update_all_windows
- pre_me_update_all_windows # original function
- @name_window.update
- end
- #--------------------------------------------------------------------------
- # * Open Window and Wait for It to Fully Open
- #--------------------------------------------------------------------------
- alias :pre_me_open_and_wait :open_and_wait unless $@
- def open_and_wait
- # Blank the name window
- @name_window.set("")
- # Get the final text
- sizer_text = convert_escape_characters_spec($game_message.all_text)
- draw_face($game_message.face_name, $game_message.face_index, 0, 0)
- # Get the new height and width
- nheight = 0
- nwidth = 0
- # Loop through text
- sizer_text.each_line { |line|
- nheight += line_height if !line.include?("\x10")
- tw = contents.text_size(line).width
- nwidth = tw if tw > nwidth
- }
- # Adjust the heights
- self.width = nwidth + new_line_x + 24
- self.height = nheight + 24
- self.x = (Graphics.width - self.width) / 2
- self.y = Graphics.height - self.height - line_height
- update_placement
- draw_face($game_message.face_name, $game_message.face_index, 0, 0)
- pre_me_open_and_wait # original function
- end
- #--------------------------------------------------------------------------
- # * Update Window Position
- #--------------------------------------------------------------------------
- alias :pre_me_update_placement :update_placement unless $@
- def update_placement
- @position = $game_message.position
- case @position
- when 0
- self.y = [@face_sprite.height - self.height, 24].max + line_height
- when 1
- self.y = (Graphics.height/2) - (self.height / 2) + (line_height / 2)
- when 2
- self.y = Graphics.height - self.height - line_height
- end
- @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
- end
- #--------------------------------------------------------------------------
- # * New Page
- #--------------------------------------------------------------------------
- alias :pre_me_new_page :new_page unless $@
- def new_page(text, pos)
- pre_me_new_page(text, pos) # original function
- gx = self.x + 6 + new_line_x
- if gx + @name_window.width > self.x + self.width
- gx = self.x + self.width - @name_window.width
- end
- @name_window.move_window(gx, self.y + 11, true, false)
- if !@name_window.text.empty?
- @name_window.visible = true
- @name_window.open
- end
- end
- #--------------------------------------------------------------------------
- # * Get New Line Position
- #--------------------------------------------------------------------------
- def new_line_x
- $game_message.face_name.empty? ? 0 : @face_sprite.width
- end
- #--------------------------------------------------------------------------
- # * Close Window and Wait for It to Fully Close
- #--------------------------------------------------------------------------
- alias :pre_me_close_and_wait :close_and_wait unless $@
- def close_and_wait
- @name_window.close
- @face_sprite.visible = false
- pre_me_close_and_wait # original function
- end
- #--------------------------------------------------------------------------
- # * Free All Windows
- #--------------------------------------------------------------------------
- alias :pre_me_dispose_all_windows :dispose_all_windows unless $@
- def dispose_all_windows
- pre_me_dispose_all_windows # original function
- @face_sprite.dispose
- @name_window.dispose
- end
- end
- #==============================================================================
- # ** Window_MiniText
- #------------------------------------------------------------------------------
- # This window displays a small bit of text and fits to it's size
- # you can have it with no windowskin.
- #==============================================================================
- class Window_MiniText < Window_Base
- #--------------------------------------------------------------------------
- # * Public instance variables
- #--------------------------------------------------------------------------
- attr_reader :lh
- attr_reader :use_windowskin
- attr_reader :text
- attr_accessor :font_size
- attr_accessor :font_name
- attr_accessor :font_bold
- attr_accessor :font_italic
- attr_accessor :font_color
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, text, font_name = Font.default_name, font_size = 24, use_windowskin = false)
- # Set all our local values
- @lh = font_size
- @font_size = font_size
- @use_windowskin = use_windowskin
- @text = text
- @font_name = font_name
- @font_bold = false
- @font_italic = false
- # Create the window
- super(0, 0, window_width, fitting_height(1))
- # Modify based on initial values
- contents.font.size = @font_size
- @font_color = normal_color
- self.windowskin = Cache.system("WindowBlank") if use_windowskin
- end
- #--------------------------------------------------------------------------
- # * Simple value functions
- #--------------------------------------------------------------------------
- def text; return @text; end
- def text=(text); @text = text; end
- def use_windowskin; return @use_windowskin; end
- #--------------------------------------------------------------------------
- # * Line Height
- #--------------------------------------------------------------------------
- def line_height
- return 24 if @lh == nil
- return @lh
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- # Create temp bitmap and get text sizes
- bitmap = Bitmap.new(1,1)
- bitmap.font = Font.new(@font_name, @font_size)
- bitmap.font.bold = @font_bold
- bitmap.font.italic = @font_italic
- ts = bitmap.text_size(text).width + 26
- bitmap.dispose
- return ts
- end
- #--------------------------------------------------------------------------
- # * Move Function
- #--------------------------------------------------------------------------
- def move_window(x, y, baseline = true, consider_windowskin = true)
- self.x = x
- self.y = y
- self.y -= (self.height - 12) if baseline
- if consider_windowskin
- self.y -= 12 if baseline
- self.y -= 24 if !baseline
- end
- end
- #--------------------------------------------------------------------------
- # * Set a new location and text, use -1, -1 for x/y to not move it
- #--------------------------------------------------------------------------
- def set(new_text)
- # Modify x/y
- self.text = new_text
- self.width = window_width
- self.height = fitting_height(1)
- recreate
- refresh
- end
- #--------------------------------------------------------------------------
- # * Recreate the object
- #--------------------------------------------------------------------------
- def recreate
- # Save position
- tx = self.x
- ty = self.y
- # Remake the window and set texts
- self.windowskin = Cache.system("Window") if use_windowskin
- self.windowskin = Cache.system("WindowBlank") if !use_windowskin
- update_padding
- update_tone
- create_contents
- self.x = tx
- self.y = ty
- @opening = @closing = false
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def update
- super
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- # Re-make our contents to fit
- recreate
- # Set our font
- contents.font.size = @font_size
- contents.font.bold = @font_bold
- contents.font.italic = @font_italic
- contents.font.name = @font_name
- contents.font.color = @font_color
- # Draw the text
- draw_text(0, 0, window_width, line_height, text)
- end
- #--------------------------------------------------------------------------
- # * Open Window
- #--------------------------------------------------------------------------
- def open
- refresh
- super
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement