Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a selection menu for the next spawn loadout #894

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions Sources/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ namespace spades {
if (team == 2)
team = 255;

// Reset next loadout since you manually spawn
this->hasNextSpawnConfig = false;

if (!world->GetLocalPlayer() || world->GetLocalPlayer()->GetTeamId() >= 2) {
// join
if (team == 255) {
Expand All @@ -520,15 +523,29 @@ namespace spades {
}
yvt marked this conversation as resolved.
Show resolved Hide resolved

void Client::NextSpawnPressed() {
WeaponType weap = limbo->GetSelectedWeapon();
int team = limbo->GetSelectedTeam();
WeaponType selectedWeapon = limbo->GetSelectedWeapon();
if (!selectedWeapon)
selectedWeapon = RIFLE_WEAPON;

int selectedTeam = limbo->GetSelectedTeam();
inGameLimbo = false;
if (team == 2)
team = 255;
if (selectedTeam == 2)
selectedTeam = 255;

this->hasNextSpawnConfig = true;
this->nextTeam = team;
this->nextWeapon = weap;
nextSpawnConfig = SpawnConfig {selectedTeam, selectedWeapon};

std::string teamName = world ? world->GetTeam(selectedTeam).name
: "Team " + std::to_string(selectedTeam + 1);
std::string prefixedWeaponName;
switch (selectedWeapon) {
case RIFLE_WEAPON: prefixedWeaponName = "a Rifle"; break;
case SMG_WEAPON: prefixedWeaponName = "an SMG"; break;
case SHOTGUN_WEAPON: prefixedWeaponName = "a Shotgun"; break;
};

ShowAlert(_Tr("Client", "You will join {0} with {1} on your next spawn.", teamName, prefixedWeaponName),
AlertType::Notice);
}

void Client::ShowAlert(const std::string &contents, AlertType type) {
Expand Down
13 changes: 10 additions & 3 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,16 @@ namespace spades {

bool inGameLimbo;

bool hasNextSpawnConfig;
int nextTeam;
WeaponType nextWeapon;
/*
hasNextSpawnConfig: Boolean indicating if the Client will spawn with a new configuration (loadout) on next spawn. Gets cleared on spawn.
nextSpawnConfig: Indicates values for next spawn. These are only read when hasNextSpawnConfig is true
*/
bool hasNextSpawnConfig = false;
struct SpawnConfig {
int team;
WeaponType weapon;
};
stmp::optional<SpawnConfig> nextSpawnConfig;
ptrstr marked this conversation as resolved.
Show resolved Hide resolved

float GetLocalFireVibration();
void CaptureColor();
Expand Down
9 changes: 4 additions & 5 deletions Sources/Client/Client_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,11 @@ namespace spades {
if (player->IsAlive())
lastAliveTime = time;
else if (hasNextSpawnConfig) {
Player *p = world->GetLocalPlayer();
if (p->GetTeamId() != nextTeam) {
net->SendTeamChange(nextTeam);
if (player->GetTeamId() != (*nextSpawnConfig).team) {
net->SendTeamChange((*nextSpawnConfig).team);
}
if (nextTeam != 2 && p->GetWeapon()->GetWeaponType() != nextWeapon) {
net->SendWeaponChange(nextWeapon);
if ((*nextSpawnConfig).team < 2 && player->GetWeapon()->GetWeaponType() != (*nextSpawnConfig).weapon) {
net->SendWeaponChange((*nextSpawnConfig).weapon);
}
hasNextSpawnConfig = false;
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/LimboView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace spades {
}
break;
case MenuNextSpawn:
if (client && client->GetWorld() && client->world->GetLocalPlayer() && client->world->GetLocalPlayer()->IsAlive() && client->world->GetLocalPlayer()->GetTeamId() >= 2)
if (client->GetWorld() && !(client->world->GetLocalPlayer() && !client->world->GetLocalPlayer()->IsSpectator()))
item.visible = false;
break;
default:;
Expand Down