查看: 2194|回复: 6

[已经解决] 如何判定window_command的位置更变描绘方式?

[复制链接]
梦石
0
星屑
8498
在线时间
775 小时
注册时间
2017-11-10
回帖
1074
发表于 2018-3-31 13:44:20 | 显示全部楼层 |阅读模式

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

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

×
复写了一段自己用的脚本,发现出现了问题。
就是当某些选项无效的时候,无法在选中时显示该选项无效的颜色。
估计是描绘判断出现了问题。请教各位前辈该如何去修改这段脚本?
暂时无逻辑思路的说...
[pre lang="ruby"]#==============================================================================
# ■ Window_Command
#------------------------------------------------------------------------------
#  一般的命令选择行窗口。
#==============================================================================
  class Window_Command < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     width    : 窗口的宽
  #     commands : 命令字符串序列
  #--------------------------------------------------------------------------
  def initialize(width, commands)
    # 由命令的个数计算出窗口的高
    super(0, 0, width, commands.size * 32 + 32)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    refresh
    self.index = 0
    @putcommand = 0
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      if i != self.index
      draw_item_put(i)
      else
      draw_item(i, normal_color)
    end
  end
end
  #--------------------------------------------------------------------------
  # ● 描绘项目(选中时处理)
  #     index : 项目编号
  #--------------------------------------------------------------------------
  def draw_item_put(index)
    self.contents.font.size -= 2
    rect = Rect.new(4 + 8, 32 * index, self.contents.width - 16, 32)
    self.contents.draw_text(rect, @commands[index])
    self.contents.font.size += 2
end
  #--------------------------------------------------------------------------
  # ● 描绘项目(一般时处理)
  #     index : 项目编号
  #     color : 文字色
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
  #--------------------------------------------------------------------------
  # ● 项目无效化
  #     index : 项目编号
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  #--------------------------------------------------------------------------
  # ● 更新
  #--------------------------------------------------------------------------
  def update
    super
    if self.index != @putcommand
      @putcommand = self.index
      refresh
    end
  end
end

  [/pre]

评分

参与人数 1赞 +1 收起 理由
ikki + 1 塞糖

查看全部评分

一个只会简单事件的Rm新人,脚本完全不懂。只求做个简单的游戏完成自己的游戏之梦而已。
第一个游戏已经完成,等待各素材的完成和测试。
梦石
0
星屑
910
在线时间
94 小时
注册时间
2005-10-22
回帖
335
发表于 2018-3-31 14:09:19 | 显示全部楼层
为啥我的和你的不一样呢?
  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
复制代码
做脚本先从修改脚本做起,我只修改自己觉得能用到的东西。
以后的任何作品都将不会进行分享。
Bilibili:https://space.bilibili.com/288814521
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2018-3-31 15:54:07 | 显示全部楼层
如果要在选中的时候才刷新就动一下refresh和update

该选项无效的颜色是指字体颜色吗?还是选项文字的不透明度

点评

字体颜色是这句self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))吧···  发表于 2018-3-31 21:10
字体颜色...  发表于 2018-3-31 15:54
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复

使用道具 举报

梦石
0
星屑
910
在线时间
94 小时
注册时间
2005-10-22
回帖
335
发表于 2018-3-31 16:09:07 | 显示全部楼层
刷新的地方刷新下无效的字体颜色应该就可以了吧
做脚本先从修改脚本做起,我只修改自己觉得能用到的东西。
以后的任何作品都将不会进行分享。
Bilibili:https://space.bilibili.com/288814521
回复

使用道具 举报

梦石
0
星屑
8498
在线时间
775 小时
注册时间
2017-11-10
回帖
1074
 楼主| 发表于 2018-4-1 15:05:57 | 显示全部楼层
已经通过复写的方式解决了问题,感谢前辈们的指导。
一个只会简单事件的Rm新人,脚本完全不懂。只求做个简单的游戏完成自己的游戏之梦而已。
第一个游戏已经完成,等待各素材的完成和测试。
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部