Snippets Collections
// ---------------------------------------------------------------------------
// Project Name		:	Nook
// File Name		:	LevelSelect.c
// Author			:	Mary Khuu
// Creation Date	:	19 Mar 2021
// Purpose			:	Level Select
//
// All content © 2021 DigiPen (USA) Corporation, all rights reserved.
// ---------------------------------------------------------------------------

#include "framework.h"
#include "AEEngine.h"
#include "Audio.h"
#include "GameStateManager.h"
#include "Sprite.h"
#include "object_data.h"

#include "LevelSelect.h"

//------------------------------------------------------------------------------
// Private Constants:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Structures:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Variables:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Variables:
//------------------------------------------------------------------------------

static vec2 backgroundSize = { 1670.0f, 564.0f };
static vec2 buttonSize = { 100.0f, 30.0f };
static vec2 textSize = { 150.0f, 50.0f };
static vec2 iconSize = { 30.0f, 30.0f };
static vec2 menuPos = { 0.0f, 200.0f };
static vec2 tutorialPos = { 0.0f, 100.0f };
static vec2 level1Pos = { 0.0f, 0.0f };
static vec2 level2Pos = { 0.0f, -100.0f };
static vec2 level3Pos = { 0.0f, -200.0f };

static signed long mouseX, mouseY;
static float mouseInWorldX, mouseInWorldY;

static AEGfxVertexList* bgMesh;
static AEGfxVertexList* buttonMesh;
static AEGfxVertexList* fontMesh;
static AEGfxVertexList* iconMesh;
static AEGfxVertexList* numMesh;

static AEGfxTexture* bgTexture;
static AEGfxTexture* buttonTexture;
static AEGfxTexture* fontTexture;
static AEGfxTexture* iconTexture;
static AEGfxTexture* numTexture;

static TextureOffset numOffsets[10];
static TextureOffset fontOffsets[30];
static int* currentfontOffset = 0;
static int currfontFrame = 0;
static float* fontTime;

//------------------------------------------------------------------------------
// Private Function Declarations:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Functions:
//------------------------------------------------------------------------------

