From e4e03e6209edc9e5c9f4078c8f268c00113906da Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 21 Dec 2018 19:40:52 +0800 Subject: [PATCH] Highlight selected vote by player Animation is disabled atm because not working very well --- src/main_loop.cpp | 6 +- src/network/protocols/client_lobby.cpp | 2 +- src/race/race_manager.cpp | 0 src/states_screens/online/tracks_screen.cpp | 82 ++++++--------------- src/states_screens/online/tracks_screen.hpp | 13 ++-- 5 files changed, 31 insertions(+), 72 deletions(-) mode change 100755 => 100644 src/race/race_manager.cpp diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 00a2635d7..2303bf92e 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -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); diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 822eb6fb4..0b88996b1 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -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 peer = event->getPeerSP(); peer->cleanPlayerProfiles(); diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp old mode 100755 new mode 100644 diff --git a/src/states_screens/online/tracks_screen.cpp b/src/states_screens/online/tracks_screen.cpp index edb6a93cb..b3f5cbf7f 100644 --- a/src/states_screens/online/tracks_screen.cpp +++ b/src/states_screens/online/tracks_screen.cpp @@ -658,29 +658,19 @@ void TracksScreen::onUpdate(float dt) if (!m_network_tracks) return; + if (m_winning_index != std::numeric_limits::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::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(); - 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()) { - 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(); - 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++) diff --git a/src/states_screens/online/tracks_screen.hpp b/src/states_screens/online/tracks_screen.hpp index 1f36bd349..3a58c721e 100644 --- a/src/states_screens/online/tracks_screen.hpp +++ b/src/states_screens/online/tracks_screen.hpp @@ -21,6 +21,7 @@ #include "guiengine/screen.hpp" #include +#include #include #include @@ -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::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::max(); m_index_to_hostid.clear(); } // ------------------------------------------------------------------------ - void setVoteTimeout(float timeout); - // ------------------------------------------------------------------------ void updatePlayerVotes(); };