Display MapView in the free floating camera spectating mode

Fixes #682 partially.
This commit is contained in:
yvt 2017-12-29 19:06:10 +09:00
parent 9f464d718d
commit ff2b6587a1
2 changed files with 43 additions and 29 deletions

View File

@ -345,8 +345,11 @@ namespace spades {
void Draw2DWithoutWorld(); void Draw2DWithoutWorld();
void Draw2DWithWorld(); void Draw2DWithWorld();
/** Called when the local plyaer is alive. */
void DrawJoinedAlivePlayerHUD(); void DrawJoinedAlivePlayerHUD();
/** Called when the local plyaer is dead. */
void DrawDeadPlayerHUD(); void DrawDeadPlayerHUD();
/** Called when the local plyaer is a spectator. */
void DrawSpectateHUD(); void DrawSpectateHUD();
void DrawHottrackedPlayerName(); void DrawHottrackedPlayerName();

View File

@ -241,13 +241,35 @@ namespace spades {
if (!world) if (!world)
return; return;
if (!HasTargetPlayer(client->GetCameraMode())) { // The player to focus on
// Do not display `MapView` until the player is joined and there is a player to Player *focusPlayerPtr = nullptr;
// focus Vector3 focusPlayerPos;
float focusPlayerAngle;
if (HasTargetPlayer(client->GetCameraMode())) {
Player &player = client->GetCameraTargetPlayer();
Vector3 front = player.GetFront2D();
focusPlayerPos = player.GetPosition();
focusPlayerAngle = atan2(front.x, -front.y);
focusPlayerPtr = &player;
} else if (client->GetCameraMode() == ClientCameraMode::Free) {
focusPlayerPos = client->freeCameraState.position;
focusPlayerAngle = client->followAndFreeCameraState.yaw - static_cast<float>(M_PI) * .5f;
focusPlayerPtr = world->GetLocalPlayer();
} else {
return; return;
} }
Player &player = client->GetCameraTargetPlayer(); // The local player (this is important for access control)
if (!world->GetLocalPlayer()) {
return;
}
Player &localPlayer = *world->GetLocalPlayer();
SPAssert(targetOrLocalPlayer);
Player &focusPlayer = *focusPlayerPtr;
if (largeMap) if (largeMap)
if (zoomState < .0001f) if (zoomState < .0001f)
@ -256,12 +278,7 @@ namespace spades {
GameMap *map = world->GetMap(); GameMap *map = world->GetMap();
Vector2 mapSize = MakeVector2(map->Width(), map->Height()); Vector2 mapSize = MakeVector2(map->Width(), map->Height());
Vector3 pos = player.GetPosition(); Vector2 center = {focusPlayerPos.x, focusPlayerPos.y};
if (player.IsSpectator()) {
pos = client->freeCameraState.position;
}
Vector2 center = {pos.x, pos.y};
float cfgMapSize = cg_minimapSize; float cfgMapSize = cg_minimapSize;
if (cfgMapSize < 32) if (cfgMapSize < 32)
cfgMapSize = 32; cfgMapSize = 32;
@ -463,37 +480,31 @@ namespace spades {
Vector4 teamColorF = ModifyColor(teamColor); Vector4 teamColorF = ModifyColor(teamColor);
teamColorF *= alpha; teamColorF *= alpha;
// Draw the local player's view // Draw the focused player's view
{ {
Handle<IImage> viewIcon = renderer->RegisterImage("Gfx/Map/View.png"); Handle<IImage> viewIcon = renderer->RegisterImage("Gfx/Map/View.png");
if (player.IsAlive()) { if (focusPlayer.IsAlive()) {
Vector3 front = player.GetFront2D();
float ang;
if (player.IsSpectator()) {
ang = client->followAndFreeCameraState.yaw - static_cast<float>(M_PI) * .5f;
} else {
ang = atan2(front.x, -front.y);
}
renderer->SetColorAlphaPremultiplied(teamColorF * 0.9f); renderer->SetColorAlphaPremultiplied(teamColorF * 0.9f);
DrawIcon(focusPlayerPos, viewIcon, focusPlayerAngle);
DrawIcon(player.IsSpectator() ? client->freeCameraState.position : player.GetPosition(),
viewIcon, ang);
} }
} }
// draw player's icon // draw player's icon
for (int i = 0; i < world->GetNumPlayerSlots(); i++) { for (int i = 0; i < world->GetNumPlayerSlots(); i++) {
Player *p = world->GetPlayer(i); Player *p = world->GetPlayer(i);
if (p == nullptr || if (!p || !p->IsAlive()) {
(p->GetTeamId() != world->GetLocalPlayer()->GetTeamId() && !player.IsSpectator()) || // The player is non-existent or dead
!p->IsAlive())
continue; continue;
}
if (!localPlayer.IsSpectator() && localPlayer.GetTeamId() != p->GetTeamId()) {
// Duh
continue;
}
Vector3 front = p->GetFront2D(); Vector3 front = p->GetFront2D();
float ang = atan2(front.x, -front.y); float ang = atan2(front.x, -front.y);
if (p->IsSpectator()) { if (p == &focusPlayer && p->IsSpectator()) {
ang = client->followAndFreeCameraState.yaw - static_cast<float>(M_PI) * .5f; ang = focusPlayerAngle;
} }
// use a spec color for each player // use a spec color for each player
@ -528,7 +539,7 @@ namespace spades {
playerShotgun, ang); playerShotgun, ang);
} }
} else { // draw normal color } else { // draw normal color
DrawIcon(p->IsSpectator() ? client->freeCameraState.position : p->GetPosition(), DrawIcon(p == &focusPlayer ? focusPlayerPos : p->GetPosition(),
playerIcon, ang); playerIcon, ang);
} }
} }