#include "scripts/common.txt"
#include "scripts/BPR/BPR_Shared.cpp"

//TODO: Later On
// Randomize Chrono Pieces anywhere
// Randomize Bosses in the Arenas you enter. (Need to alter boss map scripts)
// Randomize Speed option (default off) change friction

//TODO: Much Later On
// Randomize Key Locations
// Randomize Number of Enemies (Get enemy spawning in)

kVec3 destOrigin1;
kVec3 destOrigin2;
kVec3 destOrigin3;
kVec3 destOrigin4;

kVec3 startOrigin1;
kVec3 startOrigin2;
kVec3 startOrigin3;
kVec3 startOrigin4;

float lerpTime = 0;
float explodeBob = 15.0f;

kActor @arrow = null;

//------------------------------------------------------------------------------------------------------------------------
$script 0
{
    for(int i = TW_WEAPON_BOW; i < NUMTUROKWEAPONS; i++)
    {
        if(Player.HasWeapon(i))
        {
            Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_NO_LETTERBOX|CMF_NO_INITIAL_FADEOUT);
            Game.Restart();
            return;
        }
    }
    
    bool bStartedIntro;
    kStr szShowIntros;
    
    GameVariables.GetBool("bStartedIntro", bStartedIntro);
    
    if(Sys.GetCvarValue("g_showgameintros", szShowIntros))
    {
        if(szShowIntros.Atoi() == 0)
        {
            bStartedIntro = true;
        }
    }
    
    Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_NO_LETTERBOX|CMF_NO_INITIAL_FADEOUT);
    Camera.fov = 74.0f;
    
    @arrow = World.GetActorByTID(5);
    
    arrow.AnimState().Set(anim_weaponFire, 4.0f, ANF_LOOP);
    arrow.Yaw() = Math::pi;
    
    // camera vectors
    startOrigin1.Set(0.0f, -1986.5601f, 51.2f);
    destOrigin1.Set(0.0f, -92.16f, 51.2f);
    
    // camera look at vectors
    startOrigin2.Set(0.0f, 153.6f, 51.2f);
    destOrigin2.Set(0.0f, 153.6f, 51.2f);
    
    // arrow vectors
    startOrigin3.Set(0.0f, -1955.84f, 40.96f);
    destOrigin3.Set(0.0f, -61.44f, 40.96f);
    
    // arrow dest vectors
    startOrigin4.Set(0.0f, -1955.84f, 40.96f);
    destOrigin4.Set(22.6304f, 16.9984f, 82.432f);
    
    if(bStartedIntro)
    {
        Camera.origin = destOrigin1;
        arrow.Origin() = destOrigin4;
        Camera.fov = 47.5f;
        BPR::StartSeedScreen(instigator);
        return;
    }
    
    Game.CallDelayedMapScript(1, instigator, 0);
    GameVariables.SetValue("bStartedIntro", "1");
    
    delay(2.0f);
    BPR::StartSeedScreen(instigator);
}
//------------------------------------------------------------------------------------------------------------------------
// Tick Camera follow Arrow
//------------------------------------------------------------------------------------------------------------------------
$script 1
{
    kVec3 dir;
    float t = lerpTime * (4.0f * GAME_DELTA_TIME);
    float t2 = Math::CosArc(t) * 153.6f;
    
    lerpTime += GAME_FRAME_TIME;
    
    if(!BPR::g_bSeedScreenStarted)
    {
        Camera.origin = startOrigin1;
        Camera.origin.Lerp(destOrigin1, t);
        Camera.origin.z += t2;
    }    
    
    arrow.Origin() = startOrigin3;
    arrow.Origin().Lerp(destOrigin3, t);
    arrow.Origin().z += t2;
    
    kVec3 vec1 = startOrigin2;
    kVec3 vec2 = startOrigin4;
    
    vec1.Lerp(destOrigin2, t);
    vec2.Lerp(destOrigin4, t);
    vec1.z += t2;
    vec2.z += t2;
    
    dir = vec1 - Camera.origin;
    
    if(!BPR::g_bSeedScreenStarted)
    {
        Camera.yaw = dir.ToYaw();
        Camera.pitch = -dir.ToPitch();
    }
    
    arrow.Origin().Lerp(vec2, Math::Pow(t, 8.0f));
    arrow.Roll() += Math::Deg2Rad(4.0f);
    
    if(!BPR::g_bSeedScreenStarted)
    {
        Camera.fov = (47.5f - 74.0f) * t + 74.0f;
    }
    
    if(t >= 1.0f)
    {
        lerpTime = 0;
        Game.CallDelayedMapScript(2, instigator, 0);
        
        Game.SpawnFx("fx/generic_39.kfx", kVec3(22.63f, 73.318f, 82.432f), 0);
        Game.PlaySound("sounds/shaders/generic_143.ksnd");
        return;
    }
    
    $restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Tick Arrow Explosion
//------------------------------------------------------------------------------------------------------------------------
$script 2
{
    float t = lerpTime * (4.0f * GAME_DELTA_TIME);
    lerpTime += GAME_FRAME_TIME;
    
    if(!BPR::g_bSeedScreenStarted)
    {
        Camera.origin.z = 51.2f + (Math::Sin(t * (Math::pi * 8.0f)) * explodeBob);
    }
    explodeBob = (0.0f - explodeBob) * (4.0f * GAME_DELTA_TIME) + explodeBob;
    
    if(explodeBob <= 0.05f)
    {
        return;
    }
    
    $restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Tick Seed Menu
//------------------------------------------------------------------------------------------------------------------------
$script 3
{
    BPR::TickSeedScreen();
    $restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Tick during Main Menu
//------------------------------------------------------------------------------------------------------------------------
$script 4
{
    BPR::TickMainMenu();
    $restart;
}
//------------------------------------------------------------------------------------------------------------------------
namespace BPR
{
    const int MIN_SEED_VALUE = 0;
    const int MAX_SEED_VALUE = 99999;
    const float UICAM_DIST = 10.0f;
    const float UIMENU_WIDTH = 24.0f;
    const float UIMENU_HEIGHT = 13.5f;
    const float UIMENU_HALFWIDTH = UIMENU_WIDTH * 0.5f;
    const float UIMENU_HALFHEIGHT = UIMENU_HEIGHT * 0.5f;
    const float UICHAR_WIDTH = 0.4f;
    const float UICHAR_HEIGHT = 0.5f;
    const float UICHAR_SPACING = 0.4f;

    enum TextAlignments
    {
        ALIGN_LEFT = 0,
        ALIGN_CENTER,
        ALIGN_RIGHT
    }
    
    funcdef void FUNCDEF_UISELECT();
    
    kActor@ g_pCursor;
    array<kActor@> g_npUIActors;
    array<kActor@> g_npSeedTextActors;
    array<CL_BPR_UISelection@> g_npSelections;
    CL_BPR_UISelection@ g_pCurSelection = null;
    kVec3 g_vUIPos;
    float g_fCursorX = 0.0f;
    float g_fCursorY = -4.5f;
    int16 g_iLastButtons;
    int16 g_iButtons;
    bool g_bSeedScreenStarted;
    
    //------------------------------------------------------------------------------------------------------------------------
    class CL_BPR_UISelection
    {
        FUNCDEF_UISELECT@ m_pFunc;
        CL_BPR_Rect@ m_pRect;
        kActor@ m_pActor;
        int m_iState;
        //------------------------------------------------------------------------------------------------------------------------
        CL_BPR_UISelection(FUNCDEF_UISELECT@ pFunc, const float fMinX, const float fMinY, const float fMaxX, const float fMaxY, kActor@ pActor)
        {
            @m_pFunc = pFunc;
            @m_pRect = CL_BPR_Rect(fMinX, fMinY, fMaxX, fMaxY);
            @m_pActor = pActor;
            m_iState = 0;
        }
        //------------------------------------------------------------------------------------------------------------------------
        bool IsPointInRect(const float x, const float y)
        {
            return m_pRect.IsPointInRect(x, y);
        }
        //------------------------------------------------------------------------------------------------------------------------
    }
    //------------------------------------------------------------------------------------------------------------------------
    CL_BPR_UISelection@ AddSelection(FUNCDEF_UISELECT@ pFunc, const float fMinX, const float fMinY, const float fMaxX, const float fMaxY, kActor@ pActor = null)
    {
        g_npSelections.insertLast(CL_BPR_UISelection(pFunc, fMinX, fMinY, fMaxX, fMaxY, pActor));
        return g_npSelections[g_npSelections.length() - 1];
    }
    //------------------------------------------------------------------------------------------------------------------------
    CL_BPR_UISelection@ AddSelectionCheckBox(const kStr &in sGameVar, FUNCDEF_UISELECT@ pFunc, const float fMinX,
                                const float fMinY, const float fMaxX, const float fMaxY, const float x,
                                const float z, const float sx, const float sz, const float depth)
    {
        int iState = BPR::GameVar::GetInt(sGameVar);
        kActor@ pChkBox1 = SpawnUIActor(iState == 0 ? "models/ui/checkboxoff.bin" : "models/ui/checkboxon.bin", x, z, sx, sz, depth);
        CL_BPR_UISelection@ pSelection = AddSelection(pFunc, fMinX, fMinY, fMaxX, fMaxY, pChkBox1);
        pSelection.m_iState = iState;
        
        return pSelection;
    }
    //------------------------------------------------------------------------------------------------------------------------
    void StartSeedScreen(kActor@ instigator)
    {
        g_bSeedScreenStarted = true;
        g_vUIPos = kVec3(0.0f, 1000.0f, 0.0f);
        // g_vUIPos.Set(0.0f, -22.16f, 51.2f);
        
        SpawnCursor();
        InitWindowSeed();

        Player.Unlock();
        Player.Actor().Yaw() = 0.0f;
        Player.Actor().Pitch() = 0.0f;
        Player.Actor().SetPosition(kVec3(0.0f, 0.0f, 0.0f));
        
        Game.CallDelayedMapScript(3, instigator, 0);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void TickSeedScreen()
    {
        Player.Actor().PlayerFlags() |= PF_HASJUMPED;
        
        if(g_pCursor !is null)
        {
            kVec3 vPlayerPos = Player.Actor().Origin();
            float fPlayerYaw = Player.Actor().Yaw();
            float fPlayerPitch = Player.Actor().Pitch();
         
            //Get Cursor Sensitivity
            float cursorSenX = 5.0f;
            float cursorSenY = 5.0f;
            kStr sSenX;
            kStr sSenY;
            bool cVarSensXExists = Sys.GetCvarValue("cl_msensitivityx", sSenX);
            if(cVarSensXExists)
            {
                cursorSenX = sSenX.Atof() * 0.65f;
            }
            bool cVarSensYExists = Sys.GetCvarValue("cl_msensitivityy", sSenY);
            if(cVarSensYExists)
            {
                cursorSenY = sSenY.Atof() * 0.65f;
            }

            //Get Cursor Delta Movement
            float fDeltaX = 0.0f;
            float fDeltaY = 0.0f;
            if(fPlayerYaw != 0.0f || fPlayerPitch != 0.0f)
            {
                fDeltaX = fPlayerYaw * cursorSenX;
                fDeltaY = fPlayerPitch * cursorSenY;
            }
            else if(Player.Actor().Movement().x != 0.0f || Player.Actor().Movement().y != 0.0f)
            {
                fDeltaX = Player.Actor().Movement().x / (GAME_SCALE * 2.0f);
                fDeltaY = -Player.Actor().Movement().y / (GAME_SCALE * 1.25f);
            }
            
            g_fCursorX += fDeltaX;
            g_fCursorY -= fDeltaY;
            g_fCursorX = BPR::Math::Clampf(g_fCursorX, -UIMENU_HALFWIDTH, UIMENU_HALFWIDTH);
            g_fCursorY = BPR::Math::Clampf(g_fCursorY, -UIMENU_HALFHEIGHT, UIMENU_HALFHEIGHT);
            
            // Game.PrintLine("" + g_fCursorX + " " + g_fCursorY, 0, 120);
            // for(int i = 1; i < 7; i++)
            // {
                // Game.PrintLine("", i);
            // }
            SetUIActorPos(g_pCursor, g_fCursorX, g_fCursorY);        
        }
        
        if(Camera.Active())
        {
            Player.Actor().Yaw() = 0.0f;
            Player.Actor().Pitch() = 0.0f;
            Player.Actor().SetPosition(kVec3(0.0f, 0.0f, 0.0f));
            
            Camera.fov = 74.0f;
            Camera.origin = g_vUIPos;
            Camera.origin.y -= UICAM_DIST;
            Camera.yaw = 0.0f;
            Camera.pitch = 0.0f;
        }
        
        // Check if selected an item
        g_iLastButtons = g_iButtons;
        g_iButtons = Player.Buttons();
        if((g_iLastButtons & (BC_ATTACK|BC_JUMP)) == 0 && (g_iButtons & (BC_ATTACK|BC_JUMP)) != 0)
        {
            for(uint i = 0; i < g_npSelections.length(); i++)
            {
                if(g_npSelections[i].IsPointInRect(g_fCursorX, g_fCursorY))
                {
                    @g_pCurSelection = g_npSelections[i];
                    g_npSelections[i].m_pFunc();
                    break;
                }
            }
        }
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnKP0() { KeypadNumberEntered(0); }
    void OnBtnKP1() { KeypadNumberEntered(1); }
    void OnBtnKP2() { KeypadNumberEntered(2); }
    void OnBtnKP3() { KeypadNumberEntered(3); }
    void OnBtnKP4() { KeypadNumberEntered(4); }
    void OnBtnKP5() { KeypadNumberEntered(5); }
    void OnBtnKP6() { KeypadNumberEntered(6); }
    void OnBtnKP7() { KeypadNumberEntered(7); }
    void OnBtnKP8() { KeypadNumberEntered(8); }
    void OnBtnKP9() { KeypadNumberEntered(9); }
    //------------------------------------------------------------------------------------------------------------------------
    void KeypadNumberEntered(const int iNum)
    {
        int iSeed = BPR::GameVar::GetInt(GV_KEY_START_SEED);
        iSeed = BPR::Math::Clamp(iSeed, MIN_SEED_VALUE, MAX_SEED_VALUE);
        int inputIndex = 0;
        if(iSeed != 0)
        {
            array<int> niDigits = BPR::Math::Digits(iSeed);
            inputIndex = int(niDigits.length());
        }
        
        if((iSeed == 0 && iNum == 0) || (inputIndex > 4))
        {
            Game.PlaySound("sounds/shaders/menu_item_disabled.ksnd");
            return;
        }
        Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");

        kStr sSeed;
        if(inputIndex > 0)
        {
            sSeed += "" + iSeed;
        }
        sSeed += "" + iNum;
        
        SetStartSeed(sSeed.Atoi());
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnKeypadBack()
    {
        int iSeed = BPR::GameVar::GetInt(GV_KEY_START_SEED);
        iSeed = BPR::Math::Clamp(iSeed, MIN_SEED_VALUE, MAX_SEED_VALUE);
        if(iSeed == 0)
        {
            Game.PlaySound("sounds/shaders/menu_item_disabled.ksnd");
            return;
        }
        
        Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
        if(iSeed < 9)
        {
            SetStartSeed(0);
            return;
        }
        
        array<int> niDigits = BPR::Math::Digits(iSeed);
        kStr sSeed;
        for(uint i = 0; i < niDigits.length()-1; i++)
        {
            sSeed += ("" + niDigits[i]);
        }
        SetStartSeed(sSeed.Atoi());
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnReset()
    {
        int iSeed = BPR::GameVar::GetInt(GV_KEY_START_SEED);
        if(iSeed == 0)
        {
            Game.PlaySound("sounds/shaders/menu_item_disabled.ksnd");
            return;
        }
        Game.PlaySound("sounds/shaders/generic_126_spell_cast_2.ksnd");
        SetStartSeed(0);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnRandom()
    {
        Game.PlaySound("sounds/shaders/generic_3_energy_pickup.ksnd");
        int iSeed = 0;
        int iRandCount = int(Math::Ceil(float(MAX_SEED_VALUE) / 32767.0f));
        iRandCount = Math::RandMax(iRandCount) + 1;
        for(int i = 0; i < iRandCount; i++)
        {
            iSeed += Math::Rand();
        }
        SetStartSeed(iSeed);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnIncreaseSeed()
    {
        Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
        int iSeed = BPR::GameVar::GetInt(GV_KEY_START_SEED);
        iSeed = BPR::Math::Clamp(iSeed + 1, MIN_SEED_VALUE, MAX_SEED_VALUE);
        SetStartSeed(iSeed);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnDecreaseSeed()
    {
        Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
        int iSeed = BPR::GameVar::GetInt(GV_KEY_START_SEED);
        iSeed = BPR::Math::Clamp(iSeed - 1, MIN_SEED_VALUE, MAX_SEED_VALUE);
        SetStartSeed(iSeed);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnOptions()
    {
        Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
        InitWindowOptionsPage1();
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnConfirm()
    {
        Game.HaltMapScript(3);
        RemoveWindowActors();
        
        Game.PlaySound("sounds/shaders/explosion_1.ksnd");
        Camera.origin = destOrigin1;
        Camera.fov = 47.5f;
        Player.Lock();
        Game.ShowMainMenu();
        
        Game.CallDelayedMapScript(4, Player.Actor().CastToActor(), 0);
        delay(0.0f);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnOptionsConfirm()
    {
        Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
        InitWindowSeed();
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnToggleRandPlayerLocation()
    {
        OnBtnToggle(BPR::GV_KEY_OPT_PLAYER_LOC);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnToggleAlwaysHaveKnife()
    {
        OnBtnToggle(BPR::GV_KEY_OPT_ALWAYS_KNIFE);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnToggleAlwaysHaveBow()
    {
        OnBtnToggle(BPR::GV_KEY_OPT_ALWAYS_BOW);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void OnBtnToggle(const kStr &in sGameVar)
    {
        if(g_pCurSelection.m_pActor !is null)
        {
            Game.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
            g_pCurSelection.m_iState ^= 1;
            GameVariables.SetValue(sGameVar, "" + g_pCurSelection.m_iState);
            if(g_pCurSelection.m_iState == 0)
            {
                g_pCurSelection.m_pActor.RenderModel().SetModel("models/ui/checkboxoff.bin", "anims/empty.bin");
            }
            else
            {
                g_pCurSelection.m_pActor.RenderModel().SetModel("models/ui/checkboxon.bin", "anims/empty.bin");
            }
        }
    }
    //------------------------------------------------------------------------------------------------------------------------
    void TickMainMenu()
    {
        Game.PrintLine("Randomizer Seed " + BPR::GameVar::GetInt(BPR::GV_KEY_START_SEED), 0);
        for(int i = 1; i < 7; i++)
        {
            Game.PrintLine("", i);
        }
    }
	//------------------------------------------------------------------------------------------------------------------------
    void SetStartSeed(const int iSeed)
    {
        int iNewSeed = BPR::Math::Clamp(iSeed, MIN_SEED_VALUE, MAX_SEED_VALUE);
		GameVariables.SetValue(BPR::GV_KEY_START_SEED, "" + iNewSeed);
        DrawUIText(g_npSeedTextActors, "" + iNewSeed, 0.0f, 4.1f, 1.75f, 0.0f, ALIGN_CENTER);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void SpawnCursor()
    {
        @g_pCursor = ActorFactory.Spawn("BPR_SpawnWorldUI", g_vUIPos.x, g_vUIPos.y - 0.01f, g_vUIPos.z, Math::pi);
        g_pCursor.Scale() = kVec3(0.9f, 0.9f, 0.9f);
    }
    //------------------------------------------------------------------------------------------------------------------------
    kActor@ SpawnUIActor(const kStr &in modelPath, const float x, const float z, const float sx, const float sz, const float depth, const bool addToList = true)
    {
        kActor @actor = ActorFactory.Spawn("BPR_SpawnWorldUI", g_vUIPos.x + x, g_vUIPos.y + depth, g_vUIPos.z + z, Math::pi);
        actor.RenderModel().SetModel(modelPath, "anims/empty.bin");
        actor.Scale() = kVec3(sx, 1.0f, sz);
        if(addToList)
            g_npUIActors.insertLast(actor);
        return actor;
    }
    //------------------------------------------------------------------------------------------------------------------------
    void DrawUIText(array<kActor@>& npActors, kStr &in s, const float x, const float y, const float scale, const float depth, int alignment)
    {
        for (uint i = 0; i < npActors.length(); i++)
            npActors[i].Remove();
        npActors.resize(0);
        
        // kStr sFontPath = "models/ui/font/";
        float offsetx = UICHAR_SPACING * scale;
        float scalex = UICHAR_WIDTH * scale;
        float scaley = UICHAR_HEIGHT * scale;
        int sLength = BPR::String::Length(s);
        float posx = 0.0;
        float baseX = 0.0;
        int c;
        if (alignment == ALIGN_CENTER)
            baseX = -((offsetx * sLength) / 2.0) + (offsetx / 2.0);
        for (int i = 0; i < sLength; i++)
        {
            if (alignment == ALIGN_RIGHT)
                posx = x + baseX - (offsetx * (sLength - i));
            else
                posx = x + baseX + (offsetx * i);
            
            c = s[i];
            if(c < 32 || c > 126)
                c = 32;
            
            npActors.insertLast(SpawnUIActor("models/ui/font/" + c + ".bin", posx, y, scalex, scaley, depth, false));
        }
    }
    //------------------------------------------------------------------------------------------------------------------------
    void SetUIActorPos(kActor@ actor, const float x, const float z)
    {
        actor.Origin().x = g_vUIPos.x + x;
        actor.Origin().z = g_vUIPos.z + z;
    }
    //------------------------------------------------------------------------------------------------------------------------
    void RemoveWindowActors()
    {
        @g_pCurSelection = null;
        for(uint i = 0; i < g_npSeedTextActors.length(); i++)
            g_npSeedTextActors[i].Remove();
        g_npSeedTextActors.resize(0);
        for(uint i = 0; i < g_npUIActors.length(); i++)
            g_npUIActors[i].Remove();
        g_npUIActors.resize(0);
        g_npSelections.resize(0);
    }
    //------------------------------------------------------------------------------------------------------------------------
    void InitWindow()
    {
        RemoveWindowActors();
    }
    //------------------------------------------------------------------------------------------------------------------------
    void InitWindowSeed()
    {
        InitWindow();
        
        SpawnUIActor("models/ui/menu00.bin", 0.0f, 0.0f, UIMENU_WIDTH, UIMENU_HEIGHT, 1.01f);
        
        AddSelection(OnBtnOptions, -6.58f, -6.1f, -2.74f, -4.78f);
        AddSelection(OnBtnRandom, -1.9f, -3.8f, 1.9f, -2.7f);
        AddSelection(OnBtnConfirm, 2.74f, -6.1f, 6.58f, -4.78f);
        AddSelection(OnBtnIncreaseSeed, 2.4f, 3.6f, 3.1f, 4.6f);
        AddSelection(OnBtnDecreaseSeed, -3.1f, 3.6f, -2.4f, 4.6f);
        AddSelection(OnBtnKP1, -2.0f, 1.3f, -0.66f, 2.6f);
        AddSelection(OnBtnKP2, -0.67f, 1.3f, 0.66f, 2.6f);
        AddSelection(OnBtnKP3, 0.67f, 1.3f, 2.0f, 2.6f);
        AddSelection(OnBtnKP4, -2.0f, 0.0f, -0.66f, 1.3f);
        AddSelection(OnBtnKP5, -0.67f, 0.0f, 0.66f, 1.3f);
        AddSelection(OnBtnKP6, 0.67f, 0.0f, 2.0f, 1.3f);
        AddSelection(OnBtnKP7, -2.0f, -1.3f, -0.66f, 0.0f);
        AddSelection(OnBtnKP8, -0.67f, -1.3f, 0.66f, 0.0f);
        AddSelection(OnBtnKP9, 0.67f, -1.3f, 2.0f, 0.0f);
        AddSelection(OnBtnReset, -2.0f, -2.6f, -0.66f, -1.3f);
        AddSelection(OnBtnKP0, -0.67f, -2.6f, 0.66f, -1.3f);
        AddSelection(OnBtnKeypadBack, 0.67f, -2.6f, 2.0f, -1.3f);
        
        SetStartSeed(BPR::GameVar::GetInt(GV_KEY_START_SEED));
    }
    //------------------------------------------------------------------------------------------------------------------------
    void InitWindowOptionsPage1()
    {
        InitWindow();
        
        SpawnUIActor("models/ui/menu01.bin", 0.0f, 0.0f, UIMENU_WIDTH, UIMENU_HEIGHT, 1.01f);
        AddSelectionCheckBox(BPR::GV_KEY_OPT_PLAYER_LOC, OnBtnToggleRandPlayerLocation,
                            7.5f, 4.2f, 8.5f, 5.2f,
                            9.0f, 5.4f, 1.5f, 1.5f, 1.0f);
        AddSelectionCheckBox(BPR::GV_KEY_OPT_ALWAYS_KNIFE, OnBtnToggleAlwaysHaveKnife,
                            7.5f, 2.2f, 8.5f, 3.2f,
                            9.0f, 3.15f, 1.5f, 1.5f, 1.0f);
        AddSelectionCheckBox(BPR::GV_KEY_OPT_ALWAYS_BOW, OnBtnToggleAlwaysHaveBow,
                            7.5f, 0.15f, 8.5f, 1.15f,
                            9.0f, 0.9f, 1.5f, 1.5f, 1.0f);
        AddSelection(OnBtnOptionsConfirm, 2.74f, -6.1f, 6.58f, -4.78f);
    }
    //------------------------------------------------------------------------------------------------------------------------
}
