Allow cycling backwards, closes #790

This commit is contained in:
tobspr 2020-12-07 13:04:58 +01:00
parent f5032a02ce
commit ca1af5a505
2 changed files with 9 additions and 4 deletions

View File

@ -5,6 +5,7 @@ export const CHANGELOG = [
entries: [
"Added the ability to edit constant signals by left clicking them",
"You can now add markers in the wire layer (partially by daanbreur)",
"Allow to cycle backwards in the toolbar with SHIFT + Tab (idea by emeraldblock)",
],
},
{

View File

@ -1,6 +1,6 @@
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
import { makeDiv } from "../../../core/utils";
import { STOP_PROPAGATION } from "../../../core/signal";
import { makeDiv, safeModulo } from "../../../core/utils";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { MetaBuilding } from "../../meta_building";
import { GameRoot } from "../../root";
@ -161,8 +161,12 @@ export class HUDBaseToolbar extends BaseHUDPart {
let newBuildingFound = false;
let newIndex = this.lastSelectedIndex;
for (let i = 0; i < this.primaryBuildings.length; ++i, ++newIndex) {
newIndex %= this.primaryBuildings.length;
const direction = this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed
? -1
: 1;
for (let i = 0; i <= this.primaryBuildings.length; ++i) {
newIndex = safeModulo(newIndex + direction, this.primaryBuildings.length);
const metaBuilding = gMetaBuildingRegistry.findByClass(this.primaryBuildings[newIndex]);
const handle = this.buildingHandles[metaBuilding.id];
if (!handle.selected && handle.unlocked) {