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 all 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
32 changes: 32 additions & 0 deletions Sources/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ namespace spades {
if (team == 2)
team = 255;

// Reset next loadout since you manually spawn
this->nextSpawnConfig.reset();

if (!world->GetLocalPlayer() || world->GetLocalPlayer()->GetTeamId() >= 2) {
// join
if (team == 255) {
Expand All @@ -514,6 +517,35 @@ 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;

nextSpawnConfig = SpawnConfig {selectedTeam, selectedWeapon};

if (selectedTeam < 2) {
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 Team {0} with {1} on your next spawn.", teamName, prefixedWeaponName),
AlertType::Notice);
} else
ShowAlert(_Tr("Client", "You will join the spectators on your next spawn."),
AlertType::Notice);
}

void Client::ShowAlert(const std::string &contents, AlertType type) {
float timeout;
switch (type) {
Expand Down
10 changes: 10 additions & 0 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,20 @@ namespace spades {

bool inGameLimbo;

/*
nextSpawnConfig: Indicates values for next spawn. If set it means next spawn should abide by the config
*/
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();

stmp::optional<std::tuple<Player &, hitTag_t>> HotTrackedPlayer();

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 @@ -508,6 +508,15 @@ namespace spades {

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

if (player.GetHealth() < lastHealth) {
// ouch!
Expand Down
15 changes: 13 additions & 2 deletions 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()->IsAlive() && !client->world->GetLocalPlayer()->IsSpectator()))
item.visible = false;
break;
default:;
}

Expand Down Expand Up @@ -229,7 +240,7 @@ namespace spades {
}

renderer.SetColorAlphaPremultiplied(fillColor);
if (item.type == MenuSpawn) {
if (item.type == MenuSpawn || item.type == MenuNextSpawn) {
renderer.DrawImage(menuItemBigImage, item.rect);

std::string msg = item.text;
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