Exemplo n.º 1
0
// ----------------------------------------------------------------------------
void CreateServerScreen::serverCreationRequest()
{
    const irr::core::stringw name = m_name_widget->getText().trim();
    const int max_players = m_max_players_widget->getValue();
    m_info_widget->setErrorColor();
    if (name.size() < 4 || name.size() > 30)
    {
        m_info_widget->setText(_("Name has to be between 4 and 30 characters long!"), false);
    }
    else if (max_players < 2 || max_players > 12)
    {
        m_info_widget->setText(_("The maxinum number of players has to be between 2 and 12."), false);
    }
    else
    {

        m_server_creation_request = new ServerCreationRequest();
        CurrentUser::setUserDetails(m_server_creation_request);
        m_server_creation_request->addParameter("action", "create_server");
        m_server_creation_request->addParameter("name", name);
        m_server_creation_request->addParameter("max_players", max_players);
        m_server_creation_request->queue();

        return;
    }
    sfx_manager->quickSound("anvil");
}
Exemplo n.º 2
0
/** In case of WAN it adds the server to the list of servers. In case of LAN
 *  networking, it registers this game server with the stk server.
 */
void CreateServerScreen::createServer()
{
    const irr::core::stringw name = m_name_widget->getText().trim();
    const int max_players = m_max_players_widget->getValue();
    m_info_widget->setErrorColor();
    if (name.size() < 4 || name.size() > 30)
    {
        m_info_widget->setText(
            _("Name has to be between 4 and 30 characters long!"), false);
        SFXManager::get()->quickSound("anvil");
        return;
    }
    else if (max_players < 2 || max_players > 12)
    {
        m_info_widget->setText(
            _("The maxinum number of players has to be between 2 and 12."),
            false);
        SFXManager::get()->quickSound("anvil");
        return;
    }

    // In case of a LAN game, we can create the new server object now
    if (NetworkConfig::get()->isLAN())
    {
        // FIXME Is this actually necessary?? Only in case of WAN, or LAN and WAN?
        TransportAddress address(0x7f000001,0);  // 127.0.0.1
        Server *server = new Server(name, /*lan*/true, max_players,
                                    /*current_player*/1, address);
        ServersManager::get()->addServer(server);
    }

    // In case of a WAN game, we register this server with the
    // stk server, and will get the server's id when this 
    // request is finished.
    NetworkConfig::get()->setMaxPlayers(max_players);
    NetworkConfig::get()->setServerName(name);

    // FIXME: Add the following fields to the create server screen
    // FIXME: Long term we might add a 'vote' option (e.g. GP vs single race,
    // and normal vs FTL vs time trial could be voted about).
    race_manager->setDifficulty(RaceManager::convertDifficulty("hard"));
    race_manager->setMajorMode(RaceManager::MAJOR_MODE_SINGLE);
    race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
    race_manager->setReverseTrack(false);
    STKHost::create();

}   // createServer
Exemplo n.º 3
0
void ButtonWidget::setLabel(const irr::core::stringw &label)
{
    // This method should only be called AFTER a widget is added
    assert(m_element != NULL);

    m_element->setText( label.c_str() );
    setText(label);
}
Exemplo n.º 4
0
// -----------------------------------------------------------------------------
void RibbonWidget::setLabel(const int id, irr::core::stringw new_name)
{
    if (m_labels.size() == 0) return; // ignore this call for ribbons without labels
    
    assert(id >= 0);
    assert(id < m_labels.size());
    m_labels[id].setText( new_name.c_str() );
    m_text = new_name;
}
Exemplo n.º 5
0
/** Checks if the input string is not empty. ( = has characters different
 *  from a space).
 */
