Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # TheoAllen - Animated Message Portrait
- # Version : 1.3
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (English Documentation)
- # =============================================================================
- ($imported ||= {})[:Theo_AnimPortrait] = true
- # =============================================================================
- # Change Logs:
- # -----------------------------------------------------------------------------
- # 2014.05.18 - Bugfix, Talk refresh rate wont affect rate
- # 2014.01.31 - Added screen y reposition
- # - Show portrait in bottom when placing message window in top
- # 2014.01.08 - Added show picture in middle
- # 2013.11.14 - Dimmed inactive portrait
- # - Bugfix, when remove portrait
- # 2013.10.18 - Finished Script
- # =============================================================================
- =begin
- -----------------------------------------------------------------------------
- *) Introduction :
- -----------------------------------------------------------------------------
- This script is simply adds animated portrait in dialog scene
- -----------------------------------------------------------------------------
- *) How to use :
- -----------------------------------------------------------------------------
- Put this script below material but above main
- Prepare two images in any size. One will be used for idle animation. The
- other will be used for talking animation. The image itself must consist three
- grids to the side. Named those image like these
- imagename_idle.png << Image name for idle
- imagename_talk.png << Image name for talks
- -----------------------------------------------------------------------------
- *) Script call:
- -----------------------------------------------------------------------------
- To display animated portrait, use this script call
- - set_portrait(filename, pos, flip, active)
- It's to set the portrait. Here are the explanations
- *) Filename >> is a image filename. Must be inside quotes ("").
- You don't need to add _talk / _idle.
- *) Pos >> For position. Choose between A (left), B (right),
- and C (middle)
- *) Flip >> Is the image flipped? Just put it true/false. Can be ommited.
- The default is false
- *) Active >> Is the image active? If true, when the message text is being
- typed, the image will talks. (Default : true)
- - remove_potrait(pos)
- To remove one of the portraits. Replace pos with A, B, or C
- - active_portrait(pos)
- To switch active portrait. Replace pos with A, B, or C
- - clear_portrait
- Must be called when the conversation ends
- - $game_system.portrait_ypos[pos] = value
- To give reposition of the place where the portrait is being displayed.
- Replace pos with (:A, :B, :C). Replace value with number. e.g,
- $game_system.portrait_ypos[:B] = 60
- -----------------------------------------------------------------------------
- *) Terms of use :
- -----------------------------------------------------------------------------
- Credit me, TheoAllen. You are free to edit this script by your own. As long
- as you don't claim it yours. For commercial purpose, don't forget to give me
- a free copy of the game.
- =end
- # =============================================================================
- # Configuration
- # =============================================================================
- module Theo
- module AnimePortrait
- # --------------------------------------------------------------------------
- Talk_Refresh_Rate = 4
- # Refresh rate for the currently active image. If you set 4, then the image
- # will be refreshed once per 4 characters is typed in message box. Default
- # value is 4. Just in case if you want to reset to the original setting
- # --------------------------------------------------------------------------
- # --------------------------------------------------------------------------
- Idle_Interval = [20,120]
- # Wait interval for idle animation. The format [absolute wait, random wait]
- #
- # *) absolute wait >> Absolute wait in frame
- # *) random wait >> Random wait in frame
- #
- # If you set it to [20,120] it means that the gap between idle animation
- # is 20 frame plus the random value between 0 - 120
- # (default : [20,120])
- #
- # Note : 60 frame is equal to 1 second
- # --------------------------------------------------------------------------
- # --------------------------------------------------------------------------
- Use_Dim = true # Set true if you want to use dimness
- Dim_Power = 90 # Dimness power (default : 90)
- # --------------------------------------------------------------------------
- # It's an option to make inactive image will be dimmed
- # --------------------------------------------------------------------------
- end
- end
- # =============================================================================
- # End of config. Don't touch anything below this line
- # =============================================================================
- class Game_System
- attr_reader :portrait_ypos
- alias theo_animportrait_init initialize
- def initialize
- theo_animportrait_init
- @portrait_ypos = {
- :A => 0,
- :B => 0,
- :C => 0,
- }
- end
- end
- class Game_Interpreter
- A = :A # Kiri
- B = :B # Kanan
- C = :C # Tengah
- def set_portrait(filename, pos, flip = false, active = true)
- $game_message.animportrait_name[pos] = [filename, flip]
- $game_message.active_portrait = pos if active
- end
- def clear_portrait
- $game_message.reset_animportrait
- end
- def remove_portrait(pos)
- $game_message.animportrait_name[pos][0] = ""
- end
- def active_portrait(pos)
- $game_message.active_portrait = pos
- end
- end
- class Game_Message
- attr_accessor :active_portrait
- attr_reader :animportrait_name
- alias theo_animportrait_init initialize
- def initialize
- theo_animportrait_init
- reset_animportrait
- @active_portrait = :A
- end
- def reset_animportrait
- @animportrait_name = {
- :A => ["", false],
- :B => ["", false],
- :C => ["", false],
- }
- end
- end
- class AnimPortrait < Sprite
- include Theo::AnimePortrait
- Dimmed_Color = Color.new(0,0,0,Dim_Power)
- Normal_Color = Color.new(0,0,0,0)
- attr_accessor :self_switch # Self Activation ~
- def initialize(pos, msg_window, viewport = nil)
- super(viewport)
- self.z = 150
- @msg_window = msg_window
- @pos = pos
- @self_switch = false
- @idle_pattern = 0
- @fiber = nil
- init_bitmap
- generate_idle_count
- end
- def init_bitmap
- @filename = img_name
- self.bitmap = Cache.system(@filename)
- self.mirror = $game_message.animportrait_name[@pos][1]
- case @pos
- when :A
- self.x = 0
- when :B
- self.x = Graphics.width - width
- when :C
- self.x = (Graphics.width - width) / 2
- end
- end
- def img_name
- str = $game_message.animportrait_name[@pos][0]
- return "" if str.empty?
- return str + (active? ? "_talk" : "_idle")
- end
- def bitmap=(bmp)
- super
- src_rect.width = bitmap.width / 3
- end
- def generate_idle_count
- @idle_count = random_idle_number
- end
- def random_idle_number
- return Idle_Interval[0] + rand(Idle_Interval[1])
- end
- def update
- super
- self.y = ypos_case
- self.opacity = @msg_window.openness
- update_bitmap
- update_color if Use_Dim
- update_idle unless active?
- end
- def ypos_case
- return Graphics.height - height + $game_system.portrait_ypos[@pos] if
- $game_message.position == 0
- return @msg_window.y - height + $game_system.portrait_ypos[@pos]
- end
- def update_bitmap
- if @filename != img_name
- init_bitmap
- end
- end
- def update_color
- if pos_active?
- self.color = Normal_Color
- else
- self.color = Dimmed_Color
- end
- end
- def update_active
- @fiber = nil if @fiber
- set_src_rect(rand(3))
- end
- def active?
- return pos_active? && self_switch
- end
- def pos_active?
- @pos == $game_message.active_portrait
- end
- def update_idle
- if @fiber
- @fiber.resume
- elsif @idle_count == 0
- @fiber = Fiber.new { fiber_idle }
- else
- @idle_count -= 1
- end
- end
- def fiber_idle
- setup_idle_anim
- update_idle_src_rect
- terminate_idle_anim
- end
- def setup_idle_anim
- set_src_rect(0)
- end
- def update_idle_src_rect
- random_wait
- set_src_rect(1)
- random_wait
- set_src_rect(2)
- random_wait
- set_src_rect(1)
- random_wait
- set_src_rect(0)
- random_wait
- end
- def set_src_rect(amount)
- @pattern = amount
- src_rect.x = @pattern * bitmap.width/3
- end
- def random_wait
- (2 + rand(3)).times { Fiber.yield }
- end
- def terminate_idle_anim
- @fiber = nil
- generate_idle_count
- end
- def dispose
- bitmap.dispose
- super
- end
- end
- class Window_Message < Window_Base
- alias theo_animportrait_init initialize
- def initialize
- theo_animportrait_init
- create_animportrait
- end
- def create_animportrait
- @animportrait = {
- :A => AnimPortrait.new(:A, self, viewport),
- :B => AnimPortrait.new(:B, self, viewport),
- :C => AnimPortrait.new(:C, self, viewport),
- }
- @talk_anim = 0
- end
- def active_portrait
- @animportrait[$game_message.active_portrait]
- end
- alias theo_animportrait_process_all_text process_all_text
- def process_all_text
- active_portrait.self_switch = true
- theo_animportrait_process_all_text
- end
- alias theo_animportrait_updt_show_fast update_show_fast
- def update_show_fast
- theo_animportrait_updt_show_fast
- active_portrait.set_src_rect(0) if Input.trigger?(:C)
- end
- alias theo_animportrait_wait_for_one_char wait_for_one_character
- def wait_for_one_character
- theo_animportrait_wait_for_one_char
- @talk_anim += 1
- refrate = Theo::AnimePortrait::Talk_Refresh_Rate
- active_portrait.update_active if @talk_anim % refrate == 0
- end
- alias theo_animportrait_process_input process_input
- def process_input
- active_portrait.set_src_rect(0)
- active_portrait.self_switch = false
- theo_animportrait_process_input
- end
- alias theo_animportrait_update update
- def update
- theo_animportrait_update
- @animportrait.values.each {|img| img.update }
- end
- alias theo_animportrait_dispose dispose
- def dispose
- theo_animportrait_dispose
- @animportrait.values.each {|img| img.dispose }
- end
- alias theo_animportrait_wait wait
- def wait(duration)
- active_portrait.set_src_rect(0)
- theo_animportrait_wait(duration)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment