查看: 2490|回复: 4

[已经解决] 请教多功能字幕滚动脚本的文字滚动速度如何更改

[复制链接]
梦石
0
星屑
456
在线时间
76 小时
注册时间
2020-2-23
回帖
17
发表于 2021-4-6 22:43:45 | 显示全部楼层 |阅读模式

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

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

×
论坛上搜到了一个多功能字幕滚动脚本,功能非常强大,只有一点瑕疵,就是字幕的滚动速度感觉有点快了,我又不知道如何更改,就希望网友帮忙看一下,或者也可以推荐一下别的脚本
  1. =begin
  2. 说明:

  3. 01 把字幕强化了,添加对话框的一些功能到里头去。
  4.    \f[字体]:更改字体
  5.    \c[颜色]:更改颜色,与默认对话框相同
  6.    \s[字体大小]:更改字体大小
  7.    \p[图片名称]:显示在picture文件夹下指定的图片
  8.    <b>字幕</b>:被包围的字将会变成粗体
  9.    <i>字幕</i>:被包围的字将会变成斜体
  10.    <left>:该行左边对齐
  11.    <center>:该行中间对齐
  12.    <right>:该行右边对齐

  13. 02 调用方法:(1) $scene = Scene_Credit.new
  14.              (2) $scene = Scene_Credit.new("文字")
  15.    (1) 为默认调用发,字幕会直接读取脚本里设定好的字幕
  16.    (2) 为更改字幕,字幕将变成设定的文字,支持\txt[TXT名称],将会读取
  17.        Credit文件夹底下的指定TXT,TXT格式参考范例。

  18. 03 其他玩转设置参考范例。

  19. =end
  20. module CREDIT

  21. # 字幕
  22. Subtitle=<<_end_
  23. 最普通的字幕显示

  24. 更改字幕的显示字体\\f[楷体]楷体\\f[微软雅黑]微软雅黑\\f[黑体]
  25. 更改\\c[1]字幕\\c[2]显示\\c[3]颜色\\c[0]
  26. \\s[16]更改\\s[48]字体的显示\\s[16]大小\\s[22]
  27. 图片显示:
  28. \\p[picture]
  29. <b>粗体字幕</b>
  30. <i>斜体字幕</i>
  31. <left>左边(上边)对齐
  32. <center>中间(中间)对齐
  33. <right>右边(下边)对齐
  34. _end_

  35. # 字幕移动方式 y 垂直移动,x 横着移动
  36. Subtitle_move = "y"

  37. # 允许按键推出
  38. AllowButtonExit = true

  39. # 边距
  40. MarginX = 20
  41. MarginY = 20

  42. # 背景
  43. Background = "" # 空着会调用背景颜色
  44. BackgroundRepeat = false # 背景循环 (背景移动时强行打开)
  45. BackgroundColor = Color.new(0,0,0) # 背景颜色
  46. BackgroundMoveX = 0 # 背景移动X值
  47. BackgroundMoveY = 0 # 背景移动Y值

  48. # 背景声音 放 "" 为没有声音
  49. BackgroundBGM = "017-Theme06"

  50. # 默认字体
  51. Font_name = "黑体" # 字体
  52. Font_size = 22 #大小
  53. Font_color = Color.new(255,255,255) # 颜色
  54. Font_bold = false # 是否粗体
  55. Font_italic = false # 是否斜体

  56. # 默认行高
  57. DefaultLineHeight = 32

  58. # 退出后回到的场景
  59. ExitScene = Scene_Map.new

  60. end

  61. class Scene_Credit
  62.   include CREDIT
  63.   def initialize(text = nil)
  64.     if text == nil
  65.       @text = Subtitle
  66.     else
  67.       text.gsub!(/\\[Tt][Xx][Tt]\[(\w+)\]/){"\001[#{$1}]"}
  68.       new_text = ""
  69.       while ((c = text.slice!(/./m)) != nil)
  70.         if c == "\001"
  71.           text.sub!(/\[(\w+)\]/,"")
  72.           name = "Credit/" + $1 + ".txt"
  73.           file = File.open(name)
  74.           a = file.readlines
  75.           for i in 1...a.size
  76.             new_text += a[i]
  77.           end
  78.           file.close
  79.         else
  80.           new_text += c
  81.         end
  82.       end
  83.       @text = new_text
  84.     end
  85.   end
  86.   def main
  87.     initialize_font_setting
  88.     if BackgroundRepeat or (BackgroundMoveX + BackgroundMoveY != 0)
  89.       @background = Plane.new
  90.     else
  91.       @background = Sprite.new
  92.     end
  93.     if Background != ""
  94.       @background.bitmap = RPG::Cache.picture(Background)
  95.     else
  96.       @background.bitmap = Bitmap.new(640,480)
  97.       @background.bitmap.fill_rect(0,0,640,480,BackgroundColor)
  98.     end
  99.     @subtitle = Sprite.new
  100.     process_credit(@text)
  101.     if BackgroundBGM != ""
  102.       Audio.bgm_play("Audio/BGM/#{BackgroundBGM}")
  103.     end
  104.     Graphics.transition
  105.     loop do
  106.       Graphics.update
  107.       Input.update
  108.       update
  109.       break if $scene != self
  110.     end
  111.     @subtitle.dispose
  112.     @background.dispose
  113.   end
  114.   def update
  115.     update_subtitle
  116.     if @background.is_a?(Plane)
  117.       @background.ox += BackgroundMoveX
  118.       @background.oy += BackgroundMoveY
  119.     end
  120.     if AllowButtonExit
  121.       if Input.trigger?(Input::B)
  122.         exit_scene
  123.       end
  124.     end
  125.   end
  126.   def update_subtitle
  127.     if Subtitle_move == "y"
  128.       @subtitle.y -= 1
  129.       exit_scene if @subtitle.y <= (-20 - @subtitle.bitmap.height)
  130.     else
  131.       @subtitle.x += 1
  132.       exit_scene if @subtitle.x >= (660)
  133.     end
  134.   end
  135.   def exit_scene
  136.     Audio.bgm_fade(800)
  137.     $scene = ExitScene
  138.   end
  139.   def initialize_font_setting
  140.     @align = 0
  141.     @font_size = Font_size
  142.     @font_name = Font_name
  143.     @font_color = Font_color
  144.     @font_bold = Font_bold
  145.     @font_italic = Font_italic
  146.   end
  147.   def process_credit(text)
  148.     text = text.split("\n")
  149.     if Subtitle_move == "y"
  150.       total_height = 0
  151.       for line in text
  152.         w,h = calc_line_rect(line)
  153.         total_height += h
  154.       end
  155.       initialize_font_setting
  156.       bitmap = Bitmap.new(640-2*MarginX,total_height)
  157.       y = 0
  158.       for line in text
  159.         w,h = calc_line_rect(line)
  160.         bitmap2 = create_line_bitmap(line,w,h)
  161.         rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  162.         x = @align == 0 ? 0 : @align == 1 ? (bitmap.width/2-bitmap2.width/2) : (bitmap.width-bitmap2.width)
  163.         bitmap.blt(x,y,bitmap2,rect)
  164.         y += h
  165.       end
  166.       @subtitle.bitmap = bitmap
  167.       @subtitle.x = MarginX
  168.       @subtitle.y = 481
  169.     else
  170.       total_width = 0
  171.       for line in text
  172.         w,h = calc_line_rect(line)
  173.         total_width += w
  174.       end
  175.       initialize_font_setting
  176.       bitmap = Bitmap.new(total_width,480-MarginY*2)
  177.       x = total_width
  178.       for line in text
  179.         w,h = calc_line_rect(line)
  180.         x -= w
  181.         bitmap2 = create_line_bitmap(line,w,h)
  182.         rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  183.         y = @align == 0 ? 0 : @align == 1 ? (bitmap.height/2-bitmap2.height/2) : (bitmap.height-bitmap2.height)
  184.         bitmap.blt(x,y,bitmap2,rect)
  185.       end
  186.       @subtitle.bitmap = bitmap
  187.       @subtitle.x = -total_width
  188.       @subtitle.y = MarginY
  189.     end
  190.   end
  191.   def calc_line_rect(line_text)
  192.     temp_bitmap = Bitmap.new(32,32)
  193.     temp_bitmap.font.name = @font_name
  194.     temp_bitmap.font.size = @font_size
  195.     temp_bitmap.font.color = @font_color
  196.     temp_bitmap.font.bold = @font_bold
  197.     temp_bitmap.font.italic = @font_italic
  198.     line = line_text.dup
  199.     height = 0
  200.     width = 0
  201.     line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){""}
  202.     line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){""}
  203.     line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){""}
  204.     line.gsub!(/\\\\/){"\000"}
  205.     line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
  206.     line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
  207.     line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
  208.     line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
  209.     line.gsub!(/\<[Bb]\>/){"\201"}
  210.     line.gsub!(/\<\/[Bb]\>/){"\202"}
  211.     line.gsub!(/\<[Ii]\>/){"\203"}
  212.     line.gsub!(/\<\/[Ii]\>/){"\204"}
  213.     while ((c = line.slice!(/./m)) != nil)
  214.       if c == "\000"
  215.         c = "\"
  216.       elsif c == "\001"
  217.         line.sub!(/\[(\w+)\]/,"")
  218.         font_name = $1 == nil ? Font_name : $1
  219.         temp_bitmap.font.name = @font_name = font_name
  220.       elsif c == "\003"
  221.         line.sub!(/\[(\d+)\]/,"")
  222.         font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
  223.         temp_bitmap.font.size = @font_size = font_size
  224.       elsif c == "\004"
  225.         line.sub!(/\[(\w+)\]/,"")
  226.         bitmap_name = $1 == nil ? "" : $1
  227.         if bitmap_name != ""
  228.           _temp_bitmap = RPG::Cache.picture(bitmap_name)
  229.           if Subtitle_move == "y"
  230.             width += _temp_bitmap.width
  231.             height = _temp_bitmap.height > height ? _temp_bitmap.height : height
  232.           else
  233.             width = _temp_bitmap.width > width ? _temp_bitmap.width : width
  234.             height += _temp_bitmap.height
  235.           end
  236.           _temp_bitmap.clear
  237.           _temp_bitmap.dispose
  238.           _temp_bitmap = nil
  239.         end
  240.       elsif c == "\201"
  241.         temp_bitmap.font.bold = @font_bold = true
  242.       elsif c == "\202"
  243.         temp_bitmap.font.bold = @font_bold = false
  244.       elsif c == "\203"
  245.         temp_bitmap.font.italic = @font_italic = true
  246.       elsif c == "\204"
  247.         temp_bitmap.font.italic = @font_italic = false
  248.       else
  249.         if Subtitle_move == "y"
  250.           width += temp_bitmap.text_size(c).width
  251.           height = temp_bitmap.text_size(c).height > height ?\
  252.                    temp_bitmap.text_size(c).height : height
  253.         else
  254.           width = temp_bitmap.text_size(c).width > width ?\
  255.                   temp_bitmap.text_size(c).width : width
  256.           height += temp_bitmap.text_size(c).height
  257.         end
  258.       end
  259.     end
  260.     if Subtitle_move == "y"
  261.       height = DefaultLineHeight if height < DefaultLineHeight
  262.       width = 32 if width == 0
  263.     else
  264.       width = DefaultLineHeight if width < DefaultLineHeight
  265.       height = 32 if height == 0
  266.     end
  267.     temp_bitmap.clear
  268.     temp_bitmap.dispose
  269.     temp_bitamp = nil
  270.     return width,height
  271.   end
  272.   def create_line_bitmap(line,width,height)
  273.     temp_bitmap = Bitmap.new(width,height)
  274.     temp_bitmap.font.name = @font_name
  275.     temp_bitmap.font.size = @font_size
  276.     temp_bitmap.font.color = @font_color
  277.     temp_bitmap.font.bold = @font_bold
  278.     temp_bitmap.font.italic = @font_italic
  279.     x = 0
  280.     line = line.dup
  281.     line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){"\101"}
  282.     line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){"\102"}
  283.     line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){"\100"}
  284.     line.gsub!(/\\\\/){"\000"}
  285.     line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
  286.     line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
  287.     line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
  288.     line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
  289.     line.gsub!(/\<[Bb]\>/){"\201"}
  290.     line.gsub!(/\<\/[Bb]\>/){"\202"}
  291.     line.gsub!(/\<[Ii]\>/){"\203"}
  292.     line.gsub!(/\<\/[Ii]\>/){"\204"}
  293.     while ((c = line.slice!(/./m)) != nil)
  294.       if c == "\100"
  295.         @align = 0
  296.       elsif c == "\101"
  297.         @align = 1
  298.       elsif c == "\102"
  299.         @align = 2
  300.       elsif c == "\000"
  301.         c = "\"
  302.       elsif c == "\001"
  303.         line.sub!(/\[(\w+)\]/,"")
  304.         font_name = $1 == nil ? Font_name : $1
  305.         temp_bitmap.font.name = @font_name = font_name
  306.       elsif c == "\002"
  307.         line.sub!(/\[(\d+)\]/,"")
  308.         font_color = $1 == nil ? 0 : $1.to_i
  309.         case font_color
  310.         when 1
  311.           temp_bitmap.font.color = @font_color = Color.new(128,128,255)
  312.         when 2
  313.           temp_bitmap.font.color = @font_color = Color.new(255,128,128)
  314.         when 3
  315.           temp_bitmap.font.color = @font_color = Color.new(128,255,128)
  316.         when 4
  317.           temp_bitmap.font.color = @font_color = Color.new(128,255,255)
  318.         when 5
  319.           temp_bitmap.font.color = @font_color = Color.new(255,128,255)
  320.         when 6
  321.           temp_bitmap.font.color = @font_color = Color.new(255,255,128)
  322.         when 7
  323.           temp_bitmap.font.color = @font_color = Color.new(192,192,192)
  324.         else
  325.           temp_bitmap.font.color = @font_color = Color.new(255,255,255)
  326.         end
  327.       elsif c == "\003"
  328.         line.sub!(/\[(\d+)\]/,"")
  329.         font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
  330.         temp_bitmap.font.size = @font_size = font_size
  331.       elsif c == "\004"
  332.         line.sub!(/\[(\w+)\]/,"")
  333.         bitmap_name = $1 == nil ? "" : $1
  334.         if bitmap_name != ""
  335.           _temp_bitmap = RPG::Cache.picture(bitmap_name)
  336.           rect = Rect.new(0,0,_temp_bitmap.width,_temp_bitmap.height)
  337.           if Subtitle_move == "y"
  338.             temp_bitmap.blt(x,height/2-_temp_bitmap.height/2,_temp_bitmap,rect)
  339.           else
  340.             temp_bitmap.blt(width/2-_temp_bitmap.width/2,x,_temp_bitmap,rect)
  341.           end
  342.           _temp_bitmap.clear
  343.           _temp_bitmap.dispose
  344.           _temp_bitmap = nil
  345.         end
  346.       elsif c == "\201"
  347.         temp_bitmap.font.bold = @font_bold = true
  348.       elsif c == "\202"
  349.         temp_bitmap.font.bold = @font_bold = false
  350.       elsif c == "\203"
  351.         temp_bitmap.font.italic = @font_italic = true
  352.       elsif c == "\204"
  353.         temp_bitmap.font.italic = @font_italic = false
  354.       else
  355.         if Subtitle_move == "y"
  356.           temp_bitmap.draw_text(x,0,temp_bitmap.text_size(c).width,height,c)
  357.           x += temp_bitmap.text_size(c).width
  358.         else
  359.           temp_bitmap.draw_text(0,x,width,temp_bitmap.text_size(c).height,c,1)
  360.           x += temp_bitmap.text_size(c).height
  361.         end
  362.       end
  363.     end
  364.     return temp_bitmap
  365.   end
  366. end
