设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1360|回复: 0
打印 上一主题 下一主题

[已经过期] 文本扩展

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3191
在线时间
1864 小时
注册时间
2010-6-19
帖子
1205
跳转到指定楼层
1
发表于 2022-11-7 16:28:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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




RUBY 代码复制
  1. #===========================================================================
  2. #  *  draw_text必备扩展
  3. #===========================================================================
  4. =begin
  5.  
  6.   !c[n]       #改用n号颜色 *注 颜色在color处自定
  7.   !s[n]       #改用n号大小
  8.   !n[name]    #改用名称为name的字体
  9.   !b0         #关闭粗体
  10.   !b1         #开启粗体
  11.   !i0         #关闭斜体
  12.   !i1         #开启斜体
  13.  
  14.   i[n]        #描绘id为n的物品的图标
  15.   s[n]        #描绘id为n的特技的图标
  16.   w[n]        #描绘id为n的武器的图标
  17.   a[n]        #描绘id为n的防具的图标
  18.   l[filename] #描绘文件名为filename的图标
  19.  
  20.   \\n         #手动换行
  21.  
  22.   其他功能——
  23.   *投影
  24.   *自动换行
  25.  
  26. =end
  27. class Bitmap
  28.   def ti_draw_text(x, y, text)
  29.     #记录bitmap数据
  30.     name_copy = self.font.name
  31.     size_copy = self.font.size
  32.     bold_copy = self.font.bold
  33.     italic_copy = self.font.italic
  34.     color_copy = self.font.color.clone
  35.     #初始数据
  36.     text_copy = text
  37.     tx,ty = x,y
  38.     rect = Rect.new(0, 0, 32, 32)
  39.     #字体
  40.     text_copy.gsub!(/!c\[([0-9]+)\]/) { "\001[#{$1}]" }
  41.     text_copy.gsub!(/!s\[([0-9]+)\]/) { "\002[#{$1}]" }
  42.     text_copy.gsub!(/!n\[(.+)\]/) { "\003[#{$1}]" }
  43.     text_copy.gsub!(/!b0/) { "\004" }
  44.     text_copy.gsub!(/!b1/) { "\005" }
  45.     text_copy.gsub!(/!i0/) { "\006" }
  46.     text_copy.gsub!(/!i1/) { "\007" }
  47.     #图标
  48.     text_copy.gsub!(/i\[([0-9]+)\]/) { "\020[#{$1}]" }
  49.     text_copy.gsub!(/s\[([0-9]+)\]/) { "\021[#{$1}]" }
  50.     text_copy.gsub!(/w\[([0-9]+)\]/) { "\022[#{$1}]" }
  51.     text_copy.gsub!(/a\[([0-9]+)\]/) { "\023[#{$1}]" }
  52.     text_copy.gsub!(/l\[(.+)\]/) { "\025[#{$1}]" }
  53.     #其他
  54.     text_copy.gsub!(/v\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  55.     text_copy.gsub!(/\\n/) { "\030" }
  56.     #颜色
  57.     color = []
  58.     color[0] = Color.new(255, 255, 255, 255)#白
  59.     color[1] = Color.new(128, 128, 255, 255)#蓝√
  60.     color[2] = Color.new(250, 70, 70, 255)#(255, 0, 0, 255)#(255, 0, 80, 255)#红√
  61.     color[3] = Color.new(82, 226, 82, 255)#绿√
  62.     color[4] = Color.new(0, 255, 255, 255)#青√
  63.     color[5] = Color.new(255, 128, 255, 255)#粉红
  64.     color[6] = Color.new(240, 241, 87, 255)#黄√
  65.     color[7] = Color.new(192, 192, 192, 255)#灰
  66.     color[8] = Color.new(255, 195, 105, 255)#桔色
  67.     color[9] = Color.new(255, 0, 255, 255)#紫色√
  68.  
  69.     while ((c = text_copy.slice!(/./m)) != nil)
  70.       #====================================
  71.       #设置字体
  72.       #====================================
  73.       #颜色
  74.       if c == "\001"
  75.         text_copy.sub!(/\[([0-9]+)\]/, "")
  76.         next if color[$1.to_i].nil?
  77.         self.font.color = color[$1.to_i]
  78.         next
  79.       end
  80.       #大小
  81.       if c == "\002"
  82.         text_copy.sub!(/\[([0-9]+)\]/, "")
  83.         self.font.size = $1.to_i
  84.         next
  85.       end
  86.       #名称
  87.       if c == "\003"
  88.         text_copy.sub!(/\[(.+)\]/, "")
  89.         self.font.name = $1 if Font.exist?($1)
  90.         next
  91.       end
  92.       #粗体关
  93.       if c == "\004"
  94.         self.font.bold = false
  95.         next
  96.       end
  97.       #粗体开
  98.       if c == "\005"
  99.         self.font.bold = true
  100.         next
  101.       end
  102.       #斜体关
  103.       if c == "\006"
  104.         self.font.italic = false
  105.         next
  106.       end
  107.       #斜体开
  108.       if c == "\007"
  109.         self.font.italic = true
  110.         next
  111.       end
  112.       #====================================
  113.       #描绘图标
  114.       #====================================
  115.       #物品
  116.       if c == "\020"
  117.         text_copy.sub!(/\[([0-9]+)\]/, "")
  118.         if !$data_items[$1.to_i].nil? and $data_items[$1.to_i].icon_name != ""
  119.           next if tx + 24 > self.width - 32
  120.           bitmap = RPG::Cache.icon($data_items[$1.to_i].icon_name)
  121.           self.blt(tx, ty, bitmap, rect)
  122.           tx += 24
  123.         end
  124.         next
  125.       end
  126.       #特技
  127.       if c == "\021"
  128.         text_copy.sub!(/\[([0-9]+)\]/, "")
  129.         if !$data_skills[$1.to_i].nil? and $data_skills[$1.to_i].icon_name != ""
  130.           next if tx + 24 > self.width - 32
  131.           bitmap = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
  132.           self.blt(tx, ty, bitmap, rect)
  133.           tx += 24
  134.         end
  135.         next
  136.       end
  137.       #武器
  138.       if c == "\022"
  139.         text_copy.sub!(/\[([0-9]+)\]/, "")
  140.         if !$data_weapons[$1.to_i].nil? and $data_weapons[$1.to_i].icon_name != ""
  141.           next if tx + 24 > self.width - 32
  142.           bitmap = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
  143.           self.blt(tx, ty, bitmap, rect)
  144.           tx += 24
  145.         end
  146.         next
  147.       end
  148.       #防具
  149.       if c == "\023"
  150.         text_copy.sub!(/\[([0-9]+)\]/, "")
  151.         if !$data_armors[$1.to_i].nil? and $data_armors[$1.to_i].icon_name != ""
  152.           next if tx + 24 > self.width - 32
  153.           bitmap = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
  154.           self.blt(tx, ty, bitmap, rect)
  155.           tx += 24
  156.         end
  157.         next
  158.       end
  159.       #自定
  160.       if c == "\025"
  161.         text_copy.sub!(/\[(.+)\]/, "")
  162.         if $1 != ""
  163.           next if tx + 24 > self.width - 32
  164.           bitmap = RPG::Cache.icon($1)
  165.           self.blt(tx, ty, bitmap, rect)
  166.           tx += 24
  167.         end
  168.         next
  169.       end
  170.       #====================================
  171.       #其他
  172.       #====================================
  173.       #换行
  174.       if c == "\030"
  175.         ty += self.font.size
  176.         next
  177.       end
  178.       cx = self.text_size(c).width + 1
  179.       #投影
  180.       #dl_color_copy = self.font.color.clone
  181.       #self.font.color.set(0, 0, 0)
  182.       #self.draw_text(tx+1, ty+1, cx, self.font.size, c)
  183.       #self.draw_text(tx-1, ty+1, cx, self.font.size, c)
  184.       #self.draw_text(tx+1, ty-1, cx, self.font.size, c)
  185.       #self.draw_text(tx-1, ty-1, cx, self.font.size, c)
  186.       #self.font.color = dl_color_copy
  187.       self.draw_text(tx, ty, cx, self.font.size, c)
  188.       tx += cx
  189.       #自动换行
  190.       if tx >= self.width
  191.         tx = 0 + 6
  192.         ty += self.font.size + 5
  193.       end
  194.     end
  195.     #恢复调整
  196.     self.font.name = name_copy
  197.     self.font.size = size_copy
  198.     self.font.bold = bold_copy
  199.     self.font.italic = italic_copy
  200.     self.font.color = color_copy
  201.   end
  202. end






整合表情动画


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

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-2 17:28

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表