Allowed renaming players
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3665 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -200,7 +200,6 @@ void EnterPlayerNameDialog::processEvent(std::string& eventSource)
|
||||
{
|
||||
if(eventSource == "cancel")
|
||||
{
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
@@ -220,7 +219,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
||||
if(playerName.size() > 0)
|
||||
StateManager::gotNewPlayerName( playerName );
|
||||
|
||||
// irrLicht is to stupid to remove focus from deleted widgets
|
||||
// irrLicht is too stupid to remove focus from deleted widgets
|
||||
// so do it by hand
|
||||
GUIEngine::getGUIEnv()->removeFocus( textCtrl->m_element );
|
||||
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
|
||||
@@ -319,6 +318,8 @@ void TrackInfoDialog::onEnterPressedInternal()
|
||||
|
||||
PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h) : ModalDialog(w, h)
|
||||
{
|
||||
m_player = player;
|
||||
|
||||
const int y1 = m_area.getHeight()/4;
|
||||
const int y2 = m_area.getHeight()*2/4;
|
||||
const int y3 = m_area.getHeight()*3/4;
|
||||
@@ -328,25 +329,25 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
|
||||
const int buttonHeight = textHeight + 10;
|
||||
|
||||
{
|
||||
TextBoxWidget* widget = new TextBoxWidget();
|
||||
widget->m_type = WTYPE_BUTTON;
|
||||
widget->m_properties[PROP_ID] = "renameplayer";
|
||||
widget->m_properties[PROP_TEXT] = player->getName();
|
||||
widget->x = 50;
|
||||
widget->y = y1 - textHeight/2;
|
||||
widget->w = m_area.getWidth()-100;
|
||||
widget->h = textHeight + 5;
|
||||
widget->setParent(m_irrlicht_window);
|
||||
m_children.push_back(widget);
|
||||
widget->add();
|
||||
GUIEngine::getGUIEnv()->setFocus( widget->m_element );
|
||||
textCtrl = new TextBoxWidget();
|
||||
textCtrl->m_type = WTYPE_BUTTON;
|
||||
textCtrl->m_properties[PROP_ID] = "renameplayer";
|
||||
textCtrl->m_properties[PROP_TEXT] = player->getName();
|
||||
textCtrl->x = 50;
|
||||
textCtrl->y = y1 - textHeight/2;
|
||||
textCtrl->w = m_area.getWidth()-100;
|
||||
textCtrl->h = textHeight + 5;
|
||||
textCtrl->setParent(m_irrlicht_window);
|
||||
m_children.push_back(textCtrl);
|
||||
textCtrl->add();
|
||||
GUIEngine::getGUIEnv()->setFocus( textCtrl->m_element );
|
||||
}
|
||||
|
||||
{
|
||||
ButtonWidget* widget = new ButtonWidget();
|
||||
widget->m_type = WTYPE_BUTTON;
|
||||
widget->m_properties[PROP_ID] = "renameplayer";
|
||||
widget->m_properties[PROP_TEXT] = _("Rename"); // TODO : catch events
|
||||
widget->m_properties[PROP_TEXT] = _("Rename");
|
||||
|
||||
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
|
||||
|
||||
@@ -363,7 +364,7 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
|
||||
ButtonWidget* widget = new ButtonWidget();
|
||||
widget->m_type = WTYPE_BUTTON;
|
||||
widget->m_properties[PROP_ID] = "removeplayer";
|
||||
widget->m_properties[PROP_TEXT] = _("Remove"); // TODO : catch events
|
||||
widget->m_properties[PROP_TEXT] = _("Remove");
|
||||
|
||||
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
|
||||
|
||||
@@ -379,6 +380,33 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
|
||||
void PlayerInfoDialog::onEnterPressedInternal()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerInfoDialog::processEvent(std::string& eventSource)
|
||||
{
|
||||
if(eventSource == "renameplayer")
|
||||
{
|
||||
// accept entered name
|
||||
stringw playerName = textCtrl->getText();
|
||||
if(playerName.size() > 0)
|
||||
{
|
||||
StateManager::gotNewPlayerName( playerName, m_player );
|
||||
}
|
||||
|
||||
// irrLicht is too stupid to remove focus from deleted widgets
|
||||
// so do it by hand
|
||||
GUIEngine::getGUIEnv()->removeFocus( textCtrl->m_element );
|
||||
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
|
||||
|
||||
ModalDialog::dismiss();
|
||||
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
if(eventSource == "removeplayer")
|
||||
{
|
||||
// TODO
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,6 +94,8 @@ public:
|
||||
|
||||
class PlayerInfoDialog : public ModalDialog
|
||||
{
|
||||
TextBoxWidget* textCtrl;
|
||||
Player* m_player;
|
||||
public:
|
||||
/**
|
||||
* Creates a modal dialog with given percentage of screen width and height
|
||||
@@ -101,6 +103,7 @@ public:
|
||||
PlayerInfoDialog(Player* PlayerInfoDialog,
|
||||
const float percentWidth, const float percentHeight);
|
||||
void onEnterPressedInternal();
|
||||
void processEvent(std::string& eventSource);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -516,15 +516,36 @@ namespace StateManager
|
||||
input_manager->getDeviceList()->serialize();
|
||||
}
|
||||
|
||||
void gotNewPlayerName(const stringw& newName)
|
||||
/**
|
||||
* Adds a new player (if 'player' is NULL) or renames an existing player (if 'player' is not NULL)
|
||||
*/
|
||||
void gotNewPlayerName(const stringw& newName, Player* player)
|
||||
{
|
||||
stringc newNameC( newName );
|
||||
|
||||
UserConfigParams::m_player.push_back( new Player(newNameC.c_str()) );
|
||||
|
||||
ListWidget* players = getCurrentScreen()->getWidget<ListWidget>("players");
|
||||
if(players != NULL)
|
||||
if(players == NULL) return;
|
||||
|
||||
// ---- Add new player
|
||||
if(player == NULL)
|
||||
{
|
||||
UserConfigParams::m_player.push_back( new Player(newNameC.c_str()) );
|
||||
|
||||
players->addItem( newNameC.c_str() );
|
||||
}
|
||||
else // ---- Rename existing player
|
||||
{
|
||||
player->setName( newNameC.c_str() );
|
||||
|
||||
// refresh list display
|
||||
players->clear();
|
||||
const int playerAmount = UserConfigParams::m_player.size();
|
||||
for(int n=0; n<playerAmount; n++)
|
||||
{
|
||||
players->addItem(UserConfigParams::m_player[n].getName());
|
||||
}
|
||||
|
||||
}
|
||||
// TODO : need to re-save user config here?
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace StateManager
|
||||
|
||||
void menuEventOptions(GUIEngine::Widget* widget, const std::string& name);
|
||||
void gotSensedInput(Input* sensedInput);
|
||||
void gotNewPlayerName(const irr::core::stringw& newName);
|
||||
void gotNewPlayerName(const irr::core::stringw& newName, Player* player=NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1311,6 +1311,14 @@ void ListWidget::add()
|
||||
m_element = GUIEngine::getGUIEnv()->addListBox (widget_size, m_parent, ++id_counter);
|
||||
}
|
||||
|
||||
void ListWidget::clear()
|
||||
{
|
||||
IGUIListBox* list = dynamic_cast<IGUIListBox*>(m_element);
|
||||
assert(list != NULL);
|
||||
|
||||
list->clear();
|
||||
}
|
||||
|
||||
void ListWidget::addItem(const char* item)
|
||||
{
|
||||
IGUIListBox* list = dynamic_cast<IGUIListBox*>(m_element);
|
||||
|
||||
@@ -367,6 +367,7 @@ namespace GUIEngine
|
||||
|
||||
int getSelection() const;
|
||||
std::string getSelectionName() const;
|
||||
void clear();
|
||||
};
|
||||
|
||||
class TextBoxWidget : public Widget
|
||||
|
||||
Reference in New Issue
Block a user