From 5c7e12c6d0583a50b58ec5681aa99e17b4a875c6 Mon Sep 17 00:00:00 2001 From: OleSTEEP Date: Sat, 17 Feb 2024 16:13:31 +0300 Subject: [PATCH] PIXI Controls: Stop idle timer when controls hidden --- www.rus/js/plugins/VND_ONSControls.js | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/www.rus/js/plugins/VND_ONSControls.js b/www.rus/js/plugins/VND_ONSControls.js index 39c6315..82bd3cc 100644 --- a/www.rus/js/plugins/VND_ONSControls.js +++ b/www.rus/js/plugins/VND_ONSControls.js @@ -157,11 +157,12 @@ ONSControls.idleAnimation = function() { // * Check idle animation (spinning buttons) //============================================================================= ONSControls.isIdlePlaying = false; +ONSControls.idleDisabled = false; //============================================================================= // * Play idle animation (spinning buttons) //============================================================================= ONSControls.playIdleAnimation = function() { - if (!ONSControls.isIdlePlaying) { + if (!ONSControls.isIdlePlaying && !ONSControls.idleDisabled) { ONSControls.isIdlePlaying = true; ONSControls._controlsCanvas.ticker.add(ONSControls.idleAnimation); } @@ -178,6 +179,18 @@ ONSControls.stopIdleAnimation = function() { ONSControls._showButton.rotation = 0; } //============================================================================= +// * Reset idle animation timer +//============================================================================= +ONSControls.resetIdleAnimation = function() { + if (ONSControls._idleInterval !== undefined) { + ONSControls.stopIdleAnimation(); + clearInterval(ONSControls._idleInterval); + if (!ONSControls.idleDisabled) { + ONSControls._idleInterval = setInterval(ONSControls.playIdleAnimation, 300000); + } + } +} +//============================================================================= // * Send event to virtual controller //============================================================================= ONSControls.sendEvent = function(event, button) { @@ -198,8 +211,10 @@ ONSControls.toggle = function(neededState = null) { for (elem of elements) { if (elem.visible || neededState === false) { elem.visible = false; + ONSControls.idleDisabled = true; } else { elem.visible = true; + ONSControls.idleDisabled = false; } } } @@ -282,11 +297,7 @@ ONSControls.setupInteractive = function () { // Canvas this._idleInterval = setInterval(ONSControls.playIdleAnimation, 300000); - this._controlsCanvas.stage.on("pointerdown", () => { - this.stopIdleAnimation(); - clearInterval(ONSControls._idleInterval); - ONSControls._idleInterval = setInterval(ONSControls.playIdleAnimation, 300000); - }); + this._controlsCanvas.stage.on("pointerdown", ONSControls.resetIdleAnimation); // A/B/X/Y const buttons = this._buttonsContainer.children; @@ -329,6 +340,9 @@ ONSControls.setupInteractive = function () { // Show button this._showButton.on("pointerdown", this.toggle); } +//============================================================================= +// * Get all buttons +//============================================================================= ONSControls.getControlElements = function() { return [ this._dPadContainer, this._LBsprite, @@ -406,6 +420,7 @@ ONSControls.replaceBackEvent = function() { ONSControls.openEditMode = function() { if (Graphics._canvas.hidden === false) { Graphics._canvas.hidden = true; + this.idleDisabled = true; this.clearInteractive(); this._buttonsContainer.interactive = true; for (elem of this.getControlElements()) { @@ -422,6 +437,7 @@ ONSControls.openEditMode = function() { ONSControls.closeEditMode = function() { this._editModeText.visible = false; Graphics._canvas.hidden = false; + this.idleDisabled = false; this.clearInteractive(); this.setupInteractive(); ConfigManager.ONSConfig.saveButtonsPosition();