Project1
标题:
对话框优化一点的小脚本
[打印本页]
作者:
KISS_COMPUTER
时间:
2013-7-26 09:48
标题:
对话框优化一点的小脚本
希望对大家有一点点的帮助。
#encoding:utf-8
#==============================================================================
# ■ Message_Advanced
#------------------------------------------------------------------------------
# 使对话框略微美观一点
# 调用方式:在对话内容的第一行输入“l/r”+“对话者姓名”
# l和r表示头像在左边或者右边显示,对话者姓名显示在头像下方
# 第一行输入“no”则为取消使用
#==============================================================================
class Game_Message
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :talker_name # 说话者姓名
attr_reader :talker_mirror # 是否镜象显示
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def clear
@texts = []
@choices = []
# 初始化
@talker_name = ""
@talker_mirror = false
@face_name = ""
@face_index = 0
@background = 0
@position = 2
@choice_cancel_type = 0
@choice_proc = nil
@num_input_variable_id = 0
@num_input_digits_max = 0
@item_choice_variable_id = 0
@scroll_mode = false
@scroll_speed = 2
@scroll_no_fast = false
end
#--------------------------------------------------------------------------
# ● 获取包括换行符的所有内容
#--------------------------------------------------------------------------
def all_text
# 当不取消时执行处理
if @texts[0] != "no"
# 当输入的内容包含说话者姓名时
if @texts.size > 1
# 取出第一个字符
ch = @texts[0].slice!(0, 1)
# 当右侧显示头像时设置mirror标志
@talker_mirror = true if ch == "r"
@talker_name = "[" + @texts[0] + "]"
# 当输入的内容不包含说话者姓名时
else
@talker_name = "未定义"
end
end
# 删除第一行控制内容
@texts.delete_at(0)
@texts.inject("") {|r, text| r += text + "\n" }
end
end
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● 处理纤程的主逻辑
#--------------------------------------------------------------------------
def fiber_main
$game_message.visible = true
update_background
update_placement
loop do
# 生成显示精灵
@face_sprite = Sprite.new
@name_sprite = Sprite.new
process_all_text if $game_message.has_text?
process_input
# 将显示精灵释放
@face_sprite.dispose
@name_sprite.dispose
$game_message.clear
@gold_window.close
Fiber.yield
break unless text_continue?
end
close_and_wait
$game_message.visible = false
@fiber = nil
end
#--------------------------------------------------------------------------
# ● 翻页处理
#--------------------------------------------------------------------------
def new_page(text, pos)
contents.clear
if !$game_message.talker_name.empty?
# 判断左右侧显示
if $game_message.talker_mirror
draw_face_right($game_message.face_name,$game_message.face_index)
draw_name_right($game_message.talker_name)
else
draw_face_left($game_message.face_name,$game_message.face_index)
draw_name_left($game_message.talker_name)
end
else
draw_face($game_message.face_name, $game_message.face_index, 0, 0)
end
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 draw_face_left(face_name, face_index)
# 取出图片
source = Cache.face(face_name)
# 找到脸图位置
rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
bitmap = Bitmap.new(96, 96)
# 复制到bitmap中
bitmap.blt(0, 0, source, rect)
# 计算精灵位置并显示
@face_sprite.x = standard_padding
@face_sprite.y = Graphics.height - 96 - standard_padding - line_height
@face_sprite.z = 1000
@face_sprite.bitmap = bitmap
end
#--------------------------------------------------------------------------
# ● 显示说话者脸图(右)
#--------------------------------------------------------------------------
def draw_face_right(face_name, face_index)
source = Cache.face(face_name)
rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
bitmap = Bitmap.new(96, 96)
bitmap.blt(0, 0, source, rect)
@face_sprite.x = Graphics.width - 96 - standard_padding
@face_sprite.y = Graphics.height - 96 - standard_padding - line_height
@face_sprite.z = 1000
# 设置为右侧显示
@face_sprite.mirror = true
@face_sprite.bitmap = bitmap
end
#--------------------------------------------------------------------------
# ● 显示说话者姓名图(左)
#--------------------------------------------------------------------------
def draw_name_left(talker_name)
bitmap = Bitmap.new(96, line_height)
# 描绘姓名图像
bitmap.draw_text(bitmap.rect, talker_name, 1)
# 计算精灵位置并显示
@name_sprite.x = standard_padding
@name_sprite.y = Graphics.height - standard_padding - line_height
@name_sprite.z = 1000
@name_sprite.bitmap = bitmap
end
#--------------------------------------------------------------------------
# ● 显示说话者姓名图(右)
#--------------------------------------------------------------------------
def draw_name_right(talker_name)
bitmap = Bitmap.new(96, line_height)
bitmap.draw_text(bitmap.rect, talker_name, 1)
@name_sprite.x = Graphics.width - 96 - standard_padding
@name_sprite.y = Graphics.height - standard_padding - line_height
@name_sprite.z = 1000
@name_sprite.bitmap = bitmap
end
#--------------------------------------------------------------------------
# ● 获取换行位置
#--------------------------------------------------------------------------
def new_line_x
if !$game_message.talker_mirror
return $game_message.face_name.empty? ? 0 : 112
# 右侧显示时,换行显示位置为行首
else
return 0
end
end
end
复制代码
作者:
1105741847
时间:
2013-7-26 11:00
无图无真相{:2_270:}
作者:
373484107
时间:
2013-9-7 20:24
有个严重的BUG啊,每次对话后,再次重复对话时名字就缩短了一个字节!
什么情况,求解决!
作者:
xujintao
时间:
2013-9-13 09:09
咋没有效果图呢
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1