Layout: Statuswerte links als Spalte, Power-up-Legende rechts immer offen; Chrome-Messung für Spalten-Layout inkl. Überlauf-Korrektur

This commit is contained in:
michael committed 2026-10-13 13:59:54 +00:00
1 parent d88f5b54f1
commit aa44b05f31
2 files changed
+84 -41

No files matched your search

+83 -41
View File
@@ -114,8 +114,9 @@
#msg .accent { color: var(--green); }
#dims { font-variant-numeric: tabular-nums; color: var(--dim); }
#foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: calc(11.5px * var(--s)); color: var(--muted); flex-wrap: wrap; }
#actions { margin-left: auto; display: flex; gap: 8px; }
#foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: calc(11.5px * var(--s)); color: var(--muted); flex-wrap: nowrap; }
#foot .info { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#actions { margin-left: auto; display: flex; gap: 8px; flex: none; white-space: nowrap; }
button {
font-family: var(--font); font-size: calc(11.5px * var(--s)); color: var(--text);
background: var(--chip); border: 1px solid var(--border-2);
@@ -125,8 +126,18 @@
button:hover { background: #16203a; border-color: var(--green); }
button:active { transform: translateY(1px); }
details { margin-top: 10px; }
summary { font-size: calc(12px * var(--s)); color: var(--muted); cursor: pointer; }
#main { display: block; }
#side { margin-bottom: 8px; }
#rail { margin-top: 10px; }
body.cols #main { display: flex; align-items: flex-start; gap: 10px; }
body.cols #side { flex: none; width: calc(148px * var(--s)); margin: 0; }
body.cols #rail { flex: none; width: calc(238px * var(--s)); margin: 0; }
body.cols #strip { flex-direction: column; align-items: stretch; gap: calc(6px * var(--s)); margin-left: 0; }
body.cols .pill { border-radius: 10px; justify-content: space-between; }
body.cols #wrap { flex: 1 1 0; min-width: 0; width: auto; }
body.cols #pu-legend { grid-template-columns: 1fr; }
body.cols #fxbar { flex-direction: column; align-items: flex-start; gap: calc(6px * var(--s)); }
#legend .ltitle { font-size: calc(12px * var(--s)); color: var(--muted); margin: 4px 0 6px; }
#pu-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; margin-top: 10px; }
.card {
display: flex; gap: 9px; align-items: center;
@@ -143,7 +154,7 @@
.card .d { font-size: calc(11px * var(--s)); color: var(--dim); margin-top: 2px; }
/* sehr niedrige Fenster: Kopf/Links ausblenden, Spielfeld bekommt den Platz */
body.compact #sub, body.compact #foot, body.compact details { display: none; }
body.compact #sub, body.compact #foot, body.compact #rail { display: none; }
body.compact #fxbar { min-height: 22px; }
body.compact #head { margin-bottom: 6px; }
body.compact { padding-top: 6px; padding-bottom: 6px; }
@@ -156,18 +167,20 @@
<div id="title">Breakout · Neon Clone</div>
<div id="sub">Maus klickt ins Spielfeld und wird dort gefangen · <kbd>ESC</kbd> gibt sie frei · Klick / Leertaste schießt · <kbd>P</kbd> pausiert · <kbd>R</kbd> Neustart</div>
</div>
<div id="strip">
<span class="pill" id="score">Punkte <b>0</b></span>
<span class="pill" id="best">Bestwert <b>0</b></span>
<span class="pill" id="level">Level <b>1</b></span>
<span class="pill" id="combo">Combo <b>×1,0</b></span>
<span class="pill" id="lives">Leben <span id="hearts"></span></span>
</div>
</div>
<div id="fxbar"><span class="lbl">Aktive Power-ups</span></div>
<div id="main">
<aside id="side">
<div id="strip">
<span class="pill" id="score">Punkte <b>0</b></span>
<span class="pill" id="best">Bestwert <b>0</b></span>
<span class="pill" id="level">Level <b>1</b></span>
<span class="pill" id="combo">Combo <b>×1,0</b></span>
<span class="pill" id="lives">Leben <span id="hearts"></span></span>
</div>
</aside>
<div id="wrap">
<div id="wrap">
<canvas id="cv"></canvas>
<div id="msg">
<div class="big">Breakout</div>
@@ -182,19 +195,23 @@
</div>
</div>
<aside id="rail">
<div id="fxbar"><span class="lbl">Aktive Power-ups</span></div>
<div id="legend">
<div class="ltitle">Power-ups &amp; Legende</div>
<div id="pu-legend"></div>
</div>
</aside>
</div>
<div id="foot">
<span>← → Pfeiltasten gehen auch · <span id="laserhint">Laser feuert automatisch</span> · <span id="dims"></span></span>
<span class="info">← → Pfeiltasten gehen auch · <span id="laserhint">Laser feuert automatisch</span> · <span id="dims"></span></span>
<div id="actions">
<button id="options">Optionen</button>
<button id="sound">Ton an</button>
<button id="restart">Neustart</button>
</div>
</div>
<details>
<summary>Power-ups &amp; Legende</summary>
<div id="pu-legend"></div>
</details>
</div>
<script>
@@ -309,7 +326,9 @@
var rootEl = document.documentElement;
var headEl = document.getElementById('head');
var footEl = document.getElementById('foot');
var detailsEl = document.querySelector('details');
var sideEl = document.getElementById('side');
var railEl = document.getElementById('rail');
var bodyCols = false;
var dimsEl = document.getElementById('dims');
var ASPECT = W / H; /* 680 / 470 */
@@ -324,10 +343,10 @@
return document.documentElement.clientHeight || window.innerHeight || 600;
}
/* chrome-Höhe (Kopf + Power-up-Leiste + Fuß + optional Legende) */
/* chrome-Höhe: Spaltenmodus nur Kopf+Fuß, sonst plus Seiten- und Legendenblock */
function chromeH() {
var h = headEl.offsetHeight + fxbar.offsetHeight + footEl.offsetHeight;
if (detailsEl && detailsEl.open) h += detailsEl.offsetHeight;
var h = headEl.offsetHeight + footEl.offsetHeight;
if (!bodyCols) h += sideEl.offsetHeight + railEl.offsetHeight;
return h;
}
@@ -374,26 +393,27 @@
: (document.documentElement.clientWidth || window.innerWidth || 720);
var panelFull = document.getElementById('panel').getBoundingClientRect().width;
if (!isFinite(panelFull) || panelFull < 240) panelFull = vw;
var maxFieldW = Math.max(240, wrap.clientWidth || (vw - 60));
var sideW1 = bodyCols ? (sideEl.offsetWidth + railEl.offsetWidth + 20) : 0;
var content1 = wrap.clientWidth + sideW1;
var bodyPadY = padPair(document.body, 'paddingTop', 'paddingBottom');
var panelPadY = padPair(document.getElementById('panel'), 'paddingTop', 'paddingBottom');
var chrome1 = headEl.offsetHeight + fxbar.offsetHeight + footEl.offsetHeight
+ (detailsEl && detailsEl.open ? detailsEl.offsetHeight : 0);
return { vw: vw, panelFull: panelFull, maxFieldW: maxFieldW,
panelExtraX: Math.max(0, panelFull - maxFieldW),
chrome1: chrome1, padY: bodyPadY + panelPadY };
return { vw: vw, panelFull: panelFull, sideW1: sideW1,
extra: Math.max(8, panelFull - content1),
chrome1: chromeH(), padY: bodyPadY + panelPadY };
}
function fitField(base) {
/* chrome skaliert ungefähr mit s; löse fieldW = (availH - chrome(s)) * ASPECT */
var s = 1, fieldW = 0;
/* chrome skaliert ungefähr mit s; löse fieldW = (availH - chrome(s)) * ASPECT.
Im Spaltenmodus kosten die Seiten zusätzlich Breite (sideW1 * s). */
var s = 1, fieldW = 0, pw = 0;
for (var it = 0; it < 14; it++) {
var chromeAtS = base.chrome1 * s;
var availH = base.vw ? (viewportH() - base.padY - chromeAtS) : 470;
var byH = Math.max(240, availH) * ASPECT;
fieldW = Math.min(base.maxFieldW, byH);
var byW = Math.max(240, base.panelFull - base.extra - base.sideW1 * s);
fieldW = Math.min(byW, byH);
s = clamp(fieldW / 720, S_MIN, S_MAX);
var pw = Math.min(fieldW + base.panelExtraX, base.panelFull);
pw = Math.min(base.panelFull, fieldW + base.extra + base.sideW1 * s);
/* Stabilitätskriterium: geänderte Skala ->chrome ändert -> erneut */
if (it > 0 && Math.abs(pw - lastPw) < 1) { rootEl.style.setProperty('--pw', pw.toFixed(1) + 'px'); break; }
lastPw = pw;
@@ -401,24 +421,44 @@
rootEl.style.setProperty('--s', s.toFixed(3));
}
/* letzte sichere Anwendung, falls Loop divergiert */
var pwf = Math.min(fieldW + base.panelExtraX, base.panelFull);
var pwf = Math.min(base.panelFull, fieldW + base.extra + base.sideW1 * s);
rootEl.style.setProperty('--pw', pwf.toFixed(1) + 'px');
rootEl.style.setProperty('--s', s.toFixed(3));
return s;
}
var lastPw = 0;
function layout() {
var vh = viewportH();
/* Niedrige Fenster: Kopfzeilen/Legende ausblenden, damit das Feld wächst */
/* Niedrige Fenster: kompakt (Legende/Sides unten ausgeblendet) */
document.body.classList.toggle('compact', vh < 600);
S_MAX = document.body.classList.contains('compact') ? 1.18 : 1.34;
/* Breites Fenster: Statuswerte links, Power-ups rechts als Spalten */
var vw = document.documentElement.clientWidth || window.innerWidth || 720;
bodyCols = vw >= 940 && vh >= 600;
document.body.classList.toggle('cols', bodyCols);
var base = measureChromeBase();
fitField(base);
var s = fitField(base);
var dim = resize();
if (dimsEl) dimsEl.textContent = dim.w + ' × ' + dim.h + ' px';
/* Sicherheitsnetz: ragt das Panel über den Viewport (z.B. rechte Spalte höher
als das Spielfeld), tatsächlich nachmessen und bis zu 3x nachjustieren. */
for (var guard = 0; guard < 3; guard++) {
var panelH = document.getElementById('panel').getBoundingClientRect().height;
var allowed = viewportH() - base.padY;
if (!isFinite(panelH) || panelH <= allowed + 2) break;
var wrapH = wrap.clientHeight || 1;
var sCur = clamp(parseFloat(rootEl.style.getPropertyValue('--s')) || s, S_MIN, S_MAX);
base.chrome1 = Math.max(40, (panelH - wrapH) / Math.max(0.5, sCur));
s = fitField(base);
dim = resize();
if (dimsEl) dimsEl.textContent = dim.w + ' × ' + dim.h + ' px';
}
}
var layoutQueued = false;
@@ -959,6 +999,7 @@
var fxChips = {};
function hudFx() {
/* Chips bleiben bestehen, nur Balkenbreite aktualisiert -> kein Flackern */
var changed = false;
if (!fxChips.lbl) {
var lbl = document.createElement('span'); lbl.className = 'lbl'; lbl.textContent = 'Aktive Power-ups';
fxbar.appendChild(lbl);
@@ -981,6 +1022,7 @@
chip.appendChild(glyph); chip.appendChild(label); chip.appendChild(bar);
fxbar.appendChild(chip);
e = fxChips[p.id] = { el: chip, fill: fill };
changed = true;
}
var pct = Math.max(0, Math.min(100, fx[p.id] / p.dur * 100));
e.fill.style.width = pct.toFixed(1) + '%';
@@ -995,12 +1037,13 @@
chip2.appendChild(g2); chip2.appendChild(c2);
fxbar.appendChild(chip2);
eb = fxChips.balls = { el: chip2, cnt: c2 };
changed = true;
}
eb.cnt.textContent = balls.length + ' Bälle';
}
for (var k in fxChips) if (!live[k]) { fxbar.removeChild(fxChips[k].el); delete fxChips[k]; }
/* Kein Layout mitten im Spiel – fxbar hat reservierte Höhe; Layout nur bei
echter Größenänderung des Fensters (vermeidet instabile Neuberechnung). */
for (var k in fxChips) if (!live[k]) { fxbar.removeChild(fxChips[k].el); delete fxChips[k]; changed = true; }
/* Nur bei echter Chip-Änderung neu layouten (fxbar kann umbrechen -> Höhe ändert sich) */
if (changed) requestLayout();
}
/* ---------------- input ---------------- */
@@ -1110,7 +1153,6 @@
window.addEventListener('resize', requestLayout);
window.addEventListener('orientationchange', requestLayout);
if (window.visualViewport) window.visualViewport.addEventListener('resize', requestLayout);
if (detailsEl) detailsEl.addEventListener('toggle', requestLayout);
document.addEventListener('visibilitychange', function () {
if (document.hidden && state === 'playing') { state = 'paused'; showMsg('Pause', 'Klick zum weiterspielen'); }
});