tr3
  • Overview
  • Repository
  • Tickets
  • Downloads
  • Credits
  • Statistics
  • Projects

Repository

Fix pause menu after game over

Parent commits : 867e3ac9dc291821ff4fe268ab060d4b55c36020,
Children commits : 3e7729ea5f3fd63a46d5fd4419d9bf822483f35e,

By Laurent Defert on 2015-06-20 18:43:50
Fix pause menu after game over

Browse content
Difference with parent commit 867e3ac9dc291821ff4fe268ab060d4b55c36020
Files modified:
js/pause_menu.js
--- 
+++ 
@@ -41,13 +41,23 @@
     this.addEntry('');
     this.entries[2].interactive = false;
     this.entries[2].shadow.visible = false;
+    this.addEntry('Restart game', function() {
+        menu.popup.setText('Do you really\nwant to restart\n' +
+                           'restart the game?');
+        menu.popup.rearrange();
+        menu.popup.setCallbacks(function() {
+            stage.restart();
+        });
+        menu.popup.resize();
+        menu.popup.visible = true;
+    });
     this.addEntry('Reset statistics', function() {
         menu.popup.setText('Do you really\nwant to reset\n' +
                            'current statistics\nand restart the\ngame?');
         menu.popup.rearrange();
         menu.popup.setCallbacks(function() {
             stage.srs.reset();
-            window.location.reload();
+            stage.restart();
         });
         menu.popup.resize();
         menu.popup.visible = true;

js/stage.js
--- 
+++ 
@@ -56,6 +56,7 @@
 
     Screen.call(this, this.conf_file);
     this.current_screen = SCREENS.LOADING;
+    this.pause_prev_screen = null;
     this.grid = null;
     this.score = 0;
     this.playtime = 0;
@@ -89,11 +90,15 @@
     this.init_game();
 };
 
+Stage.prototype.restart = function() {
+    this.clearAll(this);
+    this.addChild(this.loading);
+    this.init_game();
+};
+
 Stage.prototype.click = function() {
     if (this.current_screen == SCREENS.GAME_OVER) {
-        this.clearAll(this);
-        this.addChild(this.loading);
-        this.init_game();
+        this.restart();
     }
 };
 
@@ -416,6 +421,10 @@
 };
 
 Stage.prototype.setPause = function(data) {
+    if (this.current_screen == SCREENS.PAUSE) {
+        return
+    }
+    this.pause_prev_screen = this.current_screen;
     this.current_screen = SCREENS.PAUSE;
     this.pause_start = now;
     this.pause_bg.visible = true;
@@ -426,7 +435,7 @@
 };
 
 Stage.prototype.unsetPause = function(data) {
-    this.current_screen = SCREENS.GAME;
+    this.current_screen = this.pause_prev_screen;
     this.start_time += now - this.pause_start;
     this.playtime -= now - this.pause_start;
     this.last_update = this.pause_start;

Generated with KisssPM