Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/OverlayCounterManager.js
Show All 9 Lines | class OverlayCounterManager | ||||
{ | { | ||||
this.dataCounter = dataCounter; | this.dataCounter = dataCounter; | ||||
this.counters = []; | this.counters = []; | ||||
this.enabledCounters = []; | this.enabledCounters = []; | ||||
this.lastTick = undefined; | this.lastTick = undefined; | ||||
this.resizeHandlers = []; | this.resizeHandlers = []; | ||||
this.lastHeight = undefined; | this.lastHeight = undefined; | ||||
this.initSize = this.dataCounter.size; | this.initSize = this.dataCounter.size; | ||||
this.hideOverlay = false; | |||||
for (let name of this.availableCounterNames()) | for (let name of this.availableCounterNames()) | ||||
{ | { | ||||
let counterType = OverlayCounterTypes.prototype[name]; | let counterType = OverlayCounterTypes.prototype[name]; | ||||
if (counterType.IsAvailable && !counterType.IsAvailable()) | if (counterType.IsAvailable && !counterType.IsAvailable()) | ||||
continue; | continue; | ||||
let counter = new counterType(this); | let counter = new counterType(this); | ||||
this.counters.push(counter); | this.counters.push(counter); | ||||
counter.updateEnabled(); | counter.updateEnabled(); | ||||
} | } | ||||
this.dataCounter.onTick = this.onTick.bind(this); | this.dataCounter.onTick = this.onTick.bind(this); | ||||
} | } | ||||
hide(hide) | |||||
Freagarach: (`hide`/`show`?) | |||||
ImarokAuthorUnsubmitted Done Inline Actions? Imarok: ? | |||||
FreagarachUnsubmitted Not Done Inline ActionsI like explicit functions. ;) Freagarach: I like explicit functions. ;) | |||||
ImarokAuthorUnsubmitted Done Inline ActionsAh, so you'd prefer hide() and show() instead of hide(hide)? Imarok: Ah, so you'd prefer `hide()` and `show()` instead of `hide(hide)`?
I prefer one function… | |||||
FreagarachUnsubmitted Not Done Inline ActionsI should have been clearer, sorry. Yes, so the function is clear in its meaning, there is no way to pass the wrong argument ("false" vs false) and one can easily ignore calling the function with non-changing circumstances (e.g. if hide(false) is called when the overlay is already hidden). That being said, that is merely a preference of mine, which I happen to post sometimes (hence the inline in brackets) and I'm not going to nag about it. (That is a property and not a function. ;) ) Freagarach: I should have been clearer, sorry.
Yes, so the function is clear in its meaning, there is no… | |||||
{ | |||||
this.hideOverlay = hide; | |||||
this.rebuildOverlay(); | |||||
} | |||||
/** | /** | ||||
* Mods may overwrite this to change the order of the counters shown. | * Mods may overwrite this to change the order of the counters shown. | ||||
*/ | */ | ||||
availableCounterNames() | availableCounterNames() | ||||
{ | { | ||||
return Object.keys(OverlayCounterTypes.prototype); | return Object.keys(OverlayCounterTypes.prototype); | ||||
} | } | ||||
Show All 33 Lines | class OverlayCounterManager | ||||
{ | { | ||||
// Don't rebuild the caption every frame | // Don't rebuild the caption every frame | ||||
let now = Date.now(); | let now = Date.now(); | ||||
if (now < this.lastTick + this.Delay) | if (now < this.lastTick + this.Delay) | ||||
return; | return; | ||||
this.lastTick = now; | this.lastTick = now; | ||||
this.rebuildOverlay(); | |||||
} | |||||
rebuildOverlay() | |||||
{ | |||||
if (this.hideOverlay) | |||||
{ | |||||
this.dataCounter.hidden = true; | |||||
return; | |||||
} | |||||
let lineCount = 0; | let lineCount = 0; | ||||
let txt = ""; | let txt = ""; | ||||
for (let counter of this.enabledCounters) | for (let counter of this.enabledCounters) | ||||
{ | { | ||||
let newTxt = counter.get(); | let newTxt = counter.get(); | ||||
if (!newTxt) | if (!newTxt) | ||||
continue; | continue; | ||||
Show All 39 Lines |
Wildfire Games · Phabricator
(hide/show?)