mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 13:09:47 +00:00
add shortcut key
This commit is contained in:
@@ -497,6 +497,8 @@
|
||||
"boat_attack_desc": "Send a boat attack to the tile under your cursor.",
|
||||
"ground_attack": "Ground Attack",
|
||||
"ground_attack_desc": "Send a ground attack to the tile under your cursor.",
|
||||
"local_attack": "Localized Attack (Hold)",
|
||||
"local_attack_desc": "Hold to start attacks from the nearest border tile to the target.",
|
||||
"zoom_controls": "Zoom Controls",
|
||||
"zoom_out": "Zoom Out",
|
||||
"zoom_out_desc": "Zoom out the map",
|
||||
|
||||
@@ -688,12 +688,15 @@ export class ClientGameRunner {
|
||||
if (!this.myPlayer) return;
|
||||
|
||||
const targetId = this.gameView.owner(tile).id();
|
||||
const sourceTile = await resolveAttackSourceTile(
|
||||
this.gameView,
|
||||
this.myPlayer,
|
||||
targetId,
|
||||
tile,
|
||||
);
|
||||
const useLocalAttack = this.renderer.uiState.localAttackHeld;
|
||||
const sourceTile = useLocalAttack
|
||||
? await resolveAttackSourceTile(
|
||||
this.gameView,
|
||||
this.myPlayer,
|
||||
targetId,
|
||||
tile,
|
||||
)
|
||||
: null;
|
||||
this.eventBus.emit(
|
||||
new SendAttackIntentEvent(
|
||||
targetId,
|
||||
|
||||
@@ -49,6 +49,7 @@ export class HelpModal extends BaseModal {
|
||||
zoomIn: "KeyE",
|
||||
attackRatioDown: "KeyT",
|
||||
attackRatioUp: "KeyY",
|
||||
localAttack: "KeyL",
|
||||
shiftKey: "ShiftLeft",
|
||||
modifierKey: isMac ? "MetaLeft" : "ControlLeft",
|
||||
altKey: "AltLeft",
|
||||
|
||||
@@ -212,6 +212,7 @@ export class InputHandler {
|
||||
attackRatioUp: "KeyY",
|
||||
boatAttack: "KeyB",
|
||||
groundAttack: "KeyG",
|
||||
localAttack: "KeyL",
|
||||
swapDirection: "KeyU",
|
||||
modifierKey: isMac ? "MetaLeft" : "ControlLeft",
|
||||
altKey: "AltLeft",
|
||||
@@ -338,6 +339,7 @@ export class InputHandler {
|
||||
"Equal",
|
||||
this.keybinds.attackRatioDown,
|
||||
this.keybinds.attackRatioUp,
|
||||
this.keybinds.localAttack,
|
||||
this.keybinds.centerCamera,
|
||||
"ControlLeft",
|
||||
"ControlRight",
|
||||
@@ -347,6 +349,10 @@ export class InputHandler {
|
||||
) {
|
||||
this.activeKeys.add(e.code);
|
||||
}
|
||||
|
||||
if (e.code === this.keybinds.localAttack) {
|
||||
this.uiState.localAttackHeld = true;
|
||||
}
|
||||
});
|
||||
window.addEventListener("keyup", (e) => {
|
||||
const isTextInput = this.isTextInputTarget(e.target);
|
||||
@@ -385,6 +391,10 @@ export class InputHandler {
|
||||
this.eventBus.emit(new AttackRatioEvent(10));
|
||||
}
|
||||
|
||||
if (e.code === this.keybinds.localAttack) {
|
||||
this.uiState.localAttackHeld = false;
|
||||
}
|
||||
|
||||
if (e.code === this.keybinds.centerCamera) {
|
||||
e.preventDefault();
|
||||
this.eventBus.emit(new CenterCameraEvent());
|
||||
@@ -631,6 +641,7 @@ export class InputHandler {
|
||||
clearInterval(this.moveInterval);
|
||||
}
|
||||
this.activeKeys.clear();
|
||||
this.uiState.localAttackHeld = false;
|
||||
}
|
||||
|
||||
isModifierKeyPressed(event: PointerEvent): boolean {
|
||||
|
||||
@@ -21,6 +21,7 @@ const DefaultKeybinds: Record<string, string> = {
|
||||
attackRatioUp: "KeyY",
|
||||
boatAttack: "KeyB",
|
||||
groundAttack: "KeyG",
|
||||
localAttack: "KeyL",
|
||||
zoomOut: "KeyQ",
|
||||
zoomIn: "KeyE",
|
||||
centerCamera: "KeyC",
|
||||
@@ -432,6 +433,16 @@ export class KeybindsModal extends BaseModal {
|
||||
@change=${this.handleKeybindChange}
|
||||
></setting-keybind>
|
||||
|
||||
<setting-keybind
|
||||
action="localAttack"
|
||||
label=${translateText("user_setting.local_attack")}
|
||||
description=${translateText("user_setting.local_attack_desc")}
|
||||
defaultKey="KeyL"
|
||||
.value=${this.getKeyValue("localAttack")}
|
||||
.display=${this.getKeyChar("localAttack")}
|
||||
@change=${this.handleKeybindChange}
|
||||
></setting-keybind>
|
||||
|
||||
<h2
|
||||
class="text-blue-200 text-xl font-bold mt-8 mb-3 border-b border-white/10 pb-2"
|
||||
>
|
||||
|
||||
@@ -56,6 +56,7 @@ export function createRenderer(
|
||||
attackRatio: 20,
|
||||
ghostStructure: null,
|
||||
rocketDirectionUp: true,
|
||||
localAttackHeld: false,
|
||||
} as UIState;
|
||||
|
||||
//hide when the game renders
|
||||
|
||||
@@ -4,4 +4,5 @@ export interface UIState {
|
||||
attackRatio: number;
|
||||
ghostStructure: UnitType | null;
|
||||
rocketDirectionUp: boolean;
|
||||
localAttackHeld: boolean;
|
||||
}
|
||||
|
||||
@@ -601,12 +601,15 @@ export const centerButtonElement: CenterButtonElement = {
|
||||
}
|
||||
} else {
|
||||
const targetId = params.selected?.id() ?? null;
|
||||
const sourceTile = await resolveAttackSourceTile(
|
||||
params.game,
|
||||
params.myPlayer,
|
||||
targetId,
|
||||
params.tile,
|
||||
);
|
||||
const useLocalAttack = params.uiState?.localAttackHeld ?? false;
|
||||
const sourceTile = useLocalAttack
|
||||
? await resolveAttackSourceTile(
|
||||
params.game,
|
||||
params.myPlayer,
|
||||
targetId,
|
||||
params.tile,
|
||||
)
|
||||
: null;
|
||||
params.playerActionHandler.handleAttack(
|
||||
params.myPlayer,
|
||||
targetId,
|
||||
|
||||
Reference in New Issue
Block a user