mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-06 05:29:39 +00:00
Add configurable attack ratio keybind increment setting (#2835)
If this PR fixes an issue, link it below. If not, delete these two lines. Resolves #2822 ## Description: Adds an attack ratio keybind increment setting with a new dropdown UI, wires keybinds to use the configured step, updates the attack ratio adjustment logic, and makes the select reflect stored settings. <img width="806" height="165" alt="スクリーンショット 2026-01-12 9 11 12" src="https://github.com/user-attachments/assets/c6eaa96d-e147-4927-b3ed-964e832ecc36" /> ## 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 - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: aotumuri --------- Co-authored-by: Ryan <7389646+ryanbarlow97@users.noreply.github.com> Co-authored-by: iamlewis <lewismmmm@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { UserSettings } from "../core/game/UserSettings";
|
||||
import "./components/baseComponents/setting/SettingKeybind";
|
||||
import { SettingKeybind } from "./components/baseComponents/setting/SettingKeybind";
|
||||
import "./components/baseComponents/setting/SettingNumber";
|
||||
import "./components/baseComponents/setting/SettingSelect";
|
||||
import "./components/baseComponents/setting/SettingSlider";
|
||||
import "./components/baseComponents/setting/SettingToggle";
|
||||
import { BaseModal } from "./components/BaseModal";
|
||||
@@ -361,6 +362,23 @@ export class UserSettingModal extends BaseModal {
|
||||
}
|
||||
}
|
||||
|
||||
private changeAttackRatioIncrement(
|
||||
e: CustomEvent<{ value: number | string }>,
|
||||
) {
|
||||
const rawValue = e.detail?.value;
|
||||
const value =
|
||||
typeof rawValue === "number" ? rawValue : parseInt(String(rawValue), 10);
|
||||
if (!Number.isFinite(value)) {
|
||||
console.warn("Select event missing detail.value", e);
|
||||
return;
|
||||
}
|
||||
this.userSettings.setFloat(
|
||||
"settings.attackRatioIncrement",
|
||||
Math.round(value),
|
||||
);
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
private toggleTerritoryPatterns(e: CustomEvent<{ checked: boolean }>) {
|
||||
const enabled = e.detail?.checked;
|
||||
if (typeof enabled !== "boolean") return;
|
||||
@@ -614,7 +632,9 @@ export class UserSettingModal extends BaseModal {
|
||||
<setting-keybind
|
||||
action="attackRatioDown"
|
||||
label=${translateText("user_setting.attack_ratio_down")}
|
||||
description=${translateText("user_setting.attack_ratio_down_desc")}
|
||||
description=${translateText("user_setting.attack_ratio_down_desc", {
|
||||
amount: this.userSettings.attackRatioIncrement(),
|
||||
})}
|
||||
defaultKey="KeyT"
|
||||
.value=${this.getKeyValue("attackRatioDown")}
|
||||
.display=${this.getKeyChar("attackRatioDown")}
|
||||
@@ -624,7 +644,9 @@ export class UserSettingModal extends BaseModal {
|
||||
<setting-keybind
|
||||
action="attackRatioUp"
|
||||
label=${translateText("user_setting.attack_ratio_up")}
|
||||
description=${translateText("user_setting.attack_ratio_up_desc")}
|
||||
description=${translateText("user_setting.attack_ratio_up_desc", {
|
||||
amount: this.userSettings.attackRatioIncrement(),
|
||||
})}
|
||||
defaultKey="KeyY"
|
||||
.value=${this.getKeyValue("attackRatioUp")}
|
||||
.display=${this.getKeyChar("attackRatioUp")}
|
||||
@@ -893,6 +915,21 @@ export class UserSettingModal extends BaseModal {
|
||||
@change=${this.sliderAttackRatio}
|
||||
></setting-slider>
|
||||
|
||||
<!-- ⚔️ Attack Ratio Increment -->
|
||||
<setting-select
|
||||
label=${translateText("user_setting.attack_ratio_increment_label")}
|
||||
description=${translateText("user_setting.attack_ratio_increment_desc")}
|
||||
.options=${[
|
||||
{ value: 1, label: "1%" },
|
||||
{ value: 2, label: "2%" },
|
||||
{ value: 5, label: "5%" },
|
||||
{ value: 10, label: "10%" },
|
||||
{ value: 20, label: "20%" },
|
||||
]}
|
||||
.value=${String(this.userSettings.attackRatioIncrement())}
|
||||
@change=${this.changeAttackRatioIncrement}
|
||||
></setting-select>
|
||||
|
||||
${this.showEasterEggSettings
|
||||
? html`
|
||||
<setting-slider
|
||||
|
||||
Reference in New Issue
Block a user