#==============================================================================
#■ AVG式对话框(未通用化)
# 功能:
# 1. 用图片代替默认对话框
# 2. 额外显示对话者姓名
# 3. 姓名&对话内容自动染色
#==============================================================================
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
# 游戏中所有窗口的父类
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ● 进行控制符的事前变换
# 在实际绘制前、将控制符替换为实际的内容。
# 为了减少歧异,文字「\」会被首先替换为转义符(\e)。
#--------------------------------------------------------------------------
def convert_escape_characters(text)
result = text.to_s.clone
result.gsub!(/\\/) { "\e" }
result.gsub!(/\e\e/) { "\\" }
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 }
result.gsub!(/^\eName\[(.+)\]/i){""}
@speaker_name = $1.to_s
result
end
#--------------------------------------------------------------------------
# ● 处理普通文字
#--------------------------------------------------------------------------
def process_normal_character(c, pos)
text_width = text_size(c).width
talk_color
draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
pos[:x] += text_width
end
#--------------------------------------------------------------------------
# ● 角色文字染色
#--------------------------------------------------------------------------
def talk_color
if $has_color_change != true
case @speaker_name
when "柔一"
contents.font.color.set(145,55,0)
when "坚二"
contents.font.color.set(165,75,0)
else
contents.font.color.set(255,255,255)
end
end
end
#--------------------------------------------------------------------------
# ● 控制符的处理
# code : 控制符的实际形式(比如“\C[1]”是“C”)
# text : 绘制处理中的字符串缓存(字符串可能会被修改)
# pos : 绘制位置 {:x, :y, :new_x, :height}
#--------------------------------------------------------------------------
def process_escape_character(code, text, pos)
case code.upcase
when 'C'
$has_color_change = true
change_color(text_color(obtain_escape_param(text)))
when 'I'
process_draw_icon(obtain_escape_param(text), pos)
when '{'
make_font_bigger
when '}'
make_font_smaller
end
end
#--------------------------------------------------------------------------
# ● 绘制内容
# args : 与 Bitmap#draw_text 相同
#--------------------------------------------------------------------------
def draw_text(*args)
if contents.font.bold != true
contents.font.name = "微软雅黑"
contents.font.bold = true
contents.font.shadow = true
contents.font.size = 27
end
contents.draw_text(*args)
end
end
#==============================================================================
# ■ Window_Message
#------------------------------------------------------------------------------
# 显示文字信息的窗口。
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias old_initialize initialize
def initialize
old_initialize
creat_bg_pic
end
#--------------------------------------------------------------------------
# ● 获取窗口的高度
#--------------------------------------------------------------------------
def window_height
fitting_height(visible_line_number) + 30
end
#--------------------------------------------------------------------------
# ● 获取背景图片
#--------------------------------------------------------------------------
def creat_bg_pic
@bg_sprite = Sprite.new
@bg_sprite.x = 15
@bg_sprite.y = 380
@bg_sprite.bitmap = Cache.ui("Dialog").clone
@bg_sprite.visible = false
end
#--------------------------------------------------------------------------
# ● 更新窗口背景
#--------------------------------------------------------------------------
alias old_update_background update_background
def update_background
old_update_background
self.opacity = 0
self.height = 150
self.x = 25
end
#--------------------------------------------------------------------------
# ● 处理纤程的主逻辑
#--------------------------------------------------------------------------
def fiber_main
$game_message.visible = true
@bg_sprite.visible = true
update_background
update_placement
loop do
process_all_text if $game_message.has_text?
process_input
$game_message.clear
@gold_window.close
Fiber.yield
$has_color_change = false
clear_dialog_name
break unless text_continue?
end
close_and_wait
clear_dialog_name
@bg_sprite.visible = false
$game_message.visible = false
@fiber = nil
end
#--------------------------------------------------------------------------
# ● 处理所有内容
#--------------------------------------------------------------------------
def process_all_text
open_and_wait
text = convert_escape_characters($game_message.all_text)
show_dialog_name
pos = {}
new_page(text, pos)
process_character(text.slice!(0, 1), text, pos) until text.empty?
end
#--------------------------------------------------------------------------
# ● 显示对话姓名
#--------------------------------------------------------------------------
def show_dialog_name
@name_viewport = Viewport.new
@name_string_sprite = Sprite.new(@name_viewport)
@name_string_sprite.x = -130
@name_string_sprite.y = 348
@name_string_sprite.z = 1
@name_string_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
if @name_string_sprite.bitmap.font.bold != true
@name_string_sprite.bitmap.font.name = "微软雅黑"
@name_string_sprite.bitmap.font.bold = true
@name_string_sprite.bitmap.font.shadow = true
@name_string_sprite.bitmap.font.size = 27
end
name_color
@name_string_sprite.bitmap.draw_text(200, 0, 100, 100, @speaker_name)
if !@speaker_name.empty?
@name_pic_sprite = Sprite.new(@name_viewport)
@name_pic_sprite.bitmap = Cache.ui("nameBack").clone
@name_pic_sprite.x = 15
@name_pic_sprite.y = 380
@name_pic_sprite.z = 0
end
end
#--------------------------------------------------------------------------
# ● 姓名染色
#--------------------------------------------------------------------------
def name_color
case @speaker_name
when "柔一"
name_color = Color.new(145,55,0)
when "坚二"
name_color = Color.new(165,75,0)
else
name_color = Color.new(255,255,255)
end
@name_string_sprite.bitmap.font.color.set(name_color)
end
#--------------------------------------------------------------------------
# ● 清除对话姓名
#--------------------------------------------------------------------------
def clear_dialog_name
@name_pic_sprite.bitmap.dispose
@name_string_sprite.bitmap.dispose
@name_viewport.dispose
end
end