Skip to content

Commit

Permalink
change objective formatting to be easier to translate and add parenth…
Browse files Browse the repository at this point in the history
…eses to make it easier to read. add support for percentage-based objectives for mappers.
  • Loading branch information
BenLubar committed May 20, 2024
1 parent d28105b commit 8c9e2d2
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 107 deletions.
2 changes: 2 additions & 0 deletions reactivedrop/fgd/swarm.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -3585,11 +3585,13 @@
objectivetitle(string) : "Objective Title" : "" : "Title to use for this objective in the list on the briefing screen, or in-game for the current objective HUD display."
SetProgress(integer) : "Initial Progress" : 0 : "Numerator of progress fraction."
SetMaxProgress(integer) : "Max Progress" : 0 : "Denominator of progress fraction (0 for no progress tracking)."
SetShowPercentage(boolean) : "Show Percentage" : 0 : "Show a percentage rather than a fraction"
input SetComplete(void) : "SetComplete"
input SetIncomplete(void) : "SetIncomplete"
input SetFailed(void) : "SetFailed"
input SetProgress(integer) : "Set numerator of objective progress"
input SetMaxProgress(integer) : "Set denominator of objective progress"
input SetShowPercentage(bool) : "Show a percentage rather than a fraction"
]

@PointClass base(Targetname, ASWObjective) iconsprite("editor/asw_objective_escape.vmt") = asw_objective_escape :
Expand Down
34 changes: 7 additions & 27 deletions src/game/client/swarm/c_asw_objective_kill_aliens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ END_RECV_TABLE()

C_ASW_Objective_Kill_Aliens::C_ASW_Objective_Kill_Aliens()
{
m_pKillText = NULL;
m_pAlienPluralText = NULL;
m_pAlienSingularText = NULL;
m_bFoundText = false;
m_wszTitleBuffer[0] = '\0';
m_iLastKills = -1;
Expand All @@ -29,6 +27,7 @@ void C_ASW_Objective_Kill_Aliens::OnDataChanged(DataUpdateType_t updateType)
{
FindText();
}

BaseClass::OnDataChanged(updateType);
}

Expand All @@ -41,7 +40,7 @@ bool C_ASW_Objective_Kill_Aliens::NeedsTitleUpdate()

const wchar_t *C_ASW_Objective_Kill_Aliens::GetObjectiveTitle()
{
if ( !m_bFoundText || !m_pKillText || !m_pAlienPluralText || !m_pAlienSingularText )
if ( !m_bFoundText || !m_pAlienPluralText )
{
return L"";
}
Expand All @@ -59,39 +58,20 @@ const wchar_t *C_ASW_Objective_Kill_Aliens::GetObjectiveTitle()
V_snwprintf( wszNum2, NELEMS( wszNum2 ), L"%d", m_iTargetKills.Get() );

g_pVGuiLocalize->ConstructString( m_wszTitleBuffer, sizeof( m_wszTitleBuffer ),
g_pVGuiLocalize->Find( "#asw_kill_objective_format" ), 4,
m_pKillText, m_pAlienPluralText, wszNum, wszNum2 );
g_pVGuiLocalize->Find( "#asw_kill_objective_format" ), 3,
m_pAlienPluralText, wszNum, wszNum2 );
}

return m_wszTitleBuffer;
}

void C_ASW_Objective_Kill_Aliens::FindText()
{
m_pKillText = g_pVGuiLocalize->Find( "#asw_kill" );
m_pAlienPluralText = GetPluralText();
m_pAlienSingularText = GetSingularText();
m_bFoundText = true;
}

const wchar_t *C_ASW_Objective_Kill_Aliens::GetPluralText()
{
if ( m_AlienClassNum < 0 || m_AlienClassNum >= NELEMS( g_Aliens ) )
if ( m_AlienClassNum >= 0 && m_AlienClassNum < NELEMS( g_Aliens ) )
{
return NULL;
m_pAlienPluralText = g_pVGuiLocalize->Find( VarArgs( "#%ss", g_Aliens[m_AlienClassNum].m_pszAlienClass ) );
}

return g_pVGuiLocalize->Find( VarArgs( "#%ss", g_Aliens[m_AlienClassNum].m_pszAlienClass ) );
}

const wchar_t *C_ASW_Objective_Kill_Aliens::GetSingularText()
{
if ( m_AlienClassNum < 0 || m_AlienClassNum >= NELEMS( g_Aliens ) )
{
return NULL;
}

return g_pVGuiLocalize->Find( VarArgs( "#%s", g_Aliens[m_AlienClassNum].m_pszAlienClass ) );
m_bFoundText = true;
}

