mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 02:37:44 +00:00
3eccbaa982
## Description: This PR adds a **User Settings** modal accessible from the main UI. Currently available settings include: - Toggle for Dark Mode - Writing Speed Multiplier (slider) - Bug Count (number input) - Troop and Worker Ratio (slider) - Left Click to Open Menu - Emoji toggle Settings are saved via `localStorage` and persist across sessions. There's also a hidden Easter Egg... https://discord.com/channels/1284581928254701718/1286741605310533653/1355900228712009908 <img width="787" alt="スクリーンショット 2025-03-31 8 40 08" src="https://github.com/user-attachments/assets/a9943834-cf40-4fa6-b828-06a8476172da" /> Fixes #482 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: <DISCORD USERNAME> aotumuri
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
@customElement("setting-slider")
|
|
export class SettingSlider extends LitElement {
|
|
@property() label = "Setting";
|
|
@property() description = "";
|
|
@property({ type: Number }) value = 0;
|
|
@property({ type: Number }) min = 0;
|
|
@property({ type: Number }) max = 100;
|
|
@property({ type: Boolean }) easter = false;
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
|
|
private handleInput(e: Event) {
|
|
const input = e.target as HTMLInputElement;
|
|
this.value = Number(input.value);
|
|
this.updateSliderStyle(input);
|
|
|
|
this.dispatchEvent(
|
|
new CustomEvent("change", {
|
|
detail: { value: this.value },
|
|
bubbles: true,
|
|
composed: true,
|
|
}),
|
|
);
|
|
}
|
|
|
|
private handleSliderChange(e: Event) {
|
|
const detail = (e as CustomEvent)?.detail;
|
|
if (!detail || typeof detail.value === "undefined") {
|
|
console.warn("Invalid slider change event", e);
|
|
return;
|
|
}
|
|
|
|
const value = detail.value;
|
|
console.log("Slider changed to", value);
|
|
}
|
|
|
|
private updateSliderStyle(slider: HTMLInputElement) {
|
|
const percent = ((this.value - this.min) / (this.max - this.min)) * 100;
|
|
slider.style.background = `linear-gradient(to right, #2196f3 ${percent}%, #444 ${percent}%)`;
|
|
}
|
|
|
|
firstUpdated() {
|
|
const slider = this.renderRoot.querySelector(
|
|
"input[type=range]",
|
|
) as HTMLInputElement;
|
|
if (slider) this.updateSliderStyle(slider);
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<div class="setting-item vertical${this.easter ? " easter-egg" : ""}">
|
|
<div class="setting-label-group">
|
|
<label class="setting-label" for="setting-slider-input"
|
|
>${this.label}</label
|
|
>
|
|
<div class="setting-description">${this.description}</div>
|
|
</div>
|
|
<input
|
|
type="range"
|
|
id="setting-slider-input"
|
|
class="setting-input slider full-width"
|
|
min=${this.min}
|
|
max=${this.max}
|
|
.value=${String(this.value)}
|
|
@input=${this.handleInput}
|
|
/>
|
|
<div class="slider-value">${this.value}%</div>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|