AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f)
{    
    ScalableFont* font = GUIEngine::getFont();
    const int textHeight = GUIEngine::getFontHeight();
    const int buttonHeight = textHeight + 10;
    
    const int y_bottom = m_area.getHeight() - 2*(buttonHeight + 10) - 10;

    core::rect<s32> text_area( 15, 15, m_area.getWidth()-15, y_bottom-15 );
    
    IGUIStaticText* b = GUIEngine::getGUIEnv()->addStaticText( _("To add a new Gamepad/Joystick device, simply start SuperTuxKart with it connected and it will appear in the list.\n\nTo add a keyboard config, you can use the button below, HOWEVER please note that most keyboards only support a limited amount of simultaneous keypresses and are thus inappropriate for multiplayer gameplay. (You can, however, connect multiple keyboards to the computer. Remember that everyone still needs different keybindings in this case.)"),
                                                              text_area, false , true , // border, word warp
                                                              m_irrlicht_window);
    b->setTabStop(false);
    
       
    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "addkeyboard";
        
        //I18N: In the 'add new input device' dialog
        widget->setText( _("Add Keyboard Configuration") );
        
        const int textWidth = 
            font->getDimension( widget->getText().c_str() ).Width + 40;
        
        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = y_bottom;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
    }
    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "cancel";
        widget->setText( _("Cancel") );
        
        const int textWidth = 
            font->getDimension( widget->getText().c_str() ).Width + 40;
        
        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = y_bottom + buttonHeight + 10;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
        
        widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER );    

    }
    
}
/** Show the current data of this player.
 */
void PlayerInfoDialog::showRegularDialog()
{
    if (m_irrlicht_window)
        clearWindow();

    const int y1 = m_area.getHeight()/6;
    const int y2 = m_area.getHeight()*2/6;
    const int y3 = m_area.getHeight()*3/6;
    const int y4 = m_area.getHeight()*5/6;

    ScalableFont* font = GUIEngine::getFont();
    const int textHeight = GUIEngine::getFontHeight();
    const int buttonHeight = textHeight + 10;

    {
        textCtrl = new TextBoxWidget();
        textCtrl->m_properties[PROP_ID] = "newname";
        textCtrl->setText(m_player->getName());
        textCtrl->m_x = 50;
        textCtrl->m_y = y1 - textHeight/2;
        textCtrl->m_w = m_area.getWidth()-100;
        textCtrl->m_h = textHeight + 5;
        textCtrl->setParent(m_irrlicht_window);
        m_widgets.push_back(textCtrl);
        textCtrl->add();
    }

    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "renameplayer";

        //I18N: In the player info dialog
        widget->setText( _("Rename") );

        const int textWidth = 
                    font->getDimension( widget->getText().c_str() ).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = y2;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
    }
    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "cancel";
        widget->setText( _("Cancel") );

        const int textWidth =
            font->getDimension(widget->getText().c_str()).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = y3;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
    }

    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "removeplayer";

        //I18N: In the player info dialog
        widget->setText( _("Remove"));

        const int textWidth =
            font->getDimension(widget->getText().c_str()).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = y4;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
    }

    textCtrl->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
}   // showRegularDialog
Beispiel #3
0
AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f)
{
    doInit();

    ScalableFont* font = GUIEngine::getFont();
    const int textHeight = GUIEngine::getFontHeight();
    const int buttonHeight = textHeight + 10;

#ifdef ENABLE_WIIUSE
    const int nbButtons = 3;
#else
    const int nbButtons = 2;
#endif

    const int y_bottom = m_area.getHeight() - nbButtons*(buttonHeight + 10) - 10;
    const int y_stride = buttonHeight+10;
    int cur_y = y_bottom;

    core::rect<s32> text_area( 15, 15, m_area.getWidth()-15, y_bottom-15 );

    core::stringw msg =
        _("To add a new Gamepad/Joystick device, simply start SuperTuxKart "
          "with it connected and it will appear in the list.\n\nTo add a "
          "keyboard config, you can use the button below, HOWEVER please "
          "note that most keyboards only support a limited amount of "
          "simultaneous keypresses and are thus inappropriate for multiplayer "
          "gameplay. (You can, however, connect multiple keyboards to the "
          "computer. Remember that everyone still needs different keybindings "
          "in this case.)");
    IGUIStaticText* b =
        GUIEngine::getGUIEnv()->addStaticText(msg.c_str(),
                                              text_area,
                                              /*border*/false ,
                                              /*word wrap*/true,
                                              m_irrlicht_window);
    b->setTabStop(false);
    b->setRightToLeft(translations->isRTLLanguage());
    // because it looks like 'setRightToLeft' applies next time
    // setText is called only
    b->setText(msg.c_str());

#ifdef ENABLE_WIIUSE
    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "addwiimote";

        //I18N: In the 'add new input device' dialog
        widget->setText( _("Add Wiimote") );

        const int textWidth =
            font->getDimension( widget->getText().c_str() ).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = cur_y;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
        cur_y += y_stride;
    }
