Skip to content

Commit

Permalink
Fix spectator display and keyboard input
Browse files Browse the repository at this point in the history
- Fixes yvt#681 (Pressing space while in free-camera mode does not move up).
- Fixes yvt#678 (Have seconday fire cycle through the player list backwards
  in sepctator mode).
- "Stop following a player" is bound to "R" (reload) by default.
- Add help messages displayed on the screen.
  • Loading branch information
yvt committed Dec 29, 2017
1 parent 38ad676 commit 4bd819a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 28 deletions.
7 changes: 5 additions & 2 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,18 @@ namespace spades {
void DrawJoinedAlivePlayerHUD();
/** Called when the local plyaer is dead. */
void DrawDeadPlayerHUD();
/** Called when the local plyaer is a spectator. */
void DrawSpectateHUD();

/**
* Called when `IsFirstPerson(GetCameraMode()).` Renders the follwing element:
* - The center reticule
*/
void DrawFirstPersonHUD();

/**
* Called when the local player is dead or a spectator.
*/
void DrawSpectateHUD();

void DrawHottrackedPlayerName();
void DrawHurtScreenEffect();
void DrawHurtSprites();
Expand Down
83 changes: 60 additions & 23 deletions Sources/Client/Client_Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
DEFINE_SPADES_SETTING(cg_hitIndicator, "1");
DEFINE_SPADES_SETTING(cg_debugAim, "0");
SPADES_SETTING(cg_keyReloadWeapon);
SPADES_SETTING(cg_keyJump);
SPADES_SETTING(cg_keyAttack);
SPADES_SETTING(cg_keyAltAttack);
SPADES_SETTING(cg_keyCrouch);
DEFINE_SPADES_SETTING(cg_screenshotFormat, "jpeg");
DEFINE_SPADES_SETTING(cg_stats, "0");
DEFINE_SPADES_SETTING(cg_hideHud, "0");
Expand All @@ -85,6 +89,18 @@ namespace spades {
SPRaise("Invalid screenshot format: %s", cg_screenshotFormat.CString());
}
}

std::string TranslateKeyName(const std::string &name) {
if (name == "LeftMouseButton") {
return "LMB";
} else if (name == "RightMouseButton") {
return "RMB";
} else if (name.empty()) {
return _Tr("Client", "Unbound");
} else {
return name;
}
}
}

void Client::TakeScreenShot(bool sceneOnly) {
Expand Down Expand Up @@ -546,7 +562,7 @@ namespace spades {
} else if (weap->GetStock() > 0 &&
weap->GetAmmo() < weap->GetClipSize() / 4) {
msg = _Tr("Client", "Press [{0}] to Reload",
(std::string)cg_keyReloadWeapon);
TranslateKeyName(cg_keyReloadWeapon));
}
} break;
default:;
Expand Down Expand Up @@ -602,19 +618,55 @@ namespace spades {
MakeVector4(0, 0, 0, 0.5));
}
}

// draw map
mapView->Draw();
}
}

void Client::DrawSpectateHUD() {
SPADES_MARK_FUNCTION();

if (!cg_hideHud) {
// draw map
mapView->Draw();
if (cg_hideHud) {
return;
}

IFont &font = *fontManager->GetGuiFont();
float scrWidth = renderer->ScreenWidth();

float textX = scrWidth - 8.0f;
float textY = 256.0f + 32.0f;

auto addLine = [&](const std::string &text) {
Vector2 size = font.Measure(text);
Vector2 pos = MakeVector2(textX, textY);
pos.x -= size.x;
textY += 20.0f;
font.DrawShadow(text, pos, 1.f, MakeVector4(1, 1, 1, 1),
MakeVector4(0, 0, 0, 0.5));
};

if (HasTargetPlayer(GetCameraMode())) {
addLine(_Tr("Client", "Following {0}",
world->GetPlayerPersistent(GetCameraTargetPlayerId()).name));
}

textY += 10.0f;

// Help messages (make sure to synchronize these with the keyboard input handler)
if (FollowsNonLocalPlayer(GetCameraMode())) {
addLine(_Tr("Client", "[{0}] Cycle camera mode", TranslateKeyName(cg_keyJump)));
addLine(_Tr("Client", "[{0}/{1}] Next/previous player", TranslateKeyName(cg_keyAttack), TranslateKeyName(cg_keyAltAttack)));

if (GetWorld()->GetLocalPlayer()->IsSpectator()) {
addLine(_Tr("Client", "[{0}] Unfollow", TranslateKeyName(cg_keyReloadWeapon)));
}
} else {
addLine(_Tr("Client", "[{0}/{1}] Follow a player", TranslateKeyName(cg_keyAttack), TranslateKeyName(cg_keyAltAttack)));
}

if (GetCameraMode() == ClientCameraMode::Free) {
addLine(_Tr("Client", "[{0}/{1}] Go up/down", TranslateKeyName(cg_keyJump), TranslateKeyName(cg_keyCrouch)));
}

mapView->Draw();
}

void Client::DrawAlert() {
Expand Down Expand Up @@ -735,11 +787,6 @@ namespace spades {
void Client::Draw2DWithWorld() {
SPADES_MARK_FUNCTION();

float scrWidth = renderer->ScreenWidth();
// float scrHeight = renderer->ScreenHeight();
IFont *font;
// float wTime = world->GetTime();

for (auto &ent : localEntities) {
ent->Render2D();
}
Expand All @@ -764,22 +811,12 @@ namespace spades {
DrawJoinedAlivePlayerHUD();
} else {
DrawDeadPlayerHUD();
DrawSpectateHUD();
}
} else {
DrawSpectateHUD();
}

if (FollowsNonLocalPlayer(GetCameraMode()) && !cg_hideHud) {
font = fontManager->GetGuiFont();
std::string msg = _Tr("Client", "Following {0}",
world->GetPlayerPersistent(GetCameraTargetPlayerId()).name);
Vector2 size = font->Measure(msg);
Vector2 pos = MakeVector2(scrWidth - 8.f, 256.f + 32.f);
pos.x -= size.x;
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
MakeVector4(0, 0, 0, 0.5));
}

if (!cg_hideHud) {
DrawAlert();

Expand Down
12 changes: 9 additions & 3 deletions Sources/Client/Client_Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,25 @@ namespace spades {
followedPlayerId = world->GetLocalPlayerIndex();
}
if (world->GetLocalPlayer()->IsSpectator()) {
// Unfollow
followCameraState.enabled = false;
} else if (time > lastAliveTime + 1.3f) {
FollowNextPlayer(true);
followCameraState.enabled = true;
}
}
return;
} else if (CheckKey(cg_keyJump, name)) {
} else if (CheckKey(cg_keyJump, name) && cameraMode != ClientCameraMode::Free) {
if (down) {
followCameraState.firstPerson = !followCameraState.firstPerson;
}
return;
} else if (CheckKey(cg_keyReloadWeapon, name) &&
world->GetLocalPlayer()->IsSpectator() &&
followCameraState.enabled) {
if (down) {
// Unfollow
followCameraState.enabled = false;
}
return;
}
break;
}
Expand Down

0 comments on commit 4bd819a

Please sign in to comment.