void LevelSelectLoad()
{
    /*mesh for bg*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 0.0f, 1.0f,
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        backgroundSize.x, backgroundSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    bgMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(bgMesh, "Failed to create button!");

    bgTexture = AEGfxTextureLoad("Assets/CityscapeGrey.png");
    AE_ASSERT_MESG(bgTexture, "Failed to create pTex!!");

    /*mesh for buttons: green*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -buttonSize.x, -buttonSize.y, 0xFF00FF00, 0.0f, 1.0f,
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        buttonSize.x, buttonSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    buttonMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(buttonMesh, "Failed to create button!");

    buttonTexture = AEGfxTextureLoad("Assets/NookButtonBright.png");
    AE_ASSERT_MESG(buttonTexture, "Failed to create texture!");

    /*mesh for hover icon*/
    iconMesh = createQuadMesh(iconSize.x, iconSize.y, 1.0f, 1.0f, "yarn");

    iconTexture = AEGfxTextureLoad("Assets/TempHover.png");
    AE_ASSERT_MESG(iconTexture, "Failed to create texture!");

    /*mesh for text*/
    fontMesh = createQuadMesh(15.0f, 15.0f, 1.0 / 5, 1.0f / 6, "alphabets");

    fontTexture = AEGfxTextureLoad("Assets/NookFontSheet_alphabet.png");
    AE_ASSERT_MESG(fontTexture, "Failed to create texture!");    

    fontOffsets[0].mX = 0.0f;			    fontOffsets[0].mY = 0.0f / 6;  //A
    fontOffsets[1].mX = 1.0f / 5;		    fontOffsets[1].mY = 0.0f / 6;  //B
    fontOffsets[2].mX = 2.0f / 5;			fontOffsets[2].mY = 0.0f / 6;  //C
    fontOffsets[3].mX = 3.0f / 5;			fontOffsets[3].mY = 0.0f / 6;  //D
    fontOffsets[4].mX = 4.0f / 5;			fontOffsets[4].mY = 0.0f / 6;  //E

    fontOffsets[5].mX = 0.0f;			    fontOffsets[5].mY = 1.0f / 6;  //F
    fontOffsets[6].mX = 1.0f / 5;		    fontOffsets[6].mY = 1.0f / 6;  //G
    fontOffsets[7].mX = 2.0f / 5;			fontOffsets[7].mY = 1.0f / 6;  //H
    fontOffsets[8].mX = 3.0f / 5;			fontOffsets[8].mY = 1.0f / 6;  //I
    fontOffsets[9].mX = 4.0f / 5;			fontOffsets[9].mY = 1.0f / 6;  //J

    fontOffsets[10].mX = 0.0f;			    fontOffsets[10].mY = 2.0f / 6;  //K
    fontOffsets[11].mX = 1.0f / 5;		    fontOffsets[11].mY = 2.0f / 6;  //L
    fontOffsets[12].mX = 2.0f / 5;			fontOffsets[12].mY = 2.0f / 6;  //M
    fontOffsets[13].mX = 3.0f / 5;			fontOffsets[13].mY = 2.0f / 6;  //N
    fontOffsets[14].mX = 4.0f / 5;			fontOffsets[14].mY = 2.0f / 6;  //O

    fontOffsets[15].mX = 0.0f;			    fontOffsets[15].mY = 3.0f / 6;  //P
    fontOffsets[16].mX = 1.0f / 5;		    fontOffsets[16].mY = 3.0f / 6;  //Q
    fontOffsets[17].mX = 2.0f / 5;			fontOffsets[17].mY = 3.0f / 6;  //R
    fontOffsets[18].mX = 3.0f / 5;			fontOffsets[18].mY = 3.0f / 6;  //S
    fontOffsets[19].mX = 4.0f / 5;			fontOffsets[19].mY = 3.0f / 6;  //T

    fontOffsets[20].mX = 0.0f;			    fontOffsets[20].mY = 4.0f / 6;  //U
    fontOffsets[21].mX = 1.0f / 5;		    fontOffsets[21].mY = 4.0f / 6;  //V
    fontOffsets[22].mX = 2.0f / 5;			fontOffsets[22].mY = 4.0f / 6;  //W
    fontOffsets[23].mX = 3.0f / 5;			fontOffsets[23].mY = 4.0f / 6;  //X
    fontOffsets[24].mX = 4.0f / 5;			fontOffsets[24].mY = 4.0f / 6;  //Y


    fontOffsets[25].mX = 0.0f;			    fontOffsets[25].mY = 5.0f / 6;   //Z  
    fontOffsets[26].mX = 1.0f / 5;		    fontOffsets[26].mY = 5.0f / 6;  //blank (1)
    fontOffsets[27].mX = 2.0f / 5;			fontOffsets[27].mY = 5.0f / 6;  //blank (2)
    fontOffsets[28].mX = 3.0f / 5;			fontOffsets[28].mY = 5.0f / 6;  //blank (3)
    fontOffsets[29].mX = 4.0f / 5;			fontOffsets[29].mY = 5.0f / 6;  //blank (4)

    /*mesh for numbers*/
    numMesh = createQuadMesh(15.0f, 15.0f, 1.0 / 3, 1.0f / 4, "numbers");

    numTexture = AEGfxTextureLoad("Assets/NookFontSheet_numbers.png");
    AE_ASSERT_MESG(numTexture, "Failed to create texture!");

    numOffsets[0].mX = 0.0f;			    numOffsets[0].mY = 0.0f / 4;  //0
    numOffsets[1].mX = 1.0f / 3;		    numOffsets[1].mY = 0.0f / 4;  //1
    numOffsets[2].mX = 2.0f / 3;			numOffsets[2].mY = 0.0f / 4;  //2
    
    numOffsets[3].mX = 0.0f;			    numOffsets[3].mY = 1.0f / 4;  //3
    numOffsets[4].mX = 1.0f / 3;			numOffsets[4].mY = 1.0f / 4;  //4
    numOffsets[5].mX = 2.0f / 3;			numOffsets[5].mY = 1.0f / 4;  //5
    
    numOffsets[6].mX = 0.0f;		        numOffsets[6].mY = 2.0f / 4;  //6
    numOffsets[7].mX = 1.0f / 3;			numOffsets[7].mY = 2.0f / 4;  //7
    numOffsets[8].mX = 2.0f / 3;			numOffsets[8].mY = 2.0f / 4;  //8
    
    numOffsets[9].mX = 0.0f / 3;			numOffsets[9].mY = 3.0f / 4;  //9
}

