Refactored code that draws the Pokémon info box in battle

This commit is contained in:
Maruno17
2022-06-13 23:17:09 +01:00
parent cc540b0132
commit c0c672806d
2 changed files with 81 additions and 56 deletions

View File

@@ -205,62 +205,87 @@ class Battle::Scene::PokemonDataBox < SpriteWrapper
end
end
def refresh
self.bitmap.clear
return if !@battler.pokemon
textPos = []
imagePos = []
# Draw background panel
def draw_background
self.bitmap.blt(0, 0, @databoxBitmap.bitmap, Rect.new(0, 0, @databoxBitmap.width, @databoxBitmap.height))
# Draw Pokémon's name
end
def draw_name
nameWidth = self.bitmap.text_size(@battler.name).width
nameOffset = 0
nameOffset = nameWidth - 116 if nameWidth > 116
textPos.push([@battler.name, @spriteBaseX + 8 - nameOffset, 12, false, NAME_BASE_COLOR, NAME_SHADOW_COLOR])
# Draw Pokémon's gender symbol
case @battler.displayGender
when 0 # Male
textPos.push([_INTL(""), @spriteBaseX + 126, 12, false, MALE_BASE_COLOR, MALE_SHADOW_COLOR])
when 1 # Female
textPos.push([_INTL(""), @spriteBaseX + 126, 12, false, FEMALE_BASE_COLOR, FEMALE_SHADOW_COLOR])
end
pbDrawTextPositions(self.bitmap, textPos)
# Draw Pokémon's level
imagePos.push(["Graphics/Pictures/Battle/overlay_lv", @spriteBaseX + 140, 16])
pbDrawTextPositions(self.bitmap,
[[@battler.name, @spriteBaseX + 8 - nameOffset, 12, false, NAME_BASE_COLOR, NAME_SHADOW_COLOR]]
)
end
def draw_level
# "Lv" graphic
pbDrawImagePositions(self.bitmap,
[["Graphics/Pictures/Battle/overlay_lv", @spriteBaseX + 140, 16]]
)
# Level number
pbDrawNumber(@battler.level, self.bitmap, @spriteBaseX + 162, 16)
# Draw shiny icon
if @battler.shiny?
shinyX = (@battler.opposes?(0)) ? 206 : -6 # Foe's/player's
imagePos.push(["Graphics/Pictures/shiny", @spriteBaseX + shinyX, 36])
end
def draw_gender
gender = @battler.displayGender
return if ![0, 1].include?(gender)
gender_text = (gender == 0) ? _INTL("") : _INTL("")
base_color = (gender == 0) ? MALE_BASE_COLOR : FEMALE_BASE_COLOR
shadow_color = (gender == 0) ? MALE_SHADOW_COLOR : FEMALE_SHADOW_COLOR
pbDrawTextPositions(self.bitmap, [[gender_text, @spriteBaseX + 126, 12, false, base_color, shadow_color]])
end
def draw_status
return if @battler.status == :NONE
if @battler.status == :POISON && @battler.statusCount > 0 # Badly poisoned
s = GameData::Status.count - 1
else
s = GameData::Status.get(@battler.status).icon_position
end
# Draw Mega Evolution/Primal Reversion icon
return if s < 0
pbDrawImagePositions(self.bitmap, [["Graphics/Pictures/Battle/icon_statuses", @spriteBaseX + 24, 36,
0, s * STATUS_ICON_HEIGHT, -1, STATUS_ICON_HEIGHT]])
end
def draw_shiny_icon
return if !@battler.shiny?
shiny_x = (@battler.opposes?(0)) ? 206 : -6 # Foe's/player's
pbDrawImagePositions(self.bitmap, [["Graphics/Pictures/shiny", @spriteBaseX + shiny_x, 36]])
end
def draw_special_form_icon
# Mega Evolution/Primal Reversion icon
if @battler.mega?
imagePos.push(["Graphics/Pictures/Battle/icon_mega", @spriteBaseX + 8, 34])
pbDrawImagePositions(self.bitmap, [["Graphics/Pictures/Battle/icon_mega", @spriteBaseX + 8, 34]])
elsif @battler.primal?
filename = nil
if @battler.isSpecies?(:GROUDON)
filename = "Graphics/Pictures/Battle/icon_primal_Groudon"
elsif @battler.isSpecies?(:KYOGRE)
filename = "Graphics/Pictures/Battle/icon_primal_Kyogre"
end
primalX = (@battler.opposes?) ? 208 : -28 # Foe's/player's
if @battler.isSpecies?(:KYOGRE)
imagePos.push(["Graphics/Pictures/Battle/icon_primal_Kyogre", @spriteBaseX + primalX, 4])
elsif @battler.isSpecies?(:GROUDON)
imagePos.push(["Graphics/Pictures/Battle/icon_primal_Groudon", @spriteBaseX + primalX, 4])
end
pbDrawImagePositions(self.bitmap, [[filename, @spriteBaseX + primalX, 4]]) if filename
end
# Draw owned icon (foe Pokémon only)
if @battler.owned? && @battler.opposes?(0)
imagePos.push(["Graphics/Pictures/Battle/icon_own", @spriteBaseX + 8, 36])
end
# Draw status icon
if @battler.status != :NONE
if @battler.status == :POISON && @battler.statusCount > 0 # Badly poisoned
s = GameData::Status.count - 1
else
s = GameData::Status.get(@battler.status).icon_position
end
if s >= 0
imagePos.push(["Graphics/Pictures/Battle/icon_statuses", @spriteBaseX + 24, 36,
0, s * STATUS_ICON_HEIGHT, -1, STATUS_ICON_HEIGHT])
end
end
pbDrawImagePositions(self.bitmap, imagePos)
end
def draw_owned_icon
return if !@battler.owned? || !@battler.opposes?(0) # Draw for foe Pokémon only
pbDrawImagePositions(self.bitmap, [["Graphics/Pictures/Battle/icon_own", @spriteBaseX + 8, 36]])
end
def refresh
self.bitmap.clear
return if !@battler.pokemon
draw_background
draw_name
draw_level
draw_gender
draw_status
draw_shiny_icon
draw_special_form_icon
draw_owned_icon
refreshHP
refreshExp
end

