Make network tracks screen usable for all game modes

This commit is contained in:
Benau 2018-07-14 00:40:53 +08:00
parent 49d7a2fbbc
commit 9fbfe0588f
5 changed files with 96 additions and 15 deletions

View File

@ -373,6 +373,9 @@ namespace UserConfigParams
PARAM_PREFIX BoolUserConfigParam m_soccer_use_time_limit
PARAM_DEFAULT( BoolUserConfigParam(false, "soccer-use-time-limit",
&m_race_setup_group, "Enable time limit in soccer mode.") );
PARAM_PREFIX BoolUserConfigParam m_random_arena_item
PARAM_DEFAULT( BoolUserConfigParam(false, "random-arena-item",
&m_race_setup_group, "Enable random location of items in an arena.") );
PARAM_PREFIX IntUserConfigParam m_difficulty
PARAM_DEFAULT( IntUserConfigParam(0, "difficulty",
&m_race_setup_group,
@ -638,9 +641,6 @@ namespace UserConfigParams
/** If track debugging is enabled. */
PARAM_PREFIX int m_track_debug PARAM_DEFAULT( false );
/** If random number of items is used in an arena. */
PARAM_PREFIX bool m_random_arena_item PARAM_DEFAULT( false );
/** True if check structures should be debugged. */
PARAM_PREFIX bool m_check_debug PARAM_DEFAULT( false );

View File

@ -77,6 +77,8 @@ void GameSetup::update(bool remove_disconnected_players)
//-----------------------------------------------------------------------------
void GameSetup::loadWorld()
{
// Notice: for arena (battle / soccer) lap and reverse will be mapped to
// goals / time limit and random item location
assert(!m_tracks.empty());
// Disable accidentally unlocking of a challenge
if (PlayerManager::getCurrentPlayer())

View File

@ -407,9 +407,36 @@ void ClientLobby::displayPlayerVote(Event* event)
int rev = data.getUInt8();
core::stringw yes = _("Yes");
core::stringw no = _("No");
//I18N: Vote message in network game from a player
core::stringw vote_msg = _("Track: %s,\nlaps: %d, reversed: %s",
track_readable, lap, rev == 1 ? yes : no);
core::stringw vote_msg;
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_3_STRIKES)
{
//I18N: Vote message in network game from a player
vote_msg = _("Track: %s,\nrandom item location: %s",
track_readable, rev == 1 ? yes : no);
}
else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
if (m_game_setup->isSoccerGoalTarget())
{
//I18N: Vote message in network game from a player
vote_msg = _("Track: %s,\n"
"number of goals to win: %d,\nrandom item location: %s",
track_readable, lap, rev == 1 ? yes : no);
}
else
{
//I18N: Vote message in network game from a player
vote_msg = _("Track: %s,\n"
"maximum time: %d,random item location: %s",
track_readable, lap, rev == 1 ? yes : no);
}
}
else
{
//I18N: Vote message in network game from a player
vote_msg = _("Track: %s,\nlaps: %d, reversed: %s",
track_readable, lap, rev == 1 ? yes : no);
}
vote_msg = StringUtils::utf8ToWide(player_name) + vote_msg;
TracksScreen::getInstance()->addVoteMessage(player_name +
StringUtils::toString(host_id), vote_msg);

View File

@ -225,6 +225,10 @@ void TrackInfoScreen::init()
{
m_option->setState(race_manager->getReverseTrack());
}
else if (random_item)
{
m_option->setState(UserConfigParams::m_random_arena_item);
}
else
m_option->setState(false);

View File

@ -30,6 +30,7 @@
#include "guiengine/widgets/label_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"
@ -161,17 +162,14 @@ void TracksScreen::beforeAddingWidget()
rect_box->setVisible(true);
rect_box->m_properties[GUIEngine::PROP_HEIGHT] = StringUtils::toString(m_bottom_box_height);
getWidget("lap-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("lap-text")->setText(_("Number of laps"), false);
m_laps = getWidget<SpinnerWidget>("lap-spinner");
assert(m_laps != NULL);
m_laps->setVisible(true);
getWidget("reverse-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("reverse-text")->setText(_("Drive in reverse"), false);
m_reversed = getWidget<CheckBoxWidget>("reverse");
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();
@ -253,13 +251,59 @@ void TracksScreen::init()
STKTexManager::getInstance()->unsetTextureErrorMessage();
if (m_network_tracks)
{
// Notice: for arena (battle / soccer) lap and reverse will be mapped to
// goals / time limit and random item location
if (UserConfigParams::m_num_laps == 0 ||
UserConfigParams::m_num_laps > 20)
UserConfigParams::m_num_laps = 1;
m_laps->setValue(UserConfigParams::m_num_laps);
m_reversed->setState(m_reverse_checked);
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_3_STRIKES)
{
getWidget("lap-text")->setVisible(false);
m_laps->setVisible(false);
getWidget("reverse-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("reverse-text")->setText(_("Random item location"), false);
m_reversed->setVisible(true);
m_reversed->setState(UserConfigParams::m_random_arena_item);
}
else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
m_laps->setVisible(true);
getWidget("lap-text")->setVisible(true);
auto cl = LobbyProtocol::get<ClientLobby>();
assert(cl);
if (cl->getGameSetup()->isSoccerGoalTarget())
{
//I18N: In track screen
getWidget<LabelWidget>("lap-text")->setText(_("Number of goals to win"), false);
m_laps->setValue(UserConfigParams::m_num_goals);
}
else
{
//I18N: In track screen
getWidget<LabelWidget>("lap-text")->setText(_("Maximum time (min.)"), false);
m_laps->setValue(UserConfigParams::m_soccer_time_limit);
}
getWidget("reverse-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("reverse-text")->setText(_("Random item location"), false);
m_reversed->setVisible(true);
m_reversed->setState(UserConfigParams::m_random_arena_item);
}
else
{
getWidget("lap-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("lap-text")->setText(_("Number of laps"), false);
m_laps->setVisible(true);
m_laps->setValue(UserConfigParams::m_num_laps);
getWidget("reverse-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("reverse-text")->setText(_("Drive in reverse"), false);
m_reversed->setVisible(true);
m_reversed->setState(m_reverse_checked);
}
}
if (NetworkConfig::get()->isAutoConnect() && m_network_tracks)
{
assert(!m_random_track_list.empty());
@ -371,8 +415,12 @@ void TracksScreen::voteForPlayer()
assert(m_selected_track);
assert(m_laps);
assert(m_reversed);
// Remember reverse globally for each stk instance
m_reverse_checked = m_reversed->getState();
// Remember reverse globally for each stk instance if not arena
if (race_manager->getMinorMode() != RaceManager::MINOR_MODE_3_STRIKES &&
race_manager->getMinorMode() != RaceManager::MINOR_MODE_SOCCER)
m_reverse_checked = m_reversed->getState();
else
UserConfigParams::m_random_arena_item = m_reversed->getState();
UserConfigParams::m_num_laps = m_laps->getValue();
NetworkString vote(PROTOCOL_LOBBY_ROOM);
vote.addUInt8(LobbyProtocol::LE_VOTE);