Fixed and implemented new pause menu and Trainer Card scripts

This commit is contained in:
Maruno17
2024-08-22 22:26:57 +01:00
parent f4358e1542
commit 2c6fe70f0c
11 changed files with 587 additions and 430 deletions

View File

@@ -103,9 +103,7 @@ class Scene_Map
$game_temp.in_menu = true $game_temp.in_menu = true
$game_player.straighten $game_player.straighten
$game_map.update $game_map.update
sscene = PokemonPauseMenu_Scene.new UI::PauseMenu.new
sscreen = PokemonPauseMenu.new(sscene)
sscreen.pbStartPokemonMenu
$game_temp.in_menu = false $game_temp.in_menu = false
end end

View File

@@ -3,19 +3,117 @@
# This bitmap can't be changed to a different one. # This bitmap can't be changed to a different one.
#=============================================================================== #===============================================================================
class BitmapSprite < Sprite class BitmapSprite < Sprite
attr_reader :text_themes
def initialize(width, height, viewport = nil) def initialize(width, height, viewport = nil)
super(viewport) super(viewport)
self.bitmap = Bitmap.new(width, height) self.bitmap = Bitmap.new(width, height)
@text_themes = {}
@initialized = true @initialized = true
end end
def dispose
self.bitmap.dispose if !self.disposed?
super
end
def bitmap=(value) def bitmap=(value)
super(value) if !@initialized super(value) if !@initialized
end end
def dispose #-----------------------------------------------------------------------------
self.bitmap.dispose if !self.disposed?
super def add_text_theme(id, base_color, shadow_color = nil)
@text_themes[id] = [base_color, shadow_color]
end
# TODO: Replaces def pbDrawTextPositions.
def draw_themed_text(string, text_x, text_y, align = :left, theme = :default, outline = :shadow)
string_size = self.bitmap.text_size(string)
case align
when :right
text_x -= string_size.width
when :center
text_x -= (string_size.width / 2)
end
if !@text_themes[theme]
theme = (@text_themes[:default]) ? :default : @text_themes.keys.first
end
case outline || :shadow
when :shadow
draw_shadowed_text(string, text_x, text_y, theme)
when :outline
draw_outlined_text(string, text_x, text_y, theme)
when :none
draw_plain_text(string, text_x, text_y, theme)
end
end
# TODO: Replaces def pbDrawShadowText.
def draw_shadowed_text(string, text_x, text_y, theme)
return if !@text_themes[theme]
base_color, shadow_color = @text_themes[theme]
string_size = self.bitmap.text_size(string)
string_width = string_size.width + 1
string_height = string_size.height + 1
if shadow_color && shadow_color.alpha > 0
self.bitmap.font.color = shadow_color
self.bitmap.draw_text(text_x + 2, text_y, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x, text_y + 2, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x + 2, text_y + 2, string_width, string_height, string, 0)
end
if base_color && base_color.alpha > 0
self.bitmap.font.color = base_color
self.bitmap.draw_text(text_x, text_y, string_width, string_height, string, 0)
end
end
# TODO: Replaces def pbDrawOutlineText.
def draw_outlined_text(string, text_x, text_y, theme)
return if !@text_themes[theme]
base_color, shadow_color = @text_themes[theme]
string_size = self.bitmap.text_size(string)
string_width = string_size.width + 1
string_height = string_size.height + 1
if shadow_color && shadow_color.alpha > 0
self.bitmap.font.color = shadow_color
self.bitmap.draw_text(text_x - 2, text_y - 2, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x, text_y - 2, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x + 2, text_y - 2, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x - 2, text_y, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x + 2, text_y, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x - 2, text_y + 2, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x, text_y + 2, string_width, string_height, string, 0)
self.bitmap.draw_text(text_x + 2, text_y + 2, string_width, string_height, string, 0)
end
if base_color && base_color.alpha > 0
self.bitmap.font.color = base_color
self.bitmap.draw_text(text_x, text_y, string_width, string_height, string, 0)
end
end
# TODO: Replaces def pbDrawPlainText.
def draw_plain_text(string, text_x, text_y, theme)
return if !@text_themes[theme]
base_color = @text_themes[theme][0]
return if !base_color || base_color.alpha == 0
string_size = self.bitmap.text_size(string)
string_width = string_size.width + 1
string_height = string_size.height + 1
self.bitmap.font.color = base_color
self.bitmap.draw_text(text_x, text_y, string_width, string_height, string, 0)
end
#-----------------------------------------------------------------------------
# TODO: Replaces def pbDrawImagePositions.
def draw_image(filename, image_x, image_y, src_x = 0, src_y = 0, src_width = -1, src_height = -1)
src_bitmap = AnimatedBitmap.new(pbBitmapName(filename))
src_width = (src_width >= 0) ? src_width : src_bitmap.width
src_height = (src_height >= 0) ? src_height : src_bitmap.height
src_rect = Rect.new(src_x, src_y, src_width, src_height)
self.bitmap.blt(image_x, image_y, src_bitmap.bitmap, src_rect)
src_bitmap.dispose
end end
end end

View File

