Created module MenuHandlers for the contents of various menus

This commit is contained in:
Maruno17
2021-12-31 17:45:07 +00:00
parent 7da449aec3
commit 4cf13f2942
15 changed files with 1073 additions and 1124 deletions

View File

@@ -1,116 +1,6 @@
#===============================================================================
#
#===============================================================================
class TrainerPC
def shouldShow?
return true
end
def name
return _INTL("{1}'s PC", $player.name)
end
def access
pbMessage(_INTL("\\se[PC access]Accessed {1}'s PC.", $player.name))
pbTrainerPCMenu
end
end
#===============================================================================
#
#===============================================================================
class StorageSystemPC
def shouldShow?
return true
end
def name
if $player.seen_storage_creator
return _INTL("{1}'s PC", pbGetStorageCreator)
else
return _INTL("Someone's PC")
end
end
def access
pbMessage(_INTL("\\se[PC access]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)
if command >= 0 && command < 3
case command
when 1 # Withdraw
if $PokemonStorage.party_full?
pbMessage(_INTL("Your party is full!"))
next
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
end
pbFadeOutIn {
scene = PokemonStorageScene.new
screen = PokemonStorageScreen.new(scene, $PokemonStorage)
screen.pbStartScreen(command)
}
else
break
end
end
end
end
#===============================================================================
#
#===============================================================================
module PokemonPCList
@@pclist = []
def self.registerPC(pc)
@@pclist.push(pc)
end
def self.getCommandList
commands = []
@@pclist.each do |pc|
commands.push(pc.name) if pc.shouldShow?
end
commands.push(_INTL("Log Off"))
return commands
end
def self.callCommand(cmd)
return false if cmd < 0 || cmd >= @@pclist.length
i = 0
@@pclist.each do |pc|
next if !pc.shouldShow?
if i == cmd
pc.access
return true
end
i += 1
end
return false
end
end
#===============================================================================
# PC menus
#===============================================================================
def pbPCItemStorage
command = 0
loop do
@@ -162,6 +52,9 @@ def pbPCItemStorage
end
end
#===============================================================================
#
#===============================================================================
def pbPCMailbox
if !$PokemonGlobal.mailbox || $PokemonGlobal.mailbox.length == 0
pbMessage(_INTL("There's no Mail here."))
@@ -211,6 +104,15 @@ def pbPCMailbox
end
end
#===============================================================================
#
#===============================================================================
def pbTrainerPC
pbMessage(_INTL("\\se[PC open]{1} booted up the PC.", $player.name))
pbTrainerPCMenu
pbSEPlay("PC close")
end
def pbTrainerPCMenu
command = 0
loop do
@@ -226,20 +128,27 @@ def pbTrainerPCMenu
end
end
def pbTrainerPC
pbMessage(_INTL("\\se[PC open]{1} booted up the PC.", $player.name))
pbTrainerPCMenu
pbSEPlay("PC close")
end
#===============================================================================
#
#===============================================================================
def pbPokeCenterPC
pbMessage(_INTL("\\se[PC open]{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
commands = PokemonPCList.getCommandList
command = pbMessage(_INTL("Which PC should be accessed?"), commands,
commands.length, nil, command)
break if !PokemonPCList.callCommand(command)
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
@@ -251,5 +160,65 @@ end
#===============================================================================
#
#===============================================================================
PokemonPCList.registerPC(StorageSystemPC.new)
PokemonPCList.registerPC(TrainerPC.new)
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(_INTL("\\se[PC access]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 1 # Withdraw
if $PokemonStorage.party_full?
pbMessage(_INTL("Your party is full!"))
next
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
end
pbFadeOutIn {
scene = PokemonStorageScene.new
screen = PokemonStorageScreen.new(scene, $PokemonStorage)
screen.pbStartScreen(command)
}
end
next false
}
})
MenuHandlers.add(:pc_menu, :player_pc, {
"name" => proc { next _INTL("{1}'s PC", $player.name) },
"order" => 20,
"effect" => proc { |menu|
pbMessage(_INTL("\\se[PC access]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
}
})