Improve splitscreen dialog for easier adding

This commit is contained in:
Benau 2018-03-22 12:52:37 +08:00
parent 1b4caa36af
commit c026261e0f
4 changed files with 66 additions and 12 deletions

View File

@ -8,16 +8,16 @@
<div width="80%" align="center" layout="vertical-row" height="fit" >
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="Splitscreen player in network" text="Name"/>
<label id="name-text" proportion="1" text_align="left" I18N="Splitscreen player in network" text="Name"/>
<spinner id="name-spinner" width="50%" align="center" wrap_around="true" />
</div>
</div>
<spacer height="20" width="50"/>
<div width="80%" align="center" layout="vertical-row" height="fit" >
<div id="handicap-row" width="80%" align="center" layout="vertical-row" height="fit" >
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="Splitscreen player in network" text="Handicap"/>
<label id="handicap-text" proportion="1" text_align="left" I18N="Splitscreen player in network" text="Handicap"/>
<checkbox id="handicap" align="center" />
</div>
</div>

View File

@ -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();

View File

@ -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<SpinnerWidget>("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<LabelWidget>("message-label");
assert(m_message != NULL);
m_handicap = getWidget<CheckBoxWidget>("handicap");
m_handicap->setState(false);
m_handicap->setActive(UserConfigParams::m_per_player_difficulty);
assert(m_handicap != NULL);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_add = getWidget<IconButtonWidget>("add");
assert(m_add != NULL);
m_connect = getWidget<IconButtonWidget>("connect");
@ -58,6 +67,29 @@ void SplitscreenPlayerDialog::beforeAddingWidgets()
m_reset = getWidget<IconButtonWidget>("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;

View File

@ -20,12 +20,22 @@
#define HEADER_SPLITSCREEN_PLAYER_DIALOG_HPP
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "utils/types.hpp"
#include <irrString.h>
#include <vector>
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<PlayerProfile*> m_available_players;
GUIEngine::LabelWidget* m_message;
GUIEngine::SpinnerWidget* m_profiles;