bool notEmpty(const irr::core::stringw& input)
{
    const int size = input.size();
    int nonEmptyChars = 0;
    for (int n=0; n<size; n++)
    {
        if (input[n] != L' ')
        {
            nonEmptyChars++;
        }
    }
    return (nonEmptyChars > 0);
}   // getExtension
Exemplo n.º 6
0
// -----------------------------------------------------------------------------
void ListWidget::renameCell(const int row_index, const int col_index, const irr::core::stringw newName, const int icon)
{
    // May only be called AFTER this widget has been add()ed
    assert(m_element != NULL);

    CGUISTKListBox* list = getIrrlichtElement<CGUISTKListBox>();
    assert(list != NULL);

    list->setCell(row_index, col_index, newName.c_str(), icon);

    list->setItemOverrideColor( row_index, EGUI_LBC_TEXT          , video::SColor(255,0,0,0) );
    list->setItemOverrideColor( row_index, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,255,255) );
}
/**
 * \param original Message to translate
 * \param context  Optional, can be set to differentiate 2 strings that are identical
 *                 in English but could be different in other languages
 */
const wchar_t* Translations::w_gettext(const char* original, const char* context)
{
    if (original[0] == '\0') return L"";

#if TRANSLATE_VERBOSE
    Log::info("Translations", "Translating %s", original);
#endif

    const std::string& original_t = (context == NULL ?
                                     m_dictionary.translate(original) :
                                     m_dictionary.translate_ctxt(context, original));

    if (original_t == original)
    {
        static irr::core::stringw converted_string;
        converted_string = StringUtils::utf8ToWide(original);

#if TRANSLATE_VERBOSE
        std::wcout << L"  translation : " << converted_string << std::endl;
#endif
        return converted_string.c_str();
    }

    // print
    //for (int n=0;; n+=4)

    static core::stringw original_tw;
    original_tw = StringUtils::utf8ToWide(original_t);

    const wchar_t* out_ptr = original_tw.c_str();
    if (REMOVE_BOM) out_ptr++;

#if TRANSLATE_VERBOSE
    std::wcout << L"  translation : " << out_ptr << std::endl;
#endif

    return out_ptr;
}
Exemplo n.º 8
0
void FeatureUnlockedCutScene::addUnlockedPicture(irr::video::ITexture* picture,
                                                 float w, float h,
                                                 irr::core::stringw msg)
{
    if (picture == NULL)
    {
        Log::warn("FeatureUnlockedCutScene::addUnlockedPicture", "Unlockable has no picture: %s",
            core::stringc(msg.c_str()).c_str());
        picture = irr_driver->getTexture(file_manager->getAsset(FileManager::GUI,"main_help.png"));

    }

    m_unlocked_stuff.push_back( new UnlockedThing(picture, w, h, msg) );
}   // addUnlockedPicture
Exemplo n.º 9
0
void FeatureUnlockedCutScene::addUnlockedPicture(irr::video::ITexture* picture,
                                                 float w, float h,
                                                 irr::core::stringw msg)
{
    if (picture == NULL)
    {
        std::cerr << "[FeatureUnlockedCutScene::addUnlockedPicture] WARNING: unlockable has no picture : "
                  << core::stringc(msg.c_str()).c_str() << "\n";
        picture = irr_driver->getTexture(file_manager->getAsset(FileManager::GUI,"main_help.png"));

    }

    m_unlocked_stuff.push_back( new UnlockedThing(picture, w, h, msg) );
}   // addUnlockedPicture
Exemplo n.º 10
0
void SpinnerWidget::setValue(irr::core::stringw new_value)
{
    const int size = (int)m_labels.size();
    for (int n=0; n<size; n++)
    {
        if (m_labels[n] == new_value)
        {
            setValue(n);
            return;
        }
    }

    Log::fatal("SpinnerWidget::setValue", "Cannot find element named '%s'",
        irr::core::stringc(new_value.c_str()).c_str());
}
Exemplo n.º 11
0
void SpinnerWidget::setValue(irr::core::stringw new_value)
{
    const int size = (int)m_labels.size();
    for (int n=0; n<size; n++)
    {
        if (m_labels[n] == new_value)
        {
            setValue(n);
            return;
        }
    }

    std::cerr << "ERROR [SpinnerWidget::setValue] : cannot find element named '"
              <<  irr::core::stringc(new_value.c_str()).c_str() << "'\n";
    assert(false);
}
    /** Splits a string into substrings separated by a certain character, and
     *  returns a std::vector of all those substring. E.g.:
     *  split("a b=c d=e",' ')  --> ["a", "b=c", "d=e"]
     *  This is the version for wide strings.
     *  \param s The string to split.
     *  \param c The character  by which the string is split.
     */
    std::vector<irr::core::stringw> split(const irr::core::stringw& s, char c,
                                           bool keepSplitChar)
    {
        try
        {
            std::vector<irr::core::stringw> result;

            irr::s32 start = 0;
            while (start < (irr::s32)s.size())
            {
                irr::s32 i = s.findNext(c, start);
                if (i != -1)
                {
                    if (keepSplitChar)
                    {
                        int from = start-1;
                        if (from < 0) from = 0;
                        result.push_back( s.subString(from, i-from) );
                    }
                    else result.push_back( s.subString(start, i-start) );
                    start = i+1;
                }
                else
                {
                    if (keepSplitChar)
                        result.push_back( s.subString(start - 1,
                                                      s.size()-start + 1) );
                    else
                        result.push_back( s.subString(start, s.size()-start) );

                    return result;
                    //start = i+1;
                }
            }
            return result;
        }
        catch (std::exception& e)
        {
            (void)e;  // avoid warning about unused variable
            Log::fatal("StringUtils",
                       "Fatal error in split(stringw) : %s @ line %i : '%s'.",
                       __FILE__, __LINE__, e.what());
            exit(1);
        }
    }   // split
