mirror of
https://github.com/Shu-Ying/noname-shuying.git
synced 2026-11-24 14:06:29 +08:00
fixed # 修复部分样式BUG
This commit is contained in:
@@ -79,22 +79,34 @@ export function createHandInput(player, session, adapter, fan, env, refresh, log
|
||||
function removeAim() { aim?.remove(); aim = null; }
|
||||
function showAim(card, point) {
|
||||
const rect = card.getBoundingClientRect();
|
||||
const x = rect.left + rect.width / 2, y = rect.top + Math.min(12, rect.height / 2);
|
||||
const dx = point.x - x, dy = point.y - y;
|
||||
const length = Math.hypot(dx, dy);
|
||||
if (!(rect.width > 0 && rect.height > 0 && length > 0 && Number.isFinite(length))) {
|
||||
const x = rect.left + rect.width / 2, y = rect.top;
|
||||
if (!(rect.width > 0 && rect.height > 0 && Number.isFinite(point.x) && Number.isFinite(point.y))) {
|
||||
removeAim();
|
||||
return;
|
||||
}
|
||||
if (!aim) {
|
||||
aim = document.createElement("div");
|
||||
const svg = "http://www.w3.org/2000/svg";
|
||||
aim = document.createElementNS(svg, "svg");
|
||||
aim.classList.add("mengsan-hand-aim-shuying");
|
||||
aim.setAttribute("aria-hidden", "true");
|
||||
// 无名杀缩放 body,牌面矩形和指针事件都使用视口坐标。
|
||||
aim.appendChild(document.createElementNS(svg, "line"));
|
||||
document.documentElement.appendChild(aim);
|
||||
}
|
||||
aim.style.width = `${length}px`;
|
||||
aim.style.transform = `translate(${x}px, ${y}px) rotate(${Math.atan2(dy, dx)}rad) translateY(-50%)`;
|
||||
// 牌面和触点在同一个视口坐标系,统一换算到绘制层的局部坐标。
|
||||
const matrix = aim.getScreenCTM();
|
||||
const determinant = matrix && matrix.a * matrix.d - matrix.b * matrix.c;
|
||||
if (!determinant || !Number.isFinite(determinant)) { removeAim(); return; }
|
||||
const inverse = matrix.inverse();
|
||||
const viewportPoint = aim.createSVGPoint();
|
||||
viewportPoint.x = x; viewportPoint.y = y;
|
||||
const from = viewportPoint.matrixTransform(inverse);
|
||||
viewportPoint.x = point.x; viewportPoint.y = point.y;
|
||||
const to = viewportPoint.matrixTransform(inverse);
|
||||
const line = aim.firstElementChild;
|
||||
line.setAttribute("x1", from.x);
|
||||
line.setAttribute("y1", from.y);
|
||||
line.setAttribute("x2", to.x);
|
||||
line.setAttribute("y2", to.y);
|
||||
}
|
||||
function clearSelection(state) {
|
||||
if (!live(state) || !state.selected) return;
|
||||
|
||||
@@ -78,16 +78,18 @@
|
||||
}
|
||||
.mengsan-hand-aim-shuying {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 2.6px;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
transform-origin: 0 0;
|
||||
transition: none;
|
||||
border-radius: 2px;
|
||||
background: rgb(250, 220, 140);
|
||||
box-shadow: 0 0 2px #f5d25b;
|
||||
}
|
||||
.mengsan-hand-aim-shuying > line {
|
||||
stroke: rgb(250, 220, 140);
|
||||
stroke-width: 2.6px;
|
||||
stroke-linecap: round;
|
||||
vector-effect: non-scaling-stroke;
|
||||
filter: drop-shadow(0 0 2px #f5d25b);
|
||||
}
|
||||
/* 只在梦三手牌挂载期间隐藏十周年阶段、等待响应和对方思考图片。 */
|
||||
body.mengsan-hand-ui-shuying [style*="extension/十周年UI/ui/assets/lbtn/tips/"]:is(
|
||||
|
||||
+10
-6
@@ -312,7 +312,7 @@ export function mountBattleHUD(player, battle, env) {
|
||||
right:`${(h.right - a.right + (layout === 'wide' ? 24 : 16) * arenaScale) / scale}px`, bottom:`${(h.bottom - a.bottom + bottom * arenaScale) / scale}px`,
|
||||
width:`${rail * arenaScale / scale}px`, 'max-height':`${maxHeight * arenaScale / scale}px`})) style(node, key, value);
|
||||
}
|
||||
function syncControls() {
|
||||
function syncControls(response) {
|
||||
// The actual action controls stay horizontal above the hand; skill references get their own rail.
|
||||
const candidates = [...new Set([ui.skills, ui.skills2, ui.skills3, ui.skillControl, ui.gskillControl])]
|
||||
.filter(node => node?.isConnected && node !== ui.control);
|
||||
@@ -339,7 +339,7 @@ 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 = arena.clientWidth < 1000;
|
||||
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);
|
||||
for (const group of ui.control.children) if (group.classList.contains('control')) {
|
||||
if (external.includes(group)) {
|
||||
@@ -361,8 +361,9 @@ export function mountBattleHUD(player, battle, env) {
|
||||
ownClass(node,'mengsan-hud-external-action-shuying');
|
||||
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 center=(parseFloat(arena.style.getPropertyValue('--mengsan-hud-left'))+arena.clientWidth-parseFloat(arena.style.getPropertyValue('--mengsan-hud-right')))/2;
|
||||
const side=node===ui.confirm?-1: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 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);
|
||||
}
|
||||
}
|
||||
@@ -388,8 +389,11 @@ export function mountBattleHUD(player, battle, env) {
|
||||
healthFill.style.width = `${Math.max(0, Math.min(100, player.maxHp > 0 ? player.hp / player.maxHp * 100 : 0))}%`;
|
||||
text(energy, `费用 ${player.storage.mengsanEnergy_shuying ?? 0} / ${player.storage.mengsanMaxEnergy_shuying ?? 0}`);
|
||||
syncActors(); syncExternalEquipment(); renderStatuses();
|
||||
refreshDetails(); syncControls(); syncNotifications();
|
||||
overlays.refresh({ footerHeight:hudHeightFor(), status:_status });
|
||||
const event = _status.event;
|
||||
const response = event?.player === player && Boolean(event.respondTo || event.name === 'chooseToRespond');
|
||||
refreshDetails(); syncControls(response); syncNotifications();
|
||||
battle.potionUI?.layoutBattleSlots(ui);
|
||||
overlays.refresh({ footerHeight:hudHeightFor(), status:_status, response });
|
||||
}
|
||||
function schedule() {
|
||||
if (disposed || frozen || document.hidden || frame !== null) return;
|
||||
|
||||
+93
-14
@@ -32,14 +32,18 @@ export function createOverlayLayout(arena, hand, ui, player) {
|
||||
for (const [name, had] of record.classes) if (!had) node.classList.remove(name);
|
||||
records.delete(node);
|
||||
}
|
||||
function mark(node, name) {
|
||||
function recordFor(node) {
|
||||
let record=records.get(node);
|
||||
if(!record) {record={styles:new Map(),classes:new Map()};records.set(node,record);}
|
||||
return record;
|
||||
}
|
||||
function mark(node, name) {
|
||||
const record = recordFor(node);
|
||||
if(!record.classes.has(name))record.classes.set(name,node.classList.contains(name));
|
||||
node.classList.add(name);return record;
|
||||
}
|
||||
function style(node,key,value) {
|
||||
const record=records.get(node);
|
||||
const record=recordFor(node);
|
||||
if(!record.styles.has(key))record.styles.set(key,{before:node.style.getPropertyValue(key),priority:node.style.getPropertyPriority(key)});
|
||||
const field=record.styles.get(key);
|
||||
if(field.requested!==value||node.style.getPropertyValue(key)!==field.last)node.style.setProperty(key,value,'important');
|
||||
@@ -52,32 +56,107 @@ export function createOverlayLayout(arena, hand, ui, player) {
|
||||
style(node,'left',`${(x-h.left)/sx-host.clientLeft+host.scrollLeft}px`);
|
||||
style(node,'top',`${(y-h.top)/sy-host.clientTop+host.scrollTop}px`);
|
||||
}
|
||||
function hostScale(node) {
|
||||
const host = node.offsetParent || arena;
|
||||
const box = host.getBoundingClientRect();
|
||||
return {x:box.width / host.offsetWidth || 1,y:box.height / host.offsetHeight || 1};
|
||||
}
|
||||
function currentShift(node, scale) {
|
||||
const field = records.get(node)?.styles.get('translate');
|
||||
return field?.last && node.style.getPropertyValue('translate') === field.last
|
||||
? {x:field.x * scale.x,y:field.y * scale.y} : {x:0,y:0};
|
||||
}
|
||||
function shift(node, x, y, scale, used) {
|
||||
if (Math.abs(x) < .05 && Math.abs(y) < .05) return;
|
||||
// Keep the engine's transform animation, but apply the layout shift immediately.
|
||||
if (arena.ownerDocument.defaultView.getComputedStyle(node).transitionProperty === 'all') {
|
||||
style(node, 'transition-property', 'transform, opacity, left, top');
|
||||
}
|
||||
const dx = x / scale.x, dy = y / scale.y;
|
||||
style(node, 'translate', `${dx}px ${dy}px`);
|
||||
Object.assign(records.get(node).styles.get('translate'), {x:dx,y:dy});
|
||||
used.add(node);
|
||||
}
|
||||
function visibleButtons(node, selector) {
|
||||
return [...node.querySelectorAll(selector)]
|
||||
.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) {
|
||||
const controls = [ui.control];
|
||||
if (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;
|
||||
const buttons = visibleButtons(node,isRoot ? ':scope > .control > div' : ':scope > div');
|
||||
if (!buttons.length) continue;
|
||||
const confirm = ui.confirm;
|
||||
let responseButtons = [];
|
||||
if (confirm && (node === confirm || node.contains(confirm))) {
|
||||
responseButtons = confirm.node ? [confirm.node.ok,confirm.node.cancel]
|
||||
.filter(button => button?.isConnected && button.getClientRects().length)
|
||||
.map(button => button.getBoundingClientRect()) : visibleButtons(confirm,':scope > div');
|
||||
}
|
||||
const centered = responseButtons.length ? responseButtons : buttons;
|
||||
const left = Math.min(...centered.map(box => box.left));
|
||||
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;
|
||||
shift(node,center - (left + right)/2 + previous.x,offset,scale,used);
|
||||
top = Math.min(top, ...buttons.map(box => box.top - previous.y + offset));
|
||||
}
|
||||
return top;
|
||||
}
|
||||
function clearResponseCards(promptTop, battlefieldTop, gap, used) {
|
||||
const cards = (ui.thrown || []).filter(card => card.parentNode === arena && !card.fixed &&
|
||||
!card.matches('.drawingcard,.gainingcard,.movingcard,.removing,.hidden'));
|
||||
const geometry = cards.map(card => {
|
||||
const scale = hostScale(card), previous = currentShift(card,scale), box = card.getBoundingClientRect();
|
||||
return {card,scale,top:box.top - previous.y,bottom:box.bottom - previous.y};
|
||||
});
|
||||
if (!geometry.length) return;
|
||||
const top = Math.min(...geometry.map(box => box.top));
|
||||
const bottom = Math.max(...geometry.map(box => box.bottom));
|
||||
const offset = Math.min(0, Math.max(battlefieldTop + gap - top, promptTop - gap - bottom));
|
||||
// The normal discard position wins whenever it clears the response prompt.
|
||||
for (const {card,scale} of geometry) shift(card,0,offset,scale,used);
|
||||
}
|
||||
const api = {
|
||||
refresh(nextOptions) {
|
||||
options = nextOptions;
|
||||
const {footerHeight,status} = nextOptions;
|
||||
const {footerHeight,status,response} = nextOptions;
|
||||
const used=new Set(),a=arena.getBoundingClientRect(),zoom=a.width/arena.clientWidth||1;
|
||||
const left=parseFloat(arena.style.getPropertyValue('--mengsan-hud-left'))||0;
|
||||
const right=parseFloat(arena.style.getPropertyValue('--mengsan-hud-right'))||0;
|
||||
const x=a.left+left*zoom,width=Math.max(100,arena.clientWidth-left-right);
|
||||
const controlTop=ui.control.getBoundingClientRect().top;
|
||||
const prompts=new Set(arena.querySelectorAll(':scope > .hand-tip,:scope > .hand-tip-info'));
|
||||
const dialog=ui.dialog;
|
||||
if(dialog?.isConnected && !dialog.classList.contains('popped') && !dialog.classList.contains('fullheight') && !dialog.forcebutton && !dialog.buttons?.length && !dialog.querySelector('.button,.card,.player,input,textarea,select') && status.event?.player===player)prompts.add(dialog);
|
||||
// The event owns simple native prompt dialogs too, without a global game dependency.
|
||||
const eventDialog=status.event?.dialog;
|
||||
if(eventDialog?.isConnected && eventDialog===dialog && !eventDialog.buttons?.length && !eventDialog.forcebutton && !eventDialog.querySelector('.button,.card,.player,input,textarea,select'))prompts.add(eventDialog);
|
||||
let promptBottom=Math.min(controlTop-10*zoom,a.bottom-(footerHeight+54)*zoom);
|
||||
for(const node of prompts) {
|
||||
if(node.hidden || node.style.display==='none')continue;
|
||||
mark(node,'mengsan-hud-prompt-shuying');used.add(node);
|
||||
position(node,x,0,width,arena.clientHeight<=500?34:64);
|
||||
const height=node.getBoundingClientRect().height;
|
||||
position(node,x,Math.max(a.top+50*zoom,promptBottom-height),width,arena.clientHeight<=500?34:64);
|
||||
promptBottom=node.getBoundingClientRect().top-6*zoom;
|
||||
}
|
||||
const handBox=hand.getBoundingClientRect();
|
||||
const handTop=Math.min(handBox.top,...[...hand.querySelectorAll('.handcards>.card')].map(node=>node.getBoundingClientRect().top));
|
||||
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 controlTop=ui.control.getBoundingClientRect().top;
|
||||
let promptBottom=Math.min(controlTop-10*zoom,a.bottom-(footerHeight+54)*zoom);
|
||||
if(Number.isFinite(responseTop))promptBottom=responseTop-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;
|
||||
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);
|
||||
promptTop=node.getBoundingClientRect().top;
|
||||
promptBottom=promptTop-6*zoom;
|
||||
}
|
||||
if(response && Number.isFinite(promptTop)) clearResponseCards(promptTop,a.top,gap,used);
|
||||
const popups=popped();
|
||||
let hasPopup=false;
|
||||
for(const node of popups) {
|
||||
|
||||
+11
-4
@@ -10,13 +10,20 @@
|
||||
|
||||
.mengsan-battle-potions {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
max-width: 44%;
|
||||
top: var(--mengsan-potion-top, 8px);
|
||||
left: var(--mengsan-potion-left, 8px);
|
||||
width: max-content;
|
||||
max-width: calc(50% - 16px);
|
||||
transition: none;
|
||||
z-index: 7;
|
||||
}
|
||||
|
||||
/* Decade UI sets data-id during every skill-bar rebuild, before its first paint. */
|
||||
.mengsan-hud-arena-shuying :is(.skill-control, .skill-controlzuoshou, .gskill-control)
|
||||
[data-id^="mengsan_use_"][data-id$="_potion_shuying"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.mengsan-potion-slot {
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
|
||||
+44
-1
@@ -58,6 +58,45 @@ export function showPotionDescription(node, view) {
|
||||
parent.append(view.richDescription.slice(start));
|
||||
}
|
||||
|
||||
function positionBattlePotions(root, strip, ui) {
|
||||
if (!root.clientWidth || !root.clientHeight) return;
|
||||
const view = root.ownerDocument.defaultView;
|
||||
const arena = root.getBoundingClientRect();
|
||||
const scaleX = arena.width / root.clientWidth || 1;
|
||||
const scaleY = arena.height / root.clientHeight || 1;
|
||||
const {width,height} = strip.getBoundingClientRect();
|
||||
const gapX = 8 * scaleX, gapY = 8 * scaleY;
|
||||
const startX = arena.left + gapX;
|
||||
const limitX = arena.left + arena.width / 2 - gapX;
|
||||
const obstacles = [];
|
||||
for (const panel of new Set([ui.cardRoundTime,ui.cardRoundTimeNode,ui.cardPileNumber,
|
||||
ui.time,ui.time3,ui.time4,ui.timeNode,ui.roundmenu])) {
|
||||
if (!panel?.isConnected) continue;
|
||||
const style = view.getComputedStyle(panel);
|
||||
if (style.visibility === 'hidden' || style.display === 'none' || Number(style.opacity) === 0) continue;
|
||||
for (const node of [panel,...panel.querySelectorAll('.cardPileNumber,.roundNumber,.time,.cardPileNumber > span')]) {
|
||||
const box = node.getBoundingClientRect();
|
||||
if (box.width && box.height) obstacles.push(box);
|
||||
}
|
||||
}
|
||||
let x = startX, y = arena.top + gapY;
|
||||
for (;;) {
|
||||
const nearby = obstacles.filter(box => box.left < x + width + gapX && box.right + gapX > x &&
|
||||
box.top < y + height + gapY && box.bottom + gapY > y);
|
||||
if (!nearby.length) break;
|
||||
const nextX = Math.max(...nearby.map(box=>box.right)) + gapX;
|
||||
if (nextX + width <= limitX) {
|
||||
x = nextX;
|
||||
} else {
|
||||
x = startX;
|
||||
y = Math.min(...nearby.map(box=>box.bottom)) + gapY;
|
||||
}
|
||||
}
|
||||
const left = `${(x-arena.left)/scaleX}px`, top = `${(y-arena.top)/scaleY}px`;
|
||||
if (strip.style.getPropertyValue('--mengsan-potion-left') !== left) strip.style.setProperty('--mengsan-potion-left',left);
|
||||
if (strip.style.getPropertyValue('--mengsan-potion-top') !== top) strip.style.setProperty('--mengsan-potion-top',top);
|
||||
}
|
||||
|
||||
export function mountPotionSlots(root, player, actions = {}) {
|
||||
const strip = element("div", "mengsan-potion-slots");
|
||||
if (actions.use) strip.classList.add("mengsan-battle-potions");
|
||||
@@ -142,5 +181,9 @@ export function mountPotionSlots(root, player, actions = {}) {
|
||||
strip.addEventListener(type, event => event.stopPropagation());
|
||||
}
|
||||
refresh();
|
||||
return { refresh, dispose() { close(); strip.remove(); } };
|
||||
return {
|
||||
refresh,
|
||||
layoutBattleSlots(ui) { if (actions.use && strip.isConnected) positionBattlePotions(root, strip, ui); },
|
||||
dispose() { close(); strip.remove(); },
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user