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