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

@@ -467,25 +467,16 @@ end
#===============================================================================
#
#===============================================================================
class HallOfFamePC
def shouldShow?
return $PokemonGlobal.hallOfFameLastNumber > 0
end
def name
return _INTL("Hall of Fame")
end
def access
MenuHandlers.add(:pc_menu, :hall_of_fame, {
"name" => _INTL("Hall of Fame"),
"order" => 40,
"condition" => proc { next $PokemonGlobal.hallOfFameLastNumber > 0 },
"effect" => proc { |menu|
pbMessage(_INTL("\\se[PC access]Accessed the Hall of Fame."))
pbHallOfFamePC
end
end
#===============================================================================
#
#===============================================================================
PokemonPCList.registerPC(HallOfFamePC.new)
next false
}
})
#===============================================================================
#

View File

@@ -92,6 +92,8 @@ class PokemonPauseMenu
@scene.pbShowMenu
end
def pbShowInfo; end
def pbStartPokemonMenu
if !$player
if $DEBUG
@@ -101,198 +103,218 @@ class PokemonPauseMenu
return
end
@scene.pbStartScene
endscene = true
# Show extra info window if relevant
pbShowInfo
# Get all commands
command_list = []
commands = []
cmdPokedex = -1
cmdPokemon = -1
cmdBag = -1
cmdTrainer = -1
cmdSave = -1
cmdOption = -1
cmdPokegear = -1
cmdTownMap = -1
cmdDebug = -1
cmdQuit = -1
cmdEndGame = -1
if $player.has_pokedex && $player.pokedex.accessible_dexes.length > 0
commands[cmdPokedex = commands.length] = _INTL("Pokédex")
MenuHandlers.each_available(:pause_menu) do |option, hash, name|
command_list.push(name)
commands.push(hash)
end
commands[cmdPokemon = commands.length] = _INTL("Pokémon") if $player.party_count > 0
commands[cmdBag = commands.length] = _INTL("Bag") if !pbInBugContest?
if $player.has_pokegear
commands[cmdPokegear = commands.length] = _INTL("Pokégear")
elsif $bag.has?(:TOWNMAP)
commands[cmdTownMap = commands.length] = _INTL("Town Map")
end
commands[cmdTrainer = commands.length] = $player.name
if pbInSafari?
if Settings::SAFARI_STEPS <= 0
@scene.pbShowInfo(_INTL("Balls: {1}", pbSafariState.ballcount))
else
@scene.pbShowInfo(_INTL("Steps: {1}/{2}\nBalls: {3}",
pbSafariState.steps, Settings::SAFARI_STEPS, pbSafariState.ballcount))
end
commands[cmdQuit = commands.length] = _INTL("Quit")
elsif pbInBugContest?
if pbBugContestState.lastPokemon
@scene.pbShowInfo(_INTL("Caught: {1}\nLevel: {2}\nBalls: {3}",
pbBugContestState.lastPokemon.speciesName,
pbBugContestState.lastPokemon.level,
pbBugContestState.ballcount))
else
@scene.pbShowInfo(_INTL("Caught: None\nBalls: {1}", pbBugContestState.ballcount))
end
commands[cmdQuit = commands.length] = _INTL("Quit Contest")
elsif $game_system && !$game_system.save_disabled
commands[cmdSave = commands.length] = _INTL("Save")
end
commands[cmdOption = commands.length] = _INTL("Options")
commands[cmdDebug = commands.length] = _INTL("Debug") if $DEBUG
commands[cmdEndGame = commands.length] = _INTL("Quit Game")
# Main loop
end_scene = false
loop do
command = @scene.pbShowCommands(commands)
if cmdPokedex >= 0 && command == cmdPokedex
pbPlayDecisionSE
if Settings::USE_CURRENT_REGION_DEX
pbFadeOutIn {
scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
elsif $player.pokedex.accessible_dexes.length == 1
$PokemonGlobal.pokedexDex = $player.pokedex.accessible_dexes[0]
pbFadeOutIn {
scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
else
pbFadeOutIn {
scene = PokemonPokedexMenu_Scene.new
screen = PokemonPokedexMenuScreen.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
end
elsif cmdPokemon >= 0 && command == cmdPokemon
pbPlayDecisionSE
hiddenmove = nil
pbFadeOutIn {
sscene = PokemonParty_Scene.new
sscreen = PokemonPartyScreen.new(sscene, $player.party)
hiddenmove = sscreen.pbPokemonScreen
(hiddenmove) ? @scene.pbEndScene : @scene.pbRefresh
}
if hiddenmove
$game_temp.in_menu = false
pbUseHiddenMove(hiddenmove[0], hiddenmove[1])
return
end
elsif cmdBag >= 0 && command == cmdBag
pbPlayDecisionSE
item = nil
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, $bag)
item = screen.pbStartScreen
(item) ? @scene.pbEndScene : @scene.pbRefresh
}
if item
$game_temp.in_menu = false
pbUseKeyItemInField(item)
return
end
elsif cmdPokegear >= 0 && command == cmdPokegear
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonPokegear_Scene.new
screen = PokemonPokegearScreen.new(scene)
screen.pbStartScreen
($game_temp.fly_destination) ? @scene.pbEndScene : @scene.pbRefresh
}
return if pbFlyToNewLocation
elsif cmdTownMap >= 0 && command == cmdTownMap
pbFadeOutIn {
scene = PokemonRegionMap_Scene.new(-1, false)
screen = PokemonRegionMapScreen.new(scene)
ret = screen.pbStartScreen
$game_temp.fly_destination = ret if ret
($game_temp.fly_destination) ? @scene.pbEndScene : @scene.pbRefresh
}
return if pbFlyToNewLocation
elsif cmdTrainer >= 0 && command == cmdTrainer
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonTrainerCard_Scene.new
screen = PokemonTrainerCardScreen.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
elsif cmdQuit >= 0 && command == cmdQuit
@scene.pbHideMenu
if pbInSafari?
if pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
@scene.pbEndScene
pbSafariState.decision = 1
pbSafariState.pbGoToStart
return
else
pbShowMenu
end
elsif pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
@scene.pbEndScene
pbBugContestState.pbStartJudging
return
else
pbShowMenu
end
elsif cmdSave >= 0 && command == cmdSave
@scene.pbHideMenu
scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene)
if screen.pbSaveScreen
@scene.pbEndScene
endscene = false
break
else
pbShowMenu
end
elsif cmdOption >= 0 && command == cmdOption
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonOption_Scene.new
screen = PokemonOptionScreen.new(scene)
screen.pbStartScreen
pbUpdateSceneMap
@scene.pbRefresh
}
elsif cmdDebug >= 0 && command == cmdDebug
pbPlayDecisionSE
pbFadeOutIn {
pbDebugMenu
@scene.pbRefresh
}
elsif cmdEndGame >= 0 && command == cmdEndGame
@scene.pbHideMenu
if pbConfirmMessage(_INTL("Are you sure you want to quit the game?"))
scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene)
if screen.pbSaveScreen
@scene.pbEndScene
end
@scene.pbEndScene
$scene = nil
return
else
pbShowMenu
end
else
choice = @scene.pbShowCommands(command_list)
if choice < 0
pbPlayCloseMenuSE
end_scene = true
break
end
break if commands[choice]["effect"].call(@scene)
end
@scene.pbEndScene if endscene
@scene.pbEndScene if end_scene
end
end
#===============================================================================
# Pause menu commands.
#===============================================================================
MenuHandlers.add(:pause_menu, :pokedex, {
"name" => _INTL("Pokédex"),
"order" => 10,
"condition" => proc { next $player.has_pokedex && $player.pokedex.accessible_dexes.length > 0 },
"effect" => proc { |menu|
pbPlayDecisionSE
if Settings::USE_CURRENT_REGION_DEX
pbFadeOutIn {
scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen
menu.pbRefresh
}
elsif $player.pokedex.accessible_dexes.length == 1
$PokemonGlobal.pokedexDex = $player.pokedex.accessible_dexes[0]
pbFadeOutIn {
scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen
menu.pbRefresh
}
else
pbFadeOutIn {
scene = PokemonPokedexMenu_Scene.new
screen = PokemonPokedexMenuScreen.new(scene)
screen.pbStartScreen
menu.pbRefresh
}
end
next false
}
})
MenuHandlers.add(:pause_menu, :party, {
"name" => _INTL("Pokémon"),
"order" => 20,
"condition" => proc { next $player.party_count > 0 },
"effect" => proc { |menu|
pbPlayDecisionSE
hidden_move = nil
pbFadeOutIn {
sscene = PokemonParty_Scene.new
sscreen = PokemonPartyScreen.new(sscene, $player.party)
hidden_move = sscreen.pbPokemonScreen
(hidden_move) ? menu.pbEndScene : menu.pbRefresh
}
next false if !hidden_move
$game_temp.in_menu = false
pbUseHiddenMove(hidden_move[0], hidden_move[1])
next true
}
})
MenuHandlers.add(:pause_menu, :bag, {
"name" => _INTL("Bag"),
"order" => 30,
"condition" => proc { next !pbInBugContest? },
"effect" => proc { |menu|
pbPlayDecisionSE
item = nil
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, $bag)
item = screen.pbStartScreen
(item) ? menu.pbEndScene : menu.pbRefresh
}
next false if !item
$game_temp.in_menu = false
pbUseKeyItemInField(item)
next true
}
})
MenuHandlers.add(:pause_menu, :pokegear, {
"name" => _INTL("Pokégear"),
"order" => 40,
"condition" => proc { next $player.has_pokegear },
"effect" => proc { |menu|
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonPokegear_Scene.new
screen = PokemonPokegearScreen.new(scene)
screen.pbStartScreen
($game_temp.fly_destination) ? menu.pbEndScene : menu.pbRefresh
}
next pbFlyToNewLocation
}
})
MenuHandlers.add(:pause_menu, :town_map, {
"name" => _INTL("Town Map"),
"order" => 40,
"condition" => proc { next !$player.has_pokegear && $bag.has?(:TOWNMAP) },
"effect" => proc { |menu|
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonRegionMap_Scene.new(-1, false)
screen = PokemonRegionMapScreen.new(scene)
ret = screen.pbStartScreen
$game_temp.fly_destination = ret if ret
($game_temp.fly_destination) ? menu.pbEndScene : menu.pbRefresh
}
next pbFlyToNewLocation
}
})
MenuHandlers.add(:pause_menu, :trainer_card, {
"name" => proc { next $player.name },
"order" => 50,
"effect" => proc { |menu|
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonTrainerCard_Scene.new
screen = PokemonTrainerCardScreen.new(scene)
screen.pbStartScreen
menu.pbRefresh
}
next false
}
})
MenuHandlers.add(:pause_menu, :save, {
"name" => _INTL("Save"),
"order" => 60,
"condition" => proc { next $game_system && !$game_system.save_disabled &&
!pbInSafari? && !pbInBugContest? },
"effect" => proc { |menu|
menu.pbHideMenu
scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene)
if screen.pbSaveScreen
menu.pbEndScene
next true
end
menu.pbRefresh
menu.pbShowMenu
next false
}
})
MenuHandlers.add(:pause_menu, :options, {
"name" => _INTL("Options"),
"order" => 70,
"effect" => proc { |menu|
pbPlayDecisionSE
pbFadeOutIn {
scene = PokemonOption_Scene.new
screen = PokemonOptionScreen.new(scene)
screen.pbStartScreen
pbUpdateSceneMap
menu.pbRefresh
}
next false
}
})
MenuHandlers.add(:pause_menu, :debug, {
"name" => _INTL("Debug"),
"order" => 80,
"condition" => proc { next $DEBUG },
"effect" => proc { |menu|
pbPlayDecisionSE
pbFadeOutIn {
pbDebugMenu
menu.pbRefresh
}
next false
}
})
MenuHandlers.add(:pause_menu, :quit_game, {
"name" => _INTL("Quit Game"),
"order" => 90,
"effect" => proc { |menu|
menu.pbHideMenu
if pbConfirmMessage(_INTL("Are you sure you want to quit the game?"))
scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene)
screen.pbSaveScreen
menu.pbEndScene
$scene = nil
next true
end
menu.pbRefresh
menu.pbShowMenu
next false
}
})

