Example #1
0
void Screen_Pause::Tick(double TimePassed)
{
    Screen_Base::Tick( TimePassed );

    if( g_pGame->m_pResources )
    {
        for( int i=0; i<m_MenuItemsNeeded; i++ )
            GetMenuButton( i )->SetFont( g_pGame->m_pSystemFont );
    }
}
int Screen_Base::GetMenuButtonHeldCount()
{
    int count = 0;

    for( int i=0; i<m_MenuItemsNeeded; i++ )
    {
        if( GetMenuItem(i) && GetMenuItemType(i) == MIT_Button )
        {
            if( GetMenuButton(i)->GetState() == MBS_HeldDown )
                count++;
        }
    }

    return count;
}
char* Screen_Base::ExportMenuLayout()
{
    cJSON* menuitemarray = cJSON_CreateArray();

    for( int i=0; i<MAX_MENUITEMS; i++ )
    {
        MenuItem* pMenuItem = m_pMenuItems[i];

        if( pMenuItem )
        {
            cJSON* menuitem = cJSON_CreateObject();
            cJSON_AddItemToArray( menuitemarray, menuitem );

            cJSON_AddStringToObject( menuitem, "Name", pMenuItem->m_Name );

            cJSON_AddNumberToObject( menuitem, "X", pMenuItem->m_Transform.m41 );
            cJSON_AddNumberToObject( menuitem, "Y", pMenuItem->m_Transform.m42 );

            cJSON_AddNumberToObject( menuitem, "Scale", pMenuItem->m_Scale.x );

            cJSON_AddNumberToObject( menuitem, "SX", pMenuItem->m_Size.x );
            cJSON_AddNumberToObject( menuitem, "SY", pMenuItem->m_Size.y );

            cJSON_AddNumberToObject( menuitem, "OffX", pMenuItem->m_PositionOffset.x );
            cJSON_AddNumberToObject( menuitem, "OffY", pMenuItem->m_PositionOffset.y );

            switch( pMenuItem->m_MenuItemType )
            {
            case MIT_Sprite:
                {
                    MenuSprite* pMenuSprite = GetMenuSprite( i );

                    cJSON_AddNumberToObject( menuitem, "W", pMenuItem->m_Transform.m11 );
                    cJSON_AddNumberToObject( menuitem, "H", pMenuItem->m_Transform.m22 );

                    cJSON_AddNumberToObject( menuitem, "BGShadowX", pMenuSprite->m_DropShadowOffsetBG_X );
                    cJSON_AddNumberToObject( menuitem, "BGShadowY", pMenuSprite->m_DropShadowOffsetBG_Y );
                }
                break;

            case MIT_Text: // MenuText_SaveLoad
                {
                    MenuText* pMenuText = GetMenuText( i );

                    cJSON_AddNumberToObject( menuitem, "FontHeight", pMenuText->m_FontHeight );

                    cJSON_AddNumberToObject( menuitem, "TextShadowX", pMenuText->m_DropShadowOffsetX );
                    cJSON_AddNumberToObject( menuitem, "TextShadowY", pMenuText->m_DropShadowOffsetY );

                    cJSON_AddNumberToObject( menuitem, "Justify", pMenuText->m_Justification );
                }
                break;

            case MIT_Button:
                {
                    MenuButton* pMenuButton = GetMenuButton( i );

                    cJSON_AddNumberToObject( menuitem, "W", pMenuItem->m_Transform.m11 );
                    cJSON_AddNumberToObject( menuitem, "H", pMenuItem->m_Transform.m22 );

                    cJSON_AddNumberToObject( menuitem, "IW", pMenuButton->m_InputWidth );
                    cJSON_AddNumberToObject( menuitem, "IH", pMenuButton->m_InputHeight );

                    cJSON_AddNumberToObject( menuitem, "FontHeight", pMenuButton->m_FontHeight );

                    cJSON_AddNumberToObject( menuitem, "BGShadowX", pMenuButton->m_DropShadowOffsetBG_X );
                    cJSON_AddNumberToObject( menuitem, "BGShadowY", pMenuButton->m_DropShadowOffsetBG_Y );

                    cJSON_AddNumberToObject( menuitem, "TextShadowX", pMenuButton->m_DropShadowOffsetText_X );
                    cJSON_AddNumberToObject( menuitem, "TextShadowY", pMenuButton->m_DropShadowOffsetText_Y );
                }
                break;

            case MIT_Base:
            case MIT_InputBox:
            case MIT_ScrollingText:
            case MIT_ScrollBox:
            case MIT_CheckBox:
            case MIT_NumMenuItemTypes:
                break;
            }
        }
    }

    char* savestring = cJSON_PrintUnformatted( menuitemarray );
    cJSON_Delete( menuitemarray );

    char* RidiculousReallocatedStringSoICanUseMyNewDeleteOverridesWithoutChangingThecJSONCodeToUseThemForAllItsSmallAllocations;
    int len = (int)strlen( savestring );
    RidiculousReallocatedStringSoICanUseMyNewDeleteOverridesWithoutChangingThecJSONCodeToUseThemForAllItsSmallAllocations = MyNew char[len+1];
    strcpy_s( RidiculousReallocatedStringSoICanUseMyNewDeleteOverridesWithoutChangingThecJSONCodeToUseThemForAllItsSmallAllocations, len+1, savestring );
    free( savestring );

    return RidiculousReallocatedStringSoICanUseMyNewDeleteOverridesWithoutChangingThecJSONCodeToUseThemForAllItsSmallAllocations;
}
void Screen_Base::ImportMenuLayout(const char* layout)
{
    if( layout == 0 )
        return;

    cJSON* menuitemarray = cJSON_Parse( layout );
    assert( menuitemarray );

    if( menuitemarray )
    {
        int numitems = cJSON_GetArraySize( menuitemarray );
        assert( numitems <= MAX_MENUITEMS );

        for( int i=0; i<numitems; i++ )
        {
            cJSON* menuitem = cJSON_GetArrayItem( menuitemarray, i );

            cJSON* objname = cJSON_GetObjectItem( menuitem, "Name" );

            int itemindex = -1;
            for( itemindex = 0; itemindex < MAX_MENUITEMS; itemindex++ )
            {
                if( strcmp( objname->valuestring, m_pMenuItems[itemindex]->m_Name ) == 0 )
                    break;
            }

            if( itemindex < MAX_MENUITEMS )
            {
                float x = 0;
                float y = 0;
                float w = 0;
                float h = 0;
                float iw = -1;
                float ih = -1;

                MenuItem* pMenuItem = m_pMenuItems[itemindex];

                cJSONExt_GetFloat( menuitem, "X", &x );
                cJSONExt_GetFloat( menuitem, "Y", &y );

                cJSONExt_GetFloat( menuitem, "Scale", &pMenuItem->m_Scale.x );
                cJSONExt_GetFloat( menuitem, "Scale", &pMenuItem->m_Scale.y );
                cJSONExt_GetFloat( menuitem, "Scale", &pMenuItem->m_Scale.z );

                cJSONExt_GetFloat( menuitem, "SX", &pMenuItem->m_Size.x );
                cJSONExt_GetFloat( menuitem, "SY", &pMenuItem->m_Size.y );

                cJSONExt_GetFloat( menuitem, "W", &w );
                cJSONExt_GetFloat( menuitem, "H", &h );

                cJSONExt_GetFloat( menuitem, "IW", &iw );
                cJSONExt_GetFloat( menuitem, "IH", &ih );

                cJSONExt_GetFloat( menuitem, "OffX", &pMenuItem->m_PositionOffset.x );
                cJSONExt_GetFloat( menuitem, "OffY", &pMenuItem->m_PositionOffset.y );

                pMenuItem->SetPositionAndSize( x, y, w, h, iw, ih );

                switch( pMenuItem->m_MenuItemType )
                {
                case MIT_Sprite:
                    {
                        MenuSprite* pMenuSprite = GetMenuSprite( itemindex );

                        cJSONExt_GetFloat( menuitem, "BGShadowX", &pMenuSprite->m_DropShadowOffsetBG_X );
                        cJSONExt_GetFloat( menuitem, "BGShadowY", &pMenuSprite->m_DropShadowOffsetBG_Y );
                    }
                    break;

                case MIT_Text: // MenuText_SaveLoad
                    {
                        MenuText* pMenuText = GetMenuText( itemindex );

                        cJSONExt_GetFloat( menuitem, "FontHeight", &pMenuText->m_FontHeight );
                        cJSONExt_GetFloat( menuitem, "TextShadowX", &pMenuText->m_DropShadowOffsetX );
                        cJSONExt_GetFloat( menuitem, "TextShadowY", &pMenuText->m_DropShadowOffsetY );

                        cJSONExt_GetUnsignedChar( menuitem, "Justify", &pMenuText->m_Justification );
                    }
                    break;

                case MIT_Button:
                    {
                        MenuButton* pMenuButton = GetMenuButton( itemindex );

                        cJSONExt_GetFloat( menuitem, "FontHeight", &pMenuButton->m_FontHeight );
                        cJSONExt_GetFloat( menuitem, "BGShadowX", &pMenuButton->m_DropShadowOffsetBG_X );
                        cJSONExt_GetFloat( menuitem, "BGShadowY", &pMenuButton->m_DropShadowOffsetBG_Y );
                        cJSONExt_GetFloat( menuitem, "TextShadowX", &pMenuButton->m_DropShadowOffsetText_X );
                        cJSONExt_GetFloat( menuitem, "TextShadowY", &pMenuButton->m_DropShadowOffsetText_Y );
                    }
                    break;

                case MIT_Base:
                case MIT_InputBox:
                case MIT_ScrollingText:
                case MIT_ScrollBox:
                case MIT_CheckBox:
                case MIT_NumMenuItemTypes:
                    break;
                }
            }
        }

        cJSON_Delete( menuitemarray );
    }
}
Example #5
0
void Screen_Pause::Init()
{
    Screen_Base::Init();

    for( int i=0; i<m_MenuItemsNeeded; i++ )
        CreateMenuButton( i );

    float fontheight = 30;

    for( int i=0; i<m_MenuItemsNeeded; i++ )
    {
        MenuButton* pButton = GetMenuButton( i );

        MySprite* pWhiteSquare = g_pGame->m_pResources->m_pSprites[SL_WhiteSquare];

        MaterialDefinition* pMatGray = g_pMaterialManager->LoadMaterial( "Data/Materials/Gray.mymaterial" );
        MaterialDefinition* pMatDarkGray = g_pMaterialManager->LoadMaterial( "Data/Materials/DarkGray.mymaterial" );
        MaterialDefinition* pMatShadow = g_pMaterialManager->LoadMaterial( "Data/Materials/Shadow.mymaterial" );
        pButton->SetMaterial( MenuButton::Material_BG, pMatGray );
        pButton->SetMaterial( MenuButton::Material_BGDisabled, pMatGray );
        pButton->SetMaterial( MenuButton::Material_BGOverlay, pMatGray );
        pButton->SetMaterial( MenuButton::Material_BGPressed, pMatDarkGray );
        pButton->SetMaterial( MenuButton::Material_Shadow, pMatShadow );
        pMatGray->Release();
        pMatDarkGray->Release();
        pMatShadow->Release();

        float yspace = fontheight * 2 * 2;

        //pButton->m_pFont = g_pGame->m_pResources->m_pGBResources->m_pFontArial48;
        //pButton->m_Style = MBTS_SingleLine;
        pButton->m_FontHeight = fontheight;
        pButton->SetTextShadow( 3.0f, -3.0f );

        pButton->SetPositionAndSize( 320.0f, 576.0f - i*yspace, g_pGame->m_GameWidth, 77 );
        pButton->m_InputWidth = g_pGame->m_GameWidth;
        pButton->m_InputHeight = yspace;

        pButton->SetBGShadow( 0.0f, 6.0f );

        pButton->m_TextColor = GameMenuButtonColors[MBCT_SelectableText];
        pButton->m_BGColor = GameMenuButtonColors[MBCT_SelectableBG];

        pButton->m_DisabledBGColor = GameMenuButtonColors[MBCT_DisabledBG];
        pButton->m_DisabledTextColor = GameMenuButtonColors[MBCT_DisabledBG];
    }

    int i = 0;

    if( 0 ) //g_pGame->m_GBGameType != GBType_Options )
    {
        GetMenuButton( i )->SetString( "Resume" );
        GetMenuButton( i )->m_ButtonAction[0] = (int)PMA_Resume;
        i++;
    }

    GetMenuButton( i )->SetString( "Achievements" );
    GetMenuButton( i )->m_ButtonAction[0] = (int)PMA_Achievements;
    i++;

    GetMenuButton( i )->SetString( "Stats" );
    GetMenuButton( i )->m_ButtonAction[0] = (int)PMA_Stats;
    i++;

    if( 0 ) //g_pGame->m_GBGameType == GBType_WordPuzzle && g_pGame->m_OnlineMode == false )
    {
        GetMenuButton( i )->SetString( "Level select" );
        GetMenuButton( i )->m_ButtonAction[0] = (int)PMA_LevelSelect;
        i++;
    }

    GetMenuButton( i )->SetString( "How to Play" );
    GetMenuButton( i )->m_ButtonAction[0] = (int)PMA_HowToPlay;
    i++;

    GetMenuButton( i )->SetString( "Back to main menu" );
    GetMenuButton( i )->m_ButtonAction[0] = (int)PMA_MainMenu;
    i++;
}