View File

@@ -364,9 +364,9 @@ class PokemonPartyPanel < SpriteWrapper
@overlaysprite.bitmap&.clear
draw_name
draw_level
draw_gender
draw_hp
draw_status
draw_gender
draw_shiny_icon
draw_annotation
end
@@ -388,6 +388,15 @@ class PokemonPartyPanel < SpriteWrapper
pbSetSystemFont(@overlaysprite.bitmap)
end
def draw_gender
return if @pokemon.egg? || @pokemon.genderless?
gender_text = (@pokemon.male?) ? _INTL("") : _INTL("")
base_color = (@pokemon.male?) ? Color.new(0, 112, 248) : Color.new(232, 32, 16)
shadow_color = (@pokemon.male?) ? Color.new(120, 184, 232) : Color.new(248, 168, 184)
pbDrawTextPositions(@overlaysprite.bitmap,
[[gender_text, 224, 22, 0, base_color, shadow_color]])
end
def draw_hp
return if @pokemon.egg? || (@text && @text.length > 0)
# HP numbers
@@ -422,15 +431,6 @@ class PokemonPartyPanel < SpriteWrapper
@overlaysprite.bitmap.blt(78, 68, @statuses.bitmap, statusrect)
end
def draw_gender
return if @pokemon.egg? || @pokemon.genderless?
gender_text = (@pokemon.male?) ? _INTL("") : _INTL("")
base_color = (@pokemon.male?) ? Color.new(0, 112, 248) : Color.new(232, 32, 16)
shadow_color = (@pokemon.male?) ? Color.new(120, 184, 232) : Color.new(248, 168, 184)
pbDrawTextPositions(@overlaysprite.bitmap,
[[gender_text, 224, 22, 0, base_color, shadow_color]])
end
def draw_shiny_icon
return if @pokemon.egg? || !@pokemon.shiny?
pbDrawImagePositions(@overlaysprite.bitmap,