Browse Source

added oxygine-flow to CMakeLists.txt
use oxygine-flow for scenes

dmuratshin 9 years ago
parent
commit
54cf01e5ff

+ 4 - 1
my_awesome_game/project/proj.cmake/CMakeLists.txt

@@ -12,6 +12,9 @@ add_definitions(${OXYGINESOUND_DEFINITIONS})
 include_directories(${OXYGINESOUND_INCLUDE_DIRS})
 link_directories(${OXYGINESOUND_LIBRARY_DIRS})
 
+add_subdirectory(../../../oxygine-flow/ oxygine-flow)
+include_directories(${OXYGINE_FLOW_INCLUDE_DIRS})
+
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 set(SRC ../src)
@@ -50,4 +53,4 @@ if (WIN32) #disable console mode for VC++
 	set_target_properties(MyAwesomeGame PROPERTIES WIN32_EXECUTABLE TRUE)
 endif(WIN32)
 
-target_link_libraries(MyAwesomeGame ${OXYGINESOUND_LIBS} ${OXYGINE_CORE_LIBS})
+target_link_libraries(MyAwesomeGame ${OXYGINESOUND_LIBS} oxygine-flow ${OXYGINE_CORE_LIBS})

+ 5 - 12
my_awesome_game/project/src/GameMenu.cpp

@@ -7,6 +7,7 @@ spGameMenu GameMenu::instance;
 
 GameMenu::GameMenu()
 {
+	_dialog = true;
     //initialize dialog background
     _bg = initActor(new Box9Sprite,
                     arg_attachTo = _view,
@@ -72,11 +73,13 @@ GameMenu::GameMenu()
         button->setName(txt[i]);
         //handle click on button
         //each Object could have unique name. In this example button has the same name as text
-        button->addEventListener(TouchEvent::CLICK, CLOSURE(this, &GameMenu::onEvent));
+        button->addEventListener(TouchEvent::CLICK, getFinish());
     }
+
+	addEventListener(EVENT_PRE_SHOWING, CLOSURE(this, &GameMenu::preShowing));
 }
 
-void GameMenu::_show()
+void GameMenu::preShowing(Event*)
 {
     //before showing dialog hide buttons
     _buttons->setAlpha(0);
@@ -99,14 +102,4 @@ void GameMenu::showButtons(Event* ev)
     //tween activated from GameMenu::_show is done
     //fade in buttons and text
     _buttons->addTween(Actor::TweenAlpha(255), 300);
-}
-
-void GameMenu::onEvent(Event* ev)
-{
-    //button clicked
-    //remember it's name. It would asked later from GameScene.cpp
-    _lastClicked = ev->currentTarget->getName();
-
-    //hide dialog
-    hide();
 }

+ 1 - 4
my_awesome_game/project/src/GameMenu.h

@@ -8,14 +8,11 @@ public:
     static spGameMenu instance;
 
     GameMenu();
-    const string& getLastClicked() const {return _lastClicked;}
 
 private:
-    void onEvent(Event* ev);
     void showButtons(Event* ev);
-    void _show();
+	void preShowing(Event*);
 
     spBox9Sprite _bg;
     spActor _buttons;
-    string _lastClicked;
 };

+ 8 - 21
my_awesome_game/project/src/GameScene.cpp

@@ -31,9 +31,6 @@ GameScene::GameScene()
 
     //handle click to menu
     btn->addEventListener(TouchEvent::CLICK, CLOSURE(this, &GameScene::onEvent));
-
-    //subscribe to Hidden Event from GameMenu
-    GameMenu::instance->addEventListener(GameScene::HiddenEvent::EVENT, CLOSURE(this, &GameScene::onEvent));
 }
 
 void GameScene::onEvent(Event* ev)
@@ -45,25 +42,15 @@ void GameScene::onEvent(Event* ev)
         _game->getClock()->pause();
 
         //show GameMenu dialog
-        GameMenu::instance->show();
-    }
+		flow::show(GameMenu::instance, [=](Event* ev){
 
+			//"Continue" button was clicked
+			//dialog already hidden
+			//just resume Clock to continue game
+			_game->getClock()->resume();
 
-    if (ev->type == GameScene::HiddenEvent::EVENT)
-    {
-        //event from GameMenu called after GameMenu::instance->hide()
-        const string& name = GameMenu::instance->getLastClicked();
-        if (name == "Exit")
-        {
-            //if "Exit" button was clicked
-            changeScene(MainMenuScene::instance);
-        }
-        else
-        {
-            //"Continue" button was clicked
-            //dialog already hidden
-            //just resume Clock to continue game
-            _game->getClock()->resume();
-        }
+			if (ev->target->getName() == "Exit")
+				finish();
+		});
     }
 }

+ 1 - 1
my_awesome_game/project/src/MainMenuScene.cpp

@@ -76,6 +76,6 @@ void MainMenuScene::onEvent(Event* ev)
     {
         //clicked to play button
         //change scene
-        changeScene(GameScene::instance);
+        flow::show(GameScene::instance);
     }
 }

