查看: 1972|回复: 0

[已经过期] 文本扩展

[复制链接]
梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
发表于 2022-11-7 16:28:31 | 显示全部楼层 |阅读模式

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

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

×
下面这个draw_text必备扩展脚本,如何把显示表情动画的功能整合进去。会的大佬帮忙看下




  1. #===========================================================================
  2. #  *  draw_text必备扩展
  3. #===========================================================================
  4. =begin

  5.   !c[n]       #改用n号颜色 *注 颜色在color处自定
  6.   !s[n]       #改用n号大小
  7.   !n[name]    #改用名称为name的字体
  8.   !b0         #关闭粗体
  9.   !b1         #开启粗体
  10.   !i0         #关闭斜体
  11.   !i1         #开启斜体
  12.   
  13.   i[n]        #描绘id为n的物品的图标
  14.   s[n]        #描绘id为n的特技的图标
  15.   w[n]        #描绘id为n的武器的图标
  16.   a[n]        #描绘id为n的防具的图标
  17.   l[filename] #描绘文件名为filename的图标
  18.   
  19.   \\n         #手动换行
  20.   
  21.   其他功能——
  22.   *投影
  23.   *自动换行

  24. =end
  25. class Bitmap
  26.   def ti_draw_text(x, y, text)
  27.     #记录bitmap数据
  28.     name_copy = self.font.name
  29.     size_copy = self.font.size
  30.     bold_copy = self.font.bold
  31.     italic_copy = self.font.italic
  32.     color_copy = self.font.color.clone
  33.     #初始数据
  34.     text_copy = text
  35.     tx,ty = x,y
  36.     rect = Rect.new(0, 0, 32, 32)
  37.     #字体
  38.     text_copy.gsub!(/!c\[([0-9]+)\]/) { "\001[#{$1}]" }
  39.     text_copy.gsub!(/!s\[([0-9]+)\]/) { "\002[#{$1}]" }
  40.     text_copy.gsub!(/!n\[(.+)\]/) { "\003[#{$1}]" }
  41.     text_copy.gsub!(/!b0/) { "\004" }
  42.     text_copy.gsub!(/!b1/) { "\005" }
  43.     text_copy.gsub!(/!i0/) { "\006" }
  44.     text_copy.gsub!(/!i1/) { "\007" }
  45.     #图标
  46.     text_copy.gsub!(/i\[([0-9]+)\]/) { "\020[#{$1}]" }
  47.     text_copy.gsub!(/s\[([0-9]+)\]/) { "\021[#{$1}]" }
  48.     text_copy.gsub!(/w\[([0-9]+)\]/) { "\022[#{$1}]" }
  49.     text_copy.gsub!(/a\[([0-9]+)\]/) { "\023[#{$1}]" }
  50.     text_copy.gsub!(/l\[(.+)\]/) { "\025[#{$1}]" }
  51.     #其他
  52.     text_copy.gsub!(/v\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  53.     text_copy.gsub!(/\\n/) { "\030" }
  54.     #颜色
  55.     color = []
  56.     color[0] = Color.new(255, 255, 255, 255)#白
  57.     color[1] = Color.new(128, 128, 255, 255)#蓝√
  58.     color[2] = Color.new(250, 70, 70, 255)#(255, 0, 0, 255)#(255, 0, 80, 255)#红√
  59.     color[3] = Color.new(82, 226, 82, 255)#绿√
  60.     color[4] = Color.new(0, 255, 255, 255)#青√
  61.     color[5] = Color.new(255, 128, 255, 255)#粉红
  62.     color[6] = Color.new(240, 241, 87, 255)#黄√
  63.     color[7] = Color.new(192, 192, 192, 255)#灰
  64.     color[8] = Color.new(255, 195, 105, 255)#桔色
  65.     color[9] = Color.new(255, 0, 255, 255)#紫色√

  66.     while ((c = text_copy.slice!(/./m)) != nil)
  67.       #====================================
  68.       #设置字体
  69.       #====================================
  70.       #颜色
  71.       if c == "\001"
  72.         text_copy.sub!(/\[([0-9]+)\]/, "")
  73.         next if color[$1.to_i].nil?
  74.         self.font.color = color[$1.to_i]
  75.         next
  76.       end
  77.       #大小
  78.       if c == "\002"
  79.         text_copy.sub!(/\[([0-9]+)\]/, "")
  80.         self.font.size = $1.to_i
  81.         next
  82.       end
  83.       #名称
  84.       if c == "\003"
  85.         text_copy.sub!(/\[(.+)\]/, "")
  86.         self.font.name = $1 if Font.exist?($1)
  87.         next
  88.       end
  89.       #粗体关
  90.       if c == "\004"
  91.         self.font.bold = false
  92.         next
  93.       end
  94.       #粗体开
  95.       if c == "\005"
  96.         self.font.bold = true
  97.         next
  98.       end
  99.       #斜体关
  100.       if c == "\006"
  101.         self.font.italic = false
  102.         next
  103.       end
  104.       #斜体开
  105.       if c == "\007"
  106.         self.font.italic = true
  107.         next
  108.       end
  109.       #====================================
  110.       #描绘图标
  111.       #====================================
  112.       #物品
  113.       if c == "\020"
  114.         text_copy.sub!(/\[([0-9]+)\]/, "")
  115.         if !$data_items[$1.to_i].nil? and $data_items[$1.to_i].icon_name != ""
  116.           next if tx + 24 > self.width - 32
  117.           bitmap = RPG::Cache.icon($data_items[$1.to_i].icon_name)
  118.           self.blt(tx, ty, bitmap, rect)
  119.           tx += 24
  120.         end
  121.         next
  122.       end
  123.       #特技
  124.       if c == "\021"
  125.         text_copy.sub!(/\[([0-9]+)\]/, "")
  126.         if !$data_skills[$1.to_i].nil? and $data_skills[$1.to_i].icon_name != ""
  127.           next if tx + 24 > self.width - 32
  128.           bitmap = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
  129.           self.blt(tx, ty, bitmap, rect)
  130.           tx += 24
  131.         end
  132.         next
  133.       end
  134.       #武器
  135.       if c == "\022"
  136.         text_copy.sub!(/\[([0-9]+)\]/, "")
  137.         if !$data_weapons[$1.to_i].nil? and $data_weapons[$1.to_i].icon_name != ""
  138.           next if tx + 24 > self.width - 32
  139.           bitmap = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
  140.           self.blt(tx, ty, bitmap, rect)
  141.           tx += 24
  142.         end
  143.         next
  144.       end
  145.       #防具
  146.       if c == "\023"
  147.         text_copy.sub!(/\[([0-9]+)\]/, "")
  148.         if !$data_armors[$1.to_i].nil? and $data_armors[$1.to_i].icon_name != ""
  149.           next if tx + 24 > self.width - 32
  150.           bitmap = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
  151.           self.blt(tx, ty, bitmap, rect)
  152.           tx += 24
  153.         end
  154.         next
  155.       end
  156.       #自定
  157.       if c == "\025"
  158.         text_copy.sub!(/\[(.+)\]/, "")
  159.         if $1 != ""
  160.           next if tx + 24 > self.width - 32
  161.           bitmap = RPG::Cache.icon($1)
  162.           self.blt(tx, ty, bitmap, rect)
  163.           tx += 24
  164.         end
  165.         next
  166.       end
  167.       #====================================
  168.       #其他
  169.       #====================================
  170.       #换行
  171.       if c == "\030"
  172.         ty += self.font.size
  173.         next
  174.       end
  175.       cx = self.text_size(c).width + 1
  176.       #投影
  177.       #dl_color_copy = self.font.color.clone
  178.       #self.font.color.set(0, 0, 0)
  179.       #self.draw_text(tx+1, ty+1, cx, self.font.size, c)
  180.       #self.draw_text(tx-1, ty+1, cx, self.font.size, c)
  181.       #self.draw_text(tx+1, ty-1, cx, self.font.size, c)
  182.       #self.draw_text(tx-1, ty-1, cx, self.font.size, c)
  183.       #self.font.color = dl_color_copy
  184.       self.draw_text(tx, ty, cx, self.font.size, c)
  185.       tx += cx
  186.       #自动换行
  187.       if tx >= self.width
  188.         tx = 0 + 6
  189.         ty += self.font.size + 5
  190.       end
  191.     end
  192.     #恢复调整
  193.     self.font.name = name_copy
  194.     self.font.size = size_copy
  195.     self.font.bold = bold_copy
  196.     self.font.italic = italic_copy
  197.     self.font.color = color_copy
  198.   end
  199. end
  200.   
复制代码






整合表情动画


  1. #==============================================================================
  2. # ■ Window_Message
  3. #------------------------------------------------------------------------------
  4. #  显示文章的信息窗口。
  5. #==============================================================================

  6. class Window_Message < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化状态
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(236, 304, 563, 160)
  12.     self.contents = Bitmap.new(width - 32, height - 32)
  13.     self.visible = false
  14.     self.z = 9997
  15.     @fade_in = false
  16.     @fade_out = false
  17.     @contents_showing = false
  18.     @cursor_width = 0
  19.     # 更改窗口皮肤
  20.     self.windowskin = RPG::Cache.windowskin('对话皮肤/对话框')
  21.    
  22.     # 描绘字体样式
  23.     self.contents.font.name = (["simsun.ttf","黑体"])

  24. #@bq = []
  25. #for i in 0..63
  26. #@bq += [RPG::Cache.animation("表情#{i}", 0)]
  27. #end
  28. #for i in 74..99
  29. #@bq += [RPG::Cache.animation("表情#{i}", 0)]
  30. #end
  31.     self.active = false
  32.     self.index = -1
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 释放
  36.   #--------------------------------------------------------------------------
  37.   def dispose
  38.     terminate_message
  39.     $game_temp.message_window_showing = false
  40.    # @bq.clear
  41.     if @input_number_window != nil
  42.       @input_number_window.dispose
  43.     end  
  44.     super
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # ● 处理信息结束
  48.   #--------------------------------------------------------------------------
  49.   def terminate_message
  50.     self.active = false
  51.     self.pause = false
  52.     self.index = -1
  53.     self.contents.clear
  54.     # 清除显示中标志
  55.     @contents_showing = false
  56.     # 呼叫信息调用
  57.     if $game_temp.message_proc != nil
  58.       $game_temp.message_proc.call
  59.     end
  60.     # 清除文章、选择项、输入数值的相关变量
  61.     $game_temp.message_text = nil
  62.     $game_temp.message_proc = nil
  63.     $game_temp.choice_start = 99
  64.     $game_temp.choice_max = 0
  65.     $game_temp.choice_cancel_type = 0
  66.     $game_temp.choice_proc = nil
  67.     $game_temp.num_input_start = 99
  68.     $game_temp.num_input_variable_id = 0
  69.     $game_temp.num_input_digits_max = 0
  70.     # 开放金钱窗口
  71.     if @gold_window != nil
  72.       @gold_window.dispose
  73.       @gold_window = nil
  74.     end
  75.    
  76. #============================夏娜改===========================
  77.     if @ani_array != nil
  78.       for sp in @ani_array
  79.         sp.loop_animation(nil)
  80.         sp.bitmap.dispose
  81.         sp.dispose
  82.       end
  83.       @ani_array.clear
  84.       @ani_array = nil
  85.     end
  86.     if @w17v != nil
  87.       @w17v.dispose
  88.       @w17v = nil     
  89.     end
  90. #=============================================================
  91.   end
  92. #--------------------------------------------------------------------------
  93. # ● 刷新
  94. #--------------------------------------------------------------------------
  95.   def refresh
  96.     self.contents.clear
  97.     self.contents.font.color = normal_color
  98.     x = y = 0
  99.     @cursor_width = 0
  100.     # 到选择项的下一行字
  101.     if $game_temp.choice_start == 0
  102.       x = 0#8 # 选择项文字和光标的距离
  103.     end
  104.     # 有等待显示的文字的情况下
  105.     if $game_temp.message_text != nil
  106.       text = $game_temp.message_text
  107. #=====================6饭改,长文不换行显示=========================         
  108.       if (/\\_\n/.match(text)) != nil
  109.         $game_temp.choice_start -= 1
  110.         text.gsub!(/\\_\n/) { "" }
  111.       end
  112. #=====================6饭改,手动换行===============================
  113.       if (/\\n/.match(text)) != nil
  114.         $game_temp.choice_start += 1
  115.         text.gsub!(/\\n/) { "\n" }
  116.       end
  117. #===================================================================      
  118.       # 限制文字处理
  119.       begin
  120.         last_text = text.clone
  121.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  122.       end until text == last_text
  123.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  124.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  125.       end
  126.       # 为了方便、将 "\\\" 变换为 "\000"
  127.       text.gsub!(/\\\\/) { "\000" }
  128.       # "\\C" 变为 "\001" に、"\\G" 变为 "\002"
  129.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  130.       text.gsub!(/\\[Gg]/) { "\002" }
  131.          
  132. #===========================夏娜改,6饭再改===========================
  133.     #  text.gsub!(/\#\[([0-9]+)\]/) { "\003[#{$1}]" }
  134.        text.gsub!(/\#([0-9]+)/) { "\003#{$1}" }
  135. #=====================================================================      
  136.       # c 获取 1 个字 (如果不能取得文字就循环)
  137.       while ((c = text.slice!(/./m)) != nil)
  138.         # \\ 的情况下
  139.         if c == "\000"
  140.           # 还原为本来的文字
  141.           c = "\"
  142.         end
  143.         # \C[n] 的情况下
  144.         if c == "\001"
  145.           # 更改文字色
  146.          text.sub!(/\[([0-9]+)\]/, "")
  147.           color = $1.to_i
  148.           if color >= 0 and color <= 7
  149.             self.contents.font.color = text_color(color)
  150.           end
  151.           # 下面的文字
  152.           next
  153.         end
  154. #===========================夏娜改,6饭再改===========================
  155.         if c == "\003"
  156.         #  text.sub!(/\[([0-9]+)\]/, "")
  157.            text.sub!(/([0-9]+)/, "")   
  158.           @ani_array = [] if @ani_array.nil?
  159.           id = $1.to_i
  160.           id = 100 if $1.to_i == 0
  161.           @w17v = Viewport.new(self.x + x + 6 ,self.y + y * 32 ,100,100)
  162.           @w17v.z = 9999
  163.           w17 = RPG::Sprite.new(@w17v)
  164.           w17.bitmap = Bitmap.new(48,46)
  165.           w17.loop_animation($data_animations[id])
  166.           @ani_array.push w17
  167.           x += 32
  168.           # 下面的文字         
  169.           next
  170.         end
  171. #=====================================================================         
  172.         
  173.         # \G 的情况下
  174.         if c == "\002"
  175.           # 生成金钱窗口
  176.           if @gold_window == nil
  177.             @gold_window = Window_Gold.new
  178.             @gold_window.x = 560 - @gold_window.width
  179.             if $game_temp.in_battle
  180.               @gold_window.y = 192
  181.             else
  182.               @gold_window.y = self.y >= 128 ? 32 : 384
  183.             end
  184.             @gold_window.opacity = self.opacity
  185.             @gold_window.back_opacity = self.back_opacity
  186.           end
  187.           # 下面的文字
  188.           next
  189.         end
  190.         # 另起一行文字的情况下
  191.         if c == "\n"
  192.           # 刷新选择项及光标的高
  193.           if y >= $game_temp.choice_start
  194.             @cursor_width = [@cursor_width, x].max
  195.           end
  196.           # y 加 1
  197.           y += 1
  198.           x = 0
  199.           # 移动到选择项的下一行
  200.           if y >= $game_temp.choice_start
  201.             x = 0 #8 # 选择项文字和光标的距离
  202.           end
  203.           # 下面的文字
  204.           next
  205.         end
  206.         # 描绘文字
  207.         self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  208.         # x 为要描绘文字的加法运算
  209.         x += self.contents.text_size(c).width
  210.       end
  211.     end
  212.     # 选择项的情况
  213.     if $game_temp.choice_max > 0
  214.       @item_max = $game_temp.choice_max
  215.       self.active = true
  216.       self.index = 0
  217.     end
  218.     # 输入数值的情况
  219.     if $game_temp.num_input_variable_id > 0
  220.       digits_max = $game_temp.num_input_digits_max
  221.       number = $game_variables[$game_temp.num_input_variable_id]
  222.       @input_number_window = Window_InputNumber.new(digits_max)
  223.       @input_number_window.number = number
  224.       @input_number_window.x = self.x + 8
  225.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  226.     end
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # ● 设置窗口位置与不透明度
  230.   #--------------------------------------------------------------------------
  231.   def reset_window
  232.     if $game_temp.in_battle
  233.       self.y = 16
  234.     else
  235.       case $game_system.message_position
  236.       when 0  # 上
  237.         self.y = 18+64
  238.       when 1  # 中
  239.         self.y = 304
  240.       when 2  # 下
  241.         self.y = 592-58
  242.       end
  243.     end
  244.     if $game_system.message_frame == 0
  245.       self.opacity = 255
  246.     else
  247.       self.opacity = 0
  248.     end
  249.     self.back_opacity = 160
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # ● 刷新画面
  253.   #--------------------------------------------------------------------------
  254.   def update
  255.     super
  256.    
  257. #============================夏娜改===========================
  258.     if @ani_array != nil and (Graphics.frame_count % 4 == 0)
  259.       for sp in @ani_array
  260.         sp.update
  261.       end
  262.     end
  263. #=============================================================   
  264.     # 渐变的情况下
  265.     if @fade_in
  266.       self.contents_opacity += 24
  267.       if @input_number_window != nil
  268.         @input_number_window.contents_opacity += 24
  269.       end
  270.       if self.contents_opacity == 255
  271.         @fade_in = false
  272.       end
  273.       return
  274.     end
  275.     # 输入数值的情况下
  276.     if @input_number_window != nil
  277.       @input_number_window.update
  278.       # 确定
  279.       if Input.trigger?(Input::C)
  280.         $game_system.se_play($data_system.decision_se)
  281.         $game_variables[$game_temp.num_input_variable_id] =
  282.           @input_number_window.number
  283.         $game_map.need_refresh = true
  284.         # 释放输入数值窗口
  285.         @input_number_window.dispose
  286.         @input_number_window = nil
  287.         terminate_message
  288.       end
  289.       return
  290.     end
  291.     # 显示信息中的情况下
  292.     if @contents_showing
  293.       # 如果不是在显示选择项中就显示暂停标志
  294.       if $game_temp.choice_max == 0
  295.         self.pause = true
  296.       end
  297.       # 取消
  298.       if Input.trigger?(Input::B)
  299.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  300.           $game_system.se_play($data_system.cancel_se)
  301.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  302.           terminate_message
  303.         end
  304.       end
  305.       # 确定
  306.       if Input.trigger?(Input::C)
  307.         if $game_temp.choice_max > 0
  308.           $game_system.se_play($data_system.decision_se)
  309.           $game_temp.choice_proc.call(self.index)
  310.         end
  311.         terminate_message
  312.       end
  313.       return
  314.     end
  315.    
  316.     # 在渐变以外的状态下有等待显示的信息与选择项的场合
  317.     if @fade_out == false and $game_temp.message_text != nil
  318.       @contents_showing = true
  319.       $game_temp.message_window_showing = true
  320.       reset_window
  321.       refresh
  322.       Graphics.frame_reset
  323.       self.visible = true
  324.       self.contents_opacity = 0
  325.       if @input_number_window != nil
  326.         @input_number_window.contents_opacity = 0
  327.       end
  328.       @fade_in = true
  329.       return
  330.     end
  331.     # 没有可以显示的信息、但是窗口为可见的情况下
  332.     if self.visible
  333.       @fade_out = true
  334.       self.opacity -= 48
  335.       if self.opacity == 0
  336.         self.visible = false
  337.         @fade_out = false
  338.         $game_temp.message_window_showing = false
  339.       end
  340.       return
  341.     end
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● 刷新光标矩形
  345.   #--------------------------------------------------------------------------
  346.   def update_cursor_rect
  347.     if @index >= 0
  348.       n = $game_temp.choice_start + @index
  349. #     self.cursor_rect.set(8, n * 32, @cursor_width, 32) # 默认长度
  350.       self.cursor_rect.set(3, n * 32, 520, 32)
  351.     else
  352.       self.cursor_rect.empty
  353.     end
  354.   end
  355. end
复制代码

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

本版积分规则

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

在本版发帖返回顶部