Home > RGSS Script Reference > Window_EquipItem
Window_EquipItem
Inherits from: Window_Selectable
Description: This window shows the items that can be equipped by a character once an equipment slot is selected from the list that appears above this window on the equip screen.
class Window_EquipItem < Window_Selectable
# ------------------------------------
def initialize(actor, equip_type)
super(0, 256, 640, 224)
@actor = actor
@equip_type = equip_type
@column_max = 2
refresh
self.active = false
self.index = -1
end
# ------------------------------------
def item
return @data[self.index]
end
# ------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
if @equip_type == 0
weapon_set = $data_classes[@actor.class_id].weapon_set
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)
@data.push($data_weapons[i])
end
end
end
if @equip_type != 0
armor_set = $data_classes[@actor.class_id].armor_set
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0 and armor_set.include?(i)
if $data_armors[i].kind == @equip_type-1
@data.push($data_armors[i])
end
end
end
end
@data.push(nil)
@item_max = @data.size
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max-1
draw_item(i)
end
end
# ------------------------------------
def draw_item(index)
item = @data[index]
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
case item
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.font.color = normal_color
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
# ------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
|
Actor: The actor whose equipment is being changed.
Equip_Type: The type of items to show in the window (0 = Weapons, 1 = Shields, 2 = Helmets, 3 = Armor, 4 = Accessories).
Data: An array containing the items to be drawn. The contents of this array are determined in the refresh method.
Initialize
Arguments:
Actor: The actor whose equipment is being changed.
Equip_Type: The type of equipment to be shown. See the property definitions for a guide to the meaning of this value.
Local Variables: None
How it Works: This method initializes the window. First, the window's x coordinate is initialized to 0, the y coordinate is initialized to 256, the width to 640, and the height to 224. Then, the @actor and @equip_type instance variables are set. The window is then populated with data by the refresh method, and the window is set to be inactive.
Item
Arguments: None
Local Variables: None
How it Works: This method returns the item in the @data array corresponding to the index of the currently selected item.
Refresh
Arguments: None
Local Variables:
Weapon_Set: The list of weapons that can be equipped by the actor's class. Used only if the value of @equip_type is 0.
Armor_Set: The list of defensive items that can be equipped by the actor's class. Used only if the value of @equip_type is not 0.
How it Works: This method draws the contents of the item window. First, the window disposes of its contents and constructs an entirely new bitmap, since the height of the bitmap is tailored to the number of items to be displayed. The @data array is then initialized (or reinitialized) to an empty array. The @data array is then constructed based on whether the value of @equip_type is zero or nonzero. In the case of @equip_type being zero, the value of the local variable weapon_set is set to the list of weapons that the actor's class can equip. Then, for each weapon declared in the database, the method checks to see if the party has at least one of them, and if that weapon is included in the weapon_set array. If both of these conditions are satisfied, then the weapon is added to the @data array. The way it works for armor and the armor_set variable is similar, but there is one difference. Because there are different kinds of armors, and only one type of armor is shown in the window at once, not only must the party have one and the actor's class be able to equip it, but the weapon's "kind" must be equal to the value of @equip_type, minus one. After adding either the weapons or armors to the array, one instance of nil is pushed onto the array. This is done in order to create an extra empty space after all the other items. If the player selects the space, the item in that slot will be removed without it being replaced by another item. The window's @item_max is then dynamically set based on the size of the @data array. After all that, the height of the new window bitmap is determined. The width of the bitmap is always 608, but the height is 32 for each two or part of two items in the @data array. Then, each item in @data is drawn with a call to draw_item.
Draw_Item
Arguments:
Index: The index of the item to be drawn.
Local Variables: None
How it Works: This method draws an individual item in the window. The first thing to do is acquire the coordinates at which the item should be drawn. If the item's index is even, then the x coordinate at which the item is drawn is 4. If the item's index is odd, then x coordinate is 324. The y coordinate at which the index is drawn is half the index (rounded down) multiplied by 32. Next, the method determines whether the item in question is a RPG::Weapon or RPG::Armor object. This determines which method to call to determine how many of this item is in the party's inventory. The method then acquires the bitmap of the item's icon name. The item's icon is then drawn in a 24x24 rectangle. The item's name, followed by the string ":", followed by the number of that item in the party's inventory, is drawn to the right of the icon.
Update_Help
Arguments: None
Local Variables: None
How it Works: This method updates the help window with the description of the currently selected item, or nil if an empty space is currently selected.
|
|