Added rename functionality.
This commit is contained in:
parent
737c8a9983
commit
0be01a5977
@ -39,7 +39,8 @@ using namespace irr::gui;
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
EnterPlayerNameDialog::EnterPlayerNameDialog(INewPlayerListener* listener,
|
||||
const float w, const float h) :
|
||||
const float w, const float h,
|
||||
const core::stringw &name):
|
||||
ModalDialog(w, h)
|
||||
{
|
||||
m_listener = listener;
|
||||
@ -48,9 +49,14 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(INewPlayerListener* listener,
|
||||
|
||||
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||
assert(text_field != NULL);
|
||||
text_field->setText(name);
|
||||
text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
if(name!=L"")
|
||||
m_original_player = PlayerManager::get()->getPlayer(name);
|
||||
else
|
||||
m_original_player = NULL;
|
||||
|
||||
std::string username = "";
|
||||
core::stringw username = name;
|
||||
|
||||
// If there is no player (i.e. first start of STK), try to pick
|
||||
// a good default name
|
||||
@ -120,10 +126,16 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, add the new player.
|
||||
PlayerManager::get()->addNewPlayer(player_name);
|
||||
PlayerManager::get()->save();
|
||||
|
||||
if(m_original_player)
|
||||
{
|
||||
m_original_player->setName(player_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Finally, add the new player.
|
||||
PlayerManager::get()->addNewPlayer(player_name);
|
||||
PlayerManager::get()->save();
|
||||
}
|
||||
// It's unsafe to delete from inside the event handler so we do it
|
||||
// in onUpdate (which checks for m_self_destroy)
|
||||
m_self_destroy = true;
|
||||
|
@ -31,11 +31,13 @@ namespace GUIEngine
|
||||
class LabelWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Dialog that allows the player to enter the name for a new player
|
||||
class PlayerProfile;
|
||||
|
||||
/** Dialog that allows the player to enter the name for a new player or
|
||||
* rename an existing player.
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class EnterPlayerNameDialog : public GUIEngine::ModalDialog//, public GUIEngine::ITextBoxWidgetListener
|
||||
class EnterPlayerNameDialog : public GUIEngine::ModalDialog
|
||||
{
|
||||
|
||||
public:
|
||||
@ -51,6 +53,10 @@ private:
|
||||
|
||||
INewPlayerListener* m_listener;
|
||||
bool m_self_destroy;
|
||||
|
||||
/** Pointer to the original PlayerProfile if it's a rename, or NULL if it
|
||||
* is a new player. */
|
||||
PlayerProfile *m_original_player;
|
||||
|
||||
public:
|
||||
|
||||
@ -58,7 +64,7 @@ public:
|
||||
* Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
EnterPlayerNameDialog(INewPlayerListener* listener, const float percentWidth,
|
||||
const float percentHeight);
|
||||
const float percentHeight, const core::stringw &name="");
|
||||
~EnterPlayerNameDialog();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
|
@ -254,6 +254,10 @@ void UserScreen::eventCallback(Widget* widget,
|
||||
}
|
||||
else if (button == "rename")
|
||||
{
|
||||
PlayerProfile *cp = getSelectedPlayer();
|
||||
new EnterPlayerNameDialog(this, 0.5f, 0.4f, cp->getName());
|
||||
// Init will automatically be called, which
|
||||
// refreshes the player list
|
||||
}
|
||||
else if (button == "delete")
|
||||
{
|
||||
@ -392,7 +396,6 @@ void UserScreen::deletePlayer()
|
||||
} // onConfirm
|
||||
}; // ConfirmServer
|
||||
|
||||
|
||||
new MessageDialog(message, MessageDialog::MESSAGE_DIALOG_CONFIRM,
|
||||
new ConfirmServer(), true);
|
||||
} // deletePlayer
|
||||
|
Loading…
Reference in New Issue
Block a user