float C_ASW_Objective_Kill_Aliens::GetObjectiveProgress()
Expand Down
12 changes: 4 additions & 8 deletions src/game/client/swarm/c_asw_objective_kill_aliens.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@ class C_ASW_Objective_Kill_Aliens : public C_ASW_Objective

C_ASW_Objective_Kill_Aliens();

virtual void OnDataChanged(DataUpdateType_t updateType);
virtual void OnDataChanged( DataUpdateType_t updateType );
virtual const wchar_t *GetObjectiveTitle();
virtual bool NeedsTitleUpdate();
virtual float GetObjectiveProgress();
void FindText();
const wchar_t *GetPluralText();
const wchar_t *GetSingularText();

CNetworkVar(int, m_iTargetKills);
CNetworkVar(int, m_iCurrentKills);
CNetworkVar(int, m_AlienClassNum);
CNetworkVar( int, m_iTargetKills );
CNetworkVar( int, m_iCurrentKills );
CNetworkVar( int, m_AlienClassNum );

const wchar_t *m_pKillText;
const wchar_t *m_pAlienPluralText;
const wchar_t *m_pAlienSingularText;
bool m_bFoundText;

wchar_t m_wszTitleBuffer[64];
Expand Down
40 changes: 1 addition & 39 deletions src/game/client/swarm/c_asw_objective_kill_eggs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,10 @@ END_RECV_TABLE()

C_ASW_Objective_Kill_Eggs::C_ASW_Objective_Kill_Eggs()
{
m_pKillText = NULL;
m_pAlienPluralText = NULL;
m_pAlienSingularText = NULL;
m_bFoundText = false;
m_wszTitleBuffer[0] = '\0';
m_iLastKills = -1;
}

void C_ASW_Objective_Kill_Eggs::OnDataChanged(DataUpdateType_t updateType)
{
if ( updateType == DATA_UPDATE_CREATED )
{
FindText();
}

BaseClass::OnDataChanged(updateType);
}

bool C_ASW_Objective_Kill_Eggs::NeedsTitleUpdate()
{
int iKills = MIN( m_iTargetKills.Get(), m_iCurrentKills.Get() );
Expand All @@ -40,11 +26,6 @@ bool C_ASW_Objective_Kill_Eggs::NeedsTitleUpdate()

const wchar_t *C_ASW_Objective_Kill_Eggs::GetObjectiveTitle()
{
if ( !m_bFoundText || !m_pKillText || !m_pAlienPluralText || !m_pAlienSingularText )
{
return L"";
}

int iKills = MIN( m_iTargetKills.Get(), m_iCurrentKills.Get() );

if ( iKills != m_iLastKills ) // update the string
Expand All @@ -58,31 +39,12 @@ const wchar_t *C_ASW_Objective_Kill_Eggs::GetObjectiveTitle()
V_snwprintf( wszNum2, NELEMS( wszNum2 ), L"%d", m_iTargetKills.Get() );

g_pVGuiLocalize->ConstructString( m_wszTitleBuffer, sizeof( m_wszTitleBuffer ),
g_pVGuiLocalize->Find( "#asw_kill_objective_format" ), 4,
m_pKillText, m_pAlienPluralText, wszNum, wszNum2 );
g_pVGuiLocalize->Find( "#asw_kill_eggs_objective_format" ), 2, wszNum, wszNum2 );
}

return m_wszTitleBuffer;
}

void C_ASW_Objective_Kill_Eggs::FindText()
{
m_pKillText = g_pVGuiLocalize->Find( "#asw_destroy" );
m_pAlienPluralText = GetPluralText();
m_pAlienSingularText = GetSingularText();
m_bFoundText = true;
}

wchar_t *C_ASW_Objective_Kill_Eggs::GetPluralText()
{
return g_pVGuiLocalize->Find( "#asw_eggs" );
}

wchar_t *C_ASW_Objective_Kill_Eggs::GetSingularText()
{
return g_pVGuiLocalize->Find( "#asw_egg" );
}