复制代码
梦石
0
星屑
8003
在线时间
1184 小时
注册时间
2007-7-29
回帖
2014
发表于 2021-4-7 00:02:13 | 显示全部楼层
替换掉原本的 update_subtitle
  1.   def update_subtitle
  2.     @count = 0 if @count == nil
  3.     @count = (@count + 1) % 2
  4.     if @count == 0
  5.       if Subtitle_move == "y"
  6.         @subtitle.y -= 1
  7.         exit_scene if @subtitle.y <= (-20 - @subtitle.bitmap.height)
  8.       else
  9.         @subtitle.x += 1
  10.         exit_scene if @subtitle.x >= (660)
  11.       end
  12.     end
  13.   end
复制代码
  1. @count = (@count + 1) % 2
复制代码

以上脚本的2是移动延迟,越大越慢,举例:
  1. @count = (@count + 1) % 10
复制代码

自行调整。

评分

参与人数 1星屑 +100 赞 +1 收起 理由
RyanBern + 100 + 1 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
456
在线时间
76 小时
注册时间
2020-2-23
回帖
17
 楼主| 发表于 2021-4-7 00:24:08 | 显示全部楼层
enghao_lim 发表于 2021-4-7 00:02
替换掉原本的 update_subtitle

大哥,多谢你啊,不过有一个问题,就是用了这个之后,结束字幕的时候会报错。
脚本‘多功能字幕滚动”的210行发生NameError。
undefined local variable or method exit scene'for
#<Scene_Credit:0x11814ed0>

