chat.c 3.0 KB

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