Add the GUI to update server config in lobby
This commit is contained in:
parent
66f7aea3bb
commit
083e1180fb
44
data/gui/dialogs/online/server_configuration_dialog.stkgui
Normal file
44
data/gui/dialogs/online/server_configuration_dialog.stkgui
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<stkgui>
|
||||
<div x="0" y="0" width="100%" height="100%" layout="vertical-row" >
|
||||
<header id="title" text_align="center" width="80%" align="center" I18N="In the server configuration screen" text="Server Configuration"/>
|
||||
<box proportion="1" width="90%" layout="vertical-row" align="center">
|
||||
|
||||
<label width="100%" height="fit" text_align="left" I18N="In the server configuration screen" text="Difficulty"/>
|
||||
<ribbon id="difficulty" height="15%" width="90%" align="center">
|
||||
<icon-button id="novice" width="128" height="128" icon="gui/icons/difficulty_easy.png"
|
||||
I18N="Difficulty" text="Novice"/>
|
||||
<icon-button id="intermediate" width="128" height="128" icon="gui/icons/difficulty_medium.png"
|
||||
I18N="Difficulty" text="Intermediate"/>
|
||||
<icon-button id="expert" width="128" height="128" icon="gui/icons/difficulty_hard.png"
|
||||
I18N="Difficulty" text="Expert"/>
|
||||
<icon-button id="best" width="128" height="128" icon="gui/icons/difficulty_best.png"
|
||||
I18N="Difficulty" text="SuperTux"/>
|
||||
</ribbon>
|
||||
<label width="100%" height="fit" text_align="left" I18N="In the server configuration screen" text="Game mode"/>
|
||||
<ribbon id="gamemode" height="15%" width="90%" align="center">
|
||||
<icon-button id="normal" width="128" height="128" icon="gui/icons/mode_normal.png"
|
||||
I18N="Multiplayer game mode" text="Normal Race"/>
|
||||
<icon-button id="timetrial" width="128" height="128" icon="gui/icons/mode_tt.png"
|
||||
I18N="Multiplayer game mode" text="Time Trial"/>
|
||||
<icon-button id="3strikes" width="128" height="128" icon="gui/icons/weapons.png"
|
||||
I18N="Multiplayer game mode" text="Battle"/>
|
||||
<icon-button id="soccer" width="128" height="128" icon="gui/icons/mode_soccer.png"
|
||||
I18N="Multiplayer game mode" text="Soccer"/>
|
||||
</ribbon>
|
||||
|
||||
<spacer height="10" width="20"/>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label id="more-options" proportion="1" text_align="left"/>
|
||||
<spinner id="more-options-spinner" proportion="1" wrap_around="true"/>
|
||||
</div>
|
||||
<spacer width="10" height="20"/>
|
||||
<buttonbar id="options" x="0" y="0" width="25%" height="12%" align="center">
|
||||
<icon-button id="ok" width="64" height="64" icon="gui/icons/green_check.png"
|
||||
I18N="In the server configuration screen" text="OK" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/icons/main_quit.png"
|
||||
I18N="In the server configuration screen" text="Cancel" label_location="bottom"/>
|
||||
</buttonbar>
|
||||
</box>
|
||||
</div>
|
||||
</stkgui>
|
@ -88,6 +88,7 @@ ClientLobby::ClientLobby(const TransportAddress& a, std::shared_ptr<Server> s)
|
||||
m_disconnected_msg[PDI_KICK] = _("You were kicked from the server.");
|
||||
m_disconnected_msg[PDI_BAD_CONNECTION] =
|
||||
_("Bad network connection is detected.");
|
||||
m_first_connect = true;
|
||||
} // ClientLobby
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -582,6 +583,13 @@ void ClientLobby::handleServerInfo(Event* event)
|
||||
// At least 6 bytes should remain now
|
||||
if (!checkDataSize(event, 6)) return;
|
||||
|
||||
if (!m_first_connect)
|
||||
{
|
||||
NetworkingLobby::getInstance()
|
||||
->addMoreServerInfo(L"--------------------");
|
||||
}
|
||||
m_first_connect = false;
|
||||
|
||||
NetworkString &data = event->data();
|
||||
// Add server info
|
||||
core::stringw str, each_line;
|
||||
@ -676,8 +684,6 @@ void ClientLobby::updatePlayerList(Event* event)
|
||||
if (m_waiting_for_game && !waiting)
|
||||
{
|
||||
// The waiting game finished
|
||||
NetworkingLobby::getInstance()
|
||||
->addMoreServerInfo(L"--------------------");
|
||||
SFXManager::get()->quickSound("wee");
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,8 @@ private:
|
||||
|
||||
bool m_auto_started;
|
||||
|
||||
bool m_first_connect;
|
||||
|
||||
uint64_t m_auto_back_to_lobby_time;
|
||||
|
||||
/** The state of the finite state machine. */
|
||||
|
183
src/states_screens/dialogs/server_configuration_dialog.cpp
Normal file
183
src/states_screens/dialogs/server_configuration_dialog.cpp
Normal file
@ -0,0 +1,183 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2018 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/dialogs/server_configuration_dialog.hpp"
|
||||
|
||||
#include "config/user_config.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/protocols/lobby_protocol.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ServerConfigurationDialog::beforeAddingWidgets()
|
||||
{
|
||||
m_more_options_text = getWidget<LabelWidget>("more-options");
|
||||
assert(m_more_options_text != NULL);
|
||||
m_more_options_spinner = getWidget<SpinnerWidget>("more-options-spinner");
|
||||
assert(m_more_options_spinner != NULL);
|
||||
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
m_game_mode_widget = getWidget<RibbonWidget>("gamemode");
|
||||
assert(m_game_mode_widget != NULL);
|
||||
m_difficulty_widget = getWidget<RibbonWidget>("difficulty");
|
||||
assert(m_difficulty_widget != NULL);
|
||||
m_ok_widget = getWidget<IconButtonWidget>("ok");
|
||||
assert(m_ok_widget != NULL);
|
||||
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||
assert(m_cancel_widget != NULL);
|
||||
} // beforeAddingWidgets
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ServerConfigurationDialog::init()
|
||||
{
|
||||
ModalDialog::init();
|
||||
|
||||
RibbonWidget* difficulty = getWidget<RibbonWidget>("difficulty");
|
||||
assert(difficulty != NULL);
|
||||
difficulty->setSelection((int)race_manager->getDifficulty(),
|
||||
PLAYER_ID_GAME_MASTER);
|
||||
|
||||
RibbonWidget* gamemode = getWidget<RibbonWidget>("gamemode");
|
||||
assert(gamemode != NULL);
|
||||
gamemode->setSelection(m_prev_mode, PLAYER_ID_GAME_MASTER);
|
||||
|
||||
updateMoreOption(m_prev_mode);
|
||||
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
m_options_widget->select("cancel", PLAYER_ID_GAME_MASTER);
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation
|
||||
ServerConfigurationDialog::processEvent(const std::string& source)
|
||||
{
|
||||
if (source == m_options_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const std::string& selection =
|
||||
m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (selection == m_cancel_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_self_destroy = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (selection == m_ok_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_self_destroy = true;
|
||||
NetworkString change(PROTOCOL_LOBBY_ROOM);
|
||||
change.addUInt8(LobbyProtocol::LE_CONFIG_SERVER);
|
||||
change.addUInt8((uint8_t)m_difficulty_widget
|
||||
->getSelection(PLAYER_ID_GAME_MASTER));
|
||||
switch (m_game_mode_widget->getSelection(PLAYER_ID_GAME_MASTER))
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
change.addUInt8(3).addUInt8(0);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
change.addUInt8(4).addUInt8(0);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
int v = m_more_options_spinner->getValue();
|
||||
if (v == 0)
|
||||
change.addUInt8(7).addUInt8(0);
|
||||
else
|
||||
change.addUInt8(8).addUInt8(0);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
int v = m_more_options_spinner->getValue();
|
||||
change.addUInt8(6).addUInt8((uint8_t)v);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
STKHost::get()->sendToServer(&change, true);
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
}
|
||||
else if (source == m_game_mode_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const int selection =
|
||||
m_game_mode_widget->getSelection(PLAYER_ID_GAME_MASTER);
|
||||
m_prev_value = 0;
|
||||
updateMoreOption(selection);
|
||||
m_prev_mode = selection;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ServerConfigurationDialog::updateMoreOption(int game_mode)
|
||||
{
|
||||
switch (game_mode)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
{
|
||||
m_more_options_text->setVisible(false);
|
||||
m_more_options_spinner->setVisible(false);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
m_more_options_text->setVisible(true);
|
||||
m_more_options_spinner->setVisible(true);
|
||||
m_more_options_spinner->clearLabels();
|
||||
m_more_options_text->setText(_("Battle mode"), false);
|
||||
m_more_options_spinner->setVisible(true);
|
||||
m_more_options_spinner->clearLabels();
|
||||
m_more_options_spinner->addLabel(_("Free-For-All"));
|
||||
m_more_options_spinner->addLabel(_("Capture The Flag"));
|
||||
m_more_options_spinner->setValue(m_prev_value);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
m_more_options_text->setVisible(true);
|
||||
m_more_options_spinner->setVisible(true);
|
||||
m_more_options_spinner->clearLabels();
|
||||
m_more_options_text->setText(_("Soccer game type"), false);
|
||||
m_more_options_spinner->setVisible(true);
|
||||
m_more_options_spinner->clearLabels();
|
||||
m_more_options_spinner->addLabel(_("Time limit"));
|
||||
m_more_options_spinner->addLabel(_("Goals limit"));
|
||||
m_more_options_spinner->setValue(m_prev_value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_more_options_text->setVisible(false);
|
||||
m_more_options_spinner->setVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // updateMoreOption
|
117
src/states_screens/dialogs/server_configuration_dialog.hpp
Normal file
117
src/states_screens/dialogs/server_configuration_dialog.hpp
Normal file
@ -0,0 +1,117 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2018 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_SERVER_CONFIGURATION_DIALOG_HPP
|
||||
#define HEADER_SERVER_CONFIGURATION_DIALOG_HPP
|
||||
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class SpinnerWidget;
|
||||
class LabelWidget;
|
||||
class RibbonWidget;
|
||||
class IconButtonWidget;
|
||||
}
|
||||
|
||||
class ServerConfigurationDialog : public GUIEngine::ModalDialog
|
||||
{
|
||||
private:
|
||||
int m_prev_mode;
|
||||
int m_prev_value;
|
||||
bool m_self_destroy;
|
||||
|
||||
GUIEngine::SpinnerWidget* m_more_options_spinner;
|
||||
|
||||
GUIEngine::LabelWidget* m_more_options_text;
|
||||
|
||||
GUIEngine::RibbonWidget* m_difficulty_widget;
|
||||
GUIEngine::RibbonWidget* m_game_mode_widget;
|
||||
GUIEngine::RibbonWidget* m_options_widget;
|
||||
GUIEngine::IconButtonWidget* m_ok_widget;
|
||||
GUIEngine::IconButtonWidget* m_cancel_widget;
|
||||
|
||||
void updateMoreOption(int game_mode);
|
||||
public:
|
||||
ServerConfigurationDialog(bool soccer_goal) : ModalDialog(0.8f, 0.8f)
|
||||
{
|
||||
m_self_destroy = false;
|
||||
switch (race_manager->getMinorMode())
|
||||
{
|
||||
case RaceManager::MINOR_MODE_NORMAL_RACE:
|
||||
{
|
||||
m_prev_mode = 0;
|
||||
m_prev_value = 0;
|
||||
break;
|
||||
}
|
||||
case RaceManager::MINOR_MODE_TIME_TRIAL:
|
||||
{
|
||||
m_prev_mode = 1;
|
||||
m_prev_value = 0;
|
||||
break;
|
||||
}
|
||||
case RaceManager::MINOR_MODE_FREE_FOR_ALL:
|
||||
{
|
||||
m_prev_mode = 2;
|
||||
m_prev_value = 0;
|
||||
break;
|
||||
}
|
||||
case RaceManager::MINOR_MODE_CAPTURE_THE_FLAG:
|
||||
{
|
||||
m_prev_mode = 2;
|
||||
m_prev_value = 1;
|
||||
break;
|
||||
}
|
||||
case RaceManager::MINOR_MODE_SOCCER:
|
||||
{
|
||||
m_prev_mode = 3;
|
||||
m_prev_value = soccer_goal ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_prev_mode = 0;
|
||||
m_prev_value = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
loadFromFile("online/server_configuration_dialog.stkgui");
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void beforeAddingWidgets();
|
||||
// ------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation processEvent(const std::string& source);
|
||||
// ------------------------------------------------------------------------
|
||||
void init();
|
||||
// ------------------------------------------------------------------------
|
||||
void onEnterPressedInternal() { m_self_destroy = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool onEscapePressed()
|
||||
{
|
||||
m_self_destroy = true;
|
||||
return false;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void onUpdate(float dt)
|
||||
{
|
||||
if (m_self_destroy)
|
||||
ModalDialog::dismiss();
|
||||
}
|
||||
}; // class ServerConfigurationDialog
|
||||
|
||||
#endif
|
@ -35,14 +35,16 @@
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
#include "network/protocols/client_lobby.hpp"
|
||||
#include "network/server.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "states_screens/dialogs/splitscreen_player_dialog.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/dialogs/network_user_dialog.hpp"
|
||||
#include "states_screens/dialogs/server_configuration_dialog.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include <utfwrapping.h>
|
||||
@ -451,6 +453,16 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
|
||||
start.addUInt8(LobbyProtocol::LE_REQUEST_BEGIN);
|
||||
STKHost::get()->sendToServer(&start, true);
|
||||
}
|
||||
else if (name == m_config_button->m_properties[PROP_ID])
|
||||
{
|
||||
auto cl = LobbyProtocol::get<ClientLobby>();
|
||||
if (cl)
|
||||
{
|
||||
new ServerConfigurationDialog(
|
||||
race_manager->isSoccerMode() &&
|
||||
cl->getGameSetup()->isSoccerGoalTarget());
|
||||
}
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -471,7 +471,6 @@ void RaceResultGUI::backToLobby()
|
||||
cleanupGPProgress();
|
||||
StateManager::get()->resetAndSetStack(
|
||||
NetworkConfig::get()->getResetScreens(true/*lobby*/).data());
|
||||
NetworkingLobby::getInstance()->addMoreServerInfo(L"--------------------");
|
||||
} // backToLobby
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user