Use icon to identify server owner, online and offline players

Also hide the friend request button for offline players
This commit is contained in:
Benau 2018-03-12 11:28:13 +08:00
parent 95208967cf
commit d527c0eee2
8 changed files with 76 additions and 41 deletions

View File

@ -20,7 +20,7 @@
<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" />
<button id="send_text" height="30%" width="fit" I18N="In the network lobby" text="Send" />
</box>
<spacer width="40"/>
<buttonbar id="actions" proportion="1" width="75%" height="75%">

View File

@ -118,11 +118,9 @@ public:
// ------------------------------------------------------------------------
uint32_t getOnlineID() const { return m_online_id; }
// ------------------------------------------------------------------------
std::shared_ptr<STKPeer> getPeer() const { return m_peer.lock(); }
bool isOfflineAccount() const { return m_online_id == 0; }
// ------------------------------------------------------------------------
/** Returns the minimun info for networking lobby screen. */
std::tuple<uint32_t, uint32_t, irr::core::stringw> toTuple() const
{ return std::make_tuple(m_host_id, m_online_id, m_player_name); }
std::shared_ptr<STKPeer> getPeer() const { return m_peer.lock(); }
}; // class NetworkPlayerProfile

View File

@ -269,7 +269,7 @@ bool ClientLobby::notifyEventAsynchronous(Event* event)
case LE_VOTE_TRACK: playerTrackVote(event); break;
case LE_VOTE_REVERSE: playerReversedVote(event); break;
case LE_VOTE_LAPS: playerLapsVote(event); break;
case LE_AUTHORISED: becomingServerOwner(); break;
case LE_SERVER_OWNERSHIP: becomingServerOwner(); break;
} // switch
return true;
@ -454,18 +454,21 @@ void ClientLobby::connectionAccepted(Event* event)
void ClientLobby::updatePlayerList(Event* event)
{
if (!checkDataSize(event, 1)) return;
NetworkString &data = event->data();
NetworkString& data = event->data();
unsigned player_count = data.getUInt8();
NetworkingLobby::getInstance()->cleanPlayers();
std::vector<std::tuple<uint32_t, uint32_t, core::stringw, int> > players;
for (unsigned i = 0; i < player_count; i++)
{
std::tuple<uint32_t, uint32_t, core::stringw, bool> pl;
std::tuple<uint32_t, uint32_t, core::stringw, int> pl;
std::get<0>(pl) = data.getUInt32();
std::get<1>(pl) = data.getUInt32();
data.decodeStringW(&std::get<2>(pl));
std::get<3>(pl) = data.getUInt8() == 1;
NetworkingLobby::getInstance()->addPlayer(pl);
// icon to be used, see NetworkingLobby::loadedFromFile
std::get<3>(pl) = data.getUInt8() == 1 /*if server owner*/ ? 0 :
std::get<1>(pl) != 0 /*if online account*/ ? 1 : 2;
players.push_back(pl);
}
NetworkingLobby::getInstance()->updatePlayers(players);
} // updatePlayerList
//-----------------------------------------------------------------------------

View File

@ -62,7 +62,7 @@ public:
LE_VOTE_LAPS, // vote number of laps
LE_CHAT,
LE_FINAL_PLAYER_LIST,
LE_AUTHORISED,
LE_SERVER_OWNERSHIP,
LE_KICK_HOST
};

View File

