From 23192bfe212ca37b14d9a9b5a8e338a5343f2832 Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 28 Jun 2009 20:46:20 +0000 Subject: [PATCH] Allowed deleting players git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3666 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/gui/modaldialog.cpp | 11 +++++++++-- src/gui/options_screen.cpp | 18 ++++++++++++++++++ src/gui/options_screen.hpp | 4 ++-- src/utils/ptr_vector.hpp | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/gui/modaldialog.cpp b/src/gui/modaldialog.cpp index 266c7beba..36e3421dc 100644 --- a/src/gui/modaldialog.cpp +++ b/src/gui/modaldialog.cpp @@ -403,8 +403,15 @@ void PlayerInfoDialog::processEvent(std::string& eventSource) } if(eventSource == "removeplayer") { - // TODO - dismiss(); + StateManager::deletePlayer( 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(); + return; } } diff --git a/src/gui/options_screen.cpp b/src/gui/options_screen.cpp index dfacb1281..586123acd 100644 --- a/src/gui/options_screen.cpp +++ b/src/gui/options_screen.cpp @@ -548,6 +548,24 @@ namespace StateManager // TODO : need to re-save user config here? } + void deletePlayer(Player* player) + { + UserConfigParams::m_player.erase(player); + + // refresh list display + ListWidget* players = getCurrentScreen()->getWidget("players"); + if(players == NULL) return; + players->clear(); + + const int playerAmount = UserConfigParams::m_player.size(); + for(int n=0; naddItem(UserConfigParams::m_player[n].getName()); + } + + // TODO : need to re-save user config here? + } + // ----------------------------------------------------------------------------- // main call (from StateManager); dispatches the call to a specialissed function as needed void menuEventOptions(Widget* widget, const std::string& name) diff --git a/src/gui/options_screen.hpp b/src/gui/options_screen.hpp index 64d011b5b..b12a82195 100644 --- a/src/gui/options_screen.hpp +++ b/src/gui/options_screen.hpp @@ -31,11 +31,11 @@ struct Input; namespace StateManager { - void menuEventOptions(GUIEngine::Widget* widget, const std::string& name); + void gotSensedInput(Input* sensedInput); void gotNewPlayerName(const irr::core::stringw& newName, Player* player=NULL); - + void deletePlayer(Player* player); } #endif diff --git a/src/utils/ptr_vector.hpp b/src/utils/ptr_vector.hpp index 1bb9d77e7..068633699 100644 --- a/src/utils/ptr_vector.hpp +++ b/src/utils/ptr_vector.hpp @@ -191,6 +191,9 @@ void clearWithoutDeleting() contentsVector.clear(); } +/** + * Removes without deleting + */ void remove(TYPE* obj) { for(unsigned int n=0; n