diff --git a/src/battle/BattleState.lua b/src/battle/BattleState.lua index 6cee785a..99b3a53a 100644 --- a/src/battle/BattleState.lua +++ b/src/battle/BattleState.lua @@ -145,6 +145,17 @@ function BattleState:statusHUDVisible() self) ~= false end +function BattleState:caughtMarkerVisible() + local dex = self.game and self.game.save and self.game.save.pokedex + if not self.enemy or (self.kind ~= "wild" and self.kind ~= "safari") + or not (dex and dex.owned and dex.owned[self.enemy.mon.species]) then + return false + end + if not Runtime.wantsHook("battle.caught_marker_visible") then return false end + return Runtime.call("battle.caught_marker_visible", + function() return false end, self) == true +end + function BattleState:moveGridNavigation() if self:wideLayout() then return true end if not Runtime.wantsHook("battle.move_grid_navigation") then return false end @@ -4779,7 +4790,7 @@ end -- Party pokeball row (SetupPokeballs tiles: ball / status ball / -- fainted ball / empty), 6 slots stepping dx from (x,y). local ballQuads -function BattleState:drawBallRow(party, x, y, dx) +local function balls() if ballQuads == nil then local ok, img = pcall(love.graphics.newImage, "assets/generated/battle/balls.png") if ok then @@ -4791,11 +4802,23 @@ function BattleState:drawBallRow(party, x, y, dx) ballQuads = false end end - if not ballQuads then return end + return ballQuads or nil +end + +function BattleState:drawCaughtBall(x, y) + local quads = balls() + if not quads then return end + love.graphics.setColor(1, 1, 1, 1) + love.graphics.draw(quads.img, quads[0], x, y) +end + +function BattleState:drawBallRow(party, x, y, dx) + local quads = balls() + if not quads then return end for i = 1, 6 do local mon = party[i] local tile = not mon and 3 or mon.hp <= 0 and 2 or mon.status and 1 or 0 - love.graphics.draw(ballQuads.img, ballQuads[tile], x + (i - 1) * dx, y) + love.graphics.draw(quads.img, quads[tile], x + (i - 1) * dx, y) end end @@ -5511,7 +5534,12 @@ function BattleState:drawHUDs(slide) love.graphics.translate(hudShake, 0) end love.graphics.setColor(0, 0, 0, 1) - Font.draw(self.enemy.name, nameX(1, self.enemy.name), 0) + local enemyNameX = nameX(1, self.enemy.name) + local enemyNameWidth = Font.draw(self.enemy.name, enemyNameX, 0) + if self:caughtMarkerVisible() then + self:drawCaughtBall(enemyNameX + enemyNameWidth, 0) + love.graphics.setColor(0, 0, 0, 1) + end if self.enemy.shownStatus then Font.draw(self:statusLabel({ status = self.enemy.shownStatus }), 40, 8) else diff --git a/tests/mod_qol_hooks_tests.lua b/tests/mod_qol_hooks_tests.lua index dfa425b2..ff9716b6 100644 --- a/tests/mod_qol_hooks_tests.lua +++ b/tests/mod_qol_hooks_tests.lua @@ -193,6 +193,26 @@ do "battle status HUD returns when the hook is removed") end +-- ------- battle.caught_marker_visible (caught wild marker) + +do + local BattleState = require("src.battle.BattleState") + local state = { kind = "wild", enemy = { mon = { species = "RATTATA" } }, + game = { save = { pokedex = { owned = { RATTATA = true } } } } } + check(not BattleState.caughtMarkerVisible(state), + "caught marker is opt-in") + local unsub = wrap("battle.caught_marker_visible", function() return true end) + check(BattleState.caughtMarkerVisible(state), + "a mod can show a caught wild marker") + state.kind = "trainer" + check(not BattleState.caughtMarkerVisible(state), + "trainer battles never show a caught marker") + state.kind, state.game.save.pokedex.owned.RATTATA = "wild", false + check(not BattleState.caughtMarkerVisible(state), + "uncaught wild Pokemon have no marker") + unsub() +end + -- ------- grid navigation ownership (alternate menu renderers) do