Add left or right player action to change spectating target
This commit is contained in:
parent
66794781fe
commit
214272468d
@ -38,6 +38,7 @@
|
||||
#include "modes/profile_world.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/protocols/client_lobby.hpp"
|
||||
#include "network/rewind_manager.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
#include "race/history.hpp"
|
||||
@ -806,6 +807,28 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
|
||||
|
||||
if (pk == NULL)
|
||||
{
|
||||
if (auto cl = LobbyProtocol::get<ClientLobby>())
|
||||
{
|
||||
Camera* cam = Camera::getActiveCamera();
|
||||
if (cl->isSpectator() && cam)
|
||||
{
|
||||
// Network spectating handling
|
||||
int current_idx = 0;
|
||||
if (cam->getKart())
|
||||
current_idx = cam->getKart()->getWorldKartId();
|
||||
if (action == PA_STEER_LEFT && value == 0)
|
||||
current_idx = ++current_idx % World::getWorld()->getNumKarts();
|
||||
else if (action == PA_STEER_RIGHT && value == 0)
|
||||
{
|
||||
if (current_idx == 0)
|
||||
current_idx = World::getWorld()->getNumKarts() - 1;
|
||||
else
|
||||
current_idx = --current_idx;
|
||||
}
|
||||
cam->setKart(World::getWorld()->getKart(current_idx));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Log::error("InputManager::dispatchInput", "Trying to process "
|
||||
"action for an unknown player");
|
||||
return;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/message_queue.hpp"
|
||||
#include "guiengine/screen_keyboard.hpp"
|
||||
@ -280,14 +281,21 @@ void ClientLobby::addAllPlayers(Event* event)
|
||||
// Disable until render gui during loading is bug free
|
||||
//StateManager::get()->enterGameState();
|
||||
|
||||
// Live join if state is CONNECTED
|
||||
// Live join or spectate if state is CONNECTED
|
||||
if (m_state.load() == CONNECTED)
|
||||
{
|
||||
World* w = World::getWorld();
|
||||
w->setLiveJoinWorld(true);
|
||||
Camera* cam = Camera::getActiveCamera();
|
||||
for (unsigned i = 0; i < w->getNumKarts(); i++)
|
||||
{
|
||||
AbstractKart* k = w->getKart(i);
|
||||
// Change spectating target to first non-eliminated kart
|
||||
if (isSpectator() && cam && !k->isEliminated())
|
||||
{
|
||||
cam->setKart(k);
|
||||
cam = NULL;
|
||||
}
|
||||
// The final joining ticks will be set by server later
|
||||
if (k->getController()->isLocalPlayerController())
|
||||
k->setLiveJoinKart(std::numeric_limits<int>::max());
|
||||
@ -960,7 +968,7 @@ void ClientLobby::backToLobby(Event *event)
|
||||
{
|
||||
case BLR_NO_GAME_FOR_LIVE_JOIN:
|
||||
// I18N: Error message shown if live join failed in network
|
||||
msg = _("No more game is available for live join.");
|
||||
msg = _("No more game is available for live join or spectating.");
|
||||
break;
|
||||
case BLR_NO_PLACE_FOR_LIVE_JOIN:
|
||||
// I18N: Error message shown if live join failed in network
|
||||
@ -988,7 +996,7 @@ void ClientLobby::backToLobby(Event *event)
|
||||
void ClientLobby::finishedLoadingWorld()
|
||||
{
|
||||
NetworkString* ns = getNetworkString(1);
|
||||
// Live join if state is CONNECTED
|
||||
// Live join or spectate if state is CONNECTED
|
||||
ns->setSynchronous(m_state.load() == CONNECTED);
|
||||
ns->addUInt8(LE_CLIENT_LOADED_WORLD);
|
||||
sendToServer(ns, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user