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

Project1

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

[RMVA发布] 动态值槽脚本(3/16更新)

[复制链接]

Lv3.寻梦者 (版主)

…あたしは天使なんかじゃないわ

梦石
0
星屑
2208
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

跳转到指定楼层
1
发表于 2014-3-8 10:39:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 taroxd 于 2014-3-16 14:50 编辑

http://rpg.blue/thread-228005-1-1.html 的脚本差不多也是这个效果。
上面的链接的脚本效果也不错,但是我承认我基本看不懂他的脚本……而且似乎会影响到原来血槽的大小之类的。于是我还是按照自己的需求来制作了一个类似的脚本。

这里是发布版。自用版见 http://rpg.blue/thread-344203-2-1.html 16L。除非发现严重Bug,否则只会更新自用版而不会在这里更新

特点:
值槽完全按照默认脚本设计
值槽上的显示值完全不影响实际值。即:值槽的滚动完全不影响战斗的进行。
值槽滚动的速度可以按照显示的位置分别设置
易于DIY和整合(需要脚本知识,见2L讲解。)

可能会产生脚本兼容性问题(对于导入该脚本的窗口类,该脚本会覆盖 draw_actor_hp 系列方法)
滚动速度并非完全按照设置区域的速度,可能会略快于设置速度。(系统调用的 refresh 方法会导致值槽滚动一次)
值槽每一次滚动都是一次额外的彻底重绘窗口,可能会造成卡顿。(这时应该增大 gauge_refresh_interval 的数值)
两次连续的滚动(如:连续使用两次回复道具)不会叠加,而是会在第一次滚动结束的时间结束(也就是说,第二次使用回复道具不会延长值槽滚动的时间)
值槽的滚动仅对 draw_actor_hp、draw_actor_mp、draw_actor_tp 所绘制的值槽有效

