Converted the 'new player' dialog to use XML files
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5742 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
f43d9d4d35
commit
b7fe74141e
@ -54,6 +54,7 @@
|
|||||||
\li \ref widget10
|
\li \ref widget10
|
||||||
\li \ref widget11
|
\li \ref widget11
|
||||||
\li \ref widget12
|
\li \ref widget12
|
||||||
|
\li \ref widget13
|
||||||
|
|
||||||
\ref props
|
\ref props
|
||||||
\li \ref prop1
|
\li \ref prop1
|
||||||
@ -240,6 +241,11 @@
|
|||||||
|
|
||||||
\n
|
\n
|
||||||
|
|
||||||
|
\subsection widget13 WTYPE_TEXTBOX
|
||||||
|
<em> Name in XML files: </em> \c "textbox"
|
||||||
|
|
||||||
|
A text field where the user can type text
|
||||||
|
|
||||||
\n
|
\n
|
||||||
\n
|
\n
|
||||||
\section props Properties
|
\section props Properties
|
||||||
|
@ -139,6 +139,15 @@ void LayoutManager::readCoords(Widget* self, ITopLevelWidgetContainer* topLevelC
|
|||||||
// lines are required, we need to specify a height explicitely
|
// lines are required, we need to specify a height explicitely
|
||||||
label_h = dim.Height + self->getHeightNeededAroundLabel();
|
label_h = dim.Height + self->getHeightNeededAroundLabel();
|
||||||
}
|
}
|
||||||
|
if (self->getType() == WTYPE_TEXTBOX)
|
||||||
|
{
|
||||||
|
IGUIFont* font = (self->m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont());
|
||||||
|
|
||||||
|
// get text height, a text box is always as high as the text it could contain
|
||||||
|
core::dimension2d< u32 > dim = font->getDimension( L"X" );
|
||||||
|
label_h = dim.Height + self->getHeightNeededAroundLabel();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ---- read dimension
|
// ---- read dimension
|
||||||
// width
|
// width
|
||||||
|
@ -55,6 +55,13 @@ ModalDialog::ModalDialog(const float percentWidth, const float percentHeight)
|
|||||||
void ModalDialog::loadFromFile(const char* xmlFile)
|
void ModalDialog::loadFromFile(const char* xmlFile)
|
||||||
{
|
{
|
||||||
IrrXMLReader* xml = irr::io::createIrrXMLReader( (file_manager->getGUIDir() + "/" + xmlFile).c_str() );
|
IrrXMLReader* xml = irr::io::createIrrXMLReader( (file_manager->getGUIDir() + "/" + xmlFile).c_str() );
|
||||||
|
if (xml == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Cannot open file %s\n", xmlFile);
|
||||||
|
assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Screen::parseScreenFileDiv(xml, m_children, m_irrlicht_window);
|
Screen::parseScreenFileDiv(xml, m_children, m_irrlicht_window);
|
||||||
delete xml;
|
delete xml;
|
||||||
|
|
||||||
|
@ -114,6 +114,13 @@ void Screen::loadFromFile()
|
|||||||
assert(m_magic_number == 0xCAFEC001);
|
assert(m_magic_number == 0xCAFEC001);
|
||||||
|
|
||||||
IrrXMLReader* xml = irr::io::createIrrXMLReader( (file_manager->getGUIDir() + "/" + m_filename).c_str() );
|
IrrXMLReader* xml = irr::io::createIrrXMLReader( (file_manager->getGUIDir() + "/" + m_filename).c_str() );
|
||||||
|
if (xml == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Cannot open file %s\n", m_filename.c_str());
|
||||||
|
assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parseScreenFileDiv(xml, m_widgets);
|
parseScreenFileDiv(xml, m_widgets);
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
calculateLayout();
|
calculateLayout();
|
||||||
|
@ -145,9 +145,14 @@ void Screen::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>&
|
|||||||
{
|
{
|
||||||
append_to.push_back(new ListWidget());
|
append_to.push_back(new ListWidget());
|
||||||
}
|
}
|
||||||
|
else if (!strcmp("textbox", xml->getNodeName()))
|
||||||
|
{
|
||||||
|
append_to.push_back(new TextBoxWidget());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "/!\\ Warning /!\\ : unknown tag found in STK GUI file : '" << xml->getNodeName() << "'" << std::endl;
|
std::cerr << "/!\\ Warning /!\\ : unknown tag found in STK GUI file : '"
|
||||||
|
<< xml->getNodeName() << "'" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,59 +34,19 @@ using namespace irr::gui;
|
|||||||
EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
|
EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
|
||||||
ModalDialog(w, h)
|
ModalDialog(w, h)
|
||||||
{
|
{
|
||||||
m_label_ctrl = new LabelWidget();
|
loadFromFile("enter_player_name_dialog.stkgui");
|
||||||
|
|
||||||
//I18N: In the 'add new player' dialog
|
TextBoxWidget* textCtrl = (TextBoxWidget*)Screen::getWidget("textfield", &m_children);
|
||||||
m_label_ctrl->m_text = _("Enter the new player's name");
|
assert(textCtrl != NULL);
|
||||||
|
|
||||||
m_label_ctrl->m_properties[PROP_TEXT_ALIGN] = "center";
|
|
||||||
m_label_ctrl->m_x = 0;
|
|
||||||
m_label_ctrl->m_y = 0;
|
|
||||||
m_label_ctrl->m_w = m_area.getWidth();
|
|
||||||
m_label_ctrl->m_h = m_area.getHeight()/3;
|
|
||||||
m_label_ctrl->setParent(m_irrlicht_window);
|
|
||||||
|
|
||||||
m_children.push_back(m_label_ctrl);
|
|
||||||
m_label_ctrl->add();
|
|
||||||
|
|
||||||
// ----
|
|
||||||
|
|
||||||
//IGUIFont* font = GUIEngine::getFont();
|
|
||||||
const int textHeight = GUIEngine::getFontHeight();
|
|
||||||
|
|
||||||
const int textAreaYFrom = m_area.getHeight()/2 - textHeight/2;
|
|
||||||
|
|
||||||
textCtrl = new TextBoxWidget();
|
|
||||||
textCtrl->m_text = "";
|
|
||||||
textCtrl->m_x = 50;
|
|
||||||
textCtrl->m_y = textAreaYFrom - 10;
|
|
||||||
textCtrl->m_w = m_area.getWidth()-100;
|
|
||||||
textCtrl->m_h = textHeight + 5;
|
|
||||||
textCtrl->setParent(m_irrlicht_window);
|
|
||||||
m_children.push_back(textCtrl);
|
|
||||||
textCtrl->add();
|
|
||||||
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||||
|
|
||||||
// TODO : add Ok button
|
|
||||||
|
|
||||||
cancelButton = new ButtonWidget();
|
|
||||||
cancelButton->m_properties[PROP_ID] = "cancel";
|
|
||||||
cancelButton->m_text = _("Cancel");
|
|
||||||
cancelButton->m_x = 15;
|
|
||||||
cancelButton->m_y = m_area.getHeight() - textHeight - 12;
|
|
||||||
cancelButton->m_w = m_area.getWidth() - 30;
|
|
||||||
cancelButton->m_h = textHeight + 6;
|
|
||||||
cancelButton->setParent(m_irrlicht_window);
|
|
||||||
|
|
||||||
m_children.push_back(cancelButton);
|
|
||||||
cancelButton->add();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
EnterPlayerNameDialog::~EnterPlayerNameDialog()
|
EnterPlayerNameDialog::~EnterPlayerNameDialog()
|
||||||
{
|
{
|
||||||
|
// FIXME: what is this code for?
|
||||||
|
TextBoxWidget* textCtrl = (TextBoxWidget*)Screen::getWidget("textfield", &m_children);
|
||||||
textCtrl->getIrrlichtElement()->remove();
|
textCtrl->getIrrlichtElement()->remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +54,7 @@ EnterPlayerNameDialog::~EnterPlayerNameDialog()
|
|||||||
|
|
||||||
GUIEngine::EventPropagation EnterPlayerNameDialog::processEvent(const std::string& eventSource)
|
GUIEngine::EventPropagation EnterPlayerNameDialog::processEvent(const std::string& eventSource)
|
||||||
{
|
{
|
||||||
if(eventSource == "cancel")
|
if (eventSource == "cancel")
|
||||||
{
|
{
|
||||||
dismiss();
|
dismiss();
|
||||||
return GUIEngine::EVENT_BLOCK;
|
return GUIEngine::EVENT_BLOCK;
|
||||||
@ -108,6 +68,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
|||||||
{
|
{
|
||||||
// ---- Cancel button pressed
|
// ---- Cancel button pressed
|
||||||
const int playerID = 0; // FIXME: don't hardcode player 0?
|
const int playerID = 0; // FIXME: don't hardcode player 0?
|
||||||
|
ButtonWidget* cancelButton = (ButtonWidget*)Screen::getWidget("cancel", &m_children);
|
||||||
if (GUIEngine::isFocusedForPlayer(cancelButton, playerID))
|
if (GUIEngine::isFocusedForPlayer(cancelButton, playerID))
|
||||||
{
|
{
|
||||||
std::string fakeEvent = "cancel";
|
std::string fakeEvent = "cancel";
|
||||||
@ -116,13 +77,15 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---- Otherwise, accept entered name
|
// ---- Otherwise, accept entered name
|
||||||
|
TextBoxWidget* textCtrl = (TextBoxWidget*)Screen::getWidget("textfield", &m_children);
|
||||||
stringw playerName = textCtrl->getText();
|
stringw playerName = textCtrl->getText();
|
||||||
if (playerName.size() > 0)
|
if (playerName.size() > 0)
|
||||||
{
|
{
|
||||||
const bool success = OptionsScreenPlayers::getInstance()->gotNewPlayerName( playerName );
|
const bool success = OptionsScreenPlayers::getInstance()->gotNewPlayerName( playerName );
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
m_label_ctrl->setText(_("Cannot add a player with this name."));
|
LabelWidget* label = (LabelWidget*)Screen::getWidget("title", &m_children);
|
||||||
|
label->setText(_("Cannot add a player with this name."));
|
||||||
sfx_manager->quickSound( "use_anvil" );
|
sfx_manager->quickSound( "use_anvil" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@ namespace GUIEngine
|
|||||||
|
|
||||||
class EnterPlayerNameDialog : public GUIEngine::ModalDialog
|
class EnterPlayerNameDialog : public GUIEngine::ModalDialog
|
||||||
{
|
{
|
||||||
GUIEngine::LabelWidget* m_label_ctrl;
|
//GUIEngine::LabelWidget* m_label_ctrl;
|
||||||
GUIEngine::TextBoxWidget* textCtrl;
|
//GUIEngine::TextBoxWidget* textCtrl;
|
||||||
GUIEngine::ButtonWidget* cancelButton;
|
//GUIEngine::ButtonWidget* cancelButton;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user