File size: 3,025 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
// #include "Scripts\Classes\Gui\ChatLine.c"
/*!
channel type, possible values
CCSystem(1)
CCAdmin(2)
CCDirect(4)
CCMegaphone(8)
CCTransmitter(16)
CCPublicAddressSystem(32)
CCBattlEye(64)
*/
class Chat
{
const int LINE_COUNT = 12;
protected Widget m_RootWidget;
protected int m_LineHeight;
protected int m_LastLine;
protected ref array<ref ChatLine> m_Lines;
void Chat()
{
m_Lines = new array<ref ChatLine>;
}
void ~Chat()
{
Destroy();
}
void Init(Widget root_widget)
{
Destroy();
m_RootWidget = root_widget;
if (m_RootWidget)
{
float w;
float h;
m_RootWidget.GetSize(w,h);
m_LineHeight = h / LINE_COUNT;
m_LastLine = 0;
for (int i = 0; i < LINE_COUNT; i++)
{
ChatLine line = new ChatLine(m_RootWidget);
m_Lines.Insert(line);
}
}
}
void Destroy()
{
m_Lines.Clear();
}
void Clear()
{
for (int i = 0; i < LINE_COUNT; i++)
{
m_Lines.Get(i).Clear();
}
}
void Add(ChatMessageEventParams params)
{
int max_lenght = ChatMaxUserLength;
int name_lenght = params.param2.Length();
int text_lenght = params.param3.Length();
int total_lenght = text_lenght + name_lenght;
int channel = params.param1;
if( channel & CCSystem || channel & CCBattlEye) //TODO separate battleye bellow
{
if( g_Game.GetProfileOption( EDayZProfilesOptions.GAME_MESSAGES ) )
return;
max_lenght = ChatMaxSystemLength; // system messages can be longer
}
//TODO add battleye filter to options
/*else if( channel & CCBattlEye )
{
if( g_Game.GetProfileOption( EDayZProfilesOptions.BATTLEYE_MESSAGES ) )
return;
}*/
else if( channel & CCAdmin )
{
if( g_Game.GetProfileOption( EDayZProfilesOptions.ADMIN_MESSAGES ) )
return;
}
else if( channel & CCDirect || channel & CCMegaphone || channel & CCTransmitter || channel & CCPublicAddressSystem )
{
if( g_Game.GetProfileOption( EDayZProfilesOptions.PLAYER_MESSAGES ) )
return;
}
else if( channel != 0 ) // 0 should be local messages to self
{
Print("Chat: Unknown channel " + channel);
return;
}
if (total_lenght > max_lenght)
{
int pos = 0;
int lenght = Math.Clamp(max_lenght - name_lenght, 0, text_lenght);
ref ChatMessageEventParams tmp = new ChatMessageEventParams(params.param1, params.param2, "", params.param4);
while (pos < text_lenght)
{
tmp.param3 = params.param3.Substring(pos, lenght);
AddInternal(tmp);
tmp.param2 = "";
pos += lenght;
lenght = Math.Clamp(text_lenght - pos, 0, max_lenght);
}
}
else
{
AddInternal(params);
}
}
void AddInternal(ChatMessageEventParams params)
{
m_LastLine = (m_LastLine + 1) % m_Lines.Count();
ChatLine line = m_Lines.Get(m_LastLine);
line.Set(params);
for (int i = 0; i < m_Lines.Count(); i++)
{
line = m_Lines.Get((m_LastLine + 1 + i) % LINE_COUNT);
line.m_RootWidget.SetPos(0, i * m_LineHeight);
float x = 0;
float y = 0;
line.m_RootWidget.GetPos(x, y);
}
}
}
|