#include "Scene_MainUi.h"
#include "Asset/Squirrel/SquirrelManager.h"

void Scene_MainUi::Enter()
{
    Scene::Enter();

    HSQUIRRELVM v = SquirrelEx::GetInstance().GetSquirrelVM();
    SQInteger top = sq_gettop(v);
    sq_pushroottable(v);
    sq_pushstring(v, _SC("_MainUI_Enter_"), -1);
    if (SQ_SUCCEEDED(sq_get(v, -2)))
    {
        sq_pushroottable(v);
        sq_pushuserpointer(v, this);
        sq_call(v, 2, SQFalse, SQTrue);
    }
    sq_settop(v, top);

}

void Scene_MainUi::HandleEvents(SDL_Event *e)
{
    Scene::HandleEvents(e);
    HSQUIRRELVM v = SquirrelEx::GetInstance().GetSquirrelVM();
    SQInteger top = sq_gettop(v);
    sq_pushroottable(v);
    sq_pushstring(v, _SC("_MainUI_HandleEvents_"), -1);
    if (SQ_SUCCEEDED(sq_get(v, -2)))
    {
        sq_pushroottable(v);
        sq_pushinteger(v, 1);
        sq_call(v, 2, SQFalse, SQTrue);
    }
    sq_settop(v, top);
}

void Scene_MainUi::Update(float deltaTime)
{
    Scene::Update(deltaTime);
    HSQUIRRELVM v = SquirrelEx::GetInstance().GetSquirrelVM();
    SQInteger top = sq_gettop(v);
    sq_pushroottable(v);
    sq_pushstring(v, _SC("_MainUI_Update_"), -1);
    if (SQ_SUCCEEDED(sq_get(v, -2)))
    {
        sq_pushroottable(v);
        sq_pushfloat(v, deltaTime);
        sq_call(v, 2, SQFalse, SQTrue);
    }
    sq_settop(v, top);
}

void Scene_MainUi::Exit()
{
    Scene::Exit();
    HSQUIRRELVM v = SquirrelEx::GetInstance().GetSquirrelVM();
    SQInteger top = sq_gettop(v);
    sq_pushroottable(v);
    sq_pushstring(v, _SC("_MainUI_Exit_"), -1);
    if (SQ_SUCCEEDED(sq_get(v, -2)))
    {
        sq_pushroottable(v);
        sq_call(v, 1, SQFalse, SQTrue);
    }
    sq_settop(v, top);
}

void Scene_MainUi::Render()
{
    Scene::Render();
}