float C_ASW_Objective_Kill_Eggs::GetObjectiveProgress()
{
if ( m_iTargetKills <= 0 )
Expand Down
15 changes: 3 additions & 12 deletions src/game/client/swarm/c_asw_objective_kill_eggs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ class C_ASW_Objective_Kill_Eggs : public C_ASW_Objective

C_ASW_Objective_Kill_Eggs();

virtual void OnDataChanged(DataUpdateType_t updateType);
virtual const wchar_t* GetObjectiveTitle();
virtual const wchar_t *GetObjectiveTitle();
virtual bool NeedsTitleUpdate();
virtual float GetObjectiveProgress();
void FindText();
wchar_t *GetPluralText();
wchar_t *GetSingularText();

CNetworkVar(int, m_iTargetKills);
CNetworkVar(int, m_iCurrentKills);

wchar_t *m_pKillText;
wchar_t *m_pAlienPluralText;
wchar_t *m_pAlienSingularText;
bool m_bFoundText;
CNetworkVar( int, m_iTargetKills );
CNetworkVar( int, m_iCurrentKills );

wchar_t m_wszTitleBuffer[64];
int m_iLastKills;
Expand Down
11 changes: 4 additions & 7 deletions src/game/client/swarm/c_asw_objective_kill_goo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ class C_ASW_Objective_Kill_Goo : public C_ASW_Objective

C_ASW_Objective_Kill_Goo();

virtual const wchar_t* GetObjectiveTitle();
virtual const wchar_t *GetObjectiveTitle();
virtual bool NeedsTitleUpdate();
virtual float GetObjectiveProgress();
void FindText();
wchar_t *GetPluralText();
wchar_t *GetSingularText();

CNetworkVar(int, m_iTargetKills);
CNetworkVar(int, m_iCurrentKills);
CNetworkVar( int, m_iTargetKills );
CNetworkVar( int, m_iCurrentKills );

wchar_t m_wszTitleBuffer[64];
int m_iLastKills;

Expand Down
6 changes: 0 additions & 6 deletions src/game/client/swarm/c_asw_objective_kill_queen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,4 @@ C_ASW_Objective_Kill_Queen::C_ASW_Objective_Kill_Queen()

C_ASW_Objective_Kill_Queen::~C_ASW_Objective_Kill_Queen()
{

}

void C_ASW_Objective_Kill_Queen::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged(updateType);
}
9 changes: 3 additions & 6 deletions src/game/client/swarm/c_asw_objective_kill_queen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ class C_ASW_Objective_Kill_Queen : public C_ASW_Objective
DECLARE_CLASS( C_ASW_Objective_Kill_Queen, C_ASW_Objective );
DECLARE_CLIENTCLASS();

C_ASW_Objective_Kill_Queen();
C_ASW_Objective_Kill_Queen();
virtual ~C_ASW_Objective_Kill_Queen();

virtual void OnDataChanged( DataUpdateType_t updateType );

CNetworkHandle(C_ASW_Queen, m_hQueen);
CNetworkHandle( C_ASW_Queen, m_hQueen );

private:
C_ASW_Objective_Kill_Queen( const C_ASW_Objective_Kill_Queen & ); // not defined, not accessible
};


#endif // _INCLUDED_C_ASW_OBJECTIVE_KILL_QUEEN_H
#endif // _INCLUDED_C_ASW_OBJECTIVE_KILL_QUEEN_H
20 changes: 18 additions & 2 deletions src/game/client/swarm/c_asw_objective_triggered.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#include "cbase.h"
#include "c_asw_objective_triggered.h"
#include "asw_hud_objective.h"
#include "vgui/ILocalize.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

IMPLEMENT_CLIENTCLASS_DT( C_ASW_Objective_Triggered, DT_ASW_Objective_Triggered, CASW_Objective_Triggered )
RecvPropInt( RECVINFO( m_nProgress ) ),
RecvPropInt( RECVINFO( m_nMaxProgress ) ),
RecvPropBool( RECVINFO( m_bShowPercentage ) ),
END_RECV_TABLE()

