#==============================================================================
# ■ 动态头像(修改Window_Message)by 只有金刚心
#------------------------------------------------------------------------------
# 使用方法:在文件名加上相应后缀,然后在事件显示文字中添加头像就可以了
# 文件名后缀+"_a"为循环播放
# 文件名后缀+"_b"为播放一次,停止在最后一帧
# 如果没有加后缀,就按系统默认的静态头像显示
# 动态头像的宽度和高度可以再28-29行重新设定
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, window_height)
self.z = 200
self.openness = 0
create_all_windows
create_back_bitmap
create_back_sprite
clear_instance_variables
#★★动态头像定义★★
@face_index = 0
@face_ani_speed = 8 #动态头像播放速度
@face_width = 96 #头像的单帧宽度
@face_height = 96 #头像的高度
@face_bitmap = Sprite.new
@face_bitmap.bitmap = Bitmap.new(@face_width,@face_height)
@face_bitmap.z = 10000
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
super
dispose_all_windows
dispose_back_bitmap
dispose_back_sprite
#★★释放头像★★
@face_bitmap.dispose
@face_bitmap.bitmap.dispose
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_all_windows
update_back_sprite
update_fiber
#★★动态头像播放计数★★
@face_index += 1
#★★判断是否为动态头像★★
if $game_message.face_name =~ /[a-zA-Z0-9]_a/ or $game_message.face_name =~ /[a-zA-Z0-9]_b/
update_face
end
end
#--------------------------------------------------------------------------
# ★★ 动态头像 ★★
#--------------------------------------------------------------------------
#★★绘制/更新头像★★
def update_face
@bitmap = Cache.face($game_message.face_name)
@face_index_max = @bitmap.width/@face_width - 1
@face_bitmap.bitmap.clear
#文件名后缀+"_a"为循环播放
if $game_message.face_name =~ /[a-zA-Z0-9]_a/
rect = Rect.new(@face_index / @face_ani_speed % @face_index_max * @face_width,0,@face_width,@face_height)
#文件名后缀+"_b"为播放一次,停止在最后一帧
elsif $game_message.face_name =~ /[a-zA-Z0-9]_b/
if (@face_index /@face_ani_speed) < @face_index_max
rect = Rect.new(@face_index /@face_ani_speed * @face_width,0,@face_width,@face_height)
else
rect = Rect.new(@face_index_max * @face_width,0,@face_width,@face_height)
end
#文件名不加后缀则为系统默认的静态头像★宽度高度未重新设置★
else
rect = Rect.new($game_message.face_index % 4 * 96 , $game_message.face_index / 4 * 96, 96,96)
end
@face_bitmap.bitmap.blt(0,0, @bitmap,rect)
end
#--------------------------------------------------------------------------
# ● 处理纤程的主逻辑
#--------------------------------------------------------------------------
def fiber_main
$game_message.visible = true
update_background
update_placement
loop do
process_all_text if $game_message.has_text?
process_input
#★★清除头像★★
@face_bitmap.bitmap.clear
$game_message.clear
@gold_window.close
Fiber.yield
break unless text_continue?
end
close_and_wait
$game_message.visible = false
@fiber = nil
end
#--------------------------------------------------------------------------
# ● 更新窗口的位置
#--------------------------------------------------------------------------
def update_placement
@position = $game_message.position
self.y = @position * (Graphics.height - height) / 2
#★★更新头像的坐标★★
face_y = @position * (Graphics.height - height) / 2 + 12
@face_bitmap.y = face_y
@face_bitmap.x = 12
@gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
end
#--------------------------------------------------------------------------
# ● 翻页处理
#--------------------------------------------------------------------------
def new_page(text, pos)
contents.clear
#★★载入头像以及重新计数★★
update_face
@face_index = 0
#draw_face($game_message.face_name, $game_message.face_index, 0, 0)
reset_font_settings
pos[:x] = new_line_x
pos[:y] = 0
pos[:new_x] = new_line_x
pos[:height] = calc_line_height(text)
clear_flags
end
#--------------------------------------------------------------------------
# ● 获取换行位置
#--------------------------------------------------------------------------
def new_line_x
#★★修正换行位置★★
if $game_message.face_name.empty?
return 0
elsif $game_message.face_name =~ /[a-zA-Z0-9]_a/ or $game_message.face_name =~ /[a-zA-Z0-9]_b/
return 112 + @face_width - 96
else
return 112
end
end
end