Project1

标题: 如何判定window_command的位置更变描绘方式? [打印本页]

作者: 文雅夕露    时间: 2018-3-31 13:44
标题: 如何判定window_command的位置更变描绘方式?
复写了一段自己用的脚本,发现出现了问题。
就是当某些选项无效的时候,无法在选中时显示该选项无效的颜色。
估计是描绘判断出现了问题。请教各位前辈该如何去修改这段脚本?
暂时无逻辑思路的说...
RUBY 代码复制
  1. #==============================================================================
  2. # ■ Window_Command
  3. #------------------------------------------------------------------------------
  4. #  一般的命令选择行窗口。
  5. #==============================================================================
  6.   class Window_Command < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     width    : 窗口的宽
  10.   #     commands : 命令字符串序列
  11.   #--------------------------------------------------------------------------
  12.   def initialize(width, commands)
  13.     # 由命令的个数计算出窗口的高
  14.     super(0, 0, width, commands.size * 32 + 32)
  15.     @item_max = commands.size
  16.     @commands = commands
  17.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  18.     refresh
  19.     self.index = 0
  20.     @putcommand = 0
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 刷新
  24.   #--------------------------------------------------------------------------
  25.   def refresh
  26.     self.contents.clear
  27.     for i in 0...@item_max
  28.       if i != self.index
  29.       draw_item_put(i)
  30.       else
  31.       draw_item(i, normal_color)
  32.     end
  33.   end
  34. end
  35.   #--------------------------------------------------------------------------
  36.   # ● 描绘项目(选中时处理)
  37.   #     index : 项目编号
  38.   #--------------------------------------------------------------------------
  39.   def draw_item_put(index)
  40.     self.contents.font.size -= 2
  41.     rect = Rect.new(4 + 8, 32 * index, self.contents.width - 16, 32)
  42.     self.contents.draw_text(rect, @commands[index])
  43.     self.contents.font.size += 2
  44. end
  45.   #--------------------------------------------------------------------------
  46.   # ● 描绘项目(一般时处理)
  47.   #     index : 项目编号
  48.   #     color : 文字色
  49.   #--------------------------------------------------------------------------
  50.   def draw_item(index, color)
  51.     self.contents.font.color = color
  52.     rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
  53.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  54.     self.contents.draw_text(rect, @commands[index])
  55.   end
  56.   #--------------------------------------------------------------------------
  57.   # ● 项目无效化
  58.   #     index : 项目编号
  59.   #--------------------------------------------------------------------------
  60.   def disable_item(index)
  61.     draw_item(index, disabled_color)
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ● 更新
  65.   #--------------------------------------------------------------------------
  66.   def update
  67.     super
  68.     if self.index != @putcommand
  69.       @putcommand = self.index
  70.       refresh
  71.     end
  72.   end
  73. end

作者: ikki    时间: 2018-3-31 14:09
为啥我的和你的不一样呢?
  1. #==============================================================================
  2. # ■ Window_Command
  3. #------------------------------------------------------------------------------
  4. #  一般的命令选择行窗口。
  5. #==============================================================================

  6. class Window_Command < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     width    : 窗口的宽
  10.   #     commands : 命令字符串序列
  11.   #--------------------------------------------------------------------------
  12.   def initialize(width, commands)
  13.     # 由命令的个数计算出窗口的高
  14.     super(0, 0, width, commands.size * 32 + 32)
  15.     @item_max = commands.size
  16.     @commands = commands
  17.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  18.     refresh
  19.     self.index = 0
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # ● 刷新
  23.   #--------------------------------------------------------------------------
  24.   def refresh
  25.     self.contents.clear
  26.     for i in 0...@item_max
  27.       draw_item(i, normal_color)
  28.     end
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # ● 描绘项目
  32.   #     index : 项目编号
  33.   #     color : 文字色
  34.   #--------------------------------------------------------------------------
  35.   def draw_item(index, color)
  36. #    self.contents.font.color = color
  37.     rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
  38.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  39.     self.contents.draw_text(rect, @commands[index])
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● 项目无效化
  43.   #     index : 项目编号
  44.   #--------------------------------------------------------------------------
  45.   def disable_item(index)
  46.     draw_item(index, disabled_color)
  47.   end
  48. end
复制代码

作者: chd114    时间: 2018-3-31 15:54
如果要在选中的时候才刷新就动一下refresh和update

该选项无效的颜色是指字体颜色吗?还是选项文字的不透明度
作者: ikki    时间: 2018-3-31 16:09
刷新的地方刷新下无效的字体颜色应该就可以了吧
作者: 文雅夕露    时间: 2018-4-1 15:05
已经通过复写的方式解决了问题,感谢前辈们的指导。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1