Add remaining time to vote message

This commit is contained in:
Benau 2018-03-16 12:45:38 +08:00
parent cf898c2795
commit d6936c5746
4 changed files with 15 additions and 6 deletions

View File

@ -101,7 +101,7 @@ private:
public:
TextMessage(MessageQueue::MessageType mt, const core::stringw &message) :
Message(5.0f)
Message(mt == MessageQueue::MT_NETWORK_MSG ? 1.0f : 5.0f)
{
m_message_type = mt;
m_message = message;
@ -111,7 +111,8 @@ public:
m_render_type = "achievement-message::neutral";
else if (mt == MessageQueue::MT_ERROR)
m_render_type = "error-message::neutral";
else if (mt == MessageQueue::MT_GENERIC)
else if (mt == MessageQueue::MT_GENERIC ||
mt == MessageQueue::MT_NETWORK_MSG)
m_render_type = "generic-message::neutral";
else
m_render_type = "friend-message::neutral";

View File

@ -40,6 +40,7 @@ namespace MessageQueue
MT_ACHIEVEMENT,
MT_ERROR,
MT_GENERIC,
MT_NETWORK_MSG,
MT_PROGRESS
};

View File

@ -295,13 +295,14 @@ void ClientLobby::displayPlayerVote(Event* event)
core::stringw track_readable = track->getName();
int lap = data.getUInt8();
bool reversed = (bool)data.getUInt8();
int t = 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, Laps: %d, Reversed: %s",
track_readable, lap, reversed ? yes : no);
core::stringw vote_msg = _("Track: %s, laps: %d, reversed: %s, "
"remaining time: %ds", track_readable, lap, reversed ? yes : no, t);
vote_msg = player_name + vote_msg;
MessageQueue::add(MessageQueue::MT_GENERIC, vote_msg);
MessageQueue::add(MessageQueue::MT_NETWORK_MSG, vote_msg);
} // displayPlayerVote
//-----------------------------------------------------------------------------

View File

@ -1000,9 +1000,15 @@ void ServerLobby::playerVote(Event* event)
other.addUInt8(LE_VOTE).encodeString(event->getPeer()
->getPlayerProfiles()[0]->getName());
other += data;
// Check if first vote, if so start counter (10 seconds voting time)
if (m_timeout == std::numeric_limits<float>::max())
m_timeout = (float)StkTime::getRealTime() + 10.0f;
float remaining_time = m_timeout - (float)StkTime::getRealTime();
if (remaining_time < 0.0f)
remaining_time = 0.0f;
other.addUInt8((uint8_t)remaining_time);
sendMessageToPeersChangingToken(&other);
// Save the vote
} // playerVote
// ----------------------------------------------------------------------------