Remved VoteOverview screen, and migrated voting related code
to TracksScreen. No display of votes yet.
This commit is contained in:
parent
c4e5a24059
commit
4bd57b9f67
1
data/gui/screens/tracks.stkgui
Normal file → Executable file
1
data/gui/screens/tracks.stkgui
Normal file → Executable file
@ -23,7 +23,6 @@
|
||||
wrap_around="true" />
|
||||
<spacer width="2%"/>
|
||||
<label id="lap-text" width="48%" I18N="In the track screen" text_align="left"/>
|
||||
<button id ="submit" width="20%" I18N="In the track screen" text="Submit" />
|
||||
</div>
|
||||
<spacer height="10"/>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "race/history.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/online/vote_overview.hpp"
|
||||
#include "states_screens/online/tracks_screen.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
@ -568,7 +568,7 @@ void MainLoop::renderGUI(int phase, int loop_index, int loop_size)
|
||||
|
||||
if (NetworkConfig::get()->isNetworking() && phase >= 5000)
|
||||
{
|
||||
VoteOverview::getInstance()->showVoteResult();
|
||||
TracksScreen::getInstance()->showVoteResult();
|
||||
}
|
||||
// TODO: remove debug output
|
||||
//Log::verbose("mainloop", "Rendergui t %llu dt %f phase %d index %d / %d",
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "network/stk_peer.hpp"
|
||||
#include "states_screens/online/networking_lobby.hpp"
|
||||
#include "states_screens/online/network_kart_selection.hpp"
|
||||
#include "states_screens/online/vote_overview.hpp"
|
||||
#include "states_screens/race_result_gui.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/online/tracks_screen.hpp"
|
||||
@ -122,7 +121,7 @@ void ClientLobby::setup()
|
||||
{
|
||||
clearPlayers();
|
||||
m_received_server_result = false;
|
||||
VoteOverview::getInstance()->resetVote();
|
||||
TracksScreen::getInstance()->resetVote();
|
||||
LobbyProtocol::setup();
|
||||
m_state.store(NONE);
|
||||
} // setup
|
||||
@ -244,7 +243,7 @@ void ClientLobby::addAllPlayers(Event* event)
|
||||
PeerVote winner_vote(data);
|
||||
|
||||
m_game_setup->setRace(winner_vote);
|
||||
VoteOverview::getInstance()->setResult(winner_vote);
|
||||
TracksScreen::getInstance()->setResult(winner_vote);
|
||||
|
||||
std::shared_ptr<STKPeer> peer = event->getPeerSP();
|
||||
peer->cleanPlayerProfiles();
|
||||
@ -465,8 +464,8 @@ void ClientLobby::receivePlayerVote(Event* event)
|
||||
if (!track)
|
||||
Log::fatal("ClientLobby", "Missing track %s", vote.m_track_name.c_str());
|
||||
|
||||
VoteOverview *overview = VoteOverview::getInstance();
|
||||
overview->addVote(host_id2);
|
||||
TracksScreen *ts = TracksScreen::getInstance();
|
||||
ts->addVote(host_id2);
|
||||
|
||||
} // receivePlayerVote
|
||||
|
||||
@ -678,7 +677,7 @@ void ClientLobby::updatePlayerList(Event* event)
|
||||
m_total_players = total_players;
|
||||
|
||||
NetworkingLobby::getInstance()->updatePlayers(players);
|
||||
VoteOverview::getInstance()->updateNumPlayers(players.size());
|
||||
TracksScreen::getInstance()->updateNumPlayers(players.size());
|
||||
} // updatePlayerList
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -858,8 +857,8 @@ void ClientLobby::startSelection(Event* event)
|
||||
screen->push();
|
||||
}
|
||||
|
||||
VoteOverview *overview = VoteOverview::getInstance();
|
||||
overview->resetVote();
|
||||
TracksScreen *ts = TracksScreen::getInstance();
|
||||
ts->resetVote();
|
||||
m_state.store(SELECTING_ASSETS);
|
||||
Log::info("ClientLobby", "Selection starts now");
|
||||
} // startSelection
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "network/protocols/client_lobby.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "states_screens/online/vote_overview.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/track_info_screen.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
@ -55,11 +54,12 @@ static const char ALL_TRACK_GROUPS_ID[] = "all";
|
||||
void TracksScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
if (name == "submit")
|
||||
if ((name == "lap-spinner" || name == "reverse") &&
|
||||
STKHost::existHost() && m_selected_track != NULL)
|
||||
{
|
||||
voteForPlayer();
|
||||
VoteOverview::getInstance()->push();
|
||||
}
|
||||
|
||||
else if (name == "tracks")
|
||||
{
|
||||
DynamicRibbonWidget* w2 = dynamic_cast<DynamicRibbonWidget*>(widget);
|
||||
@ -90,8 +90,8 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
selection = m_random_track_list.front();
|
||||
m_random_track_list.pop_front();
|
||||
m_random_track_list.push_back(selection);
|
||||
|
||||
} // selection=="random_track"
|
||||
|
||||
m_selected_track = track_manager->getTrack(selection);
|
||||
|
||||
if (m_selected_track)
|
||||
@ -99,6 +99,7 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
if (STKHost::existHost())
|
||||
{
|
||||
w2->setBadge(selection, OK_BADGE);
|
||||
voteForPlayer();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -512,3 +513,153 @@ void TracksScreen::onUpdate(float dt)
|
||||
m_timer->setValue(new_value * 100.0f);
|
||||
|
||||
} // 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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Stores the number of players. This can be used to determine how many
|
||||
* slotes for votes are required. This function is called from ClientLobby
|
||||
* upon an update from the server.
|
||||
* \param n New number of players that can vote.
|
||||
*/
|
||||
void TracksScreen::updateNumPlayers(int n)
|
||||
{
|
||||
m_max_num_votes = n;
|
||||
} //updateNumPlayers
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Selects in which part of the vote list the new host is being shown and
|
||||
* stores this information in the m_index_to_hostid mapping. If the host_id is
|
||||
* already mapped, this is ignored (this can happen in case one host changes
|
||||
* its vote.
|
||||
* \param host_id Index of the host that is voting.
|
||||
*/
|
||||
void TracksScreen::addVote(int host_id)
|
||||
{
|
||||
auto it = std::find(m_index_to_hostid.begin(), m_index_to_hostid.end(),
|
||||
host_id);
|
||||
|
||||
Log::verbose("TracksScreen", "addVote: hostid %d is new %d",
|
||||
host_id, it == m_index_to_hostid.end());
|
||||
|
||||
// Add a new index if this is the first vote for the host/
|
||||
if (it == m_index_to_hostid.end())
|
||||
{
|
||||
m_index_to_hostid.push_back(host_id);
|
||||
}
|
||||
|
||||
// If the screen is already shown, update the voting display
|
||||
if (GUIEngine::getCurrentScreen() == this)
|
||||
showVote(host_id);
|
||||
} // addVote
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Populates one entry in the voting list with the vote from the
|
||||
* corresponding host. A mapping of host_id to index MUST exist for this
|
||||
* host when this function is called.
|
||||
* \param host_id Host id from hich a new vote was received.
|
||||
*/
|
||||
void TracksScreen::showVote(int host_id)
|
||||
{
|
||||
auto it = std::find(m_index_to_hostid.begin(), m_index_to_hostid.end(),
|
||||
host_id);
|
||||
assert(it != m_index_to_hostid.end());
|
||||
|
||||
int index = it - m_index_to_hostid.begin();
|
||||
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
const PeerVote *vote = lp->getVote(host_id);
|
||||
assert(vote);
|
||||
|
||||
// This is the old code that needs to be updated for the new list display
|
||||
#ifdef OLD_DISPLAY
|
||||
std::string s = StringUtils::insertValues("name-%d", index);
|
||||
LabelWidget *name_widget = getWidget<LabelWidget>(s.c_str());
|
||||
name_widget->setText(_("Name: %s", vote->m_player_name), true);
|
||||
|
||||
s = StringUtils::insertValues("track-%d", index);
|
||||
IconButtonWidget *track_widget = getWidget<IconButtonWidget>(s.c_str());
|
||||
Track *track = track_manager->getTrack(vote->m_track_name);
|
||||
track_widget->setVisible(true);
|
||||
track_widget->setImage(track->getScreenshotFile());
|
||||
|
||||
s = StringUtils::insertValues("numlaps-%d", index);
|
||||
LabelWidget *laps_widget = getWidget<LabelWidget>(s.c_str());
|
||||
laps_widget->setText(_("Laps: %d", vote->m_num_laps), true);
|
||||
|
||||
s = StringUtils::insertValues("reverse-%d", index);
|
||||
LabelWidget *reverse_widget = getWidget<LabelWidget>(s.c_str());
|
||||
core::stringw yes = _("yes");
|
||||
core::stringw no = _("no");
|
||||
reverse_widget->setText(_("Reverse: %s", vote->m_reverse ? yes : no),
|
||||
true);
|
||||
#endif
|
||||
} // addVote
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Received the winning vote. i.e. the data about the track to play (including
|
||||
* #laps etc).
|
||||
*/
|
||||
void TracksScreen::setResult(const PeerVote &winner_vote)
|
||||
{
|
||||
// If the GUI is forced from the server lobby, m_timer is not defined
|
||||
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++)
|
||||
{
|
||||
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
|
||||
|
||||
} // setResult
|
||||
|
@ -20,15 +20,17 @@
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class PeerVote;
|
||||
class Track;
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class CheckBoxWidget;
|
||||
class CheckBoxWidget;
|
||||
class LabelWidget;
|
||||
class SpinnerWidget;
|
||||
@ -54,10 +56,20 @@ private:
|
||||
* (going backwards). */
|
||||
GUIEngine::ProgressBarWidget *m_timer;
|
||||
|
||||
/** Maximum number of votes, as sent by the server. */
|
||||
unsigned int m_max_num_votes;
|
||||
|
||||
bool m_network_tracks, m_reverse_checked, m_quit_server;
|
||||
|
||||
int m_bottom_box_height;
|
||||
|
||||
/** Index of the winning vote. */
|
||||
int m_winning_index;
|
||||
|
||||
/** This stores which vote (hostid) is shown at which index in
|
||||
* the vote overview list. */
|
||||
std::vector<int> m_index_to_hostid;
|
||||
|
||||
std::deque<std::string> m_random_track_list;
|
||||
|
||||
/** adds the tracks from the current track group into the tracks ribbon */
|
||||
@ -75,6 +87,12 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
void addVote(int host_id);
|
||||
void showVote(int host_id);
|
||||
void setResult(const PeerVote &winner_vote);
|
||||
void showVoteResult();
|
||||
void updateNumPlayers(int n);
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
||||
@ -103,6 +121,13 @@ public:
|
||||
void setNetworkTracks() { m_network_tracks = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setQuitServer() { m_quit_server = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Called at the beginning of the voting process to reset any previous
|
||||
* data fields. */
|
||||
void resetVote()
|
||||
{
|
||||
m_index_to_hostid.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,339 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009-2015 Marianne Gagnon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/online/vote_overview.hpp"
|
||||
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/progress_bar_widget.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/protocols/lobby_protocol.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/online/tracks_screen.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
VoteOverview::VoteOverview() : Screen("online/vote_overview.stkgui")
|
||||
{
|
||||
m_quit_server = false;
|
||||
m_timer = NULL;
|
||||
m_max_num_votes = 0;
|
||||
} // VoteOverview
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::loadedFromFile()
|
||||
{
|
||||
} // loadedFromFile
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::beforeAddingWidget()
|
||||
{
|
||||
Screen::init();
|
||||
|
||||
m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer");
|
||||
m_timer->showLabel(false);
|
||||
|
||||
Widget* rect_box = getWidget("rect-box");
|
||||
|
||||
rect_box->setVisible(true);
|
||||
rect_box->m_properties[GUIEngine::PROP_HEIGHT] = StringUtils::toString(rect_box->m_h);
|
||||
|
||||
calculateLayout();
|
||||
|
||||
RaceManager::MinorRaceModeType minor_mode = race_manager->getMinorMode();
|
||||
bool is_soccer = minor_mode == RaceManager::MINOR_MODE_SOCCER;
|
||||
bool is_arena = is_soccer || minor_mode == RaceManager::MINOR_MODE_BATTLE;
|
||||
|
||||
|
||||
} // beforeAddingWidget
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::init()
|
||||
{
|
||||
m_timer->setVisible(true);
|
||||
m_random_anim_timer = 0.0f;
|
||||
// change the back button image (because it makes the game quit)
|
||||
if (m_quit_server)
|
||||
{
|
||||
IconButtonWidget* back_button = getWidget<IconButtonWidget>("back");
|
||||
back_button->setImage("gui/icons/main_quit.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
IconButtonWidget* back_button = getWidget<IconButtonWidget>("back");
|
||||
back_button->setImage("gui/icons/back.png");
|
||||
}
|
||||
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
|
||||
for (unsigned int i = 0; i < 8; i++)
|
||||
{
|
||||
// Make all boxes visible (in case a previous voting screen
|
||||
// has made some invisible).
|
||||
std::string s = StringUtils::insertValues("rect-box%d", i);
|
||||
Widget *box = getWidget(s.c_str());
|
||||
box->setSelected(PLAYER_ID_GAME_MASTER, false);
|
||||
box->setVisible(i < m_max_num_votes);
|
||||
|
||||
// Make sure all track images are invisible initially (till we
|
||||
// receive a vote), otherwise a "?" is shown
|
||||
s = StringUtils::insertValues("track-%d", i);
|
||||
IconButtonWidget *track_widget = getWidget<IconButtonWidget>(s.c_str());
|
||||
track_widget->setVisible(false);
|
||||
}
|
||||
for(auto host_id: m_index_to_hostid)
|
||||
showVote(host_id);
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::tearDown()
|
||||
{
|
||||
m_quit_server = false;
|
||||
} // tearDown
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::updateNumPlayers(int n)
|
||||
{
|
||||
m_max_num_votes = n;
|
||||
|
||||
} //updateNumPlayers
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Selects in which part of the grid the new host is being shown and stores
|
||||
* this information in the m_index_to_hostid mapping. If the host_id is
|
||||
* already mapped, this is ignored (this can happen in case one host changes
|
||||
* its vote.
|
||||
* \param host_id Index of the host that is voting.
|
||||
*/
|
||||
void VoteOverview::addVote(int host_id)
|
||||
{
|
||||
auto it = std::find(m_index_to_hostid.begin(), m_index_to_hostid.end(),
|
||||
host_id);
|
||||
|
||||
Log::verbose("VO", "hostid %d new %d",
|
||||
host_id, it==m_index_to_hostid.end());
|
||||
|
||||
// Add a new index if this is the first vote for the host/
|
||||
if (it == m_index_to_hostid.end())
|
||||
{
|
||||
m_index_to_hostid.push_back(host_id);
|
||||
}
|
||||
|
||||
if(GUIEngine::getCurrentScreen() == this)
|
||||
showVote(host_id);
|
||||
|
||||
} // addVote
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Populates the one box in the voting screen with the vote from the
|
||||
* corresponding host. A mapping of host_id to index MUST exist for this
|
||||
* host.
|
||||
* \param host_id Host id from hich a new vote was received.
|
||||
*/
|
||||
void VoteOverview::showVote(int host_id)
|
||||
{
|
||||
auto it = std::find(m_index_to_hostid.begin(), m_index_to_hostid.end(),
|
||||
host_id);
|
||||
assert(it!=m_index_to_hostid.end());
|
||||
|
||||
int index = it - m_index_to_hostid.begin();
|
||||
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
const PeerVote *vote = lp->getVote(host_id);
|
||||
assert(vote);
|
||||
|
||||
std::string s = StringUtils::insertValues("name-%d", index);
|
||||
LabelWidget *name_widget = getWidget<LabelWidget>(s.c_str());
|
||||
name_widget->setText(_("Name: %s", vote->m_player_name), true);
|
||||
|
||||
s = StringUtils::insertValues("track-%d", index);
|
||||
IconButtonWidget *track_widget = getWidget<IconButtonWidget>(s.c_str());
|
||||
Track *track = track_manager->getTrack(vote->m_track_name);
|
||||
track_widget->setVisible(true);
|
||||
track_widget->setImage(track->getScreenshotFile());
|
||||
|
||||
s = StringUtils::insertValues("numlaps-%d", index);
|
||||
LabelWidget *laps_widget = getWidget<LabelWidget>(s.c_str());
|
||||
laps_widget->setText(_("Laps: %d", vote->m_num_laps), true);
|
||||
|
||||
s = StringUtils::insertValues("reverse-%d", index);
|
||||
LabelWidget *reverse_widget = getWidget<LabelWidget>(s.c_str());
|
||||
core::stringw yes = _("yes");
|
||||
core::stringw no = _("no");
|
||||
reverse_widget->setText(_("Reverse: %s", vote->m_reverse ? yes : no),
|
||||
true);
|
||||
|
||||
} // addVote
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::onUpdate(float dt)
|
||||
{
|
||||
// Show the remaining time:
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||
if (new_value < 0) new_value = 0;
|
||||
m_timer->setValue(new_value * 100);
|
||||
|
||||
if(m_index_to_hostid.size()==0) return;
|
||||
|
||||
// First make sure the old grid is set back to normal:
|
||||
int old_index = int(m_random_anim_timer) % m_index_to_hostid.size();
|
||||
std::string box_name = StringUtils::insertValues("rect-box%d", old_index);
|
||||
Widget *box = getWidget(box_name.c_str());
|
||||
box->setSelected(PLAYER_ID_GAME_MASTER, false);
|
||||
|
||||
// Increase timer, and determine next index to show
|
||||
m_random_anim_timer += 2*dt;
|
||||
int new_index = int(m_random_anim_timer) % m_index_to_hostid.size();
|
||||
box_name = StringUtils::insertValues("rect-box%d", new_index);
|
||||
box = getWidget(box_name.c_str());
|
||||
box->setSelected(PLAYER_ID_GAME_MASTER, true);
|
||||
} // onUpdate
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Received the winning vote. i.e. the data about the track to play (including
|
||||
* #laps etc).
|
||||
*/
|
||||
void VoteOverview::setResult(const PeerVote &winner_vote)
|
||||
{
|
||||
// If the GUI is forced from the server lobby, m_timer is not defined
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
} // winnind==-1
|
||||
} // setResult
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Called when the final 'random picking' animation is finished so that only
|
||||
* the result is shown: all boxes except the winner is set to be invisible.
|
||||
*/
|
||||
void VoteOverview::showVoteResult()
|
||||
{
|
||||
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
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Called on any event, e.g. user input.
|
||||
*/
|
||||
void VoteOverview::eventCallback(Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
if (name == "tracks")
|
||||
{
|
||||
DynamicRibbonWidget* w2 = dynamic_cast<DynamicRibbonWidget*>(widget);
|
||||
if (!w2) return;
|
||||
|
||||
std::string selection = w2->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (UserConfigParams::logGUI())
|
||||
{
|
||||
Log::info("VoteOverview", "Clicked on track '%s'.",
|
||||
selection.c_str());
|
||||
}
|
||||
|
||||
UserConfigParams::m_last_track = selection;
|
||||
if (selection == "locked" && race_manager->getNumLocalPlayers() == 1)
|
||||
{
|
||||
unlock_manager->playLockSound();
|
||||
return;
|
||||
}
|
||||
else if (selection == RibbonWidget::NO_ITEM_ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
} // name=="tracks"
|
||||
else if (name == "back")
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool VoteOverview::onEscapePressed()
|
||||
{
|
||||
if (m_quit_server)
|
||||
{
|
||||
// Remove this screen
|
||||
StateManager::get()->popMenu();
|
||||
STKHost::get()->shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ts = TracksScreen::getInstance();
|
||||
if (ts)
|
||||
ts->setNetworkTracks();
|
||||
}
|
||||
// remove the screen
|
||||
return true;
|
||||
} // onEscapePressed
|
||||
|
@ -1,106 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2018 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_VOTE_OVERVIEW_HPP
|
||||
#define HEADER_VOTE_OVERVIEW_HPP
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
|
||||
#include "network/peer_vote.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class ProgressBarWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief screen where the user can select a track
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class VoteOverview: public GUIEngine::Screen,
|
||||
public GUIEngine::ScreenSingleton<VoteOverview>
|
||||
{
|
||||
friend class GUIEngine::ScreenSingleton<VoteOverview>;
|
||||
|
||||
private:
|
||||
|
||||
/** Pointer to progress bar widget which is used as a timer
|
||||
* (going backwards). */
|
||||
GUIEngine::ProgressBarWidget *m_timer;
|
||||
|
||||
/** This stores which vote (hostid) is shown at which index in
|
||||
* the result gui. */
|
||||
std::vector<int> m_index_to_hostid;
|
||||
|
||||
/** Index of the winning vote. */
|
||||
int m_winning_index;
|
||||
|
||||
/** Maximum number of votes, as sent by the server. */
|
||||
unsigned int m_max_num_votes;
|
||||
|
||||
bool m_quit_server;
|
||||
|
||||
/* A timer used to randomly select tracks. */
|
||||
float m_random_anim_timer;
|
||||
|
||||
VoteOverview();
|
||||
|
||||
public:
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void eventCallback(GUIEngine::Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID) OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void init() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void tearDown() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual bool onEscapePressed() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void onUpdate(float dt) OVERRIDE;
|
||||
|
||||
void addVote(int host_id);
|
||||
void showVote(int host_id);
|
||||
void showVoteResult();
|
||||
void setResult(const PeerVote &winner_vote);
|
||||
void updateNumPlayers(int n);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void setQuitServer() { m_quit_server = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
void resetVote()
|
||||
{
|
||||
m_index_to_hostid.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user