Exemplo n.º 13
0
/** Converts a unicode string to plain ASCII using XML entites (e.g. &x00;)
 *  \param s The input string which should be encoded.
 *  \return A std:;string with ASCII characters.
 */
std::string xmlEncode(const irr::core::stringw &s)
{
    std::ostringstream output;
    for(unsigned int i=0; i<s.size(); i++)
    {
        if (s[i] >= 128 || s[i] == '&' || s[i] == '<' || s[i] == '>' || s[i] == '\"')
        {
            output << "&#x" << std::hex << std::uppercase << s[i] << ";";
        }
        else
        {
            irr::c8 c = (char)(s[i]);
            output << c;
        }
    }
    return output.str();
}   // xmlEncode
Exemplo n.º 14
0
// ----------------------------------------------------------------------------
void RibbonWidget::setLabel(const unsigned int id, irr::core::stringw new_name)
{
    if (m_element == NULL)
    {
        // before adding
        m_children[id].setText(new_name);
    }
    else
    {
        // after adding
        // ignore this call for ribbons without labels
        if (m_labels.size() == 0) return;

        assert(id < m_labels.size());
        m_labels[id].setText(new_name.c_str());
        //m_text = new_name;
    }
}   // setLabel
 /** Converts a unicode string to plain ASCII using html-like & codes.
  *  \param s The input string which should be encoded.
  *  \return A std:;string with ASCII characters.
  */
 std::string encodeToHtmlEntities(const irr::core::stringw &s)
 {
     std::ostringstream output;
     for(unsigned int i=0; i<s.size(); i++)
     {
         if(s[i]=='&')
             output<<"&amp;";
         else
         {
             if(s[i]<128)
             {
                 irr::c8 c=(char)(s[i]);
                 output<<c;
             }
             else
             {
                 output <<"&#x" << std::hex <<std::uppercase<< s[i]<<";";
             }
         }
     }
     return output.str();
 }   // encodeToHtmlEntities
void MessageDialog::doInit(irr::core::stringw msg, MessageDialogType type,
                           IConfirmDialogListener* listener, bool own_listener)
{
    loadFromFile("confirm_dialog.stkgui");

    m_listener = listener;
    m_own_listener = own_listener;
    
    LabelWidget* message = getWidget<LabelWidget>("title");
    message->setText( msg.c_str(), false );

    // If the dialog is a simple 'OK' dialog, then hide the "Yes" button and
    // change "Cancel" to "OK"
    if (type == MessageDialog::MESSAGE_DIALOG_OK)
    {
        ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm");
        yesbtn->setVisible(false);

        ButtonWidget* cancelbtn = getWidget<ButtonWidget>("cancel");
        cancelbtn->setText(_("OK"));
        cancelbtn->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
    }
}
Exemplo n.º 17
0
 /** Returns the description of this achievement. */
 irr::core::stringw getDescription() const { return _(m_description.c_str()); }