View File

@@ -128,43 +128,71 @@ class PokemonPokegearScreen
end
def pbStartScreen
# Get all commands
command_list = []
commands = []
cmdMap = -1
cmdPhone = -1
cmdJukebox = -1
commands[cmdMap = commands.length] = ["map", _INTL("Map")]
if $PokemonGlobal.phoneNumbers && $PokemonGlobal.phoneNumbers.length > 0
commands[cmdPhone = commands.length] = ["phone", _INTL("Phone")]
MenuHandlers.each_available(:pokegear_menu) do |option, hash, name|
command_list.push([hash["icon_name"] || "", name])
commands.push(hash)
end
commands[cmdJukebox = commands.length] = ["jukebox", _INTL("Jukebox")]
@scene.pbStartScene(commands)
@scene.pbStartScene(command_list)
# Main loop
end_scene = false
loop do
cmd = @scene.pbScene
if cmd < 0
choice = @scene.pbScene
if choice < 0
end_scene = true
break
elsif cmdMap >= 0 && cmd == cmdMap
pbFadeOutIn {
scene = PokemonRegionMap_Scene.new(-1, false)
screen = PokemonRegionMapScreen.new(scene)
ret = screen.pbStartScreen
if ret
$game_temp.fly_destination = ret
next 99999 # Ugly hack to make Pokégear scene not reappear if flying
end
}
break if $game_temp.fly_destination
elsif cmdPhone >= 0 && cmd == cmdPhone
pbFadeOutIn {
PokemonPhoneScene.new.start
}
elsif cmdJukebox >= 0 && cmd == cmdJukebox
pbFadeOutIn {
scene = PokemonJukebox_Scene.new
screen = PokemonJukeboxScreen.new(scene)
screen.pbStartScreen
}
end
break if commands[choice]["effect"].call(@scene)
end
($game_temp.fly_destination) ? @scene.dispose : @scene.pbEndScene
@scene.pbEndScene if end_scene
end
end
#===============================================================================
#
#===============================================================================
MenuHandlers.add(:pokegear_menu, :map, {
"name" => _INTL("Map"),
"icon_name" => "map",
"order" => 10,
"effect" => proc { |menu|
pbFadeOutIn {
scene = PokemonRegionMap_Scene.new(-1, false)
screen = PokemonRegionMapScreen.new(scene)
ret = screen.pbStartScreen
if ret
$game_temp.fly_destination = ret
menu.dispose
next 99999
end
}
next $game_temp.fly_destination
}
})
MenuHandlers.add(:pokegear_menu, :phone, {
"name" => _INTL("Phone"),
"icon_name" => "phone",
"order" => 20,
"condition" => proc { next $PokemonGlobal.phoneNumbers && $PokemonGlobal.phoneNumbers.length > 0 },
"effect" => proc { |menu|
pbFadeOutIn { PokemonPhoneScene.new.start }
next false
}
})
MenuHandlers.add(:pokegear_menu, :jukebox, {
"name" => _INTL("Jukebox"),
"icon_name" => "jukebox",
"order" => 30,
"effect" => proc { |menu|
pbFadeOutIn {
scene = PokemonJukebox_Scene.new
screen = PokemonJukeboxScreen.new(scene)
screen.pbStartScreen
}
next false
}
})

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
}
})

View File

@@ -1314,22 +1314,13 @@ end
#===============================================================================
#
#===============================================================================
class PurifyChamberPC
def shouldShow?
return $player.seen_purify_chamber
end
def name
return _INTL("Purify Chamber")
end
def access
MenuHandlers.add(:pc_menu, :purify_chamber, {
"name" => _INTL("Purify Chamber"),
"order" => 30,
"condition" => proc { next $player.seen_purify_chamber },
"effect" => proc { |menu|
pbMessage(_INTL("\\se[PC access]Accessed the Purify Chamber."))
pbPurifyChamber
end
end
#===============================================================================
#
#===============================================================================
PokemonPCList.registerPC(PurifyChamberPC.new)
next false
}
})