Skip to content

Commit

Permalink
Merge pull request FreezingMoon#2127 from jackwu999/master
Browse files Browse the repository at this point in the history
added modular hotkey configuration, fixes FreezingMoon#2070
  • Loading branch information
DreadKnight authored Dec 5, 2022
2 parents 9a7aba5 + 87133bc commit d26badd
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 137 deletions.
221 changes: 221 additions & 0 deletions src/ui/hotkeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
export class Hotkeys {
constructor(ui) {
this.ui = ui;
}

pressQ() {
this.ui.dashopen ? this.ui.closeDash() : this.ui.selectNextAbility();
}

pressS(event) {
if (event.shiftKey) {
this.ui.btnToggleScore.triggerClick();
} else if (event.metaKey || event.ctrlKey) {
this.ui.game.gamelog.get('save');
} else {
this.ui.dashopen ? this.ui.gridSelectDown() : this.ui.btnSkipTurn.triggerClick();
}
}

pressD(event) {
if (event.shiftKey) {
this.ui.btnToggleDash.triggerClick();
} else {
this.ui.dashopen ? this.ui.gridSelectRight() : this.ui.btnDelay.triggerClick();
}
}

pressW() {
this.ui.dashopen ? this.ui.gridSelectUp() : this.ui.abilitiesButtons[1].triggerClick();
}

pressE() {
!this.ui.dashopen && this.ui.abilitiesButtons[2].triggerClick();
}

pressP(event) {
if (event.metaKey && event.altKey) {
this.ui.game.signals.ui.dispatch('toggleMetaPowers');
}
}

pressR() {
this.ui.dashopen ? this.ui.closeDash() : this.ui.abilitiesButtons[3].triggerClick();
}

pressA(event) {
if (event.shiftKey) {
this.ui.btnAudio.triggerClick();
} else {
this.ui.dashopen && this.ui.gridSelectLeft();
}
}

pressF(event) {
if (event.shiftKey) {
this.ui.fullscreen.toggle();
} else {
this.ui.btnFlee.triggerClick();
}
}

pressX() {
this.ui.btnExit.triggerClick();
}

pressArrowUp() {
this.ui.dashopen ? this.ui.gridSelectUp() : this.ui.game.grid.selectHexUp();
}

pressArrowDown() {
this.ui.dashopen ? this.ui.gridSelectDown() : this.ui.game.grid.selectHexDown();
}

pressArrowLeft() {
this.ui.dashopen ? this.ui.gridSelectLeft() : this.ui.game.grid.selectHexLeft();
}

pressArrowRight() {
this.ui.dashopen ? this.ui.gridSelectRight() : this.ui.game.grid.selectHexRight();
}

pressEnter() {
this.ui.dashopen ? this.ui.materializeButton.triggerClick() : this.ui.chat.toggle();
}

pressEscape() {
const isAbilityActive =
this.ui.activeAbility && this.ui.$scoreboard.hasClass('hide') && !this.ui.chat.isOpen;

if (isAbilityActive) {
/* Check to see if dash view or chat are open first before
* canceling the active ability when using Esc hotkey
*/
this.ui.game.activeCreature.queryMove();
this.ui.selectAbility(-1);
}

this.ui.game.signals.ui.dispatch('closeInterfaceScreens');
}

pressShiftKeyDown() {
this.ui.game.grid.showGrid(true);
this.ui.game.grid.showCurrentCreatureMovementInOverlay(this.ui.game.activeCreature);
}

pressShiftKeyUp() {
this.ui.game.grid.showGrid(false);
this.ui.game.grid.cleanOverlay();
this.ui.game.grid.redoLastQuery();
}

pressSpace() {
!this.ui.dashopen && this.ui.game.grid.confirmHex();
}
}
export function getHotKeys(hk) {
const hotkeys = {
KeyS: {
onkeydown(event) {
hk.pressS(event);
},
},
KeyD: {
onkeydown(event) {
hk.pressD(event);
},
},
KeyQ: {
onkeydown() {
hk.pressQ();
},
},
KeyW: {
onkeydown() {
hk.pressW();
},
},
KeyE: {
onkeydown() {
hk.pressE();
},
},
KeyP: {
onkeydown(event) {
hk.pressP(event);
},
},
KeyR: {
onkeydown() {
hk.pressR();
},
},
KeyA: {
onkeydown(event) {
hk.pressA(event);
},
},
KeyF: {
onkeydown(event) {
hk.pressF(event);
},
},
KeyX: {
onkeydown() {
hk.pressX();
},
},
ArrowUp: {
onkeydown() {
hk.pressArrowUp();
},
},
ArrowDown: {
onkeydown() {
hk.pressArrowDown();
},
},
ArrowLeft: {
onkeydown() {
hk.pressArrowLeft();
},
},
ArrowRight: {
onkeydown() {
hk.pressArrowRight();
},
},
Enter: {
onkeydown() {
hk.pressEnter();
},
},
Escape: {
onkeydown() {
hk.pressEscape();
},
},
ShiftLeft: {
onkeydown() {
hk.pressShiftKeyDown();
},
onkeyup() {
hk.pressShiftKeyUp();
},
},
ShiftRight: {
onkeydown() {
hk.pressShiftKeyDown();
},
onkeyup() {
hk.pressShiftKeyUp();
},
},
Space: {
onkeydown() {
hk.pressSpace();
},
},
};
return hotkeys;
}
140 changes: 3 additions & 137 deletions src/ui/interface.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as $j from 'jquery';
import * as time from '../utility/time';
import * as emoji from 'node-emoji';
import { Hotkeys, getHotKeys } from './hotkeys';