Exemplo n.º 18
0
 /** Returns the name of this achievement. */
 irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
Exemplo n.º 19
0
std::string stringw_to_stdstring(irr::core::stringw sw)
{
    std::stringstream ss;
        ss << sw.c_str();
        return ss.str();
}
Exemplo n.º 20
0
void ListWidget::selectItemWithLabel(const irr::core::stringw& name)
{
    CGUISTKListBox* list = getIrrlichtElement<CGUISTKListBox>();
    assert(list != NULL);
    return list->setSelectedByCellText( name.c_str() );
}
Exemplo n.º 21
0
// ----------------------------------------------------------------------------
void KartSelectionScreen::updateKartWidgetModel(int widget_id,
                const std::string& selection,
                const irr::core::stringw& selectionText)
{
    // Update the displayed model
    ModelViewWidget* w3 = m_kart_widgets[widget_id].m_model_view;
    assert( w3 != NULL );

    if (selection == RANDOM_KART_ID)
    {
        // Random kart
        scene::IMesh* model =
            ItemManager::getItemModel(Item::ITEM_BONUS_BOX);

        w3->clearModels();
        w3->addModel( model, Vec3(0.0f, -12.0f, 0.0f),
                      Vec3(35.0f, 35.0f, 35.0f) );
        w3->update(0);
        m_kart_widgets[widget_id].m_kart_name
        ->setText( _("Random Kart"), false );
    }
    // selection contains the name of the kart, so check only for substr
    else if (StringUtils::startsWith(selection, ID_LOCKED) && !m_multiplayer)
    {
        w3->clearModels();
        w3->addModel(irr_driver->getAnimatedMesh(
                         file_manager->getAsset(FileManager::MODEL, "chest.b3d") )->getMesh(20),
                     Vec3(0,0,0), Vec3(15.0f, 15.0f, 15.0f) );
        w3->update(0);

        if (m_multiplayer)
        {
            m_kart_widgets[widget_id].m_kart_name
            ->setText(_("Locked"), false );
        }
        else
        {
            m_kart_widgets[widget_id].m_kart_name
            ->setText(_("Locked : solve active challenges to gain access to more!"), false );
        }
    }
    else
    {
        const KartProperties *kp =
            kart_properties_manager->getKart(selection);
        if (kp != NULL)
        {
            const KartModel &kart_model = kp->getMasterKartModel();

            float scale = 35.0f;
            if (kart_model.getLength() > 1.45f)
            {
                // if kart is too long, size it down a bit so that it fits
                scale = 30.0f;
            }

            w3->clearModels();
            w3->addModel( kart_model.getModel(), Vec3(0,0,0),
                Vec3(scale, scale, scale),
                          kart_model.getBaseFrame() );
            w3->addModel( kart_model.getWheelModel(0),
                          kart_model.getWheelGraphicsPosition(0) );
            w3->addModel( kart_model.getWheelModel(1),
                          kart_model.getWheelGraphicsPosition(1) );
            w3->addModel( kart_model.getWheelModel(2),
                          kart_model.getWheelGraphicsPosition(2) );
            w3->addModel( kart_model.getWheelModel(3),
                          kart_model.getWheelGraphicsPosition(3) );
            for (size_t i = 0; i < kart_model.getSpeedWeightedObjectsCount(); i++)
            {
                const SpeedWeightedObject&  obj = kart_model.getSpeedWeightedObject((int)i);
                w3->addModel(obj.m_model, obj.m_position);
            }
            //w3->update(0);

            m_kart_widgets[widget_id].m_kart_name
            ->setText( selectionText.c_str(), false );
        }
        else
            Log::warn("KartSelectionScreen", "could not "
                      "find a kart named '%s'",
                      selection.c_str());
    }
}
Exemplo n.º 22
0
 bool               isRTLText(const irr::core::stringw &str) { return isRTLText(str.c_str()); }
 /** 
   * Sets the text of a widget from a stringw.
   * \note This method uses the virtual setText(wchar_t*) function, so only the latter
   *       needs to be overwritten by other classes.
   * \note Not all widgets use strings, so some widgets may ignore this text property
   * \note Changing the text property will only take effect the next time this widget
   *       is add()ed
   */
 virtual void setText(const irr::core::stringw &s) { setText(s.c_str()); }