C_ASW_Objective_Triggered::C_ASW_Objective_Triggered()
{
m_nProgress = 0;
m_nMaxProgress = 0;
m_bShowPercentage = false;
m_nPrevProgress = 0;
m_bNeedsUpdate = true;
}
Expand Down Expand Up @@ -54,9 +57,22 @@ const wchar_t *C_ASW_Objective_Triggered::GetObjectiveTitle()
{
V_wcsncpy( m_wszObjectiveTitle, BaseClass::GetObjectiveTitle(), sizeof( m_wszObjectiveTitle ) );
}
else if ( m_bShowPercentage )
{
int nProgressPermille = m_nProgress * 1000 / m_nMaxProgress;
if ( nProgressPermille > 1000 )
nProgressPermille = 1000;
wchar_t wszPercent[4], wszTenths[2];
V_snwprintf( wszPercent, NELEMS( wszPercent ), L"%d", nProgressPermille / 10 );
V_snwprintf( wszTenths, NELEMS( wszTenths ), L"%d", nProgressPermille % 10 );
g_pVGuiLocalize->ConstructString( m_wszObjectiveTitle, sizeof( m_wszObjectiveTitle ), g_pVGuiLocalize->Find( "#asw_generic_objective_percent" ), 3, BaseClass::GetObjectiveTitle(), wszPercent, wszTenths );
}
else
{
V_snwprintf( m_wszObjectiveTitle, ARRAYSIZE( m_wszObjectiveTitle ), L"%s %d/%d", BaseClass::GetObjectiveTitle(), m_nProgress.Get(), m_nMaxProgress.Get() );
wchar_t wszProgress[11], wszMaxProgress[11];
V_snwprintf( wszProgress, NELEMS( wszProgress ), L"%d", m_nProgress.Get() );
V_snwprintf( wszMaxProgress, NELEMS( wszMaxProgress ), L"%d", m_nMaxProgress.Get() );
g_pVGuiLocalize->ConstructString( m_wszObjectiveTitle, sizeof( m_wszObjectiveTitle ), g_pVGuiLocalize->Find( "#asw_generic_objective_fraction" ), 3, BaseClass::GetObjectiveTitle(), wszProgress, wszMaxProgress );
}

m_bNeedsUpdate = false;
Expand All @@ -72,7 +88,7 @@ float C_ASW_Objective_Triggered::GetObjectiveProgress()
return BaseClass::GetObjectiveProgress();
}

float flProgress = ( float )m_nProgress / ( float )m_nMaxProgress;
float flProgress = float( m_nProgress ) / float( m_nMaxProgress );
flProgress = clamp<float>( flProgress, 0.0f, 1.0f );

return flProgress;
Expand Down
1 change: 1 addition & 0 deletions src/game/client/swarm/c_asw_objective_triggered.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class C_ASW_Objective_Triggered : public C_ASW_Objective

CNetworkVar( int, m_nProgress );
CNetworkVar( int, m_nMaxProgress );
CNetworkVar( bool, m_bShowPercentage );
int m_nPrevProgress;
bool m_bNeedsUpdate;

Expand Down
3 changes: 3 additions & 0 deletions src/game/server/swarm/asw_objective_triggered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ LINK_ENTITY_TO_CLASS( asw_objective_triggered, CASW_Objective_Triggered );
IMPLEMENT_SERVERCLASS_ST( CASW_Objective_Triggered, DT_ASW_Objective_Triggered )
SendPropInt( SENDINFO( m_nProgress ), -1, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_nMaxProgress ), -1, SPROP_UNSIGNED ),
SendPropBool( SENDINFO( m_bShowPercentage ) ),
END_SEND_TABLE()

BEGIN_DATADESC( CASW_Objective_Triggered )
DEFINE_INPUT( m_nProgress, FIELD_INTEGER, "SetProgress" ),
DEFINE_INPUT( m_nMaxProgress, FIELD_INTEGER, "SetMaxProgress" ),
DEFINE_INPUT( m_bShowPercentage, FIELD_BOOLEAN, "SetShowPercentage" ),
DEFINE_INPUTFUNC( FIELD_VOID, "SetComplete", InputSetComplete ),
DEFINE_INPUTFUNC( FIELD_VOID, "SetIncomplete", InputSetIncomplete ),
DEFINE_INPUTFUNC( FIELD_VOID, "SetFailed", InputSetFailed ),
Expand All @@ -26,6 +28,7 @@ CASW_Objective_Triggered::CASW_Objective_Triggered()
{
m_nProgress = 0;
m_nMaxProgress = 0;
m_bShowPercentage = false;
}

CASW_Objective_Triggered::~CASW_Objective_Triggered()
Expand Down
1 change: 1 addition & 0 deletions src/game/server/swarm/asw_objective_triggered.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CASW_Objective_Triggered : public CASW_Objective

CNetworkVar( int, m_nProgress );
CNetworkVar( int, m_nMaxProgress );
CNetworkVar( bool, m_bShowPercentage );
};

#endif /* _INCLUDED_ASW_OBJECTIVE_TRIGGERED_H */

0 comments on commit 8c9e2d2

Please sign in to comment.