Added 'voting result' screen, though it does not have any functionality atm.
This commit is contained in:
parent
772e2fb3f5
commit
fa7d3eef73
@ -2,7 +2,7 @@
|
||||
<stkgui>
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/icons/back.png"/>
|
||||
|
||||
<div id="all-track" x="1%" y="1%" width="60%" height="96%" layout="vertical-row" >
|
||||
<div id="all-track" x="1%" y="1%" width="98%" height="96%" layout="vertical-row" >
|
||||
<header width="80%" I18N="In the track selection screen" text="All Tracks"
|
||||
align="center" text_align="center" />
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
<spinner id="lap-spinner" width="20%" min_value="1" max_value="20" align="center"
|
||||
wrap_around="true" />
|
||||
<spacer width="2%"/>
|
||||
<label id="lap-text" width="78%" I18N="In the track screen" text_align="left"/>
|
||||
<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" >
|
||||
@ -33,12 +34,6 @@
|
||||
<label id="reverse-text" width="78%" I18N="In the track screen" text_align="left"/>
|
||||
</div>
|
||||
</box>
|
||||
</div>
|
||||
<div id="vote" x="63%" y="1%" width="37%" height="96%" layout="vertical-row">
|
||||
<div width="95%" proportion="2" layout="horizontal-row">
|
||||
<box proportion="2" height="100%" layout="vertical-row">
|
||||
<label id="vote-text" word_wrap="true" proportion="3" width="100%" height="100%" text_valign="top"/>
|
||||
</box>
|
||||
</div>
|
||||
<progressbar id="timer" height="4%" width="100%"></progressbar>
|
||||
</div>
|
||||
</stkgui>
|
||||
|
@ -28,12 +28,14 @@
|
||||
#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 "guiengine/widgets/spinner_widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#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"
|
||||
@ -59,6 +61,10 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
voteForPlayer();
|
||||
}
|
||||
else if (name == "submit")
|
||||
{
|
||||
VoteOverview::getInstance()->push();
|
||||
}
|
||||
else if (name == "tracks")
|
||||
{
|
||||
DynamicRibbonWidget* w2 = dynamic_cast<DynamicRibbonWidget*>(widget);
|
||||
@ -151,7 +157,6 @@ void TracksScreen::loadedFromFile()
|
||||
{
|
||||
m_reversed = NULL;
|
||||
m_laps = NULL;
|
||||
m_votes = NULL;
|
||||
} // loadedFromFile
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -159,6 +164,9 @@ void TracksScreen::beforeAddingWidget()
|
||||
{
|
||||
Screen::init();
|
||||
|
||||
m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer");
|
||||
m_timer->showLabel(false);
|
||||
|
||||
Widget* rect_box = getWidget("rect-box");
|
||||
|
||||
if (m_bottom_box_height == -1)
|
||||
@ -177,18 +185,7 @@ void TracksScreen::beforeAddingWidget()
|
||||
assert(m_reversed != NULL);
|
||||
m_reversed->m_properties[GUIEngine::PROP_ALIGN] = "center";
|
||||
m_reversed->setVisible(true);
|
||||
getWidget("all-track")->m_properties[GUIEngine::PROP_WIDTH] = "60%";
|
||||
getWidget("vote")->setVisible(true);
|
||||
calculateLayout();
|
||||
static bool shown_msg = false;
|
||||
if (!shown_msg)
|
||||
{
|
||||
shown_msg = true;
|
||||
//I18N: In track screen for networking, clarify voting phase
|
||||
core::stringw msg = _("If a majority of players all select the"
|
||||
" same track and race settings, voting will end early.");
|
||||
MessageQueue::add(MessageQueue::MT_GENERIC, msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -200,12 +197,8 @@ void TracksScreen::beforeAddingWidget()
|
||||
getWidget("lap-spinner")->setVisible(false);
|
||||
getWidget("reverse-text")->setVisible(false);
|
||||
getWidget("reverse")->setVisible(false);
|
||||
getWidget("all-track")->m_properties[GUIEngine::PROP_WIDTH] = "98%";
|
||||
getWidget("vote")->setVisible(false);
|
||||
calculateLayout();
|
||||
}
|
||||
m_votes = getWidget<LabelWidget>("vote-text");
|
||||
m_votes->setVisible(false);
|
||||
|
||||
RibbonWidget* tabs = getWidget<RibbonWidget>("trackgroups");
|
||||
tabs->clearAllChildren();
|
||||
@ -489,27 +482,9 @@ void TracksScreen::onUpdate(float dt)
|
||||
// The following code
|
||||
if(!m_network_tracks) return;
|
||||
|
||||
assert(m_votes);
|
||||
|
||||
m_votes->setVisible(true);
|
||||
auto cl = LobbyProtocol::get<LobbyProtocol>();
|
||||
|
||||
int remaining_time = cl->getRemainingVotingTime();
|
||||
if (remaining_time < 0) remaining_time = 0;
|
||||
|
||||
//I18N: In tracks screen, about voting of tracks in network
|
||||
core::stringw message = _("Remaining time: %d", remaining_time);
|
||||
message += L"\n";
|
||||
unsigned height = GUIEngine::getFont()->getDimension(L"X").Height;
|
||||
const unsigned total_height = m_votes->getDimension().Height;
|
||||
for (auto& p : m_vote_messages)
|
||||
{
|
||||
height += GUIEngine::getFont()->getDimension(L"X").Height * 2;
|
||||
if (height > total_height)
|
||||
break;
|
||||
message += p.second;
|
||||
message += L"\n";
|
||||
}
|
||||
m_votes->setText(message, true);
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||
if (new_value < 0) new_value = 0;
|
||||
m_timer->moveValue(int(new_value * 100));
|
||||
|
||||
} // onUpdate
|
||||
|
@ -44,26 +44,19 @@ class TracksScreen : public GUIEngine::Screen,
|
||||
friend class GUIEngine::ScreenSingleton<TracksScreen>;
|
||||
|
||||
private:
|
||||
TracksScreen() : Screen("tracks.stkgui")
|
||||
{
|
||||
m_network_tracks = false;
|
||||
m_reverse_checked = false;
|
||||
m_quit_server = false;
|
||||
m_bottom_box_height = -1;
|
||||
m_vote_timeout = std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
|
||||
Track* m_selected_track = NULL;
|
||||
GUIEngine::CheckBoxWidget* m_reversed;
|
||||
GUIEngine::SpinnerWidget* m_laps;
|
||||
GUIEngine::LabelWidget* m_votes;
|
||||
|
||||
/** Pointer to progress bar widget which is used as a timer
|
||||
* (going backwards). */
|
||||
GUIEngine::ProgressBarWidget *m_timer;
|
||||
|
||||
bool m_network_tracks, m_reverse_checked, m_quit_server;
|
||||
|
||||
int m_bottom_box_height;
|
||||
|
||||
uint64_t m_vote_timeout;
|
||||
|
||||
std::map<std::string, core::stringw> m_vote_messages;
|
||||
|
||||
std::deque<std::string> m_random_track_list;
|
||||
@ -73,6 +66,14 @@ private:
|
||||
|
||||
void voteForPlayer();
|
||||
|
||||
TracksScreen() : Screen("tracks.stkgui")
|
||||
{
|
||||
m_network_tracks = false;
|
||||
m_reverse_checked = false;
|
||||
m_quit_server = false;
|
||||
m_bottom_box_height = -1;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
|
181
src/states_screens/online/vote_overview.cpp
Normal file
181
src/states_screens/online/vote_overview.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
// 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 "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/message_queue.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/check_box_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 "guiengine/widgets/spinner_widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/protocols/client_lobby.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/track_info_screen.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
|
||||
static const char ALL_TRACK_GROUPS_ID[] = "all";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** 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;
|
||||
}
|
||||
|
||||
if (selection == "random_track")
|
||||
{
|
||||
if (m_random_track_list.empty()) return;
|
||||
|
||||
selection = m_random_track_list.front();
|
||||
m_random_track_list.pop_front();
|
||||
m_random_track_list.push_back(selection);
|
||||
|
||||
} // selection=="random_track"
|
||||
|
||||
} // 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 cl = LobbyProtocol::get<ClientLobby>();
|
||||
if (cl)
|
||||
cl->clearPlayers();
|
||||
}
|
||||
// remove the screen
|
||||
return true;
|
||||
} // onEscapePressed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::tearDown()
|
||||
{
|
||||
m_quit_server = false;
|
||||
} // tearDown
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
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");
|
||||
|
||||
if (m_bottom_box_height == -1)
|
||||
m_bottom_box_height = rect_box->m_h;
|
||||
|
||||
rect_box->setVisible(true);
|
||||
rect_box->m_properties[GUIEngine::PROP_HEIGHT] = StringUtils::toString(m_bottom_box_height);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
//DynamicRibbonWidget* tracks_widget = getWidget<DynamicRibbonWidget>("tracks");
|
||||
//tracks_widget->setItemCountHint( (int)track_manager->getNumberOfTracks()+1 );
|
||||
|
||||
} // beforeAddingWidget
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::init()
|
||||
{
|
||||
// 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");
|
||||
}
|
||||
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void VoteOverview::onUpdate(float dt)
|
||||
{
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||
if (new_value < 0) new_value = 0;
|
||||
m_timer->moveValue(int(new_value * 100));
|
||||
|
||||
} // onUpdate
|
105
src/states_screens/online/vote_overview.hpp
Normal file
105
src/states_screens/online/vote_overview.hpp
Normal file
@ -0,0 +1,105 @@
|
||||
// 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 "utils/synchronised.hpp"
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class CheckBoxWidget;
|
||||
class LabelWidget;
|
||||
class SpinnerWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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;
|
||||
|
||||
bool m_reverse_checked, m_quit_server;
|
||||
|
||||
int m_bottom_box_height;
|
||||
|
||||
std::map<std::string, core::stringw> m_vote_messages;
|
||||
|
||||
std::deque<std::string> m_random_track_list;
|
||||
|
||||
VoteOverview() : Screen("online/vote_overview.stkgui")
|
||||
{
|
||||
m_reverse_checked = false;
|
||||
m_quit_server = false;
|
||||
m_bottom_box_height = -1;
|
||||
}
|
||||
|
||||
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 setQuitServer() { m_quit_server = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
void resetVote()
|
||||
{
|
||||
m_vote_messages.clear();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void addVoteMessage(const std::string& user,
|
||||
const irr::core::stringw& message)
|
||||
{
|
||||
m_vote_messages[user] = message;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user