From a36ed76a4e42bf0a4ad116b86b4b8f603fcf3021 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Fri, 12 Feb 2016 00:26:59 +0100 Subject: [PATCH] AmmunitionHUDSystem now really working --- assets | 2 +- ...DSystem - Copy.h => AmmunitionHUDSystem.h} | 0 resources/Schema/Entities/Player.xml | 17 ++++----- src/Game/Systems/AmmunitionHUDSystem.cpp | 36 +++++++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) rename include/Game/Systems/{HealthHUDSystem - Copy.h => AmmunitionHUDSystem.h} (100%) create mode 100644 src/Game/Systems/AmmunitionHUDSystem.cpp diff --git a/assets b/assets index dfa0fc61..4d36fdce 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit dfa0fc61ab88456f3461779bd7c6ac97d15f6493 +Subproject commit 4d36fdced7007a594a56b7371bb26861876889aa diff --git a/include/Game/Systems/HealthHUDSystem - Copy.h b/include/Game/Systems/AmmunitionHUDSystem.h similarity index 100% rename from include/Game/Systems/HealthHUDSystem - Copy.h rename to include/Game/Systems/AmmunitionHUDSystem.h diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 8a5a4d24..910e440f 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -274,7 +274,7 @@ Idle - 0.14471987707210765 + 1.9901368826444736 1 @@ -293,8 +293,8 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + @@ -313,8 +313,9 @@ - - + + + @@ -371,7 +372,7 @@ Idle - 1.7139414005989018 + 0.22602443705505681 1 @@ -395,8 +396,8 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + diff --git a/src/Game/Systems/AmmunitionHUDSystem.cpp b/src/Game/Systems/AmmunitionHUDSystem.cpp new file mode 100644 index 00000000..c9d87072 --- /dev/null +++ b/src/Game/Systems/AmmunitionHUDSystem.cpp @@ -0,0 +1,36 @@ +#include "Game/Systems/AmmunitionHUDSystem.h" + +void AmmunitionHUDSystem::Update(double dt) +{ + //Hud element for tracking ammunition from parent with AssaultWeapon component.Child with the name "MagazineAmmo" tracks clip ammunition.Child with the name "Ammo" tracks ammo. + + auto ammunitionHUDs = m_World->GetComponents("AmmunitionHUD"); + if (ammunitionHUDs == nullptr) { + return; + } + + for (auto& ammunitionHUDComponent : *ammunitionHUDs) { + EntityWrapper entity = EntityWrapper(m_World, ammunitionHUDComponent.EntityID); + + EntityWrapper playerEntity = entity.FirstParentWithComponent("AssaultWeapon"); + + if (!playerEntity.Valid()) { + return; + } + + + EntityWrapper magazineAmmo = entity.FirstChildByName("MagazineAmmo"); + if(magazineAmmo.Valid()) { + if(magazineAmmo.HasComponent("Text")) { + (std::string&)magazineAmmo["Text"]["Content"] = std::to_string((int)playerEntity["AssaultWeapon"]["MagazineAmmo"]); + } + } + + EntityWrapper ammo = entity.FirstChildByName("Ammo"); + if (ammo.Valid()) { + if (ammo.HasComponent("Text")) { + (std::string&)ammo["Text"]["Content"] = std::to_string((int)playerEntity["AssaultWeapon"]["Ammo"]); + } + } + } +}