Home > RGSS Script Reference > Scene_Item
Scene_Item
Inherits from: None
Description: This class handles the selection of items from the item menu contained within the main menu. Note that a seperate process handles the item menu that appears when the "Item" battle command is selected.
class Scene_Item
# ------------------------------------
def main
@help_window = Window_Help.new
@item_window = Window_Item.new
@item_window.help_window = @help_window
@target_window = Window_Target.new
@target_window.visible = false
@target_window.active = false
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@item_window.dispose
@target_window.dispose
end
# ------------------------------------
def update
@help_window.update
@item_window.update
@target_window.update
if @item_window.active
update_item
return
end
if @target_window.active
update_target
return
end
end
# ------------------------------------
def update_item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
return
end
if Input.trigger?(Input::C)
@item = @item_window.item
unless @item.is_a?(RPG::Item)
$game_system.se_play($data_system.buzzer_se)
return
end
unless $game_party.item_can_use?(@item.id)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
if @item.scope >= 3
@item_window.active = false
@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
else
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
$scene = Scene_Map.new
return
end
end
return
end
end
# ------------------------------------
def update_target
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
unless $game_party.item_can_use?(@item.id)
@item_window.refresh
end
@item_window.active = true
@target_window.visible = false
@target_window.active = false
return
end
if Input.trigger?(Input::C)
if $game_party.item_number(@item.id) == 0
$game_system.se_play($data_system.buzzer_se)
return
end
if @target_window.index == -1
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
if @target_window.index >= 0
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
if used
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
@target_window.refresh
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$scene = Scene_Map.new
return
end
end
unless used
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
end
|
Help_Window: A Window_Help object for the help menu that shows the description of the currently selected item.
Item_Window: A Window_Item object. This is the main item selection window.
Target_Window: A Window_Target object that is used when a curative item is selected. This window prompts the user to select a target for the curative item.
Item: The item that was selected from the menu. This class then does further processing based on how the item with this ID was defined in the database.
Main
Arguments: None
Local Variables: None
How it Works: This is the main method that initializes the object, processes the update, and disposes of the object. The first part of the method initializes the three windows and makes the target window invisible until it is needed. The main loop updates the graphics, checks for input, and updates the window in response to user input. Once the value of $Scene has changed (when the user leaves the item menu), the final part of the method disposes of the windows.
Update
Arguments: None
Local Variables: None
How it Works: This method updates the contents of the three windows, which updates the user's selection, if any, and updates the item description shown. What the method does next depends on whether the user is currently selecting an item or a target for a curative item. If the user is selecting an item, the update_item method is called to respond to user input on the item menu. If the user is selecting a target, the update_target method is called to respond to user input on that menu.
Update_Item
Arguments: None
Local Variables: None
How it Works: This method responds to the user's input on the main item menu. If the user's input is "B" (cancel key), then the cancel sound effect is played and the scene is changed to the main menu. If the user's input is "C" (decision key), then the value of @item is set to the currently selected item on the item menu. Then, the value of @item is checked to see if it's an RPG::Item. If it isn't, then that means it's a weapon or armor, which isn't usable from the menu by default, so the buzzer sound effect is played and the method returns. Even if the item is an RPG::Item, the party may not be able to use it at this time (maybe it's a story item, for instance), so the method checks to see if the party can use the item. If it can't, then the buzzer sound effect is played and the method returns. If the party can use the item, then the decision sound effect is played and the item's "scope" is checked. If the scope is 3 or greater (usable on allies or self), then the item window transfers control to the target window. The @target_window.x = (@item_window.index + 1) % 2 * 304 statement determines where the target window will appear. If the index of the selected item is odd, then that means selected item is on the right side of the window, so the target window should appear on the left side (at X = 0). Otherwise, the selected item is on the left side of the window and the target window should appear on the right side (at X = 304). If the "scope" of the item being used is 4 (all allies) or 6 (all allies HP 0), then the selection index of the target window is set to -1 (a special index meaning "select all targets"). If only one target is called for, the index is set to 0 (the party leader). If the scope wasn't such that the target window would be activated, then the method checks if a common event is associated with the item. If one is, then $game_temp.common_event_id is loaded with the common event's ID (so that it will be being executing as soon as the party returns to the map) and a copy of the item is deducted if it's consumable. Then the method transfers control back to the map.
Update_Target
Arguments: None
Local Variables:
Used: This flag is set if the item is used (there is at least one legal target).
How it Works: This method responds to user input on the target window. If the user input is "B" (cancel key), then the cancel sound effect is played. Since the user can cancel this menu after having used any number of copies of the item that was being targetted, the method needs to check if the party can still use the item. If it can't, the main item window is updated to reflect this. Control is then transferred back to the main window. If the user input is "C" (decision key), then the method checks to see if the party has run out of the item being targetted. If it has, then the buzzer sound effect plays and nothing else happens. If the target index is -1 (entire party), then the loop contained within applies the item effect to each party member. The local variable used is necessary to keep track of whether the item actually gets used or not. The item may not be used if this is an HP restoration item, but all legal targets are already at their maximum HP values, for instance. Otherwise, the item effect is applied to the specific target and the return value of the Game_Battler#Item_Effect method is stored in used. In the next section, used flag comes into play. If the flag is set, then the menu sound effect is played, and if the item is consumable, then the party loses one copy of the item and the item window is refreshed. If there's a common event associated with the item, then the ID of the common event is loaded into $game_temp.common_event_id and control is transferred back to the map for processing. If the used flag is not set, then the buzzer sound plays, since the target(s) of the item were illegal.
|
|