#===============================================================================
# ** Window_BlacksmithForge
#===============================================================================
class Window_BlacksmithForge < Window_Selectable
def initialize(shop_goods)
super(0, 128, 368, 352)
# Initialize window and create instance variable to store available goods.
@shop_goods = shop_goods
self.active = self.visible = false
refresh
self.index = 0
end
#-----------------------------------------------------------------------------
def item
return @data[self.index]
end
#-----------------------------------------------------------------------------
def refresh(enchanting = false)
# Dispose bitmap and set to nil if not already.
if self.contents != nil
self.contents = self.contents.dispose
end
# Set flag for enchanting
@enchanting = enchanting
# Create array of equipment, depending on flag
if @enchanting
@data = []
# Add weapons
($data_weapons - [nil]).each {|weapon|
if $game_party.weapon_number(weapon.id) > 0 &&
!Blacksmith::NO_ENCHANT_WEAPONS.include?(weapon.id)
@data.push(weapon)
end
}
# Add Armor
($data_armors - [nil]).each {|armor|
if $game_party.armor_number(armor.id) > 0 &&
!Blacksmith::NO_ENCHANT_ARMORS.include?(armor.id)
@data.push(armor)
end
}
else
@data = @shop_goods
end
# Keep only items that you have materials for
@new_data = []
@data.each{|i|
case i
when RPG::Weapon
type = 0
when RPG::Armor
type = 1
when RPG::Item
type = 2
end
@new_data.push(i) if Blacksmith.materials?(type, i.id)
}
@data = @new_data
# Create a new bitmap, sized for available items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
(0...@item_max).each {|i| draw_item(i) }
end
end
#-----------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
# Set a few local variables depending on the type of item.
case item
when RPG::Weapon
quantity = $game_party.weapon_number(item.id)
price, type = Blacksmith.weapon_gold(item.id)[0], 0
when RPG::Armor
quantity = $game_party.armor_number(item.id)
price, type = Blacksmith.armor_gold(item.id)[0], 1
when RPG::Item
quantity = $game_party.item_number(item.id)
price, type = Blacksmith.item_gold(item.id)[0], 2
end
# Don't check material requirments for forging wjen enchanting
result = @enchanting ? true : Blacksmith.materials?(type, item.id)
# Determine the color to use for drawing the item name.
if quantity < 99 && result
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
# Draw the item name, icon, and price.
x, y = 4, index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
if !@enchanting
self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
end
end
#-----------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? '' : self.item.description)
end
end