脚本:
RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2. #  ● 动态值槽脚本 Ver1.0 作者:Taroxd
  3. #     可以实现值槽变化时的动态效果。
  4. #     该脚本可能会有较大的不兼容性。如果产生问题,请删除此脚本
  5. #
  6. #--------此处是设置区域,如无必要无需改动---------
  7.  
  8. #  ↓ 此处为战斗时值槽的设置
  9.   class Window_BattleStatus
  10.     def gauge_rolling_times
  11.       30  # 设置每次值槽变化的刷新次数。该数越大,滚动越慢。
  12.     end
  13.     def gauge_refresh_interval
  14.       1   # 设置两次滚动之间的间隔(单位:帧)。该数越大,滚动越慢且越不连续。
  15.     end   # 增大此数可以提高性能。如果卡顿,可以尝试增大此数。
  16.   end
  17. #  ↑ 战斗场景设置完毕
  18.  
  19. #  ↓ 此处为菜单中使用道具时值槽的设置
  20.   class Window_MenuStatus < Window_Selectable
  21.     def gauge_rolling_times
  22.       30  # 设置每次值槽变化的刷新次数。该数越大,滚动越慢。
  23.     end
  24.     def gauge_refresh_interval
  25.       2   # 设置两次滚动之间的间隔(单位:帧)。该数越大,滚动越慢且越不连续。
  26.     end   # 增大此数可以提高性能。如果卡顿,可以尝试增大此数。
  27.   end
  28. #  ↑ 使用道具窗口设置完毕
  29.  
  30. #  ↓ 此处为菜单中使用技能时值槽的设置
  31.   class Window_SkillStatus < Window_Base
  32.     def gauge_rolling_times
  33.       30  # 设置每次值槽变化的刷新次数。该数越大,滚动越慢。
  34.     end
  35.     def gauge_refresh_interval
  36.       2   # 设置两次滚动之间的间隔(单位:帧)。该数越大,滚动越慢且越不连续。
  37.     end   # 增大此数可以提高性能。如果卡顿,可以尝试增大此数。
  38.   end
  39. #  ↑ 使用技能窗口设置完毕
  40.  
  41. #-------------------更新日志--------------------
  42.  
  43. #  3/16 修复了对队友使用技能时值槽会重新滚动的bug
  44.  
  45. #---------不理解脚本者请勿修改以下内容-----------
  46. module RollingGauge
  47.   #--------------------------------------------------------------------------
  48.   # ● 值槽滚动所需的次数
  49.   #--------------------------------------------------------------------------
  50.   def gauge_rolling_times; 30; end
  51.   #--------------------------------------------------------------------------
  52.   # ● 每隔多少帧刷新一次值槽
  53.   #--------------------------------------------------------------------------
  54.   def gauge_refresh_interval; 1; end
  55.   #--------------------------------------------------------------------------
  56.   # ● 初始化
  57.   #--------------------------------------------------------------------------
  58.   def initialize(*)
  59.     @last_gauge_value = {}
  60.     @gauge_fiber      = {}
  61.     @gauge_refresh_counting = 0
  62.     super
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ● 更新
  66.   #--------------------------------------------------------------------------
  67.   def update
  68.     super
  69.     update_gauge_rolling
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● 更新值槽
  73.   #--------------------------------------------------------------------------
  74.   def update_gauge_rolling
  75.     @gauge_refresh_counting += 1 unless @gauge_fiber.empty?
  76.     if @gauge_refresh_counting >= gauge_refresh_interval
  77.       refresh
  78.       @gauge_refresh_counting = 0
  79.     end
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # ● 绘制值槽的方法模板
  83.   #--------------------------------------------------------------------------
  84.   def self.def_draw_actor_(sym)
  85.     module_eval %{
  86.       def draw_actor_#{sym}(actor, x, y, width = 124)
  87.         key = [x, y]
  88.         fiber = @gauge_fiber[key]
  89.         return fiber.resume if fiber
  90.         value = actor.#{sym}
  91.         @last_gauge_value[key] ||= value
  92.         last_value = @last_gauge_value[key]
  93.         if last_value == value
  94.           draw_#{sym}_by_value(actor, value, x, y, width)
  95.           return
  96.         end
  97.         @gauge_fiber[key] = fiber = Fiber.new do
  98.           value = last_value.to_f
  99.           (gauge_rolling_times - 1).times do |i|
  100.             value += (actor.#{sym} - value) / (gauge_rolling_times - i)
  101.             draw_#{sym}_by_value(actor, value.round, x, y, width)
  102.             Fiber.yield
  103.           end
  104.           @last_gauge_value[key] = value = actor.#{sym}
  105.           draw_#{sym}_by_value(actor, value, x, y, width)
  106.           @gauge_fiber.delete(key)
  107.         end
  108.         fiber.resume
  109.       end
  110.     }
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ● 定义绘制值槽的方法
  114.   #--------------------------------------------------------------------------
  115.   def_draw_actor_ :hp
  116.   def_draw_actor_ :mp
  117.   def_draw_actor_ :tp
  118.   #--------------------------------------------------------------------------
  119.   # ● 按值绘制 HP
  120.   #--------------------------------------------------------------------------
  121.   def draw_hp_by_value(actor, value, x, y, width = 124)
  122.     draw_gauge(x, y, width, value.to_f / actor.mhp,
  123.       hp_gauge_color1, hp_gauge_color2)
  124.     change_color(system_color)
  125.     draw_text(x, y, 30, line_height, Vocab::hp_a)
  126.     draw_current_and_max_values(x, y, width, value, actor.mhp,
  127.       hp_color(actor), normal_color)
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # ● 按值绘制 MP
  131.   #--------------------------------------------------------------------------
  132.   def draw_mp_by_value(actor, value, x, y, width = 124)
  133.     draw_gauge(x, y, width, value.to_f / actor.mmp,
  134.       mp_gauge_color1, mp_gauge_color2)
  135.     change_color(system_color)
  136.     draw_text(x, y, 30, line_height, Vocab::mp_a)
  137.     draw_current_and_max_values(x, y, width, value, actor.mmp,
  138.       mp_color(actor), normal_color)
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ● 按值绘制 TP
  142.   #--------------------------------------------------------------------------
  143.   def draw_tp_by_value(actor, value, x, y, width = 124)
  144.     draw_gauge(x, y, width, value.to_f / actor.max_tp,
  145.       tp_gauge_color1, tp_gauge_color2)
  146.     change_color(system_color)
  147.     draw_text(x, y, 30, line_height, Vocab::tp_a)
  148.     change_color(tp_color(actor))
  149.     draw_text(x + width - 42, y, 42, line_height, value.to_i, 2)
  150.   end
  151. end
  152.  
  153. class Window_BattleActor < Window_BattleStatus
  154.   alias draw_actor_hp draw_actor_hp
  155.   alias draw_actor_mp draw_actor_mp
  156.   alias draw_actor_tp draw_actor_tp
  157. end
  158.  
  159. class Window_BattleStatus < Window_Selectable
  160.   include RollingGauge
  161. end
  162.  
  163. class Window_MenuStatus < Window_Selectable
  164.   include RollingGauge
  165. end
  166.  
  167. class Window_SkillStatus < Window_Base
  168.   include RollingGauge
  169. end

Lv3.寻梦者 (版主)

…あたしは天使なんかじゃないわ

梦石
0
星屑
2208
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

2
 楼主| 发表于 2014-3-8 10:39:45 | 只看该作者
脚本的讲解:

RUBY 代码复制
  1. # 设置区域省略
  2. module RollingGauge
  3.   #--------------------------------------------------------------------------
  4.   # ● 值槽滚动所需的次数
  5.   #--------------------------------------------------------------------------
  6.   def gauge_rolling_times; 30; end  # 见上方注释
  7.   #--------------------------------------------------------------------------
  8.   # ● 每隔多少帧刷新一次值槽
  9.   #--------------------------------------------------------------------------
  10.   def gauge_refresh_interval; 1; end  # 见上方注释
  11.  
  12.   # ↑ 以上两个量定义为方法而不是常量,可以便于子类修改,也可以进行动态的计算
  13.   # 想要改动滚动速度,应该在子类对这两个方法进行重定义
  14.   # 如:gauge_rolling_times 可以定义为 $game_party.members.collect(&:mhp).max / 100
  15.   # 可以随着队伍的升级,增加滚动所需要的时间
  16.  
  17.   #--------------------------------------------------------------------------
  18.   # ● 初始化
  19.   #--------------------------------------------------------------------------
  20.   def initialize(*)              # 不改变参数列表
  21.     @last_gauge_value = {}       # 值槽 => 滚动前值槽上显示的值
  22.     @gauge_fiber      = {}       # 值槽 => 滚动值槽所用的纤程
  23.     @gauge_refresh_counting = 0  # 距离上次刷新值槽已经过了几帧
  24.     super
  25.   end
  26.   #--------------------------------------------------------------------------
  27.   # ● 更新
  28.   #--------------------------------------------------------------------------
  29.   def update
  30.     super
  31.     update_gauge_rolling
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 更新值槽
  35.   #--------------------------------------------------------------------------
  36.   def update_gauge_rolling
  37.     @gauge_refresh_counting += 1 unless @gauge_fiber.empty?  # 如果还有值槽没有滚动完毕,则更新计数
  38.     if @gauge_refresh_counting >= gauge_refresh_interval     # 此时应该刷新值槽
  39.       refresh                       # 完全重绘,重绘的时候会调用 draw_actor_hp 系列来刷新值槽
  40.       @gauge_refresh_counting = 0   # 计数归零
  41.     end
  42.   end
  43.  
  44.   # 因为这里hp,mp,tp定义完全相同,因此我在原脚本里偷了个懒。这里仅仅演示hp
  45.   def draw_actor_hp(actor, x, y, width = 124)
  46.     # 这一段判断:如果值槽正在滚动状态,则向前滚动一次(①)
  47.     key = [x, y]                  # 值槽的横纵坐标是值槽的特征。横纵坐标均相同的值槽视为同一值槽。
  48.     fiber = @gauge_fiber[key]     # 获取绘制值槽的纤程
  49.     return fiber.resume if fiber  # 如果当前值槽正在滚动,则从上次停止滚动的地方继续
  50.  
  51.     # 这一段判断:如果值槽的值不变,则无须滚动(②)
  52.     value = actor.hp              # 获取当前 hp。变量名使用value而不是hp是为了不需要对mp、tp进行修改
  53.     @last_gauge_value[key] ||= value  # 初始化该值槽的信息。这一行代码对一个值槽总共只会执行一次。
  54.     last_value = @last_gauge_value[key]  # 获取值槽上次显示的值
  55.     if last_value == value        # 如果值没有变化
  56.       return draw_hp_by_value(actor, value, x, y, width)  # 直接画出值槽并返回,无须滚动
  57.     end
  58.  
  59.     # 这一段创建滚动的纤程(③)
  60.     @gauge_fiber[key] = fiber = Fiber.new do  # 创建值槽滚动的纤程
  61.       value = last_value.to_f                 # 初始化需要绘制的值
  62.       (gauge_rolling_times - 1).times do |i|  # 前 n - 1 次滚动
  63.         # 计算公式说明
  64.         # actor.hp - value: 距离滚动目标的差值
  65.         # gauge_rolling_times - i: 值槽滚动剩余的次数
  66.         value += (actor.hp - value) / (gauge_rolling_times - i)
  67.         draw_hp_by_value(actor, value.round, x, y, width)        # 绘制值槽
  68.         Fiber.yield                           # 暂停滚动
  69.       end
  70.       # 最后一次滚动
  71.       @last_gauge_value[key] = value = actor.hp    # 储存当前值槽的值
  72.       draw_hp_by_value(actor, value, x, y, width)  # 最后一次绘制
  73.       @gauge_fiber.delete(key)                     # 表明该值槽已经不需要滚动了
  74.     end
  75.  
  76.     # 创建的纤程不会立即执行,因此执行一次
  77.     fiber.resume
  78.  
  79.     # 创建完纤程之后,下一次调用 draw_actor_hp 时,在第①段就会返回,直到滚动完毕为止。
  80.     # 当值槽需要滚动(即 @gauge_fiber 不为空)时,update会定期调用refresh,来进行值槽的滚动。
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # ● 按值绘制 HP
  84.   #--------------------------------------------------------------------------
  85.   # 如果想要DIY值槽,应该在子类对这个方法进行重定义
  86.   def draw_hp_by_value(actor, value, x, y, width = 124)
  87.     draw_gauge(x, y, width, value.to_f / actor.mhp,
  88.       hp_gauge_color1, hp_gauge_color2)
  89.     change_color(system_color)
  90.     draw_text(x, y, 30, line_height, Vocab::hp_a)
  91.     draw_current_and_max_values(x, y, width, value, actor.mhp,
  92.       hp_color(actor), normal_color)
  93.   end
  94. end
  95.  
  96. # 战斗状态栏
  97. class Window_BattleStatus < Window_Selectable
  98.   include RollingGauge
  99. end
  100.  
  101. # 使用道具时的状态栏
  102. class Window_MenuStatus < Window_Selectable
  103.   include RollingGauge
  104. end
  105.  
  106. # 使用技能时的状态栏
  107. class Window_SkillStatus < Window_Base
  108.   include RollingGauge
  109. end
  110.  
  111. # 整合方式
  112. class Your_Window
  113.   include RollingGauge
  114.   def gauge_rolling_times; 30; end  # 设置该窗口的值槽滚动速度
  115.   def gauge_refresh_interval; 1; end  # 设置该窗口的值槽滚动间隔
  116.   def draw_hp_by_value(actor, value, x, y, width = 124) # 如果需要
  117.     # 设置该窗口绘制hp的方式
  118.   end
  119.   def draw_all_items  # 如果需要(比如原先绘制值槽不是用draw_actor_hp系列) 注:方法名瞎起的
  120.     # 通过调用 draw_actor_hp 来绘制值槽
  121.   end
  122. end

点评

此处已经不再更新,请阅读使用规约后,用 https://taroxd.github.io/rgss/ 里面的版本  发表于 2017-2-20 07:06
大神,这个脚本我在用,发现一个BUG就是当职业MP最大值是0时,显示MP槽值时会报错。请问可以修复这个吗。  发表于 2017-2-19 23:54
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-21 09:53

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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