Exemplo n.º 24
0
void ProgressBarWidget::setLabel(irr::core::stringw label)
{
    m_element->setText( label.c_str() );
    m_text = label;
}
Exemplo n.º 25
0
 // ------------------------------------------------------------------------
 const irr::core::stringw
       getChallengeDescription() const 
                               {return _(m_challenge_description.c_str()); }
Exemplo n.º 26
0
 /** Returns the name of the challenge. */
 const irr::core::stringw getName() const
                           { return irr::core::stringw(_(m_name.c_str())); }
Exemplo n.º 27
0
TrackInfoDialog::TrackInfoDialog(const std::string& ribbonItem, const std::string& trackIdent,
                                 const irr::core::stringw& trackName, ITexture* screenshot,
                                 const float w, const float h) : ModalDialog(w, h)
{
    loadFromFile("track_info_dialog.stkgui");

    const bool has_laps       = race_manager->modeHasLaps();
    const bool has_highscores = race_manager->modeHasHighscores();

    m_track_ident = trackIdent;
    m_ribbon_item = ribbonItem;

    getWidget<LabelWidget>("name")->setText(trackName.c_str(), false);

    Track* track = track_manager->getTrack(trackIdent);
    //I18N: when showing who is the author of track '%s' (place %s where the name of the author should appear)
    getWidget<LabelWidget>("author")->setText( _("Track by %s", track->getDesigner().c_str()), false );


    // ---- Track screenshot
    Widget* screenshot_div = getWidget("screenshot_div");
    IconButtonWidget* screenshotWidget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO,
                                                              false /* tab stop */, false /* focusable */);
    // images are saved squared, but must be stretched to 4:
    screenshotWidget->setCustomAspectRatio(4.0f / 3.0f);

    screenshotWidget->m_x = screenshot_div->m_x;
    screenshotWidget->m_y = screenshot_div->m_y;
    screenshotWidget->m_w = screenshot_div->m_w;
    screenshotWidget->m_h = screenshot_div->m_h;

    // temporary icon, will replace it just after (but it will be shown if the given icon is not found)
    screenshotWidget->m_properties[PROP_ICON] = "gui/main_help.png";
    screenshotWidget->setParent(m_irrlicht_window);
    screenshotWidget->add();

    if (screenshot != NULL)
    {
        screenshotWidget->setImage(screenshot);
    }
    m_widgets.push_back(screenshotWidget);


    // ---- Lap count m_spinner
    if (has_laps)
    {
        m_spinner = getWidget<SpinnerWidget>("lapcountspinner");

        m_spinner->m_properties[PROP_ID] = "lapcountspinner";
        if (UserConfigParams::m_artist_debug_mode)
        {
            m_spinner->setMin(0);
        }

        //I18N: In the track setup screen (number of laps choice, where %i is the number)
        //m_spinner->setText( _("%i laps") );
        m_spinner->setValue( UserConfigParams::m_num_laps );
        //m_spinner->getIrrlichtElement()->setTabStop(true);
        //m_spinner->getIrrlichtElement()->setTabGroup(false);

        const int num_laps = m_spinner->getValue();
        race_manager->setNumLaps(num_laps);
    }
    else
    {
        getWidget<SpinnerWidget>("lapcountspinner")->setVisible(false);
        m_spinner = NULL;
    }


    // Reverse track
    const bool reverse_available = track->reverseAvailable() &&
               race_manager->getMinorMode() != RaceManager::MINOR_MODE_EASTER_EGG;
    if (reverse_available)
    {
        m_checkbox = getWidget<CheckBoxWidget>("reverse");
        m_checkbox->setState(race_manager->getReverseTrack());
    }
    else
    {
        getWidget<CheckBoxWidget>("reverse")->setVisible(false);
        getWidget<LabelWidget>("reverse-text")->setVisible(false);
        m_checkbox = NULL;
        race_manager->setReverseTrack(false);
    }

    // ---- High Scores
    if (has_highscores)
    {
        m_kart_icons[0] = getWidget<IconButtonWidget>("iconscore1");
        m_kart_icons[1] = getWidget<IconButtonWidget>("iconscore2");
        m_kart_icons[2] = getWidget<IconButtonWidget>("iconscore3");

        m_highscore_entries[0] = getWidget<LabelWidget>("highscore1");
        m_highscore_entries[1] = getWidget<LabelWidget>("highscore2");
        m_highscore_entries[2] = getWidget<LabelWidget>("highscore3");

        updateHighScores();

    }
    else
    {
        getWidget<IconButtonWidget>("iconscore1")->setVisible(false);
        getWidget<IconButtonWidget>("iconscore2")->setVisible(false);
        getWidget<IconButtonWidget>("iconscore3")->setVisible(false);

        getWidget<LabelWidget>("highscores")->setVisible(false);
        getWidget<LabelWidget>("highscore1")->setVisible(false);
        getWidget<LabelWidget>("highscore2")->setVisible(false);
        getWidget<LabelWidget>("highscore3")->setVisible(false);
    }

    getWidget<ButtonWidget>("start")->setFocusForPlayer( PLAYER_ID_GAME_MASTER );

}   // TrackInfoDialog
Exemplo n.º 28
0
/** Sets an error message for the gui.
 */
