More sorting, changed keybind to U

This commit is contained in:
PeekabooSteam 2023-10-01 12:00:10 +01:00
parent 72c6e4e94e
commit 85b1404321
2 changed files with 31 additions and 5 deletions

View File

@ -68,7 +68,7 @@ export class UnitListPanel extends Panel {
"callback": () => {
this.toggle()
},
"code": "Quote"
"code": "KeyU"
});
this.startUpdates();
@ -86,14 +86,18 @@ export class UnitListPanel extends Panel {
this.#units = Object.values( this.#olympusApp.getUnitsManager().getUnits() );
if ( this.#currentSortAlgorithm === "unitName" ) {
this.#sortUnitsByUnitName();
if ( this.#currentSortAlgorithm === "coalition" ) {
this.#sortUnitsByCoalition();
}
if ( this.#currentSortAlgorithm === "name" ) {
this.#sortUnitsByName();
}
if ( this.#currentSortAlgorithm === "unitName" ) {
this.#sortUnitsByUnitName();
}
Object.values( this.#units ).forEach( ( unit:Unit ) => {
@ -142,6 +146,28 @@ export class UnitListPanel extends Panel {
}
#sortUnitsByCoalition() {
this.#units.sort( ( unit1:Unit, unit2:Unit ) => {
let str1 = unit1.getCoalition();
let str2 = unit2.getCoalition();
let cmp = this.#sortStringsCompare( str1, str2 );
if ( cmp !== 0 ) {
return cmp;
}
str1 = unit1.getUnitName().toLowerCase();
str2 = unit2.getUnitName().toLowerCase();
return this.#sortStringsCompare( str1, str2 );
});
}
#sortUnitsByName() {
this.#units.sort( ( unit1:Unit, unit2:Unit ) => {

View File

@ -1,10 +1,10 @@
<div id="unit-list-panel" class="ol-panel">
<div id="unit-list-panel" class="ol-panel hide">
<h3>Unit List</h3>
<div class="unit-list-unit headers">
<div data-sort-field="unitName">Name</div>
<div data-sort-field="name">Vehicle</div>
<div data-sort-field="coalition">Coalition</div>
<div data-sort-field="human">Human/AI</div>
<div>Human/AI</div>
</div>
<div id="unit-list-panel-content" class="ol-scrollable"></div>
</div>