class Window_Command < Window_Selectable
#--------------------------------------------------------------------------
# ? initialize
#--------------------------------------------------------------------------
def initialize(width, commands)
super(0, 0, width, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
@sprites = []
for i in 0...@item_max
@sprites[i] = Sprite.new
@sprites[i].x = self.x + 16
@sprites[i].y = self.y + 16 + 32 * i
@sprites[i].z = 100
@sprites[i].bitmap = Bitmap.new(self.width - 32, 32)
@sprites[i].bitmap.draw_text(4, 0, self.width - 32, 32, @commands[i])
end
self.contents = Bitmap.new(width - 32, @item_max * 32)
self.index = 0
end
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
super
for i in 0...@sprites.size
sprite = @sprites[i]
x = i == @index ? self.x + 16 + 32 : self.x + 16
if sprite.x < x
n = (x - sprite.x) / 3
n = 1 if n == 0
sprite.x += n
elsif sprite.x > x
n = (sprite.x - x) / 3
n = 1 if n == 0
sprite.x -= n
end
end
end
#--------------------------------------------------------------------------
# ? x=(x)
#--------------------------------------------------------------------------
def x=(x)
super
return if @sprites == nil
for sprite in @sprites
sprite.x = self.x + 16
end
end
#--------------------------------------------------------------------------
# ? y=(y)
#--------------------------------------------------------------------------
def y=(y)
super
return if @sprites == nil
for i in 0...@sprites.size
@sprites[i].y = self.y + 16 + 32 * i
end
end
#--------------------------------------------------------------------------
# ? visible=(visible)
#--------------------------------------------------------------------------
def visible=(visible)
super
return if @sprites == nil
for sprite in @sprites
sprite.visible = visible
end
end
#--------------------------------------------------------------------------
# ? dispose
#--------------------------------------------------------------------------
def dispose
super
return if @sprites == nil
for sprite in @sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# ? draw_item
#--------------------------------------------------------------------------
def draw_item(index, color)
sprite = @sprites[index]
sprite.bitmap.clear
sprite.bitmap.font.color = color
sprite.bitmap.draw_text(4, 0, self.width - 32, 32, @commands[index])
end
#--------------------------------------------------------------------------
# ? disable_item
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
end[code]