More work on networking UI

This commit is contained in:
Marianne Gagnon 2016-03-06 20:01:40 -05:00
parent 6fd6dd8792
commit 04999c35ee
6 changed files with 64 additions and 20 deletions

View File

@ -6,6 +6,6 @@
<spacer height="40" width="50"/>
Waiting...
<label proportion="1" width="100%" text_align="left" id="lblDetails"/>
</div>
</stkgui>

View File

@ -234,18 +234,9 @@ uint8_t RaceVote::getLapsVote(uint8_t track_number) const
RaceConfig::RaceConfig()
{
setMaxPlayerCount(NetworkConfig::get()->getMaxPlayers());
m_max_players = NetworkConfig::get()->getMaxPlayers();
} // RaceConfig
//-----------------------------------------------------------------------------
/** Sets the maximum number of players.
*/
void RaceConfig::setMaxPlayerCount(uint8_t count)
{
m_max_players = count;
m_votes.resize(m_max_players);
} // setMaxPlayerCount
//-----------------------------------------------------------------------------
void RaceConfig::setPlayerMajorVote(uint8_t player_id, uint32_t major)
{
@ -451,10 +442,11 @@ int RaceConfig::getNumTrackVotes() const
{
int count = 0;
for (unsigned int i = 0; i < m_max_players; i++)
for (auto entry : m_votes)
{
if (m_votes[i].hasVotedTrack())
count ++;
if (entry.second.hasVotedTrack())
count++;
}
return count;
} // getNumTrackVotes

View File

@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <map>
#include "utils/types.hpp"
/** Stores the name of a track, number of laps, and reverse driving.
@ -99,7 +100,6 @@ private:
public:
RaceConfig();
void setMaxPlayerCount(uint8_t count);
void setPlayerMajorVote(uint8_t player_id, uint32_t major);
void setPlayerRaceCountVote(uint8_t player_id, uint8_t count);
void setPlayerMinorVote(uint8_t player_id, uint32_t minor);
@ -117,13 +117,18 @@ public:
bool getLapCount() const;
int getNumTrackVotes() const;
protected:
const RaceVote& getRaceVote(int global_player_id) { return m_votes[global_player_id]; }
int getMaxPlayers() const { return m_max_players; }
protected:
std::vector<TrackInfo> m_tracks;
int m_minor_mode;
int m_major_mode;
unsigned int m_races_count;
std::vector<RaceVote> m_votes;
/** Key: globalPlayerID */
std::map<int, RaceVote> m_votes;
uint8_t m_max_players;
}; // class RaceConfig

View File

@ -33,6 +33,7 @@
#include "states_screens/server_selection.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/tracks_screen.hpp"
#include "states_screens/waiting_for_others.hpp"
static const char ID_LOCKED[] = "locked/";
@ -180,7 +181,9 @@ void NetworkKartSelectionScreen::playerSelected(uint8_t player_id,
clrp->voteReversed(race_manager->getReverseTrack());
clrp->voteRaceCount(1);
// FIXME: for debugging set only 0 laps
clrp->voteLaps(0);
clrp->voteLaps(3);
//WaitingForOthersScreen::getInstance()->push();
//return;
}
TracksScreen::getInstance()->push();
} // playerSelected

View File

@ -19,12 +19,15 @@
#include "config/user_config.hpp"
#include "guiengine/widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "input/keyboard_device.hpp"
#include "karts/kart_properties_manager.hpp"
#include "network/game_setup.hpp"
#include "network/network_player_profile.hpp"
#include "network/stk_host.hpp"
#include "network/stk_peer.hpp"
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
@ -58,3 +61,42 @@ void WaitingForOthersScreen::init()
} //init
// -----------------------------------------------------------------------------
void WaitingForOthersScreen::onUpdate(float dt)
{
const std::vector<STKPeer*>& peers = STKHost::get()->getPeers();
RaceConfig* config = STKHost::get()->getGameSetup()->getRaceConfig();
core::stringw w;
for (int i = 0; i < peers.size(); i++)
{
//race_manager->get
STKPeer* peer = peers[i];
NetworkPlayerProfile* profile = peer->getPlayerProfile();
if (profile == NULL)
continue;
core::stringw name = profile->getName();
w += name + L" : ";
int playerId = profile->getGlobalPlayerId();
const RaceVote& vote = config->getRaceVote(playerId);
if (vote.hasVotedTrack())
{
w += vote.getTrackVote().c_str();
}
else
{
w += L"...";
}
w += "\n";
}
GUIEngine::LabelWidget* lbl = getWidget<GUIEngine::LabelWidget>("lblDetails");
lbl->setText(w.c_str(), true);
}
// -----------------------------------------------------------------------------

View File

@ -42,6 +42,8 @@ public:
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void init() OVERRIDE;
virtual void onUpdate(float dt) OVERRIDE;
};
#endif