void STKHost::setErrorMessage(const irr::core::stringw &message)
{
    irr::core::stringc s(message.c_str());
    Log::error("STKHost", "%s", s.c_str());
    m_error_message = message;
}   // setErrorMessage
    // ------------------------------------------------------------------------
    irr::core::stringw insertValues(const irr::core::stringw &s,
                                    std::vector<irr::core::stringw>& all_vals)
    {
        try
        {
            unsigned int insertValID = 0;

            const std::vector<irr::core::stringw> sv =
                                              StringUtils::split(s, '%', true);

            irr::core::stringw new_string="";

            const unsigned int size = sv.size();
            for (unsigned int i=0; i<size; i++)
            {
                if(sv[i][0] != '%')
                {
                    new_string += sv[i];
                }
                else
                {
                    if (sv[i][1]=='s' || sv[i][1]=='d' || sv[i][1]=='i')
                    {
                        if (insertValID >= all_vals.size())
                        {
                            Log::warn("StringUtils", "insertValues: "
                                      "Invalid number of arguments in '%s'\n",
                                      irr::core::stringc(s.c_str()).c_str());
                            new_string += "??";
                            new_string += sv[i].subString(2, sv[i].size()-2);
                        }
                        else
                        {
                            new_string += all_vals[insertValID].c_str();
                            new_string += sv[i].subString(2, sv[i].size()-2);
                        }
                        insertValID++;
                    }
                    else if(irr::core::isdigit(sv[i][1]))
                    {
                        irr::core::stringw rest =
                                            sv[i].subString(2, sv[i].size()-2);
                        int delta = 0;

                        if (sv[i].size() >= 4 && sv[i][2]=='$')
                        {
                            rest = sv[i].subString(4, sv[i].size()-4);
                            delta = -1;
                        }

                        const unsigned int index =
                                 irr::core::stringc(sv[i].c_str()).c_str()[1]
                                 - '0' + delta;
                        if (index >= all_vals.size())
                        {
                            Log::warn("StringUtils", "insertValues: "
                                      "Invalid argument ID in '%s' : %i\n",
                                      irr::core::stringc(s.c_str()).c_str(),
                                      index);
                            new_string += "??";
                            new_string += rest;
                        }
                        else
                        {
                            new_string += all_vals[index] + rest;
                        }
                    }
                    else
                    {
                        new_string+=sv[i];
                    }
                }
            }
            return new_string;
        }
        catch (std::exception& e)
        {
            (void)e;  // avoid warning about unused variable
            Log::fatal("StringUtils",
                       "Fatal error in insertValues(stringw) : %s @ line %i.",
                       __FILE__, __LINE__);
            exit(1);
        }
    }