Browse Source

fixed exit

dmuratshin 10 years ago
parent
commit
eeb5b53d5f
1 changed files with 24 additions and 17 deletions
  1. 24 17
      src/flow/flow.cpp

+ 24 - 17
src/flow/flow.cpp

@@ -50,16 +50,6 @@ namespace oxygine
 
 
         void Flow::init()
         void Flow::init()
         {
         {
-            spScene first = new Scene;
-            first->setName("initial scene");
-            first->_holder->attachTo(getStage());
-            first->addEventListener(Scene::EVENT_SCENE_HIDDEN, [=](Event*)
-            {
-				if (scenes2show.empty())
-					core::requestQuit();
-            }
-                                   );
-            scenes.push_back(first);
         }
         }
 
 
         void Flow::free()
         void Flow::free()
@@ -73,6 +63,17 @@ namespace oxygine
 
 
         void Flow::show(spScene scene, const resultCallback& cb)
         void Flow::show(spScene scene, const resultCallback& cb)
         {
         {
+            if (scenes.empty())
+            {
+                scenes.push_back(scene);
+                scene->entering();
+                scene->preShowing();
+                scene->_holder->attachTo(getStage());
+                scene->postShowing();
+                scene->_resultCB = cb;
+                return;
+            }
+
             auto p = std::find(scenes.begin(), scenes.end(), scene);
             auto p = std::find(scenes.begin(), scenes.end(), scene);
             if (p != scenes.end())
             if (p != scenes.end())
                 log::error("you can't show scene '%s', it is already in the list", scene->getName().c_str());
                 log::error("you can't show scene '%s', it is already in the list", scene->getName().c_str());
@@ -141,7 +142,10 @@ namespace oxygine
             if (!_back || !current->_dialog)
             if (!_back || !current->_dialog)
                 next->postShowing();
                 next->postShowing();
 
 
-            
+            if (_back)
+                next->sceneHidden(current);
+
+
             getStage()->removeEventListener(TouchEvent::CLICK, CLOSURE(this, &Flow::blockedTouch));
             getStage()->removeEventListener(TouchEvent::CLICK, CLOSURE(this, &Flow::blockedTouch));
 
 
             if (current->_done)
             if (current->_done)
@@ -155,8 +159,6 @@ namespace oxygine
                 }
                 }
             }
             }
 
 
-			if (_back)
-				next->sceneHidden(current);
 
 
             if (current->_remove)
             if (current->_remove)
             {
             {
@@ -182,9 +184,11 @@ namespace oxygine
             if (current->_done)
             if (current->_done)
             {
             {
                 scenes.pop_back();
                 scenes.pop_back();
-                spScene prev = scenes.back();
-
-                phaseBegin(current, prev, true);
+                if (!scenes.empty())
+                {
+                    spScene prev = scenes.back();
+                    phaseBegin(current, prev, true);
+                }
             }
             }
         }
         }
 
 
@@ -218,7 +222,7 @@ namespace oxygine
             if (DebugActor::instance)
             if (DebugActor::instance)
             {
             {
                 std::string str;
                 std::string str;
-                for (size_t i = 1; i < scenes.size(); ++i)
+                for (size_t i = 0; i < scenes.size(); ++i)
                 {
                 {
                     str += scenes[i]->getName();
                     str += scenes[i]->getName();
                     str += "->";
                     str += "->";
@@ -264,6 +268,9 @@ namespace oxygine
                 current->dispatchEvent(&ev);
                 current->dispatchEvent(&ev);
                 checkDone();
                 checkDone();
             }
             }
+
+            if (scenes.empty())
+                core::requestQuit();
         }
         }
 
 
         void update()
         void update()