114 lines
13 KiB
Python
114 lines
13 KiB
Python
#!/usr/bin/env python3
|
||
# 佣兵加装备位(秘境最高通关 ≥ 10 层解锁):佣兵面板的装备区整块照玩家装备栏——十个物品格(原有四格 + 项链 / 手套 / 两戒指 / 腰带 / 鞋)的矩形 = 玩家物品栏布局里
|
||
# 同名格的矩形平移一个固定偏移(格子图在两个面板里左上角之差)。底图由 gen_merc_art.py 生成(石纹和格子都从玩家栏的原图逐像素拷,名字条下移、属性表压行距),
|
||
# 这里改布局:原四格挪到玩家栏的格位,加六个原版物品格控件(名字 = 部位、空位图照玩家物品栏面板),名字条 / 经验条 / 技能图标整体下移 216 单位,属性表五行按新行距重排;
|
||
# 手柄光标的上下左右停靠照玩家物品栏接上。
|
||
# 未解锁时六个格上各盖一块我们自己的暗红矩形 TouchMercLock_<部位>(原版「这个位置不可用」的颜色,如佣兵拿双手武器时的副手格),缺省在屏外,宿主(dm_rift_ui.c)按解锁状态挪。
|
||
# 服务端放不放得进去由数据表(wide_stash.py 补佣兵行)和放置校验那道门(patch_nso.py 0x8d)决定,这里只管画面
|
||
# Extra mercenary equipment slots (unlocked at highest rift level cleared ≥ 10): the equipment area of the mercenary panel follows the player's equipment panel as a whole -- the rectangles of the ten item cells (the original four + amulet / gloves / two rings / belt / boots) = the rectangles of the
|
||
# same-named cells in the player inventory layout translated by a fixed offset (the difference between the grid image's top-left corners in the two panels). The base image is generated by gen_merc_art.py (stone texture and cells both copied pixel for pixel from the player panel's original images, name strip moved down, stat table row pitch compressed),
|
||
# and the layout is changed here: the original four cells move to the player panel's cell positions, six original item cell widgets are added (name = body location, empty-slot image as in the player inventory panel), the name strip / experience bar / skill icons move down as a whole by 216 units, and the five stat table rows are re-laid at the new row pitch;
|
||
# up / down / left / right controller cursor navigation is wired up following the player inventory.
|
||
# When not unlocked each of the six cells is covered by our own dark red rectangle TouchMercLock_<body location> (the original game's color for "this slot is unavailable", such as the off-hand cell when the mercenary holds a two-handed weapon), off-screen by default and moved by the host (dm_rift_ui.c) according to the unlock state.
|
||
# Whether the server lets an item in is decided by the data table (wide_stash.py adds the mercenary row) and the placement check gate (patch_nso.py 0x8d); this file only handles what is drawn
|
||
import os, re, shutil, sys
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
import touch_layout
|
||
|
||
PANEL = 'controller/hirelinginventorypanelhd.json'; PLAYER = 'controller/playerinventoryoriginallayouthd.json'
|
||
BG = 'data/hd/global/ui/controller/panel/hirelinginventory/v2/hirelinginventorybg.sprite'
|
||
SHIFT = 216 # 名字条下移(布局单位 = 底图 108 像素) | Name strip moved down (layout units = 108 pixels in the base image)
|
||
ROWS = {902: 1064, 903: 1065, 905: 1067, 994: 1132, 993: 1131, 995: 1133, 1088: 1200, 1089: 1201, 1090: 1202, 1183: 1268, 1185: 1270, 1279: 1336} # 属性表各行:原 y → 新 y(底图里每行 34 像素) | Stat table rows: original y → new y (34 pixels per row in the base image)
|
||
# 名字(上)、经验条(中)、「等级 N 佣兵类型」(下):原版两行字都贴各自矩形的下沿,中文字体下名字离经验条 13 像素、等级那行却几乎贴着条(原版佣兵面板本来如此,:
|
||
# 错位不对称、压到经验条)。改成两行各放进一个 60 高的矩形、竖向居中,两个矩形关于经验条槽(底图里 y 956–972,中心 964)上下对称:{控件: (y, 高)}
|
||
# Name (top), experience bar (middle), "Level N <mercenary type>" (bottom): in the original both text lines sit on the bottom edge of their own rectangles, so with the Chinese font the name is 13 pixels from the experience bar while the level line almost touches the bar (the original mercenary panel is like this to begin with:
|
||
# misaligned and asymmetric, pressing on the experience bar). Changed to put each line in a 60-high rectangle, vertically centered, with the two rectangles symmetric above and below the experience bar groove (y 956–972 in the base image, center 964): {widget: (y, height)}
|
||
ROWS_TXT = {'CharacterName': (884, 60), 'HireTypeText': (984, 60)}
|
||
BAND = ('CharacterName', 'HireTypeText', 'XpProgress', 'NextLevelXP', 'CurrentXP', 'Skill0', 'Skill1', 'Skill2')
|
||
STATS = ('HPTitle', 'HPStat', 'StrengthTitle', 'StrengthStat', 'DexTitle', 'DexStat', 'DamageTitle', 'Damage', 'ArmorClassTitle', 'ArmorClass',
|
||
'FireResistanceTitle', 'FireText', 'ColdResistanceTitle', 'ColdText', 'LightningResistanceTitle', 'LightningText', 'PoisonResistanceTitle', 'PoisonText')
|
||
NEW = ('neck', 'gloves', 'right_hand', 'belt', 'left_hand', 'feet')
|
||
NAV = { # 手柄光标停靠(照玩家物品栏:上排 武器 / 头 / 项链 / 副手,下排 手套 / 右戒 / 腰带 / 左戒 / 鞋) | Controller cursor navigation (following the player inventory: top row weapon / head / amulet / off-hand, bottom row gloves / right ring / belt / left ring / boots)
|
||
'head': {'left': 'right_arm', 'right': 'neck', 'down': 'torso'}, 'neck': {'left': 'head', 'right': 'left_arm', 'down': 'left_hand'},
|
||
'torso': {'left': 'right_arm', 'right': 'left_arm', 'up': 'head', 'down': 'belt'}, 'right_arm': {'right': 'torso', 'down': 'gloves'},
|
||
'left_arm': {'left': 'neck', 'up': 'head', 'down': 'feet'}, 'gloves': {'up': 'right_arm', 'right': 'right_hand'},
|
||
'right_hand': {'left': 'gloves', 'right': 'belt', 'up': 'torso'}, 'belt': {'left': 'right_hand', 'right': 'left_hand', 'up': 'torso'},
|
||
'left_hand': {'left': 'belt', 'right': 'feet', 'up': 'neck'}, 'feet': {'left': 'left_hand', 'up': 'left_arm'}}
|
||
|
||
def _block(text, name):
|
||
m = re.search(r'\{\s*"type"\s*:\s*"\w+"\s*,\s*"name"\s*:\s*"%s"' % re.escape(name), text)
|
||
if not m: raise SystemExit('merc_slots:布局里没有控件 ' + name)
|
||
return m.start(), touch_layout._block_end(text, m.start()) + 1
|
||
|
||
def _set_y(text, name, fn):
|
||
a, b = _block(text, name); blk = text[a:b]; r = re.compile(r'("rect"\s*:\s*\{\s*"x"\s*:\s*-?\d+\s*,\s*"y"\s*:\s*)(-?\d+)').search(blk)
|
||
if not r: raise SystemExit('merc_slots:控件 %s 没有 rect 的 y' % name)
|
||
return text[:a] + blk[:r.start(2)] + str(fn(int(r.group(2)))) + blk[r.end(2):] + text[b:]
|
||
|
||
def _nav(slot):
|
||
rows = ['"%s": { "name": "slot_%s" }' % (d, t) for d, t in NAV[slot].items()]
|
||
if slot in ('left_arm', 'feet'): rows.append('"right": { "panelBoundary": true }')
|
||
return '"navigation": { ' + ', '.join(rows) + ' }'
|
||
|
||
INV_AT = (196, 43) # 格子图左上角在玩家物品栏面板里的位置(布局单位:面板 1408×1486、图锚在中心、rect −508, −700) | Position of the grid image's top-left corner in the player inventory panel (layout units: panel 1408×1486, image anchored at the center, rect −508, −700)
|
||
ALL = ('head', 'torso', 'right_arm', 'left_arm') + NEW
|
||
|
||
def rects(player_text):
|
||
"""十个格的布局矩形 {部位: (x, y, 宽, 高)} = 玩家物品栏里同名格的矩形平移到佣兵底图的格子图位置。 | Layout rectangles of the ten cells {body location: (x, y, width, height)} = the rectangles of the same-named cells in the player inventory, translated to the grid image's position in the mercenary base image."""
|
||
import gen_merc_art
|
||
dx, dy = 2 * gen_merc_art.DX - INV_AT[0], 2 * gen_merc_art.DY - INV_AT[1]; out = {}
|
||
for s in ALL:
|
||
a, b = _block(player_text, 'slot_' + s); m = re.search(r'"rect"\s*:\s*\{\s*"x"\s*:\s*(\d+)\s*,\s*"y"\s*:\s*(\d+)\s*,\s*"width"\s*:\s*(\d+)\s*,\s*"height"\s*:\s*(\d+)\s*\}', player_text[a:b])
|
||
if not m: raise SystemExit('merc_slots:玩家物品栏布局里 slot_%s 没有 rect' % s)
|
||
x, y, w, h = map(int, m.groups()); out[s] = (x + dx, y + dy, w, h)
|
||
return out
|
||
|
||
def transform(text, player_text):
|
||
for n in BAND: text = _set_y(text, n, lambda y: y + SHIFT)
|
||
for n, (y, h) in ROWS_TXT.items(): # 名字 / 等级两行:见 ROWS_TXT | The name / level rows: see ROWS_TXT
|
||
a, b = _block(text, n); blk = text[a:b]
|
||
blk, n1 = re.subn(r'("rect"\s*:\s*\{\s*"x"\s*:\s*-?\d+\s*,\s*"y"\s*:\s*)-?\d+(\s*,\s*"width"\s*:\s*\d+\s*,\s*"height"\s*:\s*)\d+', lambda m: '%s%d%s%d' % (m.group(1), y, m.group(2), h), blk, count=1)
|
||
blk, n2 = re.subn(r'"v"\s*:\s*"bottom"', '"v": "center"', blk, count=1)
|
||
if n1 != 1 or n2 != 1: raise SystemExit('merc_slots:%s 的 rect / 竖向对齐和原版布局对不上(原版布局变了?)' % n)
|
||
text = text[:a] + blk + text[b:]
|
||
for n in STATS:
|
||
def fn(y, n=n):
|
||
if y not in ROWS: raise SystemExit('merc_slots:属性表控件 %s 的 y = %d 不在行表里(原版布局变了?)' % (n, y))
|
||
return ROWS[y]
|
||
text = _set_y(text, n, fn)
|
||
R = rects(player_text)
|
||
for s in ('head', 'torso', 'right_arm', 'left_arm'): # 原四格:挪到玩家栏的格位,停靠方向换成新的 | The original four cells: moved to the player panel's cell positions, with navigation targets replaced by the new ones
|
||
a, b = _block(text, 'slot_' + s); blk = text[a:b]; i = blk.index('"navigation"'); j = touch_layout._block_end(blk, blk.index('{', i)) + 1
|
||
blk = blk[:i] + _nav(s) + blk[j:]; x, y, w, h = R[s]
|
||
blk, n = re.subn(r'"rect"\s*:\s*\{[^}]*\}', '"rect": { "x": %d, "y": %d, "width": %d, "height": %d }' % (x, y, w, h), blk, count=1)
|
||
if n != 1: raise SystemExit('merc_slots:佣兵面板 slot_%s 没有 rect' % s)
|
||
text = text[:a] + blk + text[b:]
|
||
add = ''
|
||
for s in NEW:
|
||
pa, pb = _block(player_text, 'slot_' + s); bg = re.search(r'"backgroundFilename"\s*:\s*"([^"]+)"', player_text[pa:pb]).group(1); x, y, w, h = R[s]
|
||
add += ',\n { "type": "InventorySlotWidget", "name": "slot_%s", "fields": { "rect": { "x": %d, "y": %d, "width": %d, "height": %d }, "backgroundFilename": "%s", %s } }' % (s, x, y, w, h, bg, _nav(s))
|
||
# 盖板放在物品格之后(画在上层)。颜色按实跑截图配到和原版不可用格(佣兵拿双手武器时的副手格)同一个红:副手格实测约 (41, 8, 9)、空凹槽底色约 (19, 19, 19),
|
||
# 盖板不透明度 0.78 时颜色 = (目标 − 0.22 × 底色) ÷ 0.78 ÷ 255(第一版 (70, 8, 10) 太扎眼)
|
||
# The covers come after the item cells (drawn on top). The color was matched from actual-run screenshots to the same red as an original disabled cell (the off-hand cell when the mercenary holds a two-handed weapon): the off-hand cell measured about (41, 8, 9), the empty recess background about (19, 19, 19),
|
||
# and with cover opacity 0.78 the color = (target − 0.22 × background) ÷ 0.78 ÷ 255 (the first version (70, 8, 10) was too glaring)
|
||
for s in NEW:
|
||
x, y, w, h = R[s]
|
||
add += ',\n { "type": "RectangleWidget", "name": "TouchMercLock_%s", "fields": { "rect": { "x": 99999, "y": %d, "width": %d, "height": %d }, "color": [ 0.187, 0.019, 0.022, 0.78 ] } }' % (s, y, w, h)
|
||
a, b = _block(text, 'slot_left_arm')
|
||
return text[:b] + add + text[b:]
|
||
|
||
def build(romfs, outdir, repl):
|
||
"""触屏版:叠在触摸布局已改的那份(右上角关闭钮)上。返回 {包内逻辑路径: 本地文件}。 | Touch version: stacked on the copy already modified by the touch layout (close button at the top right). Returns {logical path in the package: local file}."""
|
||
import gen_merc_art
|
||
out = {}; p = os.path.join(outdir, 'ms_hirelinginventorybg.sprite'); shutil.copyfile(os.path.join(gen_merc_art.ART, 'HirelingInventoryBG.sprite'), p); out[BG] = p
|
||
logical = touch_layout.read_layout(romfs, PANEL)[0].lower(); src = repl.get(logical)
|
||
text = open(src, encoding='utf-8').read() if src else touch_layout.read_layout(romfs, PANEL)[1]
|
||
p = os.path.join(outdir, 'ms_hireling.json'); open(p, 'w', encoding='utf-8').write(transform(text, touch_layout.read_layout(romfs, PLAYER)[1])); out[logical] = p
|
||
return out
|
||
|
||
def build_pad(romfs, outdir):
|
||
"""手柄版:原版布局上直接改。 | Controller layout: edited directly on the original layout."""
|
||
logical, text = touch_layout.read_layout(romfs, PANEL)
|
||
p = os.path.join(outdir, 'pad_hireling.json'); open(p, 'w', encoding='utf-8').write(transform(text, touch_layout.read_layout(romfs, PLAYER)[1]))
|
||
return {logical.lower(): p}
|