Added env_message and game_text support.

This commit is contained in:
Marco Cawthorne 2019-01-10 11:13:12 +01:00
parent 4605482174
commit 3c42426b43
8 changed files with 296 additions and 0 deletions

View file

@ -272,6 +272,8 @@ void CSQC_UpdateView(float fWinWidth, float fWinHeight, float fGameFocus) {
Nightvision_PostDraw((int)vVideoMins[0],(int)vVideoMins[1], (int)fWinWidth, (int)fWinHeight);
if(fGameFocus == TRUE) {
GameText_Draw();
// The spectator sees things... differently
if (getplayerkeyvalue(player_localnum, "*spec") != "0") {
VGUI_DrawSpectatorHUD();

View file

@ -553,6 +553,10 @@ void CSQC_Parse_Event(void) {
Fade_Parse();
} else if (fHeader == EV_SPRITE) {
Sprite_ParseEvent();
} else if (fHeader == EV_TEXT) {
GameText_Parse();
} else if (fHeader == EV_MESSAGE) {
GameMessage_Parse();
}
}

View file

@ -257,6 +257,8 @@ enum {
EV_FLASH,
EV_SHAKE,
EV_FADE,
EV_TEXT,
EV_MESSAGE,
EV_SPRITE,
EV_MODELGIB,
EV_CAMERATRIGGER,

View file

@ -1,4 +1,5 @@
#includelist
../gs-entbase/client/fade.cpp
../gs-entbase/client/sprite.cpp
../gs-entbase/client/text.cpp
#endlist

View file

@ -0,0 +1,120 @@
/***
*
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
*
* See the file LICENSE attached with the sources for usage details.
*
****/
typedef struct
{
string m_strMessage;
float m_flPosX;
float m_flPosY;
int m_iEffect;
vector m_vecColor1;
vector m_vecColor2;
float m_flFadeIn;
float m_flFadeOut;
float m_flHoldTime;
float m_flFXTime;
float m_flTime;
} gametext_t;
gametext_t g_textchannels[5];
void GameText_Draw(void)
{
for (int i = 0; i < 5; i++) {
float a = 0.0f;
vector rpos;
float mtime;
float btime;
float strwidth;
mtime = g_textchannels[i].m_flFadeIn + g_textchannels[i].m_flHoldTime + g_textchannels[i].m_flFadeOut;
btime = g_textchannels[i].m_flFadeIn + g_textchannels[i].m_flHoldTime;
if (g_textchannels[i].m_flTime > mtime) {
continue;
}
strwidth = stringwidth(g_textchannels[i].m_strMessage, TRUE, [12,12]);
if (g_textchannels[i].m_flPosX == -1) {
rpos[0] = (vVideoResolution[0] / 2) - (strwidth/2);
} else {
rpos[0] = vVideoResolution[0] * g_textchannels[i].m_flPosX;
if (g_textchannels[i].m_flPosX >= 0.5) {
rpos[0] -= strwidth;
}
}
if (g_textchannels[i].m_flPosY == -1) {
rpos[1] = (vVideoResolution[1] / 2) - 6;
} else {
rpos[1] = ((vVideoResolution[1] - 12) * g_textchannels[i].m_flPosY);
}
if (g_textchannels[i].m_flTime < g_textchannels[i].m_flFadeIn) {
a = (g_textchannels[i].m_flTime / g_textchannels[i].m_flFadeIn);
} else if (g_textchannels[i].m_flTime < btime) {
a = 1.0f;
} else if (g_textchannels[i].m_flTime < mtime) {
if (g_textchannels[i].m_flFadeOut) {
a = 1 - (g_textchannels[i].m_flTime - btime) / g_textchannels[i].m_flFadeOut;
}
}
if (g_textchannels[i].m_flPosX >= 0.5) {
drawstring(rpos, g_textchannels[i].m_strMessage, '12 12', g_textchannels[i].m_vecColor2, a, 0 );
} else {
drawstring(rpos, g_textchannels[i].m_strMessage, '12 12', g_textchannels[i].m_vecColor2, a, 0 );
}
g_textchannels[i].m_flTime += clframetime;
}
}
void GameText_Parse(void)
{
int chan = readbyte();
g_textchannels[chan].m_strMessage = readstring();
g_textchannels[chan].m_flPosX = readfloat();
g_textchannels[chan].m_flPosY = readfloat();
g_textchannels[chan].m_iEffect = readbyte();
g_textchannels[chan].m_vecColor1[0] = readbyte() / 255;
g_textchannels[chan].m_vecColor1[1] = readbyte() / 255;
g_textchannels[chan].m_vecColor1[2] = readbyte() / 255;
g_textchannels[chan].m_vecColor2[0] = readbyte() / 255;
g_textchannels[chan].m_vecColor2[1] = readbyte() / 255;
g_textchannels[chan].m_vecColor2[2] = readbyte() / 255;
g_textchannels[chan].m_flFadeIn = readfloat();
g_textchannels[chan].m_flFadeOut = readfloat();
g_textchannels[chan].m_flHoldTime = readfloat();
g_textchannels[chan].m_flFXTime = readfloat();
g_textchannels[chan].m_flTime = 0.0f;
}
void GameMessage_Parse(void)
{
string strSound;
float flVolume;
int iAttenuation;
/* TODO: Fill in the other string data from titles.txt */
g_textchannels[0].m_strMessage = readstring();
g_textchannels[0].m_flTime = 0.0f;
g_textchannels[0].m_flPosX = -1;
g_textchannels[0].m_flPosY = 0.75f;
g_textchannels[0].m_flFadeIn = 0.5f;
g_textchannels[0].m_flFadeOut = 0.5f;
g_textchannels[0].m_flHoldTime = 4.0f;
strSound = readstring();
flVolume = readfloat();
iAttenuation = readbyte();
sound(self, CHAN_ITEM, strSound, flVolume, iAttenuation);
}

View file

@ -13,6 +13,8 @@
../gs-entbase/server/env_render.cpp
../gs-entbase/server/env_glow.cpp
../gs-entbase/server/env_shake.cpp
../gs-entbase/server/env_message.cpp
../gs-entbase/server/game_text.cpp
../gs-entbase/server/func_recharge.cpp
../gs-entbase/server/func_healthcharger.cpp
../gs-entbase/server/func_breakable.cpp

View file

@ -0,0 +1,73 @@
/***
*
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
*
* See the file LICENSE attached with the sources for usage details.
*
****/
enumflags
{
EMF_ONCE,
EMF_ALLPLAYERS
};
class env_message:CBaseTrigger
{
string m_strSound;
float m_flVolume;
int m_iAttenuation;
void() env_message;
virtual void() Play;
virtual void() Respawn;
};
void env_message::Play(void)
{
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_MESSAGE);
WriteString(MSG_MULTICAST, m_strMessage);
WriteString(MSG_MULTICAST, m_strSound);
WriteFloat(MSG_MULTICAST, m_flVolume);
WriteByte(MSG_MULTICAST, m_iAttenuation);
if (spawnflags & EMF_ALLPLAYERS) {
msg_entity = this;
multicast(origin, MULTICAST_ALL);
} else {
msg_entity = eActivator;
multicast(origin, MULTICAST_ONE_R);
}
if (spawnflags & EMF_ONCE) {
Trigger = __NULL__;
}
}
void env_message::Respawn(void)
{
Trigger = Play;
}
void env_message::env_message(void)
{
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
switch (argv(i)) {
case "messagesound":
m_strSound = argv(i+1);
break;
case "messagevolume":
m_flVolume = stof(argv(i+1));
break;
case "messageattenuation":
m_iAttenuation = stoi(argv(i+1));
break;
default:
break;
}
}
CBaseTrigger::CBaseTrigger();
env_message::Respawn();
}

View file

@ -6,3 +6,95 @@
*
****/
enumflags
{
GTF_ALLPLAYERS
};
class game_text:CBaseTrigger
{
float m_flPosX;
float m_flPosY;
int m_iEffect;
vector m_vecColor1;
vector m_vecColor2;
float m_flFadeIn;
float m_flFadeOut;
float m_flHoldTime;
float m_flFXTime;
int m_iChannel;
void() game_text;
virtual void() Trigger;
};
void game_text::Trigger(void)
{
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_TEXT);
WriteByte(MSG_MULTICAST, m_iChannel);
WriteString(MSG_MULTICAST, m_strMessage);
WriteFloat(MSG_MULTICAST, m_flPosX);
WriteFloat(MSG_MULTICAST, m_flPosY);
WriteByte(MSG_MULTICAST, m_iEffect);
WriteByte(MSG_MULTICAST, m_vecColor1[0]);
WriteByte(MSG_MULTICAST, m_vecColor1[1]);
WriteByte(MSG_MULTICAST, m_vecColor1[2]);
WriteByte(MSG_MULTICAST, m_vecColor2[0]);
WriteByte(MSG_MULTICAST, m_vecColor2[1]);
WriteByte(MSG_MULTICAST, m_vecColor2[2]);
WriteFloat(MSG_MULTICAST, m_flFadeIn);
WriteFloat(MSG_MULTICAST, m_flFadeOut);
WriteFloat(MSG_MULTICAST, m_flHoldTime);
WriteFloat(MSG_MULTICAST, m_flFXTime);
if (spawnflags & GTF_ALLPLAYERS) {
msg_entity = this;
multicast(origin, MULTICAST_ALL);
} else {
msg_entity = eActivator;
multicast(origin, MULTICAST_ONE_R);
}
}
void game_text::game_text(void)
{
for ( int i = 1; i < ( tokenize( __fullspawndata ) - 1 ); i += 2 ) {
switch ( argv( i ) ) {
case "x":
m_flPosX = stof(argv(i+1));
break;
case "y":
m_flPosY = stof(argv(i+1));
break;
case "effect":
m_iEffect = stoi(argv(i+1));
break;
case "color":
m_vecColor1 = stov(argv(i+1));
break;
case "color2":
m_vecColor2 = stov(argv(i+1));
break;
case "fadein":
m_flFadeIn = stof(argv(i+1));
break;
case "fadeout":
m_flFadeOut = stof(argv(i+1));
break;
case "holdtime":
m_flHoldTime = stof(argv(i+1));
break;
case "fxtime":
m_flFXTime = stof(argv(i+1));
break;
case "channel":
m_iChannel = stoi(argv(i+1));
break;
default:
break;
}
}
CBaseTrigger::CBaseTrigger();
}