@@ -2,11 +2,13 @@ module UI
#============================================================================= #=============================================================================
# The visuals class. # The visuals class.
#============================================================================= #=============================================================================
class BaseUIVisuals class BaseVisuals
GRAPHICS_FOLDER = "Graphics/UI/" UI_FOLDER = "Graphics/UI/"
BACKGROUND_FILENAME = "bg" @@graphics_folder = "" # Subfolder in UI_FOLDER
BLACK_TEXT_COLOR = Color.new(72, 72, 72) @@background_filename = "bg"
BLACK_TEXT_SHADOW_COLOR = Color.new(160, 160, 160) @@text_colors = { # These color themes are added to @sprites[:overlay]
:default => [Color.new(72, 72, 72), Color.new(160, 160, 160)] # Base and shadow colour
}
def initialize def initialize
@bitmaps = {} @bitmaps = {}
@@ -29,17 +31,18 @@ module UI
end end
def initialize_background def initialize_background
addBackgroundPlane(@sprites, :background, GRAPHICS_FOLDER + background_filename, @viewport) addBackgroundPlane(@sprites, :background, @@graphics_folder + background_filename, @viewport)
@sprites[:background].z = -1000 @sprites[:background].z = -1000
end end
def background_filename def background_filename
return gendered_filename(BACKGROUND_FILENAME) return gendered_filename(@@background_filename)
end end
def initialize_overlay def initialize_overlay
@sprites[:overlay] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport) @sprites[:overlay] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
@sprites[:overlay].z = 1000 @sprites[:overlay].z = 1000
@@text_colors.each_pair { |key, values| @sprites[:overlay].add_text_theme(key, *values) }
pbSetSystemFont(@sprites[:overlay].bitmap) pbSetSystemFont(@sprites[:overlay].bitmap)
end end
@@ -49,7 +52,7 @@ module UI
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
def add_icon_sprite(key, x, y, filename = nil) def add_icon_sprite(key, x, y, filename = nil)
@sprites[key] = IconSprite.new(x, y, :viewport) @sprites[key] = IconSprite.new(x, y, @viewport)
@sprites[key].setBitmap(filename) if filename @sprites[key].setBitmap(filename) if filename
end end
@@ -73,6 +76,10 @@ module UI
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
def graphics_folder
return UI_FOLDER + @@graphics_folder
end
def gendered_filename(base_filename) def gendered_filename(base_filename)
return filename_with_appendix(base_filename, "_f") if $player.female? return filename_with_appendix(base_filename, "_f") if $player.female?
return base_filename return base_filename
@@ -81,7 +88,7 @@ module UI
def filename_with_appendix(base_filename, appendix) def filename_with_appendix(base_filename, appendix)
if appendix && appendix != "" if appendix && appendix != ""
trial_filename = base_filename + appendix trial_filename = base_filename + appendix
return trial_filename if pbResolveBitmap(GRAPHICS_FOLDER + trial_filename) return trial_filename if pbResolveBitmap(graphics_folder + trial_filename)
end end
return base_filename return base_filename
end end
@@ -102,13 +109,23 @@ module UI
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
def draw_text(string, text_x, text_y, align: :left, theme: :default, outline: :shadow, overlay: :overlay)
@sprites[overlay].draw_themed_text(string, text_x, text_y, align, theme, outline)
end
def draw_image(filename, image_x, image_y, src_x = 0, src_y = 0, src_width = -1, src_height = -1, overlay: :overlay)
@sprites[overlay].draw_image(filename, image_x, image_y, src_x, src_y, src_width, src_height)
end
#---------------------------------------------------------------------------
# Redraw everything on the screen. # Redraw everything on the screen.
def refresh def refresh
refresh_overlay refresh_overlay
end end
def refresh_overlay def refresh_overlay
@sprites[:overlay].bitmap.clear @sprites[:overlay].bitmap.clear if @sprites[:overlay]
end end
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
@@ -146,14 +163,15 @@ module UI
#============================================================================= #=============================================================================
# The logic class. # The logic class.
#============================================================================= #=============================================================================
class BaseUIScreen class BaseScreen
def initialize def initialize
@disposed = false
initialize_visuals initialize_visuals
main main
end end
def initialize_visuals def initialize_visuals
@visuals = UI::BaseUIVisuals.new @visuals = UI::BaseVisuals.new
end end
def start_screen def start_screen
@@ -161,8 +179,17 @@ module UI
end end
def end_screen def end_screen
return if @disposed
@visuals.fade_out @visuals.fade_out
@visuals.dispose @visuals.dispose
@disposed = true
end
# Same as def end_screen but without fading out.
def silent_end_screen
return if @disposed
@visuals.dispose
@disposed = true
end end
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
@@ -181,6 +208,10 @@ module UI
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
def refresh
@visuals.refresh
end
def main def main
start_screen start_screen
loop do loop do

View File

