diff --git a/Sources/Client/Client.cpp b/Sources/Client/Client.cpp index 72f1b2bc0..feb840cdb 100644 --- a/Sources/Client/Client.cpp +++ b/Sources/Client/Client.cpp @@ -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) { @@ -514,6 +517,35 @@ namespace spades { } } + 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) { diff --git a/Sources/Client/Client.h b/Sources/Client/Client.h index ba3760e0a..fdb2b30ed 100644 --- a/Sources/Client/Client.h +++ b/Sources/Client/Client.h @@ -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 nextSpawnConfig; + float GetLocalFireVibration(); void CaptureColor(); bool IsLimboViewActive(); void SpawnPressed(); + void NextSpawnPressed(); stmp::optional> HotTrackedPlayer(); diff --git a/Sources/Client/Client_Update.cpp b/Sources/Client/Client_Update.cpp index 0107c5e6d..8c906158c 100644 --- a/Sources/Client/Client_Update.cpp +++ b/Sources/Client/Client_Update.cpp @@ -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! diff --git a/Sources/Client/LimboView.cpp b/Sources/Client/LimboView.cpp index 6dc21f427..8d547c0aa 100644 --- a/Sources/Client/LimboView.cpp +++ b/Sources/Client/LimboView.cpp @@ -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; @@ -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; } } } @@ -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:; } @@ -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; diff --git a/Sources/Client/LimboView.h b/Sources/Client/LimboView.h index 30beaad81..f0e9d540d 100644 --- a/Sources/Client/LimboView.h +++ b/Sources/Client/LimboView.h @@ -38,7 +38,8 @@ namespace spades { MenuWeaponRifle, MenuWeaponSMG, MenuWeaponShotgun, - MenuSpawn + MenuSpawn, + MenuNextSpawn }; struct MenuItem { MenuType type;