mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-10-03 16:16:38 -04:00
49a5408c2d
A Pokémon's level is printed on four Gen 1 surfaces -- both battle healthboxes, the party rows, and both status pages -- and every one of them prints it unconditionally. There is no seam, so a mode that wants the number gone has two options today and both are bad: paint over the engine's own pixels from render.hud (four rectangles, a background shade to match, and the palette flashes and healthbox slide to survive), or monkey-patch the render modules from inside the sandbox, which works and is exactly what CONTRIBUTING-mods.md tells mods not to do. The motivating case is a battle royale that scales every party to a shared rung rising with its fog: the number is the same for everyone, it changes on a clock, and it reads as a threat it is not -- a Lv37 opponent looks dangerous to a player who has not worked out that their own team is Lv37 too. A randomizer keeping an encounter unreadable, a challenge run that forbids level-checking and a blind Nuzlocke want the same switch. New hook `pokemon.level_visible`, taking the shape the presentation predicates on the battle screen already use -- battle.status_hud_visible, battle.bottom_ui_visible, battle.caught_marker_visible: consulted behind Runtime.wantsHook, default visible, only an explicit false suppresses. It is not named battle.* because a level is not a battle-only readout, and it carries the surface that asked (battle.enemy / battle.player / party / summary) so a mode can hide an opponent's level and keep its own. src/ui/LevelDisplay.lua holds the one definition of "visible", so the four call sites are a one-line guard each rather than four copies of the same five lines that can drift apart. No layout moves. Each site keeps its own hand-rolled PrintLevel rule (home/pokemon.asm:335-345), it just asks first. Two details are deliberate: a status condition still replaces the level on a healthbox exactly as in the cart, so hiding a level never hides PSN or BRN (the guard is an elseif on the existing status branch); and on status page 2 the <to> arrow is hidden with the level it points at, because an arrow with nothing after it is half a sentence. Gen 1 only. The Gen 2 screens and the Gen 1 PC box list -- where the level is part of a row label rather than a drawn field -- keep their own readouts and do not consult the hook. Both are stated as follow-ups in the RFC and beside the hook in docs/modding.md, so a mod author reads the limit before depending on it. Verification: tests/modkit/cases/pokemon_level_visible.lua covers the contract through the public mod API; gate_hooks picks the hook up on its own because it walks the live catalog; gate_meta_coverage is satisfied by the change that introduces the seam, so it never enters the DEBT ledger. tests/run_modkit.lua 33/33, tests/run_engine.lua 327/331 -- the same four audio/hostshell suites fail unchanged on dev without this branch. Co-Authored-By: Claude <noreply@anthropic.com>
228 lines
9.8 KiB
Lua
228 lines
9.8 KiB
Lua
-- Pokémon status screen, laid out like the original's two pages
|
|
-- (engine/pokemon/status_screen.asm): page 1 = pic, No., HP bar,
|
|
-- STATUS/, the ATTACK/DEFENSE/SPEED/SPECIAL box and TYPE1/TYPE2/
|
|
-- IDNo/OT; page 2 = EXP and the moves with PP. A flips pages, B (or
|
|
-- A on page 2) closes.
|
|
|
|
local Font = require("src.render.Font")
|
|
-- status_screen.asm PrintMonType prints the type's DISPLAY name from the
|
|
-- TypeNames table, not the constant: species types are stored as pokered
|
|
-- constants (RomExtractor:typesById) and PSYCHIC's is "PSYCHIC_TYPE" (so it
|
|
-- won't collide with the PSYCHIC move), which would overflow the TYPE field.
|
|
-- TypeChart.displayName maps it back to "PSYCHIC", like HallOfFame and the
|
|
-- battle move-type box already do (#214).
|
|
local TypeChart = require("src.battle.TypeChart")
|
|
local LevelDisplay = require("src.ui.LevelDisplay")
|
|
local Strings = require("src.core.Strings")
|
|
local Stats = require("src.pokemon.Stats")
|
|
local Status = require("src.battle.Status")
|
|
|
|
local SummaryMenu = {}
|
|
SummaryMenu.__index = SummaryMenu
|
|
SummaryMenu.isOpaque = true
|
|
|
|
-- SGB: SetPal_StatusScreen -- HP-bar palette overall, mon pic zone in
|
|
-- the species palette
|
|
function SummaryMenu:sgbPalettes(game)
|
|
local P = require("src.render.PaletteFX")
|
|
local mon = self.mon
|
|
if not mon then return P.wholeNamed(game.data, "MEWMON") end
|
|
local bar = P.pal(game.data, P.barPalName(mon.hp, mon.stats.hp))
|
|
if not bar then return nil end
|
|
return { P.whole(bar), P.zone(P.monPal(game.data, mon.species), 1, 0, 7, 6) }
|
|
end
|
|
|
|
function SummaryMenu.new(game, mon)
|
|
-- status_screen.asm:66-76: StatusScreen recalculates the stat block before
|
|
-- it draws anything when the mon came from a box or the daycare ("mon is
|
|
-- in a box or daycare" -> CalcStats), because box_struct carries none.
|
|
-- Bill's PC hands us that mon table directly (src/ui/BoxMenu.lua's STATS
|
|
-- submenu entry), and for a .sav imported through
|
|
-- src/save_convert/GenSave.lua it really does arrive with mon.stats nil,
|
|
-- which crashed the HP bar draw below (#233). Redundant once
|
|
-- SaveData.validate has run over a loaded save, but this is the site the
|
|
-- original recomputes at, and it also covers a mon handed in by a mod.
|
|
Stats.ensure(game.data.pokemon[mon.species], mon)
|
|
local self = setmetatable({ game = game, mon = mon, page = 1 }, SummaryMenu)
|
|
local Sprites = require("src.pokemon.Sprites")
|
|
local path, trueColor = Sprites.path(game.data, mon.species, "front",
|
|
{ mon = mon, kind = "summary" })
|
|
if path then
|
|
local ok, img = pcall(love.graphics.newImage, path)
|
|
self.sprite = ok and img or nil
|
|
end
|
|
self.spriteTrueColor = self.sprite and trueColor or false
|
|
require("src.core.Sound").playCry(game.data, mon.species)
|
|
return self
|
|
end
|
|
|
|
function SummaryMenu:update(dt)
|
|
local input = self.game.input
|
|
-- both A and B advance the pages (WaitForTextScrollButtonPress)
|
|
if input:wasPressed("a") or input:wasPressed("b") then
|
|
if self.page == 1 then
|
|
self.page = 2
|
|
else
|
|
self.game.stack:pop()
|
|
end
|
|
end
|
|
end
|
|
|
|
-- DrawLineBox (status_screen.asm): a vertical edge down the right,
|
|
-- a corner, a horizontal run leftward and the half-arrow ending --
|
|
-- drawn from the same HUD tiles the original loads
|
|
local function drawLineBox(tx, ty, b, c)
|
|
local HudTiles = require("src.render.HudTiles")
|
|
-- Under the status screen's overlay the vertical is $78 -- DrawLineBox
|
|
-- writes `ld [hl], $78` (status_screen.asm:222), and :90-93 is what puts
|
|
-- hud_2's single bar tile there. $73 is the <ID> glyph on this screen,
|
|
-- not a line, so the whole box has to come off statusTile (#280). The
|
|
-- drawn shapes are unchanged: hud_2 tile 0 is the same bar the battle
|
|
-- layout parks at $73.
|
|
for i = 0, b - 1 do HudTiles.statusTile(0x78, tx * 8, (ty + i) * 8) end
|
|
HudTiles.statusTile(0x77, tx * 8, (ty + b) * 8)
|
|
for i = 1, c do HudTiles.statusTile(0x76, (tx - i) * 8, (ty + b) * 8) end
|
|
HudTiles.statusTile(0x6F, (tx - c - 1) * 8, (ty + b) * 8)
|
|
end
|
|
|
|
-- home/pokemon.asm:335-345 PrintLevel: the "<LV>" (":L") tile at (tx,ty)
|
|
-- then the level LEFT_ALIGNed after it; at level 100 hl is decremented so
|
|
-- the third digit is written back OVER the ":L" tile. Both status pages
|
|
-- print a level this way, and src/ui/PartyMenu.lua models the same rule for
|
|
-- its rows. #280
|
|
local function printLevel(tx, ty, level)
|
|
local HudTiles = require("src.render.HudTiles")
|
|
local x = tx * 8
|
|
if level < 100 then
|
|
HudTiles.statusTile(0x6E, x, ty * 8)
|
|
x = x + 8
|
|
end
|
|
Font.draw(tostring(level), x, ty * 8)
|
|
end
|
|
|
|
function SummaryMenu:draw()
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
love.graphics.rectangle("fill", 0, 0, 160, 144)
|
|
local mon = self.mon
|
|
local game = self.game
|
|
local data = game.data
|
|
local def = data.pokemon[mon.species]
|
|
|
|
-- shared header: pic (1,0), name (9,1), № + dex number (1,7). The pic is
|
|
-- MIRRORED -- status_screen.asm:170 draws it through
|
|
-- LoadFlippedFrontSpriteByMonIndex (home/pokemon.asm sets wSpriteFlipped),
|
|
-- the same routine the intro's NIDORINO show-off uses (OakSpeech picFlip:
|
|
-- negative x scale anchored at the pic's right edge). #280
|
|
if self.sprite then
|
|
local pw, ph = self.sprite:getDimensions()
|
|
local py = math.max(0, 56 - ph)
|
|
love.graphics.draw(self.sprite, 8 + pw, py, 0, -1, 1)
|
|
-- a full-color pic has to sit out the SGB monPal recolor, so mark the
|
|
-- rect the mirrored draw covers for the unshaded pass (#430)
|
|
if self.spriteTrueColor then
|
|
require("src.render.PaletteFX").markTrueColor(8, py, pw, ph)
|
|
end
|
|
end
|
|
local HudTiles = require("src.render.HudTiles")
|
|
love.graphics.setColor(0, 0, 0, 1)
|
|
Font.draw(mon.nickname or def.name, 72, 8)
|
|
-- status_screen.asm:109-113 backs hl up from DrawLineBox's end to write
|
|
-- the single-tile '№' at (1,7) and '<DOT>' at (2,7); :143-146 then
|
|
-- PrintNumbers the dex number (LEADING_ZEROES, 3 digits) at (3,7).
|
|
-- Spelling "No." out of three letter tiles pushed every digit a column
|
|
-- right of the original. #280
|
|
HudTiles.statusTile(0x74, 8, 56) -- №
|
|
Font.drawCode(0xF2, 16, 56) -- <DOT> (charmap.asm:182)
|
|
Font.draw(("%03d"):format(def.dex or 0), 24, 56)
|
|
|
|
if self.page == 1 then
|
|
-- level is page 1 only: StatusScreen2 opens with ClearScreenArea over
|
|
-- (9,2) 5x10 (status_screen.asm:303-305). #280
|
|
if LevelDisplay.visible(mon, "summary", self.game) then -- RFC 0019
|
|
printLevel(14, 2, mon.level)
|
|
end
|
|
drawLineBox(19, 1, 6, 10)
|
|
-- engine/pokemon/status_screen.asm:120-125
|
|
local PaletteFX = require("src.render.PaletteFX")
|
|
local barZoned = PaletteFX.shader() ~= nil
|
|
and PaletteFX.pal(data, "GREENBAR") ~= nil
|
|
HudTiles.drawHPBar(data, 11, 3, mon, 1, barZoned) -- wHPBarType 1
|
|
Font.draw(("%3d/%3d"):format(mon.hp, mon.stats.hp), 96, 32)
|
|
Font.draw(Strings("STATUS/"), 72, 48)
|
|
Font.draw(Status.hudLabelFor(data.statuses, mon.status) or "OK", 128, 48)
|
|
|
|
-- stats box (0,8) 10x10: names rows 9/11/13/15, values indented
|
|
Font.drawBox(0, 8, 10, 10)
|
|
local stats = {
|
|
{ "ATTACK", mon.stats.attack }, { "DEFENSE", mon.stats.defense },
|
|
{ "SPEED", mon.stats.speed }, { "SPECIAL", mon.stats.special },
|
|
}
|
|
for i, s in ipairs(stats) do
|
|
local y = 72 + (i - 1) * 16
|
|
Font.draw(Strings(s[1]), 8, y)
|
|
Font.draw(("%3d"):format(s[2]), 48, y + 8)
|
|
end
|
|
|
|
-- TYPE1/TYPE2/IDNo/OT column (10,9) with values indented (11,10)
|
|
drawLineBox(19, 9, 8, 6)
|
|
Font.draw(Strings("TYPE1/"), 80, 72)
|
|
Font.draw(def.types[1] and TypeChart.displayName(def.types[1]) or "", 88, 80)
|
|
if def.types[2] then
|
|
Font.draw(Strings("TYPE2/"), 80, 88)
|
|
Font.draw(TypeChart.displayName(def.types[2]), 88, 96)
|
|
end
|
|
-- TypesIDNoOTText's third row is "<ID>№/" (status_screen.asm:205-210):
|
|
-- two single-tile glyphs and a slash, three columns wide, not the five
|
|
-- letter tiles "IDNo/" this used to spell out. #280
|
|
HudTiles.statusTile(0x73, 80, 104) -- <ID>
|
|
HudTiles.statusTile(0x74, 88, 104) -- №
|
|
Font.draw("/", 96, 104)
|
|
-- the trainer ID is rolled at new game (SaveData.newGame) and
|
|
-- backfilled on load for old saves
|
|
Font.draw(("%05d"):format(mon.otId or game.save.player.id or 0), 96, 112)
|
|
Font.draw(Strings("OT/"), 80, 120)
|
|
Font.draw(mon.ot or game.save.player.name or "RED", 96, 128)
|
|
else
|
|
-- page 2: EXP + the moves with PP (StatusScreen2)
|
|
drawLineBox(19, 1, 6, 10)
|
|
Font.draw(Strings("EXP POINTS"), 72, 24)
|
|
-- PrintNumber at (12,4) with 7 columns: the exp is RIGHT-aligned into
|
|
-- cols 12-18 (status_screen.asm:400-403), not left-aligned from col 12.
|
|
-- #280
|
|
Font.draw(("%7d"):format(mon.exp), 96, 32)
|
|
-- StatusScreen2: "LEVEL UP" at (9,5); next-exp PrintNumber 7 cols at
|
|
-- (7,6); the narrow '<to>' tile at (14,6); PrintLevel at (16,6)
|
|
-- (status_screen.asm:393-403). The old "%d to L%d" string at x=88
|
|
-- overflowed the DrawLineBox edge.
|
|
Font.draw(Strings("LEVEL UP"), 72, 40)
|
|
local Growth = require("src.pokemon.Growth")
|
|
local nextExp = mon.level < 100
|
|
and (Growth.expForLevel(def.growthRate, mon.level + 1) - mon.exp) or 0
|
|
Font.draw(("%7d"):format(math.max(0, nextExp)), 56, 48)
|
|
if LevelDisplay.visible(mon, "summary", self.game) then -- RFC 0019
|
|
-- the '<to>' arrow is half a sentence without the level it points at,
|
|
-- so the pair is hidden together
|
|
HudTiles.statusTile(0x70, 112, 48) -- '<to>' at (14,6), was missing (#280)
|
|
printLevel(16, 6, math.min(100, mon.level + 1))
|
|
end
|
|
Font.drawBox(0, 8, 20, 10)
|
|
for i = 1, 4 do
|
|
local mv = mon.moves[i]
|
|
local y = 72 + (i - 1) * 16
|
|
if mv then
|
|
local mdef = data.moves[mv.id]
|
|
Font.draw(mdef.name, 16, y)
|
|
Font.draw(Strings("PP"), 88, y + 8)
|
|
local maxPP = mdef.pp + (mv.ppUps or 0) * math.floor(mdef.pp / 5)
|
|
Font.draw(("%2d/%2d"):format(mv.pp, maxPP), 112, y + 8)
|
|
else
|
|
Font.draw("-", 16, y)
|
|
Font.draw("--", 112, y + 8)
|
|
end
|
|
end
|
|
end
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
end
|
|
|
|
return SummaryMenu
|