@@ -1,140 +0,0 @@
# TODO: This code is incomplete, in that all the MenuHandlers for the pause menu
# assume the visuals class has def pbRefresh, def pbEndScene, def
# pbHideMenu and def pbShowMenu.
#===============================================================================
#
#===============================================================================
class UI::PauseMenuVisuals < UI::BaseUIVisuals
def initialize
@info_state = false
# @help_state = false
super
end
def initialize_background; end
def initialize_overlay; end
def initialize_sprites
# Pause menu
@sprites[:commands] = Window_CommandPokemon.new([])
@sprites[:commands].visible = false
@sprites[:commands].viewport = @viewport
# Info text box
@sprites[:info_text] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
@sprites[:info_text].visible = false
# Help text box
# @sprites[:help_text] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
# @sprites[:help_text].visible = false
end
#-----------------------------------------------------------------------------
# commands is [[command IDs], [command names]].
def set_commands(commands)
@commands = commands
cmd_window = @sprites[:commands]
cmd_window = @commands[1]
cmd_window.index = $game_temp.menu_last_choice
cmd_window.resizeToFit(@commands)
cmd_window.x = Graphics.width - cmd_window.width
cmd_window.y = 0
cmd_window.visible = true
end
#-----------------------------------------------------------------------------
def show_menu
@sprites[:commands].visible = true
@sprites[:info_text].visible = @info_state
# @sprites[:help_text].visible = @help_state
end
def hide_menu
@sprites[:commands].visible = false
@sprites[:info_text].visible = false
# @sprites[:help_text].visible = false
end
# Used in Safari Zone and Bug-Catching Contest to show extra information.
def show_info(text)
@sprites[:info_text].resizeToFit(text, Graphics.height)
@sprites[:info_text].text = text
@sprites[:info_text].visible = true
@info_state = true
end
# Unused.
# def show_help(text)
# @sprites[:help_text].resizeToFit(text, Graphics.height)
# @sprites[:help_text].text = text
# @sprites[:help_text].visible = true
# pbBottomLeft(@sprites[:help_text])
# @help_state = true
# end
#-----------------------------------------------------------------------------
def update_visuals
pbUpdateSceneMap
super
end
def update_input
if Input.trigger?(Input::BACK) || Input.trigger?(Input::ACTION)
return :quit
end
if Input.trigger?(Input::USE)
idx = @sprites[:commands].index
return @commands[0][idx]
end
return nil
end
end
#===============================================================================
#
#===============================================================================
class UI::PauseMenuScreen < UI::BaseUIScreen
def initialize
raise _INTL("Tried to open the pause menu when $player was not defined.") if !$player
initialize_commands
super
end
def initialize_commands
@commands ||= [[], []]
@commands.clear
@commands_hashes ||= {}
@commands_hashes.clear
MenuHandlers.each_available(:pause_menu) do |option, hash, name|
@commands[0].push(option)
@commands[1].push(name)
@commands_hashes[option] = hash
end
end
def initialize_visuals
@visuals = UI::PauseMenuVisuals.new
@visuals.set_commands(@commands)
end
def start_screen
pbSEPlay("GUI menu open")
end
def end_screen
pbPlayCloseMenuSE if !@silent_quit
@visuals.dispose
end
#-----------------------------------------------------------------------------
def perform_action(command)
if @commands_hashes[command]["effect"].call(@visuals)
@silent_quit = true
return :quit
end
return nil
end
end

View File

