Home > RGSS Script Reference > Scene_Equip
Scene_Equip
Inherits from: None
Description: This class handles the equip screen and all the windows contained within.
class Scene_Equip
# ------------------------------------
def initialize(actor_index = 0, equip_index = 0)
@actor_index = actor_index
@equip_index = equip_index
end
# ------------------------------------
def main
@actor = $game_party.actors[@actor_index]
@help_window = Window_Help.new
@left_window = Window_EquipLeft.new(@actor)
@right_window = Window_EquipRight.new(@actor)
@item_window1 = Window_EquipItem.new(@actor, 0)
@item_window2 = Window_EquipItem.new(@actor, 1)
@item_window3 = Window_EquipItem.new(@actor, 2)
@item_window4 = Window_EquipItem.new(@actor, 3)
@item_window5 = Window_EquipItem.new(@actor, 4)
@right_window.help_window = @help_window
@item_window1.help_window = @help_window
@item_window2.help_window = @help_window
@item_window3.help_window = @help_window
@item_window4.help_window = @help_window
@item_window5.help_window = @help_window
@right_window.index = @equip_index
refresh
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@left_window.dispose
@right_window.dispose
@item_window1.dispose
@item_window2.dispose
@item_window3.dispose
@item_window4.dispose
@item_window5.dispose
end
# ------------------------------------
def refresh
@item_window1.visible = (@right_window.index == 0)
@item_window2.visible = (@right_window.index == 1)
@item_window3.visible = (@right_window.index == 2)
@item_window4.visible = (@right_window.index == 3)
@item_window5.visible = (@right_window.index == 4)
item1 = @right_window.item
case @right_window.index
when 0
@item_window = @item_window1
when 1
@item_window = @item_window2
when 2
@item_window = @item_window3
when 3
@item_window = @item_window4
when 4
@item_window = @item_window5
end
if @right_window.active
@left_window.set_new_parameters(nil, nil, nil)
end
if @item_window.active
item2 = @item_window.item
@actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)
new_atk = @actor.atk
new_pdef = @actor.pdef
new_mdef = @actor.mdef
@actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
@left_window.set_new_parameters(new_atk, new_pdef, new_mdef)
end
end
# ------------------------------------
def update
@left_window.update
@right_window.update
@item_window.update
refresh
if @right_window.active
update_right
return
end
if @item_window.active
update_item
return
end
end
# ------------------------------------
def update_right
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(2)
return
end
if Input.trigger?(Input::C)
if @actor.equip_fix?(@right_window.index)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
@right_window.active = false
@item_window.active = true
@item_window.index = 0
return
end
if Input.trigger?(Input::R)
$game_system.se_play($data_system.cursor_se)
@actor_index += 1
@actor_index %= $game_party.actors.size
$scene = Scene_Equip.new(@actor_index, @right_window.index)
return
end
if Input.trigger?(Input::L)
$game_system.se_play($data_system.cursor_se)
@actor_index += $game_party.actors.size - 1
@actor_index %= $game_party.actors.size
$scene = Scene_Equip.new(@actor_index, @right_window.index)
return
end
end
# ------------------------------------
def update_item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@right_window.active = true
@item_window.active = false
@item_window.index = -1
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.equip_se)
item = @item_window.item
@actor.equip(@right_window.index, item == nil ? 0 : item.id)
@right_window.active = true
@item_window.active = false
@item_window.index = -1
@right_window.refresh
@item_window.refresh
return
end
end
end
|
Actor_Index: The relative position within the party of the actor whose equip screen is showing.
Equip_Index: The index of the item currently being equipped (0 = Weapon, 1 = Shield, 2 = Helmet, 3 = Armor, 4 = Accessory).
Actor: The absolute ID number of the actor equipping items.
Help_Window: A Window_Help object that shows the item description for the currently selected item.
Left_Window: A Window_EquipLeft object that shows the actor's stats and the stat changes associated with equipping a new item.
Right_Window: A Window_EquipRight object that allows the user to select which slot to change equipment.
Item_Window: The currently active Window_EquipItem object.
Item_Window1: A Window_EquipItem object that shows the available weapons to equip.
Item_Window2: A Window_EquipItem object that shows the available shields to equip.
Item_Window3: A Window_EquipItem object that shows the available helmets to equip.
Item_Window4: A Window_EquipItem object that shows the available armor to equip.
Item_Window5: A Window_EquipItem object that shows the available accessories to equip.
Initialize
Arguments:
Actor_Index: The relative position of the actor to equip. Party leader if not specified.
Equip_Index: The starting position of the right window's cursor. Starts at the top of the menu if not specified.
Local Variables: None
How it Works: This method sets the relative position and the selection cursor for the the right window to the values passed to this method.
Main
Arguments: None
Local Variables: None
How it Works: This is the main method for this class. The first part of the method initializes all the window objects. Note that although there are five Window_EquipItem objects, seemingly at the same position, only one of them will be visible and active at a time. It may seem counterintuitive, so please the group of item_windowX.visible= statements in the Refresh method for a concrete representation of how this works. The next part of the method is the main loop seen in most "Scene" classes. It updates the graphics, watches for input, and updates the window state repeatedly until the value of $Scene is something other than itself, which in this case, means the user has cancelled the equip screen and returned to the main menu. The final part of the method collects the garbage after the player exits the equip screen.
Refresh
Arguments: None
Local Variables:
Item1: The item that would be unequipped if the user pressed Enter based on the item selected in the right window.
Item2: The new item that would be equipped if the user pressed Enter based on the item selected in the item window.
New_Atk: The new attack power value if the actor equipped the currently-selected item.
New_Pdef: The new physical defense power value if the actor equipped the currently-selected item.
New_Mdef: The new magical defense power value if the actor equipped the currently-selected item.
How it Works: This method refreshes the equip screen. THe method first determines which Window_EquipItem window should be visible, based on the value of @right_window.index. It then sets the main @item_window object equal to the currently-visible item window. If the right window is currently active, then the Window_EquipLeft#Set_New_Parameters method will three nil arguments, since no item for which new parameters should be displayed is selected. If the item menu is active, then the method momentarily equips the selected item to grab the actor's new parameters, then immediately unequips it. The user doesn't even notice this happening. The paramters that were grabbed are stored in new_atk, new_pdef, and new_mdef. The Window_EquipLeft#Set_New_Parameters method is then called with these three parameters so that the new stats the actor would have if the actor equipped the currently-selected item will be shown.
Update
Arguments: None
Local Variables: None
How it Works: This method updates all the windows on the equip screen. It first updates and refreshes the left, right, and item windows. Then, depending on the currently-active window, it either called update_right or update_item to respond to user input on those windows.
Update_Right
Arguments: None
Local Variables: None
How it Works: This method responds to user input on the right window. If the user presses the "B" (cancel) key, then the cancel sound effect is played and the value of $Scene reverts to the main menu. If the user presses the "C" (decision) key, then the method checks to see if this equipment slot has the "Lock Equipment" property for this actor. If it does, then it just plays the buzzer sound effect. If not, then the @item_window.active = true statement transfers control to the item window. If the user presses "R", then the value of @actor_index is incremented, then modded by the party size, to ensure that the selection doesn't go past the last actor in the party. Then, a new Scene_Equip object is created with the next actor in the party order as the actor (or the party leader if this was the last actor in the party) and retains the right window index. If the user presses "L", then the value of @actor_index is decremented, then modded by the party size, to ensure that the selection doesn't go past the first actor in the party. Then, a new Scene_Equip object is created with the previous actor in the party order as the actor (or the last member of the party if this was the party leader) and retains the right window index.
Update_Item
Arguments: None
Local Variables: None
How it Works: This method makes the item window respond to user input. If the user presses the "B" (cancel) key, then control is transferred back to the right window. If the user presses the "C" key, then "equip" sound effect is played and the currently highlighted item is equipped, and control is transferred back to the right window. Finally, the windows are refreshed to reflect the change.
|
|