Resolve Ruby and Sapphire's party menu actions once per menu

Data.drawActions looked each action's text up in the script cache on every frame. It now draws the texts the party menu resolves once for each action list (action_texts, exposed as PartyMenu._actionTextsFor), as Emerald's and FireRed's menus already do.
This commit is contained in:
thibautbus
2026-10-06 16:53:29 +02:00
parent 6a5d69adb8
commit 117af9f40c
3 changed files with 17 additions and 1 deletions
+1
View File
@@ -137,6 +137,7 @@ local function action_texts(list)
PartyMenu._actionTexts = { list = list, texts = texts }
return texts
end
PartyMenu._actionTextsFor = action_texts
local FR_INSETS = { msgX = 2, msgY = 2, actX = 9, actY = 2, cursorX = 1 }
local function textInsets()
+2 -1
View File
@@ -179,7 +179,8 @@ function Data.drawActions(ui, item)
local Font = require("src.ui.game3.frlg_font")
prompt(item and ui._submenuKind ~= "MAIL" and 13 or 5, item and (ui._submenuKind == "MAIL" and 18 or 21) or 17)
require("src.ui.game3.chrome").stdFrame(left + 1, top + 1, width - 1, count * 2)
for i, action in ipairs(actions) do Font.draw(Data.actionText(action, ui._fieldMoveData), (left + 1) * 8, (top + 1) * 8 + (i - 1) * 16,
local texts = ui._actionTextsFor(actions)
for i in ipairs(actions) do Font.draw(texts[i], (left + 1) * 8, (top + 1) * 8 + (i - 1) * 16,
require("src.ui.game3.rs.party_chrome").textOptions("menu")) end
local cursor = item and ui.itemActionCursor or ui.actionCursor
require("src.ui.game3.rs.menu_cursor").draw((left + 1) * 8, (top + 1) * 8 + (cursor - 1) * 16, (width - 1) * 8)
@@ -242,6 +242,20 @@ check(PartyData.actionText("SUMMARY") == "RESUME", "a party action reads the cac
check(PartyData.actionText("TAKE_MAIL") == "PRENDRE", "the mail's TAKE reads its own label")
check(PartyData.actionText("SWITCH") == "SWITCH", "an action missing from the cache keeps the pack's copy")
check(PartyData.actionText("CUT", { index = { CUT = 0 }, moves = { 15 } }) == "COUPE", "a field move prints its move's name")
MANIFESTS["rse/party"] = { prompts = setmetatable({}, { __index = function() return "PROMPT" end }) }
local drawn, resolved = {}, 0
local font, chrome, cursor, partyChrome = package.loaded["src.ui.game3.frlg_font"], package.loaded["src.ui.game3.chrome"],
package.loaded["src.ui.game3.rs.menu_cursor"], package.loaded["src.ui.game3.rs.party_chrome"]
package.loaded["src.ui.game3.frlg_font"] = { draw = function(text) drawn[#drawn + 1] = text end }
package.loaded["src.ui.game3.chrome"] = { stdFrame = function() end }
package.loaded["src.ui.game3.rs.menu_cursor"] = { draw = function() end }
package.loaded["src.ui.game3.rs.party_chrome"] = { textOptions = function() return {} end }
local menu = { ACTIONS = { "SUMMARY", "CANCEL" }, actionCursor = 1,
_actionTextsFor = function(list) resolved = resolved + 1 return { "RESUME", "RETOUR" } end }
PartyData.drawActions(menu, false)
check(drawn[2] == "RESUME" and drawn[3] == "RETOUR" and resolved == 1, "the action menu draws the texts resolved for its list")
package.loaded["src.ui.game3.frlg_font"], package.loaded["src.ui.game3.chrome"] = font, chrome
package.loaded["src.ui.game3.rs.menu_cursor"], package.loaded["src.ui.game3.rs.party_chrome"] = cursor, partyChrome
if failed > 0 then
print(failed .. " check(s) failed")
os.exit(1)