import { Button, ButtonStateEnum } from './button';
import { Chat } from './chat';
Expand Down Expand Up @@ -382,143 +383,8 @@ export class UI {
game.soundsys.setEffectsVolume(this.value);
}

const ingameHotkeys = {
KeyS: {
onkeydown(event) {
if (event.shiftKey) {
this.btnToggleScore.triggerClick();
} else if (event.metaKey || event.ctrlKey) {
this.game.gamelog.get('save');
} else {
this.dashopen ? this.gridSelectDown() : this.btnSkipTurn.triggerClick();
}
},
},
KeyD: {
onkeydown(event) {
if (event.shiftKey) {
this.btnToggleDash.triggerClick();
} else {
this.dashopen ? this.gridSelectRight() : this.btnDelay.triggerClick();
}
},
},
KeyQ: {
onkeydown() {
this.dashopen ? this.closeDash() : this.selectNextAbility();
},
},
KeyW: {
onkeydown() {
this.dashopen ? this.gridSelectUp() : this.abilitiesButtons[1].triggerClick();
},
},
KeyE: {
onkeydown() {
!this.dashopen && this.abilitiesButtons[2].triggerClick();
},
},
KeyP: {
onkeydown() {
if (event.metaKey && event.altKey) {
this.game.signals.ui.dispatch('toggleMetaPowers');
}
},
},
KeyR: {
onkeydown() {
this.dashopen ? this.closeDash() : this.abilitiesButtons[3].triggerClick();
},
},
KeyA: {
onkeydown(event) {
if (event.shiftKey) {
this.btnAudio.triggerClick();
} else {
this.dashopen && this.gridSelectLeft();
}
},
},
KeyF: {
onkeydown(event) {
if (event.shiftKey) {
this.fullscreen.toggle();
} else {
this.btnFlee.triggerClick();
}
},
},
KeyX: {
onkeydown() {
this.btnExit.triggerClick();
},
},
ArrowUp: {
onkeydown() {
this.dashopen ? this.gridSelectUp() : game.grid.selectHexUp();
},
},
ArrowDown: {
onkeydown() {
this.dashopen ? this.gridSelectDown() : game.grid.selectHexDown();
},
},
ArrowLeft: {
onkeydown() {
this.dashopen ? this.gridSelectLeft() : game.grid.selectHexLeft();
},
},
ArrowRight: {
onkeydown() {
this.dashopen ? this.gridSelectRight() : game.grid.selectHexRight();
},
},
Enter: {
onkeydown() {
this.dashopen ? this.materializeButton.triggerClick() : this.chat.toggle();
},
},
Escape: {
onkeydown() {
const isAbilityActive =
this.activeAbility && this.$scoreboard.hasClass('hide') && !this.chat.isOpen;

if (isAbilityActive) {
/* Check to see if dash view or chat are open first before
* canceling the active ability when using Esc hotkey
*/
game.activeCreature.queryMove();
this.selectAbility(-1);
}

this.game.signals.ui.dispatch('closeInterfaceScreens');
},
},
ShiftLeft: {
onkeydown() {
game.grid.showGrid(true);
game.grid.showCurrentCreatureMovementInOverlay(game.activeCreature);
},
onkeyup() {
game.grid.showGrid(false);
game.grid.cleanOverlay();
game.grid.redoLastQuery();
},
},
ShiftRight: {
onkeydown() {
ingameHotkeys.ShiftLeft.onkeydown();
},
onkeyup() {
ingameHotkeys.ShiftLeft.onkeyup();
},
},
Space: {
onkeydown() {
!this.dashopen && game.grid.confirmHex();
},
},
};
this.hotkeys = new Hotkeys(this);
const ingameHotkeys = getHotKeys(this.hotkeys);

// Remove hex grid if window loses focus
$j(window).on('blur', () => {
Expand Down

0 comments on commit d26badd

Please sign in to comment.