Files
d2r-mobile/dm/ios/tools/gen_vault_cover.py
T
2026-10-12 16:51:08 +08:00

50 lines
6.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# 编年史页底部盖板贴图(不要大黑块,用原版底板那一段):从宽个人页底图 StashPanelBGPersonal_wide.sprite(gen_widestash_art.py 生成)
# 裁格子下面整条(两边的环饰 + 中间的石面),存成同格式精灵图(构建时生成,不进仓库)。
# 为什么整条:第六页没有自己的底图(背景图表不能加第 6 项,见 wide_stash.py),游戏照画上一页的底图——个人页、共享页(多一个页码框)、
# 宝石 / 材料 / 符文页(魔盒凹槽)各不相同,再加上嵌入魔盒容器的「转化」「提取」两颗钮、原版的翻页箭头。整条盖住才和从哪页切来无关。
# (去掉翻页按钮下面那个原版黑框,按钮下移放大居中):改用个人页那张(没有页码框),并把中间的金币框抹成石面——
# 金币框左右两侧各有一段同一行的平石面,左半取左段的镜像、右半取右段的镜像(同行取样,明暗走向一致),正中 16 像素交叉淡入。
# 翻页箭头和页码是我们自己的控件(wide_stash.py 的 TouchV_PgL / PgR / Page),画在盖板上面;原版箭头被盖板压住,不再挖洞。
# 底图在面板里摆在 (-2, 100)、1 像素 = 2 布局单位(BankExpansionLayoutHD.json 的 background;宿主截图按金币框对位核过)。
# 用法:gen_vault_cover.py(构建时在 gen_widestash_art.py 之后跑,产物 Gen/assets/NativeHUD/widestash/VaultBottom.sprite;wide_stash.py 只拷)
# Texture for the bottom cover of the Chronicle page (no big black block; use that stretch of the original base panel): from the wide personal page base image StashPanelBGPersonal_wide.sprite (generated by gen_widestash_art.py)
# crop the whole strip below the grid (the ring ornaments on both sides + the stone face in the middle) and save it as a sprite of the same format (generated at build time, not in the repository).
# Why the whole strip: the sixth page has no base image of its own (a 6th entry cannot be added to the background image table, see wide_stash.py), so the game draws the previous page's base image -- the personal page, the shared pages (with an extra page number box), and
# the gem / material / rune pages (Horadric Cube recess) all differ, and on top of that come the two buttons 「转化」(Transmute) and 「提取」(Withdraw) embedded in the Horadric Cube container and the original page arrows. Only covering the whole strip makes it independent of which page one switched from.
# (Remove the original black box under the page buttons; move the buttons down, enlarge and center them): use the personal page's image instead (it has no page number box), and erase the gold box in the middle into stone face --
# on each side of the gold box there is a stretch of flat stone in the same rows; the left half takes the mirror image of the left stretch and the right half the mirror image of the right stretch (sampled from the same rows, so the shading runs the same way), cross-faded over the center 16 pixels.
# The page arrows and page number are our own widgets (TouchV_PgL / PgR / Page in wide_stash.py), drawn on top of the cover; the original arrows are covered by it, and holes are no longer cut.
# The base image sits at (-2, 100) in the panel, 1 pixel = 2 layout units (background in BankExpansionLayoutHD.json; checked by aligning on the gold box in a host screenshot).
# Usage: gen_vault_cover.py (run at build time after gen_widestash_art.py; output Gen/assets/NativeHUD/widestash/VaultBottom.sprite; wide_stash.py only copies it)
import os, sys
HERE = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HERE)
import gen_widestash_art as G
ART = __import__('gen_paths').gen_dir('NativeHUD', 'widestash')
BG_X, BG_Y = -2, 100
TOP = 516 # 底图像素行:格子下沿金线(第 508 行上下)以下、4 的倍数(DXT 块);wide_stash.py 的 TouchV_Cover 摆在 (BG_X, BG_Y + 2 * TOP) | Base image pixel row: below the gold line at the grid's lower edge (around row 508), a multiple of 4 (DXT blocks); wide_stash.py's TouchV_Cover is placed at (BG_X, BG_Y + 2 * TOP)
BOX = (322, 576, 524, 644) # 金币框(含边框外一圈)在底图里的像素范围 x0, y0, x1, y1;两侧平石面各宽 101:x 221–322 与 524–625 | Pixel range x0, y0, x1, y1 of the gold box (including one ring outside its border) in the base image; the flat stone on each side is 101 wide: x 221–322 and 524–625
def main():
import numpy as np
from PIL import Image
L = G.lib(); src = open(os.path.join(ART, 'StashPanelBGPersonal_wide.sprite'), 'rb').read(); im = G.decode(L, src)
w, h = im.size; eh = h - TOP; eh += -eh % 4
a = np.asarray(im).astype(np.float32).copy(); x0, y0, x1, y1 = BOX; mid = (x0 + x1) // 2; n = mid - x0
# 抹掉之前先核:框里确实是金币框(中间暗、上沿有一条亮边),两侧是平石面——底图变了就退,不瞎抹
# Check before erasing: the box really contains the gold box (dark in the middle, a bright edge along the top) and both sides are flat stone -- if the base image has changed, back out rather than erase blindly
g = a[..., :3].sum(axis=2)
if not (g[608, x0 + 20:x1 - 20].mean() < 75 and g[608, x0 - 60:x0 - 10].mean() > 85): raise SystemExit('gen_vault_cover:个人页底图里金币框不在预期位置(原版资源变了?)')
left = a[y0:y1, x0 - n:x0][:, ::-1]; right = a[y0:y1, x1:x1 + (x1 - mid)][:, ::-1]
a[y0:y1, x0:mid] = left; a[y0:y1, mid:x1] = right
for k in range(16): # 正中接缝:左右两段各自延伸过中线 8 像素再交叉淡入 | Center seam: the left and right segments each extend 8 pixels past the center line and are then cross-faded
t = (k + .5) / 16; xl = mid - 8 + k; a[y0:y1, xl] = (1 - t) * a[y0:y1, x0 - 1 - (xl - x0)] + t * a[y0:y1, x1 + (x1 - 1 - xl)]
im = Image.fromarray(np.clip(a, 0, 255).astype(np.uint8), 'RGBA')
crop = im.crop((0, TOP, w, TOP + eh)) # 超出底图的几行是透明的 | The rows beyond the base image are transparent
open(os.path.join(ART, 'VaultBottom.sprite'), 'wb').write(G.pack(L, src, G.bc3(crop), w, eh, w)); crop.save(os.path.join(ART, 'VaultBottom.png'))
print('VaultBottom:底图第 %d–%d 行,%d×%d,面板单位 (%d,%d)' % (TOP, TOP + eh, w, eh, BG_X, BG_Y + 2 * TOP))
if __name__ == '__main__':
main()