예제 #1
0
// -----------------------------------------------------------------------------
void EnterGPNameDialog::onEnterPressedInternal()
{
    //Cancel button pressed
    ButtonWidget* cancelButton = getWidget<ButtonWidget>("cancel");
    if (GUIEngine::isFocusedForPlayer(cancelButton, PLAYER_ID_GAME_MASTER))
    {
        std::string fakeEvent = "cancel";
        processEvent(fakeEvent);
        return;
    }

    //Otherwise, see if we can accept the new name
    TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
    assert(textCtrl != NULL);
    stringw name = textCtrl->getText().trim();
    if (name.size() > 0)
    {
        // check for duplicate names
        for (int i = 0; i < grand_prix_manager->getNumberOfGrandPrix(); i++)
        {
            const GrandPrixData* gp = grand_prix_manager->getGrandPrix(i);
            if (gp->getName() == name)
            {
                LabelWidget* label = getWidget<LabelWidget>("title");
                assert(label != NULL);
                label->setText(_("Another grand prix with this name already exists."), false);
                sfx_manager->quickSound("anvil");
                return;
            }
        }

        // It's unsafe to delete from inside the event handler so we do it
        // in onUpdate (which checks for m_self_destroy)
        m_self_destroy = true;
    }
    else
    {
        LabelWidget* label = getWidget<LabelWidget>("title");
        assert(label != NULL);
        label->setText(_("Cannot add a grand prix with this name"), false);
        sfx_manager->quickSound("anvil");
    }
}
예제 #2
0
// -----------------------------------------------------------------------------
void EnterGPNameDialog::onUpdate(float dt)
{
    // It's unsafe to delete from inside the event handler so we do it here
    if (m_self_destroy)
    {
        TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
        stringw name = textCtrl->getText().trim();

        // irrLicht is too stupid to remove focus from deleted widgets
        // so do it by hand
        GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
        GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );

        // we will destroy the dialog before notifying the listener to be safer.
        // but in order not to crash we must make a local copy of the listern
        // otherwise we will crash
        INewGPListener* listener = m_listener;

        ModalDialog::dismiss();

        if (listener != NULL)
            listener->onNewGPWithName(name);
    }
}