查看: 3270|回复: 0

[原创发布] 对话同时进行脚本

[复制链接]
梦石
0
星屑
2624
在线时间
289 小时
注册时间
2018-5-13
回帖
15
发表于 2019-4-6 09:10:24 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 大葱有营养 于 2019-4-6 22:13 编辑

之前提了个关于“关于对话同时进行的实现”的问题:https://rpg.blue/thread-411624-1-1.html
但是没有得到很好的解决,然后清明节有时间研究了一下,自己写了一个出来
第一次发原创……有什么不妥请各位多多包涵

本脚本旨在解决目前对话加强脚本里不能实现多个对话同时进行的问题,其是在重置版6R对话加强脚本
(我也不是很清楚名字,反正链接是 https://rpg.blue/thread-382811-1-1.html)的基础上进行的修改
以达到两段以上的对话文本同时或略有间隔地显示

实现部分主要包括这三个脚本:
直接设置文章
这部分功能是使用脚本set_message("文章内容")代替原本的事件中显示文章功能(原本显示文章的框框太小了……)
如果想要同时进行多段对话,则使用set_message("主文章","子文章1","子文章2"……)
注意,由于双引号内是字符串所以别忘了\\代替\

  1. #==============================================================================
  2. # ■ set_message
  3. #------------------------------------------------------------------------------
  4. #  直接设置呼出文章  by Road
  5. #   更新:set_message可以连用
  6. #==============================================================================

  7. class Interpreter
  8.   def set_message(*text)
  9.     # 另外的文章已经设置过 message_text 的情况下
  10.     if $game_temp.message_text != nil
  11.       wait_message
  12.       # 结束
  13.       return
  14.     end
  15.     # 设置当前信息的调用事件
  16.     $message_event_id = @event_id if !($game_temp.in_battle)
  17.     # 设置信息结束后待机和返回调用标志
  18.     @message_waiting = true
  19.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  20.     # message_text 设置为 字符串
  21.     $game_temp.message_text = text[0]
  22.     # 同时显示多个文本框的功能
  23.     if text.size > 1
  24.       $more_message_text = Array.new(text.size - 1, "")
  25.       for i in 1 ... text.size
  26.         $more_message_text[i-1] = text[i]
  27.       end
  28.     end
  29.   end
  30.   def wait_message
  31.     while @message_waiting
  32.       # 刷新游戏画面
  33.       Graphics.update
  34.       # 刷新输入信息
  35.       Input.update
  36.       # 刷新画面
  37.       $scene.update
  38.     end
  39.   end
  40. end
复制代码



对话加强基本大多数内容都源自原版(https://rpg.blue/thread-382811-1-1.html),自己略微更改了一些功能
主要增加了@child_message_window相关内容,可以通过搜索功能查找
  1. #==============================================================================
  2. # 来自Road的脚本更新
  3. # 通过width+1修复了某些字描绘的时候会缩水的问题
  4. # \align[1/2] 调节当前行的文本对齐方式,1=居中对齐,2=右对齐
  5. # 添加了场景上同时存在多个对话框时的功能,有关内容请搜索@child_message_window
  6. #==============================================================================
  7. # 本脚本原于6R对话加强脚本,对此进行了一些改动
  8. # 说明:

  9. # 使用时,要在Graphics文件夹下新建一个名为Faces的文件夹,用于存储头像
  10. # 对话框的窗口素材可不必和系统窗口相同,请将对话框窗口素材放到
  11. # Graphics/Windowskins文件夹下,并附上两个气泡箭头素材,用于指向说话者,
  12. # 命名规则为“对话框窗口素材名-top”和“对话框窗口素材名-under”
  13. # 然后在本脚本的设置区域修改。

  14. # 默认为一个字一个字的方式,如果需要一次全部显示,
  15. # 请打开特定开关(默认为 21 号)

  16. # 打开开关(默认为 22 号)后,对话时按下[空格键]可以瞬间显示全部对话。

  17. # 打卡开关(默认为 23 号)后,屏蔽加强对话框,将使用 XP 默认对话框。

  18. # 打开开关(默认为 24 号)后,对话框可以在对话显示完毕后自动消失,适合制作
  19. # 场景 CG,需要进行选择或数字输入的情况不会自动消失。此外在文本框中使用\t[数字]
  20. # 也可达到相似效果,不过作用范围仅限本次对话框。

  21. # 打开开关(默认为 25 号)后,按下 CTRL 键可以快速跳过对话,需要进行选择或者数字
  22. # 输入的情况不会跳过。

  23. # 打开开关(默认为 26 号)后,对话框的位置会自动调节,使其不会遮挡说话者
  24. # 默认对话字没有声音,如果需要声音,
  25. # 请在游戏中使用脚本:$game_system.soundname_on_speak = "这里输入文件名"
  26. # 我唯一一个见过“胡乱配音”的游戏是天使帝国2代,该游戏说话的时候每个字符随机发一个外星语音

  27. # 其他在对话中可以使用的功能:

  28. # \n[1]:显示1号角色的姓名

  29. # \name[李逍遥]:显示一个“李逍遥”方框,表示说话人姓名
  30. # \nc[0-7]:更改姓名框颜色

  31. # 非战斗时,\p功能可以自动调整对话框位置
  32. # \p[1] :对话框出现在1号事件的上方
  33. # \p[0] :主人公上方出现对话框
  34. # \p[-1]:对话框出现在屏幕下方,这种特殊类型的对话框在有大型半身像时使用
  35. #——————————————————使用\p功能后可以自动调整对话框大小
  36. # 使用\p功能后,使用事件指令[更改文章选项]可更改对话框的位置
  37. #   [上] :对话框出现在说话者上方
  38. #   [下] :对话框出现在说话者下方
  39. #   [中] :对话框出现在屏幕正中
  40. # 战斗时,\p功能有所变化
  41. # \p[1]:对话框出现在ID为1的角色战斗图附近(这个角色必须是队伍中的成员)
  42. # \p[1001]:对话框出现在Index为1的敌人战斗图附近--也就是说敌人的位置从
  43. #           1001开始算起,1002则是代表Index为2的敌人。
  44. # 战斗时使用\p指令+[更改文章选项]依然是有效的,但是如果不使用\p指令,那么
  45. # 对话框则会一直出现在屏幕正上方。

  46. # \\:显示""这个符号

  47. # \v[1] :显示变量1

  48. # \v[a1] :显示防具1

  49. # \v[w1] :显示武器1

  50. # \v[i1] :显示物品1

  51. # \v[s1] :显示特技1

  52. # \ic[001-Weapon01] : 显示图标"001-Weapon01.png"

  53. # \c[0-7]:更改颜色

  54. # \g:显示金钱窗口

  55. # \a[SE文件名]:对话的时候播放SE

  56. # \s[1-19]:更改弹字的速度

  57. # \.   :停顿一刹那(1、2帧)
  58. # \|   :停顿片刻(20帧)

  59. # \>   :文字不用打字方式
  60. # \<   :文字使用打字方式

  61. # \!   :等待玩家按回车再继续
  62. # \~   :文字直接消失

  63. # \I   :下一行从这个位置开始

  64. # \o[123]:文字透明度改为123,模拟将死之人(汗)

  65. # \h[12]:改用12号字

  66. # \b[50]:空50象素

  67. # \t[20]:对话显示完毕后等待 20 帧自动消失

  68. # \L[001]:在左边显示半身像"Graphics/Faces/001.png",并左右镜像反转
  69. # \R[001]:在右边显示半身像"Graphics/Faces/001.png"
  70. # \f[001]:在左边显示正方形头像"Graphics/Faces/001.png"
  71. # 注:不推荐同时使用显示半身像的功能和显示头像的功能。显示的头像图片大小
  72. #     不得超过 120x120,如果图片超过这个大小,图片将会被放缩
  73. # \gf[001, 0]:在左边显示正方形头像组"Graphics/Faces/001.png"的第一个
  74. # 注:头像组排序方式默认如下(先数第一行,再数第二行,可调节每行的头像个数)
  75. #  -----------------
  76. #  | 0 | 1 | 2 | 3 |
  77. #  -----------------
  78. #  | 4 | 5 | 6 | 7 |
  79. #  -----------------

  80. # \+:必须放在每一行的末尾,表示连行,它将合并下一个【显示文章】指令(需要
  81. #     在下面的设置区域调节 Max_Lines 以保证文字能正常显示出来)

  82. #==============================================================================
  83. # 设置区域(其他参数的调节请看这里)
  84. #==============================================================================
  85. module RB
  86. end
  87. module RB::Mes_Config
  88.   # 打开 XX 号开关后,关闭打字效果
  89.   No_Typing = 21
  90.   # 打开 XX 号开关后,按下[空格键]可以瞬间显示全部文字
  91.   Write_Skip = 22
  92.   # 打开 XX 号开关后,屏蔽加强对话框(使用默认对话框)
  93.   Mes_Disabled = 23
  94.   # 主角名字字符缩写
  95.   Regex_Player_Name = /pn(\d+)/
  96.   # 主角姓名框底色(RGBA)
  97.   Name_Bar_Color = Color.new(120, 180, 250, 80)
  98.   # 字体大小
  99.   Size = 23
  100.   # 对话框窗口皮肤(不写为和系统皮肤相同)
  101.   Mes_Windowskin = "talk"
  102.   # 最大行数(初值为 4,尽量不要修改,如果考虑合并选择项和连行,可以设置为 6 以上)
  103.   # 此最大行数仅在 \p 指令下有效,如果不使用 \p 指令那么对话框还是 4 行的高度
  104.   Max_Lines = 16
  105.   # 画面宽度和高度(width / height)
  106.   # 此设置一般不需要更改,当使用分辨率扩张脚本时,将如下的值改成你游戏的分辨率即可。
  107.   Graphics_Width = 640
  108.   Graphics_Height = 480
  109.   # 打开 XX 号开关后,对话自动结束(不用按下 C 键)
  110.   Auto_Terminate = 24
  111.   # 打开 XX 号开关后,按下 CTRL 可以高速跳过对话
  112.   Text_Skip_Fast = 25
  113.   # 打开 XX 号开关后,自动调节对话框使其不会挡住说话者
  114.   Auto_Adjust_Mes_Pos = 26
  115.   # 对话自动结束延迟(单位:帧)
  116.   Auto_Terminate_Frame = 10
  117.   # 头像组:横向单元数
  118.   Face_Group_W = 4
  119.   # 头像组:纵向单元数
  120.   Face_Group_H = 2  
  121.   # 默认姓名文字颜色(和系统默认编号一致)
  122.   Name_Color_Default = 6
  123.   # 快捷指令,定义后,可以直接在文本框中输入快捷指令
  124.   # 定义方式为 快捷指令 => 完整指令 ,使用方式为 \sc[快捷指令]
  125.   # 注意,指令中通常包含反斜线'\',因此需要使用单引号的字符串,
  126.   # 或者用"\"进行转义。下面是一个例子:
  127.   # 这样定义后,输入\sc[pn1]就等效为 \name[pn1]\r[L1]\p[-1]
  128.   Shortcuts = {
  129.     #'pn1' => '\name[pn1]\r[L1]\p[-1]'
  130.   }
  131.   # 高级快捷指令定义,类似于宏展开,需要借助正则表达式(高级用户使用)
  132.   Shortcuts_Regexp = {
  133.     /\\pn1/ => '\name[pn1]\r[L1]\p[-1]',
  134.     /\\[Rr]ed\[(.*?)\]/m => '\c[2]\1\c[0]',
  135.     /\\[Cc]ol\[(\d+)\]\{(.*?)\}/m => '\c[\1]\2\c[0]',
  136.   }
  137. end
  138. #==============================================================================
  139. # RPG::Cache
  140. #------------------------------------------------------------------------------
  141. # RPG::Cache 追加定义
  142. #==============================================================================
  143. module RPG::Cache
  144.   def self.face(filename)
  145.     self.load_bitmap("Graphics/Faces/", filename)
  146.   end
  147. end

  148. #==============================================================================
  149. # ■ Game_System
  150. #------------------------------------------------------------------------------
  151. #  处理系统附属数据的类。也可执行诸如 BGM 管理之类的功能。本类的实例请参考
  152. # $game_system 。
  153. #==============================================================================

  154. class Game_System
  155.   attr_accessor :soundname_on_speak
  156.   alias carol3_ini initialize
  157.   def initialize
  158.     carol3_ini
  159.     @soundname_on_speak = nil
  160.   end
  161. end

  162. #==============================================================================
  163. # ■ Window_Message
  164. #------------------------------------------------------------------------------
  165. #   修改的对话框类。
  166. #==============================================================================
  167. class Window_Message_RB < Window_Selectable
  168.   include RB::Mes_Config
  169.   #--------------------------------------------------------------------------
  170.   # ● 初始化状态
  171.   #--------------------------------------------------------------------------
  172.   def initialize
  173.     super(80, 304, 480, 160)
  174.     self.contents = Bitmap.new(1, 1)
  175.     self.visible = false
  176.     self.z = 9998
  177.     @fade_in = false
  178.     @fade_out = false
  179.     @contents_showing = false
  180.     @write_skip = false
  181.     @text_skip = false
  182.     @cursor_width = 0
  183.     @face_h = 0
  184.     self.active = false
  185.     self.index = -1
  186.     if $game_system.soundname_on_speak == nil then
  187.       $game_system.soundname_on_speak = ""
  188.     end
  189.     self.windowskin = RPG::Cache.windowskin(Mes_Windowskin) if Mes_Windowskin != ""
  190.     @opacity_text_buf = Bitmap.new(32, 32)
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # ● 释放
  194.   #--------------------------------------------------------------------------
  195.   def dispose
  196.    
  197.     terminate_message
  198.     $game_temp.message_window_showing = false
  199.     if @input_number_window != nil
  200.       @input_number_window.dispose
  201.     end
  202.     super
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # ● 处理信息结束
  206.   #--------------------------------------------------------------------------
  207.   def terminate_message
  208.     if @child_message_window != nil
  209.       for window in @child_message_window
  210.         window.dispose
  211.       end
  212.       $more_message_text = nil
  213.       @child_message_window = nil
  214.     end
  215.     self.active = false
  216.     self.pause = false
  217.     self.index = -1
  218.     self.contents.clear
  219.     # 清除显示中标志
  220.     @contents_showing = false
  221.     # 呼叫信息调用
  222.     if $game_temp.message_proc != nil
  223.       $game_temp.message_proc.call
  224.     end
  225.     # 清除文章、选择项、输入数值的相关变量
  226.     $game_temp.message_text = nil
  227.     $game_temp.message_proc = nil
  228.     $game_temp.choice_start = 99
  229.     $game_temp.choice_max = 0
  230.     $game_temp.choice_cancel_type = 0
  231.     $game_temp.choice_proc = nil
  232.     $game_temp.num_input_start = 99
  233.     $game_temp.num_input_variable_id = 0
  234.     $game_temp.num_input_digits_max = 0
  235.     # 清除头像(由于是 RPG::Cache 所以无需释放)
  236.     @face_bitmap = nil
  237.     @face_group_bitmap = nil
  238.     @face_ok = false
  239.     # 清除跳过标志
  240.     @write_skip = false
  241.     @text_skip = false
  242.     # 释放金钱窗口
  243.     if @gold_window != nil
  244.       @gold_window.dispose
  245.       @gold_window = nil
  246.     end
  247.     # 释放姓名窗口
  248.     if @name_window_text != nil
  249.       @name_window_text.dispose
  250.       @name_window_text = nil
  251.     end
  252.     # 释放右侧立绘
  253.     if @right_picture != nil
  254.       @right_picture.dispose
  255.       @right_picture = nil
  256.     end   
  257.     # 释放左侧立绘
  258.     if @left_picture != nil
  259.       @left_picture.dispose
  260.       @left_picture = nil
  261.     end
  262.     # 释放姓名蓝条
  263.     if @bar != nil
  264.       @bar.bitmap.dispose
  265.       @bar.dispose
  266.       @bar = nil
  267.     end
  268.     # 释放气泡图标
  269.     if @k_tale != nil
  270.       @k_tale.dispose
  271.       @k_tale = nil
  272.     end
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # ● 刷新
  276.   #--------------------------------------------------------------------------
  277.   def refresh
  278.     # 初期化
  279.     @x = @y = @max_x = @max_y = @indent = @lines = 0
  280.     @face_indent = 0
  281.     @opacity = 255
  282.     @cursor_width = 0
  283.     @write_speed = 1##
  284.     @write_wait = 0
  285.     @mid_stop = false
  286.     @popchar = -2
  287.     @auto_terminate = -1
  288.     if $game_temp.choice_start == 0
  289.       @x = 8
  290.     end
  291.     if $game_temp.message_text != nil
  292.       @now_text = $game_temp.message_text
  293.       # Shortcuts 预处理
  294.       @now_text.gsub!(/\\sc\[(.*?)\]/) { Shortcuts[$1] || "" }
  295.       # Shortcuts_Regexp 预处理
  296.       Shortcuts_Regexp.each_pair do |regex, str|
  297.         @now_text.gsub!(regex, str)
  298.       end
  299.       # 头像设置
  300.       if (/\\[Ff]\[(.+?)\]/.match(@now_text)) != nil
  301.         @face_bitmap = RPG::Cache.face($1)
  302.         @x = @face_indent = [128, @face_bitmap.width + 4].min
  303.         @now_text.gsub!(/\\[Ff]\[(.+?)\]/) { "" }
  304.       end
  305.       # 头像组设置
  306.       if (/\\[Gg]f\[(.+?)\s*,\s*(\d+)\]/).match(@now_text) != nil
  307.         @face_group_bitmap = RPG::Cache.face($1)
  308.         idx = $2.to_i
  309.         ix, iy = idx % Face_Group_W, idx / Face_Group_W
  310.         w, h = @face_group_bitmap.width / Face_Group_W, @face_group_bitmap.height / Face_Group_H
  311.         @face_bitmap = Bitmap.new(w, h)
  312.         @face_bitmap.blt(0, 0, @face_group_bitmap, Rect.new(ix * w, iy * h, w, h))
  313.         @x = @face_indent = [128, @face_bitmap.width + 4].min
  314.         @now_text.gsub!(/\\[Gg]f\[(.+?)\s*,\s*(\d+)\]/) { "" }
  315.       end
  316.       #——左半身像设置
  317.       if (/\\[Ll]\[(.+?)\]/.match(@now_text)) != nil then
  318.         @face = $1
  319.         if @left_picture != nil
  320.           @left_picture.dispose
  321.         end
  322.         @left_picture = Sprite.new
  323.         @left_picture.bitmap = RPG::Cache.face(@face)
  324.         @left_picture.mirror = true
  325.         @x = @face_indent = @left_picture.bitmap.width
  326.         @now_text.gsub!(/\\[Ll]\[(.*?)\]/) { "" }
  327.       end
  328.       #——右半身像设置
  329.       if (/\\[Rr]\[(.+?)\]/.match(@now_text)) != nil then
  330.         @face = $1
  331.         if @right_picture != nil
  332.           @right_picture.dispose
  333.         end
  334.         @right_picture = Sprite.new
  335.         @right_picture.bitmap = RPG::Cache.face(@face)
  336.         @now_text.gsub!(/\\[Rr]\[(.*?)\]/) { "" }
  337.       end
  338.       # 显示人物姓名
  339.       name_window_set = false
  340.       if (/\\[Nn]ame\[(.+?)\]/.match(@now_text)) != nil
  341.         name_window_set = true
  342.         name_text = $1
  343.         if Regex_Player_Name =~ name_text
  344.           name_text = $game_actors[$1.to_i].name
  345.         end
  346.         @now_text.sub!(/\\[Nn]ame\[(.*?)\]/) { "" }
  347.       end
  348.       # 人物姓名颜色
  349.       name_color = text_color(Name_Color_Default)
  350.       if (/\\[Nn]c\[(\d+)\]/.match(@now_text)) != nil
  351.         name_color = text_color($1.to_i)
  352.         @now_text.sub!(/\\[Nn]c\[(\d+)\]/) { "" }
  353.       end
  354.       # 文字位置的判定
  355.       if (/\\[Pp]\[([-1,0-9]+)\]/.match(@now_text)) != nil then
  356.         @popchar = $1.to_i
  357.         @now_text.gsub!(/\\[Pp]\[([-1,0-9]+)\]/) { "" }
  358.       end
  359.       # 自动结束判定
  360.       @auto_terminate = Auto_Terminate_Frame if $game_switches[Auto_Terminate]
  361.       if (/\\[Tt]\[(\d+)\]/).match(@now_text)
  362.         @auto_terminate = $1.to_i
  363.         @now_text.gsub!(/\\[Tt]\[(\d+)\]/) { "" }
  364.       end
  365.       # 开始替换文字(\v)
  366.       begin
  367.         last_text = @now_text.clone
  368.         @now_text.gsub!(/\\[Vv]\[([IiWwAaSs]?)([0-9]+)\]/) { convart_value($1, $2.to_i) }
  369.       end until @now_text == last_text
  370.       # 替换控制码
  371.       @now_text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  372.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  373.       end
  374.       @now_text.gsub!(/\\\\/) { "\000" }
  375.       @now_text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  376.       @now_text.gsub!(/\\[Gg]/) { "\002" }
  377.       @now_text.gsub!(/\\[Ss]\[([0-9]+)\]/) { "\003[#{$1}]" }
  378.       @now_text.gsub!(/\\[Aa]\[(.*?)\]/) { "\004[#{$1}]" }
  379.       @now_text.gsub!(/\\[.]/) { "\005" }
  380.       @now_text.gsub!(/\\[|]/) { "\006" }
  381.       @now_text.gsub!(/\\[Ii]c\[(.*?)\]/) { "\030[#{$1}] "}
  382.       @now_text.gsub!(/\\[>]/) { "\016" }
  383.       @now_text.gsub!(/\\[<]/) { "\017" }
  384.       @now_text.gsub!(/\\[!]/) { "\020" }
  385.       @now_text.gsub!(/\\[~]/) { "\021" }
  386.       @now_text.gsub!(/\\[Ii]/) { "\023" }
  387.       @now_text.gsub!(/\\[Oo]\[([0-9]+)\]/) { "\024[#{$1}]" }
  388.       @now_text.gsub!(/\\[Hh]\[([0-9]+)\]/) { "\025[#{$1}]" }
  389.       @now_text.gsub!(/\\[Bb]\[([0-9]+)\]/) { "\026[#{$1}]" }
  390.       # 根据 \p 的不同设置对话框大小
  391.       if @popchar >= 0 # \p 的情况下自动调节
  392.         @text_save = @now_text.clone
  393.         process_real_text
  394.         @max_x = name_window_set ? contents.text_size(name_text).width : 0
  395.         @max_y = Max_Lines
  396.         for i in 0...Max_Lines
  397.           line = @text_save.split(/\n/)[Max_Lines-i-1]
  398.           @max_y -= 1 if line == nil && @max_y <= Max_Lines - i
  399.           next if line == nil
  400.           contents.font.size = Size
  401.           cx = contents.text_size(line).width
  402.           @max_x = cx if cx > @max_x
  403.         end
  404.         if @right_picture != nil && !@right_picture.disposed?
  405.           self.width = @max_x + 48 + @face_indent + @right_picture.bitmap.width
  406.         else
  407.           self.width = @max_x + 48 + @face_indent
  408.         end
  409.         @face_h = @face_bitmap == nil ? 0 : [120, @face_bitmap.height].min
  410.         if $game_temp.num_input_variable_id > 0
  411.           self.height = [(@max_y - 1) * line_height + 96, @face_h + 32].max
  412.         else
  413.           self.height = [(@max_y - 1) * line_height + 64, @face_h + 32].max
  414.         end
  415.         # 生成气泡图标
  416.         @k_tale = Sprite.new
  417.       elsif @popchar == -1
  418.         line_count = @now_text.split(/\n/).size
  419.         line_count = [Max_Lines , [line_count, 4].max].min
  420.         self.width = Graphics_Width
  421.         self.height = [64 + line_height * (line_count - 1), @face_h + 32].max
  422.         @max_x = self.width - 32 - @face_indent
  423.       else
  424.         self.width = Graphics_Width * 0.6
  425.         self.height = 64 + line_height * 3
  426.         @max_x = self.width - 32 - @face_indent
  427.       end
  428.       # 如果设置了姓名框
  429.       if name_window_set
  430.         off_x = 0
  431.         off_y = -40
  432.         space = 2
  433.         x = self.x + off_x - space / 2
  434.         y = self.y + off_y - space / 2
  435.         w = self.contents.text_size(name_text).width + 26 + space
  436.         h = 40 + space
  437.         x = self.x + off_x + 4
  438.         y = self.y + off_y
  439.         @name_window_text = Air_Text.new(self.x + @face_indent+4+8, self.y+16, name_text, name_color)
  440.         @name_window_text.z = self.z + 2
  441.         @bar = Sprite.new
  442.         @bar.bitmap = Bitmap.new(self.width, 24)
  443.         face_cut = @face_bitmap == nil ? 0 : @face_indent + 2
  444.         @bar.x = self.x + 8 + face_cut
  445.         @bar.y = self.y + 16
  446.         @bar.z = self.z + 2
  447.         @bar.bitmap.fill_rect(0,0,self.width-16-face_cut,24, Name_Bar_Color)
  448.       end
  449.       # 一切设置完毕后,创建 contents
  450.       if self.contents != nil
  451.         self.contents.dispose
  452.         self.contents = nil
  453.       end
  454.       self.contents = Bitmap.new(width - 32, height - 32)
  455.       self.contents.font.color = normal_color
  456.       self.contents.font.size = Size
  457.     end
  458.     # 如果选择项被设置
  459.     if $game_temp.choice_max > 0
  460.       @item_max = $game_temp.choice_max
  461.       self.active = true
  462.       self.index = 0
  463.     end
  464.     # 如果数值输入被设置
  465.     if $game_temp.num_input_variable_id > 0
  466.       digits_max = $game_temp.num_input_digits_max
  467.       number = $game_variables[$game_temp.num_input_variable_id]
  468.       @input_number_window = Window_InputNumber.new(digits_max)
  469.       @input_number_window.number = number
  470.     end
  471.     # 更新窗口位置
  472.     update_window_pos
  473.   end
  474.   #--------------------------------------------------------------------------
  475.   # ● 更新
  476.   #--------------------------------------------------------------------------
  477.   def update
  478.     super
  479.     if @child_message_window != nil
  480.       for window in @child_message_window
  481.         window.update
  482.       end
  483.     end
  484.     # 使用默认窗口外观的情况下,如果窗口的外关被变更了、再设置
  485.     if $game_system.windowskin_name != @windowskin_name && Mes_Windowskin == ""
  486.       @windowskin_name = $game_system.windowskin_name
  487.       self.windowskin = RPG::Cache.windowskin(@windowskin_name)
  488.     end
  489.     # 地图中实时更新位置
  490.     if @k_tale != nil && @k_tale.visible && !$game_temp.in_battle
  491.       update_window_pos
  492.     end
  493.     # [空格键]跳过描绘
  494.     if $game_switches[Write_Skip] && Input.trigger?(Input::C) && self.visible
  495.       @write_skip = true
  496.     end
  497.     # CTRL 高速跳过对话
  498.     if $game_switches[Text_Skip_Fast] && Input.repeat?(Input::CTRL)
  499.       # 选择项或数字输入时无法高速跳过
  500.       if $game_temp.choice_max > 0 || @input_number_window != nil
  501.         @write_skip = true
  502.       else
  503.         @text_skip = true
  504.       end
  505.     end
  506.     # 描绘头像
  507.     if @face_bitmap != nil && !@face_ok
  508.       face_real_w = [120, @face_bitmap.width].min
  509.       face_real_h = [120, @face_bitmap.height].min
  510.       self.contents.stretch_blt(Rect.new(0, 0, face_real_w, face_real_h), @face_bitmap, Rect.new(0, 0, @face_bitmap.width, @face_bitmap.height))
  511.       @face_ok = true
  512.     end
  513.     # 淡入中的情况下
  514.     if @fade_in
  515.       self.contents_opacity += 24
  516.       if @input_number_window != nil
  517.         @input_number_window.contents_opacity += 24
  518.       end
  519.       if self.contents_opacity == 255
  520.         @fade_in = false
  521.       end
  522.       return
  523.     end
  524.     @now_text = nil if @now_text == ""
  525.     # 逐个描绘文字
  526.     if @now_text != nil && @mid_stop == false && !@text_skip
  527.       if @write_wait > 0
  528.         @write_wait -= 1
  529.         return
  530.       end
  531.       while true
  532.         @max_x = @x if @max_x < @x
  533.         @max_y = @y if @max_y < @y
  534.         # 处理字符
  535.         if (c = @now_text.slice!(/./m)) != nil
  536.           # \\的情况下
  537.           if c == "\000"
  538.             c = "\"
  539.           end
  540.           # \c的情况下
  541.           if c == "\001"
  542.             @now_text.sub!(/\[([0-9]+)\]/, "")
  543.             color = $1.to_i
  544.             if color >= 0 and color <= 7
  545.               self.contents.font.color = text_color(color)
  546.             end
  547.             c = ""
  548.           end
  549.           # \g的情况下
  550.           if c == "\002"
  551.             if @gold_window == nil && @popchar <= 0
  552.               @gold_window = Window_Gold.new
  553.               @gold_window.x = 560 - @gold_window.width
  554.               if $game_temp.in_battle
  555.                 @gold_window.y = 192
  556.               else
  557.                 @gold_window.y = self.y >= 128 ? 32 : 384
  558.               end
  559.               @gold_window.opacity = self.opacity
  560.               @gold_window.back_opacity = self.back_opacity
  561.             end
  562.             c = ""
  563.           end
  564.           # \s的情况下
  565.           if c == "\003"
  566.             @now_text.sub!(/\[([0-9]+)\]/, "")
  567.             speed = $1.to_i
  568.             if speed >= 0 and speed <= 19
  569.               @write_speed = speed
  570.             end
  571.             c = ""
  572.           end
  573.           # \a的情况下
  574.           if c == "\004"
  575.             @now_text.sub!(/\[(.*?)\]/, "")
  576.             se_filename = "Audio/SE/#{$1}"
  577.             if FileTest.exist?(se_filename)
  578.               Audio.se_play(se_filename)
  579.             end
  580.             c = ""
  581.           end
  582.           # \.的情况下
  583.           if c == "\005"
  584.             @write_wait += 5
  585.             c = ""
  586.           end
  587.           # \|的情况下
  588.           if c == "\006"
  589.             @write_wait += 20
  590.             c = ""
  591.           end
  592.           # \>的情况下
  593.           if c == "\016"
  594.             text_not_skip = false
  595.             c = ""
  596.           end
  597.           # \<的情况下
  598.           if c == "\017"
  599.             text_not_skip = true
  600.             c = ""
  601.           end
  602.           # \!的情况下
  603.           if c == "\020"
  604.             @mid_stop = true
  605.             c = ""
  606.           end
  607.           # \~的情况下
  608.           if c == "\021"
  609.             terminate_message
  610.             return
  611.           end
  612.           # \i的情况下
  613.           if c == "\023"
  614.             @indent = @x
  615.             c = ""
  616.           end
  617.           # \o的情况下
  618.           if c == "\024"
  619.             @now_text.sub!(/\[([0-9]+)\]/, "")
  620.             @opacity = $1.to_i
  621.             c = ""
  622.           end
  623.           # \h的情况下
  624.           if c == "\025"
  625.             @now_text.sub!(/\[([0-9]+)\]/, "")
  626.             self.contents.font.size = [[$1.to_i, 6].max, 32].min
  627.             c = ""
  628.           end
  629.           # \b的情况下
  630.           if c == "\026"
  631.             @now_text.sub!(/\[([0-9]+)\]/, "")
  632.             @x += $1.to_i
  633.             c = ""
  634.           end
  635.           # 图标的情况
  636.           if c == "\030"
  637.             @now_text.sub!(/\[(.*?)\]/, "")
  638.             self.contents.blt(@x , @y * line_height + (line_height - 24) / 2, RPG::Cache.icon($1), Rect.new(0, 0, 24, 24))
  639.             if $game_system.soundname_on_speak != ""
  640.               Audio.se_play($game_system.soundname_on_speak)
  641.             end
  642.             @x += 24
  643.             c = ""
  644.           end
  645.           # 另起一行的情况下
  646.           if c == "\n"
  647.             if @lines >= $game_temp.choice_start
  648.               @cursor_width = [@cursor_width, @max_x - @face_indent].max
  649.             end
  650.             @lines += 1
  651.             @y += 1
  652.             @x = 0 + @indent + @face_indent
  653.             if @lines >= $game_temp.choice_start
  654.               @x = 8 + @indent + @face_indent
  655.             end
  656.             c = ""
  657.           end
  658.           # \align[x]的处理 by Road
  659.           if c == "\"
  660.             if @now_text.sub!(/align\[([0-2])\]/, "") != nil
  661.               line_align = $1.to_i
  662.               line_width = get_line_width(@now_text[/.*?\n/])
  663.               if line_align == 1
  664.                 @x = 0 + @indent + @face_indent
  665.                 @x += (@max_x - @x - line_width) / 2
  666.               elsif line_align == 2
  667.                 @x = @max_x - line_width
  668.               end
  669.             end
  670.             c = ""
  671.           end
  672.           if c != ""
  673.             # 文字描画
  674.             @x += opacity_draw_text(self.contents, @x, @y * line_height + (line_height - self.contents.font.size) / 2, c, @opacity)
  675.             if $game_system.soundname_on_speak != "" then
  676.               Audio.se_play($game_system.soundname_on_speak)
  677.             end
  678.           end
  679.         else
  680.           break
  681.         end
  682.         if !$game_switches[No_Typing] && !@write_skip
  683.           break
  684.         end
  685.       end
  686.       @write_wait += @write_speed
  687.       return
  688.     end
  689.     # 数值输入的处理
  690.     if @input_number_window != nil
  691.       @input_number_window.update
  692.       # 确认
  693.       if Input.trigger?(Input::C)
  694.         $game_system.se_play($data_system.decision_se)
  695.         $game_variables[$game_temp.num_input_variable_id] =
  696.           @input_number_window.number
  697.         $game_map.need_refresh = true
  698.         @input_number_window.dispose
  699.         @input_number_window = nil
  700.         terminate_message
  701.       end
  702.       return
  703.     end
  704.     # 跳过对话
  705.     if @text_skip
  706.       @now_text = nil
  707.       terminate_message
  708.       return
  709.     end
  710.     # 文章显示中的情况下
  711.     if @contents_showing
  712.       if $game_temp.choice_max == 0
  713.         self.pause = true
  714.       end
  715.       # auto terminate
  716.       if $game_temp.choice_max == 0 && @auto_terminate > 0
  717.         @auto_terminate -= 1
  718.         if @auto_terminate == 0
  719.           terminate_message
  720.         end
  721.         return
  722.       end
  723.       # 取消
  724.       if Input.trigger?(Input::B)
  725.         if $game_temp.choice_max > 0 && $game_temp.choice_cancel_type > 0
  726.           $game_system.se_play($data_system.cancel_se)
  727.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  728.           terminate_message
  729.         end
  730.       end
  731.       # 确定
  732.       if Input.trigger?(Input::C)
  733.         if @mid_stop
  734.           @mid_stop = false
  735.           return
  736.         else
  737.           if $game_temp.choice_max > 0
  738.             $game_system.se_play($data_system.decision_se)
  739.             $game_temp.choice_proc.call(self.index)
  740.           end
  741.           terminate_message
  742.         end
  743.       end
  744.       return
  745.     end
  746.     if @fade_out == false and $game_temp.message_text != nil
  747.       @contents_showing = true
  748.       $game_temp.message_window_showing = true
  749.       refresh
  750.       Graphics.frame_reset
  751.       self.visible = true
  752.       self.contents_opacity = 0
  753.       if @input_number_window != nil
  754.         @input_number_window.contents_opacity = 0
  755.       end
  756.       @fade_in = true
  757.       if $more_message_text != nil
  758.         @child_message_window = Array.new($more_message_text.size, nil)
  759.         for i in 0 ... $more_message_text.size
  760.           @child_message_window[i] = Window_Message_add.new(i)
  761.         end
  762.       end
  763.       return
  764.     end
  765.     if self.visible
  766.       @fade_out = true
  767.       self.opacity -= 48
  768.       if self.opacity == 0
  769.         self.visible = false
  770.         @fade_out = false
  771.         $game_temp.message_window_showing = false
  772.       end
  773.       return
  774.     end
  775.   end
  776.   #--------------------------------------------------------------------------
  777.   # ● 获取当前行宽度 by Road
  778.   #--------------------------------------------------------------------------
  779.   def get_line_width(text)
  780.     bitmap = Bitmap.new(640, 480)
  781.     width = 0
  782.     loop do
  783.       if (c = text.slice!(/./m)) != nil
  784.           # \\的情况下
  785.           if c == "\000"
  786.             c = "\"
  787.           end
  788.           # \c的情况下
  789.           if c == "\001"
  790.             text.sub!(/\[([0-9]+)\]/, "")
  791.             c = ""
  792.           end
  793.           # \g的情况下
  794.           if c == "\002"
  795.             c = ""
  796.           end
  797.           # \s的情况下
  798.           if c == "\003"
  799.             text.sub!(/\[([0-9]+)\]/, "")
  800.             c = ""
  801.           end
  802.           # \a的情况下
  803.           if c == "\004"
  804.             text.sub!(/\[(.*?)\]/, "")
  805.             c = ""
  806.           end
  807.           # \.的情况下
  808.           if c == "\005"
  809.             c = ""
  810.           end
  811.           # \|的情况下
  812.           if c == "\006"
  813.             c = ""
  814.           end
  815.           # \>的情况下
  816.           if c == "\016"
  817.             c = ""
  818.           end
  819.           # \<的情况下
  820.           if c == "\017"
  821.             c = ""
  822.           end
  823.           # \!的情况下
  824.           if c == "\020"
  825.             c = ""
  826.           end
  827.           # \~的情况下
  828.           if c == "\021"
  829.             return
  830.           end
  831.           # \i的情况下
  832.           if c == "\023"
  833.             c = ""
  834.           end
  835.           # \o的情况下
  836.           if c == "\024"
  837.             @now_text.sub!(/\[([0-9]+)\]/, "")
  838.             c = ""
  839.           end
  840.           # \h的情况下
  841.           if c == "\025"
  842.             text.sub!(/\[([0-9]+)\]/, "")
  843.             bitmap.font.size = [[$1.to_i, 6].max, 32].min
  844.             c = ""
  845.           end
  846.           # \b的情况下
  847.           if c == "\026"
  848.             text.sub!(/\[([0-9]+)\]/, "")
  849.             width += $1.to_i
  850.             c = ""
  851.           end
  852.           # 图标的情况
  853.           if c == "\030"
  854.             text.sub!(/\[(.*?)\]/, "")
  855.             bitmap.blt(width , 0, RPG::Cache.icon($1), Rect.new(0, 0, 24, 24))
  856.             width += 24
  857.             c = ""
  858.           end
  859.           # 另起一行的情况下
  860.           if c == "\n"
  861.             c = ""
  862.           end
  863.           if c != ""
  864.             # 文字描画
  865.             width += opacity_draw_text(bitmap, width, 0, c, @opacity)
  866.           end
  867.         else
  868.           break
  869.         end
  870.     end
  871.     return width
  872.   end
  873.   #--------------------------------------------------------------------------
  874.   # ● 预览实际描绘内容(计算窗口宽用)
  875.   #--------------------------------------------------------------------------
  876.   #    实际对 @text_save 进行操作
  877.   #    此方法用于去除某些控制码引起窗口过长的影响
  878.   #--------------------------------------------------------------------------
  879.   def process_real_text
  880.     return if @text_save.nil?
  881.     regex = /[\001-\006\016\017\020\021\024](\[.*?\]){0,1}/
  882.     regex30 = /\030\[.*?\]/
  883.     @text_save.gsub!(regex, "")
  884.     @text_save.gsub!(regex30, "   ")
  885.   end
  886.   #--------------------------------------------------------------------------
  887.   # ● 获得角色(\p功能)
  888.   #--------------------------------------------------------------------------
  889.   def get_character(parameter)
  890.     case parameter
  891.     when 0
  892.       return $game_player
  893.     else
  894.       events = $game_map.events
  895.       return events == nil ? nil : events[parameter]
  896.     end
  897.   end
  898.   #--------------------------------------------------------------------------
  899.   # ● 获得战斗者(\p功能,此功能仅在战斗中有效)
  900.   #--------------------------------------------------------------------------
  901.   #    parameter : 1-999 表示主角 ID,1001-1008 表示索引为1-8的各个敌人
  902.   #--------------------------------------------------------------------------
  903.   def get_battler(parameter)
  904.     if parameter < 1000
  905.       return $game_actors[parameter]
  906.     else
  907.       return $game_troop.enemies[parameter - 1001]
  908.     end
  909.   end
  910.   #--------------------------------------------------------------------------
  911.   # ● 计算 y 偏移量(\p功能,这是考虑到不同战斗图/行走图的高度不同)
  912.   #--------------------------------------------------------------------------
  913.   #    character : 角色/战斗者
  914.   #--------------------------------------------------------------------------
  915.   def process_y_shift(character)
  916.     rate = character.is_a?(Game_Battler) ? 1 : 4
  917.     bmp = character.is_a?(Game_Battler) ?
  918.       RPG::Cache.battler(character.battler_name, character.battler_hue) :
  919.       RPG::Cache.character(character.character_name, character.character_hue)
  920.     return bmp.height / rate + 16
  921.   end
  922.   #--------------------------------------------------------------------------
  923.   # ● 更新窗口位置(所有组件)
  924.   #--------------------------------------------------------------------------
  925.   def update_window_pos
  926.     # 如果使用了 \p 设置位置
  927.     if @popchar >= 0
  928.       character = $game_temp.in_battle ? get_battler(@popchar) : get_character(@popchar)
  929.       final_pos = $game_system.message_position
  930.       if character != nil
  931.         x = [[character.screen_x - self.width / 2, 4].max, Graphics_Width - 4 - self.width].min
  932.         # adjust final_pos automatically when it is enabled
  933.         # ignore the case when pos == 1
  934.         if $game_switches[Auto_Adjust_Mes_Pos] && final_pos != 1
  935.           # try default mes_pos first
  936.           temp_y = final_pos == 2 ? [character.screen_y + 16, 4].max :
  937.             character.screen_y - process_y_shift(character) - self.height
  938.          
  939.           # set pos == 0 if temp_y exceeds the boundary of the screen
  940.           final_pos = 0 if temp_y > Graphics_Height - 4 - self.height && final_pos == 2
  941.           final_pos = 2 if temp_y < 4 && final_pos == 0
  942.         end
  943.         if final_pos == 2
  944.           y = [[character.screen_y + 16, 4].max, Graphics_Height - 4 - self.height].min
  945.         elsif final_pos == 0
  946.           y = [[character.screen_y - process_y_shift(character) - self.height, 4].max, Graphics_Height - 4 - self.height].min
  947.         else
  948.           x = (Graphics_Width - self.width) / 2
  949.           y = (Graphics_Height - self.height) / 2
  950.         end
  951.         self.x = x
  952.         self.y = y
  953.         # 设置气泡图标
  954.         if @k_tale != nil
  955.           @k_tale.x = character.is_a?(Game_Character) ?
  956.             ( character.real_x - $game_map.display_x + 64 ) * 32 / 128 - 16 :
  957.             character.screen_x
  958.           k_tale_filename = Mes_Windowskin == "" ? $game_system.windowskin_name : Mes_Windowskin
  959.           suffix = final_pos == 2 ? "-under" : "-top"
  960.           # reload @k_tale's bitmap
  961.           @k_tale.bitmap = RPG::Cache.windowskin(k_tale_filename + suffix)
  962.           if final_pos == 2
  963.             @k_tale.y = self.y - 16
  964.           elsif final_pos == 0
  965.             @k_tale.y = self.y + self.height - 16
  966.           else
  967.             @k_tale.visible = false
  968.           end
  969.           @k_tale.z = 9999
  970.         end
  971.       end
  972.     elsif @popchar == -1
  973.       self.x = 0
  974.       self.y = Graphics_Height - self.height
  975.     else # 无 \p 的情况下
  976.       self.x = (Graphics_Width - self.width) / 2
  977.       # 处于战斗中时
  978.       if $game_temp.in_battle
  979.         self.y = 16
  980.       else
  981.         # 显示文章位置的分支
  982.         case $game_system.message_position
  983.         when 0 # 上
  984.           self.y = 16
  985.         when 1 # 中
  986.           self.y = (Graphics_Height - self.height) / 2
  987.         when 2 # 下
  988.           self.y = (Graphics_Height - self.height - 16)
  989.         end
  990.       end
  991.     end # of @popchar >= 0
  992.     # 设置左侧立绘
  993.     if @left_picture != nil and !@left_picture.disposed?
  994.       @left_picture.x = self.x + 8
  995.       @left_picture.y = self.y - @left_picture.bitmap.height + self.height - 8
  996.       @left_picture.z = self.z + 4
  997.     end
  998.     # 设置右侧立绘
  999.     if @right_picture != nil and !@right_picture.disposed?
  1000.       @right_picture.x = self.x + self.width - @right_picture.bitmap.width - 8
  1001.       @right_picture.y = self.y - @right_picture.bitmap.height + self.height - 8
  1002.       @right_picture.z = self.z + 4
  1003.     end
  1004.     # 设置姓名空气文字坐标
  1005.     if @name_window_text != nil
  1006.       @name_window_text.x = self.x + @face_indent - 4
  1007.       @name_window_text.y = self.y
  1008.     end
  1009.     # 设置姓名蓝条坐标
  1010.     if @bar != nil
  1011.       face_cut = @face_bitmap == nil ? 0 : @face_indent + 2
  1012.       @bar.x = self.x + 8 + face_cut
  1013.       @bar.y = self.y + 16
  1014.     end
  1015.     # 设置数字处理
  1016.     if @input_number_window != nil
  1017.       @input_number_window.x = self.x + @face_indent
  1018.       @input_number_window.y = self.y + 8 + $game_temp.num_input_start * line_height
  1019.     end
  1020.     # 设置不透明度
  1021.     if $game_system.message_frame == 0
  1022.       self.opacity = 255
  1023.       self.back_opacity = 200
  1024.     else
  1025.       self.opacity = 0
  1026.       self.back_opacity = 200
  1027.     end
  1028.   end
  1029.   #--------------------------------------------------------------------------
  1030.   # ● line_height
  1031.   #--------------------------------------------------------------------------
  1032.   # 返回值 : 行高
  1033.   #--------------------------------------------------------------------------
  1034.   def line_height
  1035.     return [[Size * 15 / 10, 18].max, 32].min
  1036.   end
  1037.   #--------------------------------------------------------------------------
  1038.   # ● 文字描画
  1039.   #--------------------------------------------------------------------------
  1040.   # target :描绘的目标 bitmap 对象
  1041.   # x      :x 坐标
  1042.   # y      :y 坐标
  1043.   # str   :描绘的文字
  1044.   # opacity:不透明度(0~255)
  1045.   # 返回值 :文字宽度(@x 的增加值)。
  1046.   #--------------------------------------------------------------------------
  1047.   def opacity_draw_text(target, x, y, str,opacity)
  1048.     height = target.font.size
  1049.     width = target.text_size(str).width
  1050.     opacity = [[opacity, 0].max, 255].min
  1051.     if opacity == 255
  1052.       target.draw_text(x, y, width+1, height, str)
  1053.       return width
  1054.     else
  1055.       if @opacity_text_buf.width < width or @opacity_text_buf.height < height
  1056.         @opacity_text_buf.dispose
  1057.         @opacity_text_buf = Bitmap.new(width, height)
  1058.       else
  1059.         @opacity_text_buf.clear
  1060.       end
  1061.       @opacity_text_buf.font.size = target.font.size
  1062.       @opacity_text_buf.draw_text(0, 0, width+1, height, str)
  1063.       target.blt(x, y, @opacity_text_buf, Rect.new(0, 0, width, height), opacity)
  1064.     return width
  1065.     end
  1066.   end
  1067.   #--------------------------------------------------------------------------
  1068.   # ● \V 变换
  1069.   #--------------------------------------------------------------------------
  1070.   # option : 选项,'i'物品,'w'武器,'a'防具,'s'技能
  1071.   # index  : 数据库的索引
  1072.   #--------------------------------------------------------------------------
  1073.   def convart_value(option, index)
  1074.     option == nil ? option = "" : nil
  1075.     option.downcase!
  1076.     case option
  1077.       when "i"
  1078.         unless $data_items[index].name == nil
  1079.           r = sprintf("\030[%s]%s", $data_items[index].icon_name, $data_items[index].name)
  1080.         end
  1081.       when "w"
  1082.         unless $data_weapons[index].name == nil
  1083.           r = sprintf("\030[%s]%s", $data_weapons[index].icon_name, $data_weapons[index].name)
  1084.         end
  1085.       when "a"
  1086.         unless $data_armors[index].name == nil
  1087.           r = sprintf("\030[%s]%s", $data_armors[index].icon_name, $data_armors[index].name)
  1088.         end
  1089.       when "s"
  1090.         unless $data_skills[index].name == nil
  1091.           r = sprintf("\030[%s]%s", $data_skills[index].icon_name, $data_skills[index].name)
  1092.         end
  1093.       else
  1094.       r = $game_variables[index]
  1095.     end
  1096.     r == nil ? r = "" : nil
  1097.     return r
  1098.   end
  1099.   #--------------------------------------------------------------------------
  1100.   # ● 释放
  1101.   #--------------------------------------------------------------------------
  1102.   def dispose
  1103.     terminate_message
  1104.     unless @opacity_text_buf.disposed?
  1105.       @opacity_text_buf.dispose
  1106.     end
  1107.     $game_temp.message_window_showing = false
  1108.     if @input_number_window != nil
  1109.       @input_number_window.dispose
  1110.     end
  1111.     super
  1112.   end
  1113.   #--------------------------------------------------------------------------
  1114.   # ● 刷新光标矩形
  1115.   #--------------------------------------------------------------------------
  1116.   def update_cursor_rect
  1117.     if @index >= 0
  1118.       n = $game_temp.choice_start + @index
  1119.       self.cursor_rect.set(4 + @indent + @face_indent, n * line_height, @cursor_width, line_height)
  1120.     else
  1121.       self.cursor_rect.empty
  1122.     end
  1123.   end
  1124. end
  1125. #==============================================================================
  1126. # ■ Air_Text
  1127. #------------------------------------------------------------------------------
  1128. #   空气文字,借助窗口显示文字,但是不显示窗口载体。
  1129. #==============================================================================
  1130. class Air_Text < Window_Base
  1131.   #--------------------------------------------------------------------------
  1132.   # ● 对象初始化
  1133.   #--------------------------------------------------------------------------
  1134.   def initialize(x, y, designate_text, color)
  1135.     super(x-16, y-16, 32 + designate_text.size * 12, 56)
  1136.     self.opacity = 0
  1137.     self.back_opacity = 0
  1138.     self.contents = Bitmap.new(self.width - 32, self.height - 32)
  1139.     self.contents.font.size = 20
  1140.     self.contents.font.color = color
  1141.     w = self.contents.width
  1142.     h = self.contents.height
  1143.     self.contents.draw_text(0, 0, w, h, designate_text)
  1144.   end
  1145.   #--------------------------------------------------------------------------
  1146.   # ● 释放
  1147.   #--------------------------------------------------------------------------
  1148.   def dispose
  1149.     self.contents.clear
  1150.     super
  1151.   end
  1152. end

  1153. class Interpreter
  1154.   include RB::Mes_Config
  1155.   #--------------------------------------------------------------------------
  1156.   # ● 显示文章
  1157.   #--------------------------------------------------------------------------
  1158.   def command_101
  1159.     # 另外的文章已经设置过 message_text 的情况下
  1160.     if $game_temp.message_text != nil
  1161.       # 结束
  1162.       return false
  1163.     end
  1164.     # 设置信息结束后待机和返回调用标志
  1165.     @message_waiting = true
  1166.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  1167.     # message_text 设置为 1 行
  1168.     # check whether \+ exists
  1169.     append = /\\\+$/ =~ @list[@index].parameters[0]
  1170.     line = @list[@index].parameters[0].sub(/\\\+$/, "")
  1171.     $game_temp.message_text = line + "\n"
  1172.     line_count = 1
  1173.     # 循环
  1174.     loop do
  1175.       # 下一个事件指令为文章两行以上的情况
  1176.       if @list[@index+1].code == 401 || @list[@index+1].code == 101 && append
  1177.         append = /\\\+$/ =~ @list[@index+1].parameters[0]
  1178.         line = @list[@index+1].parameters[0].sub(/\\\+$/, "")
  1179.         # message_text 添加到第 2 行以下
  1180.         $game_temp.message_text += line + "\n"
  1181.         line_count += 1
  1182.       # 事件指令不在文章两行以下的情况
  1183.       else
  1184.         # 下一个事件指令为显示选择项的情况下
  1185.         if @list[@index+1].code == 102
  1186.           # 如果选择项能收纳在画面里
  1187.           if @list[@index+1].parameters[0].size <= Max_Lines - line_count
  1188.             # 推进索引
  1189.             @index += 1
  1190.             # 设置选择项
  1191.             $game_temp.choice_start = line_count
  1192.             setup_choices(@list[@index].parameters)
  1193.           end
  1194.         # 下一个事件指令为处理输入数值的情况下
  1195.         elsif @list[@index+1].code == 103
  1196.           # 如果数值输入窗口能收纳在画面里
  1197.           if line_count < Max_Lines
  1198.             # 推进索引
  1199.             @index += 1
  1200.             # 设置输入数值
  1201.             $game_temp.num_input_start = line_count
  1202.             $game_temp.num_input_variable_id = @list[@index].parameters[0]
  1203.             $game_temp.num_input_digits_max = @list[@index].parameters[1]
  1204.           end
  1205.         end
  1206.         # 继续
  1207.         return true
  1208.       end
  1209.       # 推进索引
  1210.       @index += 1
  1211.     end
  1212.   end
  1213. end

  1214. class Scene_Map
  1215.   include RB::Mes_Config
  1216.   alias rb_update_20160408 update
  1217.   def update
  1218.     if @rb_mes_disabled != $game_switches[Mes_Disabled]
  1219.       @rb_mes_disabled = $game_switches[Mes_Disabled]
  1220.       @message_window.dispose if @message_window != nil
  1221.       @message_window = @rb_mes_disabled ? Window_Message.new : Window_Message_RB.new
  1222.     end
  1223.     rb_update_20160408
  1224.   end
  1225. end

  1226. class Scene_Battle
  1227.   include RB::Mes_Config
  1228.   alias rb_update_20160408 update
  1229.   def update
  1230.     if @rb_mes_disabled != $game_switches[Mes_Disabled]
  1231.       @rb_mes_disabled = $game_switches[Mes_Disabled]
  1232.       @message_window.dispose if @message_window != nil
  1233.       @message_window = @rb_mes_disabled ? Window_Message.new : Window_Message_RB.new
  1234.     end
  1235.     rb_update_20160408
  1236.   end
  1237. end


  1238. #=============================================================================
复制代码




对话同时进行
处理子对话框的部分,主要部分也是在原版基础上更改的
  1. #==============================================================================
  2. # ■ 场景上可存在多个对话框 by Road
  3. #------------------------------------------------------------------------------
  4. #    通过set_message脚本可以创造出多个同时存在的对话框
  5. #    这里是处理子对话框的脚本,其中大部分内容与主对话框完全相同
  6. #★★切记:在主对话框修改一些功能时记得在子对话框里把对应的内容一并修改★★
  7. #==============================================================================
  8. class Window_Message_add < Window_Selectable
  9.   include RB::Mes_Config
  10.   #--------------------------------------------------------------------------
  11.   # ● 初始化状态
  12.   #--------------------------------------------------------------------------
  13.   def initialize(num)
  14.     super(80, 304, 480, 160)
  15.     self.contents = Bitmap.new(1, 1)
  16.     self.visible = false
  17.     self.z = 9998
  18.     @num = num
  19.     @fade_in = false
  20.     @fade_out = false
  21.     @contents_showing = false
  22.     @write_skip = false
  23.     @text_skip = false
  24.     @cursor_width = 0
  25.     @face_h = 0
  26.     self.active = false
  27.     self.index = -1
  28.     if $game_system.soundname_on_speak == nil then
  29.       $game_system.soundname_on_speak = ""
  30.     end
  31.     self.windowskin = RPG::Cache.windowskin(Mes_Windowskin) if Mes_Windowskin != ""
  32.     @opacity_text_buf = Bitmap.new(32, 32)
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 释放
  36.   #--------------------------------------------------------------------------
  37.   def dispose
  38.     terminate_message
  39.     super
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● 处理信息结束
  43.   #--------------------------------------------------------------------------
  44.   def terminate_message
  45.     self.active = false
  46.     self.pause = false
  47.     self.index = -1
  48.     self.contents.clear
  49.     # 清除头像(由于是 RPG::Cache 所以无需释放)
  50.     @face_bitmap = nil
  51.     @face_group_bitmap = nil
  52.     @face_ok = false
  53.     # 清除跳过标志
  54.     @write_skip = false
  55.     @text_skip = false
  56.     # 释放金钱窗口
  57.     if @gold_window != nil
  58.       @gold_window.dispose
  59.       @gold_window = nil
  60.     end
  61.     # 释放姓名窗口
  62.     if @name_window_text != nil
  63.       @name_window_text.dispose
  64.       @name_window_text = nil
  65.     end
  66.     # 释放右侧立绘
  67.     if @right_picture != nil
  68.       @right_picture.dispose
  69.       @right_picture = nil
  70.     end   
  71.     # 释放左侧立绘
  72.     if @left_picture != nil
  73.       @left_picture.dispose
  74.       @left_picture = nil
  75.     end
  76.     # 释放姓名蓝条
  77.     if @bar != nil
  78.       @bar.bitmap.dispose
  79.       @bar.dispose
  80.       @bar = nil
  81.     end
  82.     # 释放气泡图标
  83.     if @k_tale != nil
  84.       @k_tale.dispose
  85.       @k_tale = nil
  86.     end
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● 刷新
  90.   #--------------------------------------------------------------------------
  91.   def refresh
  92.     # 初期化
  93.     @x = @y = @max_x = @max_y = @indent = @lines = 0
  94.     @face_indent = 0
  95.     @opacity = 255
  96.     @cursor_width = 0
  97.     @write_speed = 1##
  98.     @write_wait = 0
  99.     @mid_stop = false
  100.     @popchar = -2
  101.     @auto_terminate = -1
  102.     if $game_temp.choice_start == 0
  103.       @x = 8
  104.     end
  105.     if $more_message_text[@num] != nil
  106.       @now_text = $more_message_text[@num]
  107.       # Shortcuts 预处理
  108.       @now_text.gsub!(/\\sc\[(.*?)\]/) { Shortcuts[$1] || "" }
  109.       # Shortcuts_Regexp 预处理
  110.       Shortcuts_Regexp.each_pair do |regex, str|
  111.         @now_text.gsub!(regex, str)
  112.       end
  113.       # 头像设置
  114.       if (/\\[Ff]\[(.+?)\]/.match(@now_text)) != nil
  115.         @face_bitmap = RPG::Cache.face($1)
  116.         @x = @face_indent = [128, @face_bitmap.width + 4].min
  117.         @now_text.gsub!(/\\[Ff]\[(.+?)\]/) { "" }
  118.       end
  119.       # 头像组设置
  120.       if (/\\[Gg]f\[(.+?)\s*,\s*(\d+)\]/).match(@now_text) != nil
  121.         @face_group_bitmap = RPG::Cache.face($1)
  122.         idx = $2.to_i
  123.         ix, iy = idx % Face_Group_W, idx / Face_Group_W
  124.         w, h = @face_group_bitmap.width / Face_Group_W, @face_group_bitmap.height / Face_Group_H
  125.         @face_bitmap = Bitmap.new(w, h)
  126.         @face_bitmap.blt(0, 0, @face_group_bitmap, Rect.new(ix * w, iy * h, w, h))
  127.         @x = @face_indent = [128, @face_bitmap.width + 4].min
  128.         @now_text.gsub!(/\\[Gg]f\[(.+?)\s*,\s*(\d+)\]/) { "" }
  129.       end
  130.       #——左半身像设置
  131.       if (/\\[Ll]\[(.+?)\]/.match(@now_text)) != nil then
  132.         @face = $1
  133.         if @left_picture != nil
  134.           @left_picture.dispose
  135.         end
  136.         @left_picture = Sprite.new
  137.         @left_picture.bitmap = RPG::Cache.face(@face)
  138.         @left_picture.mirror = true
  139.         @x = @face_indent = @left_picture.bitmap.width
  140.         @now_text.gsub!(/\\[Ll]\[(.*?)\]/) { "" }
  141.       end
  142.       #——右半身像设置
  143.       if (/\\[Rr]\[(.+?)\]/.match(@now_text)) != nil then
  144.         @face = $1
  145.         if @right_picture != nil
  146.           @right_picture.dispose
  147.         end
  148.         @right_picture = Sprite.new
  149.         @right_picture.bitmap = RPG::Cache.face(@face)
  150.         @now_text.gsub!(/\\[Rr]\[(.*?)\]/) { "" }
  151.       end
  152.       # 显示人物姓名
  153.       name_window_set = false
  154.       if (/\\[Nn]ame\[(.+?)\]/.match(@now_text)) != nil
  155.         name_window_set = true
  156.         name_text = $1
  157.         if Regex_Player_Name =~ name_text
  158.           name_text = $game_actors[$1.to_i].name
  159.         end
  160.         @now_text.sub!(/\\[Nn]ame\[(.*?)\]/) { "" }
  161.       end
  162.       # 人物姓名颜色
  163.       name_color = text_color(Name_Color_Default)
  164.       if (/\\[Nn]c\[(\d+)\]/.match(@now_text)) != nil
  165.         name_color = text_color($1.to_i)
  166.         @now_text.sub!(/\\[Nn]c\[(\d+)\]/) { "" }
  167.       end
  168.       # 文字位置的判定
  169.       if (/\\[Pp]\[([-1,0-9]+)\]/.match(@now_text)) != nil then
  170.         @popchar = $1.to_i
  171.         @now_text.gsub!(/\\[Pp]\[([-1,0-9]+)\]/) { "" }
  172.       end
  173.       # 自动结束判定
  174.       @auto_terminate = Auto_Terminate_Frame if $game_switches[Auto_Terminate]
  175.       if (/\\[Tt]\[(\d+)\]/).match(@now_text)
  176.         @auto_terminate = $1.to_i
  177.         @now_text.gsub!(/\\[Tt]\[(\d+)\]/) { "" }
  178.       end
  179.       # 开始替换文字(\v)
  180.       begin
  181.         last_text = @now_text.clone
  182.         @now_text.gsub!(/\\[Vv]\[([IiWwAaSs]?)([0-9]+)\]/) { convart_value($1, $2.to_i) }
  183.       end until @now_text == last_text
  184.       # 替换控制码
  185.       @now_text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  186.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  187.       end
  188.       @now_text.gsub!(/\\\\/) { "\000" }
  189.       @now_text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  190.       @now_text.gsub!(/\\[Gg]/) { "\002" }
  191.       @now_text.gsub!(/\\[Ss]\[([0-9]+)\]/) { "\003[#{$1}]" }
  192.       @now_text.gsub!(/\\[Aa]\[(.*?)\]/) { "\004[#{$1}]" }
  193.       @now_text.gsub!(/\\[.]/) { "\005" }
  194.       @now_text.gsub!(/\\[|]/) { "\006" }
  195.       @now_text.gsub!(/\\[Ii]c\[(.*?)\]/) { "\030[#{$1}] "}
  196.       @now_text.gsub!(/\\[>]/) { "\016" }
  197.       @now_text.gsub!(/\\[<]/) { "\017" }
  198.       @now_text.gsub!(/\\[!]/) { "\020" }
  199.       @now_text.gsub!(/\\[~]/) { "\021" }
  200.       @now_text.gsub!(/\\[Ii]/) { "\023" }
  201.       @now_text.gsub!(/\\[Oo]\[([0-9]+)\]/) { "\024[#{$1}]" }
  202.       @now_text.gsub!(/\\[Hh]\[([0-9]+)\]/) { "\025[#{$1}]" }
  203.       @now_text.gsub!(/\\[Bb]\[([0-9]+)\]/) { "\026[#{$1}]" }
  204.       # 根据 \p 的不同设置对话框大小
  205.       if @popchar >= 0 # \p 的情况下自动调节
  206.         @text_save = @now_text.clone
  207.         process_real_text
  208.         @max_x = name_window_set ? contents.text_size(name_text).width : 0
  209.         @max_y = Max_Lines
  210.         for i in 0...Max_Lines
  211.           line = @text_save.split(/\n/)[Max_Lines-i-1]
  212.           @max_y -= 1 if line == nil && @max_y <= Max_Lines - i
  213.           next if line == nil
  214.           contents.font.size = Size
  215.           cx = contents.text_size(line).width
  216.           @max_x = cx if cx > @max_x
  217.         end
  218.         if @right_picture != nil && !@right_picture.disposed?
  219.           self.width = @max_x + 48 + @face_indent + @right_picture.bitmap.width
  220.         else
  221.           self.width = @max_x + 48 + @face_indent
  222.         end
  223.         @face_h = @face_bitmap == nil ? 0 : [120, @face_bitmap.height].min
  224.         if $game_temp.num_input_variable_id > 0
  225.           self.height = [(@max_y - 1) * line_height + 96, @face_h + 32].max
  226.         else
  227.           self.height = [(@max_y - 1) * line_height + 64, @face_h + 32].max
  228.         end
  229.         # 生成气泡图标
  230.         @k_tale = Sprite.new
  231.       elsif @popchar == -1
  232.         line_count = @now_text.split(/\n/).size
  233.         line_count = [Max_Lines , [line_count, 4].max].min
  234.         self.width = Graphics_Width
  235.         self.height = [64 + line_height * (line_count - 1), @face_h + 32].max
  236.         @max_x = self.width - 32 - @face_indent
  237.       else
  238.         self.width = Graphics_Width * 0.6
  239.         self.height = 64 + line_height * 3
  240.         @max_x = self.width - 32 - @face_indent
  241.       end
  242.       # 如果设置了姓名框
  243.       if name_window_set
  244.         off_x = 0
  245.         off_y = -40
  246.         space = 2
  247.         x = self.x + off_x - space / 2
  248.         y = self.y + off_y - space / 2
  249.         w = self.contents.text_size(name_text).width + 26 + space
  250.         h = 40 + space
  251.         x = self.x + off_x + 4
  252.         y = self.y + off_y
  253.         @name_window_text = Air_Text.new(self.x + @face_indent+4+8, self.y+16, name_text, name_color)
  254.         @name_window_text.z = self.z + 2
  255.         @bar = Sprite.new
  256.         @bar.bitmap = Bitmap.new(self.width, 24)
  257.         face_cut = @face_bitmap == nil ? 0 : @face_indent + 2
  258.         @bar.x = self.x + 8 + face_cut
  259.         @bar.y = self.y + 16
  260.         @bar.z = self.z + 2
  261.         @bar.bitmap.fill_rect(0,0,self.width-16-face_cut,24, Name_Bar_Color)
  262.       end
  263.       # 一切设置完毕后,创建 contents
  264.       if self.contents != nil
  265.         self.contents.dispose
  266.         self.contents = nil
  267.       end
  268.       self.contents = Bitmap.new(width - 32, height - 32)
  269.       self.contents.font.color = normal_color
  270.       self.contents.font.size = Size
  271.     end
  272.     # 如果选择项被设置
  273.     if $game_temp.choice_max > 0
  274.       @item_max = $game_temp.choice_max
  275.       self.active = true
  276.       self.index = 0
  277.     end
  278.     # 如果数值输入被设置
  279.     if $game_temp.num_input_variable_id > 0
  280.       digits_max = $game_temp.num_input_digits_max
  281.       number = $game_variables[$game_temp.num_input_variable_id]
  282.       @input_number_window = Window_InputNumber.new(digits_max)
  283.       @input_number_window.number = number
  284.     end
  285.     # 更新窗口位置
  286.     update_window_pos
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # ● 更新
  290.   #--------------------------------------------------------------------------
  291.   def update
  292.     if self.disposed?
  293.       return
  294.     end
  295.     super
  296.     # 使用默认窗口外观的情况下,如果窗口的外关被变更了、再设置
  297.     if $game_system.windowskin_name != @windowskin_name && Mes_Windowskin == ""
  298.       @windowskin_name = $game_system.windowskin_name
  299.       self.windowskin = RPG::Cache.windowskin(@windowskin_name)
  300.     end
  301.     # 地图中实时更新位置
  302.     if @k_tale != nil && @k_tale.visible && !$game_temp.in_battle
  303.       update_window_pos
  304.     end
  305.     # [空格键]跳过描绘
  306.     if $game_switches[Write_Skip] && Input.trigger?(Input::C) && self.visible
  307.       @write_skip = true
  308.     end
  309.     # CTRL 高速跳过对话
  310.     if $game_switches[Text_Skip_Fast] && Input.repeat?(Input::CTRL)
  311.       # 选择项或数字输入时无法高速跳过
  312.       if $game_temp.choice_max > 0 || @input_number_window != nil
  313.         @write_skip = true
  314.       else
  315.         @text_skip = true
  316.       end
  317.     end
  318.     # 描绘头像
  319.     if @face_bitmap != nil && !@face_ok
  320.       face_real_w = [120, @face_bitmap.width].min
  321.       face_real_h = [120, @face_bitmap.height].min
  322.       self.contents.stretch_blt(Rect.new(0, 0, face_real_w, face_real_h), @face_bitmap, Rect.new(0, 0, @face_bitmap.width, @face_bitmap.height))
  323.       @face_ok = true
  324.     end
  325.     # 淡入中的情况下
  326.     if @fade_in
  327.       self.contents_opacity += 24
  328.       if @input_number_window != nil
  329.         @input_number_window.contents_opacity += 24
  330.       end
  331.       if self.contents_opacity == 255
  332.         @fade_in = false
  333.       end
  334.       return
  335.     end
  336.     @now_text = nil if @now_text == ""
  337.     # 逐个描绘文字
  338.     if @now_text != nil && @mid_stop == false && !@text_skip
  339.       if @write_wait > 0
  340.         @write_wait -= 1
  341.         return
  342.       end
  343.       while true
  344.         @max_x = @x if @max_x < @x
  345.         @max_y = @y if @max_y < @y
  346.         # 处理字符
  347.         if (c = @now_text.slice!(/./m)) != nil
  348.           # \\的情况下
  349.           if c == "\000"
  350.             c = "\"
  351.           end
  352.           # \c的情况下
  353.           if c == "\001"
  354.             @now_text.sub!(/\[([0-9]+)\]/, "")
  355.             color = $1.to_i
  356.             if color >= 0 and color <= 7
  357.               self.contents.font.color = text_color(color)
  358.             end
  359.             c = ""
  360.           end
  361.           # \g的情况下
  362.           if c == "\002"
  363.             if @gold_window == nil && @popchar <= 0
  364.               @gold_window = Window_Gold.new
  365.               @gold_window.x = 560 - @gold_window.width
  366.               if $game_temp.in_battle
  367.                 @gold_window.y = 192
  368.               else
  369.                 @gold_window.y = self.y >= 128 ? 32 : 384
  370.               end
  371.               @gold_window.opacity = self.opacity
  372.               @gold_window.back_opacity = self.back_opacity
  373.             end
  374.             c = ""
  375.           end
  376.           # \s的情况下
  377.           if c == "\003"
  378.             @now_text.sub!(/\[([0-9]+)\]/, "")
  379.             speed = $1.to_i
  380.             if speed >= 0 and speed <= 19
  381.               @write_speed = speed
  382.             end
  383.             c = ""
  384.           end
  385.           # \a的情况下
  386.           if c == "\004"
  387.             @now_text.sub!(/\[(.*?)\]/, "")
  388.             se_filename = "Audio/SE/#{$1}"
  389.             if FileTest.exist?(se_filename)
  390.               Audio.se_play(se_filename)
  391.             end
  392.             c = ""
  393.           end
  394.           # \.的情况下
  395.           if c == "\005"
  396.             @write_wait += 5
  397.             c = ""
  398.           end
  399.           # \|的情况下
  400.           if c == "\006"
  401.             @write_wait += 20
  402.             c = ""
  403.           end
  404.           # \>的情况下
  405.           if c == "\016"
  406.             text_not_skip = false
  407.             c = ""
  408.           end
  409.           # \<的情况下
  410.           if c == "\017"
  411.             text_not_skip = true
  412.             c = ""
  413.           end
  414.           # \!的情况下
  415.           if c == "\020"
  416.             @mid_stop = true
  417.             c = ""
  418.           end
  419.           # \~的情况下
  420.           if c == "\021"
  421.             terminate_message
  422.             return
  423.           end
  424.           # \i的情况下
  425.           if c == "\023"
  426.             @indent = @x
  427.             c = ""
  428.           end
  429.           # \o的情况下
  430.           if c == "\024"
  431.             @now_text.sub!(/\[([0-9]+)\]/, "")
  432.             @opacity = $1.to_i
  433.             c = ""
  434.           end
  435.           # \h的情况下
  436.           if c == "\025"
  437.             @now_text.sub!(/\[([0-9]+)\]/, "")
  438.             self.contents.font.size = [[$1.to_i, 6].max, 32].min
  439.             c = ""
  440.           end
  441.           # \b的情况下
  442.           if c == "\026"
  443.             @now_text.sub!(/\[([0-9]+)\]/, "")
  444.             @x += $1.to_i
  445.             c = ""
  446.           end
  447.           # 图标的情况
  448.           if c == "\030"
  449.             @now_text.sub!(/\[(.*?)\]/, "")
  450.             self.contents.blt(@x , @y * line_height + (line_height - 24) / 2, RPG::Cache.icon($1), Rect.new(0, 0, 24, 24))
  451.             if $game_system.soundname_on_speak != ""
  452.               Audio.se_play($game_system.soundname_on_speak)
  453.             end
  454.             @x += 24
  455.             c = ""
  456.           end
  457.           # 另起一行的情况下
  458.           if c == "\n"
  459.             if @lines >= $game_temp.choice_start
  460.               @cursor_width = [@cursor_width, @max_x - @face_indent].max
  461.             end
  462.             @lines += 1
  463.             @y += 1
  464.             @x = 0 + @indent + @face_indent
  465.             if @lines >= $game_temp.choice_start
  466.               @x = 8 + @indent + @face_indent
  467.             end
  468.             c = ""
  469.           end
  470.           # \align[x]的处理 by Road
  471.           if c == "\"
  472.             if @now_text.sub!(/align\[([0-2])\]/, "") != nil
  473.               line_align = $1.to_i
  474.               line_width = get_line_width(@now_text[/.*?\n/])
  475.               if line_align == 1
  476.                 @x = 0 + @indent + @face_indent
  477.                 @x += (@max_x - @x - line_width) / 2
  478.               elsif line_align == 2
  479.                 @x = @max_x - line_width
  480.               end
  481.             end
  482.             c = ""
  483.           end
  484.           if c != ""
  485.             # 文字描画
  486.             @x += opacity_draw_text(self.contents, @x, @y * line_height + (line_height - self.contents.font.size) / 2, c, @opacity)
  487.             if $game_system.soundname_on_speak != "" then
  488.               Audio.se_play($game_system.soundname_on_speak)
  489.             end
  490.           end
  491.         else
  492.           break
  493.         end
  494.         if !$game_switches[No_Typing] && !@write_skip
  495.           break
  496.         end
  497.       end
  498.       @write_wait += @write_speed
  499.       return
  500.     end
  501.     # 跳过对话
  502.     if @text_skip
  503.       @now_text = nil
  504.       terminate_message
  505.       return
  506.     end
  507.     # 文章显示中的情况下
  508.     if @contents_showing
  509.       if $game_temp.choice_max == 0
  510.         self.pause = true
  511.       end
  512.       # auto terminate
  513.       if $game_temp.choice_max == 0 && @auto_terminate > 0
  514.         @auto_terminate -= 1
  515.         if @auto_terminate == 0
  516.           terminate_message
  517.         end
  518.         return
  519.       end
  520.       return
  521.     end
  522.     if @fade_out == false and $more_message_text[@num] != nil
  523.       @contents_showing = true
  524.       $game_temp.message_window_showing = true
  525.       refresh
  526.       Graphics.frame_reset
  527.       self.visible = true
  528.       self.contents_opacity = 0
  529.       if @input_number_window != nil
  530.         @input_number_window.contents_opacity = 0
  531.       end
  532.       @fade_in = true
  533.       return
  534.     end
  535.     if self.visible
  536.       @fade_out = true
  537.       self.opacity -= 48
  538.       if self.opacity == 0
  539.         self.visible = false
  540.         @fade_out = false
  541.         $game_temp.message_window_showing = false
  542.       end
  543.       return
  544.     end
  545.   end
  546.   #--------------------------------------------------------------------------
  547.   # ● 获取当前行宽度 by Road
  548.   #--------------------------------------------------------------------------
  549.   def get_line_width(text)
  550.     bitmap = Bitmap.new(640, 480)
  551.     width = 0
  552.     loop do
  553.       if (c = text.slice!(/./m)) != nil
  554.           # \\的情况下
  555.           if c == "\000"
  556.             c = "\"
  557.           end
  558.           # \c的情况下
  559.           if c == "\001"
  560.             text.sub!(/\[([0-9]+)\]/, "")
  561.             c = ""
  562.           end
  563.           # \g的情况下
  564.           if c == "\002"
  565.             c = ""
  566.           end
  567.           # \s的情况下
  568.           if c == "\003"
  569.             text.sub!(/\[([0-9]+)\]/, "")
  570.             c = ""
  571.           end
  572.           # \a的情况下
  573.           if c == "\004"
  574.             text.sub!(/\[(.*?)\]/, "")
  575.             c = ""
  576.           end
  577.           # \.的情况下
  578.           if c == "\005"
  579.             c = ""
  580.           end
  581.           # \|的情况下
  582.           if c == "\006"
  583.             c = ""
  584.           end
  585.           # \>的情况下
  586.           if c == "\016"
  587.             c = ""
  588.           end
  589.           # \<的情况下
  590.           if c == "\017"
  591.             c = ""
  592.           end
  593.           # \!的情况下
  594.           if c == "\020"
  595.             c = ""
  596.           end
  597.           # \~的情况下
  598.           if c == "\021"
  599.             return
  600.           end
  601.           # \i的情况下
  602.           if c == "\023"
  603.             c = ""
  604.           end
  605.           # \o的情况下
  606.           if c == "\024"
  607.             @now_text.sub!(/\[([0-9]+)\]/, "")
  608.             c = ""
  609.           end
  610.           # \h的情况下
  611.           if c == "\025"
  612.             text.sub!(/\[([0-9]+)\]/, "")
  613.             bitmap.font.size = [[$1.to_i, 6].max, 32].min
  614.             c = ""
  615.           end
  616.           # \b的情况下
  617.           if c == "\026"
  618.             text.sub!(/\[([0-9]+)\]/, "")
  619.             width += $1.to_i
  620.             c = ""
  621.           end
  622.           # 图标的情况
  623.           if c == "\030"
  624.             text.sub!(/\[(.*?)\]/, "")
  625.             bitmap.blt(width , 0, RPG::Cache.icon($1), Rect.new(0, 0, 24, 24))
  626.             width += 24
  627.             c = ""
  628.           end
  629.           # 另起一行的情况下
  630.           if c == "\n"
  631.             c = ""
  632.           end
  633.           if c != ""
  634.             # 文字描画
  635.             width += opacity_draw_text(bitmap, width, 0, c, @opacity)
  636.           end
  637.         else
  638.           break
  639.         end
  640.     end
  641.     return width
  642.   end
  643.   #--------------------------------------------------------------------------
  644.   # ● 预览实际描绘内容(计算窗口宽用)
  645.   #--------------------------------------------------------------------------
  646.   #    实际对 @text_save 进行操作
  647.   #    此方法用于去除某些控制码引起窗口过长的影响
  648.   #--------------------------------------------------------------------------
  649.   def process_real_text
  650.     return if @text_save.nil?
  651.     regex = /[\001-\006\016\017\020\021\024](\[.*?\]){0,1}/
  652.     regex30 = /\030\[.*?\]/
  653.     @text_save.gsub!(regex, "")
  654.     @text_save.gsub!(regex30, "   ")
  655.   end
  656.   #--------------------------------------------------------------------------
  657.   # ● 获得角色(\p功能)
  658.   #--------------------------------------------------------------------------
  659.   def get_character(parameter)
  660.     case parameter
  661.     when 0
  662.       return $game_player
  663.     else
  664.       events = $game_map.events
  665.       return events == nil ? nil : events[parameter]
  666.     end
  667.   end
  668.   #--------------------------------------------------------------------------
  669.   # ● 获得战斗者(\p功能,此功能仅在战斗中有效)
  670.   #--------------------------------------------------------------------------
  671.   #    parameter : 1-999 表示主角 ID,1001-1008 表示索引为1-8的各个敌人
  672.   #--------------------------------------------------------------------------
  673.   def get_battler(parameter)
  674.     if parameter < 1000
  675.       return $game_actors[parameter]
  676.     else
  677.       return $game_troop.enemies[parameter - 1001]
  678.     end
  679.   end
  680.   #--------------------------------------------------------------------------
  681.   # ● 计算 y 偏移量(\p功能,这是考虑到不同战斗图/行走图的高度不同)
  682.   #--------------------------------------------------------------------------
  683.   #    character : 角色/战斗者
  684.   #--------------------------------------------------------------------------
  685.   def process_y_shift(character)
  686.     rate = character.is_a?(Game_Battler) ? 1 : 4
  687.     bmp = character.is_a?(Game_Battler) ?
  688.       RPG::Cache.battler(character.battler_name, character.battler_hue) :
  689.       RPG::Cache.character(character.character_name, character.character_hue)
  690.     return bmp.height / rate + 16
  691.   end
  692.   #--------------------------------------------------------------------------
  693.   # ● 更新窗口位置(所有组件)
  694.   #--------------------------------------------------------------------------
  695.   def update_window_pos
  696.     # 如果使用了 \p 设置位置
  697.     if @popchar >= 0
  698.       character = $game_temp.in_battle ? get_battler(@popchar) : get_character(@popchar)
  699.       final_pos = $game_system.message_position
  700.       if character != nil
  701.         x = [[character.screen_x - self.width / 2, 4].max, Graphics_Width - 4 - self.width].min
  702.         # adjust final_pos automatically when it is enabled
  703.         # ignore the case when pos == 1
  704.         if $game_switches[Auto_Adjust_Mes_Pos] && final_pos != 1
  705.           # try default mes_pos first
  706.           temp_y = final_pos == 2 ? [character.screen_y + 16, 4].max :
  707.             character.screen_y - process_y_shift(character) - self.height
  708.          
  709.           # set pos == 0 if temp_y exceeds the boundary of the screen
  710.           final_pos = 0 if temp_y > Graphics_Height - 4 - self.height && final_pos == 2
  711.           final_pos = 2 if temp_y < 4 && final_pos == 0
  712.         end
  713.         if final_pos == 2
  714.           y = [[character.screen_y + 16, 4].max, Graphics_Height - 4 - self.height].min
  715.         elsif final_pos == 0
  716.           y = [[character.screen_y - process_y_shift(character) - self.height, 4].max, Graphics_Height - 4 - self.height].min
  717.         else
  718.           x = (Graphics_Width - self.width) / 2
  719.           y = (Graphics_Height - self.height) / 2
  720.         end
  721.         self.x = x
  722.         self.y = y
  723.         # 设置气泡图标
  724.         if @k_tale != nil
  725.           @k_tale.x = character.is_a?(Game_Character) ?
  726.             ( character.real_x - $game_map.display_x + 64 ) * 32 / 128 - 16 :
  727.             character.screen_x
  728.           k_tale_filename = Mes_Windowskin == "" ? $game_system.windowskin_name : Mes_Windowskin
  729.           suffix = final_pos == 2 ? "-under" : "-top"
  730.           # reload @k_tale's bitmap
  731.           @k_tale.bitmap = RPG::Cache.windowskin(k_tale_filename + suffix)
  732.           if final_pos == 2
  733.             @k_tale.y = self.y - 16
  734.           elsif final_pos == 0
  735.             @k_tale.y = self.y + self.height - 16
  736.           else
  737.             @k_tale.visible = false
  738.           end
  739.           @k_tale.z = 9999
  740.         end
  741.       end
  742.     elsif @popchar == -1
  743.       self.x = 0
  744.       self.y = Graphics_Height - self.height
  745.     else # 无 \p 的情况下
  746.       self.x = (Graphics_Width - self.width) / 2
  747.       # 处于战斗中时
  748.       if $game_temp.in_battle
  749.         self.y = 16
  750.       else
  751.         # 显示文章位置的分支
  752.         case $game_system.message_position
  753.         when 0 # 上
  754.           self.y = 16
  755.         when 1 # 中
  756.           self.y = (Graphics_Height - self.height) / 2
  757.         when 2 # 下
  758.           self.y = (Graphics_Height - self.height - 16)
  759.         end
  760.       end
  761.     end # of @popchar >= 0
  762.     # 设置左侧立绘
  763.     if @left_picture != nil and !@left_picture.disposed?
  764.       @left_picture.x = self.x + 8
  765.       @left_picture.y = self.y - @left_picture.bitmap.height + self.height - 8
  766.       @left_picture.z = self.z + 4
  767.     end
  768.     # 设置右侧立绘
  769.     if @right_picture != nil and !@right_picture.disposed?
  770.       @right_picture.x = self.x + self.width - @right_picture.bitmap.width - 8
  771.       @right_picture.y = self.y - @right_picture.bitmap.height + self.height - 8
  772.       @right_picture.z = self.z + 4
  773.     end
  774.     # 设置姓名空气文字坐标
  775.     if @name_window_text != nil
  776.       @name_window_text.x = self.x + @face_indent - 4
  777.       @name_window_text.y = self.y
  778.     end
  779.     # 设置姓名蓝条坐标
  780.     if @bar != nil
  781.       face_cut = @face_bitmap == nil ? 0 : @face_indent + 2
  782.       @bar.x = self.x + 8 + face_cut
  783.       @bar.y = self.y + 16
  784.     end
  785.     # 设置数字处理
  786.     if @input_number_window != nil
  787.       @input_number_window.x = self.x + @face_indent
  788.       @input_number_window.y = self.y + 8 + $game_temp.num_input_start * line_height
  789.     end
  790.     # 设置不透明度
  791.     if $game_system.message_frame == 0
  792.       self.opacity = 255
  793.       self.back_opacity = 200
  794.     else
  795.       self.opacity = 0
  796.       self.back_opacity = 200
  797.     end
  798.   end
  799.   #--------------------------------------------------------------------------
  800.   # ● line_height
  801.   #--------------------------------------------------------------------------
  802.   # 返回值 : 行高
  803.   #--------------------------------------------------------------------------
  804.   def line_height
  805.     return [[Size * 15 / 10, 18].max, 32].min
  806.   end
  807.   #--------------------------------------------------------------------------
  808.   # ● 文字描画
  809.   #--------------------------------------------------------------------------
  810.   # target :描绘的目标 bitmap 对象
  811.   # x      :x 坐标
  812.   # y      :y 坐标
  813.   # str   :描绘的文字
  814.   # opacity:不透明度(0~255)
  815.   # 返回值 :文字宽度(@x 的增加值)。
  816.   #--------------------------------------------------------------------------
  817.   def opacity_draw_text(target, x, y, str,opacity)
  818.     height = target.font.size
  819.     width = target.text_size(str).width
  820.     opacity = [[opacity, 0].max, 255].min
  821.     if opacity == 255
  822.       target.draw_text(x, y, width+1, height, str)
  823.       return width
  824.     else
  825.       if @opacity_text_buf.width < width or @opacity_text_buf.height < height
  826.         @opacity_text_buf.dispose
  827.         @opacity_text_buf = Bitmap.new(width, height)
  828.       else
  829.         @opacity_text_buf.clear
  830.       end
  831.       @opacity_text_buf.font.size = target.font.size
  832.       @opacity_text_buf.draw_text(0, 0, width+1, height, str)
  833.       target.blt(x, y, @opacity_text_buf, Rect.new(0, 0, width, height), opacity)
  834.     return width
  835.     end
  836.   end
  837.   #--------------------------------------------------------------------------
  838.   # ● \V 变换
  839.   #--------------------------------------------------------------------------
  840.   # option : 选项,'i'物品,'w'武器,'a'防具,'s'技能
  841.   # index  : 数据库的索引
  842.   #--------------------------------------------------------------------------
  843.   def convart_value(option, index)
  844.     option == nil ? option = "" : nil
  845.     option.downcase!
  846.     case option
  847.       when "i"
  848.         unless $data_items[index].name == nil
  849.           r = sprintf("\030[%s]%s", $data_items[index].icon_name, $data_items[index].name)
  850.         end
  851.       when "w"
  852.         unless $data_weapons[index].name == nil
  853.           r = sprintf("\030[%s]%s", $data_weapons[index].icon_name, $data_weapons[index].name)
  854.         end
  855.       when "a"
  856.         unless $data_armors[index].name == nil
  857.           r = sprintf("\030[%s]%s", $data_armors[index].icon_name, $data_armors[index].name)
  858.         end
  859.       when "s"
  860.         unless $data_skills[index].name == nil
  861.           r = sprintf("\030[%s]%s", $data_skills[index].icon_name, $data_skills[index].name)
  862.         end
  863.       else
  864.       r = $game_variables[index]
  865.     end
  866.     r == nil ? r = "" : nil
  867.     return r
  868.   end
  869.   #--------------------------------------------------------------------------
  870.   # ● 释放
  871.   #--------------------------------------------------------------------------
  872.   def dispose
  873.     terminate_message
  874.     unless @opacity_text_buf.disposed?
  875.       @opacity_text_buf.dispose
  876.     end
  877.     $game_temp.message_window_showing = false
  878.     if @input_number_window != nil
  879.       @input_number_window.dispose
  880.     end
  881.     super
  882.   end
  883.   #--------------------------------------------------------------------------
  884.   # ● 刷新光标矩形
  885.   #--------------------------------------------------------------------------
  886.   def update_cursor_rect
  887.     if @index >= 0
  888.       n = $game_temp.choice_start + @index
  889.       self.cursor_rect.set(4 + @indent + @face_indent, n * line_height, @cursor_width, line_height)
  890.     else
  891.       self.cursor_rect.empty
  892.     end
  893.   end
  894. end
复制代码




实现的效果:
QQ图片20190406085611.png

文字部分保持和原版一样的功能,详细请查看原版相关功能
所有子对话框将以主对话框为同步,当使用ctrl高速跳对话和空格快速显示时亦是如此
由于显示了这么多对话框,估计此时显示选择项和显示输入项的功能不能正常进行

再附一段自己应用到游戏上的演示效果:
演示.gif

目前也只是初步完成,有什么bug或者什么改进的地方还请各位多多指教,谢谢!

评分

参与人数 1星屑 +200 赞 +1 收起 理由
guoxiaomi + 200 + 1 精品文章

查看全部评分

游戏设计爱好者
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部