Update lobby for new gui engine code

This commit is contained in:
Benau 2018-02-25 13:31:45 +08:00
parent 7b903a09ba
commit 571a524f59
5 changed files with 42 additions and 37 deletions

View File

@ -3,9 +3,11 @@
<div x="0" y="0" width="100%" height="100%" layout="vertical-row" >
<header text_align="center" width="80%" align="center" I18N="In networking lobby" text="Lobby"/>
<spacer height="15" width="10"/>
<div proportion="3" x="2%" width="96%" layout="vertical-row">
<div proportion="4" x="2%" width="96%" layout="vertical-row">
<div width="100%" proportion="2" layout="horizontal-row">
<bubble id="text" proportion="3" height="100%"/>
<box id="info" proportion="2" height="100%" layout="vertical-row">
<label word_wrap="true" id="text" proportion="3" width="100%" height="100%" text_valign="top"/>
</box>
<spacer width="20" height="20"/>
<box proportion="1" height="100%" layout="vertical-row">
<list id="players" width="100%" height="100%"/>
@ -15,13 +17,15 @@
<spacer height="10"/>
<div width="100%" proportion="1" layout="horizontal-row">
<spacer width="20" height="20"/>
<box proportion="2" height="100%" layout="horizontal-row">
<textbox id="chat" width="100%" height="25%"/>
<box proportion="2" height="100%" layout="vertical-row">
<textbox id="chat" width="100%" height="30%"/>
<spacer height="20"/>
<button id="send_text" height="30%" width="fit" I18N="In the network lobby" text="Send text" />
</box>
<spacer width="20"/>
<spacer width="40"/>
<buttonbar id="actions" proportion="1" width="75%" height="75%">
<icon-button id="start" width="64" height="64" icon="gui/green_check.png" align="center"
I18N="In the network lobby" text="Start Race"/>
I18N="In the network lobby" text="Start race"/>
<icon-button id="exit" width="64" height="64" icon="gui/main_quit.png" align="center"
I18N="In the network lobby" text="Exit"/>
</buttonbar>

View File

@ -56,8 +56,8 @@ ConnectToServer::ConnectToServer(uint32_t server_id, uint32_t host_id)
m_server_id = server_id;
m_host_id = host_id;
m_quick_join = false;
const Server *server = ServersManager::get()->getServerByID(server_id);
m_server_address.copy(server->getAddress());
m_server = ServersManager::get()->getServerByID(m_server_id);
m_server_address.copy(m_server->getAddress());
setHandleConnections(true);
} // ConnectToServer(server, host)
@ -239,8 +239,7 @@ void ConnectToServer::update(float dt)
{
// Shutdown STKHost (go back to online menu too)
STKHost::get()->setErrorMessage(
_("Cannot connect to server with address: %s.",
m_server_address.toString().c_str()));
_("Cannot connect to server %s.", m_server->getName()));
STKHost::get()->requestShutdown();
}
requestTerminate();

View File

@ -25,6 +25,8 @@
#include <atomic>
#include <string>
class Server;
class ConnectToServer : public Protocol
{
private:
@ -34,6 +36,7 @@ private:
uint32_t m_host_id;
unsigned m_tried_connection = 0;
const Server* m_server = NULL;
/** Protocol currently being monitored. */
std::weak_ptr<Protocol> m_current_protocol;
bool m_quick_join;

View File

@ -26,6 +26,7 @@
#include "config/player_manager.hpp"
#include "guiengine/widgets/bubble_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
@ -70,10 +71,10 @@ void NetworkingLobby::loadedFromFile()
m_back_widget = getWidget<IconButtonWidget>("back");
assert(m_back_widget != NULL);
m_start_button= getWidget<IconButtonWidget>("start");
m_start_button = getWidget<IconButtonWidget>("start");
assert(m_start_button!= NULL);
m_text_bubble = getWidget<BubbleWidget>("text");
m_text_bubble = getWidget<LabelWidget>("text");
assert(m_text_bubble != NULL);
m_chat_box = getWidget<TextBoxWidget>("chat");
@ -82,7 +83,7 @@ void NetworkingLobby::loadedFromFile()
m_player_list = getWidget<ListWidget>("players");
assert(m_player_list!= NULL);
m_exit_widget = getWidget<IconButtonWidget>("exit");;
m_exit_widget = getWidget<IconButtonWidget>("exit");
assert(m_exit_widget != NULL);
} // loadedFromFile
@ -90,7 +91,6 @@ void NetworkingLobby::loadedFromFile()
// ---------------------------------------------------------------------------
void NetworkingLobby::beforeAddingWidget()
{
} // beforeAddingWidget
// ----------------------------------------------------------------------------
@ -121,8 +121,7 @@ void NetworkingLobby::init()
m_server_info.push_back(each_line);
}
if(!NetworkConfig::get()->isServer())
m_start_button->setVisible(STKHost::get()->isAuthorisedToControl());
m_start_button->setVisible(false);
// For now create the active player and bind it to the right
// input device.
@ -144,7 +143,8 @@ void NetworkingLobby::onUpdate(float delta)
{
const core::stringw connect_msg = StringUtils::loadingDots(
_("Connecting to server %s", m_server_name));
m_text_bubble->setText(connect_msg);
m_text_bubble->setText(connect_msg, true);
m_start_button->setVisible(false);
}
else
{
@ -154,12 +154,12 @@ void NetworkingLobby::onUpdate(float delta)
total_msg += string;
total_msg += L"\n";
}
m_text_bubble->setText(total_msg);
m_text_bubble->setText(total_msg, true);
}
if(NetworkConfig::get()->isClient())
if (NetworkConfig::get()->isClient() &&
STKHost::get()->isAuthorisedToControl())
{
m_start_button->setVisible(STKHost::existHost() &&
STKHost::get()->isAuthorisedToControl());
m_start_button->setVisible(true);
}
} // onUpdate
@ -175,14 +175,23 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
return;
}
if(name==m_start_button->m_properties[PROP_ID])
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return;
const std::string &selection =
ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_exit_widget->m_properties[PROP_ID])
{
if(NetworkConfig::get()->isServer())
StateManager::get()->escapePressed();
}
else if (selection == m_start_button->m_properties[PROP_ID])
{
if (NetworkConfig::get()->isServer())
{
auto slrp = LobbyProtocol::get<ServerLobby>();
slrp->startSelection();
}
else // client
else
{
// Send a message to the server to start
NetworkString start(PROTOCOL_LOBBY_ROOM);
@ -191,16 +200,6 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
STKHost::get()->sendToServer(&start, true);
}
}
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return;
const std::string &selection =
ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_exit_widget->m_properties[PROP_ID])
{
StateManager::get()->escapePressed();
}
} // eventCallback
// ----------------------------------------------------------------------------

View File

@ -25,9 +25,9 @@ class Server;
namespace GUIEngine
{
class Widget;
class ListWidget;
class LabelWidget;
class ListWidget;
class IconButtonWidget;
class BubbleWidget;
class TextBoxWidget;
}
@ -49,7 +49,7 @@ private:
std::vector<core::stringw> m_server_info;
GUIEngine::IconButtonWidget * m_back_widget;
GUIEngine::BubbleWidget * m_text_bubble;
GUIEngine::LabelWidget * m_text_bubble;
GUIEngine::IconButtonWidget * m_exit_widget;
GUIEngine::IconButtonWidget *m_start_button;
GUIEngine::ListWidget *m_player_list;