#==============================================================================
# ■ Window_Command
#------------------------------------------------------------------------------
# 一般的命令选择行窗口。
#==============================================================================
class Window_Command < Window_Selectable
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :commands # 命令
# 图标ID请在下面按照菜单项目的顺序设置...
Command_Icon = {0 => 144, 1 => 63, 2 => 40, 3 =>133 , 4 => 159, 5 => 137}
#--------------------------------------------------------------------------
# ● 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
# width : 窗口宽度
# height : 窗口高度
# spacing : 横向排列时栏间空格
#--------------------------------------------------------------------------
def initialize(width, commands, column_max = 1, row_max = 0, spacing = 32)
if row_max == 0
row_max = (commands.size + column_max - 1) / column_max
end
super(0, 0, width, row_max * WLH + 32, spacing)
@commands = commands
@item_max = commands.size
@column_max = column_max
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# ● 绘制项目
# index : 项目位置
# enabled : 有效标志,false时项目半透明化
#--------------------------------------------------------------------------
def draw_item(index, enabled = true)
rect = item_rect(index)
rect.x += 4
rect.width -= 8
self.contents.clear_rect(rect)
self.contents.font.color = normal_color
self.contents.font.color.alpha = enabled ? 255 : 128
if $scene.is_a?(Scene_Menu)
self.draw_icon(Command_Icon[index], rect.x, rect.y, enabled)
rect.x += 24
self.contents.draw_text(rect, @commands[index])
else
self.contents.draw_text(rect, @commands[index])
end
end
end