From 4bcef8e725f2a0d23180220e5ff3b896a3725f6a Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Mon, 24 Aug 2020 11:51:29 -0700 Subject: [PATCH] Add button to toggle sortedness of the statistics screen (#590) --- res/ui/icons/display_sorted.png | Bin 0 -> 430 bytes src/css/ingame_hud/statistics.scss | 9 ++++++++- src/js/game/hud/parts/statistics.js | 26 +++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 res/ui/icons/display_sorted.png diff --git a/res/ui/icons/display_sorted.png b/res/ui/icons/display_sorted.png new file mode 100644 index 0000000000000000000000000000000000000000..2e3c2badb1ace3c95cae38373ebf33fe2f91b325 GIT binary patch literal 430 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!TmyVUT!Hj|ib2ra;zK}##7ctv zf*JlMM*R>?|NP-%aA#}N)pHZP6aosT0cFU1g-~4{V`pqpSkE)Z68bptZ zF`rPKz^gFL!GuBPS_7NO0!H2+=?=5?geH?ZQoye@b<3+!;${*6>qp-F;?lxuUTdY3@-*xS3j3^P6 this.setDataSource(dataSource)); } + const buttonDisplaySorted = makeButton(this.filtersDisplayMode, ["displaySorted"]); const buttonDisplayDetailed = makeButton(this.filtersDisplayMode, ["displayDetailed"]); const buttonDisplayIcons = makeButton(this.filtersDisplayMode, ["displayIcons"]); + this.trackClicks(buttonDisplaySorted, () => this.toggleSorted()); this.trackClicks(buttonDisplayIcons, () => this.setDisplayMode(enumDisplayMode.icons)); this.trackClicks(buttonDisplayDetailed, () => this.setDisplayMode(enumDisplayMode.detailed)); @@ -80,6 +82,21 @@ export class HUDStatistics extends BaseHUDPart { } } + /** + * @param {boolean} sorted + */ + setSorted(sorted) { + this.sorted = sorted; + this.dialogInner.setAttribute("data-sorted", sorted); + if (this.visible) { + this.rerenderFull(); + } + } + + toggleSorted() { + this.setSorted(!this.sorted); + } + initialize() { this.domAttach = new DynamicDomAttach(this.root, this.background, { attachClass: "visible", @@ -95,6 +112,7 @@ export class HUDStatistics extends BaseHUDPart { /** @type {Object.} */ this.activeHandles = {}; + this.setSorted(true); this.setDataSource(enumAnalyticsDataSource.produced); this.setDisplayMode(enumDisplayMode.detailed); @@ -183,7 +201,13 @@ export class HUDStatistics extends BaseHUDPart { } } - entries.sort((a, b) => b[1] - a[1]); + entries.sort((a, b) => { + // Sort by shape key for some consistency + if (!this.sorted || b[1] == a[1]) { + return b[0].localeCompare(a[0]); + } + return b[1] - a[1]; + }); let rendered = new Set();