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

Project1

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

监控开关变量

[复制链接]

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

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

开拓者贵宾

跳转到指定楼层
1
发表于 2014-9-21 07:26:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 taroxd 于 2015-2-13 10:18 编辑

RUBY 代码复制
  1. #------------------------------------------------------------
  2. # ● 监控开关变量
  3. #------------------------------------------------------------
  4. #
  5. #    该脚本可将开关/变量固定为一个游戏数据。
  6. #    可以用于事件页的出现条件,
  7. #    可以用于其他以开关作为条件的脚本。
  8. #
  9. #    设置区域在下方,设置范例:
  10. #
  11. #    变量1 固定为队伍的金钱
  12. #      variable(1) { $game_party.gold }
  13. #
  14. #    变量2 固定为队伍中第i+1号队员的体力值,其中i为变量2原本的值
  15. #      variable(2) do |i|
  16. #        actor = $game_party.members[i]
  17. #        actor ? actor.hp : 0
  18. #      end
  19. #
  20. #    开关1 取反
  21. #      switch(1, &:!)
  22. #
  23. #------------------------------------------------------------
  24.  
  25. module Taroxd end
  26.  
  27. module Taroxd::Monitor
  28.  
  29.   # 是否更改F9调试窗口的显示。如无冲突建议为 true。
  30.   DEBUG_WINDOW = true
  31.  
  32.   @list = {}  # 保存了监控设置的哈希表
  33.  
  34.   # 获取变量的值
  35.   def self.operate(id, value)
  36.     proc = @list[id]
  37.     proc ? proc.call(value) : value
  38.   end
  39.  
  40.   # 增加开关监控(不存档)
  41.   def self.switch(id, &proc)
  42.     @list[-id] = proc
  43.   end
  44.  
  45.   # 增加变量监控(不存档)
  46.   def self.variable(id, &proc)
  47.     @list[id] = proc
  48.   end
  49.  
  50.   # 是否正在监控。若列表不存在对应的项或值为 nil,则返回 nil。
  51.   def self.include?(id)
  52.     @list[id]
  53.   end
  54.  
  55.   # --- 设置区域在此 ---
  56.  
  57.   # --- 设置区域结束 ---
  58. end
  59.  
  60. class Game_Switches
  61.   alias_method :no_monitor_value, :[]
  62.   def [](id)
  63.     Taroxd::Monitor.operate(-id, no_monitor_value(id))
  64.   end
  65. end
  66.  
  67. class Game_Variables
  68.   alias_method :no_monitor_value, :[]
  69.   def [](id)
  70.     Taroxd::Monitor.operate(id, no_monitor_value(id))
  71.   end
  72. end
  73.  
  74. class Game_Interpreter
  75.   def operate_variable(id, type, value)
  76.     $game_variables[id] = case type
  77.     when 0  # 代入
  78.       value
  79.     when 1  # 加法
  80.       $game_variables.no_monitor_value(id) + value
  81.     when 2  # 减法
  82.       $game_variables.no_monitor_value(id) - value
  83.     when 3  # 乘法
  84.       $game_variables.no_monitor_value(id) * value
  85.     when 4  # 除法
  86.       value.zero? ? 0 : $game_variables.no_monitor_value(id) / value
  87.     when 5  # 取余
  88.       value.zero? ? 0 : $game_variables.no_monitor_value(id) % value
  89.     end
  90.   end
  91. end
  92.  
  93. class Window_DebugRight < Window_Selectable
  94.   def update_switch_mode
  95.     return unless Input.trigger?(:C)
  96.     id = current_id
  97.     $game_switches[id] = !$game_switches.no_monitor_value(id)
  98.     Sound.play_ok
  99.     redraw_current_item
  100.   end
  101.  
  102.   def update_variable_mode
  103.     id = current_id
  104.     value = $game_variables.no_monitor_value(id)
  105.     return unless value.is_a?(Numeric)
  106.     value += 1 if Input.repeat?(:RIGHT)
  107.     value -= 1 if Input.repeat?(:LEFT)
  108.     value += 10 if Input.repeat?(:R)
  109.     value -= 10 if Input.repeat?(:L)
  110.     if $game_variables.no_monitor_value(current_id) != value
  111.       $game_variables[id] = value
  112.       Sound.play_cursor
  113.       redraw_current_item
  114.     end
  115.   end
  116.  
  117.   def draw_item(index)
  118.     data_id = @top_id + index
  119.     id_text = sprintf("%04d:", data_id)
  120.     id_width = text_size(id_text).width
  121.     if @mode == :switch
  122.       name = $data_system.switches[data_id]
  123.       status = $game_switches.no_monitor_value(data_id) ? '[ON]' : '[OFF]'
  124.       if Taroxd::Monitor.include?(-data_id)
  125.         status.concat($game_switches[data_id] ? ' ->  [ON]' : ' -> [OFF]')
  126.       end
  127.     else
  128.       name = $data_system.variables[data_id]
  129.       status = $game_variables.no_monitor_value(data_id).to_s
  130.       if Taroxd::Monitor.include?(data_id)
  131.         status << ' -> ' << $game_variables[data_id].to_s
  132.       end
  133.     end
  134.     name = "" unless name
  135.     rect = item_rect_for_text(index)
  136.     change_color(normal_color)
  137.     draw_text(rect, id_text)
  138.     rect.x += id_width
  139.     rect.width -= id_width + 60
  140.     draw_text(rect, name)
  141.     rect.width += 60
  142.     draw_text(rect, status, 2)
  143.   end
  144. end if Taroxd::Monitor::DEBUG_WINDOW
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

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

GMT+8, 2024-5-1 05:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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