mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-25 06:55:29 +02:00
1905261c5b
CLOSES #1483, CLOSES #1610, CLOSES #1615, CLOSES #1646, CLOSES #1649, CLOSES #1651, CLOSES #1653, CLOSES #1656, CLOSES #1683, CLOSES #1685, CLOSES #1686, CLOSES #1687, CLOSES #1688, CLOSES #1689, CLOSES #1690, CLOSES #1693, CLOSES #1694, CLOSES #1695, CLOSES #1696, CLOSES #1702, CLOSES #1704, CLOSES #1705, CLOSES #1706, CLOSES #1707, CLOSES #1708, CLOSES #1710, CLOSES #1711, CLOSES #1712, CLOSES #1713, CLOSES #1716, CLOSES #1717, CLOSES #1718, CLOSES #1719, CLOSES #1720, CLOSES #1721, CLOSES #1725, CLOSES #1732, CLOSES #1745, CLOSES #1748, CLOSES #1749, CLOSES #1751, CLOSES #1754
160 lines
5.5 KiB
Lua
160 lines
5.5 KiB
Lua
-- "Which move should be forgotten?", replaces a move when a Pokémon with
|
|
-- four moves learns a new one (engine/pokemon/learn_move.asm). Opens
|
|
-- with the TryingToLearnText "Delete an older move...?" YES/NO; HM moves
|
|
-- can't be forgotten; B gives up on the new move.
|
|
|
|
local Font = require("src.render.Font")
|
|
local Strings = require("src.core.Strings")
|
|
local romText = require("src.core.RomText")
|
|
|
|
local MoveLearnMenu = {}
|
|
MoveLearnMenu.__index = MoveLearnMenu
|
|
|
|
local CURSOR = 0xED
|
|
|
|
-- data/moves/hm_moves.asm (IsMoveHM)
|
|
local HM_MOVES = {
|
|
CUT = true, FLY = true, SURF = true, STRENGTH = true, FLASH = true,
|
|
}
|
|
|
|
function MoveLearnMenu.new(game, mon, newMoveId, onDone, learnedSound)
|
|
local self = setmetatable({}, MoveLearnMenu)
|
|
self.game = game
|
|
self.mon = mon
|
|
self.newMoveId = newMoveId
|
|
self.onDone = onDone
|
|
self.learnedSound = learnedSound or "Get_Item1"
|
|
self.index = 1
|
|
-- forget-list UI only after TryingToLearn YES (learn_move.asm .loop)
|
|
self.selecting = false
|
|
return self
|
|
end
|
|
|
|
function MoveLearnMenu:monName()
|
|
return self.mon.nickname or self.game.data.pokemon[self.mon.species].name
|
|
end
|
|
|
|
-- TryingToLearnText + yes/no (learn_move.asm TryingToLearn): NO offers
|
|
-- AbandonLearning, whose own NO loops back here (DontAbandonLearning).
|
|
-- Use TextBox opts.choice so YES/NO overlays the still-visible prompt;
|
|
-- pushing ChoiceBox from onDone pops the text first and leaves YES/NO
|
|
-- on "Which move should be forgotten?" (#173).
|
|
function MoveLearnMenu:enter()
|
|
local TextBox = require("src.render.TextBox")
|
|
local game = self.game
|
|
local mdef = game.data.moves[self.newMoveId]
|
|
local name = self:monName()
|
|
self.selecting = false
|
|
-- _TryingToLearnText is the whole exchange in pokered, delete prompt
|
|
-- included, so the extracted line carries all four slots at once
|
|
game.stack:push(TextBox.new(game,
|
|
romText(game.data, "_TryingToLearnText",
|
|
"%s is\ntrying to learn\v%s!\fBut, %s\ncan't learn more\vthan 4 moves!\f"
|
|
.. "Delete an older\nmove to make room\vfor %s?",
|
|
name, mdef.name, name, mdef.name),
|
|
nil, {
|
|
choice = function(yes)
|
|
if yes then
|
|
self.selecting = true
|
|
else
|
|
self:confirmAbandon()
|
|
end
|
|
end,
|
|
}))
|
|
end
|
|
|
|
function MoveLearnMenu:update(dt)
|
|
if not self.selecting then return end
|
|
local input = self.game.input
|
|
-- wMaxMenuItem = wNumMovesMinusOne, no CANCEL row
|
|
-- engine/pokemon/learn_move.asm:144 (#1686)
|
|
local n = #self.mon.moves
|
|
if input:wasPressed("up") then
|
|
self.index = self.index > 1 and self.index - 1 or n
|
|
elseif input:wasPressed("down") then
|
|
self.index = self.index < n and self.index + 1 or 1
|
|
elseif input:wasPressed("b") then
|
|
self:confirmAbandon()
|
|
elseif input:wasPressed("a") then
|
|
local old = self.mon.moves[self.index]
|
|
if HM_MOVES[old.id] then
|
|
-- HMCantDeleteText, then back to the forget list
|
|
local TextBox = require("src.render.TextBox")
|
|
self.game.stack:push(TextBox.new(self.game,
|
|
romText(self.game.data, "_HMCantDeleteText",
|
|
"HM techniques\ncan't be deleted!")))
|
|
return
|
|
end
|
|
local mdef = self.game.data.moves[self.newMoveId]
|
|
self.mon.moves[self.index] = { id = self.newMoveId, pp = mdef.pp }
|
|
self.forgot = self.game.data.moves[old.id].name
|
|
self:finish(true)
|
|
end
|
|
end
|
|
|
|
-- AbandonLearning (learn_move.asm): "Abandon learning MOVE?" YES/NO
|
|
-- before giving up; NO returns to the TryingToLearn prompt
|
|
-- (DontAbandonLearning)
|
|
function MoveLearnMenu:confirmAbandon()
|
|
local TextBox = require("src.render.TextBox")
|
|
local game = self.game
|
|
local mdef = game.data.moves[self.newMoveId]
|
|
self.selecting = false
|
|
game.stack:push(TextBox.new(game,
|
|
romText(game.data, "_AbandonLearningText",
|
|
"Abandon learning\n%s?", mdef.name), nil, {
|
|
choice = function(yes)
|
|
if yes then self:finish(false) else self:enter() end
|
|
end,
|
|
}))
|
|
end
|
|
|
|
function MoveLearnMenu:finish(learned)
|
|
local TextBox = require("src.render.TextBox")
|
|
local game = self.game
|
|
local name = self:monName()
|
|
local mdef = game.data.moves[self.newMoveId]
|
|
self.selecting = false
|
|
game.stack:pop()
|
|
local msg
|
|
local opts
|
|
if learned then
|
|
-- pokered pages this as four texts in a row; _ForgotAndText carries
|
|
-- the "And..." tail
|
|
msg = romText(game.data, "_OneTwoAndText", "1, 2 and...")
|
|
.. romText(game.data, "_PoofText", " Poof!")
|
|
.. romText(game.data, "_ForgotAndText",
|
|
"\f%s forgot\n%s!\fAnd...", name, self.forgot)
|
|
.. "\f" .. romText(game.data, "_LearnedMove1Text",
|
|
"%s learned\n%s!", name, mdef.name)
|
|
opts = { auto = { sound = function()
|
|
return require("src.core.Sound").play(game.data, self.learnedSound)
|
|
end, wait = true } }
|
|
else
|
|
msg = romText(game.data, "_DidNotLearnText",
|
|
"%s\ndid not learn\v%s!", name, mdef.name)
|
|
end
|
|
game.stack:push(TextBox.new(game, msg, function()
|
|
if self.onDone then self.onDone(learned) end
|
|
end, opts))
|
|
end
|
|
|
|
function MoveLearnMenu:draw()
|
|
if not self.selecting then return end
|
|
-- TextBoxBorder 4,7 b=4 c=14; PlaceString 6,8; cursor 5,8
|
|
-- engine/pokemon/learn_move.asm:123-140 (#1686)
|
|
Font.drawBox(4, 7, 16, 6)
|
|
love.graphics.setColor(0, 0, 0, 1)
|
|
for i, mv in ipairs(self.mon.moves) do
|
|
Font.draw(self.game.data.moves[mv.id].name, 48, (7 + i) * 8)
|
|
end
|
|
Font.drawCode(CURSOR, 40, (7 + self.index) * 8)
|
|
-- WhichMoveToForgetText in the bottom dialogue box
|
|
Font.drawBox(0, 12, 20, 6)
|
|
Font.draw(Strings("Which move should"), 8, 14 * 8)
|
|
Font.draw(Strings("be forgotten?"), 8, 16 * 8)
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
end
|
|
|
|
return MoveLearnMenu
|