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

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Window_ShopNumber

Window_ShopNumber


Inherits from: Window_ShopNumber

Description: This window appears when you select an item to buy or sell in a shop, prompting you to choose the number of that item to buy or sell.

Code


class Window_ShopNumber < Window_Base
# ------------------------------------
 def initialize
    super(0, 128, 368, 352)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item = nil
    @max = 1
    @price = 0
    @number = 1
  end
# ------------------------------------
 def set(item, max, price)
    @item = item
    @max = max
    @price = price
    @number = 1
    refresh
  end 
# ------------------------------------ 
 def number
    return @number
  end
# ------------------------------------
 def refresh
    self.contents.clear
    draw_item_name(@item, 4, 96)
    self.contents.font.color = normal_color
    self.contents.draw_text(272, 96, 32, 32, "x")
    self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
    self.cursor_rect.set(304, 96, 32, 32)
    domination = $data_system.words.gold
    cx = contents.text_size(domination).width
    total_price = @price * @number
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 160, 328-cx-2, 32, total_price.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
end
# ------------------------------------
def update
    super
    if self.active
      if Input.repeat?(Input::RIGHT) and @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number += 1
        refresh
      end
      if Input.repeat?(Input::LEFT) and @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number -= 1
        refresh
      end
      if Input.repeat?(Input::UP) and @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number = [@number + 10, @max].min
        refresh
      end
      if Input.repeat?(Input::DOWN) and @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number = [@number - 10, 1].max
        refresh
      end
    end
  end
end

Properties


Item: The item for which the number to buy or sell is being selected.

Max: The maximum number of items of this type that can be bought or sold. For buying, this is equal to the minimum of 99 minus the number of that item currently carried by the party and the party's gold, divided by the price of the item. For selling, this is equal to the number of copies of that item carried by the party.

Price: The price of the item being bought or sold. Note that when selling an item, this variable will have already been divided by 2 when it is passed to the set method.

Number: The number of copies of the item currently indicated in the window.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: This method initializes the window. The x coordinate of the window's upper-left pixel is set to 0, the y coordinate is set to 128, the width of the window is set to 368, and the height is set to 352. The rest of the method initializes the @item, @max, @price, and @number instance variables to dummy values. These variables will be be set to their proper values when the Scene_Shop object representing the shop calls the set method for this window.

Set

Arguments:
Item: The item for which the number to buy or sell is being selected.
Max: The maximum number of items of this type that can be bought or sold.
Price: The price of the item being bought or sold.
Local Variables: None

How it Works: This method sets the parameters for this window. The values of @item, @max, and @price are set to the values passed to this method, and the @number instance variable is set to 1, since this is the default number of copies to buy or sell when the window first appears.

Number

Arguments: None
Local Variables: None

How it Works: This method returns the number of copies of the item currently indicated in the window.

Refresh

Arguments: None
Local Variables:
Domination: The word for the game's currency, as defined in the System tab of the database. I have no idea why the variable is called "domination". Maybe a programmer has a BDSM fetish?
Total_Price: The total cost of the items being bought or sold.

How it Works: This method draws the contents of the window. The method first clears the window's contents. The item's icon and name are then drawn at x coordinate 4 and y coordinate 96. The font color is changed to the normal color. The letter "x" is then drawn at x coordinate 272 and y coordinate 96. The current value of @number is drawn at x coordinate 308 and y coordinate 96. Note that the optiional argument "2" is used for this instance of the draw_text, meaning the number will be drawn right-justified within its bounding box. The self.cursor_rect.set(304, 96, 32, 32) statement sets the window's cursor rectangle over the number value just drawn. In this case, there isn't any need to make an update_cursor_rect method, since the cursor never moves once it's set. Next, the value of domination is set equal to the name of the game's currency. The value of total_price is set to the total money involved in the transaction. The total price and the the word stored in domination are then drawn side-by-side at x coordinate 4 and y coordinate 160, but both are right-justified, so they will appear near the right side of the window, since the bounding box for the number is most likely going to be over 300 pixels wide. The total price is drawn in the normal color, and the currency word is drawn in the system color.

Update

Arguments: None
Local Variables: None

How it Works: This method updates the window each frame and responds to user input. The call to super performs updating common to all window classes. The rest of this method only does anything if the window is active. If the user has pressed the right arrow key, then the method checks to see if the value of @number is less than the value of @max. If it is, then the cursor sound effect is played, and the value of @number is incremented. If the user has pressed the left arrow key, then the method checks to see if the value of @number is greater than 1. If it is, then the cursor sound effect is played, and the value of @number is decremented. If the user has pressed the up arrow key, then the method checks to see if the value of @number is less than the value of @max. If it is, then the cursor sound effect is played, and the value of @number is increased by 10, but if this would cause the value of @number to be more than the value of @max, then the value of @number becomes equal to @max instead. If the user has pressed the down arrow key, then the method checks to see if the value of @number is greater than 1. If it is, then the cursor sound effect is played, and the value of @number is decreased by 10, but if this would cause the value of @number to go below 1, then the value of @number becomes 1 instead. 
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