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:
1 parent
d88f5b54f1
commit
aa44b05f31
2 files changed
+84
-41
No files matched your search
@@ -41,4 +41,5 @@ Umschaltbar, Persistenz via `localStorage` (`breakout.options`):
|
|||||||
- Combo-Sound: Tonhöhe steigt mit jedem Stein in der Combo-Kette
|
- Combo-Sound: Tonhöhe steigt mit jedem Stein in der Combo-Kette
|
||||||
- Combo-Multiplikator, Leben, Level, Steine mit Hitpoints
|
- Combo-Multiplikator, Leben, Level, Steine mit Hitpoints
|
||||||
- Power-up-HUD mit Countdown-Balken, Highscore-Top-5 via `localStorage` (Beim Game Over einsortiert)
|
- Power-up-HUD mit Countdown-Balken, Highscore-Top-5 via `localStorage` (Beim Game Over einsortiert)
|
||||||
|
- Breites Fenster (ab 940 px): Statuswerte (Punkte/Bestwert/Level/Combo/Leben) als Liste links, aktive Power-ups + Legende immer offen rechts; schmale/niedrige Fenster stapeln alles unter das Spielfeld
|
||||||
- Automatische Skalung: Spielfeld löst Fensterbreite und -höhe gemeinsam auf, UI skaliert proportional, HiDPI-scharf, Kompakt-Modus bei niedrigen Fenstern
|
- Automatische Skalung: Spielfeld löst Fensterbreite und -höhe gemeinsam auf, UI skaliert proportional, HiDPI-scharf, Kompakt-Modus bei niedrigen Fenstern
|
||||||
+83
-41
@@ -114,8 +114,9 @@
|
|||||||
#msg .accent { color: var(--green); }
|
#msg .accent { color: var(--green); }
|
||||||
|
|
||||||
#dims { font-variant-numeric: tabular-nums; color: var(--dim); }
|
#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; }
|
#foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: calc(11.5px * var(--s)); color: var(--muted); flex-wrap: nowrap; }
|
||||||
#actions { margin-left: auto; display: flex; gap: 8px; }
|
#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 {
|
button {
|
||||||
font-family: var(--font); font-size: calc(11.5px * var(--s)); color: var(--text);
|
font-family: var(--font); font-size: calc(11.5px * var(--s)); color: var(--text);
|
||||||
background: var(--chip); border: 1px solid var(--border-2);
|
background: var(--chip); border: 1px solid var(--border-2);
|
||||||
@@ -125,8 +126,18 @@
|
|||||||
button:hover { background: #16203a; border-color: var(--green); }
|
button:hover { background: #16203a; border-color: var(--green); }
|
||||||
button:active { transform: translateY(1px); }
|
button:active { transform: translateY(1px); }
|
||||||
|
|
||||||
details { margin-top: 10px; }
|
#main { display: block; }
|
||||||
summary { font-size: calc(12px * var(--s)); color: var(--muted); cursor: pointer; }
|
#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; }
|
#pu-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; margin-top: 10px; }
|
||||||
.card {
|
.card {
|
||||||
display: flex; gap: 9px; align-items: center;
|
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; }
|
.card .d { font-size: calc(11px * var(--s)); color: var(--dim); margin-top: 2px; }
|
||||||
|
|
||||||
/* sehr niedrige Fenster: Kopf/Links ausblenden, Spielfeld bekommt den Platz */
|
/* 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 #fxbar { min-height: 22px; }
|
||||||
body.compact #head { margin-bottom: 6px; }
|
body.compact #head { margin-bottom: 6px; }
|
||||||
body.compact { padding-top: 6px; padding-bottom: 6px; }
|
body.compact { padding-top: 6px; padding-bottom: 6px; }
|
||||||
@@ -156,18 +167,20 @@
|
|||||||
<div id="title">Breakout · Neon Clone</div>
|
<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 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>
|
||||||
<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>
|
||||||
|
|
||||||
<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>
|
<canvas id="cv"></canvas>
|
||||||
<div id="msg">
|
<div id="msg">
|
||||||
<div class="big">Breakout</div>
|
<div class="big">Breakout</div>
|
||||||
@@ -182,19 +195,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<aside id="rail">
|
||||||
|
<div id="fxbar"><span class="lbl">Aktive Power-ups</span></div>
|
||||||
|
<div id="legend">
|
||||||
|
<div class="ltitle">Power-ups & Legende</div>
|
||||||
|
<div id="pu-legend"></div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="foot">
|
<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">
|
<div id="actions">
|
||||||
<button id="options">Optionen</button>
|
<button id="options">Optionen</button>
|
||||||
<button id="sound">Ton an</button>
|
<button id="sound">Ton an</button>
|
||||||
<button id="restart">Neustart</button>
|
<button id="restart">Neustart</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Power-ups & Legende</summary>
|
|
||||||
<div id="pu-legend"></div>
|
|
||||||
</details>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -309,7 +326,9 @@
|
|||||||
var rootEl = document.documentElement;
|
var rootEl = document.documentElement;
|
||||||
var headEl = document.getElementById('head');
|
var headEl = document.getElementById('head');
|
||||||
var footEl = document.getElementById('foot');
|
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 dimsEl = document.getElementById('dims');
|
||||||
var ASPECT = W / H; /* 680 / 470 */
|
var ASPECT = W / H; /* 680 / 470 */
|
||||||
|
|
||||||
@@ -324,10 +343,10 @@
|
|||||||
return document.documentElement.clientHeight || window.innerHeight || 600;
|
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() {
|
function chromeH() {
|
||||||
var h = headEl.offsetHeight + fxbar.offsetHeight + footEl.offsetHeight;
|
var h = headEl.offsetHeight + footEl.offsetHeight;
|
||||||
if (detailsEl && detailsEl.open) h += detailsEl.offsetHeight;
|
if (!bodyCols) h += sideEl.offsetHeight + railEl.offsetHeight;
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,26 +393,27 @@
|
|||||||
: (document.documentElement.clientWidth || window.innerWidth || 720);
|
: (document.documentElement.clientWidth || window.innerWidth || 720);
|
||||||
var panelFull = document.getElementById('panel').getBoundingClientRect().width;
|
var panelFull = document.getElementById('panel').getBoundingClientRect().width;
|
||||||
if (!isFinite(panelFull) || panelFull < 240) panelFull = vw;
|
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 bodyPadY = padPair(document.body, 'paddingTop', 'paddingBottom');
|
||||||
var panelPadY = padPair(document.getElementById('panel'), 'paddingTop', 'paddingBottom');
|
var panelPadY = padPair(document.getElementById('panel'), 'paddingTop', 'paddingBottom');
|
||||||
var chrome1 = headEl.offsetHeight + fxbar.offsetHeight + footEl.offsetHeight
|
return { vw: vw, panelFull: panelFull, sideW1: sideW1,
|
||||||
+ (detailsEl && detailsEl.open ? detailsEl.offsetHeight : 0);
|
extra: Math.max(8, panelFull - content1),
|
||||||
return { vw: vw, panelFull: panelFull, maxFieldW: maxFieldW,
|
chrome1: chromeH(), padY: bodyPadY + panelPadY };
|
||||||
panelExtraX: Math.max(0, panelFull - maxFieldW),
|
|
||||||
chrome1: chrome1, padY: bodyPadY + panelPadY };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fitField(base) {
|
function fitField(base) {
|
||||||
/* chrome skaliert ungefähr mit s; löse fieldW = (availH - chrome(s)) * ASPECT */
|
/* chrome skaliert ungefähr mit s; löse fieldW = (availH - chrome(s)) * ASPECT.
|
||||||
var s = 1, fieldW = 0;
|
Im Spaltenmodus kosten die Seiten zusätzlich Breite (sideW1 * s). */
|
||||||
|
var s = 1, fieldW = 0, pw = 0;
|
||||||
for (var it = 0; it < 14; it++) {
|
for (var it = 0; it < 14; it++) {
|
||||||
var chromeAtS = base.chrome1 * s;
|
var chromeAtS = base.chrome1 * s;
|
||||||
var availH = base.vw ? (viewportH() - base.padY - chromeAtS) : 470;
|
var availH = base.vw ? (viewportH() - base.padY - chromeAtS) : 470;
|
||||||
var byH = Math.max(240, availH) * ASPECT;
|
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);
|
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 */
|
/* 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; }
|
if (it > 0 && Math.abs(pw - lastPw) < 1) { rootEl.style.setProperty('--pw', pw.toFixed(1) + 'px'); break; }
|
||||||
lastPw = pw;
|
lastPw = pw;
|
||||||
@@ -401,24 +421,44 @@
|
|||||||
rootEl.style.setProperty('--s', s.toFixed(3));
|
rootEl.style.setProperty('--s', s.toFixed(3));
|
||||||
}
|
}
|
||||||
/* letzte sichere Anwendung, falls Loop divergiert */
|
/* 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('--pw', pwf.toFixed(1) + 'px');
|
||||||
rootEl.style.setProperty('--s', s.toFixed(3));
|
rootEl.style.setProperty('--s', s.toFixed(3));
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
var lastPw = 0;
|
var lastPw = 0;
|
||||||
|
|
||||||
function layout() {
|
function layout() {
|
||||||
var vh = viewportH();
|
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);
|
document.body.classList.toggle('compact', vh < 600);
|
||||||
S_MAX = document.body.classList.contains('compact') ? 1.18 : 1.34;
|
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();
|
var base = measureChromeBase();
|
||||||
fitField(base);
|
var s = fitField(base);
|
||||||
|
|
||||||
var dim = resize();
|
var dim = resize();
|
||||||
if (dimsEl) dimsEl.textContent = dim.w + ' × ' + dim.h + ' px';
|
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;
|
var layoutQueued = false;
|
||||||
@@ -959,6 +999,7 @@
|
|||||||
var fxChips = {};
|
var fxChips = {};
|
||||||
function hudFx() {
|
function hudFx() {
|
||||||
/* Chips bleiben bestehen, nur Balkenbreite aktualisiert -> kein Flackern */
|
/* Chips bleiben bestehen, nur Balkenbreite aktualisiert -> kein Flackern */
|
||||||
|
var changed = false;
|
||||||
if (!fxChips.lbl) {
|
if (!fxChips.lbl) {
|
||||||
var lbl = document.createElement('span'); lbl.className = 'lbl'; lbl.textContent = 'Aktive Power-ups';
|
var lbl = document.createElement('span'); lbl.className = 'lbl'; lbl.textContent = 'Aktive Power-ups';
|
||||||
fxbar.appendChild(lbl);
|
fxbar.appendChild(lbl);
|
||||||
@@ -981,6 +1022,7 @@
|
|||||||
chip.appendChild(glyph); chip.appendChild(label); chip.appendChild(bar);
|
chip.appendChild(glyph); chip.appendChild(label); chip.appendChild(bar);
|
||||||
fxbar.appendChild(chip);
|
fxbar.appendChild(chip);
|
||||||
e = fxChips[p.id] = { el: chip, fill: fill };
|
e = fxChips[p.id] = { el: chip, fill: fill };
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
var pct = Math.max(0, Math.min(100, fx[p.id] / p.dur * 100));
|
var pct = Math.max(0, Math.min(100, fx[p.id] / p.dur * 100));
|
||||||
e.fill.style.width = pct.toFixed(1) + '%';
|
e.fill.style.width = pct.toFixed(1) + '%';
|
||||||
@@ -995,12 +1037,13 @@
|
|||||||
chip2.appendChild(g2); chip2.appendChild(c2);
|
chip2.appendChild(g2); chip2.appendChild(c2);
|
||||||
fxbar.appendChild(chip2);
|
fxbar.appendChild(chip2);
|
||||||
eb = fxChips.balls = { el: chip2, cnt: c2 };
|
eb = fxChips.balls = { el: chip2, cnt: c2 };
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
eb.cnt.textContent = balls.length + ' Bälle';
|
eb.cnt.textContent = balls.length + ' Bälle';
|
||||||
}
|
}
|
||||||
for (var k in fxChips) if (!live[k]) { fxbar.removeChild(fxChips[k].el); delete fxChips[k]; }
|
for (var k in fxChips) if (!live[k]) { fxbar.removeChild(fxChips[k].el); delete fxChips[k]; changed = true; }
|
||||||
/* Kein Layout mitten im Spiel – fxbar hat reservierte Höhe; Layout nur bei
|
/* Nur bei echter Chip-Änderung neu layouten (fxbar kann umbrechen -> Höhe ändert sich) */
|
||||||
echter Größenänderung des Fensters (vermeidet instabile Neuberechnung). */
|
if (changed) requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- input ---------------- */
|
/* ---------------- input ---------------- */
|
||||||
@@ -1110,7 +1153,6 @@
|
|||||||
window.addEventListener('resize', requestLayout);
|
window.addEventListener('resize', requestLayout);
|
||||||
window.addEventListener('orientationchange', requestLayout);
|
window.addEventListener('orientationchange', requestLayout);
|
||||||
if (window.visualViewport) window.visualViewport.addEventListener('resize', requestLayout);
|
if (window.visualViewport) window.visualViewport.addEventListener('resize', requestLayout);
|
||||||
if (detailsEl) detailsEl.addEventListener('toggle', requestLayout);
|
|
||||||
document.addEventListener('visibilitychange', function () {
|
document.addEventListener('visibilitychange', function () {
|
||||||
if (document.hidden && state === 'playing') { state = 'paused'; showMsg('Pause', 'Klick zum weiterspielen'); }
|
if (document.hidden && state === 'playing') { state = 'paused'; showMsg('Pause', 'Klick zum weiterspielen'); }
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user