Files
infinitefusion-e18/Data/Scripts/016_UI/019_UI_PC.rb
2024-09-13 23:01:40 +01:00

269 lines
9.1 KiB
Ruby

#===============================================================================
#
#===============================================================================
def pbPCItemStorage
command = 0
loop do
command = pbShowCommandsWithHelp(nil,
[_INTL("Withdraw Item"),
_INTL("Deposit Item"),
_INTL("Toss Item"),
_INTL("Exit")],
[_INTL("Take out items from the PC."),
_INTL("Store items in the PC."),
_INTL("Throw away items stored in the PC."),
_INTL("Go back to the previous menu.")], -1, command)
case command
when 0 # Withdraw Item
$PokemonGlobal.pcItemStorage ||= PCItemStorage.new
if $PokemonGlobal.pcItemStorage.empty?
pbMessage(_INTL("There are no items."))
else
pbFadeOutIn do
scene = WithdrawItemScene.new
screen = ItemStorageScreen.new(scene, $bag)
screen.pbWithdrawItemScreen
end
end
when 1 # Deposit Item
$PokemonGlobal.pcItemStorage ||= PCItemStorage.new
item_storage = $PokemonGlobal.pcItemStorage
pbFadeOutIn do
bag_screen = UI::Bag.new($bag, mode: :choose_item)
given_item = bag_screen.choose_item do |item|
item_data = GameData::Item.get(item)
qty = $bag.quantity(item)
if qty > 1 && !item_data.is_important?
qty = bag_screen.choose_number(_INTL("How many do you want to deposit?"), qty)
end
if qty > 0
if item_storage.can_add?(item, qty)
raise "Can't delete items from Bag" if !$bag.remove(item, qty)
raise "Can't deposit items to storage" if !item_storage.add(item, qty)
bag_screen.refresh
disp_qty = (item_data.is_important?) ? 1 : qty
item_name = (disp_qty > 1) ? item_data.portion_name_plural : item_data.portion_name
bag_screen.show_message(_INTL("Deposited {1} {2}.", disp_qty, item_name))
else
bag_screen.show_message(_INTL("There's no room to store items."))
end
end
next false
end
end
when 2 # Toss Item
$PokemonGlobal.pcItemStorage ||= PCItemStorage.new
if $PokemonGlobal.pcItemStorage.empty?
pbMessage(_INTL("There are no items."))
else
pbFadeOutIn do
scene = TossItemScene.new
screen = ItemStorageScreen.new(scene, $bag)
screen.pbTossItemScreen
end
end
else
break
end
end
end
#===============================================================================
#
#===============================================================================
def pbPCMailbox
if !$PokemonGlobal.mailbox || $PokemonGlobal.mailbox.length == 0
pbMessage(_INTL("There's no Mail here."))
else
loop do
command = 0
commands = []
$PokemonGlobal.mailbox.each do |mail|
commands.push(mail.sender)
end
commands.push(_INTL("Cancel"))
command = pbShowCommands(nil, commands, -1, command)
if command >= 0 && command < $PokemonGlobal.mailbox.length
mail_index = command
commandMail = pbMessage(
_INTL("What do you want to do with {1}'s Mail?", $PokemonGlobal.mailbox[mail_index].sender),
[_INTL("Read"),
_INTL("Move to Bag"),
_INTL("Give"),
_INTL("Cancel")], -1
)
case commandMail
when 0 # Read
pbFadeOutIn do
pbDisplayMail($PokemonGlobal.mailbox[mail_index])
end
when 1 # Move to Bag
if pbConfirmMessage(_INTL("The message will be lost. Is that OK?"))
if $bag.add($PokemonGlobal.mailbox[mail_index].item)
pbMessage(_INTL("The Mail was returned to the Bag with its message erased."))
$PokemonGlobal.mailbox.delete_at(mail_index)
else
pbMessage(_INTL("The Bag is full."))
end
end
when 2 # Give
pbFadeOutIn do
screen = UI::Party.new($player.party, mode: :choose_pokemon)
screen.choose_pokemon do |pkmn, party_index|
next true if party_index < 0
if pkmn.egg?
screen.show_message(_INTL("Eggs can't hold mail."))
elsif pkmn.hasItem? || pkmn.mail
screen.show_message(_INTL("This Pokémon is holding an item. It can't hold mail."))
else
pkmn.mail = $PokemonGlobal.mailbox[mail_index]
pkmn.item = pkmn.mail.item
$PokemonGlobal.mailbox.delete_at(mail_index)
screen.refresh
screen.show_message(_INTL("Mail was transferred from the Mailbox."))
next true
end
next false
end
end
end
else
break
end
end
end
end
#===============================================================================
#
#===============================================================================
def pbTrainerPC
pbMessage("\\se[PC open]" + _INTL("{1} booted up the PC.", $player.name))
pbTrainerPCMenu
pbSEPlay("PC close")
end
def pbTrainerPCMenu
command = 0
loop do
command = pbMessage(_INTL("What do you want to do?"),
[_INTL("Item Storage"),
_INTL("Mailbox"),
_INTL("Turn Off")], -1, nil, command)
case command
when 0 then pbPCItemStorage
when 1 then pbPCMailbox
else break
end
end
end
#===============================================================================
#
#===============================================================================
def pbPokeCenterPC
pbMessage("\\se[PC open]" + _INTL("{1} booted up the PC.", $player.name))
# Get all commands
command_list = []
commands = []
MenuHandlers.each_available(:pc_menu) do |option, hash, name|
command_list.push(name)
commands.push(hash)
end
# Main loop
command = 0
loop do
choice = pbMessage(_INTL("Which PC should be accessed?"), command_list, -1, nil, command)
if choice < 0
pbPlayCloseMenuSE
break
end
break if commands[choice]["effect"].call
end
pbSEPlay("PC close")
end
def pbGetStorageCreator
return GameData::Metadata.get.storage_creator
end
#===============================================================================
#
#===============================================================================
MenuHandlers.add(:pc_menu, :pokemon_storage, {
"name" => proc {
next ($player.seen_storage_creator) ? _INTL("{1}'s PC", pbGetStorageCreator) : _INTL("Someone's PC")
},
"order" => 10,
"effect" => proc { |menu|
pbMessage("\\se[PC access]" + _INTL("The Pokémon Storage System was opened."))
command = 0
loop do
command = pbShowCommandsWithHelp(nil,
[_INTL("Organize Boxes"),
_INTL("Withdraw Pokémon"),
_INTL("Deposit Pokémon"),
_INTL("See ya!")],
[_INTL("Organize the Pokémon in Boxes and in your party."),
_INTL("Move Pokémon stored in Boxes to your party."),
_INTL("Store Pokémon in your party in Boxes."),
_INTL("Return to the previous menu.")], -1, command)
break if command < 0
case command
when 0 # Organize
pbFadeOutIn do
scene = PokemonStorageScene.new
screen = PokemonStorageScreen.new(scene, $PokemonStorage)
screen.pbStartScreen(0)
end
when 1 # Withdraw
if $PokemonStorage.party_full?
pbMessage(_INTL("Your party is full!"))
next
end
pbFadeOutIn do
scene = PokemonStorageScene.new
screen = PokemonStorageScreen.new(scene, $PokemonStorage)
screen.pbStartScreen(1)
end
when 2 # Deposit
count = 0
$PokemonStorage.party.each do |p|
count += 1 if p && !p.egg? && p.hp > 0
end
if count <= 1
pbMessage(_INTL("Can't deposit the last Pokémon!"))
next
end
pbFadeOutIn do
scene = PokemonStorageScene.new
screen = PokemonStorageScreen.new(scene, $PokemonStorage)
screen.pbStartScreen(2)
end
else
break
end
end
next false
}
})
MenuHandlers.add(:pc_menu, :player_pc, {
"name" => proc { next _INTL("{1}'s PC", $player.name) },
"order" => 20,
"effect" => proc { |menu|
pbMessage("\\se[PC access]" + _INTL("Accessed {1}'s PC.", $player.name))
pbTrainerPCMenu
next false
}
})
MenuHandlers.add(:pc_menu, :close, {
"name" => _INTL("Log off"),
"order" => 100,
"effect" => proc { |menu|
next true
}
})