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 2 commits
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: 29 additions & 0 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 @@ -519,6 +522,32 @@ namespace spades {
}
}
yvt marked this conversation as resolved.
Show resolved Hide resolved

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

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

this->hasNextSpawnConfig = true;
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) {
float timeout;
switch (type) {
Expand Down
12 changes: 12 additions & 0 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,22 @@ namespace spades {

bool inGameLimbo;

/*
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();
bool IsLimboViewActive();
void SpawnPressed();
void NextSpawnPressed();

Player *HotTrackedPlayer(hitTag_t *hitFlag);

Expand Down
9 changes: 9 additions & 0 deletions Sources/Client/Client_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@ namespace spades {

if (player->IsAlive())
lastAliveTime = time;
else if (hasNextSpawnConfig) {
if (player->GetTeamId() != (*nextSpawnConfig).team) {
net->SendTeamChange((*nextSpawnConfig).team);
}
if ((*nextSpawnConfig).team < 2 && player->GetWeapon()->GetWeaponType() != (*nextSpawnConfig).weapon) {
net->SendWeaponChange((*nextSpawnConfig).weapon);
}
hasNextSpawnConfig = false;
}

if (player->GetHealth() < lastHealth) {
// ouch!
Expand Down
13 changes: 12 additions & 1 deletion Sources/Client/LimboView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ namespace spades {

//! The "Spawn" button that you press when you're ready to "spawn".
items.push_back(MenuItem(MenuSpawn,
AABB2(left + contentsWidth - 266.f, firstY + 4.f, 256.f, 64.f),
AABB2(left + contentsWidth - 266.f, firstY, 256.f, 48.f),
_Tr("Client", "Spawn")));

//! The next spawn button to activate the settings the next time you spawn
items.push_back(MenuItem(MenuNextSpawn,
AABB2(left + contentsWidth - 266.f, firstY + 52.f, 256.f, 48.f),
_Tr("Client", "Set For Next Spawn")));

cursorPos = MakeVector2(renderer->ScreenWidth() * .5f, renderer->ScreenHeight() * .5f);

selectedTeam = 2;
Expand Down Expand Up @@ -116,6 +121,7 @@ namespace spades {
case MenuWeaponSMG: selectedWeapon = SMG_WEAPON; break;
case MenuWeaponShotgun: selectedWeapon = SHOTGUN_WEAPON; break;
case MenuSpawn: client->SpawnPressed(); break;
case MenuNextSpawn: client->NextSpawnPressed(); break;
}
}
}
Expand Down Expand Up @@ -156,6 +162,11 @@ namespace spades {
if (selectedTeam == 2) {
item.visible = false;
}
break;
case MenuNextSpawn:
if (client->GetWorld() && !(client->world->GetLocalPlayer() && !client->world->GetLocalPlayer()->IsSpectator()))
item.visible = false;
break;
default:;
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Client/LimboView.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace spades {
MenuWeaponRifle,
MenuWeaponSMG,
MenuWeaponShotgun,
MenuSpawn
MenuSpawn,
MenuNextSpawn
};
struct MenuItem {
MenuType type;
Expand Down