экран настроек. черные рамки
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { getRenderSettings, setRenderSettings } from '../pixi/renderSettings';
|
||||
|
||||
/** Builds a toggle button that shows its current on/off state in its own label and flips it on
|
||||
* click — the DOM-side equivalent of a checkbox, styled like the rest of the menu's buttons. */
|
||||
function createToggle(label: string, initial: boolean, onChange: (value: boolean) => void): HTMLButtonElement {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'menu-btn';
|
||||
let value = initial;
|
||||
|
||||
function render(): void {
|
||||
btn.textContent = `${label}: ${value ? 'вкл' : 'выкл'}`;
|
||||
}
|
||||
render();
|
||||
|
||||
btn.addEventListener('click', () => {
|
||||
value = !value;
|
||||
render();
|
||||
onChange(value);
|
||||
});
|
||||
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** Builds the settings screen — rendering-diagnostics toggles that take effect the next time a
|
||||
* game is (re)started (GameCanvas reads them once, on mount), reachable from the main menu. */
|
||||
export function createSettingsScreen(onBack: () => void): HTMLElement {
|
||||
const root = document.createElement('div');
|
||||
root.className = 'main-menu';
|
||||
|
||||
const title = document.createElement('h1');
|
||||
title.className = 'main-menu__title';
|
||||
title.textContent = 'Настройки';
|
||||
|
||||
const buttons = document.createElement('div');
|
||||
buttons.className = 'main-menu__buttons';
|
||||
|
||||
const settings = getRenderSettings();
|
||||
|
||||
const antialiasingBtn = createToggle('Антиалиасинг экрана', settings.antialiasing, (value) => {
|
||||
setRenderSettings({ antialiasing: value });
|
||||
});
|
||||
|
||||
const noScaleBtn = createToggle('Рендер без масштабирования (k=1)', settings.noScale, (value) => {
|
||||
setRenderSettings({ noScale: value });
|
||||
});
|
||||
|
||||
const backBtn = document.createElement('button');
|
||||
backBtn.type = 'button';
|
||||
backBtn.className = 'menu-btn';
|
||||
backBtn.textContent = 'Назад';
|
||||
backBtn.addEventListener('click', onBack);
|
||||
|
||||
buttons.append(antialiasingBtn, noScaleBtn, backBtn);
|
||||
root.append(title, buttons);
|
||||
return root;
|
||||
}
|
||||
Reference in New Issue
Block a user