#endif  // ENABLE_WIIUSE

    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "addkeyboard";

        //I18N: In the 'add new input device' dialog
        widget->setText( _("Add Keyboard Configuration") );

        const int textWidth =
            font->getDimension( widget->getText().c_str() ).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = cur_y;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
        cur_y += y_stride;
    }
    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "cancel";
        widget->setText( _("Cancel") );

        const int textWidth =
            font->getDimension( widget->getText().c_str() ).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = cur_y;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
        cur_y += y_stride;

        widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER );

    }

}   // AddDeviceDialog
Beispiel #4
0
    // -----------------------------------------------------------------------
    void init(IrrlichtDevice* device_a, IVideoDriver* driver_a, 
              AbstractStateManager* state_manager )
    {       
        g_env = device_a->getGUIEnvironment();
        g_device = device_a;
        g_driver = driver_a;
        g_state_manager = state_manager;
        
        for (int n=0; n<MAX_PLAYER_COUNT; n++)
        {
            g_focus_for_player[n] = NULL;
        }
        
        /*
         To make the g_font a little bit nicer, we load an external g_font
         and set it as the new default g_font in the g_skin.
         To keep the standard g_font for tool tip text, we set it to
         the built-in g_font.
         */
        try
        {
            g_skin = new Skin(g_env->getSkin());
            g_env->setSkin(g_skin);
            g_skin->drop(); // GUI env grabbed it
            assert(g_skin->getReferenceCount() == 1);
        }
        catch (std::runtime_error& err)
        {
            (void)err;   // avoid warning about unused variable
            std::cerr << 
                "ERROR, cannot load skin specified in user config. Falling "
                "back to defaults.\n";
            UserConfigParams::m_skin_file.revertToDefaults();
            
            try
            {
                g_skin = new Skin(g_env->getSkin());
                g_env->setSkin(g_skin);
                g_skin->drop(); // GUI env grabbed it
                assert(g_skin->getReferenceCount() == 1);
            }
            catch (std::runtime_error& err)
            {
                std::cerr << "FATAL, cannot load default GUI skin\n";
                throw err;
            }
        }
        
        // font size is resolution-dependent.
        // normal text will range from 0.8, in 640x* resolutions (won't scale
        // below that) to 1.0, in 1024x* resolutions, and linearly up
        // normal text will range from 0.2, in 640x* resolutions (won't scale
        // below that) to 0.4, in 1024x* resolutions, and linearly up
        const int screen_width = irr_driver->getFrameSize().Width;
        const float normal_text_scale = 
            0.7f + 0.2f*std::max(0, screen_width - 640)/564.0f;
        const float title_text_scale = 
            0.2f + 0.2f*std::max(0, screen_width - 640)/564.0f;
        
        ScalableFont* sfont = 
            new ScalableFont(g_env,
                            file_manager->getFontFile("StkFont.xml").c_str());
        sfont->setScale(normal_text_scale);
        sfont->setKerningHeight(-5);
        g_font = sfont;
        
        ScalableFont* digit_font =
            new ScalableFont(g_env,
                             file_manager->getFontFile("BigDigitFont.xml").c_str());
        digit_font->lazyLoadTexture(0); // make sure the texture is loaded for this one
        g_digit_font = digit_font;
        
        Private::font_height = g_font->getDimension( L"X" ).Height;
        
        ScalableFont* sfont_smaller = sfont->getHollowCopy();
        sfont_smaller->setScale(normal_text_scale*0.8f);
        sfont_smaller->setKerningHeight(-5);
        g_small_font = sfont_smaller;
        
        Private::small_font_height = 
            g_small_font->getDimension( L"X" ).Height;
        
        
        ScalableFont* sfont2 = 
            new ScalableFont(g_env, 
                          file_manager->getFontFile("title_font.xml").c_str());
        sfont2->m_fallback_font = sfont;
        // Because the fallback font is much smaller than the title font:
        sfont2->m_fallback_font_scale = 4.0f; 
        sfont2->m_fallback_kerning_width = 15;
        sfont2->setScale(title_text_scale);
        sfont2->setKerningWidth(-18);
        sfont2->m_black_border = true;
        g_title_font = sfont2;
        Private::title_font_height = 
            g_title_font->getDimension( L"X" ).Height;

        
        if (g_font != NULL) g_skin->setFont(g_font);
        
        // set event receiver
        g_device->setEventReceiver(EventHandler::get());
        
        g_device->getVideoDriver()
                ->beginScene(true, true, video::SColor(255,100,101,140));
        renderLoading();
        g_device->getVideoDriver()->endScene();
    }   // init