mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 22:48:12 +00:00
Feature/colorblind mode (#4150)
**Add approved & assigned issue number here:** Resolves #2549 ## Description: Adds colorblind mode. Similar to dark mode, it exists as a toggle in settings. When enabled, it swaps the game's theme (which is refactored to extend from a theme base class) to use more colorblind-friendly colors and brightness variations. Borders are darkened, and terrarin is separated by lightness. Friendly/Foe colors and switched to blue/orange instead of red/green. The theme refactor supports adding new themes without having to reimplement the color distribution system. New themes can extend the BaseTheme and supply the data, such as palettes, team-color variations, and terrain. New setting: <img width="880" height="273" alt="Screenshot 2026-06-04 at 11 30 27 AM" src="https://github.com/user-attachments/assets/d5d573d5-cc64-4ac1-95c2-00627faf17cc" /> New color palette: <img width="1119" height="757" alt="Screenshot 2026-06-04 at 11 30 59 AM" src="https://github.com/user-attachments/assets/2bb15bc9-992b-41ae-ab0e-b01fe0c3c6bb" /> ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory ## Please put your Discord username so you can be contacted if a bug or regression is found: jetaviz
This commit is contained in:
@@ -299,6 +299,18 @@ export class GraphicsSettingsModal extends LitElement implements Controller {
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
/** Merge a patch into the accessibility graphics overrides and persist it. */
|
||||
private patchAccessibility(
|
||||
patch: Partial<GraphicsOverrides["accessibility"]>,
|
||||
) {
|
||||
const current = this.userSettings.graphicsOverrides();
|
||||
this.userSettings.setGraphicsOverrides({
|
||||
...current,
|
||||
accessibility: { ...current.accessibility, ...patch },
|
||||
});
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
private currentSpecialEffects(): boolean {
|
||||
return (
|
||||
this.userSettings.graphicsOverrides().passEnabled?.fx ??
|
||||
@@ -310,6 +322,18 @@ export class GraphicsSettingsModal extends LitElement implements Controller {
|
||||
this.patchPassEnabled({ fx: !this.currentSpecialEffects() });
|
||||
}
|
||||
|
||||
/** Whether colorblind mode is currently enabled. */
|
||||
private currentColorblind(): boolean {
|
||||
return (
|
||||
this.userSettings.graphicsOverrides().accessibility?.colorblind ?? false
|
||||
);
|
||||
}
|
||||
|
||||
/** Toggle colorblind-friendly colors. */
|
||||
private onToggleColorblind() {
|
||||
this.patchAccessibility({ colorblind: !this.currentColorblind() });
|
||||
}
|
||||
|
||||
private onNameScaleChange(event: Event) {
|
||||
const value = parseFloat((event.target as HTMLInputElement).value);
|
||||
this.patchName({ nameScaleFactor: value });
|
||||
@@ -356,6 +380,7 @@ export class GraphicsSettingsModal extends LitElement implements Controller {
|
||||
const territoryAlpha = this.currentTerritoryAlpha();
|
||||
const railDrawDistance = RAIL_ZOOM_MAX - this.currentRailMinZoom();
|
||||
const railThickness = this.currentRailThickness();
|
||||
const colorblind = this.currentColorblind();
|
||||
|
||||
return html`
|
||||
<div
|
||||
@@ -717,6 +742,31 @@ export class GraphicsSettingsModal extends LitElement implements Controller {
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div
|
||||
class="px-3 py-1 text-xs font-semibold text-slate-400 uppercase tracking-wider mt-2"
|
||||
>
|
||||
${translateText("graphics_setting.section_accessibility")}
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="flex gap-3 items-center w-full text-left p-3 hover:bg-slate-700 rounded-sm text-white transition-colors"
|
||||
@click=${this.onToggleColorblind}
|
||||
>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium">
|
||||
${translateText("user_setting.colorblind_label")}
|
||||
</div>
|
||||
<div class="text-sm text-slate-400">
|
||||
${translateText("user_setting.colorblind_desc")}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-slate-400">
|
||||
${colorblind
|
||||
? translateText("user_setting.on")
|
||||
: translateText("user_setting.off")}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div class="border-t border-slate-600 pt-3 mt-4">
|
||||
<button
|
||||
class="flex gap-3 items-center w-full text-left p-3 hover:bg-slate-700 rounded-sm text-white transition-colors"
|
||||
|
||||
Reference in New Issue
Block a user