Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
chatline.c
Go to the documentation of this file.
1 class ChatLine
2 {
3  // Consts
4  const float FADE_TIMEOUT = 30;
5  const float FADE_OUT_DURATION = 3;
6  const float FADE_IN_DURATION = 0.5;
7 
8  private const string RADIO_PREFIX = "(" + "#str_radio" + ") ";
9  private const string GAME_PREFIX = "(" + "#layout_chat_game" + ") ";
10  private const string ADMIN_PREFIX = "(" + "#STR_MP_MASTER" + ") ";
11  private const int DEFAULT_COLOUR = ARGB(255, 255, 255, 255);
12  private const int GAME_TEXT_COLOUR = ARGB(255, 255, 0, 0);
13  private const int ADMIN_TEXT_COLOUR = ARGB(255, 255, 255, 0);
14 
15  // Widgets
16  Widget m_RootWidget;
17  TextWidget m_NameWidget;
18  TextWidget m_TextWidget;
19 
20  private ref WidgetFadeTimer m_FadeTimer;
21  private ref Timer m_TimeoutTimer;
22 
23  void ChatLine(Widget root_widget)
24  {
25  m_RootWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_chat_item.layout", root_widget);
26 
27  m_NameWidget = TextWidget.Cast( m_RootWidget.FindAnyWidget( "ChatItemSenderWidget" ) );
28  m_TextWidget = TextWidget.Cast( m_RootWidget.FindAnyWidget( "ChatItemTextWidget" ) );
29 
30  m_FadeTimer = new WidgetFadeTimer;
31  m_TimeoutTimer = new Timer(CALL_CATEGORY_GUI);
32  }
33 
34  void ~ChatLine()
35  {
36  delete m_TextWidget;
37  }
38 
39  void Set(ChatMessageEventParams params) // Param 1 --> Channel, Param 2 --> sender name, Param 3 --> message, Param 4 ??
40  {
41  int channel;
42 
43  m_NameWidget.SetText("");
44  m_TextWidget.SetText("");
45 
46  SetColour(DEFAULT_COLOUR);
47  m_RootWidget.Show(true);
48 
49  channel = params.param1; // 0 = Survior 1 = Game/System 2 = Admin
50 
51  /*
52  if (params.param2 != "")
53  {
54  m_NameWidget.SetText( params.param2 + " : ");
55  }
56 
57  if( channel & CCSystem )
58  {
59  if(params.param2 != "")
60  {
61  m_NameWidget.SetText(GAME_PREFIX + ": " );
62  }
63  SetColour(GAME_TEXT_COLOUR);
64  }
65  else if( channel & CCAdmin )
66  {
67  m_NameWidget.SetText(ADMIN_PREFIX + ": ");
68  SetColour(ADMIN_TEXT_COLOUR);
69  }
70  else if( channel & CCTransmitter )
71  {
72  m_NameWidget.SetText(RADIO_PREFIX + params.param2 + " : ");
73  }
74  */
75 
76  if ( channel & CCSystem )
77  {
78  // Game
79  if (params.param2 != "")
80  {
81  m_NameWidget.SetText(GAME_PREFIX + ": " );
82  }
83 
84  SetColorByParam(params.param4, GAME_TEXT_COLOUR);
85  }
86  else if ( channel & CCAdmin )
87  {
88  // Admin
89  m_NameWidget.SetText(ADMIN_PREFIX + ": ");
90  SetColorByParam(params.param4, ADMIN_TEXT_COLOUR);
91  }
92  else if ( channel & CCTransmitter )
93  {
94  // Radio - Trasnmitter
95  m_NameWidget.SetText(RADIO_PREFIX + params.param2 + " : ");
96  }
97  else if ( channel == 0 || channel & CCDirect )
98  {
99  // Player
100  if (params.param2 != "")
101  {
102  m_NameWidget.SetText(params.param2 + " : ");
103  }
104  }
105 
106 
107  m_TextWidget.SetText(params.param3);
108 
109  m_FadeTimer.FadeIn(m_RootWidget, FADE_IN_DURATION);
110  m_TimeoutTimer.Run(FADE_TIMEOUT, m_FadeTimer, "FadeOut", new Param2<Widget, float>(m_RootWidget, FADE_OUT_DURATION));
111  }
112 
113  private void SetColour(int colour)
114  {
115  m_NameWidget.SetColor(colour);
116  m_TextWidget.SetColor(colour);
117  }
118 
119  protected void SetColorByParam(string pParamValue, int pFallback)
120  {
121  if (pParamValue != "")
122  {
123  SetColour(ColorNameToColor(pParamValue));
124  return;
125  }
126 
127  SetColour(pFallback);
128  }
129 
130  void Clear()
131  {
132  m_RootWidget.Show( false );
133  m_TimeoutTimer.Stop();
134  m_FadeTimer.Stop();
135  }
136 
137  protected int ColorNameToColor(string pColorName)
138  {
139  int color = 0xFFFFFFFF;
140  switch (pColorName)
141  {
142  case "colorStatusChannel":
143  color = COLOR_BLUE;
144  break;
145  case "colorAction":
146  color = COLOR_YELLOW;
147  break;
148  case "colorFriendly":
149  color = COLOR_GREEN;
150  break;
151  case "colorImportant":
152  color = COLOR_RED;
153  break;
154  }
155 
156  return color;
157  }
158 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
ChatMessageEventParams
Param4< int, string, string, string > ChatMessageEventParams
channel, from, text, color config class
Definition: gameplay.c:396
COLOR_YELLOW
const int COLOR_YELLOW
Definition: constants.c:67
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
ChatLine
Definition: chatline.c:1
TextWidget
Definition: enwidgets.c:219
COLOR_GREEN
const int COLOR_GREEN
Definition: constants.c:65
COLOR_RED
const int COLOR_RED
Definition: constants.c:64
Timer
Definition: dayzplayerimplement.c:62
Widget
Definition: enwidgets.c:189
COLOR_BLUE
const int COLOR_BLUE
Definition: constants.c:66
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322