diff --git a/data/gui/online/splitscreen_player_dialog.stkgui b/data/gui/online/splitscreen_player_dialog.stkgui index cb00675a9..4fbcf1973 100644 --- a/data/gui/online/splitscreen_player_dialog.stkgui +++ b/data/gui/online/splitscreen_player_dialog.stkgui @@ -8,16 +8,16 @@
-
-
+
-
diff --git a/src/network/network_config.hpp b/src/network/network_config.hpp index 7da7ac33b..bcd97c5f8 100644 --- a/src/network/network_config.hpp +++ b/src/network/network_config.hpp @@ -201,6 +201,16 @@ public: return true; } // ------------------------------------------------------------------------ + bool playerExists(PlayerProfile* profile) const + { + for (auto& p : m_network_players) + { + if (std::get<1>(p) == profile) + return true; + } + return false; + } + // ------------------------------------------------------------------------ void cleanNetworkPlayers() { m_network_players.clear(); diff --git a/src/states_screens/dialogs/splitscreen_player_dialog.cpp b/src/states_screens/dialogs/splitscreen_player_dialog.cpp index be6750813..668ba831d 100644 --- a/src/states_screens/dialogs/splitscreen_player_dialog.cpp +++ b/src/states_screens/dialogs/splitscreen_player_dialog.cpp @@ -24,6 +24,11 @@ #include "guiengine/dialog_queue.hpp" #include "guiengine/engine.hpp" #include "guiengine/message_queue.hpp" +#include "guiengine/widgets/check_box_widget.hpp" +#include "guiengine/widgets/icon_button_widget.hpp" +#include "guiengine/widgets/label_widget.hpp" +#include "guiengine/widgets/ribbon_widget.hpp" +#include "guiengine/widgets/spinner_widget.hpp" #include "network/network_config.hpp" #include "states_screens/networking_lobby.hpp" #include "utils/translation.hpp" @@ -38,17 +43,21 @@ void SplitscreenPlayerDialog::beforeAddingWidgets() { m_profiles = getWidget("name-spinner"); for (unsigned i = 0; i < PlayerManager::get()->getNumPlayers(); i++) - m_profiles->addLabel(PlayerManager::get()->getPlayer(i)->getName()); + { + PlayerProfile* p = PlayerManager::get()->getPlayer(i); + if (!NetworkConfig::get()->playerExists(p)) + { + m_profiles->addLabel(p->getName()); + m_available_players.push_back(p); + } + } m_message = getWidget("message-label"); - + assert(m_message != NULL); m_handicap = getWidget("handicap"); - m_handicap->setState(false); - m_handicap->setActive(UserConfigParams::m_per_player_difficulty); - + assert(m_handicap != NULL); m_options_widget = getWidget("options"); assert(m_options_widget != NULL); - m_add = getWidget("add"); assert(m_add != NULL); m_connect = getWidget("connect"); @@ -58,6 +67,29 @@ void SplitscreenPlayerDialog::beforeAddingWidgets() m_reset = getWidget("reset"); assert(m_reset != NULL); + if (NetworkConfig::get()->getNetworkPlayers().size() == MAX_PLAYER_COUNT) + { + m_available_players.clear(); + } + if (m_available_players.empty()) + { + getWidget("name-text")->setVisible(false); + getWidget("handicap-row")->setVisible(false); + m_add->setVisible(false); + m_profiles->setVisible(false); + m_connect->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + } + else + { + getWidget("name-text")->setVisible(true); + getWidget("handicap-row")->setVisible(true); + m_add->setVisible(true); + m_profiles->setVisible(true); + m_add->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + m_handicap->setState(false); + m_handicap->setActive(UserConfigParams::m_per_player_difficulty); + } + input_manager->getDeviceManager()->setAssignMode(NO_ASSIGN); input_manager->getDeviceManager()->mapFireToSelect(false); @@ -75,7 +107,7 @@ GUIEngine::EventPropagation { const unsigned pid = m_profiles->getValue(); assert(pid < PlayerManager::get()->getNumPlayers()); - PlayerProfile* p = PlayerManager::get()->getPlayer(pid); + PlayerProfile* p = m_available_players[pid]; const bool handicap = m_handicap->getState(); if (NetworkConfig::get()->addNetworkPlayer(m_device, p, handicap)) { @@ -88,7 +120,7 @@ GUIEngine::EventPropagation { //I18N: in splitscreen player dialog for network game m_message->setErrorColor(); - m_message->setText(_("Player or input device already exists."), + m_message->setText(_("Input device already exists."), false); } return GUIEngine::EVENT_BLOCK; diff --git a/src/states_screens/dialogs/splitscreen_player_dialog.hpp b/src/states_screens/dialogs/splitscreen_player_dialog.hpp index d4ad3a5e4..3a84c707b 100644 --- a/src/states_screens/dialogs/splitscreen_player_dialog.hpp +++ b/src/states_screens/dialogs/splitscreen_player_dialog.hpp @@ -20,12 +20,22 @@ #define HEADER_SPLITSCREEN_PLAYER_DIALOG_HPP #include "guiengine/modaldialog.hpp" -#include "guiengine/widgets.hpp" #include "utils/types.hpp" #include +#include class InputDevice; +class PlayerProfile; + +namespace GUIEngine +{ + class CheckBoxWidget; + class IconButtonWidget; + class LabelWidget; + class RibbonWidget; + class SpinnerWidget; +} /** * \brief Dialog that handle user in network lobby @@ -38,6 +48,8 @@ private: bool m_self_destroy; + std::vector m_available_players; + GUIEngine::LabelWidget* m_message; GUIEngine::SpinnerWidget* m_profiles;