From ed32238412c337505b4aecb62c79d6cd41c899ac Mon Sep 17 00:00:00 2001 From: tobspr Date: Sat, 19 Sep 2020 20:51:47 +0200 Subject: [PATCH] Allow toggling units in the statistics dialog --- res/ui/icons/toggle_unit.png | Bin 0 -> 2909 bytes src/css/ingame_hud/statistics.scss | 43 +++++++++++++++------ src/js/game/hud/parts/statistics.js | 19 ++++++++- src/js/game/hud/parts/statistics_handle.js | 23 ++++++++--- translations/base-en.yaml | 5 ++- 5 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 res/ui/icons/toggle_unit.png diff --git a/res/ui/icons/toggle_unit.png b/res/ui/icons/toggle_unit.png new file mode 100644 index 0000000000000000000000000000000000000000..e2126a975266b8cabfc510bdc5196131cac9a9ac GIT binary patch literal 2909 zcmbVO2~-nV7EM4vVuHAU0Rx1v2m@JxKmq|{012|h2r2?iLZt$MBo(u;sZ0PtG_=~{ zGVTa2U@PhYwN(btkp^i5#CBs^K@o5n1(y~&C{6{DW6yE6u5*6~QmEKY?$AnzImQlD^Ci9nd(Brz-1D7W{)45morEW*&G1_E9pVi8vOL{cIZ957W9mZJoh znMum@B0s?nni#u{p5m7F-0p^O@;{$7&%L*AX7;cgG&=Y5io^QXq3_kSQ{vw#fI}M@Ii=&Pw#Z~tDpcx_4A_myfP59Lipf@hWIm{Z zG)e#r$$-stGI*n4a+IJ@4Jl(FNc#Drc%Mzib2x^JVc^|XNaP|YQ|11}88BF=23Z6e zg+?J#7(^-~hDKp}`!apJJSa3Kh4Kj+35g`)?5{%om{iK|pm5fRglge`1&aWt7*fiF zu+I{iFa;zla^)(uP!53HU={(64@n{sF@3y+3^7RYAp#;XK%{wjCleWTiWdg%j<_F8@ zpU($FfX0vopU;c_&-2kr30#Fj=^y4X)TSYQm|+qXe6iV+)w2v-J-L!f@Dmxs6at1y zU=aXA3Vn&3EiQ(725yTu`(6%qp<6y~|uJBO~5-&dkMA-7WL;if2^MEz!!X!W*#* z*;ivct@F)YJo&Xe-?F*-_tAf`eN9un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AJKe0bIF&b>wS4qLuNxSpRF zZS&(Aj^upTVsYilst=COH+$92H?d`T*5~O?)vmT*T7Ji_*E;C}`=n)+RS7yw&_2NT zUBQ_CjYU}9PVJoVv8KS%itU@nLu{U4-B78~N!zP>0mUz;Q(IrHn|?G-v`>dFlGR4k z_{VN~V3DCsXu4TGdsMb_-BLw)vE4451>mE)dtJOJCM~IA?VG1pj~zc7>c63zsPp=1 z_-%XsuH)!l0~JiB3az5ZPAi?-(ZTW!S$kpriDdY9!I=`N4e$?A$B;{;D&)auAFjjScm z?QuP-Zbn8E^_m}M_#+m_UoiA-T5*;0xG6pSWyqNg%j*Y+9)@{=*&|K3q!#_m?M`nu UNgrA@7=D1cAyL8Aiv;=q1mVAQ@c;k- literal 0 HcmV?d00001 diff --git a/src/css/ingame_hud/statistics.scss b/src/css/ingame_hud/statistics.scss index 47809d5a..41ed4467 100644 --- a/src/css/ingame_hud/statistics.scss +++ b/src/css/ingame_hud/statistics.scss @@ -33,18 +33,39 @@ &.displayIcons, &.displayDetailed, + &.displaySorted, + &.displayIterateUnit { + background: transparent center center / #{D(15px)} no-repeat; + } + + &.displayDetailed { + background-image: uiResource("icons/display_list.png"); + } + + &.displayIcons { + background-image: uiResource("icons/display_icons.png"); + background-size: #{D(11.5px)}; + } + + &.displayDetailed { + @include S(border-top-left-radius, $globalBorderRadius); + @include S(border-bottom-left-radius, $globalBorderRadius); + } + &.displaySorted { - background: uiResource("icons/display_list.png") center center / #{D(15px)} no-repeat; - &.displayIcons { - background-image: uiResource("icons/display_icons.png"); - background-size: #{D(11.5px)}; - } - &.displaySorted { - background-image: uiResource("icons/display_sorted.png"); - background-size: #{D(11.5px)}; - margin-right: 4px; - @include S(padding, 1px, 0); - } + background-image: uiResource("icons/display_sorted.png"); + background-size: #{D(11.5px)}; + margin-right: 5px; + @include S(border-top-right-radius, $globalBorderRadius); + @include S(border-bottom-right-radius, $globalBorderRadius); + + @include S(padding, 1px, 0); + } + + &.displayIterateUnit { + background-image: uiResource("icons/toggle_unit.png"); + opacity: 0.8; + @include S(padding, 1px, 0); } background-color: #44484a !important; diff --git a/src/js/game/hud/parts/statistics.js b/src/js/game/hud/parts/statistics.js index c5136312..4e8cc9d1 100644 --- a/src/js/game/hud/parts/statistics.js +++ b/src/js/game/hud/parts/statistics.js @@ -4,7 +4,7 @@ import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper"; import { enumAnalyticsDataSource } from "../../production_analytics"; import { BaseHUDPart } from "../base_hud_part"; import { DynamicDomAttach } from "../dynamic_dom_attach"; -import { enumDisplayMode, HUDShapeStatisticsHandle } from "./statistics_handle"; +import { enumDisplayMode, HUDShapeStatisticsHandle, statisticsUnitsSeconds } from "./statistics_handle"; import { T } from "../../../translations"; /** @@ -47,10 +47,12 @@ export class HUDStatistics extends BaseHUDPart { this.trackClicks(button, () => this.setDataSource(dataSource)); } + const buttonIterateUnit = makeButton(this.filtersDisplayMode, ["displayIterateUnit"]); const buttonDisplaySorted = makeButton(this.filtersDisplayMode, ["displaySorted"]); const buttonDisplayDetailed = makeButton(this.filtersDisplayMode, ["displayDetailed"]); const buttonDisplayIcons = makeButton(this.filtersDisplayMode, ["displayIcons"]); + this.trackClicks(buttonIterateUnit, () => this.iterateUnit()); this.trackClicks(buttonDisplaySorted, () => this.toggleSorted()); this.trackClicks(buttonDisplayIcons, () => this.setDisplayMode(enumDisplayMode.icons)); this.trackClicks(buttonDisplayDetailed, () => this.setDisplayMode(enumDisplayMode.detailed)); @@ -97,6 +99,17 @@ export class HUDStatistics extends BaseHUDPart { this.setSorted(!this.sorted); } + /** + * Chooses the next unit + */ + iterateUnit() { + const units = Array.from(Object.keys(statisticsUnitsSeconds)); + const newIndex = (units.indexOf(this.currentUnit) + 1) % units.length; + this.currentUnit = units[newIndex]; + + this.rerenderPartial(); + } + initialize() { this.domAttach = new DynamicDomAttach(this.root, this.background, { attachClass: "visible", @@ -112,6 +125,8 @@ export class HUDStatistics extends BaseHUDPart { /** @type {Object.} */ this.activeHandles = {}; + this.currentUnit = "second"; + this.setSorted(true); this.setDataSource(enumAnalyticsDataSource.produced); this.setDisplayMode(enumDisplayMode.detailed); @@ -173,7 +188,7 @@ export class HUDStatistics extends BaseHUDPart { rerenderPartial() { for (const key in this.activeHandles) { const handle = this.activeHandles[key]; - handle.update(this.displayMode, this.dataSource); + handle.update(this.displayMode, this.dataSource, this.currentUnit); } } diff --git a/src/js/game/hud/parts/statistics_handle.js b/src/js/game/hud/parts/statistics_handle.js index 6f49f8d3..a64a5f5b 100644 --- a/src/js/game/hud/parts/statistics_handle.js +++ b/src/js/game/hud/parts/statistics_handle.js @@ -12,6 +12,16 @@ export const enumDisplayMode = { detailed: "detailed", }; +/** + * Stores how many seconds one unit is + * @type {Object} + */ +export const statisticsUnitsSeconds = { + second: 1, + minute: 60, + hour: 3600, +}; + /** * Simple wrapper for a shape definition within the shape statistics */ @@ -64,9 +74,10 @@ export class HUDShapeStatisticsHandle { * * @param {enumDisplayMode} displayMode * @param {enumAnalyticsDataSource} dataSource + * @param {string} unit * @param {boolean=} forced */ - update(displayMode, dataSource, forced = false) { + update(displayMode, dataSource, unit, forced = false) { if (!this.element) { return; } @@ -89,12 +100,12 @@ export class HUDShapeStatisticsHandle { case enumAnalyticsDataSource.delivered: case enumAnalyticsDataSource.produced: { let rate = - (this.root.productionAnalytics.getCurrentShapeRate(dataSource, this.definition) / - globalConfig.analyticsSliceDurationSeconds) * - 60; - this.counter.innerText = T.ingame.statistics.shapesPerSecond.replace( + this.root.productionAnalytics.getCurrentShapeRate(dataSource, this.definition) / + globalConfig.analyticsSliceDurationSeconds; + + this.counter.innerText = T.ingame.statistics.shapesDisplayUnits[unit].replace( "", - formatBigNumber(rate / 60) + formatBigNumber(rate * statisticsUnitsSeconds[unit]) ); break; } diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 3621ea2d..a32607bc 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -380,7 +380,10 @@ ingame: noShapesProduced: No shapes have been produced so far. # Displays the shapes per second, e.g. '523 / s' - shapesPerSecond: / s + shapesDisplayUnits: + second: / s + minute: / m + hour: / h # Settings menu, when you press "ESC" settingsMenu: