Merge pull request #1098 into task/kbmwave

This commit is contained in:
Valiantsin Dzerakh committed 2026-11-11 13:10:00 +03:00
commit 6ec533524c
12 files changed
+118 -21

No files matched your search

+3 -2
View File
@@ -65,7 +65,7 @@ At a game resolution of another shape than 16:9 the game loads `romfs-patches-xb
| Switch | Prompt |
|---|---|
| A, B, X, Y | E, Shift, Space, left click |
| A, B, X, Y | E, Shift, Space, left click (T in text prompts) |
| L, R, ZL, ZR | Q, R, right click, F |
| Plus, Minus | Tab, M |
| D-pad | 1 (left), 2 (up), 3 (right), 4 (down), as a cross or the keys of the directions meant |
@@ -74,7 +74,8 @@ At a game resolution of another shape than 16:9 the game loads `romfs-patches-xb
- The glyphs keep the width of the game's own, so the right-aligned guides do not run into their text. A key is a rounded square with its label cut out in the game's own text fonts (Shift: an arrow over its name); a mouse button is a mouse with that button filled and the others hollow.
- The button guide in play draws every button from images of the Common archive (`Nt_KeyTexA/B/X/Y/L/ZL_00`, `Nt_KeyTexLSt_00` and `_01`, the stick tilted and pressed): all of them are painted with the same icons. The letters of the action prompt's diamond are one character of the Normal font each: E, an arrow for Shift, a bar for Space, L and R for the mouse buttons.
- Like the Xbox prompts they follow the defaults and not the bindings. `--binds <totk.ini>` draws the first key of each `bind_` line of that file instead, for a folder made by hand.
- Y has two keys, the left mouse button and T. The button guide in play and the action prompt show the left button, which attacks there; the prompts in text (the menus' guides such as *Sort*, the dialogue log's) show T, because while a menu has the pointer the left button is that menu's A, and T presses Y everywhere (`PC_TEXT_KEYS` in `tools/button_icons.py`). With a `bind_y` line, the text prompts take its first key that is not a mouse button (its only key when all are mouse buttons).
- They follow the bindings of the install's `totk.ini` as the setup found them: its *Drawing the keyboard and mouse prompts* step passes the file as `--binds` (the first key of each `bind_` line), and the keyboard defaults without one. After a change on the Controls tab run the setup again: that step alone runs, since it is keyed by the `bind_` lines (`PcPrompts` in `installer/steps.py`). The Xbox prompts follow the defaults.
- At a game resolution of another shape than 16:9 the game loads `romfs-patches-pc-<w>x<h>` in place of `romfs-patches-<w>x<h>`: the same prompts with that shape's UI layout, `make_romfs_patches.py --prompts pc --aspect <w>x<h> --reuse <install>\romfs-patches-pc --out <install>\romfs-patches-pc-<w>x<h>`. The setup writes one for each of the fifteen sizes it lays the UI out for, so on a display of one of those shapes the game resolution follows the display with these prompts too. At another size, without that folder, the Switch prompts stay (*off at this game resolution*).
## Window keys
+1 -1
View File
@@ -619,7 +619,7 @@ class App:
# ---- self test ---------------------------------------------------------------------------------------------------
SAMPLE_START = {'type': 'start', 'release': 'selftest', 'mode': 'install', 'dest': 'Z:/selftest/TotK', 'log': 'D:\\log.txt',
'steps': ['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'dlss', 'cleanup']}
'steps': ['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'pc_prompts', 'dlss', 'cleanup']}
SAMPLE_RUN = [
SAMPLE_START,
{'type': 'plan', 'run': ['check', 'fonts', 'extract'], 'skip': {}},
+1 -1
View File
@@ -27,7 +27,7 @@ TEXT = Path(__file__).resolve().parent / 'text'
UI_LANGUAGES = ('en', 'ru', 'pt-BR', 'zh-Hans')
# what the language switch in the window's corner shows for each
UI_LANGUAGE_LABELS = {'en': 'English', 'ru': 'Русский', 'pt-BR': 'Português (Brasil)', 'zh-Hans': '简体中文'}
STEP_ORDER = ('check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'dlss', 'cleanup')
STEP_ORDER = ('check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'pc_prompts', 'dlss', 'cleanup')
# message parameter -> catalog id prefix of the names that replace its raw values
PARAM_NAMES = {'lang': 'lang.', 'known': 'lang.', 'step': 'step.', 'input': 'param.input.'}
LANG_RU = 0x19 # primary language id of Russian in a Windows LANGID
+62 -5
View File
@@ -1098,10 +1098,10 @@ class Prepare(Step):
# romfs-patches-xbox for the Nintendo pad layout, romfs-patches-xbox-label for xbox and auto (runtime/input_map.c
# input_prompts_folder). Both are written on every install, so the menu choices work without another run of
# the setup. Optional: when one fails, the game keeps the Switch prompts with that layout and the menu says the
# files are missing, so the setup warns once and goes on. romfs-patches-pc likewise, with keyboard and mouse
# prompts for prompts = pc.
# files are missing, so the setup warns once and goes on. The keyboard and mouse prompts are the PcPrompts
# step's: they follow totk.ini's bindings.
failed = None
for style in ('xbox', 'xbox-label', 'pc'):
for style in ('xbox', 'xbox-label'):
out = dest / f'romfs-patches-{style}'
remove(out)
code, log = run_tool(ctx, f'prepare-{style}', layout.tools / 'make_romfs_patches.py',
@@ -1116,7 +1116,7 @@ class Prepare(Step):
# the prompts and the screen's shape. Only the Common archive differs from romfs-patches-<style>; --reuse links
# the fonts, messages and size table from there instead of compressing them again, so each folder takes
# seconds and a few MiB. Optional like romfs-patches-<style>, and skipped without it.
for style in ('xbox', 'xbox-label', 'pc'):
for style in ('xbox', 'xbox-label'):
plain = dest / f'romfs-patches-{style}'
for size in ASPECT_SIZES:
out = dest / f'romfs-patches-{style}-{size}'
@@ -1167,6 +1167,63 @@ class Prepare(Step):
return {'xlate_sha256': file_sha256(xlate)}
# ---- 6b. Keyboard and mouse prompts
def bind_lines(dest):
"""The bind_ lines of the install's totk.ini (the Controls tab writes them), '' without the file."""
try:
text = (dest / 'totk.ini').read_text(encoding='utf-8', errors='replace')
except OSError:
return ''
return '\n'.join(s for s in (line.split('#')[0].split(';')[0].strip() for line in text.splitlines())
if s.lower().startswith('bind_'))
class PcPrompts(Step):
"""romfs-patches-pc and romfs-patches-pc-<w>x<h>, for prompts = pc: the prompts drawn as the keys and mouse buttons
of totk.ini's bind_ lines (make_romfs_patches.py --prompts pc --binds), the keyboard defaults without them. Its own
step, keyed by those lines, so running the setup again after a change of the bindings draws the prompts again and
leaves the shaders alone. Optional like the Xbox prompts: a failure warns, and the game keeps the Switch prompts."""
id = 'pc_prompts'
def key(self, ctx):
layout = ctx.layout
tools = [layout.tools / n for n in ('make_romfs_patches.py', 'ultrawide_layout.py', 'button_icons.py')]
return fingerprint('pc-prompts-1', ctx.keys['extract'], *tools, bind_lines(ctx.dest))
def current(self, ctx, record):
return record.get('failed') or (ctx.dest / 'romfs-patches-pc' / 'manifest.tsv').is_file()
def run(self, ctx):
layout, rep, dest = ctx.layout, ctx.reporter, ctx.dest
rep.progress('pc_prompts', 'draw', force=True)
binds = []
if bind_lines(dest):
binds = ['--binds', dest / 'totk.ini']
version = ['--version', version_tag(game_version(ctx)), '--romfs', dest / 'romfs']
plain = dest / 'romfs-patches-pc'
for out in [plain] + [dest / f'romfs-patches-pc-{size}' for size in ASPECT_SIZES]:
remove(out)
code, log = run_tool(ctx, 'prepare-pc', layout.tools / 'make_romfs_patches.py',
version + ['--out', plain, '--prompts', 'pc', *binds])
failed = (code, log) if code else None
# Each shape of ASPECT_SIZES once more, as for the Xbox prompts (Prepare): --reuse links all but the Common
# archive from romfs-patches-pc.
for size in ASPECT_SIZES if not failed else ():
out = dest / f'romfs-patches-pc-{size}'
code, log = run_tool(ctx, f'prepare-pc-{size}', layout.tools / 'make_romfs_patches.py',
version + ['--out', out, '--prompts', 'pc', '--aspect', size, '--reuse', plain, *binds])
if code:
remove(out)
failed = failed or (code, log)
if failed:
if not (plain / 'manifest.tsv').is_file():
remove(plain)
rep.warning('warn.xbox_prompts_failed', code=failed[0], log=str(failed[1]))
return {'failed': True}
return {}
# ---- 7. NVIDIA DLSS
# NVIDIA's DLSS library, which NGX loads from the folder of totk.exe (runtime/vk_dlaa.c). The setup does not ship it:
@@ -1310,4 +1367,4 @@ def romfs_problem(romfs, expected):
def all_steps():
return [Check(), Fonts(), Extract(), Lift(), Compile(), Prepare(), Dlss(), Cleanup()]
return [Check(), Fonts(), Extract(), Lift(), Compile(), Prepare(), PcPrompts(), Dlss(), Cleanup()]
+2
View File
@@ -5,6 +5,7 @@
"step.lift": "Translating the game code to C",
"step.compile": "Compiling {game_exe}",
"step.prepare": "Preparing the shaders",
"step.pc_prompts": "Drawing the keyboard and mouse prompts",
"step.dlss": "Downloading NVIDIA DLSS",
"step.cleanup": "Cleaning up",
@@ -29,6 +30,7 @@
"phase.compile.compile": "Compiling",
"phase.compile.link": "Linking {game_exe}",
"phase.prepare.romfs_patches": "Writing the 60 fps game data patches",
"phase.pc_prompts.draw": "Drawing the keyboard and mouse button prompts from totk.ini's bindings",
"phase.prepare.seed": "Reading the shaders from the game data",
"phase.prepare.translate": "Translating the shaders",
"phase.prepare.libraries": "Building the shaders for the graphics driver",
+2
View File
@@ -5,6 +5,7 @@
"step.lift": "Traduzindo o código do jogo para C",
"step.compile": "Compilando o {game_exe}",
"step.prepare": "Preparando os shaders",
"step.pc_prompts": "Desenhando os ícones de teclado e mouse",
"step.dlss": "Baixando o NVIDIA DLSS",
"step.cleanup": "Finalizando",
@@ -29,6 +30,7 @@
"phase.compile.compile": "Compilando",
"phase.compile.link": "Ligando o {game_exe}",
"phase.prepare.romfs_patches": "Gravando os patches de 60 fps nos dados do jogo",
"phase.pc_prompts.draw": "Desenhando os ícones de teclas e botões do mouse a partir das atribuições do totk.ini",
"phase.prepare.seed": "Lendo os shaders dos dados do jogo",
"phase.prepare.translate": "Traduzindo os shaders",
"phase.prepare.libraries": "Montando os shaders para o driver de vídeo",
+2
View File
@@ -5,6 +5,7 @@
"step.lift": "Перевод кода игры в C",
"step.compile": "Сборка {game_exe}",
"step.prepare": "Подготовка шейдеров",
"step.pc_prompts": "Рисование подсказок клавиатуры и мыши",
"step.dlss": "Загрузка NVIDIA DLSS",
"step.cleanup": "Уборка",
@@ -29,6 +30,7 @@
"phase.compile.compile": "Компиляция",
"phase.compile.link": "Компоновка {game_exe}",
"phase.prepare.romfs_patches": "Запись патчей данных игры для 60 кадров/с",
"phase.pc_prompts.draw": "Рисование подсказок клавиш и кнопок мыши по назначениям из totk.ini",
"phase.prepare.seed": "Чтение шейдеров из данных игры",
"phase.prepare.translate": "Трансляция шейдеров",
"phase.prepare.libraries": "Сборка шейдеров для драйвера видеокарты",
+2
View File
@@ -5,6 +5,7 @@
"step.lift": "将游戏代码转换为 C 代码",
"step.compile": "编译 {game_exe}",
"step.prepare": "准备着色器",
"step.pc_prompts": "绘制键盘和鼠标按键提示",
"step.dlss": "下载 NVIDIA DLSS",
"step.cleanup": "清理",
@@ -29,6 +30,7 @@
"phase.compile.compile": "编译",
"phase.compile.link": "链接 {game_exe}",
"phase.prepare.romfs_patches": "写入 60 帧游戏数据补丁",
"phase.pc_prompts.draw": "根据 totk.ini 中的按键绑定绘制键盘和鼠标按键提示",
"phase.prepare.seed": "从游戏数据中读取着色器",
"phase.prepare.translate": "转译着色器",
"phase.prepare.libraries": "为显卡驱动构建着色器",
+1 -1
View File
@@ -575,7 +575,7 @@ class FontsTest(unittest.TestCase):
def test_all_steps_order(self):
self.assertEqual([s.id for s in steps.all_steps()],
['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'dlss', 'cleanup'])
['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'pc_prompts', 'dlss', 'cleanup'])
def test_extracts_into_the_install_folder(self):
self.fake_tool()
+15
View File
@@ -528,7 +528,12 @@ class PromptsTest(unittest.TestCase):
drawn = font(sarc_files(romfs.read(out, DEFAULT_FONT))['scft/External.bfotf'])
advances = icons.font_advances(sarc_files(romfs.contents[DEFAULT_FONT])['scft/External.bfotf'])
pc = icons.pc_icons(icons.text_glyphs(romfs.text_fonts), advances)
text = icons.pc_icons(icons.text_glyphs(romfs.text_fonts), advances, icons.pc_binds(text=True))
self.assertIn(0xE05E, pc) # the left stick's W A S D
# In the font Y is T (PC_TEXT_KEYS); the button guide's Y image below stays the left mouse button
otf = unbfotf(sarc_files(romfs.contents[DEFAULT_FONT])['scft/External.bfotf'])
t = TTFont(io.BytesIO(icons.redraw_font(otf, {0xE043: text[0xE043]})))
self.assertEqual(glyph(drawn, 0xE043)[0], glyph(t, 0xE043)[0])
for cp in range(0xE040, 0xE069):
outline, advance = glyph(drawn, cp)
if cp in pc:
@@ -565,6 +570,16 @@ class PromptsTest(unittest.TestCase):
self.assertEqual({b: panes[f'T_{b}_00'] for b in PC_PANES}, {**PC_PANES, 'A': 'F'})
self.assertEqual(icons.pc_binds(ini.read_text(encoding='utf-8')), {**icons.PC_BINDS, 'A': 'f'})
def test_pc_text_prompts_show_y_as_its_first_key_that_is_not_a_mouse_button(self):
def y(line=None, text=True):
return icons.pc_binds(f'[input]\n{line}\n' if line else None, text=text)['Y']
self.assertEqual((y(), y(text=False)), ('t', 'mouse_l'))
self.assertEqual(y('bind_Y = pad:north, key:mouse_l, key:h'), 'h')
self.assertEqual(y('bind_Y = key:g, key:mouse_l'), 'g')
self.assertEqual(y('bind_Y = key:mouse_l'), 'mouse_l') # no key besides the mouse: the mouse button
self.assertEqual(y('bind_Y = key:default'), 't')
self.assertEqual(y('bind_Y = key:h, key:mouse_l', text=False), 'h')
def test_same_input_same_output_and_the_older_flag(self):
romfs = self.romfs['v121']
for flags in (('--prompts', 'xbox'), ('--xbox-prompts',)):
+17 -6
View File
@@ -18,7 +18,9 @@ start, MacNativeGames found).
The button guide in play (bottom right) draws its buttons, L and ZL among them, from images of the common layout
archive instead (timg/__Combined.bntx, Nt_KeyTexL_00 and Nt_KeyTexZL_00): bntx_redraw paints the same icons into them,
the size unchanged. The Xbox prompts redraw L and ZL, the keyboard and mouse ones every image (PC_HUD_TEXTURES: A, B, X,
Y, L, ZL and the stick's two). Prompts drawn as fixed images (some tutorial animations) keep the Switch icons.
Y, L, ZL and the stick's two) with the keys of pc_binds. The font's glyphs use pc_binds(text=True): a text prompt shows
Y as T, the button guide the left mouse button. Prompts drawn as fixed images (some tutorial animations) keep the
Switch icons.
Needs fontTools (tools/requirements-installer.txt, tools/requirements-py314.txt).
"""
@@ -212,12 +214,18 @@ PC_HUD_TEXTURES = {'Nt_KeyTexA_00': 0xE040, 'Nt_KeyTexB_00': 0xE041, 'Nt_KeyTexX
'Nt_KeyTexL_00': 0xE044, 'Nt_KeyTexZL_00': 0xE046, 'Nt_KeyTexLSt_00': 0xE052,
'Nt_KeyTexLSt_01': 0xE05E}
PC_MOUSE = ('mouse_l', 'mouse_r', 'mouse_m')
# The text prompts (the button font: the menus' guides, the dialogue log's) show Y as T, the key runtime/input_map.c
# binds next to the left mouse button: while a game menu has the pointer the left button is that menu's A
# (runtime/menu_cursor.c), and T presses Y everywhere. The button guide in play and the action prompt keep the left
# button (PC_BINDS), which attacks there.
PC_TEXT_KEYS = {'Y': 't'}
def pc_binds(ini_text=None):
def pc_binds(ini_text=None, text=False):
"""PC_BINDS with the first key of each bind_<action> line of a totk.ini text over it (a line without a key entry,
or with key:default, keeps the default)."""
binds = dict(PC_BINDS)
or with key:default, keeps the default). text: the binds the button font is drawn with, where a button of
PC_TEXT_KEYS shows its first key that is not a mouse button (PC_TEXT_KEYS's without a line)."""
binds = dict(PC_BINDS, **(PC_TEXT_KEYS if text else {}))
for line in (ini_text or '').splitlines():
line = line.split('#')[0].split(';')[0].strip()
if not line.lower().startswith('bind_') or '=' not in line:
@@ -225,8 +233,11 @@ def pc_binds(ini_text=None):
action, value = (s.strip() for s in line.split('=', 1))
keys = [e.strip()[4:].strip().lower() for e in value.split(',') if e.strip().lower().startswith('key:')]
keys = [k for k in keys if k != 'default']
if keys and action[5:].upper() in binds:
binds[action[5:].upper()] = keys[0]
button = action[5:].upper()
if text and button in PC_TEXT_KEYS:
keys = [k for k in keys if not k.startswith('mouse_')] or keys
if keys and button in binds:
binds[button] = keys[0]
return binds
+10 -5
View File
@@ -43,8 +43,10 @@ romfs-patches-xbox-label-<w>x<h>: the same prompts with that shape's UI layout.
--prompts pc: keyboard and mouse prompts, for prompts = pc (romfs-patches-pc, or romfs-patches-pc-<w>x<h> with
--aspect): every button of the button font is drawn as the key or mouse button the keyboard defaults put on it
(button_icons.pc_icons; --binds <totk.ini> takes the first key of its bind_ lines instead), and so are the button
guide's images (A, B, X, Y, L, ZL and the stick's two). The one-letter panes around the action prompt name the keys
with one character of the Normal font (E, an arrow for Shift, a bar for Space, L and R for the mouse buttons).
guide's images (A, B, X, Y, L, ZL and the stick's two). In the font Y is T, the key that presses it next to the left
mouse button, which is A in the game's menus (button_icons.PC_TEXT_KEYS); the button guide keeps the left button. The
one-letter panes around the action prompt name the keys with one character of the Normal font (E, an arrow for Shift,
a bar for Space, L and R for the mouse buttons).
--reuse <folder>: an overlay made before, such as romfs-patches-pc for romfs-patches-pc-<w>x<h>. Each file of it whose
contents match the new one is hard-linked (copied where links fail) instead of compressed again; the summary's reused
@@ -403,12 +405,15 @@ if args.prompts:
assert not missing, f'no {", ".join(missing)} in {icons.TEXT_ARCHIVE}'
glyphs = icons.text_glyphs(archives[icons.TEXT_ARCHIVE][slice(*text[name])] for name in icons.TEXT_FONTS)
if pc:
binds = icons.pc_binds(args.binds.read_text(encoding='utf-8', errors='replace') if args.binds else None)
ini = args.binds.read_text(encoding='utf-8', errors='replace') if args.binds else None
binds = icons.pc_binds(ini)
advances = icons.font_advances(archives[icons.TEXT_ARCHIVE][slice(*text[icons.FONT])])
drawn = icons.pc_icons(glyphs, advances, binds)
# The text prompts show Y as T (button_icons.PC_TEXT_KEYS); the button guide's images keep the left click
font_drawn = icons.pc_icons(glyphs, advances, icons.pc_binds(ini, text=True))
pane_letters = {letter: icons.pc_letter(binds[letter]) for letter in 'ABXY'}
else:
drawn = icons.xbox_icons(glyphs)
drawn = font_drawn = icons.xbox_icons(glyphs)
pane_letters = KEY_LETTERS
bntx = members['timg/__Combined.bntx'][0]
letters = {}
@@ -431,7 +436,7 @@ if args.prompts:
lo, hi = sarc_members(bfarc)[icons.FONT]
otf, key = icons.bfotf_decode(bfarc[lo:hi])
if otf not in fonts:
fonts[otf] = icons.redraw_font(otf, drawn, KEY_GLYPHS if by_position else ())
fonts[otf] = icons.redraw_font(otf, font_drawn, KEY_GLYPHS if by_position else ())
outputs[path] = sarc_replace(bfarc, {icons.FONT: icons.bfotf_encode(fonts[otf], key, bfarc[lo:hi])})
messages = {}
for path in MALS if letter_panes else []: