Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ChatMessageLineComponent.c
Go to the documentation of this file.
2{
4
5 protected ResourceName CHAT_IMAGESET = "{1872FFA1133724A2}UI/Textures/Chat/chat.imageset";
6
7 protected Widget m_wRoot;
8
9 //------------------------------------------------------------------------------------------------
10 override void HandlerAttached(Widget w)
11 {
12 m_wRoot = w;
13 m_Widgets.Init(w);
15 }
16
17 //------------------------------------------------------------------------------------------------
22 protected Color GetTextColor(notnull SCR_ChatMessageStyle style, SCR_Faction senderFaction = null, int senderId = -1)
23 {
24 if (senderId < 0)
25 return Color.FromInt(Color.WHITE);
26
27 if (style.m_bColoredPlayerName)
28 return Color.FromInt(style.m_Color.PackToInt());
29
30 return Color.FromInt(Color.WHITE);
31 }
32
33 //------------------------------------------------------------------------------------------------
39 protected Color GetBadgeColor(notnull SCR_ChatMessageStyle style, SCR_Faction senderFaction = null, SCR_Faction localFaction = null, int senderId = -1)
40 {
41 if (style.m_bColoredBadge)
42 return style.m_Color;
43
44 if (!style.m_bColorBadgeWithRelationColor || !senderFaction)
45 return Color.FromInt(Color.WHITE);
46
47 if (senderFaction == localFaction && senderFaction.IsPlayerCommander(senderId))
48 return Color.FromInt(style.m_iBadgeColorForCommander);
49
50 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
51 if (!groupsManager)
52 return Color.FromInt(senderFaction.GetFactionColor().PackToInt());
53
54 SCR_AIGroup senderGroup = groupsManager.GetPlayerGroup(senderId);
55 if (!senderGroup)
56 return Color.FromInt(senderFaction.GetFactionColor().PackToInt());
57
58 SCR_AIGroup localGroup = groupsManager.GetPlayerGroup(SCR_PlayerController.GetLocalPlayerId());
59 if (localGroup == senderGroup)
60 return senderFaction.GetOutlineFactionColor();
61
62 return Color.FromInt(senderFaction.GetFactionColor().PackToInt());
63 }
64
65 //------------------------------------------------------------------------------------------------
71 protected Color GetBackgroundColor(notnull SCR_ChatMessageStyle style, SCR_Faction senderFaction = null, SCR_Faction localFaction = null, int senderId = -1)
72 {
73 if (style.m_bColoredBackground)
74 return style.m_Color;
75
76 if (style.m_bColorCommanderBackground && senderFaction && senderFaction == localFaction && senderFaction.IsPlayerCommander(senderId))
77 return Color.FromInt(style.m_iCommanderBackgroundColor);
78
79 return Color.FromInt(Color.BLACK);
80 }
81
82 //------------------------------------------------------------------------------------------------
85 void SetMessage(notnull SCR_ChatMessage msg, notnull SCR_ChatMessageStyle style)
86 {
87 // Enable elements which can be disabled for empty message lines
88 m_Widgets.m_wBadge.SetVisible(true);
89 m_Widgets.m_wTypeImage.SetVisible(true);
90
91 Color channelColor = style.m_Color;
92 string chatTypeImageName = style.m_sIconName;
93
94 //---------------------------------------------------------------------------------
95 // Common properties derived from the resolved style, regardless of message type
96
97 SCR_Faction senderFaction;
98 SCR_Faction localFaction;
99 int senderId = -1;
100 SCR_ChatMessageGeneral messageGeneral = SCR_ChatMessageGeneral.Cast(msg);
101 if (messageGeneral && messageGeneral.m_iSenderId > 0 && !messageGeneral.m_sSenderName.IsEmpty())
102 {
103 senderFaction = SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(messageGeneral.m_iSenderId));
104 localFaction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
105 senderId = messageGeneral.m_iSenderId;
106 }
107
108 Color textColor = GetTextColor(style, senderFaction, senderId);
109 Color badgeColor = GetBadgeColor(style, senderFaction, localFaction, senderId);
110 Color backgroundColor = GetBackgroundColor(style, senderFaction, localFaction, senderId);
111
112 // Badge color
113 m_Widgets.m_wBadge.SetColor(badgeColor);
114
115 // Image color
116 Color imageColor = Color.FromInt(Color.WHITE);
117 if (style.m_bColoredIcon)
118 imageColor = channelColor;
119
120 m_Widgets.m_wTypeImage.SetColor(imageColor);
121
122 // Background color
123 float bgAlphaOld = m_Widgets.m_wBackgroundImage.GetColor().A();
124 backgroundColor.SetA(bgAlphaOld); // Keep the old alpha value
125 m_Widgets.m_wBackgroundImage.SetColor(backgroundColor);
126 m_Widgets.m_wBackgroundImage.SetVisible(true);
127
128 //---------------------------------------------------------------------------------
129 // Properties specific to message type
130
131 // Set properties depending on channel class
132 string senderNameText;
133 if (messageGeneral)
134 senderNameText = messageGeneral.m_sSenderName + ": ";
135
136 m_Widgets.m_wTypeImage.LoadImageFromSet(0, CHAT_IMAGESET, chatTypeImageName);
137
138 string finalMessage = msg.m_sMessage;
139
140 if(senderNameText.IsEmpty())
141 m_Widgets.m_wMessageText.ClearFlags(WidgetFlags.NO_LOCALIZATION);
142 else
143 m_Widgets.m_wMessageText.SetFlags(WidgetFlags.NO_LOCALIZATION);
144
145 m_Widgets.m_wMessageText.SetColor(textColor);
146 m_Widgets.m_wMessageText.SetText(senderNameText + finalMessage);
147
149 if (!playerController)
150 return;
151
152 playerController.SetPlatformImageTo(senderId, m_Widgets.m_wPlatformImage);
153 }
154
155 //------------------------------------------------------------------------------------------------
157 {
158 // Hide elements, leave only text so that it constraints the height of this strip
159 m_Widgets.m_wBadge.SetVisible(false);
160 m_Widgets.m_wBackgroundImage.SetVisible(false);
161 m_Widgets.m_wTypeImage.SetVisible(false);
162 m_Widgets.m_wMessageText.SetText(" ");
163 m_Widgets.m_wPlatformImage.SetVisible(false);
164 }
165
166 //------------------------------------------------------------------------------------------------
168 void SetVisible(bool visible)
169 {
170 m_wRoot.SetVisible(visible);
171 }
172
173 //------------------------------------------------------------------------------------------------
176 {
177 return m_wRoot;
178 }
179}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Color.c:13
void SetMessage(notnull SCR_ChatMessage msg, notnull SCR_ChatMessageStyle style)
Color GetBackgroundColor(notnull SCR_ChatMessageStyle style, SCR_Faction senderFaction=null, SCR_Faction localFaction=null, int senderId=-1)
Color GetBadgeColor(notnull SCR_ChatMessageStyle style, SCR_Faction senderFaction=null, SCR_Faction localFaction=null, int senderId=-1)
Color GetTextColor(notnull SCR_ChatMessageStyle style, SCR_Faction senderFaction=null, int senderId=-1)
ref SCR_ChatMessageLineWidgets m_Widgets
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
proto external PlayerController GetPlayerController()
WidgetFlags
Widget flags. See enf::Widget::SetFlags().
Definition WidgetFlags.c:14