@ -166,6 +166,7 @@ void ServerLobby::kickHost(Event* event)
if (m_server_owner.lock() != event->getPeerSP())
return;
lock.unlock();
if (!checkDataSize(event, 4)) return;
NetworkString& data = event->data();
uint32_t host_id = data.getUInt32();
std::shared_ptr<STKPeer> peer = STKHost::get()->findPeerByHostId(host_id);
@ -872,7 +873,7 @@ void ServerLobby::updateServerOwner()
if (owner)
{
NetworkString* ns = getNetworkString();
ns->addUInt8(LE_AUTHORISED);
ns->addUInt8(LE_SERVER_OWNERSHIP);
owner->sendPacket(ns);
delete ns;
m_server_owner = owner;

View File

@ -47,6 +47,7 @@ void NetworkUserDialog::beforeAddingWidgets()
m_friend_widget = getWidget<IconButtonWidget>("friend");
assert(m_friend_widget != NULL);
m_friend_widget->setVisible(m_online_id != 0);
m_kick_widget = getWidget<IconButtonWidget>("decline");
assert(m_kick_widget != NULL);

View File

@ -15,16 +15,12 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DEBUG_MENU_ITEM 0
#include "states_screens/networking_lobby.hpp"
#include <string>
#include <iostream>
#include "challenges/unlock_manager.hpp"
#include "config/player_manager.hpp"
#include "guiengine/widgets/bubble_widget.hpp"
#include "guiengine/CGUISpriteBank.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
@ -86,6 +82,18 @@ void NetworkingLobby::loadedFromFile()
m_exit_widget = getWidget<IconButtonWidget>("exit");
assert(m_exit_widget != NULL);
m_icon_bank = new irr::gui::STKModifiedSpriteBank(GUIEngine::getGUIEnv());
video::ITexture* icon_1 = irr_driver->getTexture
(file_manager->getAsset(FileManager::GUI, "cup_gold.png"));
video::ITexture* icon_2 = irr_driver->getTexture
(file_manager->getAsset(FileManager::GUI, "difficulty_medium.png"));
video::ITexture* icon_3 = irr_driver->getTexture
(file_manager->getAsset(FileManager::GUI, "main_help.png"));
m_icon_bank->addTextureAsSprite(icon_1);
m_icon_bank->addTextureAsSprite(icon_2);
m_icon_bank->addTextureAsSprite(icon_3);
const int screen_width = irr_driver->getFrameSize().Width;
m_icon_bank->setScale(screen_width > 1280 ? 0.4f : 0.25f);
} // loadedFromFile
// ---------------------------------------------------------------------------
@ -105,7 +113,8 @@ void NetworkingLobby::init()
// For now create the active player and bind it to the right
// input device.
InputDevice *device = input_manager->getDeviceManager()->getLatestUsedDevice();
InputDevice* device =
input_manager->getDeviceManager()->getLatestUsedDevice();
PlayerProfile* profile = PlayerManager::getCurrentPlayer();
StateManager::get()->createActivePlayer(profile, device);
} // init
@ -241,6 +250,13 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
} // eventCallback
// ----------------------------------------------------------------------------
void NetworkingLobby::unloaded()
{
delete m_icon_bank;
m_icon_bank = NULL;
} // unloaded
// ----------------------------------------------------------------------------
void NetworkingLobby::tearDown()
@ -248,7 +264,6 @@ void NetworkingLobby::tearDown()
} // tearDown
// ----------------------------------------------------------------------------
bool NetworkingLobby::onEscapePressed()
{
STKHost::get()->shutdown();
@ -256,25 +271,29 @@ bool NetworkingLobby::onEscapePressed()
} // onEscapePressed
// ----------------------------------------------------------------------------
void NetworkingLobby::addPlayer(const std::tuple<uint32_t, uint32_t,
core::stringw, bool>& p)
void NetworkingLobby::updatePlayers(const std::vector<std::tuple<uint32_t,
uint32_t, core::stringw, int> >& p)
{
// In GUI-less server this function will be called without proper
// initialisation
if (m_player_list)
{
const std::string internal_name =
StringUtils::toString(std::get<0>(p)) + "_" +
StringUtils::toString(std::get<1>(p));
m_player_list->addItem(internal_name, std::get<2>(p));
if (std::get<3>(p))
m_player_list->markItemBlue(internal_name, true);
}
} // addPlayer
if (!m_player_list)
return;
m_player_list->clear();
// ----------------------------------------------------------------------------
void NetworkingLobby::cleanPlayers()
{
if (m_player_list)
m_player_list->clear();
} // cleanPlayers
if (p.empty())
return;
irr::gui::STKModifiedSpriteBank* icon_bank = m_icon_bank;
for (auto& q : p)
{
if (icon_bank)
{
m_player_list->setIcons(icon_bank);
icon_bank = NULL;
}
const std::string internal_name =
StringUtils::toString(std::get<0>(q)) + "_" +
StringUtils::toString(std::get<1>(q));
m_player_list->addItem(internal_name, std::get<2>(q), std::get<3>(q));
}
} // updatePlayers

View File

@ -33,6 +33,14 @@ namespace GUIEngine
class TextBoxWidget;
}
namespace irr
{
namespace gui
{
class STKModifiedSpriteBank;
}
}
/**
* \brief Handles the networking lobby
* \ingroup states_screens
@ -55,6 +63,11 @@ private:
GUIEngine::ListWidget *m_player_list;
GUIEngine::TextBoxWidget* m_chat_box;
irr::gui::STKModifiedSpriteBank* m_icon_bank;
/** \brief implement optional callback from parent class GUIEngine::Screen */
virtual void unloaded();
public:
virtual void onUpdate(float delta) OVERRIDE;
@ -81,9 +94,9 @@ public:
/** Used to insert each client chat message (reserved). */
void addMoreServerInfo(const core::stringw& info);
void setJoinedServer(std::shared_ptr<Server> server);
void addPlayer(const std::tuple<uint32_t/*host id*/, uint32_t/*online id*/,
core::stringw/*player name*/, bool/*is server owner*/>& p);
void cleanPlayers();
void updatePlayers(const std::vector<std::tuple<uint32_t/*host id*/,
uint32_t/*online id*/, core::stringw/*player name*/,
int/*icon id*/> >& p);
}; // class NetworkingLobby
#endif