void LevelSelectInit()
{
	AEGfxSetBackgroundColor(1.0f, 1.0f, 1.0f);
	AEGfxSetBlendMode(AE_GFX_BM_BLEND);
}

void LevelSelectUpdate(float dt)
{
    /* Tell the compiler that the 'dt' variable is unused. */
    UNREFERENCED_PARAMETER(dt);

    /*draw background*/
    AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
    AEGfxTextureSet(bgTexture, 0, 0);
    AEGfxSetTransparency(1.0f);
    AEGfxSetPosition(-250.0f, 0.0f);
    AEGfxMeshDraw(bgMesh, AE_GFX_MDM_TRIANGLES);

    //draw menu button
    AEGfxSetPosition(menuPos.x, menuPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw tutorial button
    AEGfxSetPosition(tutorialPos.x, tutorialPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);
    

    //draw level1 button
    AEGfxSetPosition(level1Pos.x, level1Pos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw level2 button
    AEGfxSetPosition(level2Pos.x, level2Pos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw level3 button
    AEGfxSetPosition(level3Pos.x, level3Pos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    /*MENU*/
    AEGfxSetPosition(menuPos.x - 45.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[12].mX, fontOffsets[12].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(menuPos.x - 13.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(menuPos.x + 15.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[13].mX, fontOffsets[13].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(menuPos.x + 45.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[20].mX, fontOffsets[20].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*MENU - end*/

    /*TUTORIAL*/
    AEGfxSetPosition(tutorialPos.x - 86.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x - 58.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[20].mX, fontOffsets[20].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x - 30.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[14].mX, fontOffsets[14].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 30.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[17].mX, fontOffsets[17].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 46.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[8].mX, fontOffsets[8].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 65.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[0].mX, fontOffsets[0].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 90.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*TUTORIAL - end*/

    /*LEVEL 1*/
    AEGfxSetPosition(level1Pos.x - 85.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x - 60.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x - 34.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[21].mX, fontOffsets[21].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x - 5.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x + 17.5f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x + 85.0f, level1Pos.y);
    AEGfxTextureSet(numTexture, numOffsets[1].mX, numOffsets[1].mY, 0.0f); // 1
    AEGfxMeshDraw(numMesh, AE_GFX_MDM_TRIANGLES);

    /*LEVEL 1 - end*/

    /*LEVEL 2*/
    AEGfxSetPosition(level2Pos.x - 85.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x - 60.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x - 34.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[21].mX, fontOffsets[21].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x - 5.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x + 17.5f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x + 85.0f, level2Pos.y);
    AEGfxTextureSet(numTexture, numOffsets[2].mX, numOffsets[2].mY, 0.0f); // 2
    AEGfxMeshDraw(numMesh, AE_GFX_MDM_TRIANGLES);

    /*LEVEL 2 - end*/

    /*LEVEL 3*/
    AEGfxSetPosition(level3Pos.x - 85.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x - 60.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x - 34.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[21].mX, fontOffsets[21].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x - 5.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x + 17.5f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x + 85.0f, level3Pos.y);
    AEGfxTextureSet(numTexture, numOffsets[3].mX, numOffsets[3].mY, 0.0f); // 3
    AEGfxMeshDraw(numMesh, AE_GFX_MDM_TRIANGLES);

    /*LEVEL 3 - end*/

    /*get the mouse position*/
    AEInputGetCursorPosition(&mouseX, &mouseY);
    AEGfxConvertScreenCoordinatesToWorld(mouseX, mouseY, &mouseInWorldX, &mouseInWorldY);

    /*if menu is hovered*/
    if ((mouseInWorldX > (menuPos.x - buttonSize.x) && mouseInWorldX < (menuPos.x + buttonSize.x)) &&
        (mouseInWorldY > (menuPos.y - buttonSize.y) && mouseInWorldY < (menuPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(menuPos.x - 140.0f, menuPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Menu);
        }
    }

    /*if tutorial is hovered*/
    if ((mouseInWorldX > (tutorialPos.x - buttonSize.x) && mouseInWorldX < (tutorialPos.x + buttonSize.x)) &&
        (mouseInWorldY > (tutorialPos.y - buttonSize.y) && mouseInWorldY < (tutorialPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(tutorialPos.x - 140.0f, tutorialPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Tutorial);
        }
    }

    /*if level1 is hovered*/
    if ((mouseInWorldX > (level1Pos.x - buttonSize.x) && mouseInWorldX < (level1Pos.x + buttonSize.x)) &&
        (mouseInWorldY > (level1Pos.y - buttonSize.y) && mouseInWorldY < (level1Pos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(level1Pos.x - 140.0f, level1Pos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Demo);
        }
    }

    /*if level2 is hovered*/
    if ((mouseInWorldX > (level2Pos.x - buttonSize.x) && mouseInWorldX < (level2Pos.x + buttonSize.x)) &&
        (mouseInWorldY > (level2Pos.y - buttonSize.y) && mouseInWorldY < (level2Pos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(level2Pos.x - 140.0f, level2Pos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Level2);
        }
    }

    /*if level3 is hovered*/
    if ((mouseInWorldX > (level3Pos.x - buttonSize.x) && mouseInWorldX < (level3Pos.x + buttonSize.x)) &&
        (mouseInWorldY > (level3Pos.y - buttonSize.y) && mouseInWorldY < (level3Pos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(level3Pos.x - 140.0f, level3Pos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Level3);
        }
    }
}

void LevelSelectShutdown()
{
    AudioCleanup();
}

void LevelSelectUnload()
{
    // Unload all textures.
    AEGfxTextureUnload(buttonTexture);
    AEGfxTextureUnload(fontTexture);
    AEGfxTextureUnload(bgTexture);
    AEGfxTextureUnload(iconTexture);
    AEGfxTextureUnload(numTexture);

    // Free all meshes.
    AEGfxMeshFree(buttonMesh);
    AEGfxMeshFree(fontMesh);
    AEGfxMeshFree(bgMesh);
    AEGfxMeshFree(iconMesh);
    AEGfxMeshFree(numMesh);
}

//------------------------------------------------------------------------------
// Private Functions:
//------------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Project Name		:	Nook
// File Name		:	Menu.c
// Author			:	Rey Rosario, Mary Khuu
// Creation Date	:	25 Jan 2021
// Purpose			:	Main Menu
//
// All content © 2021 DigiPen (USA) Corporation, all rights reserved.
// ---------------------------------------------------------------------------

#include "framework.h"
#include "AEEngine.h"
#include "Audio.h"
#include "GameStateManager.h"
#include "object_data.h"
#include "Sprite.h"

#include "Menu.h"

//------------------------------------------------------------------------------
// Private Constants:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Structures:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Variables:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Variables:
//------------------------------------------------------------------------------

static vec2 backgroundSize = { 1670.0f, 564.0f };
static vec2 buttonSize = { 100.0f, 30.0f };
static vec2 titleSize = { 150.0f, 50.0f };
static vec2 iconSize = { 30.0f, 30.0f };
static vec2 levelPos = { 0.0f, 0.0f };
static vec2 creditsPos = { 0.0f, -100.0f };
static vec2 exitPos = { 0.0f, -200.0f };
static vec2 titlePos = { 0.0f, 150.0f };

static signed long mouseX, mouseY;
static float mouseInWorldX, mouseInWorldY;

static AEGfxVertexList* buttonMesh;
static AEGfxVertexList* titleMesh;
static AEGfxVertexList* bgMesh;
static AEGfxVertexList* fontMesh;
static AEGfxVertexList* iconMesh;

static AEGfxTexture* bgTexture;
static AEGfxTexture* buttonTexture;
static AEGfxTexture* titleTexture;
static AEGfxTexture* fontTexture;
static AEGfxTexture* iconTexture;

TextureOffset titleOffsets[6];
int* currentTitleOffset = 0;
int currTitleFrame = 0;
float* titleTime;

static TextureOffset fontOffsets[30];
static int* currentfontOffset = 0;
static int currfontFrame = 0;
static float* fontTime;

static float bgMusicTimer;

//------------------------------------------------------------------------------
// Private Function Declarations:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Functions:
//------------------------------------------------------------------------------

void MenuLoad()
{
    /*mesh for bg*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 0.0f, 1.0f,
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        backgroundSize.x, backgroundSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    bgMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(bgMesh, "Failed to create button!");

    bgTexture = AEGfxTextureLoad("Assets/CityscapeGrey.png");
    AE_ASSERT_MESG(bgTexture, "Failed to create pTex!!");

    /*mesh for buttons: green*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -buttonSize.x, -buttonSize.y, 0xFF00FF00, 0.0f, 1.0f,
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        buttonSize.x, buttonSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    buttonMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(buttonMesh, "Failed to create button!");

    buttonTexture = AEGfxTextureLoad("Assets/NookButtonBright.png");
    AE_ASSERT_MESG(buttonTexture, "Failed to create texture!");

    /*mesh for text*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -titleSize.x, -titleSize.y, 0xFF00FF00, 0.0f, 1.0f / 6,
        titleSize.x, -titleSize.y, 0xFF00FF00, 1.0f, 1.0f / 6,
        -titleSize.x, titleSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        titleSize.x, -titleSize.y, 0xFF00FF00, 1.0f, 1.0f / 6,
        titleSize.x, titleSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -titleSize.x, titleSize.y, 0xFF00FF00, 0.0f, 0.0f);

    titleMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(titleMesh, "Failed to create button!");

    titleTexture = AEGfxTextureLoad("Assets/NookLogo.png");
    AE_ASSERT_MESG(titleTexture, "Failed to create texture!");

    titleOffsets[0].mX = 0.0f;			titleOffsets[0].mY = 0.0f;
    titleOffsets[1].mX = 0.0f;			titleOffsets[1].mY = 1.0f / 6;
    titleOffsets[2].mX = 0.0f;			titleOffsets[2].mY = 2.0f / 6;
    titleOffsets[3].mX = 0.0f;			titleOffsets[3].mY = 3.0f / 6;
    titleOffsets[4].mX = 0.0f;			titleOffsets[4].mY = 4.0f / 6;
    titleOffsets[5].mX = 0.0f;			titleOffsets[5].mY = 5.0f / 6;

    /*mesh for hover icon*/
    iconMesh = createQuadMesh(iconSize.x, iconSize.y, 1.0f, 1.0f, "yarn");
    
    iconTexture = AEGfxTextureLoad("Assets/TempHover.png");
    AE_ASSERT_MESG(iconTexture, "Failed to create texture!");

    /*mesh for text*/
    fontMesh = createQuadMesh(15.0f, 15.0f, 1.0 / 5, 1.0f / 6, "alphabets");

    fontTexture = AEGfxTextureLoad("Assets/NookFontSheet_alphabet.png");
    AE_ASSERT_MESG(fontTexture, "Failed to create texture!");
        
    fontOffsets[0].mX = 0.0f;			    fontOffsets[0].mY = 0.0f / 6;  //A
    fontOffsets[1].mX = 1.0f / 5;		    fontOffsets[1].mY = 0.0f / 6;  //B
    fontOffsets[2].mX = 2.0f / 5;			fontOffsets[2].mY = 0.0f / 6;  //C
    fontOffsets[3].mX = 3.0f / 5;			fontOffsets[3].mY = 0.0f / 6;  //D
    fontOffsets[4].mX = 4.0f / 5;			fontOffsets[4].mY = 0.0f / 6;  //E

    fontOffsets[5].mX = 0.0f;			    fontOffsets[5].mY = 1.0f / 6;  //F
    fontOffsets[6].mX = 1.0f / 5;		    fontOffsets[6].mY = 1.0f / 6;  //G
    fontOffsets[7].mX = 2.0f / 5;			fontOffsets[7].mY = 1.0f / 6;  //H
    fontOffsets[8].mX = 3.0f / 5;			fontOffsets[8].mY = 1.0f / 6;  //I
    fontOffsets[9].mX = 4.0f / 5;			fontOffsets[9].mY = 1.0f / 6;  //J

    fontOffsets[10].mX = 0.0f;			    fontOffsets[10].mY = 2.0f / 6;  //K
    fontOffsets[11].mX = 1.0f / 5;		    fontOffsets[11].mY = 2.0f / 6;  //L
    fontOffsets[12].mX = 2.0f / 5;			fontOffsets[12].mY = 2.0f / 6;  //M
    fontOffsets[13].mX = 3.0f / 5;			fontOffsets[13].mY = 2.0f / 6;  //N
    fontOffsets[14].mX = 4.0f / 5;			fontOffsets[14].mY = 2.0f / 6;  //O

    fontOffsets[15].mX = 0.0f;			    fontOffsets[15].mY = 3.0f / 6;  //P
    fontOffsets[16].mX = 1.0f / 5;		    fontOffsets[16].mY = 3.0f / 6;  //Q
    fontOffsets[17].mX = 2.0f / 5;			fontOffsets[17].mY = 3.0f / 6;  //R
    fontOffsets[18].mX = 3.0f / 5;			fontOffsets[18].mY = 3.0f / 6;  //S
    fontOffsets[19].mX = 4.0f / 5;			fontOffsets[19].mY = 3.0f / 6;  //T

    fontOffsets[20].mX = 0.0f;			    fontOffsets[20].mY = 4.0f / 6;  //U
    fontOffsets[21].mX = 1.0f / 5;		    fontOffsets[21].mY = 4.0f / 6;  //V
    fontOffsets[22].mX = 2.0f / 5;			fontOffsets[22].mY = 4.0f / 6;  //W
    fontOffsets[23].mX = 3.0f / 5;			fontOffsets[23].mY = 4.0f / 6;  //X
    fontOffsets[24].mX = 4.0f / 5;			fontOffsets[24].mY = 4.0f / 6;  //Y


    fontOffsets[25].mX = 0.0f;			    fontOffsets[25].mY = 5.0f / 6;   //Z  
    fontOffsets[26].mX = 1.0f / 5;		    fontOffsets[26].mY = 5.0f / 6;  //blank
    fontOffsets[27].mX = 2.0f / 5;			fontOffsets[27].mY = 5.0f / 6;  //blank
    fontOffsets[28].mX = 3.0f / 5;			fontOffsets[28].mY = 5.0f / 6;  //blank
    fontOffsets[29].mX = 4.0f / 5;			fontOffsets[29].mY = 5.0f / 6;  //blank
}

void MenuInit()
{
	AEGfxSetBackgroundColor(0.0f, 0.0f, 0.0f);
    AEGfxSetBlendMode(AE_GFX_BM_BLEND);

    AudioInit();
    bgMusicTimer = 1638.0f; // Roughly 27 seconds
}

void MenuUpdate(float dt)
{
	/* Tell the compiler that the 'dt' variable is unused. */
	UNREFERENCED_PARAMETER(dt);

    /*play bg music*/
    if (bgMusicTimer == 1638.0f)
    {
        playSoundAdvanced("Assets/Sounds/Level2Track.mp3", 0.1f);
    }
        
    /*reset time for bg music loop*/
    if (bgMusicTimer == 0.0f)
    {
        bgMusicTimer = 1638.0f;
    }
    else
    {
        bgMusicTimer--;
    }

    /*draw background*/
    AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
    AEGfxTextureSet(bgTexture, 0, 0);
    AEGfxSetTransparency(1.0f);
    AEGfxSetPosition(-250.0f, 0.0f);
    AEGfxMeshDraw(bgMesh, AE_GFX_MDM_TRIANGLES);
    
    //draw menu button
    AEGfxSetPosition(levelPos.x, levelPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxSetTransparency(1.0f);
    AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw replay button
    AEGfxSetPosition(creditsPos.x, creditsPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw exit button
    AEGfxSetPosition(exitPos.x, exitPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    /*PLAY*/

    AEGfxSetPosition(levelPos.x - 40.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[15].mX, fontOffsets[15].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(levelPos.x - 15.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(levelPos.x + 10.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[0].mX, fontOffsets[0].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(levelPos.x + 35.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[24].mX, fontOffsets[24].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*PLAY - end*/

    /*CREDITS*/
    AEGfxSetPosition(creditsPos.x - 75.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[2].mX, fontOffsets[2].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x - 45.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[17].mX, fontOffsets[17].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x - 20.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 5.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[3].mX, fontOffsets[3].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 25.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[8].mX, fontOffsets[8].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 47.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 75.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[18].mX, fontOffsets[18].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*CREDITS - end*/

    /*QUIT*/
    AEGfxSetPosition(exitPos.x - 40.0f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[16].mX, fontOffsets[16].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(exitPos.x - 7.5f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[20].mX, fontOffsets[20].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(exitPos.x + 17.5f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[8].mX, fontOffsets[8].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(exitPos.x + 40.0f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*QUIT - end*/

    animateFrames(&currentTitleOffset, &titleTime, 0.25f, dt);
    checkEndFrames(&currentTitleOffset, 6);
    currTitleFrame = currentTitleOffset;

    /*draw player*/
    AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
    AEGfxSetPosition(titlePos.x, titlePos.y);
    AEGfxTextureSet(titleTexture, titleOffsets[currTitleFrame].mX, titleOffsets[currTitleFrame].mY);
    AEGfxSetTransparency(1.0f);
    AEGfxMeshDraw(titleMesh, AE_GFX_MDM_TRIANGLES);

    /*get the mouse position*/
    AEInputGetCursorPosition(&mouseX, &mouseY);
    AEGfxConvertScreenCoordinatesToWorld(mouseX, mouseY, &mouseInWorldX, &mouseInWorldY);

    /*if demo level is hovered*/
    if ((mouseInWorldX > (levelPos.x - buttonSize.x) && mouseInWorldX < (levelPos.x + buttonSize.x)) &&
        (mouseInWorldY > (levelPos.y - buttonSize.y) && mouseInWorldY < (levelPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(levelPos.x - 140.0f, levelPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(LevelSelect);
        }
    }
    /*if credits is hovered*/
    if ((mouseInWorldX > (creditsPos.x - buttonSize.x) && mouseInWorldX < (creditsPos.x + buttonSize.x)) &&
        (mouseInWorldY > (creditsPos.y - buttonSize.y) && mouseInWorldY < (creditsPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(creditsPos.x - 140.0f, creditsPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Credits);
        }
    }

    /*if exit is hovered*/
    if ((mouseInWorldX > (exitPos.x - buttonSize.x) && mouseInWorldX < (exitPos.x + buttonSize.x)) &&
        (mouseInWorldY > (exitPos.y - buttonSize.y) && mouseInWorldY < (exitPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(exitPos.x - 140.0f, exitPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(GsQuit);
        }
    }
}

void MenuShutdown()
{
    // Do not cleanup audio so music continues into credits and level select
}

void MenuUnload()
{
	// Unload all textures.
    AEGfxTextureUnload(buttonTexture);
    AEGfxTextureUnload(titleTexture);
    AEGfxTextureUnload(bgTexture);
    AEGfxTextureUnload(fontTexture);
    AEGfxTextureUnload(iconTexture);

    // Free all meshes.
    AEGfxMeshFree(buttonMesh);
    AEGfxMeshFree(titleMesh);
    AEGfxMeshFree(bgMesh);
    AEGfxMeshFree(fontMesh);
    AEGfxMeshFree(iconMesh);
}
    @IBAction func loginPressed(_ sender: Any) {
        
        let email = emailTextField.text ?? ""
        let password = passwordTextField.text ?? ""
        var message = ""
        
        if email == "" {
            message = AppDelegate.selectedLanguage == "en" ? "Please enter email" : "الرجاء ادخال البريد الإلكتروني"
        } else if password == "" {
            message = AppDelegate.selectedLanguage == "en" ? "Please enter password" : "الرجاء ادخال كلمتك السريه"
        } else if !isValidEmail(email) {
            message = AppDelegate.selectedLanguage == "en" ? "please_enter_a_valid_email" : "الرجاء ادخال بريد إلكتروني صالح"
        }
        
        if message != "" {
            self.showToast(message: message)
            return
        }
        
        Auth.auth().signIn(withEmail: emailTextField.text ?? "", password: passwordTextField.text ?? "") { [weak self] authResult, error in
            if error != nil {
                let message = AppDelegate.selectedLanguage == "en" ? "Entered email or password is not correct" : "البريد الإلكتروني أو كلمة المرور المدخلة غير صحيحة"
                self?.showToast(message: message)
                return
            }
            self?.getUserData()
        }
    }
  override func viewDidLoad() {
        super.viewDidLoad()
        setSwipeGesture()
}

func setSwipeGesture() {
        let swipeRightGesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
        if AppDelegate.selectedLanguage == "en" {
            swipeRightGesture.direction = .right
        } else {
            swipeRightGesture.direction = .left
        }
              view.addGestureRecognizer(swipeRightGesture)
    }
    
    @objc func handleSwipe(_ gesture: UISwipeGestureRecognizer) {
            if gesture.direction == .right && isOpen == false && AppDelegate.selectedLanguage == "en" {
                toggleSideMenu()
            }  else if gesture.direction == .left && isOpen == false && AppDelegate.selectedLanguage == "ar" {
                toggleSideMenu()
            }
        
     }
    
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        if isOpen && AppDelegate.selectedLanguage == "en" {
             if let touch = touches.first {
                 let location = touch.location(in: view)
                 if location.x < 50 { // Adjust the threshold as needed
                     toggleSideMenu()
                 }
             } else if isOpen && AppDelegate.selectedLanguage == "ar" {
            
                         if let touch = touches.first {
                             let location = touch.location(in: view)
                             if location.x > view.frame.size.width - 50 { // Adjust the threshold as needed
                                 toggleSideMenu()
                             }
                         }
             }
         }
     }
    
    func toggleSideMenu() {
        if AppDelegate.selectedLanguage == "en" {
            UIView.animate(withDuration: 0.15) {
                if self.isOpen {
                    self.sideMenuView.frame.origin.x = -self.sideMenuView.frame.size.width
                    self.isOpen = false
                    
                } else {
                    self.sideMenuView.frame.origin.x = 0
                    self.isOpen = true
                }
            }
        } else {
                UIView.animate(withDuration: 0.15) {
                     if self.isOpen {
                         self.sideMenuView.frame.origin.x = self.view.frame.size.width // Slide it to the right side
                         self.isOpen = false
                     } else {
                         self.sideMenuView.frame.origin.x = self.view.frame.size.width - self.sideMenuView.frame.size.width // Slide it to the left side
                         self.isOpen = true
                     }
                 }
        }
    }
    
    func shareLinkOnSocialMedia(link: URL, viewController: UIViewController) {
        let activityViewController = UIActivityViewController(activityItems: [link], applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = viewController.view
        viewController.present(activityViewController, animated: true, completion: nil)
    }
    
    @IBAction func menuPressed(_ sender: Any) {
        toggleSideMenu()
    }

@IBAction func backMenuButton1Pressed(_ sender: Any) {
        toggleSideMenu()
    }
star

Thu Apr 04 2024 19:03:21 GMT+0000 (Coordinated Universal Time)

#c++ #c #nook #ui #levelselect #menu
star

Thu Apr 04 2024 18:50:23 GMT+0000 (Coordinated Universal Time)

#c++ #c #nook #ui #menu
star

Wed Oct 25 2023 05:48:02 GMT+0000 (Coordinated Universal Time) https://codepen.io/jh3y/pen/poGJowE

#menu #toggle #button
star

Mon Oct 09 2023 10:47:40 GMT+0000 (Coordinated Universal Time)

#ios #swift #menu #slide #slidemenu #slider #slideview
star

Mon Oct 09 2023 07:52:02 GMT+0000 (Coordinated Universal Time)

#ios #swift #menu #slide #slidemenu #slider #slideview

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension