Made Widget::m_text private and provided setter/getter functions

instead. The setter will automatically also set the corresponding
text in an irrlicht widget (if the irrlicht widget exists at that time).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5769 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-08-24 23:07:13 +00:00
parent 58e0671f9f
commit 433e1f42e2
18 changed files with 98 additions and 70 deletions

View File

@ -113,6 +113,14 @@ Widget::~Widget()
m_magic_number = 0xDEADBEEF;
}
// -----------------------------------------------------------------------------
void Widget::setText(const wchar_t *s)
{
m_text = s;
if(m_element)
m_element->setText(s);
} // setText
// -----------------------------------------------------------------------------
void Widget::elementRemoved()

View File

@ -112,6 +112,11 @@ namespace GUIEngine
*/
class Widget : public SkinWidgetContainer
{
private:
/** PROP_TEXT is a special case : since it can be translated it can't
* go in the map above, which uses narrow strings */
irr::core::stringw m_text;
protected:
unsigned int m_magic_number;
@ -335,9 +340,17 @@ namespace GUIEngine
/** A map that holds values for all specified widget properties (in the XML file)*/
std::map<Property, std::string> m_properties;
/** PROP_TEXT is a special case : since it can be transalted it can't go in the map above, which
uses narrow strings */
irr::core::stringw m_text;
/** Sets the text of a widget from a wchar_t. Handy for many constant
* strings used in stk. */
virtual void setText(const wchar_t *s);
/** Sets the text of a widget from a stringw. This uses the virtual
* setText(wchar_t*) function, so only that function needs to be
* overwritten by other classes. */
void setText(const irr::core::stringw &s) { setText(s.c_str()); }
/** Returns the text of a widget. */
const irr::core::stringw &getText() const {return m_text; }
static void resetIDCounters();

View File

@ -31,7 +31,7 @@ ButtonWidget::ButtonWidget() : Widget(WTYPE_BUTTON)
void ButtonWidget::add()
{
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
stringw& message = m_text;
const stringw& message = getText();
m_element = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, getNewID(), message.c_str(), L"");
m_id = m_element->getID();
@ -41,10 +41,10 @@ void ButtonWidget::add()
// -----------------------------------------------------------------------------
void ButtonWidget::setLabel(irr::core::stringw label)
void ButtonWidget::setLabel(const irr::core::stringw &label)
{
m_element->setText( label.c_str() );
m_text = label;
setText(label);
}
// -----------------------------------------------------------------------------

View File

@ -52,7 +52,7 @@ namespace GUIEngine
void add();
/** Change the label on the button */
void setLabel(const irr::core::stringw label);
void setLabel(const irr::core::stringw &label);
};
}

View File

@ -102,7 +102,7 @@ void IconButtonWidget::add()
m_id = m_element->getID();
// ---- label if any
stringw& message = m_text;
const stringw& message = getText();
if (message.size() > 0)
{
//std::cout << "Adding label of icon widget, m_properties[PROP_EXTEND_LABEL] = " << m_properties[PROP_EXTEND_LABEL] << std::endl;

View File

@ -24,21 +24,24 @@ using namespace GUIEngine;
using namespace irr::core;
using namespace irr::gui;
// -----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/** Constructs the label widget. Parameter:
* \param title True if the special title font should be used.
*/
LabelWidget::LabelWidget(bool title) : Widget(WTYPE_LABEL)
{
m_title_font = title;
m_has_color = false;
}
// -----------------------------------------------------------------------------
} // LabelWidget
// ----------------------------------------------------------------------------
/** Adds the stk widget to the irrlicht widget set.
*/
void LabelWidget::add()
{
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
const bool word_wrap = m_properties[PROP_WORD_WRAP] == "true";
stringw& message = m_text;
const stringw& message = getText();
EGUI_ALIGNMENT align = EGUIA_UPPERLEFT;
if (m_properties[PROP_TEXT_ALIGN] == "center") align = EGUIA_CENTER;
@ -66,12 +69,6 @@ void LabelWidget::add()
//m_element->setTabOrder(id);
m_element->setTabStop(false);
m_element->setTabGroup(false);
}
// -----------------------------------------------------------------------------
void LabelWidget::setText(stringw newText)
{
IGUIStaticText* irrwidget = Widget::getIrrlichtElement<IGUIStaticText>();
irrwidget->setText(newText.c_str());
} // add
m_text = newText;
}
// ----------------------------------------------------------------------------

View File

@ -41,14 +41,13 @@ namespace GUIEngine
void add();
/** Change the text in the label */
void setText(irr::core::stringw newText);
/** Sets the color of the widget.
* \param color The color to use for this widget. */
void setColor(const irr::video::SColor& color)
{
m_color = color;
m_has_color = true;
}
} // setColor
};
}

View File

@ -34,7 +34,7 @@ void TextBoxWidget::add()
{
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
stringw& text = m_text;
const stringw& text = getText();
m_element = GUIEngine::getGUIEnv()->addEditBox(text.c_str(), widget_size,
true /* border */, m_parent, getNewID());
m_id = m_element->getID();

View File

@ -228,13 +228,13 @@ void CreditsScreen::loadedFromFile()
std::vector<irr::core::stringw> translator = StringUtils::split(_("translator-credits"), '\n');
m_sections.push_back( new CreditsSection("Launchpad translations"));
for(int i = 1; i < translator.size(); i = i + 4)
for(unsigned int i = 1; i < translator.size(); i = i + 4)
{
line = stringw("Translations");
CreditsEntry entry(line);
getCurrentSection()->addEntry( entry );
for(int j = 0; i + j < translator.size() && j < 4; j ++)
for(unsigned int j = 0; i + j < translator.size() && j < 4; j ++)
{
getCurrentSection()->addSubEntry(translator[i + j]);
}

View File

@ -57,9 +57,10 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.7f, 0.7f)
widget->m_properties[PROP_ID] = "addkeyboard";
//I18N: In the 'add new input device' dialog
widget->m_text = _("Add Keyboard Configuration");
widget->setText( _("Add Keyboard Configuration") );
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
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;
@ -72,9 +73,10 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.7f, 0.7f)
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "cancel";
widget->m_text = _("Cancel");
widget->setText( _("Cancel") );
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
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;

View File

@ -97,7 +97,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
}
LabelWidget* widget = new LabelWidget();
widget->m_text = lineText;
widget->setText(lineText);
widget->m_x = 20;
widget->m_y = from_y;
widget->m_w = m_area.getWidth()/2 - 20;
@ -141,12 +141,12 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
if (gp_ok)
{
okBtn->m_properties[PROP_ID] = "start";
okBtn->m_text = _("Start Grand Prix");
okBtn->setText(_("Start Grand Prix"));
}
else
{
okBtn->m_properties[PROP_ID] = "cannot_start";
okBtn->m_text = _("This Grand Prix is broken!");
okBtn->setText(_("This Grand Prix is broken!"));
okBtn->setBadge(BAD_BADGE);
}

View File

@ -55,7 +55,7 @@ void PlayerInfoDialog::showRegularDialog()
{
textCtrl = new TextBoxWidget();
textCtrl->m_properties[PROP_ID] = "renameplayer";
textCtrl->m_text = m_player->getName();
textCtrl->setText(m_player->getName());
textCtrl->m_x = 50;
textCtrl->m_y = y1 - textHeight/2;
textCtrl->m_w = m_area.getWidth()-100;
@ -70,9 +70,9 @@ void PlayerInfoDialog::showRegularDialog()
widget->m_properties[PROP_ID] = "renameplayer";
//I18N: In the player info dialog
widget->m_text = _("Rename");
widget->setText( _("Rename") );
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
const int textWidth = font->getDimension( widget->getText().c_str() ).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = y2;
@ -85,9 +85,10 @@ void PlayerInfoDialog::showRegularDialog()
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "cancel";
widget->m_text = _("Cancel");
widget->setText( _("Cancel") );
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
const int textWidth =
font->getDimension(widget->getText().c_str()).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = y3;
@ -103,9 +104,10 @@ void PlayerInfoDialog::showRegularDialog()
widget->m_properties[PROP_ID] = "removeplayer";
//I18N: In the player info dialog
widget->m_text = _("Remove");
widget->setText( _("Remove"));
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
const int textWidth =
font->getDimension(widget->getText().c_str()).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = y4;
@ -149,9 +151,10 @@ void PlayerInfoDialog::showConfirmDialog()
widget->m_properties[PROP_ID] = "confirmremove";
//I18N: In the player info dialog (when deleting)
widget->m_text = _("Confirm Remove");
widget->setText( _("Confirm Remove") );
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
const int textWidth =
font->getDimension(widget->getText().c_str()).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = m_area.getHeight()/2;
@ -167,9 +170,10 @@ void PlayerInfoDialog::showConfirmDialog()
widget->m_properties[PROP_ID] = "cancelremove";
//I18N: In the player info dialog (when deleting)
widget->m_text = _("Cancel Remove");
widget->setText( _("Cancel Remove") );
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
const int textWidth =
font->getDimension( widget->getText().c_str() ).Width + 40;
widget->m_x = m_area.getWidth()/2 - textWidth/2;
widget->m_y = m_area.getHeight()*3/4;

View File

@ -340,7 +340,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
unlocked_label->m_y = label_y;
unlocked_label->m_w = m_area.getWidth() - button_h*2 - 60;
unlocked_label->m_h = button_h;
unlocked_label->m_text = _("You unlocked a new feature!");
unlocked_label->setText( _("You unlocked a new feature!") );
unlocked_label->setParent(m_irrlicht_window);
m_widgets.push_back(unlocked_label);
unlocked_label->add();
@ -352,7 +352,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_h = button_h;
whats_next_btn->setParent(m_irrlicht_window);
whats_next_btn->m_text = _("See unlocked features");
whats_next_btn->setText( _("See unlocked features") );
whats_next_btn->m_properties[PROP_ID] = "seeunlocked";
m_widgets.push_back(whats_next_btn);
@ -368,7 +368,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
new_race_btn->m_y = m_area.getHeight() - (button_h + margin_between_buttons)*3;
new_race_btn->m_w = m_area.getWidth() - 30;
new_race_btn->m_h = button_h;
new_race_btn->m_text = _("Setup New Race");
new_race_btn->setText( _("Setup New Race") );
new_race_btn->setParent(m_irrlicht_window);
m_widgets.push_back(new_race_btn);
new_race_btn->add();
@ -379,7 +379,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
race_again_btn->m_y = m_area.getHeight() - (button_h + margin_between_buttons)*2;
race_again_btn->m_w = m_area.getWidth() - 30;
race_again_btn->m_h = button_h;
race_again_btn->m_text = _("Race in this track again");
race_again_btn->setText( _("Race in this track again") );
race_again_btn->setParent(m_irrlicht_window);
m_widgets.push_back(race_again_btn);
race_again_btn->add();
@ -391,7 +391,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_h = button_h;
whats_next_btn->setParent(m_irrlicht_window);
whats_next_btn->m_text = _("Back to the main menu");
whats_next_btn->setText( _("Back to the main menu") );
whats_next_btn->m_properties[PROP_ID] = "backtomenu";
m_widgets.push_back(whats_next_btn);
@ -408,7 +408,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_h = button_h;
whats_next_btn->setParent(m_irrlicht_window);
whats_next_btn->m_text = _("Continue Grand Prix");
whats_next_btn->setText( _("Continue Grand Prix") );
whats_next_btn->m_properties[PROP_ID] = "continuegp";
m_widgets.push_back(whats_next_btn);
@ -423,7 +423,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
abort_gp->m_y = m_area.getHeight() - (button_h + margin_between_buttons);
abort_gp->m_w = m_area.getWidth() - 30;
abort_gp->m_h = button_h;
abort_gp->m_text = _("Abort Grand Prix");
abort_gp->setText( _("Abort Grand Prix") );
abort_gp->setParent(m_irrlicht_window);
m_widgets.push_back(abort_gp);
abort_gp->add();

View File

@ -120,7 +120,7 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
m_spinner->m_properties[PROP_MAX_VALUE] = "99";
//I18N: In the track setup screen (number of laps choice, where %i is the number)
m_spinner->m_text = _("%i laps");
m_spinner->setText( _("%i laps") );
m_widgets.push_back(m_spinner);
m_spinner->add();
@ -136,7 +136,7 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
// ---- Start button
ButtonWidget* okBtn = new ButtonWidget();
okBtn->m_properties[PROP_ID] = "start";
okBtn->m_text = _("Start Race");
okBtn->setText( _("Start Race") );
okBtn->m_x = m_area.getWidth()/2 - 200;
okBtn->m_y = y3;
okBtn->m_w = 400;

View File

@ -440,6 +440,10 @@ void FeatureUnlockedCutScene::onUpdate(float dt,
message_y -= (fontH + MARGIN);
}
}
printf("camera: %f %f %f\n",
m_camera->getPosition().X,
m_camera->getPosition().Y,
m_camera->getPosition().Z);
} // onUpdate
// ----------------------------------------------------------------------------

