mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-28 20:08:51 -04:00
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
189 lines
12 KiB
Python
189 lines
12 KiB
Python
"""The options menu drawn as the game's own Options screen looks (gpu/vk/vk_game_tex.h, vk_ui.h, vk_menu.cpp; no game).
|
|
|
|
The colours are the game's layouts' own (UI/Layout2Archive/Common.*.blarc: each pane's material has a white and a black
|
|
colour, linear, and its texture picks between them), written into vk_game_tex.h and vk_ui.h as numbers. This compiles
|
|
vk_game_tex.h's makers with made-up textures and checks what they give against the game's Options screen as measured:
|
|
|
|
- the chosen value's orange plate is 212,145,37 where its texture is white (measured 211,144,37), darker where the
|
|
texture is grey, as the game's: not the texture times one colour, which made its middle 168,115,29;
|
|
- the value's dark panel, the chosen tab's plate and a mask (white) take their white colour where the texture is white
|
|
and their black colour where it is black, the texture's alpha kept;
|
|
- a row's plate is darker at its rim (98,74,37 measured) than in its middle (111,84,44), where the grain texture is
|
|
white and dark: the browns ran the other way before;
|
|
- the standalone background's shade is shrunk without changing its mean.
|
|
|
|
And reads the source for what only the game shows: inside the game's own Options screen nothing dims the game's own
|
|
background and only the opaque middle of the column is drawn over the game's identical one (its soft edges stay single);
|
|
over play the System screens' shade and noise, or the flat dim without them; the two textures that needs are optional,
|
|
so a romfs without them keeps the rest of the game's look; the plates, the tab and the separator use the layouts'
|
|
colours.
|
|
|
|
python -I -B tests/test_menu_vanilla_look.py [--cxx clang++]
|
|
"""
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
VK = ROOT / "gpu" / "vk"
|
|
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
|
|
|
|
|
def check(ok, why):
|
|
if not ok:
|
|
raise SystemExit("FAIL: " + why)
|
|
|
|
|
|
def function(text, head):
|
|
start = text.index(head)
|
|
end = text.index("{", start) + 1
|
|
depth = 1
|
|
while depth:
|
|
depth += (text[end] == "{") - (text[end] == "}")
|
|
end += 1
|
|
return text[start:end]
|
|
|
|
|
|
PROGRAM = r"""
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include "vk_game_tex.h"
|
|
using namespace mkwvk::game_tex;
|
|
static int fails = 0;
|
|
static void near(const unsigned char* px, int r, int g, int b, int a, int tol, const char* what) {
|
|
if (std::abs(px[0] - r) > tol || std::abs(px[1] - g) > tol || std::abs(px[2] - b) > tol || px[3] != a) {
|
|
std::printf("FAIL: %s: %d,%d,%d,%d, not %d,%d,%d,%d\n", what, px[0], px[1], px[2], px[3], r, g, b, a);
|
|
fails++;
|
|
}
|
|
}
|
|
static Image grey(std::initializer_list<int> values, bool srgb, int alpha = 255) {
|
|
Image im;
|
|
im.w = (uint32_t)values.size(), im.h = 1, im.srgb = srgb;
|
|
for (int v : values) im.rgba.insert(im.rgba.end(), {(unsigned char)v, (unsigned char)v, (unsigned char)v, (unsigned char)alpha});
|
|
return im;
|
|
}
|
|
int main() {
|
|
// the chosen value's plate (W_CheckL_00): white texel the white colour, the measured orange; grey darker, as the game's
|
|
const Image el = grey({255, 203, 0}, true);
|
|
const Image on = make_tinted(el, kValueOnBlack, kValueOnWhite);
|
|
near(&on.rgba[0], 211, 144, 37, 255, 1, "the orange plate where its texture is white");
|
|
near(&on.rgba[4], 191, 126, 31, 255, 2, "the orange plate where its texture is 203 (its middle)");
|
|
near(&on.rgba[8], 153, 89, 19, 255, 1, "the orange plate where its texture is black");
|
|
// the value's dark panel (W_Base_01) and the tab (P_PlusMenuBg_00)
|
|
const Image panel = make_tinted(el, kValueBlack, kValueWhite);
|
|
near(&panel.rgba[0], 15, 14, 11, 255, 1, "the value's panel where its texture is white");
|
|
near(&panel.rgba[8], 51, 45, 27, 255, 1, "the value's panel where its texture is black");
|
|
const Image tab = make_tinted(grey({255, 0}, true, 128), kTabBlack, kTabWhite);
|
|
near(&tab.rgba[0], 146, 113, 66, 128, 1, "the tab's plate where its texture is white (its alpha kept)");
|
|
near(&tab.rgba[4], 50, 13, 0, 128, 1, "the tab's plate where its texture is black");
|
|
// a mask (BC4: white, its strength in alpha) is its white colour
|
|
Image mask = grey({255}, false, 77);
|
|
near(&make_tinted(mask, kValueOnBlack, kValueOnWhite).rgba[0], 212, 145, 37, 77, 1, "a mask tinted");
|
|
// a row's plate: the grain white at the rim, dark in the middle; the line over it where its mask is
|
|
Image shape = grey({255, 255, 255}, true), grain = grey({250, 80, 0}, true), line = grey({255, 255, 255}, false, 0);
|
|
line.rgba[2 * 4 + 3] = 255;
|
|
const Image plate = make_plate(shape, grain, &line, kPlateBlack, kPlateWhite, kPlateLine);
|
|
near(&plate.rgba[0], 98, 74, 37, 255, 2, "a row's plate at its rim (the grain white)");
|
|
near(&plate.rgba[4], 111, 84, 44, 255, 2, "a row's plate in its middle (the grain dark)");
|
|
near(&plate.rgba[8], 124, 104, 62, 255, 1, "a row's plate under its line");
|
|
if (plate.rgba[0] >= plate.rgba[4]) std::printf("FAIL: the plate's rim is not darker than its middle\n"), fails++;
|
|
// the shade shrunk: each texel its block's mean
|
|
Image big;
|
|
big.w = 8, big.h = 4, big.mask = true;
|
|
big.rgba.assign(8 * 4 * 4, 255);
|
|
for (int i = 0; i < 32; i++) big.rgba[i * 4 + 3] = (unsigned char)((i % 8) < 4 ? 0 : 200);
|
|
const Image small = shrink_mask(big, 4);
|
|
if (small.w != 2 || small.h != 1 || small.rgba[3] != 0 || small.rgba[7] != 200 || !small.mask)
|
|
std::printf("FAIL: shrink_mask: %ux%u %d %d\n", small.w, small.h, small.rgba[3], small.rgba[7]), fails++;
|
|
return fails ? 1 : 0;
|
|
}
|
|
"""
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--cxx", default="clang++")
|
|
args = parser.parse_args()
|
|
tex = (VK / "vk_game_tex.h").read_text(encoding="utf-8")
|
|
ui = (VK / "vk_ui.h").read_text(encoding="utf-8")
|
|
menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
|
|
|
|
# the background: inside the game's Options screen, its own; over play, the System screens' shade and noise
|
|
# (v0.5.1: draw_menu takes perf_under, and over the Mods entry (row) dims nothing)
|
|
draw = function(menu, "void draw_menu(ui::Ctx& c, bool perf_under) {")
|
|
# ((Triforce) not the tuning bar; (11-26) not Save Select over the title either, whose picture behind is out of focus)
|
|
check("if (!embed_open && !row && !tuning && !blurred && !ui::system_bg(c)) c.d->AddRectFilled(" in draw and
|
|
"const bool blurred = files_blur.load(std::memory_order_relaxed) && page == kFilesPage;" in draw,
|
|
"draw_menu dims the game's own Options screen, or not the System screens' way over play")
|
|
check(draw.count("AddRectFilled(ImVec2(0, 0), ImVec2(c.w, c.h)") == 1, "draw_menu dims the window more than once")
|
|
check("ui::column_bg(k, cx0, cx1, k.over_game);" in draw and "k.over_game = embed_open;" in draw,
|
|
"over the game's Options screen the column is not only its opaque middle")
|
|
column = function(ui, "inline void column_bg(")
|
|
check("60.0f / 1440" in column and "1380.0f / 1440" in column and "PushClipRect(clip0, clip1, true)" in column,
|
|
"column_bg's inner part is not the texture's opaque middle")
|
|
check("at(c, 0, 1240 + 2500)" in column and "at(c, 0, 1240 - 2500)" in column and "lu(c, 20)" in column,
|
|
"column_bg is not P_OptionBg_00's place (2240 x 5000 units, 1240 up, seen through S_Scissor_00)")
|
|
bg = function(ui, "inline bool system_bg(")
|
|
check('skin("SystemBgSh_00")' in bg and 'skin("DecoNoise_00")' in bg and "return false;" in bg, "system_bg does not fall back")
|
|
check("kNoiseAlpha = 102, kShadeAlpha = 179;" in ui, "the shade and the noise are not the layout's 0.7 and 0.4")
|
|
game = ui[ui.index("constexpr Palette kGamePalette = {"):]
|
|
game = game[:game.index("};")]
|
|
check(game.split("{", 1)[1].strip().startswith("rgba(255, 254, 228)") and "rgba(75, 57, 34), rgba(28, 13, 13), 0" in game and
|
|
"inline ImU32 kInk = kGamePalette.ink," in ui, "vk_ui.h's colours (the game's look, the Menu theme's default) are not the layouts' own")
|
|
# (v0.5.1: the colour is a parameter, the performance overlay asks for its own; kSeparator is its default)
|
|
check("ImU32 col = kSeparator, ImU32 line_col = 0) {" in ui, "the separator is not the layout's colour")
|
|
|
|
# the skin: the two background textures optional; the baked plates made and used
|
|
skin = function(tex, "inline bool make_skin(")
|
|
names = re.search(r"names\[\] = \{(.*?)\};", skin, re.S).group(1)
|
|
optional = re.search(r"optional\[\] = \{(.*?)\};", skin, re.S).group(1)
|
|
check("SystemBgSh_00" not in names and "DecoNoise_00" not in names, "a background texture is a required one")
|
|
check('"SystemBgSh_00", "DecoNoise_00"' in optional, "the background textures are not the optional ones")
|
|
loop = skin[skin.index("for (const char* n : optional)"):]
|
|
loop = loop[:loop.index("\n }\n") + 6]
|
|
check("continue;" in loop and "return false" not in loop, "a missing optional texture throws the skin away")
|
|
for made in ('"value_plate", make_tinted(*element, kValueBlack, kValueWhite)',
|
|
'"value_plate_on", make_tinted(*element, kValueOnBlack, kValueOnWhite)',
|
|
'"tab_select", make_tinted(*tab, kTabBlack, kTabWhite)',
|
|
'"plate_row", make_plate(*shape, *grain, skin.get("BtnThinBase_04"), kPlateBlack, kPlateWhite, kPlateLine)'):
|
|
check(made in skin, "make_skin does not make " + made.split(",")[0])
|
|
# ((Triforce, 11-26) the cursors' glows as the game's, fitted to the lab's SDR shots: the Options rows' falloff 1.35, the
|
|
# System list's own cursor (CmnBtnCursor*, for our buttons) 1.25, optional; their colours and strengths in vk_ui.h)
|
|
check('&line.img, &glow.img, 1.35f);' in skin and 'make_cursor(cmn_line, cmn_glow, &cl.img, &cg.img, 1.25f);' in skin and
|
|
'if (el && eg && bntx.decode(*el, cmn_line)' in skin, "make_skin does not make the cursors with the game's falloffs")
|
|
check("std::pow(std::clamp(g / 0.36f, 0.0f, 1.0f), falloff)" in function(tex, "inline void make_cursor("),
|
|
"make_cursor's glow does not take the falloff it is given")
|
|
check("rgba(163, 184, 255)" in ui and "constexpr ImU32 kCmnCursorGlow = rgba(125, 161, 255);" in ui and
|
|
"kCursorGlowBase = 0.76f, kCmnCursorGlowBase = 0.68f, kCursorGlowBreath = 0.08f;" in ui,
|
|
"the cursors' glows are not the game's measured ones")
|
|
# ((Triforce, 11-26) with HDR on, the glows in two layers fitted to the game's as RenoDX codes it: the overlay blends on
|
|
# HDR10's PQ codes, where one layer came out narrow and grey; with SDR once, as measured)
|
|
check("constexpr GlowLayer kCursorGlowHdr[2] = {{rgba(144, 174, 255), 0.698f}, {rgba(143, 159, 255), 0.690f}};" in ui and
|
|
"constexpr GlowLayer kCmnCursorGlowHdr[2] = {{rgba(85, 116, 255), 0.627f}, {rgba(110, 159, 254), 0.622f}};" in ui,
|
|
"the glows' HDR layers are not the fitted ones")
|
|
layers = function(ui, "inline void glow_layers(")
|
|
check("if (!c.hdr10) {" in layers and "nine(c, t, a, b, bx, by, alpha(col, s * k));" in layers and
|
|
"const float r = s / (base + kCursorGlowBreath * 0.5f) * k;" in layers and
|
|
"for (const GlowLayer& l : hdr) nine(c, t, a, b, bx, by, alpha(l.col, l.a * r));" in layers,
|
|
"glow_layers does not draw once with SDR and the two layers, breathing, with HDR on")
|
|
check("c.hdr10 = dev.hdr;" in function(menu, "ui::Ctx ui_ctx("), "ui_ctx does not say when the overlay blends on HDR10's codes")
|
|
plate = function(ui, "inline void value_plate(")
|
|
check('skin(on ? "value_plate_on" : "value_plate")' in plate and "alpha(IM_COL32_WHITE, k)" in plate,
|
|
"value_plate does not draw the baked plates untinted")
|
|
check('ui::skin("tab_select")) ui::image(c, t, a, b);' in function(menu, "void draw_tabs("), "the chosen tab is not the baked plate")
|
|
|
|
with tempfile.TemporaryDirectory(prefix="vanilla-look-") as tmp:
|
|
src, exe = Path(tmp) / "look.cpp", Path(tmp) / "look.exe"
|
|
src.write_text(PROGRAM, encoding="utf-8")
|
|
inc = [VK, ROOT / "gpu" / "third_party" / "suyu", VK / "compat", ROOT / "gpu" / "compat"]
|
|
subprocess.run([args.cxx, "-std=c++20", "-O1", "-w", *("-I" + str(p) for p in inc), str(src), "-o", str(exe)], check=True)
|
|
r = subprocess.run([str(exe)], capture_output=True, text=True)
|
|
check(r.returncode == 0, "the colours as made:\n" + r.stdout)
|
|
print("PASS: the menu's plates, tab, separator and background in the game's layouts' colours")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|