Home > RGSS Script Reference > Window_ShopSell
Window_ShopSell
Inherits from: Window_Selectable
Description: This window shows the items the party can sell when you select "Sell" from the shop command menu.
class Window_ShopSell < Window_Selectable
# ------------------------------------
def initialize
super(0, 128, 640, 352)
@column_max = 2
refresh
self.index = 0
end
# ------------------------------------
def item
return @data[self.index]
end
# ------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
# ------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
if item.price > 0
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 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)
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
|
Data: An array containing the items to be drawn. The contents of this array are determined in the refresh method.
Initialize
Arguments: None
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 128, the width to 368, and the height to 352. The window contents are drawn with the refresh method.
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: None
How it Works: This method draws the contents of the window. Since this window can be scrolled, the bitmap is disposed and recreated each time the window is refreshed. The @data array is set to be an empty array. For each item, weapon, and armor declared in the database, the item is pushed onto the @data array if the party has at least one copy of that item, weapon, or armor. The window's @item_max instance variable is set equal to the size of the @data array. If the item max is greater than 0, then the bitmap is created, and the draw_item method is called to draw the icon and item for each item in the @data array.
Draw_Item
Arguments:
Index: The index of the item to be drawn.
Local Variables:
Item: An alias for the item at the index of the @data array that is being drawn.
How it Works: This method draws an individual item within the shop buy window. The first thing to do is decide whether the item being drawn is a RPG::Item, RPG::Weapon, or RPG::Armor object. This allows the method to decide method to use to determine the number of the item the party has. If the price of the item isn't 0, then the item is drawn in the normal color. Otherwise, the item is drawn in the disabled color. (a price of 0 is a special designation meaning the item can't be sold). Next, the method needs to determine the x and y coordinates at which to draw the item. The x coordinate is always 4, and the y coordinate is 32 times the index of the item. The rectangle is then constructed with those x and y coordinates, and a length of the window's width minus 32, and a height of 32. It then draws the item's icon, name, and price within the rectangle. Note that the draw_text methods for both the name and price have the optional alignment argument. For the name, the argument is 0, meaning left-alignment, and for the price, the argument is 2, meaning right-alignment.
Update_Help
Arguments: None
Local Variables: None
How it Works: This method updates the help window with the description of the currently selected item.
|
|