Highlight selected vote by player
Animation is disabled atm because not working very well
This commit is contained in:
parent
9029621b59
commit
e4e03e6209
@ -565,11 +565,7 @@ void MainLoop::renderGUI(int phase, int loop_index, int loop_size)
|
||||
if (dt < 1.0 / 30.0f) return;
|
||||
|
||||
m_curr_time = now;
|
||||
|
||||
if (NetworkConfig::get()->isNetworking() && phase >= 5000)
|
||||
{
|
||||
TracksScreen::getInstance()->showVoteResult();
|
||||
}
|
||||
|
||||
// TODO: remove debug output
|
||||
//Log::verbose("mainloop", "Rendergui t %llu dt %f phase %d index %d / %d",
|
||||
// now, dt, phase, loop_index, loop_size);
|
||||
|
@ -233,7 +233,7 @@ void ClientLobby::addAllPlayers(Event* event)
|
||||
PeerVote winner_vote(data);
|
||||
|
||||
m_game_setup->setRace(winner_vote);
|
||||
TracksScreen::getInstance()->setResult(winner_vote);
|
||||
TracksScreen::getInstance()->setResult(winner_peer_id, winner_vote);
|
||||
|
||||
std::shared_ptr<STKPeer> peer = event->getPeerSP();
|
||||
peer->cleanPlayerProfiles();
|
||||
|
0
src/race/race_manager.cpp
Executable file → Normal file
0
src/race/race_manager.cpp
Executable file → Normal file
@ -658,29 +658,19 @@ void TracksScreen::onUpdate(float dt)
|
||||
if (!m_network_tracks)
|
||||
return;
|
||||
|
||||
if (m_winning_index != std::numeric_limits<uint32_t>::max() && m_vote_list)
|
||||
{
|
||||
int list_id =
|
||||
m_vote_list->getItemID(StringUtils::toString(m_winning_index));
|
||||
//if (StkTime::getRealTimeMs() / 1000 % 2 == 0)
|
||||
m_vote_list->setSelectionID(list_id);
|
||||
//else
|
||||
// m_vote_list->unfocused(PLAYER_ID_GAME_MASTER, NULL);
|
||||
return;
|
||||
}
|
||||
updateProgressBarText();
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when the final 'random picking' animation is finished so that only
|
||||
* the result is shown : all votes except the winner is set to be invisible.
|
||||
*/
|
||||
void TracksScreen::showVoteResult()
|
||||
{
|
||||
Log::info("TracksScreen", "showVoteResult: winning index %d",
|
||||
m_winning_index);
|
||||
// TODO: Make all listed votes except the winner invisible: something
|
||||
// like this:
|
||||
//for (unsigned int i = 0; i < 8; i++)
|
||||
//{
|
||||
// std::string box_name = StringUtils::insertValues("rect-box%d", i);
|
||||
// Widget *box = getWidget(box_name.c_str());
|
||||
// if (i != m_winning_index)
|
||||
// box->setVisible(false);
|
||||
// else
|
||||
// box->setSelected(PLAYER_ID_GAME_MASTER, true);
|
||||
//}
|
||||
} // showVoteResult
|
||||
} // onUpdate
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Selects in which part of the vote list the new host is being shown and
|
||||
@ -730,49 +720,21 @@ void TracksScreen::removeVote(uint32_t host_id)
|
||||
/** Received the winning vote. i.e. the data about the track to play (including
|
||||
* #laps etc).
|
||||
*/
|
||||
void TracksScreen::setResult(const PeerVote &winner_vote)
|
||||
void TracksScreen::setResult(uint32_t winner_host,
|
||||
const PeerVote& winner_vote)
|
||||
{
|
||||
// If the GUI is forced from the server lobby, m_timer is not defined
|
||||
if (!m_timer || winner_host == std::numeric_limits<uint32_t>::max() ||
|
||||
!m_vote_list)
|
||||
return;
|
||||
if (m_timer) m_timer->setVisible(false);
|
||||
|
||||
// Note that the votes on the server might have a different order from
|
||||
// the votes here on the client. Potentially there could also be a missing
|
||||
// vote(??)
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
m_winning_index = -1;
|
||||
for (unsigned int i = 0; i < m_index_to_hostid.size(); i++)
|
||||
m_winning_index = winner_host;
|
||||
if (auto lp = LobbyProtocol::get<LobbyProtocol>())
|
||||
{
|
||||
const PeerVote *vote = lp->getVote(m_index_to_hostid[i]);
|
||||
if (!vote) continue;
|
||||
if (vote->m_track_name == winner_vote.m_track_name &&
|
||||
vote->m_num_laps == winner_vote.m_num_laps &&
|
||||
vote->m_reverse == winner_vote.m_reverse)
|
||||
{
|
||||
m_winning_index = i;
|
||||
break;
|
||||
}
|
||||
// Try to prepare a fallback in case that the right vote is not here.
|
||||
if (vote->m_track_name == winner_vote.m_track_name)
|
||||
{
|
||||
m_winning_index = i;
|
||||
}
|
||||
} // for i in m_index_to_hostid
|
||||
|
||||
if (m_winning_index == -1)
|
||||
{
|
||||
// We don't have the right vote. Assume that a message got lost,
|
||||
// In this case, change one non-local vote:
|
||||
for (unsigned int i = 0; i < m_index_to_hostid.size(); i++)
|
||||
{
|
||||
if (m_index_to_hostid[i] != STKHost::get()->getMyHostId())
|
||||
{
|
||||
lp->addVote(m_index_to_hostid[i], winner_vote);
|
||||
m_winning_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // wim_winning_index == -1
|
||||
|
||||
lp->addVote(winner_host, winner_vote);
|
||||
}
|
||||
updatePlayerVotes();
|
||||
} // setResult
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -782,7 +744,7 @@ void TracksScreen::setResult(const PeerVote &winner_vote)
|
||||
void TracksScreen::updatePlayerVotes()
|
||||
{
|
||||
auto cl = LobbyProtocol::get<ClientLobby>();
|
||||
if (GUIEngine::getCurrentScreen() != this || !cl)
|
||||
if (GUIEngine::getCurrentScreen() != this || !cl || !m_vote_list)
|
||||
return;
|
||||
m_vote_list->clear();
|
||||
for (unsigned i = 0; i < m_index_to_hostid.size(); i++)
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "guiengine/screen.hpp"
|
||||
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -70,8 +71,8 @@ private:
|
||||
|
||||
int m_bottom_box_height;
|
||||
|
||||
/** Index of the winning vote. */
|
||||
int m_winning_index;
|
||||
/** Id of the winning peer. */
|
||||
uint32_t m_winning_index;
|
||||
|
||||
/** This stores which vote (hostid) is shown at which index in
|
||||
* the vote overview list. */
|
||||
@ -91,6 +92,8 @@ private:
|
||||
m_bottom_box_height = -1;
|
||||
m_track_icons = NULL;
|
||||
m_timer = NULL;
|
||||
m_winning_index = std::numeric_limits<uint32_t>::max();
|
||||
m_vote_list = NULL;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void updateProgressBarText();
|
||||
@ -99,8 +102,7 @@ public:
|
||||
|
||||
void addVote(uint32_t host_id);
|
||||
void removeVote(uint32_t host_id);
|
||||
void setResult(const PeerVote &winner_vote);
|
||||
void showVoteResult();
|
||||
void setResult(uint32_t winner_host, const PeerVote& winner_vote);
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
@ -138,11 +140,10 @@ public:
|
||||
* data fields. */
|
||||
void resetVote()
|
||||
{
|
||||
m_winning_index = std::numeric_limits<uint32_t>::max();
|
||||
m_index_to_hostid.clear();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setVoteTimeout(float timeout);
|
||||
// ------------------------------------------------------------------------
|
||||
void updatePlayerVotes();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user