#==============================================================================
# ** Window_HorizCommand
#------------------------------------------------------------------------------
# This window deals with general command choices. (Horizontal)
#==============================================================================
class Window_HorizCommand < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :commands
attr_accessor :c_spacing
attr_accessor :alignment
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(width, commands, c_spacing = (width - 32) / commands.size)
# Compute window height from command quantity
super(0, 0, width, 64)
@commands = commands
@item_max = commands.size
@column_max = @item_max
@c_spacing = c_spacing
@alignment = 1
self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Command
#--------------------------------------------------------------------------
def command(index = self.index)
return @commands[index]
end
#--------------------------------------------------------------------------
# * Commands
#--------------------------------------------------------------------------
def commands=(commands)
# Return if Commands Are Same
return if @commands == commands
# Reset Commands
@commands = commands
# Resets Item Max
item_max = @item_max
@item_max = @commands.size
@column_max = @item_max
# If Item Max Changes
unless item_max == @item_max
# Deletes Existing Contents (If Exist)
unless self.contents.nil?
self.contents.dispose
self.contents = nil
end
# Recreates Contents
self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
end
# Refresh Window
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index, color)
command = commands[index]
x = index * @c_spacing + 4
self.contents.font.color = color
self.contents.draw_text(x, 0, @c_spacing - 8, 32, command, @alignment)
end
#--------------------------------------------------------------------------
# * Disable Item
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(@c_spacing * @index, 0, @c_spacing, 32)
end
end
end