Esempio n. 1
0
// -----------------------------------------------------------------------------
EnterGPNameDialog::~EnterGPNameDialog()
{
    // FIXME: what is this code for?
    TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
    textCtrl->getIrrlichtElement()->remove();
    textCtrl->clearListeners();
}
Esempio n. 2
0
// -----------------------------------------------------------------------------
EnterGPNameDialog::EnterGPNameDialog(INewGPListener* listener,
    const float w, const float h)
    : ModalDialog(w, h), m_listener(listener), m_self_destroy(false)
{
    assert(listener != NULL);
    loadFromFile("enter_gp_name_dialog.stkgui");

    TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
    assert(textCtrl != NULL);
    textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
Esempio n. 3
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");
    }
}
Esempio n. 4
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);
    }
}