Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Window_ShopBuy

Window_ShopBuy


Inherits from: Window_Selectable

Description: This window shows the items available for sale when you select "Buy" from the main shop command window.

Code


class Window_ShopBuy < Window_Selectable
# ------------------------------------
 def initialize(shop_goods)
    super(0, 128, 368, 352)
    @shop_goods = shop_goods
    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 goods_item in @shop_goods
      case goods_item[0]
      when 0
        @data.push($data_items[goods_item[1]])
      when 1
        @data.push($data_weapons[goods_item[1]])
      when 2
        @data.push($data_armors[goods_item[1]])
      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 <= $game_party.gold and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = 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)
    self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s, 2)
  end
# ------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end

Properties


Shop_Goods: An array of arrays representing the items for sale at the shop. Each sub-array in the main array has two entries. Index 0 is a number representing the type of item (0 = Item, 1 = Weapon, 2 = Armor) and index 1 is the ID number of that item, weapon, or armor as declared in the database.

Data: An array containing the items to be drawn. The contents of this array are determined in the refresh method.

Methods


Initialize

Arguments:
Shop_Goods: An array of arrays representing the items for sale at the shop. Each sub-array in the main array has two entries. Index 0 is a number representing the type of item (0 = Item, 1 = Weapon, 2 = Armor) and index 1 is the ID number of that item, weapon, or armor as declared in the database.
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. Then, the @shop_goods instance variables is set to the value passed to this method. The window contents are then 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 element in the @shop_goods, the method checks the first index of the sub-array. If that value is 0, then the item with ID equal to the second index of the sub-array is pushed onto the @data array. If that value is 1, then the weapon with the ID equal to the second index of the sub-array is pushed onto @data. If that value is 2, then the armor with ID equal to the second index of the sub-array is pushed onto @data. 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 item's price is less than or equal to the price of the item and the party has fewer than 99 of the item, then the item name is drawn in the normal color. Otherwise, it's drawn in the disabled color. 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. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal