Skip to content

Commit

Permalink
Initial support for SOC weapon HUD (#392)
Browse files Browse the repository at this point in the history
Co-authored-by: SkyLoaderr <[email protected]>
  • Loading branch information
Xottab-DUTY committed Apr 14, 2023
1 parent dd2f60a commit 6e40571
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 276 deletions.
7 changes: 6 additions & 1 deletion src/xrGame/CustomOutfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ void CCustomOutfit::ApplySkinModel(CActor* pActor, bool bDress, bool bHUDOnly)
}

if (pActor == Level().CurrentViewEntity())
g_player_hud->load(pSettings->r_string(cNameSect(), "player_hud_section"));
{
if (pSettings->line_exist(cNameSect(), "player_hud_section"))
g_player_hud->load(pSettings->r_string(cNameSect(), "player_hud_section"));
else
g_player_hud->load_default();
}
}
else
{
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/Grenade.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "StdAfx.h"
#include "Grenade.h"
#include "xrPhysics/PhysicsShell.h"
//.#include "WeaponHUD.h"
#include "Entity.h"
#include "ParticlesObject.h"
#include "Actor.h"
Expand Down
34 changes: 26 additions & 8 deletions src/xrGame/HudItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ bool CHudItem::TryPlayAnimIdle()
}
if (pActor->AnyMove())
{
if (!st.bCrouch)
if (!st.bCrouch && isHUDAnimationExist("anm_idle_moving"))
{
PlayAnimIdleMoving();
return true;
Expand All @@ -376,31 +376,49 @@ bool CHudItem::TryPlayAnimIdle()
//AVO: check if animation exists
bool CHudItem::isHUDAnimationExist(pcstr anim_name) const
{
if (HudItemData()) // First person
if (const auto* data = HudItemData()) // First person
{
string256 anim_name_r;
bool is_16x9 = UI().is_widescreen();
u16 attach_place_idx = pSettings->r_u16(HudItemData()->m_sect_name, "attach_place_idx");
const bool is_16x9 = UI().is_widescreen();
const u16 attach_place_idx = data->m_attach_place_idx;
xr_sprintf(anim_name_r, "%s%s", anim_name, (attach_place_idx == 1 && is_16x9) ? "_16x9" : "");
player_hud_motion* anm = HudItemData()->m_hand_motions.find_motion(anim_name_r);
if (anm)
if (data->m_hand_motions.find_motion(anim_name_r))
return true;
}
else // Third person
else if (HudSection().c_str()) // Third person
{
const CMotionDef* temp_motion_def;
if (g_player_hud->motion_length(anim_name, HudSection(), temp_motion_def) > 100)
return true;
}
else
return false; // No hud section, no warning
#ifdef DEBUG
Msg("~ [WARNING] ------ Animation [%s] does not exist in [%s]", anim_name, HudSection().c_str());
#endif
return false;
}

pcstr CHudItem::WhichHUDAnimationExist(pcstr anim_name, pcstr anim_name2) const
{
if (isHUDAnimationExist(anim_name))
return anim_name;
if (isHUDAnimationExist(anim_name2))
return anim_name2;
return nullptr;
}

void CHudItem::PlayAnimIdleMovingCrouch() { PlayHUDMotion("anm_idle_moving_crouch", "anim_idle", true, nullptr, GetState()); }
void CHudItem::PlayAnimIdleMoving() { PlayHUDMotion("anm_idle_moving", "anim_idle", true, nullptr, GetState()); }
void CHudItem::PlayAnimIdleSprint() { PlayHUDMotion("anm_idle_sprint", "anim_idle", true, nullptr, GetState()); }

void CHudItem::PlayAnimIdleSprint()
{
if (cpcstr anim_name = WhichHUDAnimationExist("anm_idle_sprint", "anim_idle_sprint"))
PlayHUDMotion(anim_name, true, nullptr, GetState());
else
PlayHUDMotion("anm_idle", "anim_idle", true, nullptr, GetState());
}

void CHudItem::OnMovementChanged(ACTOR_DEFS::EMoveCommand cmd)
{
if (GetState() == eIdle && !m_bStopAtEndAnimIsRunning)
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/HudItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ class CHudItem : public CHUDState
virtual CHudItem* cast_hud_item() { return this; }
void PlayAnimIdleMovingCrouch(); //AVO: new crouch idle animation
bool isHUDAnimationExist(pcstr anim_name) const;
pcstr WhichHUDAnimationExist(pcstr anim_name, pcstr anim_name2) const;
};
1 change: 0 additions & 1 deletion src/xrGame/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,6 @@ void CInventory::InvalidateState() throw()
m_dwModifyFrame = Device.dwFrame;
}

//.#include "WeaponHUD.h"
void CInventory::Items_SetCurrentEntityHud(bool current_entity)
{
TIItemContainer::iterator it;
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/Missile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "StdAfx.h"
#include "Missile.h"
//.#include "WeaponHUD.h"
#include "xrPhysics/PhysicsShell.h"
#include "Actor.h"
#include "xrEngine/CameraBase.h"
Expand Down
19 changes: 19 additions & 0 deletions src/xrGame/ShootingObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ void CShootingObject::StartParticles(
{
in_hud_mode = false;
}
// XXX: Particle positions in Shoc configs were made for disabled hud mode
// Need to add checks here to use ShadowOfChernobylMode + CoP hud weapon
if (ShadowOfChernobylMode)
{
in_hud_mode = false;
}

pParticles->Play(in_hud_mode);
}
void CShootingObject::StopParticles(CParticlesObject*& pParticles)
Expand Down Expand Up @@ -318,6 +325,12 @@ void CShootingObject::OnShellDrop(const Fvector& play_pos, const Fvector& parent
{
in_hud_mode = false;
}
// XXX: Particle positions in Shoc configs were made for disabled hud mode
// Need to add checks here to use ShadowOfChernobylMode + CoP hud weapon
if (ShadowOfChernobylMode)
{
in_hud_mode = false;
}
pShellParticles->Play(in_hud_mode);
}

Expand Down Expand Up @@ -350,6 +363,12 @@ void CShootingObject::StartFlameParticles()
{
in_hud_mode = false;
}
// XXX: Particle positions in Shoc configs were made for disabled hud mode
// Need to add checks here to use ShadowOfChernobylMode + CoP hud weapon
if (ShadowOfChernobylMode)
{
in_hud_mode = false;
}
m_pFlameParticles->Play(in_hud_mode);
}
void CShootingObject::StopFlameParticles()
Expand Down
15 changes: 7 additions & 8 deletions src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,20 +1122,19 @@ void CWeaponMagazined::PlayAnimHide()

void CWeaponMagazined::PlayAnimReload()
{
auto state = GetState();
const auto state = GetState();
VERIFY(state == eReload);
if (bMisfire)
if (isHUDAnimationExist("anm_reload_misfire"))
PlayHUDMotion("anm_reload_misfire", true, this, state);
{
if (cpcstr anim_name = WhichHUDAnimationExist("anm_reload_misfire", "anim_reload_misfire"))
PlayHUDMotion(anim_name, true, this, state);
else
PlayHUDMotion("anm_reload", "anim_reload", true, this, state);
}
else
{
if (iAmmoElapsed == 0)
if (isHUDAnimationExist("anm_reload_empty"))
PlayHUDMotion("anm_reload_empty", true, this, state);
else
PlayHUDMotion("anm_reload", "anim_reload", true, this, state);
if (cpcstr anim_name = iAmmoElapsed == 0 ? WhichHUDAnimationExist("anm_reload_empty", "anim_reload_empty") : nullptr)
PlayHUDMotion(anim_name, true, this, state);
else
PlayHUDMotion("anm_reload", "anim_reload", true, this, state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/WeaponMagazinedWGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void CWeaponMagazinedWGrenade::PlayAnimShow()
PlayHUDMotion("anm_show_g", "anim_draw_g", FALSE, this, GetState());
}
else
PlayHUDMotion("anm_show", "anim_show", FALSE, this, GetState());
PlayHUDMotion("anm_show", "anim_draw", FALSE, this, GetState());
}

void CWeaponMagazinedWGrenade::PlayAnimHide()
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/WeaponPistol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void CWeaponPistol::PlayAnimShoot()
}
else
{
PlayHUDMotion("anm_shot_l", "anim_shoot_last", FALSE, this, GetState());
PlayHUDMotion("anm_shot_l", "anim_shot_last", FALSE, this, GetState());
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/xrGame/game_sv_deathmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,6 @@ void game_sv_Deathmatch::SM_SwitchOnNextActivePlayer()
SM_SwitchOnPlayer(pNewObject);
};

#include "WeaponHUD.h"

void game_sv_Deathmatch::net_Relcase(IGameObject* O)
{
if (m_pSM_CurViewEntity == O)
Expand Down
Loading

0 comments on commit 6e40571

Please sign in to comment.