请问这个是因为什么啊
回复

使用道具 举报

梦石
0
星屑
8003
在线时间
1184 小时
注册时间
2007-7-29
回帖
2014
发表于 2021-4-7 00:27:01 | 显示全部楼层
本帖最后由 enghao_lim 于 2021-4-7 00:29 编辑
3103924369 发表于 2021-4-7 00:24
大哥,多谢你啊,不过有一个问题,就是用了这个之后,结束字幕的时候会报错。
脚本‘多功能字幕滚动”的2 ...


大哥,你不会不小心连以下都覆盖了吧?
  1.   def exit_scene
  2.     Audio.bgm_fade(800)
  3.     $scene = ExitScene
  4.   end
复制代码


算了,我放出完整脚本好了:
点击展开/收起
  1. =begin
  2. 说明:

  3. 01 把字幕强化了,添加对话框的一些功能到里头去。
  4.    \f[字体]:更改字体
  5.    \c[颜色]:更改颜色,与默认对话框相同
  6.    \s[字体大小]:更改字体大小
  7.    \p[图片名称]:显示在picture文件夹下指定的图片
  8.    <b>字幕</b>:被包围的字将会变成粗体
  9.    <i>字幕</i>:被包围的字将会变成斜体
  10.    <left>:该行左边对齐
  11.    <center>:该行中间对齐
  12.    <right>:该行右边对齐

  13. 02 调用方法:(1) $scene = Scene_Credit.new
  14.              (2) $scene = Scene_Credit.new("文字")
  15.    (1) 为默认调用发,字幕会直接读取脚本里设定好的字幕
  16.    (2) 为更改字幕,字幕将变成设定的文字,支持\txt[TXT名称],将会读取
  17.        Credit文件夹底下的指定TXT,TXT格式参考范例。

  18. 03 其他玩转设置参考范例。

  19. =end
  20. module CREDIT

  21. # 字幕
  22. Subtitle=<<_end_
  23. 最普通的字幕显示

  24. 更改字幕的显示字体\\f[楷体]楷体\\f[微软雅黑]微软雅黑\\f[黑体]
  25. 更改\\c[1]字幕\\c[2]显示\\c[3]颜色\\c[0]
  26. \\s[16]更改\\s[48]字体的显示\\s[16]大小\\s[22]
  27. 图片显示:
  28. \\p[Desert]
  29. <b>粗体字幕</b>
  30. <i>斜体字幕</i>
  31. <left>左边(上边)对齐
  32. <center>中间(中间)对齐
  33. <right>右边(下边)对齐
  34. _end_

  35. # 字幕移动方式 y 垂直移动,x 横着移动
  36. Subtitle_move = "y"

  37. # 允许按键推出
  38. AllowButtonExit = true

  39. # 边距
  40. MarginX = 20
  41. MarginY = 20

  42. # 背景
  43. Background = "" # 空着会调用背景颜色
  44. BackgroundRepeat = false # 背景循环 (背景移动时强行打开)
  45. BackgroundColor = Color.new(0,0,0) # 背景颜色
  46. BackgroundMoveX = 0 # 背景移动X值
  47. BackgroundMoveY = 0 # 背景移动Y值

  48. # 背景声音 放 "" 为没有声音
  49. BackgroundBGM = "017-Theme06"

  50. # 默认字体
  51. Font_name = "黑体" # 字体
  52. Font_size = 22 #大小
  53. Font_color = Color.new(255,255,255) # 颜色
  54. Font_bold = false # 是否粗体
  55. Font_italic = false # 是否斜体

  56. # 默认行高
  57. DefaultLineHeight = 32

  58. # 退出后回到的场景
  59. ExitScene = Scene_Map.new

  60. end

  61. class Scene_Credit
  62.   include CREDIT
  63.   def initialize(text = nil)
  64.     if text == nil
  65.       @text = Subtitle
  66.     else
  67.       text.gsub!(/\\[Tt][Xx][Tt]\[(\w+)\]/){"\001[#{$1}]"}
  68.       new_text = ""
  69.       while ((c = text.slice!(/./m)) != nil)
  70.         if c == "\001"
  71.           text.sub!(/\[(\w+)\]/,"")
  72.           name = "Credit/" + $1 + ".txt"
  73.           file = File.open(name)
  74.           a = file.readlines
  75.           for i in 1...a.size
  76.             new_text += a[i]
  77.           end
  78.           file.close
  79.         else
  80.           new_text += c
  81.         end
  82.       end
  83.       @text = new_text
  84.     end
  85.   end
  86.   def main
  87.     initialize_font_setting
  88.     if BackgroundRepeat or (BackgroundMoveX + BackgroundMoveY != 0)
  89.       @background = Plane.new
  90.     else
  91.       @background = Sprite.new
  92.     end
  93.     if Background != ""
  94.       @background.bitmap = RPG::Cache.picture(Background)
  95.     else
  96.       @background.bitmap = Bitmap.new(640,480)
  97.       @background.bitmap.fill_rect(0,0,640,480,BackgroundColor)
  98.     end
  99.     @subtitle = Sprite.new
  100.     process_credit(@text)
  101.     if BackgroundBGM != ""
  102.       Audio.bgm_play("Audio/BGM/#{BackgroundBGM}")
  103.     end
  104.     Graphics.transition
  105.     loop do
  106.       Graphics.update
  107.       Input.update
  108.       update
  109.       break if $scene != self
  110.     end
  111.     @subtitle.dispose
  112.     @background.dispose
  113.   end
  114.   def update
  115.     update_subtitle
  116.     if @background.is_a?(Plane)
  117.       @background.ox += BackgroundMoveX
  118.       @background.oy += BackgroundMoveY
  119.     end
  120.     if AllowButtonExit
  121.       if Input.trigger?(Input::B)
  122.         exit_scene
  123.       end
  124.     end
  125.   end
  126.   def update_subtitle
  127.     @count = 0 if @count == nil
  128.     @count = (@count + 1) % 2
  129.     if @count == 0
  130.       if Subtitle_move == "y"
  131.         @subtitle.y -= 1
  132.         exit_scene if @subtitle.y <= (-20 - @subtitle.bitmap.height)
  133.       else
  134.         @subtitle.x += 1
  135.         exit_scene if @subtitle.x >= (660)
  136.       end
  137.     end
  138.   end
  139.   def exit_scene
  140.     Audio.bgm_fade(800)
  141.     $scene = ExitScene
  142.   end
  143.   def initialize_font_setting
  144.     @align = 0
  145.     @font_size = Font_size
  146.     @font_name = Font_name
  147.     @font_color = Font_color
  148.     @font_bold = Font_bold
  149.     @font_italic = Font_italic
  150.   end
  151.   def process_credit(text)
  152.     text = text.split("\n")
  153.     if Subtitle_move == "y"
  154.       total_height = 0
  155.       for line in text
  156.         w,h = calc_line_rect(line)
  157.         total_height += h
  158.       end
  159.       initialize_font_setting
  160.       bitmap = Bitmap.new(640-2*MarginX,total_height)
  161.       y = 0
  162.       for line in text
  163.         w,h = calc_line_rect(line)
  164.         bitmap2 = create_line_bitmap(line,w,h)
  165.         rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  166.         x = @align == 0 ? 0 : @align == 1 ? (bitmap.width/2-bitmap2.width/2) : (bitmap.width-bitmap2.width)
  167.         bitmap.blt(x,y,bitmap2,rect)
  168.         y += h
  169.       end
  170.       @subtitle.bitmap = bitmap
  171.       @subtitle.x = MarginX
  172.       @subtitle.y = 481
  173.     else
  174.       total_width = 0
  175.       for line in text
  176.         w,h = calc_line_rect(line)
  177.         total_width += w
  178.       end
  179.       initialize_font_setting
  180.       bitmap = Bitmap.new(total_width,480-MarginY*2)
  181.       x = total_width
  182.       for line in text
  183.         w,h = calc_line_rect(line)
  184.         x -= w
  185.         bitmap2 = create_line_bitmap(line,w,h)
  186.         rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  187.         y = @align == 0 ? 0 : @align == 1 ? (bitmap.height/2-bitmap2.height/2) : (bitmap.height-bitmap2.height)
  188.         bitmap.blt(x,y,bitmap2,rect)
  189.       end
  190.       @subtitle.bitmap = bitmap
  191.       @subtitle.x = -total_width
  192.       @subtitle.y = MarginY
  193.     end
  194.   end
  195.   def calc_line_rect(line_text)
  196.     temp_bitmap = Bitmap.new(32,32)
  197.     temp_bitmap.font.name = @font_name
  198.     temp_bitmap.font.size = @font_size
  199.     temp_bitmap.font.color = @font_color
  200.     temp_bitmap.font.bold = @font_bold
  201.     temp_bitmap.font.italic = @font_italic
  202.     line = line_text.dup
  203.     height = 0
  204.     width = 0
  205.     line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){""}
  206.     line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){""}
  207.     line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){""}
  208.     line.gsub!(/\\\\/){"\000"}
  209.     line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
  210.     line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
  211.     line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
  212.     line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
  213.     line.gsub!(/\<[Bb]\>/){"\201"}
  214.     line.gsub!(/\<\/[Bb]\>/){"\202"}
  215.     line.gsub!(/\<[Ii]\>/){"\203"}
  216.     line.gsub!(/\<\/[Ii]\>/){"\204"}
  217.     while ((c = line.slice!(/./m)) != nil)
  218.       if c == "\000"
  219.         c = "\"
  220.       elsif c == "\001"
  221.         line.sub!(/\[(\w+)\]/,"")
  222.         font_name = $1 == nil ? Font_name : $1
  223.         temp_bitmap.font.name = @font_name = font_name
  224.       elsif c == "\003"
  225.         line.sub!(/\[(\d+)\]/,"")
  226.         font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
  227.         temp_bitmap.font.size = @font_size = font_size
  228.       elsif c == "\004"
  229.         line.sub!(/\[(\w+)\]/,"")
  230.         bitmap_name = $1 == nil ? "" : $1
  231.         if bitmap_name != ""
  232.           _temp_bitmap = RPG::Cache.picture(bitmap_name)
  233.           if Subtitle_move == "y"
  234.             width += _temp_bitmap.width
  235.             height = _temp_bitmap.height > height ? _temp_bitmap.height : height
  236.           else
  237.             width = _temp_bitmap.width > width ? _temp_bitmap.width : width
  238.             height += _temp_bitmap.height
  239.           end
  240.           _temp_bitmap.clear
  241.           _temp_bitmap.dispose
  242.           _temp_bitmap = nil
  243.         end
  244.       elsif c == "\201"
  245.         temp_bitmap.font.bold = @font_bold = true
  246.       elsif c == "\202"
  247.         temp_bitmap.font.bold = @font_bold = false
  248.       elsif c == "\203"
  249.         temp_bitmap.font.italic = @font_italic = true
  250.       elsif c == "\204"
  251.         temp_bitmap.font.italic = @font_italic = false
  252.       else
  253.         if Subtitle_move == "y"
  254.           width += temp_bitmap.text_size(c).width
  255.           height = temp_bitmap.text_size(c).height > height ?\
  256.                    temp_bitmap.text_size(c).height : height
  257.         else
  258.           width = temp_bitmap.text_size(c).width > width ?\
  259.                   temp_bitmap.text_size(c).width : width
  260.           height += temp_bitmap.text_size(c).height
  261.         end
  262.       end
  263.     end
  264.     if Subtitle_move == "y"
  265.       height = DefaultLineHeight if height < DefaultLineHeight
  266.       width = 32 if width == 0
  267.     else
  268.       width = DefaultLineHeight if width < DefaultLineHeight
  269.       height = 32 if height == 0
  270.     end
  271.     temp_bitmap.clear
  272.     temp_bitmap.dispose
  273.     temp_bitamp = nil
  274.     return width,height
  275.   end
  276.   def create_line_bitmap(line,width,height)
  277.     temp_bitmap = Bitmap.new(width,height)
  278.     temp_bitmap.font.name = @font_name
  279.     temp_bitmap.font.size = @font_size
  280.     temp_bitmap.font.color = @font_color
  281.     temp_bitmap.font.bold = @font_bold
  282.     temp_bitmap.font.italic = @font_italic
  283.     x = 0
  284.     line = line.dup
  285.     line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){"\101"}
  286.     line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){"\102"}
  287.     line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){"\100"}
  288.     line.gsub!(/\\\\/){"\000"}
  289.     line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
  290.     line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
  291.     line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
  292.     line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
  293.     line.gsub!(/\<[Bb]\>/){"\201"}
  294.     line.gsub!(/\<\/[Bb]\>/){"\202"}
  295.     line.gsub!(/\<[Ii]\>/){"\203"}
  296.     line.gsub!(/\<\/[Ii]\>/){"\204"}
  297.     while ((c = line.slice!(/./m)) != nil)
  298.       if c == "\100"
  299.         @align = 0
  300.       elsif c == "\101"
  301.         @align = 1
  302.       elsif c == "\102"
  303.         @align = 2
  304.       elsif c == "\000"
  305.         c = "\"
  306.       elsif c == "\001"
  307.         line.sub!(/\[(\w+)\]/,"")
  308.         font_name = $1 == nil ? Font_name : $1
  309.         temp_bitmap.font.name = @font_name = font_name
  310.       elsif c == "\002"
  311.         line.sub!(/\[(\d+)\]/,"")
  312.         font_color = $1 == nil ? 0 : $1.to_i
  313.         case font_color
  314.         when 1
  315.           temp_bitmap.font.color = @font_color = Color.new(128,128,255)
  316.         when 2
  317.           temp_bitmap.font.color = @font_color = Color.new(255,128,128)
  318.         when 3
  319.           temp_bitmap.font.color = @font_color = Color.new(128,255,128)
  320.         when 4
  321.           temp_bitmap.font.color = @font_color = Color.new(128,255,255)
  322.         when 5
  323.           temp_bitmap.font.color = @font_color = Color.new(255,128,255)
  324.         when 6
  325.           temp_bitmap.font.color = @font_color = Color.new(255,255,128)
  326.         when 7
  327.           temp_bitmap.font.color = @font_color = Color.new(192,192,192)
  328.         else
  329.           temp_bitmap.font.color = @font_color = Color.new(255,255,255)
  330.         end
  331.       elsif c == "\003"
  332.         line.sub!(/\[(\d+)\]/,"")
  333.         font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
  334.         temp_bitmap.font.size = @font_size = font_size
  335.       elsif c == "\004"
  336.         line.sub!(/\[(\w+)\]/,"")
  337.         bitmap_name = $1 == nil ? "" : $1
  338.         if bitmap_name != ""
  339.           _temp_bitmap = RPG::Cache.picture(bitmap_name)
  340.           rect = Rect.new(0,0,_temp_bitmap.width,_temp_bitmap.height)
  341.           if Subtitle_move == "y"
  342.             temp_bitmap.blt(x,height/2-_temp_bitmap.height/2,_temp_bitmap,rect)
  343.           else
  344.             temp_bitmap.blt(width/2-_temp_bitmap.width/2,x,_temp_bitmap,rect)
  345.           end
  346.           _temp_bitmap.clear
  347.           _temp_bitmap.dispose
  348.           _temp_bitmap = nil
  349.         end
  350.       elsif c == "\201"
  351.         temp_bitmap.font.bold = @font_bold = true
  352.       elsif c == "\202"
  353.         temp_bitmap.font.bold = @font_bold = false
  354.       elsif c == "\203"
  355.         temp_bitmap.font.italic = @font_italic = true
  356.       elsif c == "\204"
  357.         temp_bitmap.font.italic = @font_italic = false
  358.       else
  359.         if Subtitle_move == "y"
  360.           temp_bitmap.draw_text(x,0,temp_bitmap.text_size(c).width,height,c)
  361.           x += temp_bitmap.text_size(c).width
  362.         else
  363.           temp_bitmap.draw_text(0,x,width,temp_bitmap.text_size(c).height,c,1)
  364.           x += temp_bitmap.text_size(c).height
  365.         end
  366.       end
  367.     end
  368.     return temp_bitmap
  369.   end
  370. end
复制代码
回复

使用道具 举报

梦石
0
星屑
456
在线时间
76 小时
注册时间
2020-2-23
回帖
17
 楼主| 发表于 2021-4-7 08:22:36 | 显示全部楼层
enghao_lim 发表于 2021-4-7 00:27
大哥,你不会不小心连以下都覆盖了吧?

对,我删除过头了,谢谢你了,大哥
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部