View File

@ -123,7 +123,7 @@ void GrandPrixWin::init()
unlocked_label->m_y = y_from;
unlocked_label->m_w = message_width;
unlocked_label->m_h = label_height;
unlocked_label->m_text = message;
unlocked_label->setText(message);
//const irr::video::SColor orange(255, 255, 126, 21);
//unlocked_label->setColor(orange);

View File

@ -241,9 +241,10 @@ public:
m_player_ID_label = new LabelWidget();
m_player_ID_label->m_text =
m_player_ID_label->setText(
//I18N: In kart selection screen (Will read like 'Player 1 (foobartech gamepad)')
StringUtils::insertValues(_("Player %i (%s)"), m_playerID + 1, deviceName.c_str());
StringUtils::insertValues(_("Player %i (%s)"), m_playerID + 1, deviceName.c_str())
);
m_player_ID_label->m_properties[PROP_TEXT_ALIGN] = "center";
m_player_ID_label->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_label", m_playerID);
@ -305,7 +306,7 @@ public:
// ---- Kart name label
m_kart_name = new LabelWidget();
m_kart_name->m_text = props->getName();
m_kart_name->setText(props->getName());
m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center";
m_kart_name->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_kartname", m_playerID);
m_kart_name->m_x = kart_name_x;

View File

@ -146,14 +146,14 @@ void RaceSetupScreen::onGameModeChanged()
kartamount->setDeactivated();
// dirty trick to hide the number inside the spinner (FIXME)
kartamount->m_text = L"-";
kartamount->setText(L"-");
kartamount->setValue( kartamount->getValue() );
}
else
{
kartamount->setActivated();
kartamount->m_text = L"";
kartamount->setText(L"");
kartamount->setValue( kartamount->getValue() );
}
}
@ -169,7 +169,7 @@ void RaceSetupScreen::init()
SpinnerWidget* kartamount = getWidget<SpinnerWidget>("aikartamount");
kartamount->setActivated();
kartamount->m_text = L""; // FIXME: dirty trick (see below)
kartamount->setText(L""); // FIXME: dirty trick (see below)
kartamount->setValue( race_manager->getNumberOfKarts() - race_manager->getNumPlayers() );
DynamicRibbonWidget* w2 = getWidget<DynamicRibbonWidget>("gamemode");