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

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Window_ShopStatus

Window_ShopStatus


Inherits from: Window_Base

Description: When selecting items to buy in a shop, this window shows the number of that item currently in the party's inventory, and the change in attack power (for weapons) or physical defense (for armor) for each character that can equip the item.

Code


class Window_ShopStatus < Window_Base
# ------------------------------------
 def initialize
    super(368, 128, 272, 352)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item = nil
    refresh
  end
# ------------------------------------
  def refresh
    self.contents.clear
    if @item == nil
return end 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 self.contents.font.color = system_color self.contents.draw_text(4, 0, 200, 32, "Possessed") self.contents.font.color = normal_color self.contents.draw_text(204, 0, 32, 32, number.to_s, 2) if @item.is_a?(RPG::Item) return end for i in 0...$game_party.actors.size actor = $game_party.actors[i] if actor.equippable?(@item) self.contents.font.color = normal_color else self.contents.font.color = disabled_color end self.contents.draw_text(4, 64 + 64 * i, 120, 32, actor.name) if @item.is_a?(RPG::Weapon) item1 = $data_weapons[actor.weapon_id] elsif @item.kind == 0 item1 = $data_armors[actor.armor1_id] elsif @item.kind == 1 item1 = $data_armors[actor.armor2_id] elsif @item.kind == 2 item1 = $data_armors[actor.armor3_id] else item1 = $data_armors[actor.armor4_id] end if actor.equippable?(@item) if @item.is_a?(RPG::Weapon) atk1 = item1 != nil ? item1.atk : 0 atk2 = @item != nil ? @item.atk : 0 change = atk2 - atk1 end if @item.is_a?(RPG::Armor) pdef1 = item1 != nil ? item1.pdef : 0 mdef1 = item1 != nil ? item1.mdef : 0 pdef2 = @item != nil ? @item.pdef : 0 mdef2 = @item != nil ? @item.mdef : 0 change = pdef2 - pdef1 + mdef2 - mdef1 end self.contents.draw_text(124, 64 + 64 * i, 112, 32, sprintf("%+d", change), 2) end if item1 != nil x = 4 y = 64 + 64 * i + 32 bitmap = RPG::Cache.icon(item1.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, item1.name) end end end # ------------------------------------ def item=(item) if @item != item @item = item refresh end end end

Properties


Item: The item selected in the window listing the items that can be bought.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: This method initializes the window's contents. First, the x coordinate of the window's upper-left pixel is set to 368, the y coordinate to 128, the width of the window is set to 272, and the height is set to 352. The value of @item is set to the dummy value nil, and the window's contents are drawn using the refresh method. Note that the Scene_Shop object handling this window doesn't make the window visible until the value of @item is something other than nil.

Refresh

Arguments: None
Local Variables:
Item1: The item equipped by each actor. It is used to determine the stat changes from equipping the item selected in the goods window.
Atk1: If the item selected in the goods window is a weapon, then this value is set to the attack power of the weapon the actor currently has equipped.
Atk2: The attack power of the item selected in the goods window. Used to determine the change in attack power from the value of Atk1, above.
Mdef1: If the item selected in the goods window is armor, then this value is set to the magic defense of the armor of the same type the actor currently has equipped.
Mdef2: The magic defense of the item selected in the goods window. Used to determine the change in magic defense from the value of Mdef1, above.
Pdef1: Mdef1: If the item selected in the goods window is armor, then this value is set to the physical defense of the armor of the same type the actor currently has equipped.
Pdef2: The physical defense of the item selected in the goods window. Used to determine the change in physical defense from the value of Pdef1, above.
Number: The number of copies of the item selected in the goods window carried by the party.

How it Works: This method draws the contents of the window. First, the window's contents are cleared. If the value of @item is nil, then the method returns. Next the method needs to determine the number of the item indicated by @item in the party's inventory. The appropriate method from the Game_Party class is called, depending on whether @item represents a RPG::Item, RPG::Weapon, or RPG::Armor. Next, the word "Possessed" is drawn in the system color at x coordinate 4 and y coordinate 0, and the number of items is drawn in the normal color at x coordinate 204, and y coordinate 0. Since the draw_text method call for the number of items has the optional last argument "2", the number will be drawn right-aligned within its bounding box. If @item represents an RPG::Item, then no more needs to be done, and the method returns. Otherwise, the method proceeds with drawing information about whether each character can equip the item, and for the characters that can, the changes in attack power or physical defense. For each actor in the current party, the method first checks to see whether the actor can equip the item selected in the goods window. If the actor can equip the item, then the actor's name is drawn in the normal color at x coordinate 4, and y coordinate equal to 64 plus 64 times the actor's relative position in the party (with the party leader being in position 0). If the actor can't equip the item, then the actor's name is drawn in the disabled color at the same coordinates. If the actor can equip the item, then the changes in attack power or physical/magic defense need to be determined. If the item is a RPG::Weapon, then the attack power of the actor's currently equipped weapon is subtracted from the attack power of the item indicated by @item. If the item is a RPG::Armor, then the armor's kind is determined (0 = Shield, 1 = Helmet, 2 = Armor, 3 = Accessory). Then, the value of the local variable item1 is set to the armor of the same kind the actor currently has equipped. For armor, the change in defense is the sum of the change in the actor's physical and magic defense. Whether the change being shown is a change in attack power or a change in defense power, only the string "x", where x is the value of the local variable change, is drawn at x coordinate 124, and y coordinate 64 plus 64 times the relative position of the actor within the party. Note that the optional final argument "2" is present in this call to draw_text, so the number will be drawn right-aligned within its bounding box. The final part of the method draws the current item of the same type as the item indicated by @item the actor has equipped at x coordinate 4 and y coordinate equal to 96 plus 64 times the relative position of the party (with the party leader being in position 0). Take special note that the icon's opacity is either 128 (if the actor can't equip the item in question) or 255 (if the actor can equip the item in question). You can use this optional "opacity" argument in any bitmap drawing operation.

Item=

Arguments: None
Local Variables: None

How it Works: This method sets the value of the @item instance variable. If the current value of @item is different from the one passed to this method, the value of @item is set to the value passed to this method. Note that this value is not set within this class. Rather, the Scene_Shop object representing the shop calls this method as necessary. The refresh method is then called to update the window's contents to reflect the change. 
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