Exemplo n.º 1
0
Arquivo: Menu.cpp Projeto: 3dik/MPong
//RunEditProfile
bool Menu::RunEditProfile (wstring sName, bool *pbModified)
{
    Err fErr (m_Err, L"RunEditProfile");
    if (sName.empty () || pbModified == NULL)
    {
        return fErr.Set (sERR_ARGUMENTS);
    }

    *pbModified = false;

    Config *pProfile;
    bool bCreated;
    if (!m_pProfiles->GetByName (sName, &pProfile, &bCreated))
    {
        return false;
    }

    wstring sMenuEdit, sLeft, sRight, sSpecial, sSet, sOk, sUndefined;
    if (!m_pLanguage->Get (L"ProfileEditTitle", &sMenuEdit) ||
        !m_pLanguage->Get (L"ProfileEditLeft", &sLeft) ||
        !m_pLanguage->Get (L"ProfileEditRight", &sRight) ||
        !m_pLanguage->Get (L"ProfileEditSpecial", &sSpecial) ||
        !m_pLanguage->Get (L"ProfileEditSet", &sSet) ||
        !m_pLanguage->Get (L"ProfileEditOk", &sOk) ||
        !m_pLanguage->Get (L"ProfileEditUndefined", &sUndefined))
    {
        return false;
    }
    sLeft += L": ";
    sRight += L": ";
    sSpecial += L": ";

    wstring sLeftVal, sRightVal, sSpecialVal;
    if (!pProfile->Get (sKEY_LEFT, &sLeftVal) ||
        !pProfile->Get (sKEY_RIGHT, &sRightVal) ||
        !pProfile->Get (sKEY_SPECIAL, &sSpecialVal))
    {
        return false;
    }

    unsigned int nAction;
    do
    {
        if (sLeftVal.empty ())
        {
            sLeftVal = sUndefined;
        }
        if (sRightVal.empty ())
        {
            sRightVal = sUndefined;
        }
        if (sSpecialVal.empty ())
        {
            sSpecialVal = sUndefined;
        }
        Screen EditScreen;
        if (!EditScreen.Init (&m_Err, m_pProfiles, m_pWindow, sMenuEdit + sName) ||
            !EditScreen.AddLabel (sLeft + sLeftVal, Vector2f (300, 150)) ||
            !EditScreen.AddButton (sSet, Vector2f (50, 140),
                                   eProfileEditButtonLeft) ||
            !EditScreen.AddLabel (sRight + sRightVal, Vector2f (300, 250)) ||
            !EditScreen.AddButton (sSet, Vector2f (50, 240),
                                   eProfileEditButtonRight) ||
            !EditScreen.AddLabel (sSpecial + sSpecialVal,
                                  Vector2f (300, 350)) ||
            !EditScreen.AddButton (sSet, Vector2f (50, 340),
                                   eProfileEditButtonSpecial) ||
            !EditScreen.AddButton (m_sAbort, Vector2f (700, 540),
                                   eProfileEditButtonAbort) ||
            !EditScreen.AddButton (sOk, Vector2f (700, 600),
                                   eProfileEditButtonOk))
        {
            return false;
        }
        if (!EditScreen.Run ())
        {
            return false;
        }
        if (EditScreen.IsQuit ())
        {
            m_bClose = true;
            break;
        }
        if (!EditScreen.GetSelectId (&nAction))
        {
            return false;
        }

        wstring *psCurKey = NULL;
        switch (nAction)
        {
            case (eProfileEditButtonLeft):
                psCurKey = &sLeftVal;
                break;
            case (eProfileEditButtonRight):
                psCurKey = &sRightVal;
                break;
            case (eProfileEditButtonSpecial):
                psCurKey = &sSpecialVal;
                break;
            case (eProfileEditButtonOk):
                pProfile->Set (sKEY_LEFT, sLeftVal);
                pProfile->Set (sKEY_RIGHT, sRightVal);
                pProfile->Set (sKEY_SPECIAL, sSpecialVal);
                if (!pProfile->Save ())
                {
                    return false;
                }
                *pbModified = true;
                nAction = eProfileEditButtonAbort;
                break;
        }

        if (psCurKey != NULL)
        {
            wstring sCode;
            if (!AwaitInput (&sCode))
            {
                return false;
            }
            if (!sCode.empty ())
            {
                *psCurKey = sCode;
            }
        }
    } while (!m_bClose && nAction != eProfileEditButtonAbort);

    return true;
}//RunEditProfile
Exemplo n.º 2
0
Arquivo: Menu.cpp Projeto: 3dik/MPong
//ManageProfileScreens
bool Menu::ManageProfileScreens ()
{
    Err fErr (m_Err, L"ManageProfileScreens");

    Screen Overview;
    if (!InitProfilesScreen (&Overview))
    {
        return false;
    }

    unsigned int nAction;
    do
    {
        if (!Overview.Run ())
        {
            return false;
        }
        if (Overview.IsQuit ())
        {
            m_bClose = true;
            break;
        }
        if (!Overview.GetSelectId (&nAction))
        {
            return false;
        }

        wstring sName;
        if (!Overview.Get (eProfilesListChoice, &sName))
        {
            return false;
        }

        switch (nAction)
        {
            case (eProfilesButtonEdit):
                {
                    bool bModified;
                    if (!RunEditProfile (sName, &bModified))
                    {
                        return false;
                    }
                    if (bModified && !m_pProfiles->Reload ())
                    {
                        return false;
                    }
                }
                break;
            case (eProfilesButtonCreate):
                {
                    wstring sName;
                    if (!Overview.Get (eProfilesEditCreateName, &sName))
                    {
                        return false;
                    }
                    if (sName.empty ())
                    {
                        fErr.Set (L"The given profile name is empty");
                    }
                    if (!AddProfile (sName) ||
                        !InitProfilesScreen (&Overview))
                    {
                        return false;
                    }
                }
                break;
            case (eProfilesButtonDelete):
                if (!m_pProfiles->DeleteProfile (sName) ||
                    !InitProfilesScreen (&Overview))
                {
                    return false;
                }
                break;
        }

        if (!Overview.Reset ())
        {
            return false;
        }
    } while (!m_bClose && nAction != eProfilesButtonAbort);

    return true;
}//ManageProfileScreens