Initial Mapbase commit (squashed from mapbase-beta)

This commit is contained in:
Blixibon
2019-08-31 19:28:20 +00:00
parent 0d8dceea43
commit 3d464bc051
816 changed files with 105527 additions and 957 deletions

View File

@@ -17,6 +17,12 @@
#include "vstdlib/random.h"
#include "engine/IEngineSound.h"
#include "game.h"
#ifdef MAPBASE
#include <vgui_controls/Controls.h>
#include <vgui/ILocalize.h>
#include "utlbuffer.h"
#include "saverestore_utlvector.h"
#endif
#include "player.h"
#include "entitylist.h"
@@ -38,12 +44,18 @@ public:
void Spawn( void );
void Activate( void );
void Think( void );
#ifdef MAPBASE
virtual
#endif
void DrawOverlays(void);
virtual void UpdateOnRemove();
void InputEnable( inputdata_t &inputdata );
void InputDisable( inputdata_t &inputdata );
#ifdef MAPBASE
virtual void InputSetMessage( inputdata_t &inputdata );
#endif
DECLARE_DATADESC();
@@ -68,6 +80,9 @@ BEGIN_DATADESC( CMessageEntity )
// Inputs
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
#ifdef MAPBASE
DEFINE_INPUTFUNC( FIELD_STRING, "SetMessage", InputSetMessage ),
#endif
END_DATADESC()
@@ -172,6 +187,19 @@ void CMessageEntity::InputDisable( inputdata_t &inputdata )
m_bEnabled = false;
}
#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMessageEntity::InputSetMessage( inputdata_t &inputdata )
{
char newmessage[256];
Q_strncpy(newmessage, inputdata.value.String(), sizeof(newmessage));
m_messageText = AllocPooledString(newmessage);
}
#endif
// This is a hack to make point_message stuff appear in developer 0 release builds
// for now
void DrawMessageEntities()
@@ -189,3 +217,124 @@ void DrawMessageEntities()
me->DrawOverlays();
}
}
#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CMessageEntityLocalized : public CMessageEntity
{
DECLARE_CLASS( CMessageEntityLocalized, CMessageEntity );
public:
bool KeyValue(const char *szKeyName, const char *szValue);
void SetMessage(const char *szValue);
void DrawOverlays(void);
void InputSetMessage( inputdata_t &inputdata );
CUtlVector<string_t> m_messageLines;
DECLARE_DATADESC();
};
LINK_ENTITY_TO_CLASS( point_message_localized, CMessageEntityLocalized );
BEGIN_DATADESC( CMessageEntityLocalized )
DEFINE_UTLVECTOR( m_messageLines, FIELD_STRING ),
//DEFINE_INPUTFUNC( FIELD_STRING, "SetMessage", InputSetMessage ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose: Handles key values from the BSP before spawn is called.
//-----------------------------------------------------------------------------
bool CMessageEntityLocalized::KeyValue(const char *szKeyName, const char *szValue)
{
if (FStrEq(szKeyName, "message"))
{
SetMessage(szValue);
return true;
}
return BaseClass::KeyValue(szKeyName, szValue);
}
// I would use "\\n", but Hammer doesn't let you use back slashes.
#define CONVERSION_CHAR "/n"
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMessageEntityLocalized::SetMessage(const char *szValue)
{
// Find a localization token matching this string
wchar_t *pszMessage = g_pVGuiLocalize->Find(szValue);
// If this is a localized string, convert it back to char.
// If it isn't, just copy it right into this.
char szBackToChar[256];
if (pszMessage)
g_pVGuiLocalize->ConvertUnicodeToANSI(pszMessage, szBackToChar, sizeof(szBackToChar));
else
Q_strncpy(szBackToChar, szValue, sizeof(szBackToChar));
// szTemp is used to turn \n from localized strings into /n.
char szTemp[256];
if (Q_strstr(szBackToChar, "\n"))
{
char *token = strtok(szBackToChar, "\n");
while (token)
{
Q_snprintf(szTemp, sizeof(szTemp), "%s%s%s", szTemp, token, CONVERSION_CHAR);
token = strtok(NULL, "\n");
}
}
else
{
Q_strncpy(szTemp, szBackToChar, sizeof(szTemp));
}
m_messageLines.RemoveAll();
CUtlStringList vecLines;
Q_SplitString(szTemp, CONVERSION_CHAR, vecLines);
FOR_EACH_VEC( vecLines, i )
{
m_messageLines.AddToTail( AllocPooledString(vecLines[i]) );
}
vecLines.PurgeAndDeleteElements();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMessageEntityLocalized::InputSetMessage( inputdata_t &inputdata )
{
SetMessage(inputdata.value.String());
}
//-------------------------------------------
//-------------------------------------------
void CMessageEntityLocalized::DrawOverlays(void)
{
if ( !m_drawText )
return;
if ( m_bDeveloperOnly && !g_pDeveloper->GetInt() )
return;
if ( !m_bEnabled )
return;
// display text if they are within range
int offset = 0;
FOR_EACH_VEC( m_messageLines, i )
{
EntityText( offset, STRING(m_messageLines[i]), 0 );
offset++;
}
}
#endif