@@ -1,129 +1,159 @@
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
class PokemonPauseMenu_Scene class UI::PauseMenuVisuals < UI::BaseVisuals
def pbStartScene def initialize
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height) @info_text_visible = false
@viewport.z = 99999 # @help_text_visible = false
@sprites = {} super
@sprites["cmdwindow"] = Window_CommandPokemon.new([])
@sprites["cmdwindow"].visible = false
@sprites["cmdwindow"].viewport = @viewport
@sprites["infowindow"] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
@sprites["infowindow"].visible = false
@sprites["helpwindow"] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
@sprites["helpwindow"].visible = false
@infostate = false
@helpstate = false
pbSEPlay("GUI menu open")
end end
def pbShowInfo(text) def initialize_background; end
@sprites["infowindow"].resizeToFit(text, Graphics.height) def initialize_overlay; end
@sprites["infowindow"].text = text
@sprites["infowindow"].visible = true def initialize_sprites
@infostate = true # Pause menu
@sprites[:commands] = Window_CommandPokemon.new([])
@sprites[:commands].visible = false
@sprites[:commands].viewport = @viewport
# Info text box
@sprites[:info_text] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
@sprites[:info_text].visible = false
# Help text box
# @sprites[:help_text] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
# @sprites[:help_text].visible = false
end end
def pbShowHelp(text) #-----------------------------------------------------------------------------
@sprites["helpwindow"].resizeToFit(text, Graphics.height)
@sprites["helpwindow"].text = text # commands is [[command IDs], [command names]].
@sprites["helpwindow"].visible = true def set_commands(commands)
pbBottomLeft(@sprites["helpwindow"]) @commands = commands
@helpstate = true cmd_window = @sprites[:commands]
cmd_window.commands = @commands[1]
cmd_window.index = $game_temp.menu_last_choice
cmd_window.resizeToFit(@commands[1])
cmd_window.x = Graphics.width - cmd_window.width
cmd_window.y = 0
cmd_window.visible = true
end end
def pbShowMenu #-----------------------------------------------------------------------------
@sprites["cmdwindow"].visible = true
@sprites["infowindow"].visible = @infostate def show_menu
@sprites["helpwindow"].visible = @helpstate @sprites[:commands].visible = true
@sprites[:info_text].visible = @info_text_visible
# @sprites[:help_text].visible = @help_text_visible
end end
def pbHideMenu def hide_menu
@sprites["cmdwindow"].visible = false @sprites[:commands].visible = false
@sprites["infowindow"].visible = false @sprites[:info_text].visible = false
@sprites["helpwindow"].visible = false # @sprites[:help_text].visible = false
end end
def pbShowCommands(commands) # Used in Safari Zone and Bug-Catching Contest to show extra information.
ret = -1 def show_info(text)
cmdwindow = @sprites["cmdwindow"] @sprites[:info_text].resizeToFit(text, Graphics.height)
cmdwindow.commands = commands @sprites[:info_text].text = text
cmdwindow.index = $game_temp.menu_last_choice @sprites[:info_text].visible = true
cmdwindow.resizeToFit(commands) @info_text_visible = true
cmdwindow.x = Graphics.width - cmdwindow.width end
cmdwindow.y = 0
cmdwindow.visible = true # Unused.
loop do # def show_help(text)
cmdwindow.update # @sprites[:help_text].resizeToFit(text, Graphics.height)
Graphics.update # @sprites[:help_text].text = text
Input.update # @sprites[:help_text].visible = true
pbUpdateSceneMap # pbBottomLeft(@sprites[:help_text])
if Input.trigger?(Input::BACK) || Input.trigger?(Input::ACTION) # @help_text_visible = true
ret = -1 # end
break
elsif Input.trigger?(Input::USE) #-----------------------------------------------------------------------------
ret = cmdwindow.index
$game_temp.menu_last_choice = ret def update_visuals
break pbUpdateSceneMap
end super
end
def update_input
if Input.trigger?(Input::BACK) || Input.trigger?(Input::ACTION)
return :quit
end end
return ret if Input.trigger?(Input::USE)
idx = @sprites[:commands].index
$game_temp.menu_last_choice = idx
return @commands[0][idx]
end
return nil
end end
def pbEndScene
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
def pbRefresh; end
end end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
class PokemonPauseMenu class UI::PauseMenu < UI::BaseScreen
def initialize(scene) def initialize
@scene = scene raise _INTL("Tried to open the pause menu when $player was not defined.") if !$player
initialize_commands
super
end end
def pbShowMenu def initialize_commands
@scene.pbRefresh @commands ||= [[], []]
@scene.pbShowMenu @commands[0].clear
end @commands[1].clear
@commands_hashes ||= {}
def pbShowInfo; end @commands_hashes.clear
def pbStartPokemonMenu
if !$player
if $DEBUG
pbMessage(_INTL("The player trainer was not defined, so the pause menu can't be displayed."))
pbMessage(_INTL("Please see the documentation to learn how to set up the trainer player."))
end
return
end
@scene.pbStartScene
# Show extra info window if relevant
pbShowInfo
# Get all commands
command_list = []
commands = []
MenuHandlers.each_available(:pause_menu) do |option, hash, name| MenuHandlers.each_available(:pause_menu) do |option, hash, name|
command_list.push(name) @commands[0].push(option)
commands.push(hash) @commands[1].push(name)
@commands_hashes[option] = hash
end end
# Main loop end
end_scene = false
loop do def initialize_visuals
choice = @scene.pbShowCommands(command_list) @visuals = UI::PauseMenuVisuals.new
if choice < 0 @visuals.set_commands(@commands)
pbPlayCloseMenuSE show_info
end_scene = true end
break
end def hide_menu
break if commands[choice]["effect"].call(@scene) @visuals.hide_menu
end
def show_menu
@visuals.show_menu
end
def show_info; end
def start_screen
pbSEPlay("GUI menu open")
end
def end_screen
return if @disposed
pbPlayCloseMenuSE
silent_end_screen
end
#-----------------------------------------------------------------------------
def refresh
initialize_commands
@visuals.set_commands(@commands)
super
end
def perform_action(command)
if @commands_hashes[command]["effect"].call(self)
# NOTE: Calling end_screen will have been done in the "effect" proc, so
# there's no need to do anything special here to mark that this
# screen has already been closed/disposed of.
return :quit
end end
@scene.pbEndScene if end_scene return nil
end end
end end
@@ -142,7 +172,7 @@ MenuHandlers.add(:pause_menu, :pokedex, {
scene = PokemonPokedex_Scene.new scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene) screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen screen.pbStartScreen
menu.pbRefresh menu.refresh
end end
elsif $player.pokedex.accessible_dexes.length == 1 elsif $player.pokedex.accessible_dexes.length == 1
$PokemonGlobal.pokedexDex = $player.pokedex.accessible_dexes[0] $PokemonGlobal.pokedexDex = $player.pokedex.accessible_dexes[0]
@@ -150,14 +180,14 @@ MenuHandlers.add(:pause_menu, :pokedex, {
scene = PokemonPokedex_Scene.new scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene) screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen screen.pbStartScreen
menu.pbRefresh menu.refresh
end end
else else
pbFadeOutIn do pbFadeOutIn do
scene = PokemonPokedexMenu_Scene.new scene = PokemonPokedexMenu_Scene.new
screen = PokemonPokedexMenuScreen.new(scene) screen = PokemonPokedexMenuScreen.new(scene)
screen.pbStartScreen screen.pbStartScreen
menu.pbRefresh menu.refresh
end end
end end
next false next false
@@ -175,7 +205,7 @@ MenuHandlers.add(:pause_menu, :party, {
sscene = PokemonParty_Scene.new sscene = PokemonParty_Scene.new
sscreen = PokemonPartyScreen.new(sscene, $player.party) sscreen = PokemonPartyScreen.new(sscene, $player.party)
hidden_move = sscreen.pbPokemonScreen hidden_move = sscreen.pbPokemonScreen
(hidden_move) ? menu.pbEndScene : menu.pbRefresh (hidden_move) ? menu.silent_end_screen : menu.refresh
end end
next false if !hidden_move next false if !hidden_move
$game_temp.in_menu = false $game_temp.in_menu = false
@@ -195,7 +225,7 @@ MenuHandlers.add(:pause_menu, :bag, {
scene = PokemonBag_Scene.new scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, $bag) screen = PokemonBagScreen.new(scene, $bag)
item = screen.pbStartScreen item = screen.pbStartScreen
(item) ? menu.pbEndScene : menu.pbRefresh (item) ? menu.silent_end_screen : menu.refresh
end end
next false if !item next false if !item
$game_temp.in_menu = false $game_temp.in_menu = false
@@ -214,7 +244,7 @@ MenuHandlers.add(:pause_menu, :pokegear, {
scene = PokemonPokegear_Scene.new scene = PokemonPokegear_Scene.new
screen = PokemonPokegearScreen.new(scene) screen = PokemonPokegearScreen.new(scene)
screen.pbStartScreen screen.pbStartScreen
($game_temp.fly_destination) ? menu.pbEndScene : menu.pbRefresh ($game_temp.fly_destination) ? menu.silent_end_screen : menu.refresh
end end
next pbFlyToNewLocation next pbFlyToNewLocation
} }
@@ -231,7 +261,7 @@ MenuHandlers.add(:pause_menu, :town_map, {
screen = PokemonRegionMapScreen.new(scene) screen = PokemonRegionMapScreen.new(scene)
ret = screen.pbStartScreen ret = screen.pbStartScreen
$game_temp.fly_destination = ret if ret $game_temp.fly_destination = ret if ret
($game_temp.fly_destination) ? menu.pbEndScene : menu.pbRefresh ($game_temp.fly_destination) ? menu.silent_end_screen : menu.refresh
end end
next pbFlyToNewLocation next pbFlyToNewLocation
} }
@@ -243,10 +273,8 @@ MenuHandlers.add(:pause_menu, :trainer_card, {
"effect" => proc { |menu| "effect" => proc { |menu|
pbPlayDecisionSE pbPlayDecisionSE
pbFadeOutIn do pbFadeOutIn do
scene = PokemonTrainerCard_Scene.new UI::TrainerCard.new
screen = PokemonTrainerCardScreen.new(scene) menu.refresh
screen.pbStartScreen
menu.pbRefresh
end end
next false next false
} }
@@ -259,15 +287,15 @@ MenuHandlers.add(:pause_menu, :save, {
next $game_system && !$game_system.save_disabled && !pbInSafari? && !pbInBugContest? next $game_system && !$game_system.save_disabled && !pbInSafari? && !pbInBugContest?
}, },
"effect" => proc { |menu| "effect" => proc { |menu|
menu.pbHideMenu menu.hide_menu
scene = PokemonSave_Scene.new scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene) screen = PokemonSaveScreen.new(scene)
if screen.pbSaveScreen if screen.pbSaveScreen
menu.pbEndScene menu.silent_end_screen
next true next true
end end
menu.pbRefresh menu.refresh
menu.pbShowMenu menu.show_menu
next false next false
} }
}) })
@@ -282,7 +310,7 @@ MenuHandlers.add(:pause_menu, :options, {
screen = PokemonOptionScreen.new(scene) screen = PokemonOptionScreen.new(scene)
screen.pbStartScreen screen.pbStartScreen
pbUpdateSceneMap pbUpdateSceneMap
menu.pbRefresh menu.refresh
end end
next false next false
} }
@@ -296,7 +324,7 @@ MenuHandlers.add(:pause_menu, :debug, {
pbPlayDecisionSE pbPlayDecisionSE
pbFadeOutIn do pbFadeOutIn do
pbDebugMenu pbDebugMenu
menu.pbRefresh menu.refresh
end end
next false next false
} }
@@ -306,17 +334,17 @@ MenuHandlers.add(:pause_menu, :quit_game, {
"name" => _INTL("Quit Game"), "name" => _INTL("Quit Game"),
"order" => 90, "order" => 90,
"effect" => proc { |menu| "effect" => proc { |menu|
menu.pbHideMenu menu.hide_menu
if pbConfirmMessage(_INTL("Are you sure you want to quit the game?")) if pbConfirmMessage(_INTL("Are you sure you want to quit the game?"))
scene = PokemonSave_Scene.new scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene) screen = PokemonSaveScreen.new(scene)
screen.pbSaveScreen screen.pbSaveScreen
menu.pbEndScene menu.silent_end_screen
$scene = nil $scene = nil
next true next true
end end
menu.pbRefresh menu.refresh
menu.pbShowMenu menu.show_info
next false next false
} }
}) })