+ 3 - 0
my_awesome_game/project/src/MyButton.cpp

@@ -3,6 +3,9 @@
 
 MyButton::MyButton()
 {
+	setTouchChildrenEnabled(false);
+
+
     //pressed button should be RED
     addEventListener(TouchEvent::TOUCH_DOWN, CLOSURE(this, &MyButton::onEvent));
     addEventListener(TouchEvent::TOUCH_UP, CLOSURE(this, &MyButton::onEvent));

+ 1 - 39
my_awesome_game/project/src/Scene.cpp

@@ -4,43 +4,5 @@ Scene::Scene()
 {
     _view = new Actor;
     _view->setSize(getStage()->getSize());
-}
-
-void Scene::changeScene(spScene next)
-{
-    //hide current scene
-    hide();
-
-    //show next scene
-    next->show();
-}
-
-void Scene::show()
-{
-    //add scene view to root
-    getStage()->addChild(_view);
-    //and fade in
-    _view->setAlpha(0);
-    _view->addTween(Actor::TweenAlpha(255), 300);
-
-    //call virtual method (overloaded in inherited classes)
-    _show();
-}
-
-void Scene::hide()
-{
-    spTween tween = _view->addTween(Actor::TweenAlpha(0), 300);
-    //detach when done
-    tween->setDetachActor(true);
-    //and call Scene::hidden
-    tween->addDoneCallback(CLOSURE(this, &Scene::hidden));
-}
-
-void Scene::hidden(Event* ev)
-{
-    //hidden called by Tween
-    //notify HiddenEvent listeners
-
-    HiddenEvent he(this);
-    dispatchEvent(&he);
+	_holder->addChild(_view);
 }

+ 3 - 23
my_awesome_game/project/src/Scene.h

@@ -1,40 +1,20 @@
 #pragma once
 #include "oxygine-framework.h"
+#include "oxygine-flow.h"
+
 #include <vector>
 using namespace oxygine;
 using namespace std;
 
 DECLARE_SMART(Scene, spScene);
-class Scene: public EventDispatcher
+class Scene: public flow::Scene
 {
 public:
     Scene();
 
-    //declare own Event type
-    //it would be fired when scene would completely hidden
-    class HiddenEvent: public Event
-    {
-    public:
-        //define unique int ID with makefourcc 'SHid' = SceneHidden
-        enum {EVENT = makefourcc('S', 'H', 'i', 'd')};
-
-        HiddenEvent(Scene* scene_): Event(EVENT), scene(scene_) {};
-        Scene* scene;
-    };
-
-    void show();
-
-    //fires HiddenEvent when scene completed hidden
-    void hide();
-
-    void changeScene(spScene next);
     spActor getView() const {return _view;}
 
 protected:
-    virtual void _show() {}
-    virtual void _hide() {}
-
-    void hidden(Event* ev);
     spActor _view;
 };
 

+ 4 - 1
my_awesome_game/project/src/example.cpp

@@ -20,19 +20,21 @@ void example_init()
     //load resources
     res::load();
 
+	flow::init();
     //create all scenes
     GameMenu::instance = new GameMenu;
     GameScene::instance = new GameScene;
     MainMenuScene::instance = new MainMenuScene;
 
     //show main menu
-    MainMenuScene::instance->show();
+    flow::show(MainMenuScene::instance);
 }
 
 void example_update()
 {
     SoundSystem::get()->update();
     player.update();
+	flow::update();
 }
 
 void example_destroy()
@@ -44,4 +46,5 @@ void example_destroy()
     res::free();
 
     SoundSystem::free();
+	flow::free();
 }

+ 7 - 3
my_awesome_game/project/src/res.cpp

@@ -1,12 +1,13 @@
 #include "res.h"
 #include "oxygine-sound.h"
-
+#include <map>
 extern  SoundPlayer player;
 
 namespace res
 {
     Resources ui;
-    unordered_map<string, ResSound*> sounds;
+	typedef std::map<string, ResSound*> Sounds;
+	Sounds sounds;
 
     void load()
     {
@@ -19,7 +20,10 @@ namespace res
     {
         ui.free();
 
-        delete sounds["click"];
+		for (Sounds::iterator i = sounds.begin(); i != sounds.end(); ++i)
+		{
+			delete i->second;
+		}
     }
 }
 

+ 1 - 1
oxygine-flow

@@ -1 +1 @@
-Subproject commit 4c23c32e5cb7407fd3c22554c6404317584b74b9
+Subproject commit 74162593bb92f353fbe29f1fbfe4f04e61f75425

+ 1 - 1
oxygine-framework

@@ -1 +1 @@
-Subproject commit eb39fb30fe1fd8745e728281c70abc1ad2f49e53
+Subproject commit 2db25ddc566807a070f58d92d2e41fd8b88fa2b5

+ 1 - 1
oxygine-sound

@@ -1 +1 @@
-Subproject commit 3c400bf8333b15407166b42f00c2d8f6d0edfb69
+Subproject commit 0ebaa0c6a0c093449b1d4eaa6d8ffd8b5631449b