/***********************************************************
 * God Mode On, Und[0]ne Devs < http://undonedevs.tk >
 * 2013 Pepe Romero < wizardpepe@gmail.com >
 * < https://bitbucket.org/undone_devs/god-mode-on >
 ***********************************************************/

#include "PreloadState.h"
#include "MenuState.h"

template<> PreloadState* Ogre::Singleton<PreloadState>::msSingleton = 0;

void PreloadState::enter()
{
    _root = Ogre::Root::getSingletonPtr();

    _sceneMgr = _root->createSceneManager(Ogre::ST_INTERIOR, "SceneManager");
    _camera = _sceneMgr->createCamera("PjCamera");
    _viewport = _root->getAutoCreatedWindow()->addViewport(_camera);
    _viewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0));

    // Se carga todo el GUI
    _guiRenderer = &CEGUI::OgreRenderer::bootstrapSystem();

    // Carga de todos los recursos generales de niveles
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/menus.zip", "Zip", "Menus");
    Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Menus");

    // Crea los schemes del juego
    CEGUI::SchemeManager::getSingletonPtr()->create("TaharezLook.scheme");
    CEGUI::SchemeManager::getSingletonPtr()->create("GodModeOn.scheme");

    // Entra directamente al menu principal
    changeState(MenuState::getSingletonPtr());

    _exitGame = false;
}

void PreloadState::exit()
{
    _sceneMgr->clearScene();
    _root->getAutoCreatedWindow()->removeAllViewports();
}

void PreloadState::pause(){}
void PreloadState::resume(){}

bool PreloadState::frameStarted(const Ogre::FrameEvent& evt)
{
    return true;
}

bool PreloadState::frameEnded(const Ogre::FrameEvent& evt)
{
    if (_exitGame)
        return false;
    return true;
}

void PreloadState::keyPressed(const OIS::KeyEvent &e)
{
    switch(e.key){

    case OIS::KC_RETURN:
        changeState(MenuState::getSingletonPtr());
        break;
    default:
        break;

    }
}

void PreloadState::keyReleased(const OIS::KeyEvent &e){}
void PreloadState::mouseMoved(const OIS::MouseEvent &e){}
void PreloadState::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id){}
void PreloadState::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id){}

PreloadState* PreloadState::getSingletonPtr()
{
    return msSingleton;
}

PreloadState& PreloadState::getSingleton()
{
    assert(msSingleton);
    return *msSingleton;
}