View File

@@ -1,126 +0,0 @@
#===============================================================================
#
#===============================================================================
class UI::TrainerCardVisuals < UI::BaseUIVisuals
GRAPHICS_FOLDER = "Graphics/UI/Trainer Card/"
BADGE_SIZE = [32, 32] # [width, height] of a Gym Badge
BADGE_SPACING = 16 # Size of gap between adjacent Gym Badges
FIRST_BADGE_X = 72 # Left edge of the first Gym Badge
FIRST_BADGE_Y = 310 # Top edge of the first Gym Badge
BADGE_COUNT = 8 # Number of Gym Badges to show
def initialize_sprites
# Trainer card
add_icon_sprite(:card, 0, 0, GRAPHICS_FOLDER + gendered_filename(_INTL("trainer_card")))
# Player sprite (coordinates are the bottom middle of the sprite)
add_icon_sprite(:player, 400, 240, GameData::TrainerType.player_front_sprite_filename($player.trainer_type))
if !@sprites[:player].bitmap
raise _INTL("No trainer front sprite exists for the player character, expected a file at {1}.",
"Graphics/Trainers/" + $player.trainer_type.to_s + ".png")
end
@sprites[:player].x -= @sprites[:player].bitmap.width / 2
@sprites[:player].y -= @sprites[:player].bitmap.height
@sprites[:player].z = 10
end
#-----------------------------------------------------------------------------
def refresh_overlay
super
overlay = @sprites[:overlay].bitmap
draw_ID(overlay)
draw_stats(overlay)
draw_badges(overlay)
end
# Draws the player's name and ID number onto the overlay.
def draw_ID(overlay)
pbDrawTextPositions(overlay, [
[_INTL("Name"), 34, 70, :left, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[$player.name, 302, 70, :right, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[_INTL("ID No."), 332, 70, :left, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[sprintf("%05d", $player.public_ID), 468, 70, :right, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR]
])
end
# Draws the player's money, Pokédex numbers, play time and start date onto the
# overlay.
def draw_stats(overlay)
# Create money text
money_text = _INTL("${1}", $player.money.to_s_formatted)
# Create Pokédex stats text
pokedex_text = sprintf("%d/%d", $player.pokedex.owned_count, $player.pokedex.seen_count)
# Create play time text
total_secs = $stats.play_time.to_i
hour = (total_secs / 60) / 60
min = (total_secs / 60) % 60
play_time = (hour > 0) ? _INTL("{1}h {2}m", hour, min) : _INTL("{1}m", min)
# Create start date text
$PokemonGlobal.startTime = Time.now if !$PokemonGlobal.startTime
# TODO: Put this date the proper way round for non-United States of Americans.
start_date = _INTL("{1} {2}, {3}",
pbGetAbbrevMonthName($PokemonGlobal.startTime.mon),
$PokemonGlobal.startTime.day,
$PokemonGlobal.startTime.year)
# Draw text
pbDrawTextPositions(overlay, [
[_INTL("Money"), 34, 118, :left, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[money_text, 302, 118, :right, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[_INTL("Pokédex"), 34, 166, :left, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[pokedex_text, 302, 166, :right, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[_INTL("Time"), 34, 214, :left, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[play_time, 302, 214, :right, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[_INTL("Started"), 34, 262, :left, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR],
[start_date, 302, 262, :right, BLACK_TEXT_COLOR, BLACK_TEXT_SHADOW_COLOR]
])
end
# Draws the player's owned Gym Badges onto the overlay.
def draw_badges(overlay)
x = FIRST_BADGE_X
region = pbGetCurrentRegion(0) # Get the current region
BADGE_COUNT.times do |i|
if $player.badges[i + (region * BADGE_COUNT)]
pbDrawImagePositions(overlay, [
[GRAPHICS_FOLDER + "icon_badges", x, FIRST_BADGE_Y, i * BADGE_SIZE[0], region * BADGE_SIZE[1], *BADGE_SIZE]
])
end
x += BADGE_SIZE[0] + BADGE_SPACING
end
end
end
#===============================================================================
#
#===============================================================================
class UI::TrainerCardScreen < UI::BaseUIScreen
def initialize_visuals
@visuals = UI::TrainerCardVisuals.new
end
def start_screen
super
pbSEPlay("GUI trainer card open")
end
def end_screen
pbPlayCloseMenuSE
super
end
end
#===============================================================================
#
#===============================================================================
MenuHandlers.add(:pause_menu, :new_trainer_card, {
"name" => proc { next "New Trainer Card" },
"order" => 55,
"effect" => proc { |menu|
pbPlayDecisionSE
pbFadeOutIn do
UI::TrainerCardScreen.new
menu.pbRefresh
end
next false
}
})

View File

@@ -0,0 +1,104 @@
#===============================================================================
#
#===============================================================================
class UI::TrainerCardVisuals < UI::BaseVisuals
@@graphics_folder = "Trainer Card/" # Subfolder in Graphics/UI
BADGE_SIZE = [32, 32] # [width, height] of a Gym Badge
BADGE_SPACING = 16 # Size of gap between adjacent Gym Badges
FIRST_BADGE_X = 72 # Left edge of the first Gym Badge
FIRST_BADGE_Y = 310 # Top edge of the first Gym Badge
BADGE_COUNT = 8 # Number of Gym Badges to show
def initialize_sprites
# Trainer card
add_icon_sprite(:card, 0, 0, graphics_folder + gendered_filename(_INTL("trainer_card")))
# Player sprite (coordinates are the bottom middle of the sprite)
add_icon_sprite(:player, 400, 240, GameData::TrainerType.player_front_sprite_filename($player.trainer_type))
if !@sprites[:player].bitmap
raise _INTL("No trainer front sprite exists for the player character, expected a file at {1}.",
"Graphics/Trainers/" + $player.trainer_type.to_s + ".png")
end
@sprites[:player].x -= @sprites[:player].bitmap.width / 2
@sprites[:player].y -= @sprites[:player].bitmap.height
@sprites[:player].z = 10
end
#-----------------------------------------------------------------------------
def refresh_overlay
super
draw_ID
draw_stats
draw_badges
end
# Draws the player's name and ID number onto the overlay.
def draw_ID
draw_text(_INTL("Name"), 34, 70)
draw_text($player.name, 302, 70, align: :right)
draw_text(_INTL("ID No."), 332, 70)
draw_text(sprintf("%05d", $player.public_ID), 468, 70, align: :right)
end
# Draws the player's money, Pokédex numbers, play time and start date onto the
# overlay.
def draw_stats
# Create money text
money_text = _INTL("${1}", $player.money.to_s_formatted)
# Create Pokédex stats text
pokedex_text = sprintf("%d/%d", $player.pokedex.owned_count, $player.pokedex.seen_count)
# Create play time text
total_secs = $stats.play_time.to_i
hour = (total_secs / 60) / 60
min = (total_secs / 60) % 60
play_time_text = (hour > 0) ? _INTL("{1}h {2}m", hour, min) : _INTL("{1}m", min)
# Create start date text
$PokemonGlobal.startTime = Time.now if !$PokemonGlobal.startTime
# TODO: Put this date the proper way round for non-United States of Americans.
start_date_text = _INTL("{1} {2}, {3}",
pbGetAbbrevMonthName($PokemonGlobal.startTime.mon),
$PokemonGlobal.startTime.day,
$PokemonGlobal.startTime.year)
# Draw text
draw_text(_INTL("Money"), 34, 118)
draw_text(money_text, 302, 118, align: :right)
draw_text(_INTL("Pokédex"), 34, 166)
draw_text(pokedex_text, 302, 166, align: :right)
draw_text(_INTL("Time"), 34, 214)
draw_text(play_time_text, 302, 214, align: :right)
draw_text(_INTL("Started"), 34, 262)
draw_text(start_date_text, 302, 262, align: :right)
end
# Draws the player's owned Gym Badges onto the overlay.
def draw_badges
x = FIRST_BADGE_X
region = pbGetCurrentRegion(0) # Get the current region
BADGE_COUNT.times do |i|
if $player.badges[i + (region * BADGE_COUNT)]
draw_image(graphics_folder + "icon_badges", x, FIRST_BADGE_Y,
i * BADGE_SIZE[0], region * BADGE_SIZE[1], *BADGE_SIZE)
end
x += BADGE_SIZE[0] + BADGE_SPACING
end
end
end
#===============================================================================
#
#===============================================================================
class UI::TrainerCard < UI::BaseScreen
def initialize_visuals
@visuals = UI::TrainerCardVisuals.new
end
def start_screen
super
pbSEPlay("GUI trainer card open")
end
def end_screen
pbPlayCloseMenuSE
super
end
end

View File

@@ -0,0 +1,130 @@
=begin
#===============================================================================
#
#===============================================================================
class PokemonPauseMenu_Scene
def pbStartScene
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
@sprites = {}
@sprites["cmdwindow"] = Window_CommandPokemon.new([])
@sprites["cmdwindow"].visible = false
@sprites["cmdwindow"].viewport = @viewport
@sprites["infowindow"] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
@sprites["infowindow"].visible = false
@sprites["helpwindow"] = Window_UnformattedTextPokemon.newWithSize("", 0, 0, 32, 32, @viewport)
@sprites["helpwindow"].visible = false
@infostate = false
@helpstate = false
pbSEPlay("GUI menu open")
end
def pbShowInfo(text)
@sprites["infowindow"].resizeToFit(text, Graphics.height)
@sprites["infowindow"].text = text
@sprites["infowindow"].visible = true
@infostate = true
end
def pbShowHelp(text)
@sprites["helpwindow"].resizeToFit(text, Graphics.height)
@sprites["helpwindow"].text = text
@sprites["helpwindow"].visible = true
pbBottomLeft(@sprites["helpwindow"])
@helpstate = true
end
def pbShowMenu
@sprites["cmdwindow"].visible = true
@sprites["infowindow"].visible = @infostate
@sprites["helpwindow"].visible = @helpstate
end
def pbHideMenu
@sprites["cmdwindow"].visible = false
@sprites["infowindow"].visible = false
@sprites["helpwindow"].visible = false
end
def pbShowCommands(commands)
ret = -1
cmdwindow = @sprites["cmdwindow"]
cmdwindow.commands = commands
cmdwindow.index = $game_temp.menu_last_choice
cmdwindow.resizeToFit(commands)
cmdwindow.x = Graphics.width - cmdwindow.width
cmdwindow.y = 0
cmdwindow.visible = true
loop do
cmdwindow.update
Graphics.update
Input.update
pbUpdateSceneMap
if Input.trigger?(Input::BACK) || Input.trigger?(Input::ACTION)
ret = -1
break
elsif Input.trigger?(Input::USE)
ret = cmdwindow.index
$game_temp.menu_last_choice = ret
break
end
end
return ret
end
def pbEndScene
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
def pbRefresh; end
end
#===============================================================================
#
#===============================================================================
class PokemonPauseMenu
def initialize(scene)
@scene = scene
end
def pbShowMenu
@scene.pbRefresh
@scene.pbShowMenu
end
def pbShowInfo; end
def pbStartPokemonMenu
if !$player
if $DEBUG
pbMessage(_INTL("The player trainer was not defined, so the pause menu can't be displayed."))
pbMessage(_INTL("Please see the documentation to learn how to set up the trainer player."))
end
return
end
@scene.pbStartScene
# Show extra info window if relevant
pbShowInfo
# Get all commands
command_list = []
commands = []
MenuHandlers.each_available(:pause_menu) do |option, hash, name|
command_list.push(name)
commands.push(hash)
end
# Main loop
end_scene = false
loop do
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 end_scene
end
end
=end

View File

@@ -1,3 +1,4 @@
=begin
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
@@ -113,3 +114,4 @@ class PokemonTrainerCardScreen
@scene.pbEndScene @scene.pbEndScene
end end
end end
=end

View File

@@ -164,21 +164,36 @@ end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
class PokemonPauseMenu class UI::PauseMenu < UI::BaseScreen
alias __safari_pbShowInfo pbShowInfo unless method_defined?(:__safari_pbShowInfo) alias __safari_show_info show_info unless method_defined?(:__safari_show_info)
def pbShowInfo def show_info
__safari_pbShowInfo __safari_show_info
return if !pbInSafari? return if !pbInSafari?
if Settings::SAFARI_STEPS <= 0 if Settings::SAFARI_STEPS <= 0
@scene.pbShowInfo(_INTL("Balls: {1}", pbSafariState.ballcount)) @visuals.show_info(_INTL("Balls: {1}", pbSafariState.ballcount))
else else
@scene.pbShowInfo(_INTL("Steps: {1}/{2}\nBalls: {3}", @visuals.show_info(_INTL("Steps: {1}/{2}\nBalls: {3}",
pbSafariState.steps, Settings::SAFARI_STEPS, pbSafariState.ballcount)) pbSafariState.steps, Settings::SAFARI_STEPS, pbSafariState.ballcount))
end end
end end
end end
# class PokemonPauseMenu
# alias __safari_pbShowInfo pbShowInfo unless method_defined?(:__safari_pbShowInfo)
#
# def pbShowInfo
# __safari_pbShowInfo
# return 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
# end
# end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
@@ -188,15 +203,15 @@ MenuHandlers.add(:pause_menu, :quit_safari_game, {
"order" => 60, "order" => 60,
"condition" => proc { next pbInSafari? }, "condition" => proc { next pbInSafari? },
"effect" => proc { |menu| "effect" => proc { |menu|
menu.pbHideMenu menu.hide_menu
if pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?")) if pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
menu.pbEndScene menu.silent_end_screen
pbSafariState.decision = 1 pbSafariState.decision = 1
pbSafariState.pbGoToStart pbSafariState.pbGoToStart
next true next true
end end
menu.pbRefresh menu.refresh
menu.pbShowMenu menu.show_menu
next false next false
} }
}) })

View File

@@ -408,23 +408,40 @@ end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
class PokemonPauseMenu class UI::PauseMenu < UI::BaseScreen
alias __bug_contest_pbShowInfo pbShowInfo unless method_defined?(:__bug_contest_pbShowInfo) alias __bug_contest_show_info show_info unless method_defined?(:__bug_contest_show_info)
def pbShowInfo def show_info
__bug_contest_pbShowInfo __bug_contest_show_info
return if !pbInBugContest? return if !pbInBugContest?
if pbBugContestState.lastPokemon if pbBugContestState.lastPokemon
@scene.pbShowInfo(_INTL("Caught: {1}\nLevel: {2}\nBalls: {3}", @visuals.show_info(_INTL("Caught: {1}\nLevel: {2}\nBalls: {3}",
pbBugContestState.lastPokemon.speciesName, pbBugContestState.lastPokemon.speciesName,
pbBugContestState.lastPokemon.level, pbBugContestState.lastPokemon.level,
pbBugContestState.ballcount)) pbBugContestState.ballcount))
else else
@scene.pbShowInfo(_INTL("Caught: None\nBalls: {1}", pbBugContestState.ballcount)) @visuals.show_info(_INTL("Caught: None\nBalls: {1}", pbBugContestState.ballcount))
end end
end end
end end
# class PokemonPauseMenu
# alias __bug_contest_pbShowInfo pbShowInfo unless method_defined?(:__bug_contest_pbShowInfo)
#
# def pbShowInfo
# __bug_contest_pbShowInfo
# return if !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
# end
# end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
@@ -434,14 +451,14 @@ MenuHandlers.add(:pause_menu, :quit_bug_contest, {
"order" => 60, "order" => 60,
"condition" => proc { next pbInBugContest? }, "condition" => proc { next pbInBugContest? },
"effect" => proc { |menu| "effect" => proc { |menu|
menu.pbHideMenu menu.hide_menu
if pbConfirmMessage(_INTL("Would you like to end the Contest now?")) if pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
menu.pbEndScene menu.silent_end_screen
pbBugContestState.pbStartJudging pbBugContestState.pbStartJudging
next true next true
end end
menu.pbRefresh menu.refresh
menu.pbShowMenu menu.show_menu
next false next false
} }
}) })