fixed # 新增缩放倍率适配

This commit is contained in:
2026-11-24 14:10:04 +08:00
parent 98116bef7b
commit d61b4b2526
18 changed files with 499 additions and 83 deletions
+37 -10
View File
@@ -108,7 +108,7 @@ export function mountBattleHUD(player, battle, env) {
const openDetails = (target, id = null) => {
if (disposed || frozen || !battle.session.active) return;
closeDialog(); previousFocus = document.activeElement;
dialog = create('dialog', 'mengsan-hud-dialog-shuying mengsan-deck-dialog-shuying mengsan-relic-dialog-shuying', document.body);
dialog = create('dialog', 'mengsan-hud-dialog-shuying mengsan-deck-dialog-shuying mengsan-relic-dialog-shuying', document.documentElement);
const current = dialog;
const header = create('header', 'ms-deck-header', dialog);
create('h2', '', header, `${nameOf(target)} · 当前状态`);
@@ -247,8 +247,13 @@ export function mountBattleHUD(player, battle, env) {
for (const mark of hiddenMarks) if (!wanted.has(mark)) { mark.classList.remove('mengsan-hud-represented-mark-shuying'); hiddenMarks.delete(mark); }
for (const mark of wanted) if (!mark.classList.contains('mengsan-hud-represented-mark-shuying')) { mark.classList.add('mengsan-hud-represented-mark-shuying'); hiddenMarks.add(mark); }
}
let layout = null;
let layout = null, handGeometry;
const hudHeightFor = () => layout === 'short' ? 188 : layout === 'narrow' ? 288 : 274;
function invalidateHandBounds() {
// Decade uses this cache to place the origin of committed card effects.
const bounds = window.decadeUI?.boundsCaches?.hand;
if (bounds) bounds.updated = false;
}
const oldLayout = arena.getAttribute('data-mengsan-hud-layout');
restores.push(() => {
if (arena.getAttribute('data-mengsan-hud-layout') !== layout) return;
@@ -272,20 +277,41 @@ export function mountBattleHUD(player, battle, env) {
const hudHeight = hudHeightFor();
style(arena, '--mengsan-hud-height', `${hudHeight}px`);
const large = width >= 1000;
style(arena, '--mengsan-hud-left', short ? '216px' : narrow ? '116px' : large ? '352px' : '292px');
style(arena, '--mengsan-hud-right', short ? '132px' : narrow ? '116px' : '184px');
const left = short ? 216 : narrow ? 116 : large ? 352 : 292;
const right = short ? 132 : narrow ? 116 : 184;
style(arena, '--mengsan-hud-left', `${left}px`);
style(arena, '--mengsan-hud-right', `${right}px`);
// Nova sets important geometry on #me and #handcards1. The HUD owns these positions for this battle.
const handInset = Math.min(Math.max(left,right),Math.max(0,(width-114)/2));
for (const [key,value] of Object.entries({left:`${handInset}px`,right:`${handInset}px`,
width:'auto',bottom:short?'64px':'68px'})) style(handRoot,key,value);
const firstHand = ui.handcards1Container;
if (firstHand && handRoot.contains(firstHand)) {
style(firstHand,'left','0px');
style(firstHand,'width','100%');
}
const geometry = [handRoot.offsetLeft, handRoot.offsetTop, handRoot.offsetWidth, handRoot.offsetHeight].join(',');
if (geometry !== handGeometry) {
handGeometry = geometry;
invalidateHandBounds();
}
style(arena, '--mengsan-profile-info-left', short ? '108px' : narrow ? '22px' : large ? '200px' : '160px');
style(arena, '--mengsan-profile-width', short ? '172px' : narrow ? '76px' : large ? '200px' : '130px');
skinActor(player);
// Inline important dimensions also beat skins with #arena > .player !important rules.
const selfLeft = short ? 24 : narrow ? 22 : 40;
const selfWidth = short || narrow ? 76 : large ? 144 : 104;
const selfBottom = narrow ? 180 : 24;
const selfHeight = short || narrow ? 104 : large ? 196 : 148;
const infoTop = narrow ? hudHeight - selfBottom + 16 : hudHeight - selfBottom - selfHeight + (short ? 0 : 20);
style(arena, '--mengsan-profile-info-top', `${infoTop}px`);
for (const [key, value] of Object.entries({left: short ? '24px' : narrow ? '22px' : '40px', right:'auto', top:'auto',
bottom:`${selfBottom}px`, width:short ? '76px' : narrow ? '76px' : large ? '144px' : '104px',
for (const [key, value] of Object.entries({left:`${selfLeft}px`, right:'auto', top:'auto',
bottom:`${selfBottom}px`, width:`${selfWidth}px`,
height:`${selfHeight}px`, transform:'none'})) style(player, key, value);
style(arena, '--mengsan-side-dock-bottom', `${selfBottom + selfHeight + 12}px`);
const statusBottom = selfBottom + selfHeight + 12;
const statusBesidePortrait = height - statusBottom < 36;
style(arena, '--mengsan-status-left', `${statusBesidePortrait ? selfLeft + selfWidth + 8 : selfLeft}px`);
style(arena, '--mengsan-side-dock-bottom', `${statusBesidePortrait ? 8 : statusBottom}px`);
style(arena, '--mengsan-relic-dock-bottom', `${selfBottom + selfHeight + (narrow ? -4 : 12)}px`);
style(arena, '--mengsan-skill-ceiling', `${Math.min(hudHeight - 36, selfBottom + selfHeight)}px`);
style(arena, '--mengsan-status-height', short ? '52px' : narrow ? '84px' : '160px');
@@ -339,8 +365,8 @@ export function mountBattleHUD(player, battle, env) {
const hudHeight = hudHeightFor();
const rail = layout === 'wide' ? 142 : layout === 'short' ? 112 : 96;
const actionBottom = layout === 'narrow' ? hudHeight - 48 : hudHeight + 8;
const compactActions = response || arena.clientWidth < 1000;
for (const [key,value] of Object.entries({position:'absolute',left:compactActions?'16px':'var(--mengsan-hud-left)',right:compactActions?'16px':'var(--mengsan-hud-right)',top:'auto',bottom:`${actionBottom}px`,width:'auto','max-height':'none',transform:'none'})) style(ui.control,key,value);
const actionInset = response || arena.clientWidth < 1000 ? '16px' : 'max(var(--mengsan-hud-left),var(--mengsan-hud-right))';
for (const [key,value] of Object.entries({position:'absolute',left:actionInset,right:actionInset,top:'auto',bottom:`${actionBottom}px`,width:'auto','max-height':'none',transform:'none'})) style(ui.control,key,value);
for (const group of ui.control.children) if (group.classList.contains('control')) {
if (external.includes(group)) {
ownClass(group,'mengsan-hud-native-skills-shuying');
@@ -362,7 +388,7 @@ export function mountBattleHUD(player, battle, env) {
const host=node.offsetParent||arena,a=arena.getBoundingClientRect(),h=host.getBoundingClientRect();
const scale=h.width/host.offsetWidth||1,zoom=a.width/arena.clientWidth||1;
const responseConfirm = response && node === ui.confirm;
const center=responseConfirm ? arena.clientWidth/2 : (parseFloat(arena.style.getPropertyValue('--mengsan-hud-left'))+arena.clientWidth-parseFloat(arena.style.getPropertyValue('--mengsan-hud-right')))/2;
const center=arena.clientWidth/2;
const side=responseConfirm ? 0 : node===ui.confirm?-1:1;
for(const [key,value] of Object.entries({position:'absolute',left:`${(a.left+center*zoom-h.left)/scale+side*80}px`,right:'auto',top:'auto',bottom:`${(h.bottom-a.bottom+actionBottom*zoom)/scale}px`,width:`${Math.min(rail,140)}px`,transform:'translateX(-50%)'}))style(node,key,value);
}
@@ -420,6 +446,7 @@ export function mountBattleHUD(player, battle, env) {
for (const mark of hiddenMarks) mark.classList.remove('mengsan-hud-represented-mark-shuying'); hiddenMarks.clear();
for (const restore of restores.reverse()) restore();
releaseNodes();
invalidateHandBounds();
root.remove(); link.remove();
}
ownClass(document.body, 'mengsan-hud-active-shuying'); ownClass(arena, 'mengsan-hud-arena-shuying');
+6 -6
View File
@@ -82,9 +82,9 @@ export function createOverlayLayout(arena, hand, ui, player) {
.filter(button => !button.closest('.mengsan-hud-external-control-shuying,.removing,.closing'))
.map(button => button.getBoundingClientRect()).filter(box => box.height && box.width);
}
function positionResponseActions(handTop, center, gap, used) {
function alignActions(handTop, center, gap, used, response) {
const controls = [ui.control];
if (ui.confirm?.isConnected && !ui.control.contains(ui.confirm)) controls.push(ui.confirm);
if (response && ui.confirm?.isConnected && !ui.control.contains(ui.confirm)) controls.push(ui.confirm);
let top = Infinity;
for (const node of controls) {
const isRoot = node === ui.control;
@@ -102,7 +102,7 @@ export function createOverlayLayout(arena, hand, ui, player) {
const right = Math.max(...centered.map(box => box.right));
const scale = hostScale(node), previous = currentShift(node,scale);
const bottom = Math.max(...buttons.map(box => box.bottom)) - previous.y;
const offset = handTop - gap - bottom;
const offset = response ? handTop - gap - bottom : 0;
shift(node,center - (left + right)/2 + previous.x,offset,scale,used);
top = Math.min(top, ...buttons.map(box => box.top - previous.y + offset));
}
@@ -140,16 +140,16 @@ export function createOverlayLayout(arena, hand, ui, player) {
const handCards=[...hand.querySelectorAll('.handcards>.card')].map(node=>node.getBoundingClientRect()).filter(box=>box.height&&box.width);
const handTop=Math.min(handBox.top,...handCards.map(box=>box.top));
const gap=Math.max(4,(arena.clientHeight<=500?6:8)*zoom);
const responseTop=response ? positionResponseActions(handCards.length ? Math.min(...handCards.map(box=>box.top)) : handTop,(a.left+a.right)/2,gap,used) : Infinity;
const actionTop=alignActions(handCards.length ? Math.min(...handCards.map(box=>box.top)) : handTop,(a.left+a.right)/2,gap,used,response);
const controlTop=ui.control.getBoundingClientRect().top;
let promptBottom=Math.min(controlTop-10*zoom,a.bottom-(footerHeight+54)*zoom);
if(Number.isFinite(responseTop))promptBottom=responseTop-gap;
if(response && Number.isFinite(actionTop))promptBottom=actionTop-gap;
let promptTop=Infinity;
for(const node of prompts) {
if(node.hidden || !node.getClientRects().length)continue;
mark(node,'mengsan-hud-prompt-shuying');used.add(node);
const promptX=response?a.left+16*zoom:x;
const promptWidth=response?arena.clientWidth-32:width;
const promptX=a.left+(arena.clientWidth-promptWidth)*zoom/2;
position(node,promptX,0,promptWidth,arena.clientHeight<=500?34:64);
const height=node.getBoundingClientRect().height;
position(node,promptX,Math.max(a.top+(response?8:50)*zoom,promptBottom-height),promptWidth,arena.clientHeight<=500?34:64);
+3 -6
View File
@@ -18,7 +18,7 @@
.mengsan-hud-health-track-shuying { width:100%;height:4px;margin:0 0 2px;background:#ffffff1a;border-radius:4px;overflow:hidden; }
.mengsan-hud-health-track-shuying>span { height:100%;background:#9bb78d; }
.mengsan-hud-energy-shuying { color:#eacb87;font-size:16px;font-variant-numeric:tabular-nums;white-space:nowrap; }
.mengsan-hud-center-shuying { left:40px;right:auto;top:auto;bottom:var(--mengsan-side-dock-bottom);width:var(--mengsan-profile-width);height:var(--mengsan-status-height); }
.mengsan-hud-center-shuying { left:var(--mengsan-status-left);right:auto;top:auto;bottom:var(--mengsan-side-dock-bottom);width:var(--mengsan-profile-width);height:var(--mengsan-status-height); }
.mengsan-hud-shuying .mengsan-hud-statuses-shuying { display:grid;grid-template-columns:repeat(auto-fill,32px);grid-auto-rows:32px;align-content:end;gap:6px;overflow:hidden;white-space:nowrap;height:100%; }
.mengsan-hud-shuying .mengsan-hud-status-shuying { display:flex;align-items:center;justify-content:center;width:32px;height:32px;min-width:0;min-height:32px;padding:2px;background:transparent;border-radius:6px;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;touch-action:pan-y; }
.mengsan-hud-status-shuying img { width:26px;height:26px;object-fit:contain;pointer-events:none; }
@@ -29,7 +29,7 @@
Keep them above the portrait (25) and below action controls (30).
Inline elevations used by awakening animations still take precedence. */
body.mengsan-hud-active-shuying>#decadeUI-canvas { z-index:28; }
.mengsan-hud-hand-shuying { position:absolute!important;left:var(--mengsan-hud-left)!important;right:var(--mengsan-hud-right)!important;bottom:68px!important;top:auto!important;width:calc(100% - var(--mengsan-hud-left) - var(--mengsan-hud-right))!important;height:calc(var(--mengsan-hud-height,274px) - 126px)!important;z-index:24!important;background:none!important;border:0!important;transform:none!important;pointer-events:none; }
.mengsan-hud-hand-shuying { position:absolute!important;top:auto!important;height:calc(var(--mengsan-hud-height,274px) - 126px)!important;z-index:24!important;background:none!important;border:0!important;transform:none!important;pointer-events:none; }
.mengsan-hud-hand-shuying .handcards>.card { pointer-events:auto; }
.mengsan-hud-mebg-shuying,.mengsan-hud-hand-shuying>.fakeme.avatar { display:none!important; }
/* These explicit references cover Decade's nested camp-wrap and hp-wrap as well. */
@@ -75,12 +75,10 @@ body.mengsan-hud-active-shuying .mengsan-hud-potion-action-shuying { display:non
[data-mengsan-hud-layout="short"] .mengsan-hud-hp-shuying,[data-mengsan-hud-layout="short"] .mengsan-hud-block-shuying { font-size:11px; }
[data-mengsan-hud-layout="short"] .mengsan-hud-name-shuying { font-size:15px; }
[data-mengsan-hud-layout="short"] .mengsan-hud-energy-shuying { font-size:14px; }
[data-mengsan-hud-layout="short"] .mengsan-hud-hand-shuying { bottom:64px!important;height:calc(var(--mengsan-hud-height) - 122px)!important; }
[data-mengsan-hud-layout="short"] .mengsan-hud-center-shuying { top:auto;left:24px; }
[data-mengsan-hud-layout="short"] .mengsan-hud-hand-shuying { height:calc(var(--mengsan-hud-height) - 122px)!important; }
[data-mengsan-hud-layout="short"] .mengsan-hud-shuying .mengsan-hud-status-shuying { min-height:26px;padding:2px 4px; }
[data-mengsan-hud-layout="short"] .mengsan-hud-status-shuying img { width:18px;height:18px; }
[data-mengsan-hud-layout="narrow"] .mengsan-hud-shuying .mengsan-hud-info-shuying { left:22px;width:76px;font-size:12px;gap:5px; }
[data-mengsan-hud-layout="narrow"] .mengsan-hud-hand-shuying { bottom:68px!important; }
[data-mengsan-hud-layout="narrow"] .mengsan-hud-name-shuying { font-size:16px; }
[data-mengsan-hud-layout="narrow"] .mengsan-hud-status-shuying span { display:none; }
#arena.mengsan-hud-arena-shuying>.mengsan-hud-notification-shuying { width:148px!important;max-width:148px!important;min-height:30px;height:30px!important;transition:none!important;font:600 16px/30px "Microsoft YaHei",sans-serif!important;white-space:nowrap; }
@@ -119,7 +117,6 @@ body.mengsan-hud-active-shuying #arena .mengsan-hud-equips-shuying::-webkit-scro
[data-mengsan-hud-layout="narrow"] .mengsan-hand-relics-shuying { right:16px!important;width:96px!important;max-width:96px!important;max-height:36px;flex-wrap:nowrap;justify-content:flex-start;overflow-x:auto;overflow-y:hidden;touch-action:pan-x; }
body.mengsan-hud-active-shuying #arena>.mengsan-hud-controls-shuying>.mengsan-hud-native-skills-shuying { flex-direction:column!important;flex-wrap:nowrap!important;align-items:stretch!important;max-width:none!important;overflow:auto!important; }
body.mengsan-hud-active-shuying #arena .mengsan-hud-native-skills-shuying>div { width:100%!important;min-width:0!important;box-sizing:border-box!important;padding:8px 10px!important;min-height:40px!important;font:14px/20px "Microsoft YaHei",sans-serif!important;white-space:normal!important; }
[data-mengsan-hud-layout="narrow"] .mengsan-hud-center-shuying { left:22px; }
[data-mengsan-hud-layout="short"] .mengsan-hud-shuying .mengsan-hud-statuses-shuying { height:100%; }
.mengsan-hud-prompt-shuying { box-sizing:border-box!important;height:auto!important;min-height:0!important;overflow:auto!important;padding:2px 6px!important;background:none!important;border:0!important;box-shadow:none!important;text-align:center!important;z-index:32!important;color:#f6edcb!important;text-shadow:0 1px 3px #000,0 0 6px #000!important; }
body.mengsan-hud-active-shuying .mengsan-hud-card-intro-shuying { box-sizing:border-box!important;z-index:90!important;height:auto!important;min-height:0!important;overflow:auto!important;border-radius:14px!important;background:#202020f5!important;box-shadow:0 8px 24px #0007!important;color:#f4f4f4!important;transition:none!important; }